Patchwork reduce the size of devices

login
register
about
Submitter Myles Watson
Date 2010-05-20 23:08:03
Message ID <AANLkTikioEu9dSMsl9JIEsJo8lltv0J_pPal5dKL3QJq@mail.gmail.com>
Download mbox | patch
Permalink /patch/1365/
State Accepted
Headers show

Comments

Myles Watson - 2010-05-20 23:08:03
On Thu, May 20, 2010 at 1:16 PM, Myles Watson <mylesgw@gmail.com> wrote:
> Use linked lists for resources instead of fixed arrays.

> resource_usage.diff - changes the functions where resources are used

Here's an updated patch that doesn't hang :)  I was in too much of a
hurry.  We could add the resources to the end of the list to maintain
the old order if anyone cares.  Since we're using a list, the
resources are in reverse order.

Signed-off-by: Myles Watson <mylesgw@gmail.com>

Thanks,
Myles
Patrick Georgi - 2010-05-21 14:03:56
Am 21.05.2010 01:08, schrieb Myles Watson:
> static void free_resource(device_t dev, struct resource *res, struct
resource *prev)
> ...
> +	res->next = free_resources;
> +	free_resources = res->next;

Shouldn't that be
+	res->next = free_resources;
+	free_resources = res;
to add res to the free_resources?

Other than that, this is great! Smaller, cleaner, faster code, that uses
less memory to achieve the same result - wonderful!


With the above thing cleared up, this is
Acked-by: Patrick Georgi <patrick.georgi@coresystems.de>
Myles Watson - 2010-05-21 14:43:00
On Fri, May 21, 2010 at 8:03 AM, Patrick Georgi <patrick@georgi-clan.de> wrote:
> Am 21.05.2010 01:08, schrieb Myles Watson:
>> static void free_resource(device_t dev, struct resource *res, struct
> resource *prev)
>> ...
>> +     res->next = free_resources;
>> +     free_resources = res->next;
>
> Shouldn't that be
> +       res->next = free_resources;
> +       free_resources = res;
> to add res to the free_resources?
Yes.  Thanks for catching it.  It's too bad to leak the memory you're
saving :)  Fixed.

> Other than that, this is great! Smaller, cleaner, faster code, that uses
> less memory to achieve the same result - wonderful!
Thanks.  If we do the same thing with links we could save another ~150
bytes per device.  There are 8 links per device when few of them have
any at all.

> With the above thing cleared up, this is
> Acked-by: Patrick Georgi <patrick.georgi@coresystems.de>

Rev 5576.

Thanks,
Myles

Patch

Index: svn/src/devices/device.c
===================================================================
--- svn.orig/src/devices/device.c
+++ svn/src/devices/device.c
@@ -255,16 +255,15 @@  static void compute_resources(struct bus
 
 	/* 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)
@@ -504,16 +503,15 @@  static void allocate_resources(struct bu
 
 	/* 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)
@@ -558,8 +556,7 @@  static void constrain_resources(struct d
 	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) {
@@ -606,7 +603,6 @@  static void avoid_fixed_resources(struct
 {
 	struct constraints limits;
 	struct resource *res;
-	int i;
 
 	printk(BIOS_SPEW, "%s: %s\n", __func__, dev_path(dev));
 	/* Initialize constraints to maximum size. */
@@ -619,8 +615,7 @@  static void avoid_fixed_resources(struct
 	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__,
@@ -640,9 +635,8 @@  static void avoid_fixed_resources(struct
 	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;
@@ -766,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) {
@@ -929,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();
@@ -956,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) {
@@ -989,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;
@@ -1003,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) {
Index: svn/src/devices/device_util.c
===================================================================
--- svn.orig/src/devices/device_util.c
+++ svn/src/devices/device_util.c
@@ -261,25 +261,54 @@  int path_eq(struct device_path *path1, s
 }
 
 /**
+ * Remove resource res from the device's list and add it 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->next;
+}
+
+/**
  * See if we have unused but allocated resource structures.
  * If so remove the allocation.
  * @param dev The device to find the resource on
  */
 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;
 }
 
 /**
@@ -322,12 +347,14 @@  struct resource *new_resource(device_t d
 	/* 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 = dev->resource_list;
+		dev->resource_list = resource;
 	}
 	/* Initialize the resource values */
 	if (!(resource->flags & IORESOURCE_FIXED)) {
@@ -486,23 +513,22 @@  void search_bus_resources(struct bus *bu
 {
 	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 +539,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 +586,7 @@  static void resource_tree(struct device 
 {
 	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 +597,13 @@  static void resource_tree(struct device 
 		  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 +637,8 @@  void show_devs_tree(struct device *dev, 
 	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 +672,8 @@  void show_all_devs(int debug_level, cons
 	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 +711,10 @@  void show_all_devs_resources(int debug_l
 		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, "");
 	}
 }
Index: svn/src/devices/oprom/yabel/device.c
===================================================================
--- svn.orig/src/devices/oprom/yabel/device.c
+++ svn/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;
Index: svn/src/devices/pci_device.c
===================================================================
--- svn.orig/src/devices/pci_device.c
+++ svn/src/devices/pci_device.c
@@ -550,14 +550,12 @@  static void pci_set_resource(struct devi
 
 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;
Index: svn/src/devices/pnp_device.c
===================================================================
--- svn.orig/src/devices/pnp_device.c
+++ svn/src/devices/pnp_device.c
@@ -132,14 +132,14 @@  static void pnp_set_resource(device_t de
 
 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);
 	}
 }
 
Index: svn/src/northbridge/amd/amdfam10/northbridge.c
===================================================================
--- svn.orig/src/northbridge/amd/amdfam10/northbridge.c
+++ svn/src/northbridge/amd/amdfam10/northbridge.c
@@ -592,7 +592,7 @@  static void amdfam10_create_vga_resource
 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(devic
 	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(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(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
Index: svn/src/northbridge/amd/amdk8/northbridge.c
===================================================================
--- svn.orig/src/northbridge/amd/amdk8/northbridge.c
+++ svn/src/northbridge/amd/amdk8/northbridge.c
@@ -520,14 +520,13 @@  static void amdk8_create_vga_resource(de
 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(d
 {
 #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(d
 		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
Index: svn/src/northbridge/amd/gx2/northbridge.c
===================================================================
--- svn.orig/src/northbridge/amd/gx2/northbridge.c
+++ svn/src/northbridge/amd/gx2/northbridge.c
@@ -297,11 +297,9 @@  static void northbridge_init(device_t de
 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
Index: svn/src/northbridge/amd/lx/northbridge.c
===================================================================
--- svn.orig/src/northbridge/amd/lx/northbridge.c
+++ svn/src/northbridge/amd/lx/northbridge.c
@@ -318,18 +318,18 @@  static void northbridge_init(device_t de
 
 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;
Index: svn/src/northbridge/intel/e7520/northbridge.c
===================================================================
--- svn.orig/src/northbridge/intel/e7520/northbridge.c
+++ svn/src/northbridge/intel/e7520/northbridge.c
@@ -183,9 +183,8 @@  static void mc_read_resources(device_t d
 
 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, "<mmconfig>");
Index: svn/src/northbridge/intel/e7525/northbridge.c
===================================================================
--- svn.orig/src/northbridge/intel/e7525/northbridge.c
+++ svn/src/northbridge/intel/e7525/northbridge.c
@@ -183,9 +183,8 @@  static void mc_read_resources(device_t d
 
 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, "<mmconfig>");
Index: svn/src/northbridge/intel/i3100/northbridge.c
===================================================================
--- svn.orig/src/northbridge/intel/i3100/northbridge.c
+++ svn/src/northbridge/intel/i3100/northbridge.c
@@ -204,9 +204,8 @@  static void mc_read_resources(device_t d
 
 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, "<mmconfig>");
Index: svn/src/southbridge/amd/sb600/sb600_lpc.c
===================================================================
--- svn.orig/src/southbridge/amd/sb600/sb600_lpc.c
+++ svn/src/southbridge/amd/sb600/sb600_lpc.c
@@ -108,7 +108,6 @@  static void sb600_lpc_enable_childrens_r
 {
 	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_r
 			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;
Index: svn/src/southbridge/amd/sb700/sb700_lpc.c
===================================================================
--- svn.orig/src/southbridge/amd/sb700/sb700_lpc.c
+++ svn/src/southbridge/amd/sb700/sb700_lpc.c
@@ -120,7 +120,6 @@  static void sb700_lpc_enable_childrens_r
 {
 	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_r
 			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;
Index: svn/src/southbridge/broadcom/bcm5785/bcm5785_lpc.c
===================================================================
--- svn.orig/src/southbridge/broadcom/bcm5785/bcm5785_lpc.c
+++ svn/src/southbridge/broadcom/bcm5785/bcm5785_lpc.c
@@ -69,7 +69,6 @@  static void bcm5785_lpc_enable_childrens
 {
         unsigned link;
 	uint32_t reg;
-	int i;
 
 	reg = pci_read_config8(dev, 0x44);
 
@@ -78,10 +77,9 @@  static void bcm5785_lpc_enable_childrens
                 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;
                 			end = resource_end(res);
Index: svn/src/southbridge/nvidia/ck804/ck804_lpc.c
===================================================================
--- svn.orig/src/southbridge/nvidia/ck804/ck804_lpc.c
+++ svn/src/southbridge/nvidia/ck804/ck804_lpc.c
@@ -242,10 +242,9 @@  static void ck804_lpc_enable_childrens_r
 		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;
Index: svn/src/southbridge/nvidia/mcp55/mcp55_lpc.c
===================================================================
--- svn.orig/src/southbridge/nvidia/mcp55/mcp55_lpc.c
+++ svn/src/southbridge/nvidia/mcp55/mcp55_lpc.c
@@ -217,10 +217,9 @@  static void mcp55_lpc_enable_childrens_r
 		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;
 					end = resource_end(res);
Index: svn/src/southbridge/sis/sis966/sis966_lpc.c
===================================================================
--- svn.orig/src/southbridge/sis/sis966/sis966_lpc.c
+++ svn/src/southbridge/sis/sis966/sis966_lpc.c
@@ -210,10 +210,9 @@  static void sis966_lpc_enable_childrens_
 		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;
 					end = resource_end(res);
Index: svn/src/superio/smsc/lpc47n217/superio.c
===================================================================
--- svn.orig/src/superio/smsc/lpc47n217/superio.c
+++ svn/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); */
 
Index: svn/src/superio/smsc/lpc47n227/superio.c
===================================================================
--- svn.orig/src/superio/smsc/lpc47n227/superio.c
+++ svn/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);
 }
Index: svn/src/superio/via/vt1211/vt1211.c
===================================================================
--- svn.orig/src/superio/via/vt1211/vt1211.c
+++ svn/src/superio/via/vt1211/vt1211.c
@@ -127,15 +127,13 @@  static void vt1211_pnp_enable_resources(
 
 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(str
 	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);
Index: svn/src/drivers/ati/ragexl/xlinit.c
===================================================================
--- svn.orig/src/drivers/ati/ragexl/xlinit.c
+++ svn/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
         }