[coreboot] [commit] r5576 - in trunk: src/devices src/devices/oprom/yabel src/drivers/ati/ragexl src/include/device src/northbridge/amd/amdfam10 src/northbridge/amd/amdk8 src/northbridge/amd/gx2 src/northbrid...

repository service svn at coreboot.org
Fri May 21 16:33:49 CEST 2010


Author: myles
Date: Fri May 21 16:33:48 2010
New Revision: 5576
URL: https://tracker.coreboot.org/trac/coreboot/changeset/5576

Log:
Use lists instead of arrays for resources in devices to reduce memory usage.

Signed-off-by: Myles Watson <mylesgw at gmail.com>
Acked-by: Patrick Georgi <patrick.georgi at coresystems.de>

Modified:
   trunk/src/devices/device.c
   trunk/src/devices/device_util.c
   trunk/src/devices/oprom/yabel/device.c
   trunk/src/devices/pci_device.c
   trunk/src/devices/pnp_device.c
   trunk/src/drivers/ati/ragexl/xlinit.c
   trunk/src/include/device/device.h
   trunk/src/include/device/resource.h
   trunk/src/northbridge/amd/amdfam10/northbridge.c
   trunk/src/northbridge/amd/amdk8/northbridge.c
   trunk/src/northbridge/amd/gx2/northbridge.c
   trunk/src/northbridge/amd/lx/northbridge.c
   trunk/src/northbridge/intel/e7520/northbridge.c
   trunk/src/northbridge/intel/e7525/northbridge.c
   trunk/src/northbridge/intel/i3100/northbridge.c
   trunk/src/southbridge/amd/sb600/sb600_lpc.c
   trunk/src/southbridge/amd/sb700/sb700_lpc.c
   trunk/src/southbridge/broadcom/bcm5785/bcm5785_lpc.c
   trunk/src/southbridge/nvidia/ck804/ck804_lpc.c
   trunk/src/southbridge/nvidia/mcp55/mcp55_lpc.c
   trunk/src/southbridge/sis/sis966/sis966_lpc.c
   trunk/src/superio/smsc/lpc47n217/superio.c
   trunk/src/superio/smsc/lpc47n227/superio.c
   trunk/src/superio/via/vt1211/vt1211.c
   trunk/util/sconfig/main.c

Modified: trunk/src/devices/device.c
==============================================================================
--- trunk/src/devices/device.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/devices/device.c	Fri May 21 16:33:48 2010	(r5576)
@@ -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 @@
 
 	/* 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 @@
 
 	/* 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 @@
 	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 @@
 {
 	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 @@
 	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 @@
 	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 @@
 		    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 @@
 	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 @@
 	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 @@
 	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 @@
 	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) {

Modified: trunk/src/devices/device_util.c
==============================================================================
--- trunk/src/devices/device_util.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/devices/device_util.c	Fri May 21 16:33:48 2010	(r5576)
@@ -261,25 +261,54 @@
 }
 
 /**
+ * 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.
  * @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 @@
  */
 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 *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 @@
 	/* 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 @@
 {
 	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 @@
 {
 	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 @@
 {
 	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 @@
 		  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 @@
 	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 @@
 	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 @@
 		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, "");
 	}
 }

Modified: trunk/src/devices/oprom/yabel/device.c
==============================================================================
--- trunk/src/devices/oprom/yabel/device.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/devices/oprom/yabel/device.c	Fri May 21 16:33:48 2010	(r5576)
@@ -53,8 +53,7 @@
 	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;

Modified: trunk/src/devices/pci_device.c
==============================================================================
--- trunk/src/devices/pci_device.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/devices/pci_device.c	Fri May 21 16:33:48 2010	(r5576)
@@ -550,14 +550,12 @@
 
 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;

Modified: trunk/src/devices/pnp_device.c
==============================================================================
--- trunk/src/devices/pnp_device.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/devices/pnp_device.c	Fri May 21 16:33:48 2010	(r5576)
@@ -132,14 +132,14 @@
 
 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);
 	}
 }
 

Modified: trunk/src/drivers/ati/ragexl/xlinit.c
==============================================================================
--- trunk/src/drivers/ati/ragexl/xlinit.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/drivers/ati/ragexl/xlinit.c	Fri May 21 16:33:48 2010	(r5576)
@@ -520,9 +520,9 @@
 #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 @@
 #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
         }

Modified: trunk/src/include/device/device.h
==============================================================================
--- trunk/src/include/device/device.h	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/include/device/device.h	Fri May 21 16:33:48 2010	(r5576)
@@ -74,11 +74,10 @@
 	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 @@
 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);

Modified: trunk/src/include/device/resource.h
==============================================================================
--- trunk/src/include/device/resource.h	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/include/device/resource.h	Fri May 21 16:33:48 2010	(r5576)
@@ -68,6 +68,7 @@
 	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 */

Modified: trunk/src/northbridge/amd/amdfam10/northbridge.c
==============================================================================
--- trunk/src/northbridge/amd/amdfam10/northbridge.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/northbridge/amd/amdfam10/northbridge.c	Fri May 21 16:33:48 2010	(r5576)
@@ -592,7 +592,7 @@
 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 @@
 	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 @@
 {
 #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 @@
 			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

Modified: trunk/src/northbridge/amd/amdk8/northbridge.c
==============================================================================
--- trunk/src/northbridge/amd/amdk8/northbridge.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/northbridge/amd/amdk8/northbridge.c	Fri May 21 16:33:48 2010	(r5576)
@@ -520,14 +520,13 @@
 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 @@
 {
 #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 @@
 		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

Modified: trunk/src/northbridge/amd/gx2/northbridge.c
==============================================================================
--- trunk/src/northbridge/amd/gx2/northbridge.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/northbridge/amd/gx2/northbridge.c	Fri May 21 16:33:48 2010	(r5576)
@@ -297,11 +297,9 @@
 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

Modified: trunk/src/northbridge/amd/lx/northbridge.c
==============================================================================
--- trunk/src/northbridge/amd/lx/northbridge.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/northbridge/amd/lx/northbridge.c	Fri May 21 16:33:48 2010	(r5576)
@@ -318,18 +318,18 @@
 
 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;

Modified: trunk/src/northbridge/intel/e7520/northbridge.c
==============================================================================
--- trunk/src/northbridge/intel/e7520/northbridge.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/northbridge/intel/e7520/northbridge.c	Fri May 21 16:33:48 2010	(r5576)
@@ -183,9 +183,8 @@
 
 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>");

Modified: trunk/src/northbridge/intel/e7525/northbridge.c
==============================================================================
--- trunk/src/northbridge/intel/e7525/northbridge.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/northbridge/intel/e7525/northbridge.c	Fri May 21 16:33:48 2010	(r5576)
@@ -183,9 +183,8 @@
 
 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>");

Modified: trunk/src/northbridge/intel/i3100/northbridge.c
==============================================================================
--- trunk/src/northbridge/intel/i3100/northbridge.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/northbridge/intel/i3100/northbridge.c	Fri May 21 16:33:48 2010	(r5576)
@@ -204,9 +204,8 @@
 
 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>");

Modified: trunk/src/southbridge/amd/sb600/sb600_lpc.c
==============================================================================
--- trunk/src/southbridge/amd/sb600/sb600_lpc.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/southbridge/amd/sb600/sb600_lpc.c	Fri May 21 16:33:48 2010	(r5576)
@@ -108,7 +108,6 @@
 {
 	u32 link;
 	u32 reg, reg_x;
-	int i;
 	int var_num = 0;
 	u16 reg_var[3];
 
@@ -122,10 +121,9 @@
 			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;

Modified: trunk/src/southbridge/amd/sb700/sb700_lpc.c
==============================================================================
--- trunk/src/southbridge/amd/sb700/sb700_lpc.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/southbridge/amd/sb700/sb700_lpc.c	Fri May 21 16:33:48 2010	(r5576)
@@ -120,7 +120,6 @@
 {
 	u32 link;
 	u32 reg, reg_x;
-	int i;
 	int var_num = 0;
 	u16 reg_var[3];
 
@@ -134,10 +133,9 @@
 			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;

Modified: trunk/src/southbridge/broadcom/bcm5785/bcm5785_lpc.c
==============================================================================
--- trunk/src/southbridge/broadcom/bcm5785/bcm5785_lpc.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/southbridge/broadcom/bcm5785/bcm5785_lpc.c	Fri May 21 16:33:48 2010	(r5576)
@@ -69,7 +69,6 @@
 {
         unsigned link;
 	uint32_t reg;
-	int i;
 
 	reg = pci_read_config8(dev, 0x44);
 
@@ -78,10 +77,9 @@
                 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);

Modified: trunk/src/southbridge/nvidia/ck804/ck804_lpc.c
==============================================================================
--- trunk/src/southbridge/nvidia/ck804/ck804_lpc.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/southbridge/nvidia/ck804/ck804_lpc.c	Fri May 21 16:33:48 2010	(r5576)
@@ -242,10 +242,9 @@
 		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;

Modified: trunk/src/southbridge/nvidia/mcp55/mcp55_lpc.c
==============================================================================
--- trunk/src/southbridge/nvidia/mcp55/mcp55_lpc.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/southbridge/nvidia/mcp55/mcp55_lpc.c	Fri May 21 16:33:48 2010	(r5576)
@@ -217,10 +217,9 @@
 		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);

Modified: trunk/src/southbridge/sis/sis966/sis966_lpc.c
==============================================================================
--- trunk/src/southbridge/sis/sis966/sis966_lpc.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/southbridge/sis/sis966/sis966_lpc.c	Fri May 21 16:33:48 2010	(r5576)
@@ -210,10 +210,9 @@
 		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);

Modified: trunk/src/superio/smsc/lpc47n217/superio.c
==============================================================================
--- trunk/src/superio/smsc/lpc47n217/superio.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/superio/smsc/lpc47n217/superio.c	Fri May 21 16:33:48 2010	(r5576)
@@ -99,15 +99,15 @@
  */
 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); */
 

Modified: trunk/src/superio/smsc/lpc47n227/superio.c
==============================================================================
--- trunk/src/superio/smsc/lpc47n227/superio.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/superio/smsc/lpc47n227/superio.c	Fri May 21 16:33:48 2010	(r5576)
@@ -96,14 +96,14 @@
 //
 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);
 }

Modified: trunk/src/superio/via/vt1211/vt1211.c
==============================================================================
--- trunk/src/superio/via/vt1211/vt1211.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/src/superio/via/vt1211/vt1211.c	Fri May 21 16:33:48 2010	(r5576)
@@ -127,15 +127,13 @@
 
 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 @@
 	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);

Modified: trunk/util/sconfig/main.c
==============================================================================
--- trunk/util/sconfig/main.c	Thu May 20 17:28:19 2010	(r5575)
+++ trunk/util/sconfig/main.c	Fri May 21 16:33:48 2010	(r5576)
@@ -278,8 +278,11 @@
 }
 
 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 @@
 		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 @@
 			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);




More information about the coreboot mailing list