setup-irq.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Support routines for initializing a PCI subsystem
  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. #include <linux/kernel.h>
  11. #include <linux/pci.h>
  12. #include <linux/errno.h>
  13. #include <linux/ioport.h>
  14. #include <linux/cache.h>
  15. #include "pci.h"
  16. void pci_assign_irq(struct pci_dev *dev)
  17. {
  18. u8 pin;
  19. u8 slot = -1;
  20. int irq = 0;
  21. struct pci_host_bridge *hbrg = pci_find_host_bridge(dev->bus);
  22. if (!(hbrg->map_irq)) {
  23. pci_dbg(dev, "runtime IRQ mapping not provided by arch\n");
  24. return;
  25. }
  26. /* If this device is not on the primary bus, we need to figure out
  27. which interrupt pin it will come in on. We know which slot it
  28. will come in on 'cos that slot is where the bridge is. Each
  29. time the interrupt line passes through a PCI-PCI bridge we must
  30. apply the swizzle function. */
  31. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  32. /* Cope with illegal. */
  33. if (pin > 4)
  34. pin = 1;
  35. if (pin) {
  36. /* Follow the chain of bridges, swizzling as we go. */
  37. if (hbrg->swizzle_irq)
  38. slot = (*(hbrg->swizzle_irq))(dev, &pin);
  39. /*
  40. * If a swizzling function is not used map_irq must
  41. * ignore slot
  42. */
  43. irq = (*(hbrg->map_irq))(dev, slot, pin);
  44. if (irq == -1)
  45. irq = 0;
  46. }
  47. dev->irq = irq;
  48. pci_dbg(dev, "assign IRQ: got %d\n", dev->irq);
  49. /* Always tell the device, so the driver knows what is
  50. the real IRQ to use; the device does not use it. */
  51. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
  52. }