5 #include <device/resource.h>
6 #include <device/path.h>
10 typedef struct device * device_t;
11 struct pci_operations;
12 struct pci_bus_operations;
13 struct smbus_bus_operations;
16 struct chip_operations {
17 void (*enable_dev)(struct device *dev);
18 #if CONFIG_CHIP_NAME == 1
23 #if CONFIG_CHIP_NAME == 1
24 #define CHIP_NAME(X) .name = X,
31 struct device_operations {
32 void (*read_resources)(device_t dev);
33 void (*set_resources)(device_t dev);
34 void (*enable_resources)(device_t dev);
35 void (*init)(device_t dev);
36 unsigned int (*scan_bus)(device_t bus, unsigned int max);
37 void (*enable)(device_t dev);
38 void (*set_link)(device_t dev, unsigned int link);
39 void (*reset_bus)(struct bus *bus);
40 const struct pci_operations *ops_pci;
41 const struct smbus_bus_operations *ops_smbus_bus;
42 const struct pci_bus_operations *ops_pci_bus;
47 device_t dev; /* This bridge device */
48 device_t children; /* devices behind this bridge */
49 unsigned bridge_ctrl; /* Bridge control register */
50 unsigned char link; /* The index of this link */
51 uint16_t secondary; /* secondary bus number */
52 uint16_t subordinate; /* max subordinate bus number */
53 unsigned char cap; /* PCi capability offset */
54 unsigned reset_needed : 1;
55 unsigned disable_relaxed_ordering : 1;
58 #define MAX_RESOURCES 12
61 * There is one device structure for each slot-number/function-number
66 struct bus * bus; /* bus this device is on, for bridge
67 * devices, it is the up stream bus */
68 device_t sibling; /* next device on this bus */
69 device_t next; /* chain of all devices */
71 struct device_path path;
74 unsigned int class; /* 3 bytes: (base,sub,prog-if) */
75 unsigned int hdr_type; /* PCI header type */
76 unsigned int enabled : 1; /* set if we should enable the device */
77 unsigned int initialized : 1; /* set if we have initialized the device */
78 unsigned int have_resources : 1; /* Set if we have read the devices resources */
79 unsigned int on_mainboard : 1;
80 unsigned long rom_address;
84 /* Base registers for this device. I/O, MEM and Expansion ROM */
85 struct resource resource[MAX_RESOURCES];
86 unsigned int resources;
88 /* link are (down sream) buses attached to the device, usually a leaf
89 * device with no children have 0 buses attached and a bridge has 1 bus
91 struct bus link[MAX_LINKS];
92 /* number of buses attached to the device */
95 struct device_operations *ops;
96 struct chip_operations *chip_ops;
100 extern struct device dev_root; /* root bus */
101 extern struct device *all_devices; /* list of all devices */
104 /* Generic device interface functions */
105 extern device_t alloc_dev(struct bus *parent, struct device_path *path);
106 extern void dev_enumerate(void);
107 extern void dev_configure(void);
108 extern void dev_enable(void);
109 extern void dev_initialize(void);
110 extern void dev_optimize(void);
112 /* Generic device helper functions */
113 extern int reset_bus(struct bus *bus);
114 extern unsigned int scan_bus(struct device *bus, unsigned int max);
115 extern void compute_allocate_resource(struct bus *bus, struct resource *bridge,
116 unsigned long type_mask, unsigned long type);
117 extern void assign_resources(struct bus *bus);
118 extern void enable_resources(struct device *dev);
119 extern void enumerate_static_device(void);
120 extern void enumerate_static_devices(void);
121 extern const char *dev_path(device_t dev);
122 const char *bus_path(struct bus *bus);
123 extern void dev_set_enabled(device_t dev, int enable);
124 extern void disable_children(struct bus *bus);
126 /* Helper functions */
127 device_t find_dev_path(struct bus *parent, struct device_path *path);
128 device_t alloc_find_dev(struct bus *parent, struct device_path *path);
129 device_t dev_find_device (unsigned int vendor, unsigned int device, device_t from);
130 device_t dev_find_class (unsigned int class, device_t from);
131 device_t dev_find_slot (unsigned int bus, unsigned int devfn);
132 device_t dev_find_slot_on_smbus (unsigned int bus, unsigned int addr);
135 /* Rounding for boundaries.
136 * Due to some chip bugs, go ahead and roung IO to 16
138 #define DEVICE_IO_ALIGN 16
139 #define DEVICE_MEM_ALIGN 4096
141 struct device_operations default_dev_ops_root;
142 extern void root_dev_read_resources(device_t dev);
143 extern void root_dev_set_resources(device_t dev);
144 extern unsigned int scan_static_bus(device_t bus, unsigned int max);
145 extern void enable_childrens_resources(device_t dev);
146 extern void root_dev_enable_resources(device_t dev);
147 extern unsigned int root_dev_scan_bus(device_t root, unsigned int max);
148 extern void root_dev_init(device_t dev);
149 #endif /* DEVICE_H */