irq.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * PCI IRQ handling code
  3. *
  4. * Copyright (c) 2008 James Bottomley <James.Bottomley@HansenPartnership.com>
  5. * Copyright (C) 2017 Christoph Hellwig.
  6. */
  7. #include <linux/acpi.h>
  8. #include <linux/device.h>
  9. #include <linux/kernel.h>
  10. #include <linux/export.h>
  11. #include <linux/pci.h>
  12. static void pci_note_irq_problem(struct pci_dev *pdev, const char *reason)
  13. {
  14. struct pci_dev *parent = to_pci_dev(pdev->dev.parent);
  15. dev_err(&pdev->dev,
  16. "Potentially misrouted IRQ (Bridge %s %04x:%04x)\n",
  17. dev_name(&parent->dev), parent->vendor, parent->device);
  18. dev_err(&pdev->dev, "%s\n", reason);
  19. dev_err(&pdev->dev, "Please report to linux-kernel@vger.kernel.org\n");
  20. WARN_ON(1);
  21. }
  22. /**
  23. * pci_lost_interrupt - reports a lost PCI interrupt
  24. * @pdev: device whose interrupt is lost
  25. *
  26. * The primary function of this routine is to report a lost interrupt
  27. * in a standard way which users can recognise (instead of blaming the
  28. * driver).
  29. *
  30. * Returns:
  31. * a suggestion for fixing it (although the driver is not required to
  32. * act on this).
  33. */
  34. enum pci_lost_interrupt_reason pci_lost_interrupt(struct pci_dev *pdev)
  35. {
  36. if (pdev->msi_enabled || pdev->msix_enabled) {
  37. enum pci_lost_interrupt_reason ret;
  38. if (pdev->msix_enabled) {
  39. pci_note_irq_problem(pdev, "MSIX routing failure");
  40. ret = PCI_LOST_IRQ_DISABLE_MSIX;
  41. } else {
  42. pci_note_irq_problem(pdev, "MSI routing failure");
  43. ret = PCI_LOST_IRQ_DISABLE_MSI;
  44. }
  45. return ret;
  46. }
  47. #ifdef CONFIG_ACPI
  48. if (!(acpi_disabled || acpi_noirq)) {
  49. pci_note_irq_problem(pdev, "Potential ACPI misrouting please reboot with acpi=noirq");
  50. /* currently no way to fix acpi on the fly */
  51. return PCI_LOST_IRQ_DISABLE_ACPI;
  52. }
  53. #endif
  54. pci_note_irq_problem(pdev, "unknown cause (not MSI or ACPI)");
  55. return PCI_LOST_IRQ_NO_INFORMATION;
  56. }
  57. EXPORT_SYMBOL(pci_lost_interrupt);
  58. /**
  59. * pci_request_irq - allocate an interrupt line for a PCI device
  60. * @dev: PCI device to operate on
  61. * @nr: device-relative interrupt vector index (0-based).
  62. * @handler: Function to be called when the IRQ occurs.
  63. * Primary handler for threaded interrupts.
  64. * If NULL and thread_fn != NULL the default primary handler is
  65. * installed.
  66. * @thread_fn: Function called from the IRQ handler thread
  67. * If NULL, no IRQ thread is created
  68. * @dev_id: Cookie passed back to the handler function
  69. * @fmt: Printf-like format string naming the handler
  70. *
  71. * This call allocates interrupt resources and enables the interrupt line and
  72. * IRQ handling. From the point this call is made @handler and @thread_fn may
  73. * be invoked. All interrupts requested using this function might be shared.
  74. *
  75. * @dev_id must not be NULL and must be globally unique.
  76. */
  77. int pci_request_irq(struct pci_dev *dev, unsigned int nr, irq_handler_t handler,
  78. irq_handler_t thread_fn, void *dev_id, const char *fmt, ...)
  79. {
  80. va_list ap;
  81. int ret;
  82. char *devname;
  83. va_start(ap, fmt);
  84. devname = kvasprintf(GFP_KERNEL, fmt, ap);
  85. va_end(ap);
  86. ret = request_threaded_irq(pci_irq_vector(dev, nr), handler, thread_fn,
  87. IRQF_SHARED, devname, dev_id);
  88. if (ret)
  89. kfree(devname);
  90. return ret;
  91. }
  92. EXPORT_SYMBOL(pci_request_irq);
  93. /**
  94. * pci_free_irq - free an interrupt allocated with pci_request_irq
  95. * @dev: PCI device to operate on
  96. * @nr: device-relative interrupt vector index (0-based).
  97. * @dev_id: Device identity to free
  98. *
  99. * Remove an interrupt handler. The handler is removed and if the interrupt
  100. * line is no longer in use by any driver it is disabled. The caller must
  101. * ensure the interrupt is disabled on the device before calling this function.
  102. * The function does not return until any executing interrupts for this IRQ
  103. * have completed.
  104. *
  105. * This function must not be called from interrupt context.
  106. */
  107. void pci_free_irq(struct pci_dev *dev, unsigned int nr, void *dev_id)
  108. {
  109. kfree(free_irq(pci_irq_vector(dev, nr), dev_id));
  110. }
  111. EXPORT_SYMBOL(pci_free_irq);