===================================================================
@@ -687,10 +687,11 @@ static unsigned int get_slot_status(stru
}
/**
- * trim_stale_devices - remove PCI devices that are not responding.
+ * find_stale_devices - Select PCI devices that are not responding for removal.
* @dev: PCI device to start walking the hierarchy from.
+ * @trim_list: List of devices to remove.
*/
-static void trim_stale_devices(struct pci_dev *dev)
+static void find_stale_devices(struct pci_dev *dev, struct list_head *trim_list)
{
acpi_handle handle = ACPI_HANDLE(&dev->dev);
struct pci_bus *bus = dev->subordinate;
@@ -710,21 +711,46 @@ static void trim_stale_devices(struct pc
alive = pci_bus_read_dev_vendor_id(dev->bus, dev->devfn, &v, 0);
}
if (!alive) {
- pci_stop_and_remove_bus_device(dev);
- if (handle)
- acpiphp_bus_trim(handle);
+ pci_dev_get(dev);
+ list_move(&dev->bus_list, trim_list);
} else if (bus) {
struct pci_dev *child, *tmp;
/* The device is a bridge. so check the bus below it. */
pm_runtime_get_sync(&dev->dev);
list_for_each_entry_safe(child, tmp, &bus->devices, bus_list)
- trim_stale_devices(child);
+ find_stale_devices(child, trim_list);
pm_runtime_put(&dev->dev);
}
}
+void acpiphp_trim_stale_devices(struct acpiphp_slot *slot)
+{
+ struct pci_bus *bus = slot->bus;
+ struct pci_dev *dev, *tmp;
+ LIST_HEAD(trim_list);
+
+ down_write(&pci_bus_sem);
+
+ list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list)
+ if (PCI_SLOT(dev->devfn) == slot->device)
+ find_stale_devices(dev, &trim_list);
+
+ up_write(&pci_bus_sem);
+
+ while (!list_empty(&trim_list)) {
+ acpi_handle handle;
+
+ dev = list_first_entry(&trim_list, struct pci_dev, bus_list);
+ handle = ACPI_HANDLE(&dev->dev);
+ pci_stop_and_remove_bus_device(dev);
+ pci_dev_put(dev);
+ if (handle)
+ acpiphp_bus_trim(handle);
+ }
+}
+
/**
* acpiphp_check_bridge - re-enumerate devices
* @bridge: where to begin re-enumeration
@@ -737,18 +763,11 @@ static void acpiphp_check_bridge(struct
struct acpiphp_slot *slot;
list_for_each_entry(slot, &bridge->slots, node) {
- struct pci_bus *bus = slot->bus;
- struct pci_dev *dev, *tmp;
-
mutex_lock(&slot->crit_sect);
/* wake up all functions */
if (get_slot_status(slot) == ACPI_STA_ALL) {
/* remove stale devices if any */
- list_for_each_entry_safe(dev, tmp, &bus->devices,
- bus_list)
- if (PCI_SLOT(dev->devfn) == slot->device)
- trim_stale_devices(dev);
-
+ acpiphp_trim_stale_devices(slot);
/* configure all functions */
enable_slot(slot);
} else {