Skip to content

Commit 47a650f

Browse files
Matthew Minterbjorn-helgaas
authored andcommitted
PCI: Add pci_assign_irq() function and have pci_fixup_irqs() use it
Here we delete the static pdev_fixup_irq() function which is currently what pci_fixup_irqs() uses to actually assign the IRQs and replace it with the pci_assign_irq() function which changes the interface and uses the new function pointers stored in the host bridge structure. Eventually this will allow pci_fixup_irqs() to be removed entirely and the new deferred assignment code path will call pci_assign_irq() directly. However to ensure current users continue to work, a new implementation of pci_fixup_irqs() is introduced which simply wraps the functionality of pci_assign_irq(). Signed-off-by: Matthew Minter <matt@masarand.com> [lorenzo.pieralisi@arm.com: reworked comments/log] Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 3aa8a41 commit 47a650f

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

drivers/pci/setup-irq.c

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,25 @@
1515
#include <linux/errno.h>
1616
#include <linux/ioport.h>
1717
#include <linux/cache.h>
18+
#include "pci.h"
1819

1920
void __weak pcibios_update_irq(struct pci_dev *dev, int irq)
2021
{
2122
dev_dbg(&dev->dev, "assigning IRQ %02d\n", irq);
2223
pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
2324
}
2425

25-
static void pdev_fixup_irq(struct pci_dev *dev,
26-
u8 (*swizzle)(struct pci_dev *, u8 *),
27-
int (*map_irq)(const struct pci_dev *, u8, u8))
26+
void pci_assign_irq(struct pci_dev *dev)
2827
{
29-
u8 pin, slot;
28+
u8 pin;
29+
u8 slot = -1;
3030
int irq = 0;
31+
struct pci_host_bridge *hbrg = pci_find_host_bridge(dev->bus);
32+
33+
if (!(hbrg->map_irq)) {
34+
dev_dbg(&dev->dev, "runtime IRQ mapping not provided by arch\n");
35+
return;
36+
}
3137

3238
/* If this device is not on the primary bus, we need to figure out
3339
which interrupt pin it will come in on. We know which slot it
@@ -40,17 +46,22 @@ static void pdev_fixup_irq(struct pci_dev *dev,
4046
if (pin > 4)
4147
pin = 1;
4248

43-
if (pin != 0) {
49+
if (pin) {
4450
/* Follow the chain of bridges, swizzling as we go. */
45-
slot = (*swizzle)(dev, &pin);
51+
if (hbrg->swizzle_irq)
52+
slot = (*(hbrg->swizzle_irq))(dev, &pin);
4653

47-
irq = (*map_irq)(dev, slot, pin);
54+
/*
55+
* If a swizzling function is not used map_irq must
56+
* ignore slot
57+
*/
58+
irq = (*(hbrg->map_irq))(dev, slot, pin);
4859
if (irq == -1)
4960
irq = 0;
5061
}
5162
dev->irq = irq;
5263

53-
dev_dbg(&dev->dev, "fixup irq: got %d\n", dev->irq);
64+
dev_dbg(&dev->dev, "assign IRQ: got %d\n", dev->irq);
5465

5566
/* Always tell the device, so the driver knows what is
5667
the real IRQ to use; the device does not use it. */
@@ -60,9 +71,23 @@ static void pdev_fixup_irq(struct pci_dev *dev,
6071
void pci_fixup_irqs(u8 (*swizzle)(struct pci_dev *, u8 *),
6172
int (*map_irq)(const struct pci_dev *, u8, u8))
6273
{
74+
/*
75+
* Implement pci_fixup_irqs() through pci_assign_irq().
76+
* This code should be remove eventually, it is a wrapper
77+
* around pci_assign_irq() interface to keep current
78+
* pci_fixup_irqs() behaviour unchanged on architecture
79+
* code still relying on its interface.
80+
*/
6381
struct pci_dev *dev = NULL;
82+
struct pci_host_bridge *hbrg = NULL;
6483

65-
for_each_pci_dev(dev)
66-
pdev_fixup_irq(dev, swizzle, map_irq);
84+
for_each_pci_dev(dev) {
85+
hbrg = pci_find_host_bridge(dev->bus);
86+
hbrg->swizzle_irq = swizzle;
87+
hbrg->map_irq = map_irq;
88+
pci_assign_irq(dev);
89+
hbrg->swizzle_irq = NULL;
90+
hbrg->map_irq = NULL;
91+
}
6792
}
6893
EXPORT_SYMBOL_GPL(pci_fixup_irqs);

include/linux/pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,7 @@ void pdev_enable_device(struct pci_dev *);
11471147
int pci_enable_resources(struct pci_dev *, int mask);
11481148
void pci_fixup_irqs(u8 (*)(struct pci_dev *, u8 *),
11491149
int (*)(const struct pci_dev *, u8, u8));
1150+
void pci_assign_irq(struct pci_dev *dev);
11501151
struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res);
11511152
#define HAVE_PCI_REQ_REGIONS 2
11521153
int __must_check pci_request_regions(struct pci_dev *, const char *);

0 commit comments

Comments
 (0)