[PATCH v3 1/2] PCI: Add pci_remove_irq_domain() helper

Marek Behún kabel at kernel.org
Mon Jul 15 04:48:53 PDT 2024


Add a helper function pci_remove_irq_domain() for disposing all
interrupt mappings of an IRQ domain and then removing said IRQ domain.

As explained in the attached link, the PCI INTX interrupt may be shared,
and so the PCI device drivers do not dispose mapped interrupts when they
are unbound from a device, since other devices may be still using those
mapped interrupts. Thus the interrupts must be disposed by the PCI
controller driver when the IRQ domain is being removed.

This function may be used by PCI controller drivers that wish to be
removable / modular.

Link: https://lore.kernel.org/linux-pci/878qy5rrq7.ffs@tglx/
Signed-off-by: Marek Behún <kabel at kernel.org>
---
 drivers/pci/irq.c | 21 +++++++++++++++++++++
 drivers/pci/pci.h |  7 +++++++
 2 files changed, 28 insertions(+)

diff --git a/drivers/pci/irq.c b/drivers/pci/irq.c
index 4555630be9ec..30c8d930016a 100644
--- a/drivers/pci/irq.c
+++ b/drivers/pci/irq.c
@@ -11,6 +11,7 @@
 #include <linux/errno.h>
 #include <linux/export.h>
 #include <linux/interrupt.h>
+#include <linux/irqdomain.h>
 #include <linux/pci.h>
 
 #include "pci.h"
@@ -259,6 +260,26 @@ bool pci_check_and_unmask_intx(struct pci_dev *dev)
 }
 EXPORT_SYMBOL_GPL(pci_check_and_unmask_intx);
 
+#ifdef CONFIG_IRQ_DOMAIN
+/**
+ * pci_remove_irq_domain - dispose all IRQ mappings and remove IRQ domain
+ * @domain: the IRQ domain to be removed
+ *
+ * Disposes all IRQ mappings of a given IRQ domain before removing the domain.
+ */
+void pci_remove_irq_domain(struct irq_domain *domain)
+{
+	for (irq_hw_number_t i = 0; i < domain->hwirq_max; i++) {
+		unsigned int virq = irq_find_mapping(domain, i);
+
+		if (virq)
+			irq_dispose_mapping(virq);
+	}
+
+	irq_domain_remove(domain);
+}
+#endif
+
 /**
  * pcibios_penalize_isa_irq - penalize an ISA IRQ
  * @irq: ISA IRQ to penalize
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index fd44565c4756..1ba6a6f418ac 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -170,6 +170,13 @@ void pci_no_msi(void);
 static inline void pci_no_msi(void) { }
 #endif
 
+struct irq_domain;
+#ifdef CONFIG_IRQ_DOMAIN
+void pci_remove_irq_domain(struct irq_domain *domain);
+#else
+static inline void pci_remove_irq_domain(struct irq_domain *domain) { }
+#endif
+
 void pci_realloc_get_opt(char *);
 
 static inline int pci_no_d1d2(struct pci_dev *dev)
-- 
2.44.2




More information about the linux-arm-kernel mailing list