1/* Modified by Broadcom Corp. Portions Copyright (c) Broadcom Corp, 2012. */ 2/* 3 * drivers/pci/setup-irq.c 4 * 5 * Extruded from code written by 6 * Dave Rusling (david.rusling@reo.mts.dec.com) 7 * David Mosberger (davidm@cs.arizona.edu) 8 * David Miller (davem@redhat.com) 9 * 10 * Support routines for initializing a PCI subsystem. 11 */ 12 13 14#include <linux/init.h> 15#include <linux/kernel.h> 16#include <linux/pci.h> 17#include <linux/errno.h> 18#include <linux/ioport.h> 19#include <linux/cache.h> 20 21 22static void __init 23pdev_fixup_irq(struct pci_dev *dev, 24 u8 (*swizzle)(struct pci_dev *, u8 *), 25 int (*map_irq)(struct pci_dev *, u8, u8)) 26{ 27 u8 pin, slot; 28 int irq = 0; 29 30#ifdef CONFIG_BCM47XX 31 if (pci_domain_nr(dev->bus) == 0) 32 return; 33#endif 34 35 /* If this device is not on the primary bus, we need to figure out 36 which interrupt pin it will come in on. We know which slot it 37 will come in on 'cos that slot is where the bridge is. Each 38 time the interrupt line passes through a PCI-PCI bridge we must 39 apply the swizzle function. */ 40 41 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); 42 /* Cope with illegal. */ 43 if (pin > 4) 44 pin = 1; 45 46 if (pin != 0) { 47 /* Follow the chain of bridges, swizzling as we go. */ 48 slot = (*swizzle)(dev, &pin); 49 50 irq = (*map_irq)(dev, slot, pin); 51 if (irq == -1) 52 irq = 0; 53 } 54 dev->irq = irq; 55 56 dev_dbg(&dev->dev, "fixup irq: got %d\n", dev->irq); 57 58 /* Always tell the device, so the driver knows what is 59 the real IRQ to use; the device does not use it. */ 60 pcibios_update_irq(dev, irq); 61} 62 63void __init 64pci_fixup_irqs(u8 (*swizzle)(struct pci_dev *, u8 *), 65 int (*map_irq)(struct pci_dev *, u8, u8)) 66{ 67 struct pci_dev *dev = NULL; 68 for_each_pci_dev(dev) 69 pdev_fixup_irq(dev, swizzle, map_irq); 70} 71