[PATCH 2/5] Construct one fakephp slot per pci slot

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <gregkh@...>, <kristen.c.accardi@...>, <lenb@...>, <matthew@...>, <rick.jones2@...>, <linux-kernel@...>, <linux-pci@...>, <pcihpd-discuss@...>, <linux-acpi@...>
Date: Monday, November 12, 2007 - 8:13 pm

Register one slot per slot, rather than one slot per function.
Change the name of the slot to fake%d instead of the pci address.

Signed-off-by: Alex Chiang <achiang@hp.com>
Signed-off-by: Matthew Wilcox <matthew@wil.cx>
---
 drivers/pci/hotplug/fakephp.c |   75 +++++++++++++++--------------------------
 1 files changed, 27 insertions(+), 48 deletions(-)

diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
index 027f686..828335e 100644
--- a/drivers/pci/hotplug/fakephp.c
+++ b/drivers/pci/hotplug/fakephp.c
@@ -93,6 +93,7 @@ static int add_slot(struct pci_dev *dev)
 	struct dummy_slot *dslot;
 	struct hotplug_slot *slot;
 	int retval = -ENOMEM;
+	static int count = 1;
 
 	slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
 	if (!slot)
@@ -106,7 +107,8 @@ static int add_slot(struct pci_dev *dev)
 	slot->info->max_bus_speed = PCI_SPEED_UNKNOWN;
 	slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN;
 
-	slot->name = &dev->dev.bus_id[0];
+	slot->name = kmalloc(8, GFP_KERNEL);
+	sprintf(slot->name, "fake%d", count++);
 	dbg("slot->name = %s\n", slot->name);
 
 	dslot = kmalloc(sizeof(struct dummy_slot), GFP_KERNEL);
@@ -141,17 +143,17 @@ error:
 static int __init pci_scan_buses(void)
 {
 	struct pci_dev *dev = NULL;
-	int retval = 0;
+	int lastslot = 0;
 
 	while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
-		retval = add_slot(dev);
-		if (retval) {
-			pci_dev_put(dev);
-			break;
-		}
+		if (PCI_FUNC(dev->devfn) > 0 &&
+				lastslot == PCI_SLOT(dev->devfn))
+			continue;
+		lastslot = PCI_SLOT(dev->devfn);
+		add_slot(dev);
 	}
 
-	return retval;
+	return 0;
 }
 
 static void remove_slot(struct dummy_slot *dslot)
@@ -275,23 +277,9 @@ static int enable_slot(struct hotplug_slot *hotplug_slot)
 	return -ENODEV;
 }
 
-/* find the hotplug_slot for the pci_dev */
-static struct hotplug_slot *get_slot_from_dev(struct pci_dev *dev)
-{
-	struct dummy_slot *dslot;
-
-	list_for_each_entry(dslot, &slot_list, node) {
-		if (dslot->dev == dev)
-			return dslot->slot;
-	}
-	return NULL;
-}
-
-
 static int disable_slot(struct hotplug_slot *slot)
 {
 	struct dummy_slot *dslot;
-	struct hotplug_slot *hslot;
 	struct pci_dev *dev;
 	int func;
 
@@ -301,36 +289,27 @@ static int disable_slot(struct hotplug_slot *slot)
 
 	dbg("%s - physical_slot = %s\n", __FUNCTION__, slot->name);
 
-	/* don't disable bridged devices just yet, we can't handle them easily... */
-	if (dslot->dev->subordinate) {
-		err("Can't remove PCI devices with other PCI devices behind it yet.\n");
-		return -ENODEV;
-	}
-	/* search for subfunctions and disable them first */
-	if (!(dslot->dev->devfn & 7)) {
-		for (func = 1; func < 8; func++) {
-			dev = pci_get_slot(dslot->dev->bus,
-					dslot->dev->devfn + func);
-			if (dev) {
-				hslot = get_slot_from_dev(dev);
-				if (hslot)
-					disable_slot(hslot);
-				else {
-					err("Hotplug slot not found for subfunction of PCI device\n");
-					return -ENODEV;
-				}
-				pci_dev_put(dev);
-			} else
-				dbg("No device in slot found\n");
+	for (func = 7; func >= 0; func--) {
+		dev = pci_get_slot(dslot->dev->bus, dslot->dev->devfn + func);
+		if (!dev)
+			continue;
+
+		/* don't disable bridged devices just yet, we can't handle
+		 * them easily... */
+		if (dev->subordinate) {
+			err("Can't remove PCI devices with other PCI devices behind it yet.\n");
+			return -ENODEV;
 		}
-	}
 
-	/* remove the device from the pci core */
-	pci_remove_bus_device(dslot->dev);
 
-	/* blow away this sysfs entry and other parts. */
-	remove_slot(dslot);
+		/* remove the device from the pci core */
+		pci_remove_bus_device(dslot->dev);
 
+		/* blow away this sysfs entry and other parts. */
+		remove_slot(dslot);
+
+		pci_dev_put(dev);
+	}
 	return 0;
 }
 
-- 
1.5.3.1.1.g1e61

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/5][RFC] Physical PCI slot objects, Alex Chiang, (Mon Nov 12, 8:08 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Kenji Kaneshige, (Wed Nov 14, 7:43 am)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Greg KH, (Tue Nov 13, 1:01 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Andi Kleen, (Tue Nov 13, 9:07 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Matthew Wilcox, (Wed Nov 14, 10:17 am)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Andi Kleen, (Wed Nov 14, 10:35 am)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Matthew Wilcox, (Wed Nov 14, 11:00 am)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Andi Kleen, (Wed Nov 14, 11:08 am)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Alex Chiang, (Wed Nov 14, 11:20 am)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Matthew Wilcox, (Wed Nov 14, 11:12 am)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Linas Vepstas, (Tue Nov 13, 4:24 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Alex Chiang, (Tue Nov 13, 4:59 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Linas Vepstas, (Tue Nov 13, 5:41 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Matthew Wilcox, (Tue Nov 13, 5:58 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Alex Chiang, (Tue Nov 13, 4:21 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Greg KH, (Tue Nov 13, 4:26 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Matthew Garrett, (Wed Nov 14, 1:44 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Greg KH, (Wed Nov 14, 1:51 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Matthew Garrett, (Wed Nov 14, 2:03 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Kristen Carlson Accardi, (Tue Nov 13, 6:59 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Bjorn Helgaas, (Wed Nov 14, 1:37 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Greg KH, (Wed Nov 14, 1:53 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Alex Chiang, (Wed Nov 14, 5:42 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Greg KH, (Wed Nov 14, 6:00 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Alex Chiang, (Thu Nov 15, 4:20 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Alex Chiang, (Wed Nov 14, 5:24 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Alex Chiang, (Wed Nov 14, 3:53 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Rick Jones, (Tue Nov 13, 6:51 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Greg KH, (Tue Nov 13, 6:56 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Matthew Wilcox, (Tue Nov 13, 7:04 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Kristen Carlson Accardi, (Tue Nov 13, 7:33 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Matthew Wilcox, (Tue Nov 13, 8:10 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Kenji Kaneshige, (Wed Nov 14, 5:55 am)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Kristen Carlson Accardi, (Wed Nov 14, 2:38 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Greg KH, (Tue Nov 13, 7:07 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Scott Murray, (Wed Nov 14, 2:00 am)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Matthew Wilcox, (Tue Nov 13, 2:33 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Greg KH, (Tue Nov 13, 2:51 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Matt Domsch, (Tue Nov 13, 5:15 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Greg KH, (Tue Nov 13, 5:32 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Alex Chiang, (Tue Nov 13, 5:31 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Greg KH, (Tue Nov 13, 5:36 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Alex Chiang, (Tue Nov 13, 7:14 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Alex Chiang, (Tue Nov 13, 4:36 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Greg KH, (Tue Nov 13, 5:30 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Bjorn Helgaas, (Tue Nov 13, 6:01 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Greg KH, (Tue Nov 13, 6:16 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Matthew Wilcox, (Tue Nov 13, 4:11 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Gary Hade, (Tue Nov 13, 7:08 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Alex Chiang, (Wed Nov 14, 10:42 am)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Gary Hade, (Wed Nov 14, 2:13 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Alex Chiang, (Wed Nov 14, 2:36 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Alex Chiang, (Tue Nov 13, 9:37 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Gary Hade, (Wed Nov 14, 8:40 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Alex Chiang, (Thu Nov 15, 1:36 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Gary Hade, (Thu Nov 15, 7:38 pm)
Re: [PATCH 0/5][RFC] Physical PCI slot objects, Greg KH, (Tue Nov 13, 4:19 pm)
[PATCH 4/5, RFC] ACPI PCI slot detection driver, Alex Chiang, (Mon Nov 12, 8:17 pm)
[PATCH 5/5] Add pci_slot_add_hotplug() interface, Alex Chiang, (Mon Nov 12, 8:18 pm)
[PATCH 3/5, RFC] Introduce pci_slot, Alex Chiang, (Mon Nov 12, 8:14 pm)
Re: [PATCH 3/5, RFC] Introduce pci_slot, Linas Vepstas, (Tue Nov 13, 3:56 pm)
Re: [PATCH 3/5, RFC] Introduce pci_slot, Matthew Wilcox, (Tue Nov 13, 4:03 pm)
[PATCH 2/5] Construct one fakephp slot per pci slot, Alex Chiang, (Mon Nov 12, 8:13 pm)
Re: [PATCH 2/5] Construct one fakephp slot per pci slot, Linas Vepstas, (Tue Nov 13, 3:48 pm)
Re: [PATCH 2/5] Construct one fakephp slot per pci slot, Matthew Wilcox, (Tue Nov 13, 3:52 pm)
[PATCH 1/5] Remove path attribute from sgi_hotplug, Alex Chiang, (Mon Nov 12, 8:12 pm)