1 #include <console/console.h>
2 #include <device/device.h>
3 #include <device/pci.h>
6 * Read the resources for the root device,
7 * that encompass the resources for the entire system.
8 * @param root Pointer to the device structure for the system root device
10 void root_dev_read_resources(device_t root)
12 struct resource *resource;
14 /* Initialize the system wide io space constraints */
15 resource = new_resource(root, 0);
16 resource->base = 0x400;
20 resource->limit = 0xffffUL;
21 resource->flags = IORESOURCE_IO;
22 compute_allocate_resource(&root->link[0], resource,
23 IORESOURCE_IO, IORESOURCE_IO);
25 /* Initialize the system wide memory resources constraints */
26 resource = new_resource(root, 1);
31 resource->limit = 0xffffffffUL;
32 resource->flags = IORESOURCE_MEM;
33 compute_allocate_resource(&root->link[0], resource,
34 IORESOURCE_MEM, IORESOURCE_MEM);
38 * Write the resources for the root device,
39 * and every device under it which are all of the devices.
40 * @param root Pointer to the device structure for the system root device
42 void root_dev_set_resources(device_t root)
47 compute_allocate_resource(bus,
48 &root->resource[0], IORESOURCE_IO, IORESOURCE_IO);
49 compute_allocate_resource(bus,
50 &root->resource[1], IORESOURCE_MEM, IORESOURCE_MEM);
51 assign_resources(bus);
55 * @brief Scan devices on static buses.
57 * The enumeration of certain buses is purely static. The existence of
58 * devices on those buses can be completely determined at compile time
59 * by the config file. Typical expamles are the 'PNP' devices on a legacy
60 * ISA/LPC bus. There is no need of probing of any kind, the only thing
61 * we have to do is to walk through the bus and enable or disable devices
62 * as indicated in the config file.
64 * This function is the default scan_bus() method for LPC bridges.
66 * @param root Pointer to the device structure for the system root device
67 * @param max Maximum bus number allowed in the system.
68 * @return Largest bus number used.
70 unsigned int scan_static_bus(device_t bus, unsigned int max)
75 printk_spew("%s for %s\n", __func__, dev_path(bus));
77 for(link = 0; link < bus->links; link++) {
78 for(child = bus->link[link].children; child; child = child->sibling) {
79 if (child->chip_ops && child->chip_ops->enable_dev) {
80 child->chip_ops->enable_dev(child);
82 if (child->ops && child->ops->enable) {
83 child->ops->enable(child);
85 printk_debug("%s %s\n",
87 child->enabled?"enabled": "disabled");
90 for(link = 0; link < bus->links; link++) {
91 for(child = bus->link[link].children; child; child = child->sibling) {
92 if (!child->ops || !child->ops->scan_bus)
94 printk_spew("%s scanning...\n", dev_path(child));
95 max = child->ops->scan_bus(child, max);
99 printk_spew("%s done\n", __func__);
105 * @brief Enable resources for children devices
107 * @param dev the device whos children's resources are to be enabled
109 * This function is call by the enable_resource() indirectly via the
110 * enable_resources() method of devices.
112 * Indirect mutual recursion:
114 void enable_childrens_resources(device_t dev)
117 for(link = 0; link < dev->links; link++) {
119 for(child = dev->link[link].children; child; child = child->sibling) {
120 enable_resources(child);
125 void root_dev_enable_resources(device_t dev)
127 enable_childrens_resources(dev);
131 * @brief Scan root bus for generic systems
133 * @param root The root device structure
134 * @param max The current bus number scanned so fat, usually 0x00
136 * This function is the default scan_bus() method of the dynamic root device.
137 * The bus heirachy is rooted at the host/northbridge. The northbridge of a
138 * generic PCI bus system is at Bus 0, Dev 0, Fun 0 so we scan the whole PCI
141 unsigned int root_dev_scan_bus(device_t root, unsigned int max)
143 return scan_static_bus(root, max);
146 void root_dev_init(device_t root)
151 * @brief Default device operation for root device
153 * This is the default device operation for root devices in PCI based systems.
154 * These operations should be fully usable as is. However the
155 * chip_operations::dev_enable of a motherboard can override this if you
156 * want non-default behavior. Currently src/mainboard/arima/hdama/mainbaord.c
157 * does this for debugging purposes.
159 struct device_operations default_dev_ops_root = {
160 .read_resources = root_dev_read_resources,
161 .set_resources = root_dev_set_resources,
162 .enable_resources = root_dev_enable_resources,
163 .init = root_dev_init,
164 .scan_bus = root_dev_scan_bus,
168 * @brief The root of dynamic device tree.
170 * This is the root of the dynamic device tree. A PCI tree always has
171 * one bus, bus 0. Bus 0 contains devices and bridges.
173 extern struct device dev_root;