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 encompase 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)
14 printk_spew("%s . Root is %p\n", __FUNCTION__, root);
15 /* Initialize the system wide io space constraints */
16 root->resource[res].base = 0x400;
17 root->resource[res].size = 0;
18 root->resource[res].align = 0;
19 root->resource[res].gran = 0;
20 root->resource[res].limit = 0xffffUL;
21 root->resource[res].flags = IORESOURCE_IO;
22 root->resource[res].index = 0;
23 printk_spew("%s . link %p, resource %p\n", __FUNCTION__,
24 &root->link[0], &root->resource[res]);
25 compute_allocate_resource(&root->link[0], &root->resource[res],
26 IORESOURCE_IO, IORESOURCE_IO);
29 /* Initialize the system wide memory resources constraints */
30 root->resource[res].base = 0;
31 root->resource[res].size = 0;
32 root->resource[res].align = 0;
33 root->resource[res].gran = 0;
34 root->resource[res].limit = 0xffffffffUL;
35 root->resource[res].flags = IORESOURCE_MEM;
36 root->resource[res].index = 1;
37 printk_spew("%s . link %p, resource %p\n", __FUNCTION__,
38 &root->link[0], &root->resource[res]);
39 compute_allocate_resource(&root->link[0], &root->resource[res],
40 IORESOURCE_MEM, IORESOURCE_MEM);
43 root->resources = res;
44 printk_spew("%s DONE\n", __FUNCTION__);
48 * Write the resources for the root device,
49 * and every device under it which are all of the devices.
50 * @param root Pointer to the device structure for the system root device
52 void root_dev_set_resources(device_t root)
56 compute_allocate_resource(bus,
57 &root->resource[0], IORESOURCE_IO, IORESOURCE_IO);
58 compute_allocate_resource(bus,
59 &root->resource[1], IORESOURCE_MEM, IORESOURCE_MEM);
60 assign_resources(bus);
64 * Walk through devices on the motherboard and scan for devices behind
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 walk_static_devices(device_t bus, unsigned int max)
74 for(link = 0; link < bus->links; link++) {
75 for(child = bus->link[link].children; child; child = child->sibling) {
76 if (child->ops && child->ops->enable) {
77 child->ops->enable(child);
79 printk_debug("%s %s\n",
81 child->enable?"enabled": "disabled");
84 for(link = 0; link < bus->links; link++) {
85 for(child = bus->link[link].children; child; child = child->sibling) {
86 if (!child->ops || !child->ops->scan_bus)
88 printk_debug("%s scanning...\n", dev_path(child));
89 max = child->ops->scan_bus(child, max);
95 void enable_childrens_resources(device_t dev)
98 for(link = 0; link < dev->links; link++) {
100 for(child = dev->link[link].children; child; child = child->sibling) {
101 enable_resources(child);
106 unsigned int root_dev_scan_pci_bus(device_t root, unsigned int max)
108 return pci_scan_bus(&root->link[0], 0, 0xff, max);
111 struct device_operations default_dev_ops_root = {
112 .read_resources = root_dev_read_resources,
113 .set_resources = root_dev_set_resources,
114 .enable_resources = enable_childrens_resources,
116 .scan_bus = root_dev_scan_pci_bus,
120 * This is the root of the device tree. A PCI tree always has
121 * one bus, bus 0. Bus 0 contains devices and bridges.
123 struct device dev_root = {
124 .ops = &default_dev_ops_root,
125 .bus = &dev_root.link[0],