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 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/pci.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/ioport.h> |
| 18 | #include <linux/cache.h> |
| 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 | |
Thierry Reding | 3ddbebf | 2012-09-17 13:22:53 +0200 | [diff] [blame] | 26 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | pdev_fixup_irq(struct pci_dev *dev, |
| 28 | u8 (*swizzle)(struct pci_dev *, u8 *), |
Ralf Baechle | d534194 | 2011-06-10 15:30:21 +0100 | [diff] [blame] | 29 | int (*map_irq)(const struct pci_dev *, u8, u8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | { |
| 31 | u8 pin, slot; |
Andreas Block | 691cd0c | 2007-02-05 16:36:07 -0800 | [diff] [blame] | 32 | int irq = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | /* If this device is not on the primary bus, we need to figure out |
| 35 | which interrupt pin it will come in on. We know which slot it |
| 36 | will come in on 'cos that slot is where the bridge is. Each |
| 37 | time the interrupt line passes through a PCI-PCI bridge we must |
| 38 | apply the swizzle function. */ |
| 39 | |
| 40 | pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); |
Andreas Block | 691cd0c | 2007-02-05 16:36:07 -0800 | [diff] [blame] | 41 | /* Cope with illegal. */ |
| 42 | if (pin > 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | pin = 1; |
| 44 | |
Andreas Block | 691cd0c | 2007-02-05 16:36:07 -0800 | [diff] [blame] | 45 | if (pin != 0) { |
| 46 | /* Follow the chain of bridges, swizzling as we go. */ |
| 47 | slot = (*swizzle)(dev, &pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Andreas Block | 691cd0c | 2007-02-05 16:36:07 -0800 | [diff] [blame] | 49 | irq = (*map_irq)(dev, slot, pin); |
| 50 | if (irq == -1) |
| 51 | irq = 0; |
| 52 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | dev->irq = irq; |
| 54 | |
Bjorn Helgaas | 80ccba1 | 2008-06-13 10:52:11 -0600 | [diff] [blame] | 55 | dev_dbg(&dev->dev, "fixup irq: got %d\n", dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | /* Always tell the device, so the driver knows what is |
| 58 | the real IRQ to use; the device does not use it. */ |
| 59 | pcibios_update_irq(dev, irq); |
| 60 | } |
| 61 | |
Thierry Reding | 3ddbebf | 2012-09-17 13:22:53 +0200 | [diff] [blame] | 62 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | pci_fixup_irqs(u8 (*swizzle)(struct pci_dev *, u8 *), |
Ralf Baechle | d534194 | 2011-06-10 15:30:21 +0100 | [diff] [blame] | 64 | int (*map_irq)(const struct pci_dev *, u8, u8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { |
| 66 | struct pci_dev *dev = NULL; |
Kulikov Vasiliy | 4e344b1 | 2010-07-03 20:04:39 +0400 | [diff] [blame] | 67 | for_each_pci_dev(dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | pdev_fixup_irq(dev, swizzle, map_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |