setup-irq.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #include <linux/init.h>
  12. #include <linux/kernel.h>
  13. #include <linux/pci.h>
  14. #include <linux/errno.h>
  15. #include <linux/ioport.h>
  16. #include <linux/cache.h>
  17. static void __init
  18. pdev_fixup_irq(struct pci_dev *dev,
  19. u8 (*swizzle)(struct pci_dev *, u8 *),
  20. int (*map_irq)(struct pci_dev *, u8, u8))
  21. {
  22. u8 pin, slot;
  23. int irq = 0;
  24. /* If this device is not on the primary bus, we need to figure out
  25. which interrupt pin it will come in on. We know which slot it
  26. will come in on 'cos that slot is where the bridge is. Each
  27. time the interrupt line passes through a PCI-PCI bridge we must
  28. apply the swizzle function. */
  29. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  30. /* Cope with illegal. */
  31. if (pin > 4)
  32. pin = 1;
  33. if (pin != 0) {
  34. /* Follow the chain of bridges, swizzling as we go. */
  35. slot = (*swizzle)(dev, &pin);
  36. irq = (*map_irq)(dev, slot, pin);
  37. if (irq == -1)
  38. irq = 0;
  39. }
  40. dev->irq = irq;
  41. dev_dbg(&dev->dev, "fixup irq: got %d\n", dev->irq);
  42. /* Always tell the device, so the driver knows what is
  43. the real IRQ to use; the device does not use it. */
  44. pcibios_update_irq(dev, irq);
  45. }
  46. void __init
  47. pci_fixup_irqs(u8 (*swizzle)(struct pci_dev *, u8 *),
  48. int (*map_irq)(struct pci_dev *, u8, u8))
  49. {
  50. struct pci_dev *dev = NULL;
  51. for_each_pci_dev(dev)
  52. pdev_fixup_irq(dev, swizzle, map_irq);
  53. }