1 /* chips are arbitrary chips (superio, southbridge, etc.)
2 * They have private structures that define chip resources and default
3 * settings. They have four externally visible functions for control.
4 * They have a generic component which applies to all chips for
8 #include <console/console.h>
9 #include <device/chip.h>
10 #include <device/pci.h>
13 * @brief Configure static devices
15 * Starting from the static device 'root', walk the tree and configure each
16 * device by calling the device specific chip_control::enable().
18 * This function is only an iterator, the exact definition of 'configure'
19 * depends on the device specific implementation of chip_control::enable().
21 * @param root root of the static device tree to be configured.
22 * @param pass pass of the configuration operation to be perfromed.
25 * @see chip_control::enable
27 void chip_configure(struct chip *root, enum chip_pass pass)
31 for (c = root; c; c = c->next) {
32 if (c->control && c->control->enable)
33 c->control->enable(c, pass);
36 for (c = root; c; c = c->next) {
38 chip_configure(c->children, pass);
43 * @brief Convert static device structures to dynamic structures.
45 * A static device may contain one or more dynamic devices. Dynamic device
46 * structures of these devices have to be generated before the enumeration
47 * of dynamic devices. This function converts a static chip structure to a
48 * set of dynamic device structures.
50 * This function is the generic method called by enumerate_static_device_chain()
51 * for static devices. Devices extend this default behavior by defining their
52 * own chip_controll::enumerate(). Generally, device specific
53 * chip_control::enumerate() method calls this function as its last operation.
55 * @param chip static chip structure to be converted.
58 void chip_enumerate(struct chip *chip)
68 if (chip->control && chip->control->name) {
69 printk_debug("Enumerating: %s\n", chip->control->name);
72 for (i = 0; i < MAX_CHIP_PATHS; i++) {
76 (path_eq(&chip->path[i - 1].path, &chip->path[i].path));
77 if (!identical_paths) {
83 switch(chip->path[i].path.type) {
84 case DEVICE_PATH_NONE:
85 /* no dynamic device associated */
88 bus = chip->path[i].path.u.pci.bus;
93 while (dev && (i != bus)) {
97 if ((i == bus) && dev) {
98 parent = &dev->link[0];
103 dev = alloc_dev(parent, &chip->path[i].path);
111 struct chip_resource *res, *res_limit;
112 printk_spew("path (%p) %s %s",
114 identical_paths?"identical":"");
115 printk_spew(" parent: (%p) %s\n",
116 dev->bus->dev, dev_path(dev->bus->dev));
118 dev->enabled = chip->path[i].enable;
119 dev->links = link + 1;
120 for (child = chip->children; child; child = child->next) {
121 if (!child->bus && child->link == i) {
122 child->bus = &dev->link[link];
125 res = &chip->path[i].resource[0];
126 res_limit = &chip->path[i].resource[MAX_RESOURCES];
127 for(; res < res_limit; res++) {
129 struct resource *resource;
130 resource = get_resource(dev, res->index);
131 resource->flags = res->flags | IORESOURCE_FIXED | IORESOURCE_ASSIGNED;
132 resource->base = res->base;
137 if (dev && !chip->dev) {
142 for (child = chip->children; child; child = child->next) {
144 child->bus = &chip->dev->link[0];
150 * @brief Enumerate a static device tree.
152 * A static device chain is a linked list of static device structures which are
153 * on the same branch of the static device tree. This function does not only
154 * enumerate the devices on a single chain, as its name suggest, it also walks
155 * into the subordinary chains by recursion. It calls the device specific
156 * chip_control::enumerate() of the device if one exists or calls the generic
159 * This function is only an iterator, the exact definition of 'enumerate'
160 * depends on the implementation of the generic chip_enumerate() and/or device
161 * specific chip_control::enumerate().
163 * @param root static chip structure to start with.
165 * @see chip_control::enumerate()
167 static void enumerate_static_device_chain(struct chip *root)
171 for (chip = root; chip; chip = chip->next) {
172 void (*enumerate)(struct chip *chip);
173 enumerate = chip_enumerate;
174 if (chip->control && chip->control->enumerate) {
175 enumerate = chip->control->enumerate;
180 for (chip = root; chip; chip = chip->next) {
181 if (chip->children) {
182 enumerate_static_device_chain(chip->children);
188 * @brief Enumerate static devices in the system.
190 * Static device is . Static devices are actually enumerated or "listed" in
191 * the Config.lb config file and the corresponding data structures are
192 * generated by config tool in the static.c.
194 * \note The definition of 'enumerate' is not clear in this context. Does it
197 * \note How do we determine the existence of the static devices ? Static
198 * devices are listed in the config file and generated at compile time by config
199 * tool. This function is called at certain point in the early stage of
200 * LinuxBIOS. It uses the chip_enumerate() function to convert the static
201 * structures into dynamic ones. What if the static devices listed in the config
202 * file does actually not exist in the system ? Is there any side effect of
203 * these 'phantom' device structures
205 * The static device does not necesarry conform to the dynamic device tree in
208 void enumerate_static_devices(void)
210 printk_info("Enumerating static devices...\n");
211 enumerate_static_device_chain(&static_root);