blob: eb219a1d16f760f4596dded6e9811b006946586d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
20
21static void __init
22pdev_fixup_irq(struct pci_dev *dev,
23 u8 (*swizzle)(struct pci_dev *, u8 *),
Ralf Baechled5341942011-06-10 15:30:21 +010024 int (*map_irq)(const struct pci_dev *, u8, u8))
Linus Torvalds1da177e2005-04-16 15:20:36 -070025{
26 u8 pin, slot;
Andreas Block691cd0c2007-02-05 16:36:07 -080027 int irq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29 /* If this device is not on the primary bus, we need to figure out
30 which interrupt pin it will come in on. We know which slot it
31 will come in on 'cos that slot is where the bridge is. Each
32 time the interrupt line passes through a PCI-PCI bridge we must
33 apply the swizzle function. */
34
35 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
Andreas Block691cd0c2007-02-05 16:36:07 -080036 /* Cope with illegal. */
37 if (pin > 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 pin = 1;
39
Andreas Block691cd0c2007-02-05 16:36:07 -080040 if (pin != 0) {
41 /* Follow the chain of bridges, swizzling as we go. */
42 slot = (*swizzle)(dev, &pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Andreas Block691cd0c2007-02-05 16:36:07 -080044 irq = (*map_irq)(dev, slot, pin);
45 if (irq == -1)
46 irq = 0;
47 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 dev->irq = irq;
49
Bjorn Helgaas80ccba12008-06-13 10:52:11 -060050 dev_dbg(&dev->dev, "fixup irq: got %d\n", dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52 /* Always tell the device, so the driver knows what is
53 the real IRQ to use; the device does not use it. */
54 pcibios_update_irq(dev, irq);
55}
56
57void __init
58pci_fixup_irqs(u8 (*swizzle)(struct pci_dev *, u8 *),
Ralf Baechled5341942011-06-10 15:30:21 +010059 int (*map_irq)(const struct pci_dev *, u8, u8))
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 struct pci_dev *dev = NULL;
Kulikov Vasiliy4e344b12010-07-03 20:04:39 +040062 for_each_pci_dev(dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 pdev_fixup_irq(dev, swizzle, map_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}