From akpm@osdl.org Thu Apr 28 00:27:48 2005
Subject: [patch 04/20] acpi bridge hotadd: Make pcibios_fixup_bus() hot-plug safe
To: greg@kroah.com
Cc: akpm@osdl.org, rajesh.shah@intel.com
From: akpm@osdl.org
Date: Thu, 28 Apr 2005 00:25:46 -0700


From: Rajesh Shah <rajesh.shah@intel.com>

PCI scan code calls the arch specific pcibios_fixup_bus() each time it scans a
new bridge.  For root bridge hot-plug, the bridge and it's attached devices
may not have been configured properly yet, so it's not safe to claim those
resources at this time.

This code goes away when we clean up the way pci resources are claimed (in
pci_enable_device()), so this is only a stopgap fix.

Signed-off-by: Rajesh Shah <rajesh.shah@intel.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 arch/ia64/pci/pci.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletion(-)

--- gregkh-2.6.orig/arch/ia64/pci/pci.c	2005-05-03 22:28:18.000000000 -0700
+++ gregkh-2.6/arch/ia64/pci/pci.c	2005-05-03 22:28:20.000000000 -0700
@@ -391,6 +391,25 @@
 	res->end = region->end + offset;
 }
 
+static int __devinit is_valid_resource(struct pci_dev *dev, int idx)
+{
+	unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM;
+	struct resource *devr = &dev->resource[idx];
+
+	if (!dev->bus)
+		return 0;
+	for (i=0; i<PCI_BUS_NUM_RESOURCES; i++) {
+		struct resource *busr = dev->bus->resource[i];
+
+		if (!busr || ((busr->flags ^ devr->flags) & type_mask))
+			continue;
+		if ((devr->start) && (devr->start >= busr->start) &&
+				(devr->end <= busr->end))
+			return 1;
+	}
+	return 0;
+}
+
 static void __devinit pcibios_fixup_device_resources(struct pci_dev *dev)
 {
 	struct pci_bus_region region;
@@ -404,7 +423,8 @@
 		region.start = dev->resource[i].start;
 		region.end = dev->resource[i].end;
 		pcibios_bus_to_resource(dev, &dev->resource[i], &region);
-		pci_claim_resource(dev, i);
+		if ((is_valid_resource(dev, i)))
+			pci_claim_resource(dev, i);
 	}
 }