]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/pci/setup-irq.c
Merge branch 'for-4.15-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj...
[mirror_ubuntu-bionic-kernel.git] / drivers / pci / setup-irq.c
CommitLineData
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>
47a650f2 18#include "pci.h"
1da177e4 19
47a650f2 20void pci_assign_irq(struct pci_dev *dev)
1da177e4 21{
47a650f2
MM
22 u8 pin;
23 u8 slot = -1;
691cd0c2 24 int irq = 0;
47a650f2
MM
25 struct pci_host_bridge *hbrg = pci_find_host_bridge(dev->bus);
26
27 if (!(hbrg->map_irq)) {
28 dev_dbg(&dev->dev, "runtime IRQ mapping not provided by arch\n");
29 return;
30 }
1da177e4
LT
31
32 /* If this device is not on the primary bus, we need to figure out
33 which interrupt pin it will come in on. We know which slot it
34 will come in on 'cos that slot is where the bridge is. Each
35 time the interrupt line passes through a PCI-PCI bridge we must
36 apply the swizzle function. */
37
38 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
691cd0c2
AB
39 /* Cope with illegal. */
40 if (pin > 4)
1da177e4
LT
41 pin = 1;
42
47a650f2 43 if (pin) {
691cd0c2 44 /* Follow the chain of bridges, swizzling as we go. */
47a650f2
MM
45 if (hbrg->swizzle_irq)
46 slot = (*(hbrg->swizzle_irq))(dev, &pin);
1da177e4 47
47a650f2
MM
48 /*
49 * If a swizzling function is not used map_irq must
50 * ignore slot
51 */
52 irq = (*(hbrg->map_irq))(dev, slot, pin);
691cd0c2
AB
53 if (irq == -1)
54 irq = 0;
55 }
1da177e4
LT
56 dev->irq = irq;
57
47a650f2 58 dev_dbg(&dev->dev, "assign IRQ: got %d\n", dev->irq);
1da177e4
LT
59
60 /* Always tell the device, so the driver knows what is
61 the real IRQ to use; the device does not use it. */
606799cc 62 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
1da177e4 63}