[PATCH v2 04/16] PCI: Add pci_assign_unassigned_slot_resources()
From: Ilpo Järvinen
Date: Fri Nov 20 2026 - 08:48:24 EST
Bridge window sizing and resource assignment need locks that are held
across both phases. acpiphp open-codes
pci_assign_unassigned_bus_resources() with a slot filter by calling the
internal sizing and assignment functions directly, so it would have to
duplicate that locking.
Add pci_assign_unassigned_slot_resources() which sizes only the bridges
in the given slot, and implement pci_assign_unassigned_bus_resources()
with it.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
drivers/pci/pci.h | 1 +
drivers/pci/setup-bus.c | 23 +++++++++++++++++++++--
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 77efa4c5c960..ce29d9ca0194 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -542,6 +542,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus,
void __pci_bus_assign_resources(const struct pci_bus *bus,
struct list_head *add_list,
struct list_head *fail_head);
+void pci_assign_unassigned_slot_resources(struct pci_bus *bus, u16 slot);
bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
void pci_walk_bus_locked(struct pci_bus *top,
int (*cb)(struct pci_dev *, void *),
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 10b9d3eb2864..7d135ddd93b2 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -2489,19 +2489,38 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
exclude_bars);
}
-void pci_assign_unassigned_bus_resources(struct pci_bus *bus)
+/**
+ * pci_assign_unassigned_slot_resources - Size and assign resources of a slot
+ * @bus: PCI bus
+ * @slot: Slot whose bridges to size, or %PCI_SLOT_ALL_DEVICES for all
+ * bridges on @bus
+ *
+ * Size the bridge windows of the bridges in @slot and assign unassigned
+ * resources on @bus.
+ */
+void pci_assign_unassigned_slot_resources(struct pci_bus *bus, u16 slot)
{
struct pci_dev *dev;
/* List of resources that want additional resources */
LIST_HEAD(add_list);
down_read(&pci_bus_sem);
- for_each_pci_bridge(dev, bus)
+ for_each_pci_bridge(dev, bus) {
+ if (slot != PCI_SLOT_ALL_DEVICES &&
+ PCI_SLOT(dev->devfn) != slot)
+ continue;
+
if (pci_has_subordinate(dev))
__pci_bus_size_bridges(dev->subordinate, &add_list);
+ }
up_read(&pci_bus_sem);
__pci_bus_assign_resources(bus, &add_list, NULL);
}
+
+void pci_assign_unassigned_bus_resources(struct pci_bus *bus)
+{
+ pci_assign_unassigned_slot_resources(bus, PCI_SLOT_ALL_DEVICES);
+}
EXPORT_SYMBOL_GPL(pci_assign_unassigned_bus_resources);
void pci_bus_size_and_assign_resources(struct pci_bus *bus)
--
2.47.3