This patch adds some debug functions, cleans up whitespace (per indent), and adds const in a few places.

include/device/path.h
	Make path_eq take const path*.
	
include/device/device.h
	Use const with dev_path, dev_id_string, bus_path, find_dev_path,
	andalloc_find.

device/device.c
	Add functions for tree printing of devs and resources.
	Change %p to more useful info.

device/device_util.c
	Use const changes from device.h.

lib/stage2.c
	Use updated printing functions.

Signed-off-by: Myles Watson <mylesgw@gmail.com>
Acked-by: Ronald G. Minnich <rminnich@gmail.com>


git-svn-id: svn://coreboot.org/repository/coreboot-v3@1024 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
Myles Watson 2008-11-14 16:15:33 +00:00
commit 981c3652a1
5 changed files with 282 additions and 212 deletions

View file

@ -38,16 +38,16 @@
#define TYPENAME(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|(d))
#define DEVICE_ID_MAX 64
enum device_id_type {
DEVICE_ID_NONE = 0,
DEVICE_ID_ROOT = TYPENAME('R','O','O','T'),
DEVICE_ID_PCI = TYPENAME(' ','P','C','I'),
DEVICE_ID_PNP = TYPENAME(' ','P','N','P'),
DEVICE_ID_I2C = TYPENAME(' ','I','2','C'),
DEVICE_ID_APIC = TYPENAME('A','P','I','C'),
DEVICE_ID_PCI_DOMAIN = TYPENAME('P','C','I','D'),
DEVICE_ID_APIC_CLUSTER = TYPENAME('A','P','C','C'),
DEVICE_ID_CPU = TYPENAME(' ','C','P','U'),
DEVICE_ID_CPU_BUS = TYPENAME(' ','B','U','S'),
DEVICE_ID_NONE = 0,
DEVICE_ID_ROOT = TYPENAME('R', 'O', 'O', 'T'),
DEVICE_ID_PCI = TYPENAME(' ', 'P', 'C', 'I'),
DEVICE_ID_PNP = TYPENAME(' ', 'P', 'N', 'P'),
DEVICE_ID_I2C = TYPENAME(' ', 'I', '2', 'C'),
DEVICE_ID_APIC = TYPENAME('A', 'P', 'I', 'C'),
DEVICE_ID_PCI_DOMAIN = TYPENAME('P', 'C', 'I', 'D'),
DEVICE_ID_APIC_CLUSTER = TYPENAME('A', 'P', 'C', 'C'),
DEVICE_ID_CPU = TYPENAME(' ', 'C', 'P', 'U'),
DEVICE_ID_CPU_BUS = TYPENAME(' ', 'B', 'U', 'S'),
};
struct device;
@ -56,62 +56,52 @@ struct pci_bus_operations;
struct smbus_bus_operations;
struct bus;
struct pci_domain_id
{
struct pci_domain_id {
u16 vendor, device;
};
struct pci_id
{
struct pci_id {
u16 vendor, device;
};
struct pnp_id
{
struct pnp_id {
u32 device;
};
struct i2c_id
{
struct i2c_id {
u32 id;
};
struct apic_id
{
struct apic_id {
u16 vendor, device;
};
struct apic_cluster_id
{
struct apic_cluster_id {
u16 vendor, device;
};
struct cpu_id
{
struct cpu_id {
u8 cpuid[24];
};
struct cpu_bus_id
{
struct cpu_bus_id {
u16 vendor, device;
};
struct device_id {
enum device_id_type type;
union {
struct pci_id pci;
struct pnp_id pnp;
struct i2c_id i2c;
struct apic_id apic;
struct pci_id pci;
struct pnp_id pnp;
struct i2c_id i2c;
struct apic_id apic;
struct pci_domain_id pci_domain;
struct apic_cluster_id apic_cluster;
struct cpu_id cpu;
struct cpu_bus_id cpu_bus;
struct cpu_id cpu;
struct cpu_bus_id cpu_bus;
};
};
struct device_operations {
/* the device id for this set of device operations.
* In almost all cases, this is non-zero. For the
@ -119,8 +109,8 @@ struct device_operations {
*/
struct device_id id;
/* for now, we leave these, since they seem generic */
void (*set_link)(struct device * dev, unsigned int link);
void (*reset_bus)(struct bus *bus);
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.
@ -136,52 +126,51 @@ struct device_operations {
* constructors->constructor(constructors->constructor) and a new
* device is created.
*/
void (*constructor)(struct device *, const struct device_operations *);
void (*constructor) (struct device *, const struct device_operations *);
/* set device ops */
void (*phase1_set_device_operations)(struct device *dev);
void (*phase1_set_device_operations) (struct device * dev);
/* phase 2 is for any magic you have to do before the busses are scanned */
void (*phase2_fixup)(struct device * dev);
void (*phase2_fixup) (struct device * dev);
/* phase 3 is for scanning the bus, if needed. */
void (*phase3_chip_setup_dev)(struct device *dev);
void (*phase3_chip_setup_dev) (struct device * dev);
/* some devices need to be enabled to scan. */
/* this function enables/disables according the value of 'enabled' in the device*/
void (*phase3_enable)(struct device * dev);
unsigned int (*phase3_scan)(struct device * bus, unsigned int max);
/* this function enables/disables based on 'enabled' in the device. */
void (*phase3_enable) (struct device * dev);
unsigned int (*phase3_scan) (struct device * bus, unsigned int max);
/* typically used by phase4 */
/* again, if we never use this anywhere else, we may change the names */
void (*phase4_read_resources)(struct device * dev);
void (*phase4_set_resources)(struct device * dev);
void (*phase4_read_resources) (struct device * dev);
void (*phase4_set_resources) (struct device * dev);
/* phase 5: enable devices */
void (*phase5_enable_resources)(struct device * dev);
void (*phase5_enable_resources) (struct device * dev);
/* phase 6: any post-setup device initialization that might be needed */
void (*phase6_init)(struct device * dev);
void (*phase6_init) (struct device * dev);
const struct pci_operations *ops_pci;
const struct smbus_bus_operations *ops_smbus_bus;
const struct pci_bus_operations *ops_pci_bus;
};
struct bus {
struct device * dev; /* This bridge device */
struct device * children; /* devices behind this bridge */
struct device *dev; /* This bridge device */
struct device *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 secondary; /* secondary bus number */
unsigned char subordinate; /* max subordinate bus number */
unsigned char cap; /* PCi capability offset */
unsigned reset_needed : 1;
unsigned disable_relaxed_ordering : 1;
unsigned char cap; /* PCi capability offset */
unsigned reset_needed:1;
unsigned disable_relaxed_ordering:1;
};
#define MAX_RESOURCES 12
#define MAX_LINKS 8
#define MAX_LINKS 8
#define MAX_DTSNAME_SIZE 64
/*
* There is one device structure for each slot-number/function-number
@ -189,17 +178,17 @@ struct bus {
*/
struct device {
struct bus * bus; /* bus this device is on, for bridge
struct bus *bus; /* bus this device is on, for bridge
* devices, it is the up stream bus */
struct device * sibling; /* next device on this bus */
struct device * next; /* chain of all devices */
struct device *sibling; /* next device on this bus */
struct device *next; /* chain of all devices */
struct device_path path;
/* note there is a device id maintained here. This covers the special case
* of default_device_operations, which has an id of zero.
*/
struct device_id id;
char dtsname[MAX_DTSNAME_SIZE]; /* the name from the dts */
char dtsname[MAX_DTSNAME_SIZE]; /* the name from the dts */
u16 status;
u8 revision;
u8 cache_line;
@ -210,12 +199,12 @@ struct device {
u16 subsystem_vendor;
u16 subsystem_device;
unsigned int class; /* 3 bytes: (base,sub,prog-if) */
unsigned int hdr_type; /* PCI header type */
unsigned int enabled : 1; /* set if we should enable the device */
unsigned int have_resources : 1; /* Set if we have read the devices resources */
unsigned int on_mainboard : 1;
unsigned long rom_address;
unsigned int class; /* 3 bytes: (base,sub,prog-if) */
unsigned int hdr_type; /* PCI header type */
unsigned int enabled:1; /* set if we should enable the device */
unsigned int have_resources:1; /* Set if we have read the devices resources */
unsigned int on_mainboard:1;
unsigned long rom_address;
u8 command;
@ -234,13 +223,13 @@ struct device {
void *device_configuration;
};
extern struct device dev_root; /* root bus */
extern struct device *all_devices; /* list of all devices */
extern struct device dev_root; /* root bus */
extern struct device *all_devices; /* list of all devices */
/* Generic device interface functions */
struct device_operations *find_device_operations(struct device_id *id);
struct device * alloc_dev(struct bus *parent, struct device_path *path, struct device_id *id);
struct device *alloc_dev(struct bus *parent, struct device_path *path,
struct device_id *id);
void dev_enumerate(void);
void dev_configure(void);
void dev_enable(void);
@ -251,34 +240,38 @@ void dev_optimize(void);
int reset_bus(struct bus *bus);
unsigned int scan_bus(struct device *bus, unsigned int max);
void compute_allocate_resource(struct bus *bus, struct resource *bridge,
unsigned long type_mask, unsigned long type);
unsigned long type_mask, unsigned long type);
void assign_resources(struct bus *bus);
void enable_resources(struct device *dev);
void enumerate_static_device(void);
void enumerate_static_devices(void);
const char *dev_path(struct device * dev);
const char *dev_id_string(struct device_id *id);
const char *bus_path(struct bus *bus);
void dev_set_enabled(struct device * dev, int enable);
const char *dev_path(const struct device *dev);
const char *dev_id_string(const struct device_id *id);
const char *bus_path(const struct bus *bus);
void dev_set_enabled(struct device *dev, int enable);
void disable_children(struct bus *bus);
/* Helper functions */
struct device * find_dev_path(struct bus *parent, struct device_path *path);
struct device * alloc_find_dev(struct bus *parent, struct device_path *path, struct device_id *id);
struct device * dev_find_device (struct device_id *devid, struct device * from);
struct device *find_dev_path(const struct bus *parent,
const struct device_path *path);
struct device *alloc_find_dev(struct bus *parent, struct device_path *path,
struct device_id *id);
struct device *dev_find_device(struct device_id *devid, struct device *from);
struct device *dev_find_pci_device(u16 vendor, u16 device, struct device *from);
EXPORT_SYMBOL(dev_find_pci_device);
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_class(unsigned int class, struct device *from);
struct device *dev_find_slot(unsigned int bus, unsigned int devfn);
EXPORT_SYMBOL(dev_find_slot);
struct device * dev_find_slot_on_smbus (unsigned int bus, unsigned int addr);
void default_device_constructor(struct device *dev, const struct device_operations *constructor);
struct device *dev_find_slot_on_smbus(unsigned int bus, unsigned int addr);
void default_device_constructor(struct device *dev,
const struct device_operations *constructor);
void show_all_devs(int debug_level, const char *msg);
void show_all_devs_tree(int debug_level, const char *msg);
/* Rounding for boundaries.
* Due to some chip bugs, go ahead and roung IO to 16
* Due to some chip bugs, go ahead and round IO to 16
*/
#define DEVICE_IO_ALIGN 16
#define DEVICE_IO_ALIGN 16
#define DEVICE_MEM_ALIGN 4096
resource_t align_up(resource_t val, unsigned long gran);
@ -287,24 +280,24 @@ resource_t align_down(resource_t val, unsigned long gran);
extern struct device_operations default_dev_ops_root;
extern int id_eq(struct device_id *id1, struct device_id *id2);
void root_dev_read_resources(struct device * dev);
void root_dev_set_resources(struct device * dev);
unsigned int scan_static_bus(struct device * bus, unsigned int max);
void enable_childrens_resources(struct device * dev);
void root_dev_enable_resources(struct device * dev);
unsigned int root_dev_scan_bus(struct device * root, unsigned int max);
void root_dev_init(struct device * dev);
void root_dev_read_resources(struct device *dev);
void root_dev_set_resources(struct device *dev);
unsigned int scan_static_bus(struct device *bus, unsigned int max);
void enable_childrens_resources(struct device *dev);
void root_dev_enable_resources(struct device *dev);
unsigned int root_dev_scan_bus(struct device *root, unsigned int max);
void root_dev_init(struct device *dev);
void dev_init(void);
void dev_phase1(void);
void dev_phase2(void);
void dev_root_phase3(void);
unsigned int dev_phase3_scan(struct device * busdevice, unsigned int max);
unsigned int dev_phase3_scan(struct device *busdevice, unsigned int max);
void dev_phase4(void);
void dev_root_phase5(void);
void dev_phase6(void);
void phase4_assign_resources(struct bus *bus);
unsigned int dev_phase3(struct device * bus, unsigned int max);
unsigned int dev_phase3(struct device *bus, unsigned int max);
void dev_phase5(struct device *dev);
#endif /* DEVICE_DEVICE_H */
#endif /* DEVICE_DEVICE_H */

View file

@ -22,7 +22,7 @@ enum device_path_type {
DEVICE_PATH_NONE = 0,
DEVICE_PATH_ROOT,
DEVICE_PATH_PCI_DOMAIN,
DEVICE_PATH_PCI_BUS,
DEVICE_PATH_PCI_BUS,
DEVICE_PATH_PCI,
DEVICE_PATH_PNP,
DEVICE_PATH_I2C,
@ -33,60 +33,49 @@ enum device_path_type {
DEVICE_PATH_IOPORT,
};
struct pci_domain_path
{
struct pci_domain_path {
unsigned domain;
};
struct pci_bus_path
{
struct pci_bus_path {
unsigned bus;
};
struct pci_path
{
struct pci_path {
unsigned devfn;
};
struct pnp_path
{
struct pnp_path {
unsigned port;
unsigned device;
};
struct i2c_path
{
struct i2c_path {
unsigned device;
};
struct apic_path
{
struct apic_path {
unsigned apic_id;
unsigned node_id;
unsigned core_id;
};
struct apic_cluster_path
{
struct apic_cluster_path {
unsigned cluster;
};
struct cpu_path
{
struct cpu_path {
unsigned id;
};
struct cpu_bus_path
{
struct cpu_bus_path {
unsigned id;
};
struct ioport_path
{
struct ioport_path {
unsigned iobase;
};
struct device_path {
enum device_path_type type;
union {
@ -103,10 +92,10 @@ struct device_path {
};
};
#define DEVICE_PATH_MAX 30
#define BUS_PATH_MAX (DEVICE_PATH_MAX+10)
extern int path_eq(struct device_path *path1, struct device_path *path2);
extern int path_eq(const struct device_path *path1,
const struct device_path *path2);
#endif /* DEVICE_PATH_H */
#endif /* DEVICE_PATH_H */