From nobody Fri Dec 19 18:59:59 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 01FAE2989B0; Tue, 14 Oct 2025 09:58:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760435936; cv=none; b=WpA2BPYwpHgJSdrkhcS4Z4wXcnLfVenZPERVm+/URJJ3iHRK4vA3YN7mi18+W6x9AdOKEjrR7B2ohSzC4gY5gMx+rMzN6BvWHVNPmsaCqPaJYhVdybjre/iEQbGacZ6giCuAHLYSQD70srG0um/94FkP/Yd4hiFWBDfWK/fOmwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760435936; c=relaxed/simple; bh=Pz/+OnScQH57lMVcQRcBDaL0cFCYDLZVarTyxcsqluU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qCB5Uiy0bRNe3d7tg951NpN1BnpJWo37DB8tMpwjGDv82LHMfxtzlaBVWq4KBvAkTXlYWMq1euTC945GnDvA1ggHiyHAkGAHMEFXcGjr5FBQzzZWUcJQGrxmbKCMMIOw6Gd4D6rz2/XqtHNJUJSVaEveYrsM1q3sCjIr7F41Oks= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=edoqiV/k; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="edoqiV/k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 160DBC4CEFE; Tue, 14 Oct 2025 09:58:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760435935; bh=Pz/+OnScQH57lMVcQRcBDaL0cFCYDLZVarTyxcsqluU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=edoqiV/k6P/4eC65o+fGDDwFlqeSjogcWgXII7+/HSoXlyV+dVySXOkP951zajF1S xSqlCB8VMUB/7DJUfLTnq4l8LetnDf95Se05UWSLoVaKkMmZkXqit/GUwMQ4XYkVh7 KbDpR4boCDapn1e1kPWP93/TYt99EAoIeFdgeRLiW9AuZVBFPmJMS86Em077WVIQuk Em5p7L+9Atl1BdIhUa6Gx5uCvoeBXlOdDyCEXo/kZ2PjyIcBebc7LJLr4hvJwM+KWO jwVSIQzQkSffP3QBaV6ZbWTo2Wty8jOl6WIiPZKX9dgKtlblkGfOEH3yUc5epe7lNC xwVoE1jPGaQvA== From: Lorenzo Pieralisi To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, Lorenzo Pieralisi , Sascha Bischoff , Rob Herring , Marc Zyngier , Scott Branden , Thomas Gleixner , Bjorn Helgaas , Ray Jui , Frank Li , Manivannan Sadhasivam , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= Subject: [PATCH v2 1/4] of/irq: Add msi-parent check to of_msi_xlate() Date: Tue, 14 Oct 2025 11:58:42 +0200 Message-ID: <20251014095845.1310624-2-lpieralisi@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251014095845.1310624-1-lpieralisi@kernel.org> References: <20251014095845.1310624-1-lpieralisi@kernel.org> 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" In some legacy platforms the MSI controller for a PCI host bridge is identified by an msi-parent property whose phandle points at an MSI controller node with no #msi-cells property, that implicitly means For such platforms, mapping a device ID and retrieving the MSI controller node becomes simply a matter of checking whether in the device hierarchy there is an msi-parent property pointing at an MSI controller node with such characteristics. Add a helper function to of_msi_xlate() to check the msi-parent property in addition to msi-map and retrieve the MSI controller node (with a 1:1 ID deviceID-IN<->deviceID-OUT mapping) to provide support for deviceID mapping and MSI controller node retrieval for such platforms. Fixes: 57d72196dfc8 ("irqchip/gic-v5: Add GICv5 ITS support") Signed-off-by: Lorenzo Pieralisi Cc: Sascha Bischoff Cc: Rob Herring Cc: Marc Zyngier --- drivers/of/irq.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/drivers/of/irq.c b/drivers/of/irq.c index 65c3c23255b7..e67b2041e73b 100644 --- a/drivers/of/irq.c +++ b/drivers/of/irq.c @@ -671,6 +671,35 @@ void __init of_irq_init(const struct of_device_id *mat= ches) } } =20 +static int of_check_msi_parent(struct device_node *dev_node, struct device= _node **msi_node) +{ + struct of_phandle_args msi_spec; + int ret; + + /* + * An msi-parent phandle with a missing or =3D=3D 0 #msi-cells + * property identifies a 1:1 ID translation mapping. + * + * Set the msi controller node if the firmware matches this + * condition. + */ + ret =3D of_parse_phandle_with_optional_args(dev_node, "msi-parent", "#msi= -cells", + 0, &msi_spec); + if (!ret) { + if ((*msi_node && *msi_node !=3D msi_spec.np) || msi_spec.args_count != =3D 0) + ret =3D -EINVAL; + + if (!ret) { + /* Return with a node reference held */ + *msi_node =3D msi_spec.np; + return 0; + } + of_node_put(msi_spec.np); + } + + return ret; +} + /** * of_msi_xlate - map a MSI ID and find relevant MSI controller node * @dev: device for which the mapping is to be done. @@ -678,7 +707,7 @@ void __init of_irq_init(const struct of_device_id *matc= hes) * @id_in: Device ID. * * Walk up the device hierarchy looking for devices with a "msi-map" - * property. If found, apply the mapping to @id_in. + * or "msi-parent" property. If found, apply the mapping to @id_in. * If @msi_np points to a non-NULL device node pointer, only entries targe= ting * that node will be matched; if it points to a NULL value, it will receiv= e the * device node of the first matching target phandle, with a reference held. @@ -692,12 +721,15 @@ u32 of_msi_xlate(struct device *dev, struct device_no= de **msi_np, u32 id_in) =20 /* * Walk up the device parent links looking for one with a - * "msi-map" property. + * "msi-map" or an "msi-parent" property. */ - for (parent_dev =3D dev; parent_dev; parent_dev =3D parent_dev->parent) + for (parent_dev =3D dev; parent_dev; parent_dev =3D parent_dev->parent) { if (!of_map_id(parent_dev->of_node, id_in, "msi-map", "msi-map-mask", msi_np, &id_out)) break; + if (!of_check_msi_parent(parent_dev->of_node, msi_np)) + break; + } return id_out; } =20 --=20 2.50.1 From nobody Fri Dec 19 18:59:59 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8A8872EAB70; Tue, 14 Oct 2025 09:59:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760435940; cv=none; b=KP8ikDMbftuj8Fd0M0aJx0FH2VVcfCcSYBm3iABlKi4n1TppuBi5eyza1C1beyiXD5O/+qTeFRf2nwbYeEjivj49cnCEbf5oTdz2pHEgGDNaBKarkCN3nkTPoQBbD7wYTh8QfCQmtd7QVJVwIeIoFB7DiXeGEkmxBdrylbhP860= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760435940; c=relaxed/simple; bh=T1moSDjDx6AIFQ4/WCSXt0NBcwIuqhZV4QnKZW8jK0I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SttIkAa3s9c+Q4ZmM3+lB0RtNuFV0q93EZ7vV7MehjZv/Te07ECyJgn8V95tPevXHkClM41BJRxe+vRsM6s06gTQ3lsLiJM78Ft3Wt8Bu0Oy41bAqvsxT3tkeP6NFQ8WI2NNnkmv48H+1YEr+tIjesKbEpQwWliMmoyqQUDWZY8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MMnrRDku; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MMnrRDku" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 667EBC16AAE; Tue, 14 Oct 2025 09:58:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760435940; bh=T1moSDjDx6AIFQ4/WCSXt0NBcwIuqhZV4QnKZW8jK0I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MMnrRDku3v2pqZdglfonyg3bHwZ+UdM1d/NZeQMlHg6s9RC4KL8bXP59YarcKXwEm lrRp2iCjsFsW5B0DY61+FEKqnKAd0xc1mZtakjX2rS+jIOTQG1CGdq70q2zB6bARYE rvG2fdupt7AY0Fp/7sGYeqjs8tbJ7+pMbJBnImjRfAz8V7463irI+JhMAs4+RHkN/y 6MkkU3nxUlFsxStckBODhVCB254o+nozhu+GrvoOuNxnM5VYtCp/C4/P9hW+46NVrt UUUfgkPCOhw2uwOt1+cLc8z/CoaimVjnyJEIWf+HmmY9iewa5C2L1y9Yz0evvbUTaS Otv77qBqsc54Q== From: Lorenzo Pieralisi To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, Lorenzo Pieralisi , Rob Herring , Sascha Bischoff , Scott Branden , Thomas Gleixner , Bjorn Helgaas , Ray Jui , Frank Li , Manivannan Sadhasivam , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Marc Zyngier Subject: [PATCH v2 2/4] of/irq: Fix OF node refcount in of_msi_get_domain() Date: Tue, 14 Oct 2025 11:58:43 +0200 Message-ID: <20251014095845.1310624-3-lpieralisi@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251014095845.1310624-1-lpieralisi@kernel.org> References: <20251014095845.1310624-1-lpieralisi@kernel.org> 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" In of_msi_get_domain() if the iterator loop stops early because an irq_domain match is detected, an of_node_put() on the iterator node is needed to keep the OF node refcount in sync. Add it. Signed-off-by: Lorenzo Pieralisi Cc: Rob Herring --- drivers/of/irq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/of/irq.c b/drivers/of/irq.c index e67b2041e73b..9f6cd5abba76 100644 --- a/drivers/of/irq.c +++ b/drivers/of/irq.c @@ -773,8 +773,10 @@ struct irq_domain *of_msi_get_domain(struct device *de= v, =20 of_for_each_phandle(&it, err, np, "msi-parent", "#msi-cells", 0) { d =3D irq_find_matching_host(it.node, token); - if (d) + if (d) { + of_node_put(it.node); return d; + } } =20 return NULL; --=20 2.50.1 From nobody Fri Dec 19 18:59:59 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C34262EBDC5; Tue, 14 Oct 2025 09:59:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760435944; cv=none; b=VfHuOlVUto5hGV/xzOG1JphDfT2y8VdI3uLoce3SWD/u0lUCiHNrEHlXHAlTrMtPf/GxeOg4RagZ5eZ3SJPzT/kpSnGBfo98fUueucS5Kx0vzzQur+Lpwn7jNmymZ9VyiLdR9Qqe0IID/yAbXgkB7wLuEkZWW0/mHjl7ioPL2X0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760435944; c=relaxed/simple; bh=web6L5TPZtt08mmDaVYY7W2Sw34M19ouNiW4LSSozIA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tUNn3W8c5OJwifl+0HQwDhpDvhVDFJKhnpAJNKmFBnHOWLMR7tTrtSFloZHfI1wlQPP6PEtMz8rwA2s11goJ9GGZaepaRq09B5QpT3iUc15B3biWuYROgE5+ML5TmciU7608lYGkwAVKMVGOovXSSYe7cK4t4CR7uiyRvhY8eJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CW4Fk7su; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CW4Fk7su" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD593C4CEFE; Tue, 14 Oct 2025 09:59:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760435944; bh=web6L5TPZtt08mmDaVYY7W2Sw34M19ouNiW4LSSozIA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CW4Fk7su9ktygG9em7DYneoB5NZEhF1lHm6qbCu+Glsy/c/BN3c30aeBMbgwEv/RE kFmBrCAtgTDaHTponbit3MU91WvDRrIHFX1BtJb1jWWm87OV3le2lgbeziOMfMtJ3n WxSy3lnCrhiys6R0E1RsOdaKAXnK2MjvD42z5rzMLq1oESvB8QoDro5vDjqXpgEROP HpgGtvLuiBn/UM1140634Z74Avx+Cv5N0WfRGEQO664AyP062nmzcPgLMkiF/x56mQ CAIv9U4TZRomqdQ3tTakBkJcKPjCdjKypYs9mc04vRR8VnviUETrfFkCaDrfT1651z ZOS6VC270CVnA== From: Lorenzo Pieralisi To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, Lorenzo Pieralisi , Scott Branden , Bjorn Helgaas , Rob Herring , Ray Jui , Manivannan Sadhasivam , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Sascha Bischoff , Thomas Gleixner , Frank Li , Marc Zyngier Subject: [PATCH v2 3/4] PCI: iproc: Implement MSI controller node detection with of_msi_xlate() Date: Tue, 14 Oct 2025 11:58:44 +0200 Message-ID: <20251014095845.1310624-4-lpieralisi@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251014095845.1310624-1-lpieralisi@kernel.org> References: <20251014095845.1310624-1-lpieralisi@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The functionality implemented in the iproc driver in order to detect an OF MSI controller node is now fully implemented in of_msi_xlate(). Replace the current msi-map/msi-parent parsing code with of_msi_xlate(). Since of_msi_xlate() is also a deviceID mapping API, pass in a fictitious 0 as deviceID - the driver only requires detecting the OF MSI controller node not the deviceID mapping per-se (of_msi_xlate() return value is ignored for the same reason). Signed-off-by: Lorenzo Pieralisi Cc: Scott Branden Cc: Bjorn Helgaas Cc: Rob Herring Cc: Ray Jui Cc: Manivannan Sadhasivam Cc: "Krzysztof Wilczy=C5=84ski" --- drivers/pci/controller/pcie-iproc.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/drivers/pci/controller/pcie-iproc.c b/drivers/pci/controller/p= cie-iproc.c index 22134e95574b..ccf71993ea35 100644 --- a/drivers/pci/controller/pcie-iproc.c +++ b/drivers/pci/controller/pcie-iproc.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -1337,29 +1338,16 @@ static int iproc_pcie_msi_steer(struct iproc_pcie *= pcie, =20 static int iproc_pcie_msi_enable(struct iproc_pcie *pcie) { - struct device_node *msi_node; + struct device_node *msi_node =3D NULL; int ret; =20 /* * Either the "msi-parent" or the "msi-map" phandle needs to exist * for us to obtain the MSI node. */ - - msi_node =3D of_parse_phandle(pcie->dev->of_node, "msi-parent", 0); - if (!msi_node) { - const __be32 *msi_map =3D NULL; - int len; - u32 phandle; - - msi_map =3D of_get_property(pcie->dev->of_node, "msi-map", &len); - if (!msi_map) - return -ENODEV; - - phandle =3D be32_to_cpup(msi_map + 1); - msi_node =3D of_find_node_by_phandle(phandle); - if (!msi_node) - return -ENODEV; - } + of_msi_xlate(pcie->dev, &msi_node, 0); + if (!msi_node) + return -ENODEV; =20 /* * Certain revisions of the iProc PCIe controller require additional --=20 2.50.1 From nobody Fri Dec 19 18:59:59 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5BA2F2EBDC5; Tue, 14 Oct 2025 09:59:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760435949; cv=none; b=LLIhfwE+5OrO/H88sAtCIQaKEaIq5XDipK3fYPp/N/FeRBJFANprzLzHOOaojPhGI6dTpNkWSeYhR9GnSp4ConHUet0FCPz+gtRLSAJVP+dH9q0e86zUpKNNytYWT/sxvBvG2pTc9Zt/sISgHSyZbNUVw6i9Ui9klRcFoX/0tPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760435949; c=relaxed/simple; bh=Y0bEX5hkAWRJGif5UBaJSI/DJMYF6LpNlNLgCxXcdQ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZUqGTotezM5C5Gfn+8aJ6LPYdZpoK7gaH6PWLtEpo0J225GgCtZVXQ2M5Xss0W5Dvhz9GFzGuyJ/lArhOyLh98khyOmjjLE5rBg91KQvs6AAGwlxdtNYAd+38KISVeS/WcnSILcrvFAK8IqbUMz6lDDuYKaCx9HYUNHNBLoDaKY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OgAAaxiV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OgAAaxiV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 075D9C4CEE7; Tue, 14 Oct 2025 09:59:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760435948; bh=Y0bEX5hkAWRJGif5UBaJSI/DJMYF6LpNlNLgCxXcdQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OgAAaxiVcgTmp+m3JLTe9FVIKnHuVzIyx7Zd6lxzOOsRxgW/1jR+2UWkpI+lcgQ6V JlSRhEOKj6zTUaNJ5Kmqh6lGuXNMdrvEhycEn4LVjlCWPg6db+whgEjKao8qeDGPYE 7iETeBDpoqKAYQPqksB+k5aNRuOcrO08Uoz8inrI6l1rhq90hn0XotgXYPhRNpz7Ne KqFbmn/fOWSGwzhT1ymEnGGg4+E5J2gnelPEofdRnhqOu+GD9J4GRyn07uHAJx+WIT zBxnNaP2PB4gCZOJ0+vDCnv81jPJ2BanIy+TF93TE1s5Qps/gH+rbjufpGJT4GX6zy H8EZYZg9jknmA== From: Lorenzo Pieralisi To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, Lorenzo Pieralisi , Sascha Bischoff , Thomas Gleixner , Rob Herring , Frank Li , Marc Zyngier , Scott Branden , Bjorn Helgaas , Ray Jui , Manivannan Sadhasivam , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= Subject: [PATCH v2 4/4] irqchip/gic-its: Rework platform MSI deviceID detection Date: Tue, 14 Oct 2025 11:58:45 +0200 Message-ID: <20251014095845.1310624-5-lpieralisi@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251014095845.1310624-1-lpieralisi@kernel.org> References: <20251014095845.1310624-1-lpieralisi@kernel.org> 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" Current code retrieving platform devices MSI devID in the GIC ITS MSI parent helpers suffers from some minor issues: - It leaks a struct device_node reference - It triggers an excessive WARN_ON on wrong of_phandle_args count detection - It is duplicated between GICv3 and GICv5 for no good reason - It does not use the OF phandle iterator code that simplifies the msi-parent property parsing Implement a helper function that addresses the full set of issues in one go by consolidating GIC v3 and v5 code and converting the msi-parent parsing loop to the more modern OF phandle iterator API, fixing the struct device_node reference leak in the process. Signed-off-by: Lorenzo Pieralisi Cc: Sascha Bischoff Cc: Thomas Gleixner Cc: Rob Herring Cc: Frank Li Cc: Marc Zyngier --- drivers/irqchip/irq-gic-its-msi-parent.c | 98 ++++++++---------------- 1 file changed, 33 insertions(+), 65 deletions(-) diff --git a/drivers/irqchip/irq-gic-its-msi-parent.c b/drivers/irqchip/irq= -gic-its-msi-parent.c index eb1473f1448a..a65f762b7dd4 100644 --- a/drivers/irqchip/irq-gic-its-msi-parent.c +++ b/drivers/irqchip/irq-gic-its-msi-parent.c @@ -142,83 +142,51 @@ static int its_v5_pci_msi_prepare(struct irq_domain *= domain, struct device *dev, #define its_v5_pci_msi_prepare NULL #endif /* !CONFIG_PCI_MSI */ =20 -static int of_pmsi_get_dev_id(struct irq_domain *domain, struct device *de= v, - u32 *dev_id) +static int __of_pmsi_get_dev_id(struct irq_domain *domain, struct device *= dev, u32 *dev_id, + phys_addr_t *pa, bool is_v5) { - int ret, index =3D 0; + struct of_phandle_iterator it; + uint32_t args; + int ret; =20 /* Suck the DeviceID out of the msi-parent property */ - do { - struct of_phandle_args args; + of_for_each_phandle(&it, ret, dev->of_node, "msi-parent", "#msi-cells", -= 1) { + /* GICv5 ITS domain matches the MSI controller node parent */ + struct device_node *np __free(device_node) =3D is_v5 ? of_get_parent(it.= node) + : of_node_get(it.node); =20 - ret =3D of_parse_phandle_with_args(dev->of_node, - "msi-parent", "#msi-cells", - index, &args); - if (args.np =3D=3D irq_domain_get_of_node(domain)) { - if (WARN_ON(args.args_count !=3D 1)) - return -EINVAL; - *dev_id =3D args.args[0]; - break; + if (np =3D=3D irq_domain_get_of_node(domain)) { + if (of_phandle_iterator_args(&it, &args, 1) !=3D 1) { + dev_warn(dev, "Bogus msi-parent property\n"); + ret =3D -EINVAL; + } + + if (!ret && is_v5) + ret =3D its_translate_frame_address(it.node, pa); + + if (!ret) + *dev_id =3D args; + + of_node_put(it.node); + return ret; } - index++; - } while (!ret); - - if (ret) { - struct device_node *np =3D NULL; - - ret =3D of_map_id(dev->of_node, dev->id, "msi-map", "msi-map-mask", &np,= dev_id); - if (np) - of_node_put(np); } =20 - return ret; + struct device_node *msi_ctrl __free(device_node) =3D NULL; + + return of_map_id(dev->of_node, dev->id, "msi-map", "msi-map-mask", &msi_c= trl, dev_id); +} + +static int of_pmsi_get_dev_id(struct irq_domain *domain, struct device *de= v, + u32 *dev_id) +{ + return __of_pmsi_get_dev_id(domain, dev, dev_id, NULL, false); } =20 static int of_v5_pmsi_get_msi_info(struct irq_domain *domain, struct devic= e *dev, u32 *dev_id, phys_addr_t *pa) { - int ret, index =3D 0; - /* - * Retrieve the DeviceID and the ITS translate frame node pointer - * out of the msi-parent property. - */ - do { - struct of_phandle_args args; - - ret =3D of_parse_phandle_with_args(dev->of_node, - "msi-parent", "#msi-cells", - index, &args); - if (ret) - break; - /* - * The IRQ domain fwnode is the msi controller parent - * in GICv5 (where the msi controller nodes are the - * ITS translate frames). - */ - if (args.np->parent =3D=3D irq_domain_get_of_node(domain)) { - if (WARN_ON(args.args_count !=3D 1)) - return -EINVAL; - *dev_id =3D args.args[0]; - - ret =3D its_translate_frame_address(args.np, pa); - if (ret) - return -ENODEV; - break; - } - index++; - } while (!ret); - - if (ret) { - struct device_node *np =3D NULL; - - ret =3D of_map_id(dev->of_node, dev->id, "msi-map", "msi-map-mask", &np,= dev_id); - if (np) { - ret =3D its_translate_frame_address(np, pa); - of_node_put(np); - } - } - - return ret; + return __of_pmsi_get_dev_id(domain, dev, dev_id, pa, true); } =20 int __weak iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id) --=20 2.50.1