From nobody Sun Oct 5 01:45:14 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2DDD2DECAF for ; Mon, 11 Aug 2025 09:29:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754904547; cv=none; b=SABcMSO28tRz0Ki6mKqq3Enxj4Tip5D2OKWscb1oJRk0FaEUa6kLG9tT3bQlriGBoyKdVuvtwGnINf/hilmjP4zm9xF7I/sMK8Wz/clgG+8wxXgxoXIuGU54LH9KCCP/pESJUW1aNyzHaTxBvEt8qWVKaE4yMkGofAr6C3mCA2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754904547; c=relaxed/simple; bh=iJcFQqDy8eP+MH0TvrUbe54T7dAWoywRDid7QR7ob8k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M45A6qWFM2wUSgGi6gtiTdAD9htQMCIOrHZWKRmM4c+Dg4uHVnvpkHYH+BrRlYUv8Zh3rVUVcU3KrQreXafXiXjaTu4QaIbEgXLwCkpBmG+6szETo0xhehuIiomzo4ib2Bk68Ec5JKZRaVs6XNr2jEIV14ayXJSOW0FKJCUrNc8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=2/9xn9Xx; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Gsu9AzgU; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2/9xn9Xx"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Gsu9AzgU" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1754904542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K8zWEyROxdIAiNmIXoB2YUo/KaB4rPfzDkAgJIDKX4M=; b=2/9xn9XxPMEPfoN0FaV24ZGYdGjco6YLZ6cwaWE7EPNJiYR1zl9cxuyARqLuKd4VJSmdNc oM9bYL7IvrCb4VaYjp1BrGC6WXSypNBpnHwv6WKzRLlsttYOXSOJwepDkgnWuOtrYA1krD oNK54ARyoWlvOF7ESCruxdvCg6RSovfjKo6N1FFzCNhrPfdW8f3rWdKNnWIC/6YQQWO3Oc aWoNNg/dK93vA3qoXcZQno3nlGEzZbvG1cR+YJzt2+cLx3KCJUue/YPQc+HbPkCOCaRS2i OVqO72Xq4zB61z5Dm2G8cdU7Pu1rFecwR0QU60IfVcqTMXRY6UuNBIjTL5e2IQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1754904542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K8zWEyROxdIAiNmIXoB2YUo/KaB4rPfzDkAgJIDKX4M=; b=Gsu9AzgUbR19sMTYfhR2et+Iukanoz7NWS9pZv/g6Ore5nPmlJsTgaWUQcWaVc22/NfE3a DvWAehiBmSp4OjAw== To: Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Thomas Gleixner , Marc Zyngier , Gautam Menghani , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 1/3] powerpc/xive: Untangle xive from child interrupt controller drivers Date: Mon, 11 Aug 2025 11:28:54 +0200 Message-Id: <83968073022a4cc211dcbd0faccd20ec05e58c3e.1754903590.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" xive-specific data is stored in handler_data. This creates a mess, as xive has to rely on child interrupt controller drivers to clean up this data, as was done by 9a014f45688 ("powerpc/pseries/pci: Add a msi_free() handler to clear XIVE data"). Instead, store xive-specific data in chip_data and untangle the child drivers. Signed-off-by: Nam Cao --- v2: no change --- arch/powerpc/include/asm/xive.h | 1 - arch/powerpc/platforms/powernv/pci-ioda.c | 21 +------- arch/powerpc/platforms/pseries/msi.c | 18 +------ arch/powerpc/sysdev/xive/common.c | 63 +++++++++++------------ 4 files changed, 33 insertions(+), 70 deletions(-) diff --git a/arch/powerpc/include/asm/xive.h b/arch/powerpc/include/asm/xiv= e.h index 92930b0b5d0e..efb0f5effcc6 100644 --- a/arch/powerpc/include/asm/xive.h +++ b/arch/powerpc/include/asm/xive.h @@ -111,7 +111,6 @@ void xive_native_free_vp_block(u32 vp_base); int xive_native_populate_irq_data(u32 hw_irq, struct xive_irq_data *data); void xive_cleanup_irq_data(struct xive_irq_data *xd); -void xive_irq_free_data(unsigned int virq); void xive_native_free_irq(u32 irq); int xive_native_configure_irq(u32 hw_irq, u32 target, u8 prio, u32 sw_irq); =20 diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platf= orms/powernv/pci-ioda.c index d8ccf2c9b98a..fb37098d4d58 100644 --- a/arch/powerpc/platforms/powernv/pci-ioda.c +++ b/arch/powerpc/platforms/powernv/pci-ioda.c @@ -37,7 +37,6 @@ #include #include #include -#include =20 #include "powernv.h" #include "pci.h" @@ -1707,23 +1706,6 @@ static int __pnv_pci_ioda_msi_setup(struct pnv_phb *= phb, struct pci_dev *dev, return 0; } =20 -/* - * The msi_free() op is called before irq_domain_free_irqs_top() when - * the handler data is still available. Use that to clear the XIVE - * controller. - */ -static void pnv_msi_ops_msi_free(struct irq_domain *domain, - struct msi_domain_info *info, - unsigned int irq) -{ - if (xive_enabled()) - xive_irq_free_data(irq); -} - -static struct msi_domain_ops pnv_pci_msi_domain_ops =3D { - .msi_free =3D pnv_msi_ops_msi_free, -}; - static void pnv_msi_shutdown(struct irq_data *d) { d =3D d->parent_data; @@ -1754,7 +1736,6 @@ static struct irq_chip pnv_pci_msi_irq_chip =3D { static struct msi_domain_info pnv_msi_domain_info =3D { .flags =3D (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS | MSI_FLAG_MULTI_PCI_MSI | MSI_FLAG_PCI_MSIX), - .ops =3D &pnv_pci_msi_domain_ops, .chip =3D &pnv_pci_msi_irq_chip, }; =20 @@ -1870,7 +1851,7 @@ static void pnv_irq_domain_free(struct irq_domain *do= main, unsigned int virq, virq, d->hwirq, nr_irqs); =20 msi_bitmap_free_hwirqs(&phb->msi_bmp, d->hwirq, nr_irqs); - /* XIVE domain is cleared through ->msi_free() */ + irq_domain_free_irqs_parent(domain, virq, nr_irqs); } =20 static const struct irq_domain_ops pnv_irq_domain_ops =3D { diff --git a/arch/powerpc/platforms/pseries/msi.c b/arch/powerpc/platforms/= pseries/msi.c index ee1c8c6898a3..10712477938e 100644 --- a/arch/powerpc/platforms/pseries/msi.c +++ b/arch/powerpc/platforms/pseries/msi.c @@ -15,7 +15,6 @@ #include #include #include -#include =20 #include "pseries.h" =20 @@ -436,19 +435,6 @@ static int pseries_msi_ops_prepare(struct irq_domain *= domain, struct device *dev return rtas_prepare_msi_irqs(pdev, nvec, type, arg); } =20 -/* - * ->msi_free() is called before irq_domain_free_irqs_top() when the - * handler data is still available. Use that to clear the XIVE - * controller data. - */ -static void pseries_msi_ops_msi_free(struct irq_domain *domain, - struct msi_domain_info *info, - unsigned int irq) -{ - if (xive_enabled()) - xive_irq_free_data(irq); -} - /* * RTAS can not disable one MSI at a time. It's all or nothing. Do it * at the end after all IRQs have been freed. @@ -463,7 +449,6 @@ static void pseries_msi_post_free(struct irq_domain *do= main, struct device *dev) =20 static struct msi_domain_ops pseries_pci_msi_domain_ops =3D { .msi_prepare =3D pseries_msi_ops_prepare, - .msi_free =3D pseries_msi_ops_msi_free, .msi_post_free =3D pseries_msi_post_free, }; =20 @@ -604,8 +589,7 @@ static void pseries_irq_domain_free(struct irq_domain *= domain, unsigned int virq struct pci_controller *phb =3D irq_data_get_irq_chip_data(d); =20 pr_debug("%s bridge %pOF %d #%d\n", __func__, phb->dn, virq, nr_irqs); - - /* XIVE domain data is cleared through ->msi_free() */ + irq_domain_free_irqs_parent(domain, virq, nr_irqs); } =20 static const struct irq_domain_ops pseries_irq_domain_ops =3D { diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/c= ommon.c index f10592405024..625361a15424 100644 --- a/arch/powerpc/sysdev/xive/common.c +++ b/arch/powerpc/sysdev/xive/common.c @@ -317,7 +317,7 @@ int xmon_xive_get_irq_config(u32 hw_irq, struct irq_dat= a *d) if (d) { char buffer[128]; =20 - xive_irq_data_dump(irq_data_get_irq_handler_data(d), + xive_irq_data_dump(irq_data_get_irq_chip_data(d), buffer, sizeof(buffer)); xmon_printf("%s", buffer); } @@ -437,7 +437,7 @@ static void xive_do_source_eoi(struct xive_irq_data *xd) /* irq_chip eoi callback, called with irq descriptor lock held */ static void xive_irq_eoi(struct irq_data *d) { - struct xive_irq_data *xd =3D irq_data_get_irq_handler_data(d); + struct xive_irq_data *xd =3D irq_data_get_irq_chip_data(d); struct xive_cpu *xc =3D __this_cpu_read(xive_cpu); =20 DBG_VERBOSE("eoi_irq: irq=3D%d [0x%lx] pending=3D%02x\n", @@ -595,7 +595,7 @@ static int xive_pick_irq_target(struct irq_data *d, const struct cpumask *affinity) { static unsigned int fuzz; - struct xive_irq_data *xd =3D irq_data_get_irq_handler_data(d); + struct xive_irq_data *xd =3D irq_data_get_irq_chip_data(d); cpumask_var_t mask; int cpu =3D -1; =20 @@ -628,7 +628,7 @@ static int xive_pick_irq_target(struct irq_data *d, =20 static unsigned int xive_irq_startup(struct irq_data *d) { - struct xive_irq_data *xd =3D irq_data_get_irq_handler_data(d); + struct xive_irq_data *xd =3D irq_data_get_irq_chip_data(d); unsigned int hw_irq =3D (unsigned int)irqd_to_hwirq(d); int target, rc; =20 @@ -673,7 +673,7 @@ static unsigned int xive_irq_startup(struct irq_data *d) /* called with irq descriptor lock held */ static void xive_irq_shutdown(struct irq_data *d) { - struct xive_irq_data *xd =3D irq_data_get_irq_handler_data(d); + struct xive_irq_data *xd =3D irq_data_get_irq_chip_data(d); unsigned int hw_irq =3D (unsigned int)irqd_to_hwirq(d); =20 pr_debug("%s: irq %d [0x%x] data @%p\n", __func__, d->irq, hw_irq, d); @@ -698,7 +698,7 @@ static void xive_irq_shutdown(struct irq_data *d) =20 static void xive_irq_unmask(struct irq_data *d) { - struct xive_irq_data *xd =3D irq_data_get_irq_handler_data(d); + struct xive_irq_data *xd =3D irq_data_get_irq_chip_data(d); =20 pr_debug("%s: irq %d data @%p\n", __func__, d->irq, xd); =20 @@ -707,7 +707,7 @@ static void xive_irq_unmask(struct irq_data *d) =20 static void xive_irq_mask(struct irq_data *d) { - struct xive_irq_data *xd =3D irq_data_get_irq_handler_data(d); + struct xive_irq_data *xd =3D irq_data_get_irq_chip_data(d); =20 pr_debug("%s: irq %d data @%p\n", __func__, d->irq, xd); =20 @@ -718,7 +718,7 @@ static int xive_irq_set_affinity(struct irq_data *d, const struct cpumask *cpumask, bool force) { - struct xive_irq_data *xd =3D irq_data_get_irq_handler_data(d); + struct xive_irq_data *xd =3D irq_data_get_irq_chip_data(d); unsigned int hw_irq =3D (unsigned int)irqd_to_hwirq(d); u32 target, old_target; int rc =3D 0; @@ -776,7 +776,7 @@ static int xive_irq_set_affinity(struct irq_data *d, =20 static int xive_irq_set_type(struct irq_data *d, unsigned int flow_type) { - struct xive_irq_data *xd =3D irq_data_get_irq_handler_data(d); + struct xive_irq_data *xd =3D irq_data_get_irq_chip_data(d); =20 /* * We only support these. This has really no effect other than setting @@ -815,7 +815,7 @@ static int xive_irq_set_type(struct irq_data *d, unsign= ed int flow_type) =20 static int xive_irq_retrigger(struct irq_data *d) { - struct xive_irq_data *xd =3D irq_data_get_irq_handler_data(d); + struct xive_irq_data *xd =3D irq_data_get_irq_chip_data(d); =20 /* This should be only for MSIs */ if (WARN_ON(xd->flags & XIVE_IRQ_FLAG_LSI)) @@ -837,7 +837,7 @@ static int xive_irq_retrigger(struct irq_data *d) */ static int xive_irq_set_vcpu_affinity(struct irq_data *d, void *state) { - struct xive_irq_data *xd =3D irq_data_get_irq_handler_data(d); + struct xive_irq_data *xd =3D irq_data_get_irq_chip_data(d); unsigned int hw_irq =3D (unsigned int)irqd_to_hwirq(d); int rc; u8 pq; @@ -951,7 +951,7 @@ static int xive_irq_set_vcpu_affinity(struct irq_data *= d, void *state) static int xive_get_irqchip_state(struct irq_data *data, enum irqchip_irq_state which, bool *state) { - struct xive_irq_data *xd =3D irq_data_get_irq_handler_data(data); + struct xive_irq_data *xd =3D irq_data_get_irq_chip_data(data); u8 pq; =20 switch (which) { @@ -1011,21 +1011,20 @@ void xive_cleanup_irq_data(struct xive_irq_data *xd) } EXPORT_SYMBOL_GPL(xive_cleanup_irq_data); =20 -static int xive_irq_alloc_data(unsigned int virq, irq_hw_number_t hw) +static struct xive_irq_data *xive_irq_alloc_data(unsigned int virq, irq_hw= _number_t hw) { struct xive_irq_data *xd; int rc; =20 xd =3D kzalloc(sizeof(struct xive_irq_data), GFP_KERNEL); if (!xd) - return -ENOMEM; + return ERR_PTR(-ENOMEM); rc =3D xive_ops->populate_irq_data(hw, xd); if (rc) { kfree(xd); - return rc; + return ERR_PTR(rc); } xd->target =3D XIVE_INVALID_TARGET; - irq_set_handler_data(virq, xd); =20 /* * Turn OFF by default the interrupt being mapped. A side @@ -1036,20 +1035,19 @@ static int xive_irq_alloc_data(unsigned int virq, i= rq_hw_number_t hw) */ xive_esb_read(xd, XIVE_ESB_SET_PQ_01); =20 - return 0; + return xd; } =20 -void xive_irq_free_data(unsigned int virq) +static void xive_irq_free_data(unsigned int virq) { - struct xive_irq_data *xd =3D irq_get_handler_data(virq); + struct xive_irq_data *xd =3D irq_get_chip_data(virq); =20 if (!xd) return; - irq_set_handler_data(virq, NULL); + irq_set_chip_data(virq, NULL); xive_cleanup_irq_data(xd); kfree(xd); } -EXPORT_SYMBOL_GPL(xive_irq_free_data); =20 #ifdef CONFIG_SMP =20 @@ -1286,7 +1284,7 @@ void __init xive_smp_probe(void) static int xive_irq_domain_map(struct irq_domain *h, unsigned int virq, irq_hw_number_t hw) { - int rc; + struct xive_irq_data *xd; =20 /* * Mark interrupts as edge sensitive by default so that resend @@ -1294,11 +1292,12 @@ static int xive_irq_domain_map(struct irq_domain *h= , unsigned int virq, */ irq_clear_status_flags(virq, IRQ_LEVEL); =20 - rc =3D xive_irq_alloc_data(virq, hw); - if (rc) - return rc; + xd =3D xive_irq_alloc_data(virq, hw); + if (IS_ERR(xd)) + return PTR_ERR(xd); =20 irq_set_chip_and_handler(virq, &xive_irq_chip, handle_fasteoi_irq); + irq_set_chip_data(virq, xd); =20 return 0; } @@ -1366,7 +1365,7 @@ static void xive_irq_domain_debug_show(struct seq_fil= e *m, struct irq_domain *d, seq_printf(m, "%*sXIVE:\n", ind, ""); ind++; =20 - xd =3D irq_data_get_irq_handler_data(irqd); + xd =3D irq_data_get_irq_chip_data(irqd); if (!xd) { seq_printf(m, "%*snot assigned\n", ind, ""); return; @@ -1403,6 +1402,7 @@ static int xive_irq_domain_alloc(struct irq_domain *d= omain, unsigned int virq, unsigned int nr_irqs, void *arg) { struct irq_fwspec *fwspec =3D arg; + struct xive_irq_data *xd; irq_hw_number_t hwirq; unsigned int type =3D IRQ_TYPE_NONE; int i, rc; @@ -1423,12 +1423,11 @@ static int xive_irq_domain_alloc(struct irq_domain = *domain, unsigned int virq, irq_clear_status_flags(virq, IRQ_LEVEL); =20 /* allocates and sets handler data */ - rc =3D xive_irq_alloc_data(virq + i, hwirq + i); - if (rc) - return rc; + xd =3D xive_irq_alloc_data(virq + i, hwirq + i); + if (IS_ERR(xd)) + return PTR_ERR(xd); =20 - irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i, - &xive_irq_chip, domain->host_data); + irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i, &xive_irq_chi= p, xd); irq_set_handler(virq + i, handle_fasteoi_irq); } =20 @@ -1764,7 +1763,7 @@ static void xive_debug_show_irq(struct seq_file *m, s= truct irq_data *d) seq_printf(m, "IRQ 0x%08x : target=3D0x%x prio=3D%02x lirq=3D0x%x ", hw_irq, target, prio, lirq); =20 - xive_irq_data_dump(irq_data_get_irq_handler_data(d), buffer, sizeof(buffe= r)); + xive_irq_data_dump(irq_data_get_irq_chip_data(d), buffer, sizeof(buffer)); seq_puts(m, buffer); seq_puts(m, "\n"); } --=20 2.39.5 From nobody Sun Oct 5 01:45:14 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9C7F2DECB4 for ; Mon, 11 Aug 2025 09:29:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754904546; cv=none; b=XbAerv6BULkR/8PkwRPPmO5SDAXQmQwEj2A7iU48/e9MFnP8zx2sYO6IE/ONesRwH5dlV/zy/CDkGjYK4DywS0knud105puw1AOI8trTLCj/JtQOoXTB50K7DW/ZNl4y+sqBb3Oz+5wT74ui6rN6vdkN3m0UuNsoHm7s5WucExg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754904546; c=relaxed/simple; bh=+DMUlfZTqat/D8Q3RR/QCmuDSwOoNCiCCeVHNlXJ2ZU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TDecMp5NE5Gn7d5CWrZUcE6YqjErFpSL+BFfJWeJZiFRHjCgaG+C4yOe27K2J6qSa6njfqB+9rW/LKJ0tk73r/HPkyxRww0HvRmg7Z4Wu1OuFjEnGLiWu3jvlfHOael5BEB4DimC5LOQa40GKx5zFXig4rlaolAhOQ2szjpQMYI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3XB9AeJD; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=IybW2EPV; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3XB9AeJD"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IybW2EPV" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1754904542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PJCRi2fFlTr6qmagXqPicSbakQzvmB8/AtT3di172VU=; b=3XB9AeJDdsI5ylKcOITy547DafomYbr1WYEdcLHp//aJC6eGEpU//8s1Lbiz3ONnPDo+EW WHoJJpytaxzgLPQPgiAkqLanprq2qsxvw4yN+hQLhADZmcHlqUR6C85c/fHflkgGgNeUm4 De2USqmfd0kELjVu4jkbrGLx1Y312jOGRgrtVcOKky0RdvXxHhDiNpX3jhWxEnRLZvfZSb ztatEgjFcXtyEz2/uRA2v5ULdE3VZUqFxwGo3kAH+QvrKnGKZ+y3el4UUg0khuC2Dp0wv7 jJ22iJuEVTvGZ16LbmCM0LZeev53eBehSODZj3z+cwwpe6Wi0rAwIwNv56991w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1754904542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PJCRi2fFlTr6qmagXqPicSbakQzvmB8/AtT3di172VU=; b=IybW2EPVxFx4/m4kQOtKhbsx1WN4+prnGa1EVtcx7aRJYRynYVT1hg+m9vdvCSuOFKJksE Ika4YU+TJoEndRCw== To: Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Thomas Gleixner , Marc Zyngier , Gautam Menghani , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 2/3] powerpc/powernv/pci: Switch to use msi_create_parent_irq_domain() Date: Mon, 11 Aug 2025 11:28:55 +0200 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move away from the legacy MSI domain setup, switch to use msi_create_parent_irq_domain(). Signed-off-by: Nam Cao --- v2: no change --- arch/powerpc/platforms/powernv/Kconfig | 1 + arch/powerpc/platforms/powernv/pci-ioda.c | 75 ++++++++++------------- 2 files changed, 35 insertions(+), 41 deletions(-) diff --git a/arch/powerpc/platforms/powernv/Kconfig b/arch/powerpc/platform= s/powernv/Kconfig index 95d7ba73d43d..b5ad7c173ef0 100644 --- a/arch/powerpc/platforms/powernv/Kconfig +++ b/arch/powerpc/platforms/powernv/Kconfig @@ -9,6 +9,7 @@ config PPC_POWERNV select PPC_P7_NAP select FORCE_PCI select PCI_MSI + select IRQ_MSI_LIB select EPAPR_BOOT select PPC_INDIRECT_PIO select PPC_UDBG_16550 diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platf= orms/powernv/pci-ioda.c index fb37098d4d58..c2a932c6e304 100644 --- a/arch/powerpc/platforms/powernv/pci-ioda.c +++ b/arch/powerpc/platforms/powernv/pci-ioda.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -1713,30 +1714,33 @@ static void pnv_msi_shutdown(struct irq_data *d) d->chip->irq_shutdown(d); } =20 -static void pnv_msi_mask(struct irq_data *d) +static bool pnv_init_dev_msi_info(struct device *dev, struct irq_domain *d= omain, + struct irq_domain *real_parent, struct msi_domain_info *info) { - pci_msi_mask_irq(d); - irq_chip_mask_parent(d); -} + struct irq_chip *chip =3D info->chip; =20 -static void pnv_msi_unmask(struct irq_data *d) -{ - pci_msi_unmask_irq(d); - irq_chip_unmask_parent(d); -} + if (!msi_lib_init_dev_msi_info(dev, domain, real_parent, info)) + return false; =20 -static struct irq_chip pnv_pci_msi_irq_chip =3D { - .name =3D "PNV-PCI-MSI", - .irq_shutdown =3D pnv_msi_shutdown, - .irq_mask =3D pnv_msi_mask, - .irq_unmask =3D pnv_msi_unmask, - .irq_eoi =3D irq_chip_eoi_parent, -}; + chip->irq_shutdown =3D pnv_msi_shutdown; + return true; +} =20 -static struct msi_domain_info pnv_msi_domain_info =3D { - .flags =3D (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS | - MSI_FLAG_MULTI_PCI_MSI | MSI_FLAG_PCI_MSIX), - .chip =3D &pnv_pci_msi_irq_chip, +#define PNV_PCI_MSI_FLAGS_REQUIRED (MSI_FLAG_USE_DEF_DOM_OPS | \ + MSI_FLAG_USE_DEF_CHIP_OPS | \ + MSI_FLAG_PCI_MSI_MASK_PARENT) +#define PNV_PCI_MSI_FLAGS_SUPPORTED (MSI_GENERIC_FLAGS_MASK | \ + MSI_FLAG_PCI_MSIX | \ + MSI_FLAG_MULTI_PCI_MSI) + +static const struct msi_parent_ops pnv_msi_parent_ops =3D { + .required_flags =3D PNV_PCI_MSI_FLAGS_REQUIRED, + .supported_flags =3D PNV_PCI_MSI_FLAGS_SUPPORTED, + .chip_flags =3D MSI_CHIP_FLAG_SET_EOI, + .bus_select_token =3D DOMAIN_BUS_NEXUS, + .bus_select_mask =3D MATCH_PCI_MSI, + .prefix =3D "PNV-", + .init_dev_msi_info =3D pnv_init_dev_msi_info, }; =20 static void pnv_msi_compose_msg(struct irq_data *d, struct msi_msg *msg) @@ -1855,37 +1859,26 @@ static void pnv_irq_domain_free(struct irq_domain *= domain, unsigned int virq, } =20 static const struct irq_domain_ops pnv_irq_domain_ops =3D { + .select =3D msi_lib_irq_domain_select, .alloc =3D pnv_irq_domain_alloc, .free =3D pnv_irq_domain_free, }; =20 static int __init pnv_msi_allocate_domains(struct pci_controller *hose, un= signed int count) { - struct pnv_phb *phb =3D hose->private_data; struct irq_domain *parent =3D irq_get_default_domain(); - - hose->fwnode =3D irq_domain_alloc_named_id_fwnode("PNV-MSI", phb->opal_id= ); - if (!hose->fwnode) - return -ENOMEM; - - hose->dev_domain =3D irq_domain_create_hierarchy(parent, 0, count, - hose->fwnode, - &pnv_irq_domain_ops, hose); + struct irq_domain_info info =3D { + .fwnode =3D of_fwnode_handle(hose->dn), + .ops =3D &pnv_irq_domain_ops, + .host_data =3D hose, + .size =3D count, + .parent =3D parent, + }; + + hose->dev_domain =3D msi_create_parent_irq_domain(&info, &pnv_msi_parent_= ops); if (!hose->dev_domain) { - pr_err("PCI: failed to create IRQ domain bridge %pOF (domain %d)\n", - hose->dn, hose->global_number); - irq_domain_free_fwnode(hose->fwnode); - return -ENOMEM; - } - - hose->msi_domain =3D pci_msi_create_irq_domain(of_fwnode_handle(hose->dn), - &pnv_msi_domain_info, - hose->dev_domain); - if (!hose->msi_domain) { pr_err("PCI: failed to create MSI IRQ domain bridge %pOF (domain %d)\n", hose->dn, hose->global_number); - irq_domain_free_fwnode(hose->fwnode); - irq_domain_remove(hose->dev_domain); return -ENOMEM; } =20 --=20 2.39.5 From nobody Sun Oct 5 01:45:14 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D78992DECBA for ; Mon, 11 Aug 2025 09:29:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754904547; cv=none; b=k9Fga4Rbkxj75zmxh8wvhF+4eTogxK1pl+FbRc4OZibgIzwae0nL3hdDsZLnEGhTs3PBrwfTbH64qYRR7HUxpPcusJV4lzQOJHWKTdPASiq2bKJvHJ5EqrdEFCYN4o1ek2nEin5rC3lSldmsK0g7hKqUbMIW4rURgc6qSNQG47M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754904547; c=relaxed/simple; bh=o0f1doJXmWpoY8ilu9rzAciz9ri+/pSmeCMoXQP7aaU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nGMqHh9SVMU4k/BLvw4hgXRwe5WWiusnyf6WI08nonnzUW08JRNeJ1+YQLyMD9JrJFeNThzT6GrF+gqAYvApOj23N6ZwztMLBdjgb23gU7WZZBY+a8SfSMwZ05Iy9gltpCmEuDUq48Piads3mRMpl/ObGt6y/qXBAoZDF/eEHzA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=I45gjItm; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=PX2Ru60j; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="I45gjItm"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="PX2Ru60j" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1754904543; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o1nZtiw0Ye3ybc0i6zjBCyyaQcqnd1yxvsfwvT7j5S0=; b=I45gjItmGz0E3EwboiTQfPADQd//2Ghz1CtQ3IjRiMNjHwHuz55Rwv4OUvDH+nHykXD+I6 402bHjOfQd5H0q82wiIjvoadkhjq2IqMNaX2jB/G6n5TyyjwzW66QNmpMK/wiXV9JoiXgb GIwuGlZLu61Mvjy75GWAyW4cW2MbgWagnZTG64la31wbB+JAe1O8P8YPGyrBWBrzKhlrMU bwrAosPd8NoyLfeRoA4xEw1s7GchYt30n2tYUj9B0rpfgK6tx2Ry2Ks4L5I+QPIFItBt/r NCbp3gs9i39DNSvz+qO9i5WRVjgMQ0L/Ws3HnbY/zWuMbVUcPWCG4AEvgsiQiw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1754904543; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o1nZtiw0Ye3ybc0i6zjBCyyaQcqnd1yxvsfwvT7j5S0=; b=PX2Ru60jsn00nGrVZVAjjpQEe9giQ07k/m+7UUzIYAX0OkV3S4tgoSdcLvbbNUQTrmKf3r Z0/A/QEO4WDJbkAw== To: Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Thomas Gleixner , Marc Zyngier , Gautam Menghani , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 3/3] powerpc/pseries/msi: Switch to msi_create_parent_irq_domain() Date: Mon, 11 Aug 2025 11:28:56 +0200 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move away from the legacy MSI domain setup, switch to use msi_create_parent_irq_domain(). Signed-off-by: Nam Cao --- v2: Use msi_teardown() instead of msi_post_free() to fix boot issue with NVMe --- arch/powerpc/include/asm/pci-bridge.h | 2 - arch/powerpc/platforms/pseries/Kconfig | 1 + arch/powerpc/platforms/pseries/msi.c | 114 +++++++++++-------------- 3 files changed, 49 insertions(+), 68 deletions(-) diff --git a/arch/powerpc/include/asm/pci-bridge.h b/arch/powerpc/include/a= sm/pci-bridge.h index 2aa3a091ef20..1dae53130782 100644 --- a/arch/powerpc/include/asm/pci-bridge.h +++ b/arch/powerpc/include/asm/pci-bridge.h @@ -133,8 +133,6 @@ struct pci_controller { =20 /* IRQ domain hierarchy */ struct irq_domain *dev_domain; - struct irq_domain *msi_domain; - struct fwnode_handle *fwnode; =20 /* iommu_ops support */ struct iommu_device iommu; diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platform= s/pseries/Kconfig index fa3c2fff082a..3e042218d6cd 100644 --- a/arch/powerpc/platforms/pseries/Kconfig +++ b/arch/powerpc/platforms/pseries/Kconfig @@ -7,6 +7,7 @@ config PPC_PSERIES select OF_DYNAMIC select FORCE_PCI select PCI_MSI + select IRQ_MSI_LIB select GENERIC_ALLOCATOR select PPC_XICS select PPC_XIVE_SPAPR diff --git a/arch/powerpc/platforms/pseries/msi.c b/arch/powerpc/platforms/= pseries/msi.c index 10712477938e..7da142dd5baa 100644 --- a/arch/powerpc/platforms/pseries/msi.c +++ b/arch/powerpc/platforms/pseries/msi.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -429,8 +430,9 @@ static int rtas_prepare_msi_irqs(struct pci_dev *pdev, = int nvec_in, int type, static int pseries_msi_ops_prepare(struct irq_domain *domain, struct devic= e *dev, int nvec, msi_alloc_info_t *arg) { + struct msi_domain_info *info =3D domain->host_data; struct pci_dev *pdev =3D to_pci_dev(dev); - int type =3D pdev->msix_enabled ? PCI_CAP_ID_MSIX : PCI_CAP_ID_MSI; + int type =3D (info->flags & MSI_FLAG_PCI_MSIX) ? PCI_CAP_ID_MSIX : PCI_CA= P_ID_MSI; =20 return rtas_prepare_msi_irqs(pdev, nvec, type, arg); } @@ -439,19 +441,14 @@ static int pseries_msi_ops_prepare(struct irq_domain = *domain, struct device *dev * RTAS can not disable one MSI at a time. It's all or nothing. Do it * at the end after all IRQs have been freed. */ -static void pseries_msi_post_free(struct irq_domain *domain, struct device= *dev) +static void pseries_msi_ops_teardown(struct irq_domain *domain, msi_alloc_= info_t *arg) { - if (WARN_ON_ONCE(!dev_is_pci(dev))) - return; + struct msi_desc *desc =3D arg->desc; + struct pci_dev *pdev =3D msi_desc_to_pci_dev(desc); =20 - rtas_disable_msi(to_pci_dev(dev)); + rtas_disable_msi(pdev); } =20 -static struct msi_domain_ops pseries_pci_msi_domain_ops =3D { - .msi_prepare =3D pseries_msi_ops_prepare, - .msi_post_free =3D pseries_msi_post_free, -}; - static void pseries_msi_shutdown(struct irq_data *d) { d =3D d->parent_data; @@ -459,18 +456,6 @@ static void pseries_msi_shutdown(struct irq_data *d) d->chip->irq_shutdown(d); } =20 -static void pseries_msi_mask(struct irq_data *d) -{ - pci_msi_mask_irq(d); - irq_chip_mask_parent(d); -} - -static void pseries_msi_unmask(struct irq_data *d) -{ - pci_msi_unmask_irq(d); - irq_chip_unmask_parent(d); -} - static void pseries_msi_write_msg(struct irq_data *data, struct msi_msg *m= sg) { struct msi_desc *entry =3D irq_data_get_msi_desc(data); @@ -485,27 +470,39 @@ static void pseries_msi_write_msg(struct irq_data *da= ta, struct msi_msg *msg) entry->msg =3D *msg; } =20 -static struct irq_chip pseries_pci_msi_irq_chip =3D { - .name =3D "pSeries-PCI-MSI", - .irq_shutdown =3D pseries_msi_shutdown, - .irq_mask =3D pseries_msi_mask, - .irq_unmask =3D pseries_msi_unmask, - .irq_eoi =3D irq_chip_eoi_parent, - .irq_write_msi_msg =3D pseries_msi_write_msg, -}; +static bool pseries_init_dev_msi_info(struct device *dev, struct irq_domai= n *domain, + struct irq_domain *real_parent, struct msi_domain_info *info) +{ + struct irq_chip *chip =3D info->chip; =20 + if (!msi_lib_init_dev_msi_info(dev, domain, real_parent, info)) + return false; =20 -/* - * Set MSI_FLAG_MSIX_CONTIGUOUS as there is no way to express to - * firmware to request a discontiguous or non-zero based range of - * MSI-X entries. Core code will reject such setup attempts. - */ -static struct msi_domain_info pseries_msi_domain_info =3D { - .flags =3D (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS | - MSI_FLAG_MULTI_PCI_MSI | MSI_FLAG_PCI_MSIX | - MSI_FLAG_MSIX_CONTIGUOUS), - .ops =3D &pseries_pci_msi_domain_ops, - .chip =3D &pseries_pci_msi_irq_chip, + chip->irq_shutdown =3D pseries_msi_shutdown; + chip->irq_write_msi_msg =3D pseries_msi_write_msg; + + info->ops->msi_prepare =3D pseries_msi_ops_prepare; + info->ops->msi_teardown =3D pseries_msi_ops_teardown; + + return true; +} + +#define PSERIES_PCI_MSI_FLAGS_REQUIRED (MSI_FLAG_USE_DEF_DOM_OPS | \ + MSI_FLAG_USE_DEF_CHIP_OPS | \ + MSI_FLAG_PCI_MSI_MASK_PARENT) +#define PSERIES_PCI_MSI_FLAGS_SUPPORTED (MSI_GENERIC_FLAGS_MASK | \ + MSI_FLAG_PCI_MSIX | \ + MSI_FLAG_MSIX_CONTIGUOUS | \ + MSI_FLAG_MULTI_PCI_MSI) + +static const struct msi_parent_ops pseries_msi_parent_ops =3D { + .required_flags =3D PSERIES_PCI_MSI_FLAGS_REQUIRED, + .supported_flags =3D PSERIES_PCI_MSI_FLAGS_SUPPORTED, + .chip_flags =3D MSI_CHIP_FLAG_SET_EOI, + .bus_select_token =3D DOMAIN_BUS_NEXUS, + .bus_select_mask =3D MATCH_PCI_MSI, + .prefix =3D "pSeries-", + .init_dev_msi_info =3D pseries_init_dev_msi_info, }; =20 static void pseries_msi_compose_msg(struct irq_data *data, struct msi_msg = *msg) @@ -593,6 +590,7 @@ static void pseries_irq_domain_free(struct irq_domain *= domain, unsigned int virq } =20 static const struct irq_domain_ops pseries_irq_domain_ops =3D { + .select =3D msi_lib_irq_domain_select, .alloc =3D pseries_irq_domain_alloc, .free =3D pseries_irq_domain_free, }; @@ -601,30 +599,18 @@ static int __pseries_msi_allocate_domains(struct pci_= controller *phb, unsigned int count) { struct irq_domain *parent =3D irq_get_default_domain(); - - phb->fwnode =3D irq_domain_alloc_named_id_fwnode("pSeries-MSI", - phb->global_number); - if (!phb->fwnode) - return -ENOMEM; - - phb->dev_domain =3D irq_domain_create_hierarchy(parent, 0, count, - phb->fwnode, - &pseries_irq_domain_ops, phb); + struct irq_domain_info info =3D { + .fwnode =3D of_fwnode_handle(phb->dn), + .ops =3D &pseries_irq_domain_ops, + .host_data =3D phb, + .size =3D count, + .parent =3D parent, + }; + + phb->dev_domain =3D msi_create_parent_irq_domain(&info, &pseries_msi_pare= nt_ops); if (!phb->dev_domain) { - pr_err("PCI: failed to create IRQ domain bridge %pOF (domain %d)\n", - phb->dn, phb->global_number); - irq_domain_free_fwnode(phb->fwnode); - return -ENOMEM; - } - - phb->msi_domain =3D pci_msi_create_irq_domain(of_fwnode_handle(phb->dn), - &pseries_msi_domain_info, - phb->dev_domain); - if (!phb->msi_domain) { pr_err("PCI: failed to create MSI IRQ domain bridge %pOF (domain %d)\n", phb->dn, phb->global_number); - irq_domain_free_fwnode(phb->fwnode); - irq_domain_remove(phb->dev_domain); return -ENOMEM; } =20 @@ -646,12 +632,8 @@ int pseries_msi_allocate_domains(struct pci_controller= *phb) =20 void pseries_msi_free_domains(struct pci_controller *phb) { - if (phb->msi_domain) - irq_domain_remove(phb->msi_domain); if (phb->dev_domain) irq_domain_remove(phb->dev_domain); - if (phb->fwnode) - irq_domain_free_fwnode(phb->fwnode); } =20 static void rtas_msi_pci_irq_fixup(struct pci_dev *pdev) --=20 2.39.5