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 * @brief Write the resources for the root device
40 * and every device under it which are all of the devices.
41 * @param root Pointer to the device structure for the system root device
43 void root_dev_set_resources(device_t root)
48 compute_allocate_resource(bus, &root->resource[0],
49 IORESOURCE_IO, IORESOURCE_IO);
50 compute_allocate_resource(bus, &root->resource[1],
51 IORESOURCE_MEM, IORESOURCE_MEM);
52 assign_resources(bus);
56 * @brief Scan devices on static buses.
58 * The enumeration of certain buses is purely static. The existence of
59 * devices on those buses can be completely determined at compile time
60 * and is specified in the config file. Typical exapmles are the 'PNP'
61 * devices on a legacy ISA/LPC bus. There is no need of probing of any
62 * kind, the only thing we have to do is to walk through the bus and
63 * enable or disable devices as indicated in the config file.
65 * On the other hand, some devices are virtual and their existence is
66 * artificial. They can not be probed at run time. One example is the
67 * debug device. Those virtual devices have to be listed in the config
68 * file under some static bus in order to be enumerated at run time.
70 * This function is the default scan_bus() method for the root device and
73 * @param root Pointer to the root device which the static buses are attached
74 * @param max Maximum bus number currently used before scanning.
75 * @return Largest bus number used after scanning.
77 unsigned int scan_static_bus(device_t root, unsigned int max)
82 printk_spew("%s for %s\n", __func__, dev_path(root));
84 for (link = 0; link < root->links; link++) {
85 for (child = root->link[link].children; child; child = child->sibling) {
86 if (child->chip_ops && child->chip_ops->enable_dev) {
87 child->chip_ops->enable_dev(child);
89 if (child->ops && child->ops->enable) {
90 child->ops->enable(child);
92 printk_debug("%s %s\n", dev_path(child),
93 child->enabled?"enabled": "disabled");
96 for (link = 0; link < root->links; link++) {
97 for (child = root->link[link].children; child; child = child->sibling) {
98 if (!child->ops || !child->ops->scan_bus)
100 printk_spew("%s scanning...\n", dev_path(child));
101 max = child->ops->scan_bus(child, max);
105 printk_spew("%s for %s done\n", __func__, dev_path(root));
111 * @brief Enable resources for children devices
113 * @param dev the device whos children's resources are to be enabled
115 * This function is call by the global enable_resources() indirectly via the
116 * device_operation::enable_resources() method of devices.
118 * Indirect mutual recursion:
119 * enable_childrens_resources() -> enable_resources()
120 * enable_resources() -> device_operation::enable_resources()
121 * device_operation::enable_resources() -> enable_children_resources()
123 void enable_childrens_resources(device_t dev)
126 for (link = 0; link < dev->links; link++) {
128 for (child = dev->link[link].children; child; child = child->sibling) {
129 enable_resources(child);
134 void root_dev_enable_resources(device_t dev)
136 enable_childrens_resources(dev);
140 * @brief Scan root bus for generic systems
142 * @param root The root device structure
143 * @param max The current bus number scanned so far, usually 0x00
145 * This function is the default scan_bus() method of the root device.
147 unsigned int root_dev_scan_bus(device_t root, unsigned int max)
149 return scan_static_bus(root, max);
152 void root_dev_init(device_t root)
157 * @brief Default device operation for root device
159 * This is the default device operation for root devices. These operations
160 * should be fully usable as is. However the chip_operations::enable_dev()
161 * of a motherboard can override this if you want non-default behavior.
163 struct device_operations default_dev_ops_root = {
164 .read_resources = root_dev_read_resources,
165 .set_resources = root_dev_set_resources,
166 .enable_resources = root_dev_enable_resources,
167 .init = root_dev_init,
168 .scan_bus = root_dev_scan_bus,
172 * @brief The root of device tree.
174 * This is the root of the device tree. The device tree is defined in the
175 * static.c file and is generated by config tool during compile time.
177 extern struct device dev_root;