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 | |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame] | 20 | void pci_assign_irq(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | { |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame] | 22 | u8 pin; |
| 23 | u8 slot = -1; |
Andreas Block | 691cd0c | 2007-02-05 16:36:07 -0800 | [diff] [blame] | 24 | int irq = 0; |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame] | 25 | struct pci_host_bridge *hbrg = pci_find_host_bridge(dev->bus); |
| 26 | |
| 27 | if (!(hbrg->map_irq)) { |
Frederick Lawler | 7506dc7 | 2018-01-18 12:55:24 -0600 | [diff] [blame^] | 28 | pci_dbg(dev, "runtime IRQ mapping not provided by arch\n"); |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame] | 29 | return; |
| 30 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Andreas Block | 691cd0c | 2007-02-05 16:36:07 -0800 | [diff] [blame] | 39 | /* Cope with illegal. */ |
| 40 | if (pin > 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | pin = 1; |
| 42 | |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame] | 43 | if (pin) { |
Andreas Block | 691cd0c | 2007-02-05 16:36:07 -0800 | [diff] [blame] | 44 | /* Follow the chain of bridges, swizzling as we go. */ |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame] | 45 | if (hbrg->swizzle_irq) |
| 46 | slot = (*(hbrg->swizzle_irq))(dev, &pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Matthew Minter | 47a650f | 2017-06-28 15:14:02 -0500 | [diff] [blame] | 48 | /* |
| 49 | * If a swizzling function is not used map_irq must |
| 50 | * ignore slot |
| 51 | */ |
| 52 | irq = (*(hbrg->map_irq))(dev, slot, pin); |
Andreas Block | 691cd0c | 2007-02-05 16:36:07 -0800 | [diff] [blame] | 53 | if (irq == -1) |
| 54 | irq = 0; |
| 55 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | dev->irq = irq; |
| 57 | |
Frederick Lawler | 7506dc7 | 2018-01-18 12:55:24 -0600 | [diff] [blame^] | 58 | pci_dbg(dev, "assign IRQ: got %d\n", dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | /* Always tell the device, so the driver knows what is |
| 61 | the real IRQ to use; the device does not use it. */ |
Bjorn Helgaas | 606799c | 2017-08-10 12:49:57 -0500 | [diff] [blame] | 62 | pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |