Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Support routines for initializing a PCI subsystem
0004  *
0005  * Extruded from code written by
0006  *      Dave Rusling (david.rusling@reo.mts.dec.com)
0007  *      David Mosberger (davidm@cs.arizona.edu)
0008  *  David Miller (davem@redhat.com)
0009  */
0010 
0011 #include <linux/kernel.h>
0012 #include <linux/pci.h>
0013 #include <linux/errno.h>
0014 #include <linux/ioport.h>
0015 #include <linux/cache.h>
0016 #include "pci.h"
0017 
0018 void pci_assign_irq(struct pci_dev *dev)
0019 {
0020     u8 pin;
0021     u8 slot = -1;
0022     int irq = 0;
0023     struct pci_host_bridge *hbrg = pci_find_host_bridge(dev->bus);
0024 
0025     if (!(hbrg->map_irq)) {
0026         pci_dbg(dev, "runtime IRQ mapping not provided by arch\n");
0027         return;
0028     }
0029 
0030     /*
0031      * If this device is not on the primary bus, we need to figure out
0032      * which interrupt pin it will come in on. We know which slot it
0033      * will come in on because that slot is where the bridge is. Each
0034      * time the interrupt line passes through a PCI-PCI bridge we must
0035      * apply the swizzle function.
0036      */
0037     pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
0038     /* Cope with illegal. */
0039     if (pin > 4)
0040         pin = 1;
0041 
0042     if (pin) {
0043         /* Follow the chain of bridges, swizzling as we go. */
0044         if (hbrg->swizzle_irq)
0045             slot = (*(hbrg->swizzle_irq))(dev, &pin);
0046 
0047         /*
0048          * If a swizzling function is not used, map_irq() must
0049          * ignore slot.
0050          */
0051         irq = (*(hbrg->map_irq))(dev, slot, pin);
0052         if (irq == -1)
0053             irq = 0;
0054     }
0055     dev->irq = irq;
0056 
0057     pci_dbg(dev, "assign IRQ: got %d\n", dev->irq);
0058 
0059     /*
0060      * Always tell the device, so the driver knows what is the real IRQ
0061      * to use; the device does not use it.
0062      */
0063     pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
0064 }