Kyle Swenson | 8d8f654 | 2021-03-15 11:02:55 -0600 | [diff] [blame] | 1 | /* |
| 2 | * drivers/pci/setup-irq.c |
| 3 | * |
| 4 | * Extruded from code written by |
| 5 | * Dave Rusling (david.rusling@reo.mts.dec.com) |
| 6 | * David Mosberger (davidm@cs.arizona.edu) |
| 7 | * David Miller (davem@redhat.com) |
| 8 | * |
| 9 | * Support routines for initializing a PCI subsystem. |
| 10 | */ |
| 11 | |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/pci.h> |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/ioport.h> |
| 17 | #include <linux/cache.h> |
| 18 | |
| 19 | void __weak pcibios_update_irq(struct pci_dev *dev, int irq) |
| 20 | { |
| 21 | dev_dbg(&dev->dev, "assigning IRQ %02d\n", irq); |
| 22 | pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq); |
| 23 | } |
| 24 | |
| 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)) |
| 28 | { |
| 29 | u8 pin, slot; |
| 30 | int irq = 0; |
| 31 | |
Kyle Swenson | e01461f | 2021-03-15 11:14:57 -0600 | [diff] [blame] | 32 | #ifdef CONFIG_BCM47XX |
| 33 | if (pci_domain_nr(dev->bus) == 0) |
| 34 | return; |
| 35 | #endif |
| 36 | |
Kyle Swenson | 8d8f654 | 2021-03-15 11:02:55 -0600 | [diff] [blame] | 37 | /* If this device is not on the primary bus, we need to figure out |
| 38 | which interrupt pin it will come in on. We know which slot it |
| 39 | will come in on 'cos that slot is where the bridge is. Each |
| 40 | time the interrupt line passes through a PCI-PCI bridge we must |
| 41 | apply the swizzle function. */ |
| 42 | |
| 43 | pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); |
| 44 | /* Cope with illegal. */ |
| 45 | if (pin > 4) |
| 46 | pin = 1; |
| 47 | |
| 48 | if (pin != 0) { |
| 49 | /* Follow the chain of bridges, swizzling as we go. */ |
| 50 | slot = (*swizzle)(dev, &pin); |
| 51 | |
| 52 | irq = (*map_irq)(dev, slot, pin); |
| 53 | if (irq == -1) |
| 54 | irq = 0; |
| 55 | } |
| 56 | dev->irq = irq; |
| 57 | |
| 58 | dev_dbg(&dev->dev, "fixup irq: got %d\n", dev->irq); |
| 59 | |
| 60 | /* Always tell the device, so the driver knows what is |
| 61 | the real IRQ to use; the device does not use it. */ |
| 62 | pcibios_update_irq(dev, irq); |
| 63 | } |
| 64 | |
| 65 | void pci_fixup_irqs(u8 (*swizzle)(struct pci_dev *, u8 *), |
| 66 | int (*map_irq)(const struct pci_dev *, u8, u8)) |
| 67 | { |
| 68 | struct pci_dev *dev = NULL; |
| 69 | |
| 70 | for_each_pci_dev(dev) |
| 71 | pdev_fixup_irq(dev, swizzle, map_irq); |
| 72 | } |
| 73 | EXPORT_SYMBOL_GPL(pci_fixup_irqs); |