- To reduce confuse rename the parts of linuxbios bios that run from
[coreboot.git] / src / devices / root_device.c
1 #include <console/console.h>
2 #include <device/device.h>
3 #include <device/pci.h>
4
5 /** 
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
9  */
10 void root_dev_read_resources(device_t root)
11 {
12         struct resource *resource;
13
14         /* Initialize the system wide io space constraints */
15         resource = new_resource(root, 0);
16         resource->base  = 0x400;
17         resource->size  = 0;
18         resource->align = 0;
19         resource->gran  = 0;
20         resource->limit = 0xffffUL;
21         resource->flags = IORESOURCE_IO;
22         compute_allocate_resource(&root->link[0], resource, 
23                 IORESOURCE_IO, IORESOURCE_IO);
24
25         /* Initialize the system wide memory resources constraints */
26         resource = new_resource(root, 1);
27         resource->base  = 0;
28         resource->size  = 0;
29         resource->align = 0;
30         resource->gran  = 0;
31         resource->limit = 0xffffffffUL;
32         resource->flags = IORESOURCE_MEM;
33         compute_allocate_resource(&root->link[0], resource,
34                 IORESOURCE_MEM, IORESOURCE_MEM);
35 }
36
37 /**
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
41  */
42 void root_dev_set_resources(device_t root)
43 {
44         struct bus *bus;
45
46         bus = &root->link[0];
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);
52 }
53
54 /**
55  * @brief Scan devices on static buses.
56  *
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.
63  *
64  * This function is the default scan_bus() method for LPC bridges.
65  *
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.
69  */
70 unsigned int scan_static_bus(device_t bus, unsigned int max)
71 {
72         device_t child;
73         unsigned link;
74         
75         printk_spew("%s for %s\n", __func__, dev_path(bus));
76
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);
81                         }
82                         if (child->ops && child->ops->enable) {
83                                 child->ops->enable(child);
84                         }
85                         printk_debug("%s %s\n",
86                                 dev_path(child),
87                                 child->enabled?"enabled": "disabled");
88                 }
89         }
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)
93                                 continue;
94                         printk_spew("%s scanning...\n", dev_path(child));
95                         max = child->ops->scan_bus(child, max);
96                 }
97         }
98
99         printk_spew("%s done\n", __func__);
100
101         return max;
102 }
103
104 /**
105  * @brief Enable resources for children devices
106  *
107  * @param dev the device whos children's resources are to be enabled
108  *
109  * This function is call by the enable_resource() indirectly via the
110  * enable_resources() method of devices.
111  *
112  * Indirect mutual recursion:
113  */
114 void enable_childrens_resources(device_t dev)
115 {
116         unsigned link;
117         for(link = 0; link < dev->links; link++) {
118                 device_t child;
119                 for(child = dev->link[link].children; child; child = child->sibling) {
120                         enable_resources(child);
121                 }
122         }
123 }
124
125 void root_dev_enable_resources(device_t dev)
126 {
127         enable_childrens_resources(dev);
128 }
129
130 /**
131  * @brief Scan root bus for generic systems
132  *
133  * @param root The root device structure
134  * @param max The current bus number scanned so fat, usually 0x00
135  *
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
139  * buses from there. 
140  */
141 unsigned int root_dev_scan_bus(device_t root, unsigned int max)
142 {
143         return scan_static_bus(root, max);
144 }
145
146 void root_dev_init(device_t root)
147 {
148 }
149
150 /**
151  * @brief Default device operation for root device
152  *
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.
158  */
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,
165 };
166
167 /**
168  * @brief The root of dynamic device tree.
169  *
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. 
172  */
173 extern struct device dev_root;