Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | ||
1da177e4 LT |
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 | ||
8885b7b6 TR |
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 | } | |
1da177e4 | 24 | |
3ddbebf8 | 25 | static void |
1da177e4 LT |
26 | pdev_fixup_irq(struct pci_dev *dev, |
27 | u8 (*swizzle)(struct pci_dev *, u8 *), | |
d5341942 | 28 | int (*map_irq)(const struct pci_dev *, u8, u8)) |
1da177e4 LT |
29 | { |
30 | u8 pin, slot; | |
691cd0c2 | 31 | int irq = 0; |
1da177e4 LT |
32 | |
33 | /* If this device is not on the primary bus, we need to figure out | |
34 | which interrupt pin it will come in on. We know which slot it | |
35 | will come in on 'cos that slot is where the bridge is. Each | |
36 | time the interrupt line passes through a PCI-PCI bridge we must | |
37 | apply the swizzle function. */ | |
38 | ||
39 | pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); | |
691cd0c2 AB |
40 | /* Cope with illegal. */ |
41 | if (pin > 4) | |
1da177e4 LT |
42 | pin = 1; |
43 | ||
691cd0c2 AB |
44 | if (pin != 0) { |
45 | /* Follow the chain of bridges, swizzling as we go. */ | |
46 | slot = (*swizzle)(dev, &pin); | |
1da177e4 | 47 | |
691cd0c2 AB |
48 | irq = (*map_irq)(dev, slot, pin); |
49 | if (irq == -1) | |
50 | irq = 0; | |
51 | } | |
1da177e4 LT |
52 | dev->irq = irq; |
53 | ||
80ccba11 | 54 | dev_dbg(&dev->dev, "fixup irq: got %d\n", dev->irq); |
1da177e4 LT |
55 | |
56 | /* Always tell the device, so the driver knows what is | |
57 | the real IRQ to use; the device does not use it. */ | |
58 | pcibios_update_irq(dev, irq); | |
59 | } | |
60 | ||
3ddbebf8 | 61 | void |
1da177e4 | 62 | pci_fixup_irqs(u8 (*swizzle)(struct pci_dev *, u8 *), |
d5341942 | 63 | int (*map_irq)(const struct pci_dev *, u8, u8)) |
1da177e4 LT |
64 | { |
65 | struct pci_dev *dev = NULL; | |
4e344b1c | 66 | for_each_pci_dev(dev) |
1da177e4 | 67 | pdev_fixup_irq(dev, swizzle, map_irq); |
1da177e4 | 68 | } |