- Major update of the dynamic device tree so it can handle

* subtractive resources
  * merging with the static device tree
  * more device types than just pci
- The piece to watch out for is the new enable_resources method that was needed in all of the drivers


git-svn-id: svn://svn.coreboot.org/coreboot/trunk@1096 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
Eric Biederman
2003-09-02 03:36:25 +00:00
parent d4c14524f5
commit e9a271e32c
25 changed files with 876 additions and 377 deletions

View File

@@ -1,3 +1,7 @@
#ifndef DEVICE_CHIP_H
#include <device/path.h>
/* chips are arbitrary chips (superio, southbridge, etc.)
* They have private structures that define chip resources and default
* settings. They have four externally visible functions for control.
@@ -48,23 +52,38 @@ struct chip;
/* there is one of these for each TYPE of chip */
struct chip_control {
void (*enable)(struct chip *, enum chip_pass);
char *path; /* the default path. Can be overridden
* by commands in config
*/
// This is the print name for debugging
char *name;
/* This is the print name for debugging */
char *name;
void (*enable)(struct chip *, enum chip_pass);
void (*enumerate)(struct chip *chip);
};
struct chip_device_path {
struct device_path path;
unsigned channel;
int enable;
};
struct device;
struct bus;
#ifndef MAX_CHIP_PATHS
#define MAX_CHIP_PATHS 16
#endif
struct chip {
struct chip_control *control; /* for this device */
char *path; /* can be 0, in which case the default is taken */
char *configuration; /* can be 0. */
int irq;
struct chip *next, *children;
/* there is one of these for each INSTANCE of a chip */
void *chip_info; /* the dreaded "void *" */
struct chip_control *control; /* for this device */
struct chip_device_path path[MAX_CHIP_PATHS]; /* can be 0, in which case the default is taken */
char *configuration; /* can be 0. */
struct chip *next, *children;
/* there is one of these for each INSTANCE of a chip */
void *chip_info; /* the dreaded "void *" */
/* bus and device links into the device tree */
struct bus *bus;
struct device *dev;
};
extern struct chip static_root;
extern void chip_configure(struct chip *, enum chip_pass);
extern void chip_enumerate(struct chip *chip);
#endif /* DEVICE_CHIP_H */

View File

@@ -3,6 +3,7 @@
#include <stdint.h>
#include <device/resource.h>
#include <device/path.h>
struct device;
typedef struct device * device_t;
@@ -10,33 +11,42 @@ typedef struct device * device_t;
struct device_operations {
void (*read_resources)(device_t dev);
void (*set_resources)(device_t dev);
void (*enable_resources)(device_t dev);
void (*init)(device_t dev);
unsigned int (*scan_bus)(device_t bus, unsigned int max);
void (*enable)(device_t dev);
};
struct bus {
device_t dev; /* This bridge device */
device_t children; /* devices behind this bridge */
unsigned bridge_ctrl; /* Bridge control register */
unsigned char link; /* The index of this link */
unsigned char secondary; /* secondary bus number */
unsigned char subordinate; /* max subordinate bus number */
unsigned char cap; /* PCi capability offset */
};
#define MAX_RESOURCES 6
#define MAX_LINKS 3
/*
* There is one device structure for each slot-number/function-number
* combination:
*/
struct device {
device_t bus; /* bus this device is on */
device_t children; /* devices behind this bridge */
device_t sibling; /* next device on this bus */
device_t next; /* chain of all devices */
struct bus * bus; /* bus this device is on */
device_t sibling; /* next device on this bus */
device_t next; /* chain of all devices */
unsigned int devfn; /* encoded device & function index */
struct device_path path;
unsigned short vendor;
unsigned short device;
unsigned int class; /* 3 bytes: (base,sub,prog-if) */
unsigned int hdr_type; /* PCI header type */
unsigned int enable : 1; /* set if we should enable the device */
unsigned char secondary; /* secondary bus number */
unsigned char subordinate; /* max subordinate bus number */
uint8_t command;
/*
* In theory, the irq level can be read from configuration
@@ -56,6 +66,10 @@ struct device {
*/
struct resource resource[MAX_RESOURCES];
unsigned int resources;
struct bus link[MAX_LINKS];
unsigned int links;
unsigned long rom_address;
struct device_operations *ops;
};
@@ -65,19 +79,22 @@ extern struct device *all_devices; /* list of all devices */
/* Generic device interface functions */
extern device_t alloc_dev(struct bus *parent, struct device_path *path);
extern void dev_enumerate(void);
extern void dev_configure(void);
extern void dev_enable(void);
extern void dev_initialize(void);
/* Generic device helper functions */
void append_device(device_t dev);
void compute_allocate_resource(device_t bus, struct resource *bridge,
extern void compute_allocate_resource(struct bus *bus, struct resource *bridge,
unsigned long type_mask, unsigned long type);
void assign_resources(device_t bus);
void enumerate_static_device(void);
extern void assign_resources(struct bus *bus);
extern void enable_resources(struct device *dev);
extern void enumerate_static_device(void);
extern const char *dev_path(device_t dev);
/* Helper functions */
device_t alloc_find_dev(struct bus *bus, struct device_path *path);
device_t dev_find_device (unsigned int vendor, unsigned int device, device_t from);
device_t dev_find_class (unsigned int class, device_t from);
device_t dev_find_slot (unsigned int bus, unsigned int devfn);
@@ -88,5 +105,10 @@ device_t dev_find_slot (unsigned int bus, unsigned int devfn);
#define DEVICE_IO_ALIGN 16
#define DEVICE_MEM_ALIGN 4096
struct device_operations default_dev_ops_root;
extern void root_dev_read_resources(device_t dev);
extern void root_dev_set_resources(device_t dev);
extern unsigned int walk_static_devices(device_t bus, unsigned int max);
extern void enable_childrens_resources(device_t dev);
#endif /* DEVICE_H */

41
src/include/device/path.h Normal file
View File

@@ -0,0 +1,41 @@
#ifndef DEVICE_PATH_H
#define DEVICE_PATH_H
enum device_path_type {
DEVICE_PATH_NONE = 0,
DEVICE_PATH_PCI,
DEVICE_PATH_PNP,
DEVICE_PATH_I2C,
};
struct pci_path
{
unsigned devfn;
};
struct pnp_path
{
unsigned port;
unsigned device;
};
struct i2c_path
{
unsigned device;
};
struct device_path {
enum device_path_type type;
union {
struct pci_path pci;
struct pnp_path pnp;
struct i2c_path i2c;
} u;
};
#define DEVICE_PATH_MAX 30
extern int path_eq(struct device_path *path1, struct device_path *path2);
#endif /* DEVICE_PATH_H */

View File

@@ -34,13 +34,15 @@ extern struct pci_driver epci_drivers[];
struct device_operations default_pci_ops_dev;
struct device_operations default_pci_ops_bus;
struct device_operations default_pci_ops_root;
void pci_dev_read_resources(struct device *dev);
void pci_bus_read_resources(struct device *dev);
void pci_dev_set_resources(struct device *dev);
unsigned int pci_scan_bridge(struct device *bus, unsigned int max);
void pci_dev_read_resources(device_t dev);
void pci_bus_read_resources(device_t dev);
void pci_dev_set_resources(device_t dev);
void pci_dev_enable_resources(device_t dev);
void pci_bus_enable_resources(device_t dev);
unsigned int pci_scan_bridge(device_t bus, unsigned int max);
unsigned int pci_scan_bus(struct bus *bus, unsigned min_devfn, unsigned max_devfn, unsigned int max);
#define PCI_IO_BRIDGE_ALIGN 4096
#define PCI_MEM_BRIDGE_ALIGN (1024*1024)

View File

@@ -7,7 +7,7 @@
#define IORESOURCE_IO 0x00000100 /* Resource type */
#define IORESOURCE_MEM 0x00000200
#define IORESOURCE_IRQ 0x00000400
#define IORESOURCE_DMA 0x00000800
#define IORESOURCE_DRQ 0x00000800
#define IORESOURCE_PREFETCH 0x00001000 /* No side effects */
#define IORESOURCE_READONLY 0x00002000
@@ -15,8 +15,12 @@
#define IORESOURCE_RANGELENGTH 0x00008000
#define IORESOURCE_SHADOWABLE 0x00010000
#define IORESOURCE_BUS_HAS_VGA 0x00020000
#define IORESOURCE_SUBTRACTIVE 0x00040000 /* This resource filters all of the unclaimed transactions
* to the bus below.
*/
#define IORESOURCE_SET 0x80000000
#define IORESOURCE_SET 0x80000000 /* An IO resource that has been assigned a value */
#define IORESOURCE_FIXED 0x40000000 /* An IO resource the allocator must not change */
/* PCI specific resource bits */
#define IORESOURCE_PCI64 (1<<0) /* 64bit long pci resource */