public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fakephp: Allocate PCI resources before adding the device
@ 2008-11-25 21:24 Darrick J. Wong
  2008-11-25 21:43 ` Greg KH
  2008-11-26  4:46 ` Trent Piepho
  0 siblings, 2 replies; 38+ messages in thread
From: Darrick J. Wong @ 2008-11-25 21:24 UTC (permalink / raw)
  To: Darrick J. Wong, Greg K-H; +Cc: linux-kernel

For PCI devices, pci_bus_assign_resources() must be called to set up the
pci_device->resource array before pci_bus_add_devices() can be called, else
attempts to load drivers results in BAR collision errors where there are none.
This is not done in fakephp, so devices can be "unplugged" but scanning the
parent bus won't bring the devices back due to resource unallocation.  Move the
pci_bus_add_device-calling logic into pci_rescan_bus and preface it with a call
to pci_bus_assign_resources so that we only have to (re)allocate resources once
per bus where a new device is found.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
---
 drivers/pci/hotplug/fakephp.c |   42 +++++++++++++++++++++++++----------------
 1 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
index 3a2637a..a3826e6 100644
--- a/drivers/pci/hotplug/fakephp.c
+++ b/drivers/pci/hotplug/fakephp.c
@@ -195,13 +195,13 @@ static void remove_slot_worker(struct work_struct *work)
  * Tries hard not to re-enable already existing devices;
  * also handles scanning of subfunctions.
  */
-static void pci_rescan_slot(struct pci_dev *temp)
+static int pci_rescan_slot(struct pci_dev *temp)
 {
 	struct pci_bus *bus = temp->bus;
 	struct pci_dev *dev;
 	int func;
-	int retval;
 	u8 hdr_type;
+	int count = 0;
 
 	if (!pci_read_config_byte(temp, PCI_HEADER_TYPE, &hdr_type)) {
 		temp->hdr_type = hdr_type & 0x7f;
@@ -213,17 +213,12 @@ static void pci_rescan_slot(struct pci_dev *temp)
 				dbg("New device on %s function %x:%x\n",
 					bus->name, temp->devfn >> 3,
 					temp->devfn & 7);
-				retval = pci_bus_add_device(dev);
-				if (retval)
-					dev_err(&dev->dev, "error adding "
-						"device, continuing.\n");
-				else
-					add_slot(dev);
+				count++;
 			}
 		}
 		/* multifunction device? */
 		if (!(hdr_type & 0x80))
-			return;
+			return count;
 
 		/* continue scanning for other functions */
 		for (func = 1, temp->devfn++; func < 8; func++, temp->devfn++) {
@@ -239,16 +234,13 @@ static void pci_rescan_slot(struct pci_dev *temp)
 					dbg("New device on %s function %x:%x\n",
 						bus->name, temp->devfn >> 3,
 						temp->devfn & 7);
-					retval = pci_bus_add_device(dev);
-					if (retval)
-						dev_err(&dev->dev, "error adding "
-							"device, continuing.\n");
-					else
-						add_slot(dev);
+					count++;
 				}
 			}
 		}
 	}
+
+	return count;
 }
 
 
@@ -262,6 +254,8 @@ static void pci_rescan_bus(const struct pci_bus *bus)
 {
 	unsigned int devfn;
 	struct pci_dev *dev;
+	int retval;
+	int found = 0;
 	dev = alloc_pci_dev();
 	if (!dev)
 		return;
@@ -270,7 +264,23 @@ static void pci_rescan_bus(const struct pci_bus *bus)
 	dev->sysdata = bus->sysdata;
 	for (devfn = 0; devfn < 0x100; devfn += 8) {
 		dev->devfn = devfn;
-		pci_rescan_slot(dev);
+		found += pci_rescan_slot(dev);
+	}
+
+	if (found) {
+		pci_bus_assign_resources(bus);
+		list_for_each_entry(dev, &bus->devices, bus_list) {
+			/* Skip already-added devices */
+			if (dev->is_added)
+					continue;
+			retval = pci_bus_add_device(dev);
+			if (retval)
+				dev_err(&dev->dev,
+					"Error adding device, continuing\n");
+			else
+				add_slot(dev);
+		}
+		pci_bus_add_devices(bus);
 	}
 	kfree(dev);
 }


^ permalink raw reply related	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2008-12-21  2:23 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-25 21:24 [PATCH] fakephp: Allocate PCI resources before adding the device Darrick J. Wong
2008-11-25 21:43 ` Greg KH
2008-11-26  4:46 ` Trent Piepho
2008-11-26  7:48   ` Darrick J. Wong
2008-11-26  9:56     ` Trent Piepho
2008-11-26 18:18       ` Darrick J. Wong
2008-11-26 22:23         ` Trent Piepho
2008-11-26 22:55           ` Alex Chiang
2008-11-27  1:44             ` Trent Piepho
2008-11-27  2:42               ` Matthew Wilcox
2008-11-28 10:11                 ` Trent Piepho
2008-11-28 18:57                   ` Matthew Wilcox
2008-11-28 21:21                     ` Trent Piepho
2008-11-28 21:30                       ` Matthew Wilcox
2008-12-01  1:10                         ` Problems with fakephp Trent Piepho
2008-12-16 20:28                           ` fixup PCI device booleans in sysfs Jesse Barnes
2008-11-28 23:18               ` [PATCH] fakephp: Allocate PCI resources before adding the device Alex Chiang
2008-12-01 13:00                 ` Problems with fakephp Trent Piepho
2008-12-02  3:16                   ` Alex Chiang
2008-12-03  4:07                     ` Trent Piepho
2008-12-03  4:38                       ` Alex Chiang
2008-12-03 17:22                         ` Rolf Eike Beer
2008-12-03 17:43                           ` Alex Chiang
2008-12-03 17:55                             ` Rolf Eike Beer
2008-12-03 18:22                               ` Alex Chiang
2008-12-08 21:09                                 ` Rolf Eike Beer
2008-12-01 13:36                 ` Trent Piepho
2008-12-01 14:08                   ` [PATCH] PCI: Method for removing PCI devices Trent Piepho
2008-12-01 14:40                     ` Greg KH
2008-12-01 14:08                   ` [PATCH] PCI: Legacy fakephp driver Trent Piepho
2008-11-27  1:52             ` [PATCH] fakephp: Allocate PCI resources before adding the device Darrick J. Wong
2008-11-28  9:51               ` Trent Piepho
2008-11-28 18:42                 ` Rolf Eike Beer
2008-11-28 21:06                   ` Trent Piepho
2008-12-01 17:08                     ` Rolf Eike Beer
2008-12-16 19:33                       ` Jesse Barnes
2008-12-16 20:56                         ` [PATCH] fakephp: Allocate PCI resources before adding the?device Darrick J. Wong
2008-12-21  2:23                           ` Trent Piepho

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox