1 #include <console/console.h>
2 #include <device/device.h>
3 #include <device/pci.h>
4 #include <part/hard_reset.h>
7 * Read the resources for the root device,
8 * that encompass the resources for the entire system.
9 * @param root Pointer to the device structure for the system root device
11 void root_dev_read_resources(device_t root)
13 struct resource *resource;
15 /* Initialize the system wide io space constraints */
16 resource = new_resource(root, 0);
17 resource->base = 0x400;
21 resource->limit = 0xffffUL;
22 resource->flags = IORESOURCE_IO;
23 compute_allocate_resource(&root->link[0], resource,
24 IORESOURCE_IO, IORESOURCE_IO);
26 /* Initialize the system wide memory resources constraints */
27 resource = new_resource(root, 1);
32 resource->limit = 0xffffffffUL;
33 resource->flags = IORESOURCE_MEM;
34 compute_allocate_resource(&root->link[0], resource,
35 IORESOURCE_MEM, IORESOURCE_MEM);
39 * @brief Write the resources for every device
41 * Write the resources for the root device,
42 * and every device under it which are all of the devices.
43 * @param root Pointer to the device structure for the system root device
45 void root_dev_set_resources(device_t root)
50 compute_allocate_resource(bus,
51 &root->resource[0], IORESOURCE_IO, IORESOURCE_IO);
52 compute_allocate_resource(bus,
53 &root->resource[1], IORESOURCE_MEM, IORESOURCE_MEM);
54 assign_resources(bus);
58 * @brief Scan devices on static buses.
60 * The enumeration of certain buses is purely static. The existence of
61 * devices on those buses can be completely determined at compile time
62 * and is specified in the config file. Typical examples are the 'PNP'
63 * devices on a legacy ISA/LPC bus. There is no need of probing of any kind,
64 * the only thing we have to do is to walk through the bus and
65 * enable or disable devices as indicated in the config file.
67 * On the other hand, some devices are virtual and their existence is
68 * artificial. They can not be probed at run time. One example is the
69 * debug device. Those virtual devices have to be listed in the config
70 * file under some static bus in order to be enumerated at run time.
72 * This function is the default scan_bus() method for the root device and
75 * @param bus Pointer to the device structure which the static buses are attached
76 * @param max Maximum bus number currently used before scanning.
77 * @return Largest bus number used.
79 static int smbus_max = 0;
80 unsigned int scan_static_bus(device_t bus, unsigned int max)
85 printk_spew("%s for %s\n", __func__, dev_path(bus));
87 for(link = 0; link < bus->links; link++) {
88 /* for smbus bus enumerate */
89 child = bus->link[link].children;
90 if(child && child->path.type == DEVICE_PATH_I2C) {
91 bus->link[link].secondary = ++smbus_max;
93 for(child = bus->link[link].children; child; child = child->sibling) {
94 if (child->chip_ops && child->chip_ops->enable_dev) {
95 child->chip_ops->enable_dev(child);
97 if (child->ops && child->ops->enable) {
98 child->ops->enable(child);
100 if (child->path.type == DEVICE_PATH_I2C) {
101 printk_debug("smbus: %s[%d]->",
102 dev_path(child->bus->dev), child->bus->link );
104 printk_debug("%s %s\n",
106 child->enabled?"enabled": "disabled");
109 for(link = 0; link < bus->links; link++) {
110 for(child = bus->link[link].children; child; child = child->sibling) {
111 if (!child->ops || !child->ops->scan_bus)
113 printk_spew("%s scanning...\n", dev_path(child));
114 max = scan_bus(child, max);
118 printk_spew("%s for %s done\n", __func__, dev_path(bus));
124 * @brief Enable resources for children devices
126 * @param dev the device whos children's resources are to be enabled
128 * This function is called by the global enable_resource() indirectly via the
129 * device_operation::enable_resources() method of devices.
131 * Indirect mutual recursion:
132 * enable_childrens_resources() -> enable_resources()
133 * enable_resources() -> device_operation::enable_resources()
134 * device_operation::enable_resources() -> enable_children_resources()
136 void enable_childrens_resources(device_t dev)
139 for(link = 0; link < dev->links; link++) {
141 for(child = dev->link[link].children; child; child = child->sibling) {
142 enable_resources(child);
147 void root_dev_enable_resources(device_t dev)
149 enable_childrens_resources(dev);
153 * @brief Scan root bus for generic systems
155 * @param root The root device structure
156 * @param max The current bus number scanned so far, usually 0x00
158 * This function is the default scan_bus() method of the root device.
160 unsigned int root_dev_scan_bus(device_t root, unsigned int max)
162 return scan_static_bus(root, max);
165 void root_dev_init(device_t root)
169 void root_dev_reset(struct bus *bus)
171 printk_info("Reseting board...\n");
176 * @brief Default device operation for root device
178 * This is the default device operation for root devices. These operations
179 * should be fully usable as is. However the chip_operations::enable_dev()
180 * of a motherboard can override this if you want non-default behavior.
182 struct device_operations default_dev_ops_root = {
183 .read_resources = root_dev_read_resources,
184 .set_resources = root_dev_set_resources,
185 .enable_resources = root_dev_enable_resources,
186 .init = root_dev_init,
187 .scan_bus = root_dev_scan_bus,
188 .reset_bus = root_dev_reset,
192 * @brief The root of device tree.
194 * This is the root of the device tree. The device tree is defined in the
195 * static.c file and is generated by config tool during compile time.
197 extern struct device dev_root;