Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame^] | 18 | #include "pci.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Thierry Reding | 8885b7b | 2012-09-17 13:22:54 +0200 | [diff] [blame] | 20 | void __weak pcibios_update_irq(struct pci_dev *dev, int irq) |
| 21 | { |
| 22 | dev_dbg(&dev->dev, "assigning IRQ %02d\n", irq); |
| 23 | pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq); |
| 24 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame^] | 26 | void pci_assign_irq(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | { |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame^] | 28 | u8 pin; |
| 29 | u8 slot = -1; |
Andreas Block | 691cd0c | 2007-02-05 16:36:07 -0800 | [diff] [blame] | 30 | int irq = 0; |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame^] | 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 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | /* If this device is not on the primary bus, we need to figure out |
| 39 | which interrupt pin it will come in on. We know which slot it |
| 40 | will come in on 'cos that slot is where the bridge is. Each |
| 41 | time the interrupt line passes through a PCI-PCI bridge we must |
| 42 | apply the swizzle function. */ |
| 43 | |
| 44 | pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); |
Andreas Block | 691cd0c | 2007-02-05 16:36:07 -0800 | [diff] [blame] | 45 | /* Cope with illegal. */ |
| 46 | if (pin > 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | pin = 1; |
| 48 | |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame^] | 49 | if (pin) { |
Andreas Block | 691cd0c | 2007-02-05 16:36:07 -0800 | [diff] [blame] | 50 | /* Follow the chain of bridges, swizzling as we go. */ |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame^] | 51 | if (hbrg->swizzle_irq) |
| 52 | slot = (*(hbrg->swizzle_irq))(dev, &pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame^] | 54 | /* |
| 55 | * If a swizzling function is not used map_irq must |
| 56 | * ignore slot |
| 57 | */ |
| 58 | irq = (*(hbrg->map_irq))(dev, slot, pin); |
Andreas Block | 691cd0c | 2007-02-05 16:36:07 -0800 | [diff] [blame] | 59 | if (irq == -1) |
| 60 | irq = 0; |
| 61 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | dev->irq = irq; |
| 63 | |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame^] | 64 | dev_dbg(&dev->dev, "assign IRQ: got %d\n", dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | /* Always tell the device, so the driver knows what is |
| 67 | the real IRQ to use; the device does not use it. */ |
| 68 | pcibios_update_irq(dev, irq); |
| 69 | } |
| 70 | |
Ryan Desfosses | 3c78bc6 | 2014-04-18 20:13:49 -0400 | [diff] [blame] | 71 | void pci_fixup_irqs(u8 (*swizzle)(struct pci_dev *, u8 *), |
| 72 | int (*map_irq)(const struct pci_dev *, u8, u8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame^] | 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 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | struct pci_dev *dev = NULL; |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame^] | 82 | struct pci_host_bridge *hbrg = NULL; |
Ryan Desfosses | 3c78bc6 | 2014-04-18 20:13:49 -0400 | [diff] [blame] | 83 | |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame^] | 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 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
Ray Jui | e6b29de | 2015-04-08 11:21:33 -0700 | [diff] [blame] | 93 | EXPORT_SYMBOL_GPL(pci_fixup_irqs); |