Skip to contentSkip to conversation

Implementation of pci_fixup_irqs for descendants of a specified bus

RFC PATCH In review Andrew Murray 2 participants 2 messages Jan 18, 2013 – Jan 31, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 Implementation of pci_fixup_irqs for descendants of a specified bus

Continuing from discussion with Thierry (lkml.org/lkml/2013/1/18/107) perhaps this will be useful to fold into your patchset.
---
This patch provides pci_bus_fixup_irqs which performs the same function as pci_fixup_irqs but only to descendants of the specified bus.

This can reduce unnecessary fixing up of device irqs when new buses are added.

---
 drivers/pci/setup-irq.c |   15 +++++++++++++++
 include/linux/pci.h     |    3 +++
 2 files changed, 18 insertions(+), 0 deletions(-)
drivers/pci/setup-irq.c +15 -0
index eb219a1..ea91874 100644
@@ -62,3 +62,18 @@ pci_fixup_irqs(u8 (*swizzle)(struct pci_dev *, u8 *),
 	for_each_pci_dev(dev)
 		pdev_fixup_irq(dev, swizzle, map_irq);
 }
+
+void __init
+pci_bus_fixup_irqs(struct pci_bus *bus,
+		u8 (*swizzle)(struct pci_dev *, u8 *),
+		int (*map_irq)(const struct pci_dev *, u8, u8))
+{
+	struct pci_dev *dev;
+
+	list_for_each_entry(dev, &bus->devices, bus_list) {
+		pdev_fixup_irq(dev, swizzle, map_irq);
+
+		if (dev->subordinate)
+			pci_bus_fixup_irqs(dev->subordinate, swizzle, map_irq);
+	}
+}
include/linux/pci.h +3 -0
index 5faa831..1b3c2eb 100644
@@ -953,6 +953,9 @@ void pdev_enable_device(struct pci_dev *);
 int pci_enable_resources(struct pci_dev *, int mask);
 void pci_fixup_irqs(u8 (*)(struct pci_dev *, u8 *),
 		    int (*)(const struct pci_dev *, u8, u8));
+void pci_bus_fixup_irqs(struct pci_bus *bus,
+		u8 (*swizzle)(struct pci_dev *, u8 *),
+		int (*map_irq)(const struct pci_dev *, u8, u8));
 #define HAVE_PCI_REQ_REGIONS	2
 int __must_check pci_request_regions(struct pci_dev *, const char *);
 int __must_check pci_request_regions_exclusive(struct pci_dev *, const char *);
Signature · 1 line
1.7.0.4
maintainer
#1 lore raw
Quoted 6 lines · Andrew Murray

Continuing from discussion with Thierry (lkml.org/lkml/2013/1/18/107) perhaps this will be useful to fold into your patchset.
---
This patch provides pci_bus_fixup_irqs which performs the same function as pci_fixup_irqs but only to descendants of the specified bus.

I think pci_fixup_irqs() is a broken design to begin with because it is only called once at boot-time and it iterates over all the devices we've found so far. Any hot-added devices never get the fixups.

Adding pci_bus_fixup_irqs() addresses part of that, by adding a way to fixup a subset of devices, e.g., maybe it could be done for hot-added things.

But I think it would be better to do a more extensive refactoring and do the IRQ fixups directly somewhere in the pci_device_add() path. That way we can do it a device at a time, for every device (present at boot and hot-added later), and before any drivers claim the device.

Quoted 51 lines

This can reduce unnecessary fixing up of device irqs when new buses are added.

---
 drivers/pci/setup-irq.c |   15 +++++++++++++++
 include/linux/pci.h     |    3 +++
 2 files changed, 18 insertions(+), 0 deletions(-)
drivers/pci/setup-irq.c +15 -0
index eb219a1..ea91874 100644
@@ -62,3 +62,18 @@ pci_fixup_irqs(u8 (*swizzle)(struct pci_dev *, u8 *),
        for_each_pci_dev(dev)
                pdev_fixup_irq(dev, swizzle, map_irq);
 }
+
+void __init
+pci_bus_fixup_irqs(struct pci_bus *bus,
+               u8 (*swizzle)(struct pci_dev *, u8 *),
+               int (*map_irq)(const struct pci_dev *, u8, u8))
+{
+       struct pci_dev *dev;
+
+       list_for_each_entry(dev, &bus->devices, bus_list) {
+               pdev_fixup_irq(dev, swizzle, map_irq);
+
+               if (dev->subordinate)
+                       pci_bus_fixup_irqs(dev->subordinate, swizzle, map_irq);
+       }
+}
include/linux/pci.h +3 -1
index 5faa831..1b3c2eb 100644
@@ -953,6 +953,9 @@ void pdev_enable_device(struct pci_dev *);
 int pci_enable_resources(struct pci_dev *, int mask);
 void pci_fixup_irqs(u8 (*)(struct pci_dev *, u8 *),
                    int (*)(const struct pci_dev *, u8, u8));
+void pci_bus_fixup_irqs(struct pci_bus *bus,
+               u8 (*swizzle)(struct pci_dev *, u8 *),
+               int (*map_irq)(const struct pci_dev *, u8, u8));
 #define HAVE_PCI_REQ_REGIONS   2
 int __must_check pci_request_regions(struct pci_dev *, const char *);
 int __must_check pci_request_regions_exclusive(struct pci_dev *, const char *);
--

1.7.0.4