linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: "Thomas Gleixner" <tglx@linutronix.de>,
	"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Andrew Lunn" <andrew@lunn.ch>,
	"Gregory Clement" <gregory.clement@bootlin.com>
Cc: "Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	"Rob Herring" <robh@kernel.org>,
	linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	"Manivannan Sadhasivam" <manivannan.sadhasivam@linaro.org>,
	"Marek Behún" <kabel@kernel.org>
Subject: [PATCH v3 1/2] PCI: Add pci_remove_irq_domain() helper
Date: Mon, 15 Jul 2024 13:48:53 +0200	[thread overview]
Message-ID: <20240715114854.4792-2-kabel@kernel.org> (raw)
In-Reply-To: <20240715114854.4792-1-kabel@kernel.org>

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@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



  reply	other threads:[~2024-07-15 11:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-15 11:48 [PATCH v3 0/2] PCI: mvebu: Dispose INTx IRQs before to removing INTx domain Marek Behún
2024-07-15 11:48 ` Marek Behún [this message]
2024-10-17  5:04   ` [PATCH v3 1/2] PCI: Add pci_remove_irq_domain() helper Manivannan Sadhasivam
2024-10-17 19:50   ` Thomas Gleixner
2024-07-15 11:48 ` [PATCH v3 2/2] PCI: mvebu: Dispose INTx IRQs before to removing INTx domain Marek Behún

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240715114854.4792-2-kabel@kernel.org \
    --to=kabel@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=bhelgaas@google.com \
    --cc=gregory.clement@bootlin.com \
    --cc=kw@linux.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=robh@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).