* start using arch/foo.h again instead of archfoo.h (trivial)

* make constructor an initializer.
* fix memory leak/code flow error in current code
* add spinlocking
* drop malloc and use new_device for device allocation instead.
* add CONFIG_SMP as it is needed by spinlocks and soon other stuff.

Signed-off-by: Stefan Reinauer <stepan@coresystems.de>
Acked-by: Ronald G. Minnich <rminnich@gmail.com>



git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@418 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
Stefan Reinauer 2007-06-29 16:57:23 +00:00
commit 25ebd9110b
13 changed files with 183 additions and 188 deletions

View file

@ -0,0 +1,8 @@
#ifndef ARCH_ELF_H
#define ARCH_ELF_H
#define ELF_CLASS ELFCLASS32
#define ELF_DATA ELFDATA2LSB
#define ELF_ARCH EM_386
#endif /* ARCH_ELF_H */

View file

@ -0,0 +1,83 @@
/*
* This file is part of the LinuxBIOS project.
*
* Copyright (C) 2001 Linux Networx
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ARCH_SPINLOCK_H
#define ARCH_SPINLOCK_H
/*
* Your basic SMP spinlocks, allowing only a single CPU anywhere
*/
typedef struct {
volatile unsigned int lock;
} spinlock_t;
#define SPIN_LOCK_UNLOCKED (spinlock_t) { 1 }
/*
* Simple spin lock operations. There are two variants, one clears IRQ's
* on the local processor, one does not.
*
* We make no fairness assumptions. They have a cost.
*/
#define barrier() __asm__ __volatile__("": : :"memory")
#define spin_is_locked(x) (*(volatile char *)(&(x)->lock) <= 0)
#define spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x))
#define spin_lock_string \
"\n1:\t" \
"lock ; decb %0\n\t" \
"js 2f\n" \
".section .text.lock,\"ax\"\n" \
"2:\t" \
"cmpb $0,%0\n\t" \
"rep;nop\n\t" \
"jle 2b\n\t" \
"jmp 1b\n" \
".previous"
/*
* This works. Despite all the confusion.
*/
#define spin_unlock_string \
"movb $1,%0"
static inline __attribute__((always_inline)) void spin_lock(spinlock_t *lock)
{
__asm__ __volatile__(
spin_lock_string
:"=m" (lock->lock) : : "memory");
}
static inline __attribute__((always_inline)) void spin_unlock(spinlock_t *lock)
{
__asm__ __volatile__(
spin_unlock_string
:"=m" (lock->lock) : : "memory");
}
/* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
static inline __attribute__((always_inline)) void cpu_relax(void)
{
__asm__ __volatile__("rep;nop": : :"memory");
}
#endif /* ARCH_SPINLOCK_H */

View file

@ -1,8 +0,0 @@
#ifndef ARCH_X86_ARCHELF_H
#define ARCH_X86_ARCHELF_H
#define ELF_CLASS ELFCLASS32
#define ELF_DATA ELFDATA2LSB
#define ELF_ARCH EM_386
#endif /* ARCH_X86_ARCHELF_H */

View file

@ -112,18 +112,21 @@ struct device_operations {
void (*set_link)(struct device * dev, unsigned int link);
void (*reset_bus)(struct bus *bus);
/* a constructor. The constructor for a given device is defined in the device source file.
* When is this called? Not for the static tree. When the scan bus code finds a new device, it must
* create it and insert it into the device tree. To do this, it calls a device constructor.
* The set of all device constructors is concatenated into the constructors array of structures via the usual
* gcc hack of naming a segment.
* The dev_constructor code in device.c iterates over the constructors array.
* A match consists of a path type, a vendor (which may be ignored if the constructo vendor value is 0),
* and a device id.
* When it finds a match, the dev_constructor calls the
* function constructors->constructor(constructors->constructor) and a new device is created.
/* A constructor. The constructor for a given device is defined in the
* device source file. When is this called? Not for the static tree.
* When the scan bus code finds a new device, it must create it and
* insert it into the device tree. To initialize it, it calls a device
* constructor. The set of all device constructors is concatenated
* into the constructors array of structures.
*
* The dev_constructor code in device.c iterates over the constructors
* array. A match consists of a path type, a vendor (which may be
* ignored if the constructor vendor value is 0), and a device id.
* When it finds a match, the dev_constructor calls the function
* constructors->constructor(constructors->constructor) and a new
* device is created.
*/
struct device *(*constructor)(struct constructor *);
void (*constructor)(struct device *, struct constructor *);
/* set device ops */
void (*phase1_set_device_operations)(struct device *dev);
@ -245,7 +248,7 @@ struct device * dev_find_device (unsigned int vendor, unsigned int device, struc
struct device * dev_find_class (unsigned int class, struct device * from);
struct device * dev_find_slot (unsigned int bus, unsigned int devfn);
struct device * dev_find_slot_on_smbus (unsigned int bus, unsigned int addr);
struct device *default_device_constructor(struct constructor *constructor);
void default_device_constructor(struct device *dev, struct constructor *constructor);
/* Rounding for boundaries.

View file

@ -31,7 +31,7 @@
#define ELF_H
#include <types.h>
#include <archelf.h>
#include <arch/elf.h>
/* Standard ELF types. */

View file

@ -1,22 +0,0 @@
/*
* This file is part of the LinuxBIOS project.
*
* Copyright (C) 2007 coresystems GmbH
* (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
*/
void *malloc(size_t size);