From: Marc Zyngier <maz@kernel.org>
To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Cc: "Toan Le" <toan@os.amperecomputing.com>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Manivannan Sadhasivam" <mani@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Thomas Gleixner" <tglx@linutronix.de>
Subject: [PATCH v2 12/13] PCI: xgene-msi: Restructure handler setup/teardown
Date: Tue, 8 Jul 2025 18:34:03 +0100 [thread overview]
Message-ID: <20250708173404.1278635-13-maz@kernel.org> (raw)
In-Reply-To: <20250708173404.1278635-1-maz@kernel.org>
Another utterly pointless aspect of the xgene-msi driver is that
it is built around CPU hotplug. Which is quite amusing since this
is one of the few arm64 platforms that, by construction, cannot
do CPU hotplug in a supported way (no EL3, no PSCI, no luck).
Drop the CPU hotplug nonsense and just setup the IRQs and handlers
in a less overdesigned way, grouping things more logically in the
process.
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
drivers/pci/controller/pci-xgene-msi.c | 107 +++++++++----------------
1 file changed, 37 insertions(+), 70 deletions(-)
diff --git a/drivers/pci/controller/pci-xgene-msi.c b/drivers/pci/controller/pci-xgene-msi.c
index 243c7721c8799..dd8b119ab90e0 100644
--- a/drivers/pci/controller/pci-xgene-msi.c
+++ b/drivers/pci/controller/pci-xgene-msi.c
@@ -231,12 +231,6 @@ static int xgene_allocate_domains(struct device_node *node,
return msi->inner_domain ? 0 : -ENOMEM;
}
-static void xgene_free_domains(struct xgene_msi *msi)
-{
- if (msi->inner_domain)
- irq_domain_remove(msi->inner_domain);
-}
-
static int xgene_msi_init_allocator(struct device *dev)
{
xgene_msi_ctrl->bitmap = devm_bitmap_zalloc(dev, NR_MSI_VEC, GFP_KERNEL);
@@ -283,26 +277,48 @@ static void xgene_msi_isr(struct irq_desc *desc)
chained_irq_exit(chip, desc);
}
-static enum cpuhp_state pci_xgene_online;
-
static void xgene_msi_remove(struct platform_device *pdev)
{
- struct xgene_msi *msi = platform_get_drvdata(pdev);
-
- if (pci_xgene_online)
- cpuhp_remove_state(pci_xgene_online);
- cpuhp_remove_state(CPUHP_PCI_XGENE_DEAD);
+ for (int i = 0; i < NR_HW_IRQS; i++) {
+ unsigned int irq = xgene_msi_ctrl->gic_irq[i];
+ if (!irq)
+ continue;
+ irq_set_chained_handler_and_data(irq, NULL, NULL);
+ }
- xgene_free_domains(msi);
+ if (xgene_msi_ctrl->inner_domain)
+ irq_domain_remove(xgene_msi_ctrl->inner_domain);
}
-static int xgene_msi_hwirq_alloc(unsigned int cpu)
+static int xgene_msi_handler_setup(struct platform_device *pdev)
{
+ struct xgene_msi *xgene_msi = xgene_msi_ctrl;
int i;
- int err;
- for (i = cpu; i < NR_HW_IRQS; i += num_possible_cpus()) {
- unsigned int irq = xgene_msi_ctrl->gic_irq[i];
+ for (i = 0; i < NR_HW_IRQS; i++) {
+ u32 msi_val;
+ int irq, err;
+
+ /*
+ * MSInIRx registers are read-to-clear; before registering
+ * interrupt handlers, read all of them to clear spurious
+ * interrupts that may occur before the driver is probed.
+ */
+ for (int msi_idx = 0; msi_idx < IDX_PER_GROUP; msi_idx++)
+ xgene_msi_ir_read(xgene_msi, i, msi_idx);
+
+ /* Read MSIINTn to confirm */
+ msi_val = xgene_msi_int_read(xgene_msi, i);
+ if (msi_val) {
+ dev_err(&pdev->dev, "Failed to clear spurious IRQ\n");
+ return EINVAL;
+ }
+
+ irq = platform_get_irq(pdev, i);
+ if (irq < 0)
+ return irq;
+
+ xgene_msi->gic_irq[i] = irq;
/*
* Statically allocate MSI GIC IRQs to each CPU core.
@@ -310,7 +326,7 @@ static int xgene_msi_hwirq_alloc(unsigned int cpu)
* to each core.
*/
irq_set_status_flags(irq, IRQ_NO_BALANCING);
- err = irq_set_affinity(irq, cpumask_of(cpu));
+ err = irq_set_affinity(irq, cpumask_of(i % num_possible_cpus()));
if (err) {
pr_err("failed to set affinity for GIC IRQ");
return err;
@@ -323,17 +339,6 @@ static int xgene_msi_hwirq_alloc(unsigned int cpu)
return 0;
}
-static int xgene_msi_hwirq_free(unsigned int cpu)
-{
- struct xgene_msi *msi = xgene_msi_ctrl;
- int i;
-
- for (i = cpu; i < NR_HW_IRQS; i += num_possible_cpus())
- irq_set_chained_handler_and_data(msi->gic_irq[i], NULL, NULL);
-
- return 0;
-}
-
static const struct of_device_id xgene_msi_match_table[] = {
{.compatible = "apm,xgene1-msi"},
{},
@@ -343,7 +348,6 @@ static int xgene_msi_probe(struct platform_device *pdev)
{
struct resource *res;
struct xgene_msi *xgene_msi;
- u32 msi_val, msi_idx;
int rc;
xgene_msi_ctrl = devm_kzalloc(&pdev->dev, sizeof(*xgene_msi_ctrl),
@@ -353,8 +357,6 @@ static int xgene_msi_probe(struct platform_device *pdev)
xgene_msi = xgene_msi_ctrl;
- platform_set_drvdata(pdev, xgene_msi);
-
xgene_msi->msi_regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
if (IS_ERR(xgene_msi->msi_regs)) {
rc = PTR_ERR(xgene_msi->msi_regs);
@@ -374,48 +376,13 @@ static int xgene_msi_probe(struct platform_device *pdev)
goto error;
}
- for (int irq_index = 0; irq_index < NR_HW_IRQS; irq_index++) {
- rc = platform_get_irq(pdev, irq_index);
- if (rc < 0)
- goto error;
-
- xgene_msi->gic_irq[irq_index] = rc;
- }
-
- /*
- * MSInIRx registers are read-to-clear; before registering
- * interrupt handlers, read all of them to clear spurious
- * interrupts that may occur before the driver is probed.
- */
- for (int irq_index = 0; irq_index < NR_HW_IRQS; irq_index++) {
- for (msi_idx = 0; msi_idx < IDX_PER_GROUP; msi_idx++)
- xgene_msi_ir_read(xgene_msi, irq_index, msi_idx);
-
- /* Read MSIINTn to confirm */
- msi_val = xgene_msi_int_read(xgene_msi, irq_index);
- if (msi_val) {
- dev_err(&pdev->dev, "Failed to clear spurious IRQ\n");
- rc = -EINVAL;
- goto error;
- }
- }
-
- rc = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "pci/xgene:online",
- xgene_msi_hwirq_alloc, NULL);
- if (rc < 0)
- goto err_cpuhp;
- pci_xgene_online = rc;
- rc = cpuhp_setup_state(CPUHP_PCI_XGENE_DEAD, "pci/xgene:dead", NULL,
- xgene_msi_hwirq_free);
+ rc = xgene_msi_handler_setup(pdev);
if (rc)
- goto err_cpuhp;
+ goto error;
dev_info(&pdev->dev, "APM X-Gene PCIe MSI driver loaded\n");
return 0;
-
-err_cpuhp:
- dev_err(&pdev->dev, "failed to add CPU MSI notifier\n");
error:
xgene_msi_remove(pdev);
return rc;
--
2.39.2
next prev parent reply other threads:[~2025-07-08 19:39 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-08 17:33 [PATCH v2 00/13] PCI: xgene: Fix and simplify the MSI driver Marc Zyngier
2025-07-08 17:33 ` [PATCH v2 01/13] genirq: Teach handle_simple_irq() to resend an in-progress interrupt Marc Zyngier
2025-07-08 17:33 ` [PATCH v2 02/13] PCI: xgene: Defer probing if the MSI widget driver hasn't probed yet Marc Zyngier
2025-07-08 17:33 ` [PATCH v2 03/13] PCI: xgene: Drop useless conditional compilation Marc Zyngier
2025-07-08 17:33 ` [PATCH v2 04/13] PCI: xgene: Drop XGENE_PCIE_IP_VER_UNKN Marc Zyngier
2025-07-08 17:33 ` [PATCH v2 05/13] PCI: xgene-msi: Make per-CPU interrupt setup robust Marc Zyngier
2025-07-08 17:33 ` [PATCH v2 06/13] PCI: xgene-msi: Drop superfluous fields from xgene_msi structure Marc Zyngier
2025-07-17 11:24 ` Markus Elfring
2025-07-08 17:33 ` [PATCH v2 07/13] PCI: xgene-msi: Use device-managed memory allocations Marc Zyngier
2025-07-08 17:33 ` [PATCH v2 08/13] PCI: xgene-msi: Get rid of intermediate tracking structure Marc Zyngier
2025-07-08 17:34 ` [PATCH v2 09/13] PCI: xgene-msi: Sanitise MSI allocation and affinity setting Marc Zyngier
2025-07-11 9:55 ` Lorenzo Pieralisi
2025-07-11 10:11 ` Lorenzo Pieralisi
2025-07-11 10:51 ` Marc Zyngier
2025-07-11 10:50 ` Marc Zyngier
2025-07-08 17:34 ` [PATCH v2 10/13] PCI: xgene-msi: Resend an MSI racing with itself on a different CPU Marc Zyngier
2025-07-08 17:34 ` [PATCH v2 11/13] PCI: xgene-msi: Probe as a standard platform driver Marc Zyngier
2025-07-17 11:45 ` Markus Elfring
2025-07-17 13:18 ` Lorenzo Pieralisi
2025-07-08 17:34 ` Marc Zyngier [this message]
2025-07-08 17:34 ` [PATCH v2 13/13] cpu/hotplug: Remove unused cpuhp_state CPUHP_PCI_XGENE_DEAD Marc Zyngier
2025-07-11 13:15 ` Lorenzo Pieralisi
2025-07-17 9:52 ` [PATCH v2 00/13] PCI: xgene: Fix and simplify the MSI driver Lorenzo Pieralisi
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=20250708173404.1278635-13-maz@kernel.org \
--to=maz@kernel.org \
--cc=bhelgaas@google.com \
--cc=kwilczynski@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=robh@kernel.org \
--cc=tglx@linutronix.de \
--cc=toan@os.amperecomputing.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).