From c25cc11ae32e10a7d0c9f04c29bfb7eca4d9c210 Mon Sep 17 00:00:00 2001 From: Myles Watson Date: Fri, 21 May 2010 14:33:48 +0000 Subject: [PATCH] Use lists instead of arrays for resources in devices to reduce memory usage. Signed-off-by: Myles Watson Acked-by: Patrick Georgi git-svn-id: svn://svn.coreboot.org/coreboot/trunk@5576 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- src/devices/device.c | 34 ++--- src/devices/device_util.c | 142 +++++++++++------- src/devices/oprom/yabel/device.c | 3 +- src/devices/pci_device.c | 8 +- src/devices/pnp_device.c | 6 +- src/drivers/ati/ragexl/xlinit.c | 8 +- src/include/device/device.h | 6 +- src/include/device/resource.h | 1 + src/northbridge/amd/amdfam10/northbridge.c | 21 ++- src/northbridge/amd/amdk8/northbridge.c | 16 +- src/northbridge/amd/gx2/northbridge.c | 6 +- src/northbridge/amd/lx/northbridge.c | 10 +- src/northbridge/intel/e7520/northbridge.c | 3 +- src/northbridge/intel/e7525/northbridge.c | 3 +- src/northbridge/intel/i3100/northbridge.c | 3 +- src/southbridge/amd/sb600/sb600_lpc.c | 6 +- src/southbridge/amd/sb700/sb700_lpc.c | 6 +- .../broadcom/bcm5785/bcm5785_lpc.c | 6 +- src/southbridge/nvidia/ck804/ck804_lpc.c | 5 +- src/southbridge/nvidia/mcp55/mcp55_lpc.c | 5 +- src/southbridge/sis/sis966/sis966_lpc.c | 5 +- src/superio/smsc/lpc47n217/superio.c | 6 +- src/superio/smsc/lpc47n227/superio.c | 6 +- src/superio/via/vt1211/vt1211.c | 39 +++-- util/sconfig/main.c | 36 +++-- 25 files changed, 200 insertions(+), 190 deletions(-) diff --git a/src/devices/device.c b/src/devices/device.c index c9788211cd..f6c7af48c0 100644 --- a/src/devices/device.c +++ b/src/devices/device.c @@ -43,6 +43,8 @@ struct device *all_devices = &dev_root; /** Pointer to the last device */ extern struct device **last_dev_p; +/** Linked list of free resources */ +struct resource *free_resources = NULL; /** @@ -253,16 +255,15 @@ static void compute_resources(struct bus *bus, struct resource *bridge, /* For each child which is a bridge, compute_resource_needs. */ for (dev = bus->children; dev; dev = dev->sibling) { - unsigned i; struct resource *child_bridge; if (!dev->links) continue; /* Find the resources with matching type flags. */ - for (i = 0; i < dev->resources; i++) { + for (child_bridge = dev->resource_list; child_bridge; + child_bridge = child_bridge->next) { unsigned link; - child_bridge = &dev->resource[i]; if (!(child_bridge->flags & IORESOURCE_BRIDGE) || (child_bridge->flags & type_mask) != type) @@ -502,16 +503,15 @@ static void allocate_resources(struct bus *bus, struct resource *bridge, /* For each child which is a bridge, allocate_resources. */ for (dev = bus->children; dev; dev = dev->sibling) { - unsigned i; struct resource *child_bridge; if (!dev->links) continue; /* Find the resources with matching type flags. */ - for (i = 0; i < dev->resources; i++) { + for (child_bridge = dev->resource_list; child_bridge; + child_bridge = child_bridge->next) { unsigned link; - child_bridge = &dev->resource[i]; if (!(child_bridge->flags & IORESOURCE_BRIDGE) || (child_bridge->flags & type_mask) != type) @@ -556,8 +556,7 @@ static void constrain_resources(struct device *dev, struct constraints* limits) printk(BIOS_SPEW, "%s: %s\n", __func__, dev_path(dev)); /* Constrain limits based on the fixed resources of this device. */ - for (i = 0; i < dev->resources; i++) { - res = &dev->resource[i]; + for (res = dev->resource_list; res; res = res->next) { if (!(res->flags & IORESOURCE_FIXED)) continue; if (!res->size) { @@ -604,7 +603,6 @@ static void avoid_fixed_resources(struct device *dev) { struct constraints limits; struct resource *res; - int i; printk(BIOS_SPEW, "%s: %s\n", __func__, dev_path(dev)); /* Initialize constraints to maximum size. */ @@ -617,8 +615,7 @@ static void avoid_fixed_resources(struct device *dev) limits.mem.limit = 0xffffffffffffffffULL; /* Constrain the limits to dev's initial resources. */ - for (i = 0; i < dev->resources; i++) { - res = &dev->resource[i]; + for (res = dev->resource_list; res; res = res->next) { if ((res->flags & IORESOURCE_FIXED)) continue; printk(BIOS_SPEW, "%s:@%s %02lx limit %08Lx\n", __func__, @@ -638,9 +635,8 @@ static void avoid_fixed_resources(struct device *dev) constrain_resources(dev, &limits); /* Update dev's resources with new limits. */ - for (i = 0; i < dev->resources; i++) { + for (res = dev->resource_list; res; res = res->next) { struct resource *lim; - res = &dev->resource[i]; if ((res->flags & IORESOURCE_FIXED)) continue; @@ -764,7 +760,7 @@ void assign_resources(struct bus *bus) dev_path(bus->dev), bus->secondary, bus->link); for (curdev = bus->children; curdev; curdev = curdev->sibling) { - if (!curdev->enabled || !curdev->resources) { + if (!curdev->enabled || !curdev->resource_list) { continue; } if (!curdev->ops || !curdev->ops->set_resources) { @@ -927,7 +923,6 @@ void dev_configure(void) struct resource *res; struct device *root; struct device *child; - int i; #if CONFIG_VGA_BRIDGE_SETUP == 1 set_vga_bridge_bits(); @@ -954,8 +949,7 @@ void dev_configure(void) for (child = root->link[0].children; child; child = child->sibling) { if (!(child->path.type == DEVICE_PATH_PCI_DOMAIN)) continue; - for (i = 0; i < child->resources; i++) { - res = &child->resource[i]; + for (res = child->resource_list; res; res = res->next) { if (res->flags & IORESOURCE_FIXED) continue; if (res->flags & IORESOURCE_PREFETCH) { @@ -987,8 +981,7 @@ void dev_configure(void) for (child = root->link[0].children; child; child = child->sibling) { if (child->path.type != DEVICE_PATH_PCI_DOMAIN) continue; - for (i = 0; i < child->resources; i++) { - res = &child->resource[i]; + for (res = child->resource_list; res; res = res->next) { if (!(res->flags & IORESOURCE_MEM) || res->flags & IORESOURCE_FIXED) continue; @@ -1001,8 +994,7 @@ void dev_configure(void) for (child = root->link[0].children; child; child = child->sibling) { if (!(child->path.type == DEVICE_PATH_PCI_DOMAIN)) continue; - for (i = 0; i < child->resources; i++) { - res = &child->resource[i]; + for (res = child->resource_list; res; res = res->next) { if (res->flags & IORESOURCE_FIXED) continue; if (res->flags & IORESOURCE_PREFETCH) { diff --git a/src/devices/device_util.c b/src/devices/device_util.c index 3e8cba2f98..9096c137da 100644 --- a/src/devices/device_util.c +++ b/src/devices/device_util.c @@ -260,6 +260,40 @@ int path_eq(struct device_path *path1, struct device_path *path2) return equal; } +/** + * Allocate 64 more resources to the free list. + */ +static int allocate_more_resources(void) +{ + int i; + struct resource *new_res_list; + new_res_list = malloc(64 * sizeof(*new_res_list)); + + if (new_res_list == NULL) + return 0; + + memset(new_res_list, 0, 64 * sizeof(*new_res_list)); + + for (i = 0; i < 64-1; i++) + new_res_list[i].next = &new_res_list[i+1]; + + free_resources = new_res_list; + return 1; +} + +/** + * Remove resource res from the device's list and add it to the free list. + */ +static void free_resource(device_t dev, struct resource *res, struct resource *prev) +{ + if (prev) + prev->next = res->next; + else + dev->resource_list = res->next; + res->next = free_resources; + free_resources = res; +} + /** * See if we have unused but allocated resource structures. * If so remove the allocation. @@ -267,19 +301,14 @@ int path_eq(struct device_path *path1, struct device_path *path2) */ void compact_resources(device_t dev) { - struct resource *resource; - int i; + struct resource *res, *next, *prev = NULL; /* Move all of the free resources to the end */ - for(i = 0; i < dev->resources;) { - resource = &dev->resource[i]; - if (!resource->flags) { - memmove(resource, resource + 1, (dev->resources - i) * - sizeof(*resource)); - dev->resources -= 1; - memset(&dev->resource[dev->resources], 0, sizeof(*resource)); - } else { - i++; - } + for(res = dev->resource_list; res; res = next) { + next = res->next; + if (!res->flags) + free_resource(dev, res, prev); + else + prev = res; } } @@ -292,17 +321,13 @@ void compact_resources(device_t dev) */ struct resource *probe_resource(device_t dev, unsigned index) { - struct resource *resource; - int i; + struct resource *res; /* See if there is a resource with the appropriate index */ - resource = 0; - for(i = 0; i < dev->resources; i++) { - if (dev->resource[i].index == index) { - resource = &dev->resource[i]; + for(res = dev->resource_list; res; res = res->next) { + if (res->index == index) break; - } } - return resource; + return res; } /** @@ -314,7 +339,7 @@ struct resource *probe_resource(device_t dev, unsigned index) */ struct resource *new_resource(device_t dev, unsigned index) { - struct resource *resource; + struct resource *resource, *tail; /* First move all of the free resources to the end */ compact_resources(dev); @@ -322,12 +347,20 @@ struct resource *new_resource(device_t dev, unsigned index) /* See if there is a resource with the appropriate index */ resource = probe_resource(dev, index); if (!resource) { - if (dev->resources == MAX_RESOURCES) { - die("MAX_RESOURCES exceeded."); - } - resource = &dev->resource[dev->resources]; + if (free_resources == NULL && !allocate_more_resources()) + die("Couldn't allocate more resources."); + + resource = free_resources; + free_resources = free_resources->next; memset(resource, 0, sizeof(*resource)); - dev->resources++; + resource->next = NULL; + tail = dev->resource_list; + if (tail) { + while (tail->next) tail = tail->next; + tail->next = resource; + } + else + dev->resource_list = resource; } /* Initialize the resource values */ if (!(resource->flags & IORESOURCE_FIXED)) { @@ -486,23 +519,22 @@ void search_bus_resources(struct bus *bus, { struct device *curdev; for(curdev = bus->children; curdev; curdev = curdev->sibling) { - int i; + struct resource *res; /* Ignore disabled devices */ if (!curdev->enabled) continue; - for(i = 0; i < curdev->resources; i++) { - struct resource *resource = &curdev->resource[i]; + for(res = curdev->resource_list; res; res = res->next) { /* If it isn't the right kind of resource ignore it */ - if ((resource->flags & type_mask) != type) { + if ((res->flags & type_mask) != type) { continue; } /* If it is a subtractive resource recurse */ - if (resource->flags & IORESOURCE_SUBTRACTIVE) { + if (res->flags & IORESOURCE_SUBTRACTIVE) { struct bus * subbus; - subbus = &curdev->link[IOINDEX_SUBTRACTIVE_LINK(resource->index)]; + subbus = &curdev->link[IOINDEX_SUBTRACTIVE_LINK(res->index)]; search_bus_resources(subbus, type_mask, type, search, gp); continue; } - search(gp, curdev, resource); + search(gp, curdev, res); } } } @@ -513,20 +545,19 @@ void search_global_resources( { struct device *curdev; for(curdev = all_devices; curdev; curdev = curdev->next) { - int i; + struct resource *res; /* Ignore disabled devices */ if (!curdev->enabled) continue; - for(i = 0; i < curdev->resources; i++) { - struct resource *resource = &curdev->resource[i]; + for(res = curdev->resource_list; res; res = res->next) { /* If it isn't the right kind of resource ignore it */ - if ((resource->flags & type_mask) != type) { + if ((res->flags & type_mask) != type) { continue; } /* If it is a subtractive resource ignore it */ - if (resource->flags & IORESOURCE_SUBTRACTIVE) { + if (res->flags & IORESOURCE_SUBTRACTIVE) { continue; } - search(gp, curdev, resource); + search(gp, curdev, res); } } } @@ -561,6 +592,7 @@ static void resource_tree(struct device *root, int debug_level, int depth) { int i = 0, link = 0; struct device *child; + struct resource *res; char indent[30]; /* If your tree has more levels, it's wrong. */ for (i = 0; i < depth + 1 && i < 29; i++) @@ -571,13 +603,13 @@ static void resource_tree(struct device *root, int debug_level, int depth) dev_path(root), root->links); do_printk(BIOS_DEBUG, " %s\n", root->link[0].children ? dev_path(root->link[0].children) : "NULL"); - for (i = 0; i < root->resources; i++) { + for (res = root->resource_list; res; res = res->next) { do_printk(BIOS_DEBUG, "%s%s resource base %llx size %llx align %d gran %d limit %llx flags %lx index %lx\n", - indent, dev_path(root), root->resource[i].base, - root->resource[i].size, root->resource[i].align, - root->resource[i].gran, root->resource[i].limit, - root->resource[i].flags, root->resource[i].index); + indent, dev_path(root), res->base, + res->size, res->align, + res->gran, res->limit, + res->flags, res->index); } for (link = 0; link < root->links; link++) { @@ -611,8 +643,8 @@ void show_devs_tree(struct device *dev, int debug_level, int depth, int linknum) for (i = 0; i < depth; i++) depth_str[i] = ' '; depth_str[i] = '\0'; - do_printk(debug_level, "%s%s: enabled %d, %d resources\n", - depth_str, dev_path(dev), dev->enabled, dev->resources); + do_printk(debug_level, "%s%s: enabled %d\n", + depth_str, dev_path(dev), dev->enabled); for (i = 0; i < dev->links; i++) { for (sibling = dev->link[i].children; sibling; sibling = sibling->sibling) @@ -646,10 +678,8 @@ void show_all_devs(int debug_level, const char *msg) if (!do_printk(debug_level, "Show all devs...%s\n", msg)) return; for (dev = all_devices; dev; dev = dev->next) { - do_printk(debug_level, - "%s: enabled %d, %d resources\n", - dev_path(dev), dev->enabled, - dev->resources); + do_printk(debug_level, "%s: enabled %d\n", + dev_path(dev), dev->enabled); } } @@ -687,12 +717,10 @@ void show_all_devs_resources(int debug_level, const char* msg) return; for (dev = all_devices; dev; dev = dev->next) { - int i; - do_printk(debug_level, - "%s: enabled %d, %d resources\n", - dev_path(dev), dev->enabled, - dev->resources); - for (i = 0; i < dev->resources; i++) - show_one_resource(debug_level, dev, &dev->resource[i], ""); + struct resource *res; + do_printk(debug_level, "%s: enabled %d\n", + dev_path(dev), dev->enabled); + for (res = dev->resource_list; res; res = res->next) + show_one_resource(debug_level, dev, res, ""); } } diff --git a/src/devices/oprom/yabel/device.c b/src/devices/oprom/yabel/device.c index 7e71a45e97..5e5dc2877d 100644 --- a/src/devices/oprom/yabel/device.c +++ b/src/devices/oprom/yabel/device.c @@ -53,8 +53,7 @@ biosemu_dev_get_addr_info(void) bios_device.devfn = devfn; DEBUG_PRINTF("bus: %x, devfn: %x\n", bus, devfn); - for (i = 0; i < bios_device.dev->resources; i++) { - r = &bios_device.dev->resource[i]; + for (r = bios_device.dev->resource_list; r; r = r->next) { translate_address_array[taa_index].info = r->flags; translate_address_array[taa_index].bus = bus; translate_address_array[taa_index].devfn = devfn; diff --git a/src/devices/pci_device.c b/src/devices/pci_device.c index 8863c237a4..4aed35d501 100644 --- a/src/devices/pci_device.c +++ b/src/devices/pci_device.c @@ -550,14 +550,12 @@ static void pci_set_resource(struct device *dev, struct resource *resource) void pci_dev_set_resources(struct device *dev) { - struct resource *resource, *last; + struct resource *res; unsigned link; u8 line; - last = &dev->resource[dev->resources]; - - for (resource = &dev->resource[0]; resource < last; resource++) { - pci_set_resource(dev, resource); + for (res = dev->resource_list; res; res = res->next) { + pci_set_resource(dev, res); } for (link = 0; link < dev->links; link++) { struct bus *bus; diff --git a/src/devices/pnp_device.c b/src/devices/pnp_device.c index 469487d1d2..ad14bbf89a 100644 --- a/src/devices/pnp_device.c +++ b/src/devices/pnp_device.c @@ -132,14 +132,14 @@ static void pnp_set_resource(device_t dev, struct resource *resource) void pnp_set_resources(device_t dev) { - int i; + struct resource *res; /* Select the device */ pnp_set_logical_device(dev); /* Paranoia says I should disable the device here... */ - for(i = 0; i < dev->resources; i++) { - pnp_set_resource(dev, &dev->resource[i]); + for(res = dev->resource_list; res; res = res->next) { + pnp_set_resource(dev, res); } } diff --git a/src/drivers/ati/ragexl/xlinit.c b/src/drivers/ati/ragexl/xlinit.c index 8b02239833..bcbce6c9b6 100644 --- a/src/drivers/ati/ragexl/xlinit.c +++ b/src/drivers/ati/ragexl/xlinit.c @@ -520,9 +520,9 @@ static void ati_ragexl_init(device_t dev) #define USE_AUX_REG 1 - res = &dev->resource[0]; + res = dev->resource_list; if(res->flags & IORESOURCE_IO) { - res = &dev->resource[1]; + res = res->next; } #if CONFIG_CONSOLE_BTEXT==1 @@ -532,7 +532,9 @@ static void ati_ragexl_init(device_t dev) #if USE_AUX_REG==0 info->ati_regbase = res->base+0x7ff000+0xc00; #else - res = &dev->resource[2]; + /* Fix this to look for the correct index. */ + //if (dev->resource_list && dev->resource_list->next) + res = dev->resource_list->next->next; if(res->flags & IORESOURCE_MEM) { info->ati_regbase = res->base+0x400; //using auxiliary register } diff --git a/src/include/device/device.h b/src/include/device/device.h index 59dd0815e6..6ac2d10bfc 100644 --- a/src/include/device/device.h +++ b/src/include/device/device.h @@ -74,11 +74,10 @@ struct device { u8 command; /* Base registers for this device. I/O, MEM and Expansion ROM */ - struct resource resource[MAX_RESOURCES]; - unsigned int resources; + struct resource *resource_list; /* links are (downstream) buses attached to the device, usually a leaf - * device with no children have 0 buses attached and a bridge has 1 bus + * device with no children has 0 buses attached and a bridge has 1 bus */ struct bus link[MAX_LINKS]; /* number of buses attached to the device */ @@ -96,6 +95,7 @@ struct device { extern struct device dev_root; extern struct device *all_devices; /* list of all devices */ +extern struct resource *free_resources; /* Generic device interface functions */ device_t alloc_dev(struct bus *parent, struct device_path *path); diff --git a/src/include/device/resource.h b/src/include/device/resource.h index 5452d4360c..49e218531c 100644 --- a/src/include/device/resource.h +++ b/src/include/device/resource.h @@ -68,6 +68,7 @@ struct resource { resource_t base; /* Base address of the resource */ resource_t size; /* Size of the resource */ resource_t limit; /* Largest valid value base + size -1 */ + struct resource* next; /* Next resource in the list */ unsigned long flags; /* Descriptions of the kind of resource */ unsigned long index; /* Bus specific per device resource id */ unsigned char align; /* Required alignment (log 2) of the resource */ diff --git a/src/northbridge/amd/amdfam10/northbridge.c b/src/northbridge/amd/amdfam10/northbridge.c index 3d968a9ded..009b57becc 100644 --- a/src/northbridge/amd/amdfam10/northbridge.c +++ b/src/northbridge/amd/amdfam10/northbridge.c @@ -592,7 +592,7 @@ static void amdfam10_create_vga_resource(device_t dev, unsigned nodeid) static void amdfam10_set_resources(device_t dev) { u32 nodeid, link; - int i; + struct resource *res; /* Find the nodeid */ nodeid = amdfam10_nodeid(dev); @@ -600,8 +600,8 @@ static void amdfam10_set_resources(device_t dev) amdfam10_create_vga_resource(dev, nodeid); /* Set each resource we have found */ - for(i = 0; i < dev->resources; i++) { - amdfam10_set_resource(dev, &dev->resource[i], nodeid); + for(res = dev->resource_list; res; res = res->next) { + amdfam10_set_resource(dev, res, nodeid); } for(link = 0; link < dev->links; link++) { @@ -889,7 +889,7 @@ static void pci_domain_set_resources(device_t dev) { #if CONFIG_PCI_64BIT_PREF_MEM == 1 struct resource *io, *mem1, *mem2; - struct resource *resource, *last; + struct resource *res; #endif unsigned long mmio_basek; u32 pci_tolm; @@ -943,14 +943,13 @@ static void pci_domain_set_resources(device_t dev) mem2->base, mem2->limit, mem2->size, mem2->align); } - last = &dev->resource[dev->resources]; - for(resource = &dev->resource[0]; resource < last; resource++) + for(res = &dev->resource_list; res; res = res->next) { - resource->flags |= IORESOURCE_ASSIGNED; - resource->flags &= ~IORESOURCE_STORED; - link = (resource>>2) & 3; - resource->flags |= IORESOURCE_STORED; - report_resource_stored(dev, resource, ""); + res->flags |= IORESOURCE_ASSIGNED; + res->flags &= ~IORESOURCE_STORED; + link = (res>>2) & 3; + res->flags |= IORESOURCE_STORED; + report_resource_stored(dev, res, ""); } #endif diff --git a/src/northbridge/amd/amdk8/northbridge.c b/src/northbridge/amd/amdk8/northbridge.c index 6938ec62b3..7910f291aa 100644 --- a/src/northbridge/amd/amdk8/northbridge.c +++ b/src/northbridge/amd/amdk8/northbridge.c @@ -520,14 +520,13 @@ static void amdk8_create_vga_resource(device_t dev, unsigned nodeid) static void amdk8_set_resources(device_t dev) { unsigned nodeid, link; - int i; + struct resource *res; /* Find the nodeid */ nodeid = amdk8_nodeid(dev); /* Set each resource we have found */ - for(i = 0; i < dev->resources; i++) { - struct resource *res = &dev->resource[i]; + for(res = dev->resource_list; res; res = res->next) { struct resource *old = NULL; unsigned index; @@ -846,7 +845,7 @@ static void amdk8_domain_set_resources(device_t dev) { #if CONFIG_PCI_64BIT_PREF_MEM == 1 struct resource *io, *mem1, *mem2; - struct resource *resource, *last; + struct resource *res; #endif unsigned long mmio_basek; uint32_t pci_tolm; @@ -905,12 +904,11 @@ static void amdk8_domain_set_resources(device_t dev) mem2->base, mem2->limit, mem2->size, mem2->align); #endif - last = &dev->resource[dev->resources]; - for(resource = &dev->resource[0]; resource < last; resource++) + for(res = dev->resource_list; res; res = res->next) { - resource->flags |= IORESOURCE_ASSIGNED; - resource->flags |= IORESOURCE_STORED; - report_resource_stored(dev, resource, ""); + res->flags |= IORESOURCE_ASSIGNED; + res->flags |= IORESOURCE_STORED; + report_resource_stored(dev, res, ""); } #endif diff --git a/src/northbridge/amd/gx2/northbridge.c b/src/northbridge/amd/gx2/northbridge.c index 98acbc9f95..42fdcbb496 100644 --- a/src/northbridge/amd/gx2/northbridge.c +++ b/src/northbridge/amd/gx2/northbridge.c @@ -297,11 +297,9 @@ static void northbridge_init(device_t dev) static void set_resources(struct device *dev) { #if 0 - struct resource *resource, *last; + struct resource *res; - last = &dev->resource[dev->resources]; - - for(resource = &dev->resource[0]; resource < last; resource++) { + for(res = &dev->resource_list; res; res = res->next) { pci_set_resource(dev, resource); } #endif diff --git a/src/northbridge/amd/lx/northbridge.c b/src/northbridge/amd/lx/northbridge.c index 6eba99d9df..8fd8d9ecd2 100644 --- a/src/northbridge/amd/lx/northbridge.c +++ b/src/northbridge/amd/lx/northbridge.c @@ -318,18 +318,18 @@ static void northbridge_init(device_t dev) static void northbridge_set_resources(struct device *dev) { - struct resource *resource, *last; unsigned link; uint8_t line; - last = &dev->resource[dev->resources]; - - for (resource = &dev->resource[0]; resource < last; resource++) { +#if 0 + struct resource *res; + for (res = dev->resource_list; res; res = res->next) { // andrei: do not change the base address, it will make the VSA virtual registers unusable - //pci_set_resource(dev, resource); + //pci_set_resource(dev, res); // FIXME: static allocation may conflict with dynamic mappings! } +#endif for (link = 0; link < dev->links; link++) { struct bus *bus; diff --git a/src/northbridge/intel/e7520/northbridge.c b/src/northbridge/intel/e7520/northbridge.c index 93604b6cf7..02f7c45495 100644 --- a/src/northbridge/intel/e7520/northbridge.c +++ b/src/northbridge/intel/e7520/northbridge.c @@ -183,9 +183,8 @@ static void mc_read_resources(device_t dev) static void mc_set_resources(device_t dev) { - struct resource *resource, *last; + struct resource *resource; - last = &dev->resource[dev->resources]; resource = find_resource(dev, 0xcf); if (resource) { report_resource_stored(dev, resource, ""); diff --git a/src/northbridge/intel/e7525/northbridge.c b/src/northbridge/intel/e7525/northbridge.c index 559dc15b8b..a227f22987 100644 --- a/src/northbridge/intel/e7525/northbridge.c +++ b/src/northbridge/intel/e7525/northbridge.c @@ -183,9 +183,8 @@ static void mc_read_resources(device_t dev) static void mc_set_resources(device_t dev) { - struct resource *resource, *last; + struct resource *resource; - last = &dev->resource[dev->resources]; resource = find_resource(dev, 0xcf); if (resource) { report_resource_stored(dev, resource, ""); diff --git a/src/northbridge/intel/i3100/northbridge.c b/src/northbridge/intel/i3100/northbridge.c index 195790f8cd..0675aea6bc 100644 --- a/src/northbridge/intel/i3100/northbridge.c +++ b/src/northbridge/intel/i3100/northbridge.c @@ -204,9 +204,8 @@ static void mc_read_resources(device_t dev) static void mc_set_resources(device_t dev) { - struct resource *resource, *last; + struct resource *resource; - last = &dev->resource[dev->resources]; resource = find_resource(dev, 0xcf); if (resource) { report_resource_stored(dev, resource, ""); diff --git a/src/southbridge/amd/sb600/sb600_lpc.c b/src/southbridge/amd/sb600/sb600_lpc.c index 1f3253f55b..0653772385 100644 --- a/src/southbridge/amd/sb600/sb600_lpc.c +++ b/src/southbridge/amd/sb600/sb600_lpc.c @@ -108,7 +108,6 @@ static void sb600_lpc_enable_childrens_resources(device_t dev) { u32 link; u32 reg, reg_x; - int i; int var_num = 0; u16 reg_var[3]; @@ -122,10 +121,9 @@ static void sb600_lpc_enable_childrens_resources(device_t dev) enable_resources(child); if (child->enabled && (child->path.type == DEVICE_PATH_PNP)) { - for (i = 0; i < child->resources; i++) { - struct resource *res; + struct resource *res; + for (res = child->resource_list; res; res = res->next) { u32 base, end; /* don't need long long */ - res = &child->resource[i]; if (!(res->flags & IORESOURCE_IO)) continue; base = res->base; diff --git a/src/southbridge/amd/sb700/sb700_lpc.c b/src/southbridge/amd/sb700/sb700_lpc.c index 0dcf0d1095..ab0a5ba6cc 100644 --- a/src/southbridge/amd/sb700/sb700_lpc.c +++ b/src/southbridge/amd/sb700/sb700_lpc.c @@ -120,7 +120,6 @@ static void sb700_lpc_enable_childrens_resources(device_t dev) { u32 link; u32 reg, reg_x; - int i; int var_num = 0; u16 reg_var[3]; @@ -134,10 +133,9 @@ static void sb700_lpc_enable_childrens_resources(device_t dev) enable_resources(child); if (child->enabled && (child->path.type == DEVICE_PATH_PNP)) { - for (i = 0; i < child->resources; i++) { - struct resource *res; + struct resource *res; + for (res = child->resource_list; res; res = res->next) { u32 base, end; /* don't need long long */ - res = &child->resource[i]; if (!(res->flags & IORESOURCE_IO)) continue; base = res->base; diff --git a/src/southbridge/broadcom/bcm5785/bcm5785_lpc.c b/src/southbridge/broadcom/bcm5785/bcm5785_lpc.c index 29c08ab74e..a80f5d79d5 100644 --- a/src/southbridge/broadcom/bcm5785/bcm5785_lpc.c +++ b/src/southbridge/broadcom/bcm5785/bcm5785_lpc.c @@ -69,7 +69,6 @@ static void bcm5785_lpc_enable_childrens_resources(device_t dev) { unsigned link; uint32_t reg; - int i; reg = pci_read_config8(dev, 0x44); @@ -78,10 +77,9 @@ static void bcm5785_lpc_enable_childrens_resources(device_t dev) for (child = dev->link[link].children; child; child = child->sibling) { enable_resources(child); if(child->enabled && (child->path.type == DEVICE_PATH_PNP)) { - for(i=0;iresources;i++) { - struct resource *res; + struct resource *res; + for(res = child->resource_list; res; res = res->next) { unsigned long base, end; // don't need long long - res = &child->resource[i]; if(!(res->flags & IORESOURCE_IO)) continue; base = res->base; end = resource_end(res); diff --git a/src/southbridge/nvidia/ck804/ck804_lpc.c b/src/southbridge/nvidia/ck804/ck804_lpc.c index 3458738f9b..a6637cad1c 100644 --- a/src/southbridge/nvidia/ck804/ck804_lpc.c +++ b/src/southbridge/nvidia/ck804/ck804_lpc.c @@ -242,10 +242,9 @@ static void ck804_lpc_enable_childrens_resources(device_t dev) for (child = dev->link[link].children; child; child = child->sibling) { enable_resources(child); if (child->enabled && (child->path.type == DEVICE_PATH_PNP)) { - for (i = 0; i < child->resources; i++) { - struct resource *res; + struct resource *res; + for (res = child->resource_list; res; res = res->next) { unsigned long base, end; // don't need long long - res = &child->resource[i]; if (!(res->flags & IORESOURCE_IO)) continue; base = res->base; diff --git a/src/southbridge/nvidia/mcp55/mcp55_lpc.c b/src/southbridge/nvidia/mcp55/mcp55_lpc.c index 1d2a066b1b..0f9a50ca4f 100644 --- a/src/southbridge/nvidia/mcp55/mcp55_lpc.c +++ b/src/southbridge/nvidia/mcp55/mcp55_lpc.c @@ -217,10 +217,9 @@ static void mcp55_lpc_enable_childrens_resources(device_t dev) for (child = dev->link[link].children; child; child = child->sibling) { enable_resources(child); if(child->enabled && (child->path.type == DEVICE_PATH_PNP)) { - for(i=0;iresources;i++) { - struct resource *res; + struct resource *res; + for(res = child->resource_list; res; res = res->next) { unsigned long base, end; // don't need long long - res = &child->resource[i]; if(!(res->flags & IORESOURCE_IO)) continue; base = res->base; end = resource_end(res); diff --git a/src/southbridge/sis/sis966/sis966_lpc.c b/src/southbridge/sis/sis966/sis966_lpc.c index 2efc3802b2..a3b79f078a 100644 --- a/src/southbridge/sis/sis966/sis966_lpc.c +++ b/src/southbridge/sis/sis966/sis966_lpc.c @@ -210,10 +210,9 @@ static void sis966_lpc_enable_childrens_resources(device_t dev) for (child = dev->link[link].children; child; child = child->sibling) { enable_resources(child); if(child->enabled && (child->path.type == DEVICE_PATH_PNP)) { - for(i=0;iresources;i++) { - struct resource *res; + struct resource *res; + for(res = child->resource_list; res; res = res->next) { unsigned long base, end; // don't need long long - res = &child->resource[i]; if(!(res->flags & IORESOURCE_IO)) continue; base = res->base; end = resource_end(res); diff --git a/src/superio/smsc/lpc47n217/superio.c b/src/superio/smsc/lpc47n217/superio.c index cd4b539795..085331eaa7 100644 --- a/src/superio/smsc/lpc47n217/superio.c +++ b/src/superio/smsc/lpc47n217/superio.c @@ -99,15 +99,15 @@ static void enable_dev(device_t dev) */ static void lpc47n217_pnp_set_resources(device_t dev) { - int i; + struct resource *res; pnp_enter_conf_state(dev); /* NOTE: Cannot use pnp_set_resources() here because it assumes chip * support for logical devices, which the LPC47N217 doesn't have */ - for(i = 0; i < dev->resources; i++) - lpc47n217_pnp_set_resource(dev, &dev->resource[i]); + for(res = dev->resource_list; res; res = res->next) + lpc47n217_pnp_set_resource(dev, res); /* dump_pnp_device(dev); */ diff --git a/src/superio/smsc/lpc47n227/superio.c b/src/superio/smsc/lpc47n227/superio.c index 1431908f8e..f921ed85f3 100644 --- a/src/superio/smsc/lpc47n227/superio.c +++ b/src/superio/smsc/lpc47n227/superio.c @@ -96,14 +96,14 @@ static void enable_dev(device_t dev) // void lpc47n227_pnp_set_resources(device_t dev) { - int i; + struct resource *res; pnp_enter_conf_state(dev); // NOTE: Cannot use pnp_set_resources() here because it assumes chip // support for logical devices, which the LPC47N227 doesn't have - for (i = 0; i < dev->resources; i++) - lpc47n227_pnp_set_resource(dev, &dev->resource[i]); + for (res = dev->resource_list; res; res = res->next) + lpc47n227_pnp_set_resource(dev, res); pnp_exit_conf_state(dev); } diff --git a/src/superio/via/vt1211/vt1211.c b/src/superio/via/vt1211/vt1211.c index 1b98ae666e..69b744f283 100644 --- a/src/superio/via/vt1211/vt1211.c +++ b/src/superio/via/vt1211/vt1211.c @@ -127,15 +127,13 @@ static void vt1211_pnp_enable_resources(device_t dev) static void vt1211_pnp_set_resources(struct device *dev) { - int i; - struct resource *resource; + struct resource *res; #if CONFIG_CONSOLE_SERIAL8250 == 1 if( dev->path.pnp.device == 2 ){ - for( i = 0 ; i < dev->resources; i++){ - resource = &dev->resource[i]; - resource->flags |= IORESOURCE_STORED; - report_resource_stored(dev, resource, ""); + for(res = dev->resource_list; res; res = res->next){ + res->flags |= IORESOURCE_STORED; + report_resource_stored(dev, res, ""); } return; } @@ -145,34 +143,33 @@ static void vt1211_pnp_set_resources(struct device *dev) pnp_set_logical_device(dev); /* Paranoia says I should disable the device here... */ - for(i = 0; i < dev->resources; i++) { - resource = &dev->resource[i]; - if (!(resource->flags & IORESOURCE_ASSIGNED)) { + for(res = dev->resource_list; res; res = res->next){ + if (!(res->flags & IORESOURCE_ASSIGNED)) { printk(BIOS_ERR, "ERROR: %s %02lx %s size: 0x%010Lx not assigned\n", - dev_path(dev), dev->resource->index, - resource_type(resource), - resource->size); + dev_path(dev), res->index, + resource_type(res), + res->size); continue; } /* Now store the resource */ - if (resource->flags & IORESOURCE_IO) { - vt1211_set_iobase(dev, resource->index, resource->base); + if (res->flags & IORESOURCE_IO) { + vt1211_set_iobase(dev, res->index, res->base); } - else if (resource->flags & IORESOURCE_DRQ) { - pnp_set_drq(dev, resource->index, resource->base); + else if (res->flags & IORESOURCE_DRQ) { + pnp_set_drq(dev, res->index, res->base); } - else if (resource->flags & IORESOURCE_IRQ) { - pnp_set_irq(dev, resource->index, resource->base); + else if (res->flags & IORESOURCE_IRQ) { + pnp_set_irq(dev, res->index, res->base); } else { printk(BIOS_ERR, "ERROR: %s %02lx unknown resource type\n", - dev_path(dev), resource->index); + dev_path(dev), res->index); return; } - resource->flags |= IORESOURCE_STORED; + res->flags |= IORESOURCE_STORED; - report_resource_stored(dev, resource, ""); + report_resource_stored(dev, res, ""); } pnp_exit_ext_func_mode(dev); diff --git a/util/sconfig/main.c b/util/sconfig/main.c index 9c7938617b..a8441111db 100755 --- a/util/sconfig/main.c +++ b/util/sconfig/main.c @@ -278,8 +278,11 @@ void add_register(struct device *dev, char *name, char *val) { } static void pass0(FILE *fil, struct device *ptr) { - if ((ptr->type == device) && (ptr->id != 0) && (!ptr->used)) + if ((ptr->type == device) && (ptr->id != 0) && (!ptr->used)) { fprintf(fil, "struct device %s;\n", ptr->name); + if (ptr->rescnt > 0) + fprintf(fil, "struct resource %s_res[];\n", ptr->name); + } if ((ptr->type == device) && (ptr->id != 0) && ptr->used) fprintf(fil, "struct device %s;\n", ptr->aliased_name); } @@ -295,18 +298,7 @@ static void pass1(FILE *fil, struct device *ptr) { fprintf(fil, "\t.enabled = %d,\n", ptr->enabled); fprintf(fil, "\t.on_mainboard = 1,\n"); if (ptr->rescnt > 0) { - fprintf(fil, "\t.resources = %d,\n", ptr->rescnt); - fprintf(fil, "\t.resource = {\n"); - struct resource *r = ptr->res; - while (r) { - fprintf(fil, "\t\t{ .flags=IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_"); - if (r->type == IRQ) fprintf(fil, "IRQ"); - if (r->type == DRQ) fprintf(fil, "DRQ"); - if (r->type == IO) fprintf(fil, "IO"); - fprintf(fil, ", .index=0x%x, .base=0x%x},\n", r->index, r->base); - r = r->next; - } - fprintf(fil, "\t },\n"); + fprintf(fil, "\t.resource_list = &%s_res[0],\n", ptr->name); } int link = 0; fprintf(fil, "\t.link = {\n"); @@ -346,6 +338,24 @@ static void pass1(FILE *fil, struct device *ptr) { fprintf(fil, "\t.next=&%s\n", ptr->nextdev->name); fprintf(fil, "};\n"); } + if (ptr->rescnt > 0) { + int i=1; + fprintf(fil, "struct resource %s_res[] = {\n", ptr->name); + struct resource *r = ptr->res; + while (r) { + fprintf(fil, "\t\t{ .flags=IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_"); + if (r->type == IRQ) fprintf(fil, "IRQ"); + if (r->type == DRQ) fprintf(fil, "DRQ"); + if (r->type == IO) fprintf(fil, "IO"); + fprintf(fil, ", .index=0x%x, .base=0x%x,", r->index, r->base); + if (r->next) + fprintf(fil, ".next=&%s_res[%d]},\n", ptr->name, i++); + else + fprintf(fil, ".next=NULL },\n"); + r = r->next; + } + fprintf(fil, "\t };\n"); + } if ((ptr->type == chip) && (ptr->chiph_exists)) { if (ptr->reg) { fprintf(fil, "struct %s_config %s_info_%d\t= {\n", ptr->name_underscore, ptr->name_underscore, ptr->id);