diff options
Diffstat (limited to 'util/sconfig/main.c')
-rw-r--r-- | util/sconfig/main.c | 135 |
1 files changed, 40 insertions, 95 deletions
diff --git a/util/sconfig/main.c b/util/sconfig/main.c index dd26e07de8..533c9fbb18 100644 --- a/util/sconfig/main.c +++ b/util/sconfig/main.c @@ -81,7 +81,6 @@ static struct device override_root_dev; static struct chip_instance mainboard_instance; static struct bus base_root_bus = { - .id = 0, .dev = &base_root_dev, }; @@ -95,7 +94,6 @@ static struct device base_root_dev = { }; static struct bus chipset_root_bus = { - .id = 0, .dev = &chipset_root_dev, }; @@ -109,7 +107,6 @@ static struct device chipset_root_dev = { }; static struct bus override_root_bus = { - .id = 0, .dev = &override_root_dev, }; @@ -723,30 +720,13 @@ void add_device_ops(struct bus *bus, char *ops_id) bus->dev->ops_id = ops_id; } -/* - * Allocate a new bus for the provided device. - * - If this is the first bus being allocated under this device, then its id - * is set to 0 and bus and last_bus are pointed to the newly allocated bus. - * - If this is not the first bus under this device, then its id is set to 1 - * plus the id of last bus and newly allocated bus is added to the list of - * buses under the device. last_bus is updated to point to the newly - * allocated bus. - */ +/* Allocate a new bus for the provided device. */ static void alloc_bus(struct device *dev) { struct bus *bus = S_ALLOC(sizeof(*bus)); bus->dev = dev; - - if (dev->last_bus == NULL) { - bus->id = 0; - dev->bus = bus; - } else { - bus->id = dev->last_bus->id + 1; - dev->last_bus->next_bus = bus; - } - - dev->last_bus = bus; + dev->bus = bus; } /* @@ -814,14 +794,15 @@ static const struct device *find_alias(const struct device *const parent, if (parent->alias && !strcmp(parent->alias, alias)) return parent; - const struct bus *bus; - for (bus = parent->bus; bus; bus = bus->next_bus) { - const struct device *child; - for (child = bus->children; child; child = child->sibling) { - const struct device *const ret = find_alias(child, alias); - if (ret) - return ret; - } + const struct bus *bus = parent->bus; + if (!bus) + return NULL; + + const struct device *child; + for (child = bus->children; child; child = child->sibling) { + const struct device *const ret = find_alias(child, alias); + if (ret) + return ret; } return NULL; @@ -834,11 +815,11 @@ static struct device *new_device_with_path(struct bus *parent, { struct device *new_d; - /* If device is found under parent, no need to allocate new device. */ + /* We don't allow duplicate devices in devicetree. */ new_d = get_dev(parent, path_a, path_b, bustype, chip_instance); if (new_d) { - alloc_bus(new_d); - return new_d; + printf("ERROR: Duplicate device! %s\n", new_d->name); + exit(1); } new_d = alloc_dev(parent); @@ -1084,11 +1065,8 @@ static int dev_has_children(struct device *dev) { struct bus *bus = dev->bus; - while (bus) { - if (bus->children) - return 1; - bus = bus->next_bus; - } + if (bus && bus->children) + return 1; return 0; } @@ -1098,7 +1076,7 @@ static void pass0(FILE *fil, FILE *head, struct device *ptr, struct device *next static int dev_id; if (ptr == &base_root_dev) { - fprintf(fil, "STORAGE struct bus %s_links[];\n", + fprintf(fil, "STORAGE struct bus %s_bus;\n", ptr->name); return; } @@ -1120,7 +1098,7 @@ static void pass0(FILE *fil, FILE *head, struct device *ptr, struct device *next fprintf(fil, "STORAGE struct resource %s_res[];\n", ptr->name); if (dev_has_children(ptr)) - fprintf(fil, "STORAGE struct bus %s_links[];\n", + fprintf(fil, "STORAGE struct bus %s_bus;\n", ptr->name); if (next) @@ -1192,35 +1170,18 @@ static void emit_resources(FILE *fil, struct device *ptr) fprintf(fil, "\t };\n"); } -static void emit_bus(FILE *fil, struct bus *bus) +static void emit_dev_bus(FILE *fil, struct device *ptr) { - fprintf(fil, "\t\t[%d] = {\n", bus->id); - fprintf(fil, "\t\t\t.link_num = %d,\n", bus->id); - fprintf(fil, "\t\t\t.dev = &%s,\n", bus->dev->name); - if (bus->children) - fprintf(fil, "\t\t\t.children = &%s,\n", bus->children->name); - - if (bus->next_bus) - fprintf(fil, "\t\t\t.next=&%s_links[%d],\n", bus->dev->name, - bus->id + 1); - else - fprintf(fil, "\t\t\t.next = NULL,\n"); - fprintf(fil, "\t\t},\n"); -} - -static void emit_dev_links(FILE *fil, struct device *ptr) -{ - fprintf(fil, "STORAGE struct bus %s_links[] = {\n", + fprintf(fil, "STORAGE struct bus %s_bus = {\n", ptr->name); + assert(ptr->bus && ptr->bus->children); struct bus *bus = ptr->bus; - while (bus) { - emit_bus(fil, bus); - bus = bus->next_bus; - } + fprintf(fil, "\t.dev = &%s,\n", bus->dev->name); + fprintf(fil, "\t.children = &%s,\n", bus->children->name); - fprintf(fil, "\t};\n"); + fprintf(fil, "};\n"); } static struct chip_instance *get_chip_instance(const struct device *dev) @@ -1268,8 +1229,7 @@ static void pass1(FILE *fil, FILE *head, struct device *ptr, struct device *next else fprintf(fil, "\t.ops = NULL,\n"); fprintf(fil, "#endif\n"); - fprintf(fil, "\t.bus = &%s_links[%d],\n", ptr->parent->dev->name, - ptr->parent->id); + fprintf(fil, "\t.bus = &%s_bus,\n", ptr->parent->dev->name); fprintf(fil, "\t.path = {"); fprintf(fil, ptr->path, ptr->path_a, ptr->path_b); fprintf(fil, "},\n"); @@ -1290,7 +1250,7 @@ static void pass1(FILE *fil, FILE *head, struct device *ptr, struct device *next ptr->name); } if (has_children) - fprintf(fil, "\t.link_list = &%s_links[0],\n", + fprintf(fil, "\t.link_list = &%s_bus,\n", ptr->name); else fprintf(fil, "\t.link_list = NULL,\n"); @@ -1319,7 +1279,7 @@ static void pass1(FILE *fil, FILE *head, struct device *ptr, struct device *next emit_resources(fil, ptr); if (has_children) - emit_dev_links(fil, ptr); + emit_dev_bus(fil, ptr); } static void expose_device_names(FILE *fil, FILE *head, struct device *ptr, struct device *next) @@ -1370,11 +1330,8 @@ static void add_children_to_queue(struct queue_entry **bfs_q_head, { struct bus *bus = d->bus; - while (bus) { - if (bus->children) - add_siblings_to_queue(bfs_q_head, bus->children); - bus = bus->next_bus; - } + if (dev_has_children(d)) + add_siblings_to_queue(bfs_q_head, bus->children); } static void walk_device_tree(FILE *fil, FILE *head, struct device *ptr, @@ -1724,12 +1681,9 @@ static void override_devicetree(struct bus *base_parent, * +-----------------------------------------------------------------+ * | | | * | bus | Recursively call override_devicetree on | - * | last_bus | each bus of override device. It is assumed | + * | | each bus of override device. It is assumed | * | | that bus with id X under base device | - * | | to bus with id X under override device. If | - * | | override device has more buses than base | - * | | device, then new buses are allocated under | - * | | base device. | + * | | to bus with id X under override device. | * | | | * +-----------------------------------------------------------------+ */ @@ -1841,29 +1795,20 @@ static void update_device(struct device *base_dev, struct device *override_dev) /* * Now that the device properties are all copied over, look at each bus * of the override device and run override_devicetree in a recursive - * manner. The assumption here is that first bus of override device - * corresponds to first bus of base device and so on. If base device has - * lesser buses than override tree, then new buses are allocated for it. + * manner. If base device has no bus but the override tree has, then a new + * bus is allocated for it. */ struct bus *override_bus = override_dev->bus; struct bus *base_bus = base_dev->bus; - while (override_bus) { - - /* - * If we have more buses in override tree device, then allocate - * a new bus for the base tree device as well. - */ - if (!base_bus) { - alloc_bus(base_dev); - base_bus = base_dev->last_bus; - } - - override_devicetree(base_dev->bus, override_dev->bus); + /* + * If we have more buses in override tree device, then allocate + * a new bus for the base tree device as well. + */ + if (!base_bus) + alloc_bus(base_dev); - override_bus = override_bus->next_bus; - base_bus = base_bus->next_bus; - } + override_devicetree(base_dev->bus, override_dev->bus); } /* |