From nobody Sun May 3 14:26:26 2026 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (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 337E0346774 for ; Fri, 24 Apr 2026 05:57:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777010258; cv=none; b=NkljjoOerMWK1AzruPVy88nFkcQ5xeHzCp719vMi8E6zmDZciJ4Sb9KUSeU/U3Tiv42kZ+KzSa0fpA98A/EfUG8/9pUa5+eBwrN8+HoN+yVc/lUwtoFeBJ8cgvgmfDT0xnabXZkVj/vdo8/IUWDcfvUwWXuq2KdRXHuMyax0H3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777010258; c=relaxed/simple; bh=bmn9oR4CHseVq+Q1yzNkzndMq0RHssJSS9rv7b6NSno=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SS+5Vp+ZmRhuLZ5TPVVWNnWynwujMOuK/jXrCSVC97ie927iC4QEQluLq33HnxaePGhVSXYL8RjXyf/kBDu7ZlvKjDiSFqzeF3ekc8GuTe/2gTgLLGyELjEUGQTqLhC4YJH91caJOK2omCDrihF73ND7Mbh3v1LfFpclZIPDEhk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=g7cfeXDV; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=cRWhveqQ; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="g7cfeXDV"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="cRWhveqQ" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63O433cS010155 for ; Fri, 24 Apr 2026 05:57:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= QkYW84mNfsxJu25KdM9HhqHWqHHn7yyj15gOr+bOnfo=; b=g7cfeXDVAn3snLm6 E1quUpkxWxFy4WplkkUVShkx7qxuwSa8rSOoL5CQj0TiunCMKlVceeHnJ1DJA5LA bp6L7idWgJBpIEFmCYpTOUOWbQ9+mgBg+IfduEullKSfB7BkALiGYfBNv9GnPeVB 7sl6a2UzIflDbUnDp9gDH1YtKfab1C1vLw1rnSEWmCWusw52GfaF2/XAow5rAV4u zvb/J4VqYDvAOxHKVo9s93kaSVfvCTgslusZ4AWRcVXvWpjd967QbRiN+yNq2IDN jiIHmrprUjiFsVfm9uP21SRsU7Wtqzy6u6znqP4vSahr9cI4i7DNkXSOil08nQRY +YR/pg== Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dqk17brk3-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 24 Apr 2026 05:57:36 +0000 (GMT) Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-3595485abbbso9353380a91.2 for ; Thu, 23 Apr 2026 22:57:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1777010255; x=1777615055; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=QkYW84mNfsxJu25KdM9HhqHWqHHn7yyj15gOr+bOnfo=; b=cRWhveqQsFIndYfhkoHDFxqlTPAuaIBDPk4/2zgZWObo6XwWu9X1Fv4g1i1vrufuA5 vFlm42jSk+Ljo39gjqK2mBDrr9V5O5vPc1diTbuemKD07B/Kbjh9XECOcwt2QOlE2AeQ lwFfAacw+PaINtdcEXXG7nb/dm4Wzq1S5U0504bgLoYaSNA541+CRHpqmc94zVo3i2B5 HUj0HlTCACv8KrOWH8NPW4dPSgKfkYLUBPWQUu/2GNlMvsYU0BqNjh3wykhjQD482h/c WibfotoQcHCR5NrLf54y/txO9KMSEpoqCY+UisWoEN3ryx1by3WrQ/yH125m7ya84iii Jh6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777010255; x=1777615055; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=QkYW84mNfsxJu25KdM9HhqHWqHHn7yyj15gOr+bOnfo=; b=O9DdyhfuIb6ILTfrak/Eu53ynYfz+PY2+PHXuDZcCpRp5+xoWl3N48mK0Tu/reW6+u lyll35zCXv76lVX8tAgM2uKAX7fNWCzFMZhbdPWC1GnpMmX+2V2hGPd6ZH2VZyS++xsn pr+NRwmjsGF7b1MJo4bNrlv+z4BqjJ5OQoujtbbntZXYGdu6MSoTlyNL26GYY8GNQ8nC soOtNiriC+H5nAcB3iuMjW/5dJV/GzTMcDgjU/CVgirnatO9iBgSqvTKhV+8AjWKsSf7 JfKtTs00Hel1uxb1qjKuggh1IfFXUrPpGdwwsvkUxg7OTEi6h29mOx/RMmgASIEjyT5d Fj6g== X-Gm-Message-State: AOJu0YzT90TmG561yz6jWFQoEVr7jNAcGv1mBe5nThBMXqXem1563gYa MtQ12DVZjeNxE2C61dL692LzYp56IgbMwqNl9qhbk/EoubUfEkvizLpezcd3hePR9y8nwDIHAbg OU1b7FPqU1SWYwye4YDALgw+2IxI5JHr/Ezvah95q8lBbYKnYoafYrbO+wjPrCsoT9pQ= X-Gm-Gg: AeBDiesz85eYoINPUgXfhFEX7DTpoiiOmJKBO+X7VWnDKdBXlxP0GbhejFjM3GPNpDB MIi+n3iBbZ/wt4niR5C6ApDJMt9D67XnWKX/tKKHSUkP6G2YazPDoFy99PrSwo8mlC8sW8YLLgg fdvJSNKVbMZEcqpphXIKzgYg0ZdZORoaRHKQVro6Ifx6e7HPA76Nrg/SS1JETVXYnIsb6YZtZ/i EHTD+ZfWfOzWNxDMARezfabVqk0+oRVEZ7R1npP+CbaoaXAVls0rqE/ufr+hpkeW6uPh0bd+6Tb PB6tTF4OAQo7EBaSCx/0ypWD2KgALUtxTDiD8oiYGSxku9HYAJ5+Sg6OOlkdIgmJnHBwt8VlUwZ VmPogAJpdN2e7ZhMZOa5oHWX1sEByOlTwKLSdik6tzfZBqo+bo4XZkD2NevAejr/PbTI= X-Received: by 2002:a05:6a21:9983:b0:39c:12c5:c6f5 with SMTP id adf61e73a8af0-3a08d73bfe5mr32758961637.18.1777010254769; Thu, 23 Apr 2026 22:57:34 -0700 (PDT) X-Received: by 2002:a05:6a21:9983:b0:39c:12c5:c6f5 with SMTP id adf61e73a8af0-3a08d73bfe5mr32758909637.18.1777010254185; Thu, 23 Apr 2026 22:57:34 -0700 (PDT) Received: from hu-vjitta-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c79770512afsm17288101a12.31.2026.04.23.22.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 22:57:33 -0700 (PDT) From: Vijayanand Jitta Date: Fri, 24 Apr 2026 11:26:08 +0530 Subject: [PATCH v14 1/3] of: Add convenience wrappers for of_map_id() 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 Message-Id: <20260424-parse_iommu_cells-v14-1-fd02f11b6c38@oss.qualcomm.com> References: <20260424-parse_iommu_cells-v14-0-fd02f11b6c38@oss.qualcomm.com> In-Reply-To: <20260424-parse_iommu_cells-v14-0-fd02f11b6c38@oss.qualcomm.com> To: Nipun Gupta , Nikhil Agarwal , Joerg Roedel , Will Deacon , Robin Murphy , Marc Zyngier , Lorenzo Pieralisi , Thomas Gleixner , Saravana Kannan , Richard Zhu , Lucas Stach , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Manivannan Sadhasivam , Bjorn Helgaas , Frank Li , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Dmitry Baryshkov , Konrad Dybcio , Bjorn Andersson , Rob Herring , Conor Dooley , Krzysztof Kozlowski , Prakash Gupta , Vikash Garodia Cc: linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, xen-devel@lists.xenproject.org, linux-arm-msm@vger.kernel.org, Vijayanand Jitta X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777010232; l=8620; i=vijayanand.jitta@oss.qualcomm.com; s=20260301; h=from:subject:message-id; bh=Bsp9hT6sgzNh1NrIZ0uduUy4Yj5U0gq9szC+ECoPqVA=; b=8NWpPedhLlqQ7b2HqBvErn44emkQL1+f69yBIykemc4nTU8mhLdWyBM6UrLv2aTheTYRGoULf 4gmGUfVAgn/Dyc1fN3co5ZAOWZ919HjRTHUr8oPlkiKa+0pRuDTHh2z X-Developer-Key: i=vijayanand.jitta@oss.qualcomm.com; a=ed25519; pk=Lpi7Cs3wHe8KZtqvyci7FTOLzsKpEHKGCaPNZw+1zRI= X-Proofpoint-GUID: T49bkF_yec314CQBBLfho5nqN01FmpB1 X-Authority-Analysis: v=2.4 cv=R98z39RX c=1 sm=1 tr=0 ts=69eb0650 cx=c_pps a=vVfyC5vLCtgYJKYeQD43oA==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yx91gb_oNiZeI1HMLzn7:22 a=7CQSdrXTAAAA:8 a=VwQbUJbxAAAA:8 a=8AirrxEcAAAA:8 a=1XWaLZrsAAAA:8 a=EUspDBNiAAAA:8 a=f4O9XJQV64orvU1ydW8A:9 a=QEXdDO2ut3YA:10 a=rl5im9kqc5Lf4LNbBjHf:22 a=a-qgeE7W1pNrGK8U0ZQC:22 a=ST-jHhOKWsTCqRlWije3:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDI0MDA1MSBTYWx0ZWRfX2BbU1uHjdq/Z +gSAGfQnlrIPtUnLmgRn9EuKz6jL88yhv0vuUHT3gUAQonjvYFLWk0h3x3Pa/RLLaAfDT4lpfVy X/+CAyxS6pf7N2mSOGWmVpFnGtvn2CFMDyK1O+LCMwry8gLCjHBcjrF3XmCGlHUoYSM1vWTWa71 3K9d0nNrvULkcqpVXrb1ER6aCkjXs+gab9AdeKE+wisjYqo2Y5x4KDfa/Ge6K7hiw7F9WTyPKi+ Rt2ZTJdyYW6yM/oP/MJFEZxm6vwzDvH4FtKvVFAPmyZD2yeRp1I3++xUR2EcWy1fEank/4bg81i w5g2Hv76tN2Z0qAc85fHVur11SqAcXxw97E1PjPbVpqfHReF+xS4gxW5uiNN9nTSbI387iXi+Xe Sowal2nYnbNvSgvKVq44t8eFqgy6gkDqLibZ0FHejnbQWdvHEEHaze/oKmCHN5SVSjv0MMbwV1G iN4xFUO0aTc25JhxV/w== X-Proofpoint-ORIG-GUID: T49bkF_yec314CQBBLfho5nqN01FmpB1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-23_03,2026-04-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 spamscore=0 clxscore=1015 priorityscore=1501 phishscore=0 malwarescore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2604240051 From: Robin Murphy Since we now have quite a few users parsing "iommu-map" and "msi-map" properties, give them some wrappers to conveniently encapsulate the appropriate sets of property names. This will also make it easier to then change of_map_id() to correctly account for specifier cells. Reviewed-by: Rob Herring (Arm) Reviewed-by: Frank Li Acked-by: Marc Zyngier Acked-by: Bjorn Helgaas Signed-off-by: Robin Murphy Signed-off-by: Vijayanand Jitta --- drivers/cdx/cdx_msi.c | 3 +-- drivers/iommu/of_iommu.c | 4 +--- drivers/irqchip/irq-gic-its-msi-parent.c | 2 +- drivers/of/base.c | 38 ++++++++++++++++++++++++++++= ++++ drivers/of/irq.c | 3 +-- drivers/pci/controller/dwc/pci-imx6.c | 6 ++--- drivers/pci/controller/pcie-apple.c | 3 +-- drivers/xen/grant-dma-ops.c | 3 +-- include/linux/of.h | 18 +++++++++++++++ 9 files changed, 64 insertions(+), 16 deletions(-) diff --git a/drivers/cdx/cdx_msi.c b/drivers/cdx/cdx_msi.c index 91b95422b263..63b3544ec997 100644 --- a/drivers/cdx/cdx_msi.c +++ b/drivers/cdx/cdx_msi.c @@ -128,8 +128,7 @@ static int cdx_msi_prepare(struct irq_domain *msi_domai= n, int ret; =20 /* Retrieve device ID from requestor ID using parent device */ - ret =3D of_map_id(parent->of_node, cdx_dev->msi_dev_id, "msi-map", "msi-m= ap-mask", - NULL, &dev_id); + ret =3D of_map_msi_id(parent->of_node, cdx_dev->msi_dev_id, NULL, &dev_id= ); if (ret) { dev_err(dev, "of_map_id failed for MSI: %d\n", ret); return ret; diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index 6b989a62def2..a511ecf21fcd 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -48,9 +48,7 @@ static int of_iommu_configure_dev_id(struct device_node *= master_np, struct of_phandle_args iommu_spec =3D { .args_count =3D 1 }; int err; =20 - err =3D of_map_id(master_np, *id, "iommu-map", - "iommu-map-mask", &iommu_spec.np, - iommu_spec.args); + err =3D of_map_iommu_id(master_np, *id, &iommu_spec.np, iommu_spec.args); if (err) return err; =20 diff --git a/drivers/irqchip/irq-gic-its-msi-parent.c b/drivers/irqchip/irq= -gic-its-msi-parent.c index d36b278ae66c..b63343a227a9 100644 --- a/drivers/irqchip/irq-gic-its-msi-parent.c +++ b/drivers/irqchip/irq-gic-its-msi-parent.c @@ -180,7 +180,7 @@ static int of_pmsi_get_msi_info(struct irq_domain *doma= in, struct device *dev, u =20 struct device_node *msi_ctrl __free(device_node) =3D NULL; =20 - return of_map_id(dev->of_node, dev->id, "msi-map", "msi-map-mask", &msi_c= trl, dev_id); + return of_map_msi_id(dev->of_node, dev->id, &msi_ctrl, dev_id); } =20 static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev, diff --git a/drivers/of/base.c b/drivers/of/base.c index 57420806c1a2..ae04487bd614 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2201,3 +2201,41 @@ int of_map_id(const struct device_node *np, u32 id, return 0; } EXPORT_SYMBOL_GPL(of_map_id); + +/** + * of_map_iommu_id - Translate an ID using "iommu-map" bindings. + * @np: root complex device node. + * @id: Requester ID of the device (e.g. PCI RID/BDF or a platform + * stream/device ID) used as the lookup key in the iommu-map table. + * @target: optional pointer to a target device node. + * @id_out: optional pointer to receive the translated ID. + * + * Convenience wrapper around of_map_id() using "iommu-map" and "iommu-map= -mask". + * + * Return: 0 on success or a standard error code on failure. + */ +int of_map_iommu_id(const struct device_node *np, u32 id, + struct device_node **target, u32 *id_out) +{ + return of_map_id(np, id, "iommu-map", "iommu-map-mask", target, id_out); +} +EXPORT_SYMBOL_GPL(of_map_iommu_id); + +/** + * of_map_msi_id - Translate an ID using "msi-map" bindings. + * @np: root complex device node. + * @id: Requester ID of the device (e.g. PCI RID/BDF or a platform + * stream/device ID) used as the lookup key in the msi-map table. + * @target: optional pointer to a target device node. + * @id_out: optional pointer to receive the translated ID. + * + * Convenience wrapper around of_map_id() using "msi-map" and "msi-map-mas= k". + * + * Return: 0 on success or a standard error code on failure. + */ +int of_map_msi_id(const struct device_node *np, u32 id, + struct device_node **target, u32 *id_out) +{ + return of_map_id(np, id, "msi-map", "msi-map-mask", target, id_out); +} +EXPORT_SYMBOL_GPL(of_map_msi_id); diff --git a/drivers/of/irq.c b/drivers/of/irq.c index 6367c67732d2..e37c1b3f8736 100644 --- a/drivers/of/irq.c +++ b/drivers/of/irq.c @@ -817,8 +817,7 @@ u32 of_msi_xlate(struct device *dev, struct device_node= **msi_np, u32 id_in) * "msi-map" or an "msi-parent" property. */ 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)) + if (!of_map_msi_id(parent_dev->of_node, id_in, msi_np, &id_out)) break; if (!of_check_msi_parent(parent_dev->of_node, msi_np)) break; diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller= /dwc/pci-imx6.c index a5b8d0b71677..bff8289f804a 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -1144,8 +1144,7 @@ static int imx_pcie_add_lut_by_rid(struct imx_pcie *i= mx_pcie, u32 rid) u32 sid =3D 0; =20 target =3D NULL; - err_i =3D of_map_id(dev->of_node, rid, "iommu-map", "iommu-map-mask", - &target, &sid_i); + err_i =3D of_map_iommu_id(dev->of_node, rid, &target, &sid_i); if (target) { of_node_put(target); } else { @@ -1158,8 +1157,7 @@ static int imx_pcie_add_lut_by_rid(struct imx_pcie *i= mx_pcie, u32 rid) } =20 target =3D NULL; - err_m =3D of_map_id(dev->of_node, rid, "msi-map", "msi-map-mask", - &target, &sid_m); + err_m =3D of_map_msi_id(dev->of_node, rid, &target, &sid_m); =20 /* * err_m target diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/p= cie-apple.c index 2d92fc79f6dd..a0937b7b3c4d 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -764,8 +764,7 @@ static int apple_pcie_enable_device(struct pci_host_bri= dge *bridge, struct pci_d dev_dbg(&pdev->dev, "added to bus %s, index %d\n", pci_name(pdev->bus->self), port->idx); =20 - err =3D of_map_id(port->pcie->dev->of_node, rid, "iommu-map", - "iommu-map-mask", NULL, &sid); + err =3D of_map_iommu_id(port->pcie->dev->of_node, rid, NULL, &sid); if (err) return err; =20 diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c index c2603e700178..1b7696b2d762 100644 --- a/drivers/xen/grant-dma-ops.c +++ b/drivers/xen/grant-dma-ops.c @@ -325,8 +325,7 @@ static int xen_dt_grant_init_backend_domid(struct devic= e *dev, struct pci_dev *pdev =3D to_pci_dev(dev); u32 rid =3D PCI_DEVID(pdev->bus->number, pdev->devfn); =20 - if (of_map_id(np, rid, "iommu-map", "iommu-map-mask", &iommu_spec.np, - iommu_spec.args)) { + if (of_map_iommu_id(np, rid, &iommu_spec.np, iommu_spec.args)) { dev_dbg(dev, "Cannot translate ID\n"); return -ESRCH; } diff --git a/include/linux/of.h b/include/linux/of.h index be6ec4916adf..fe841f3cc747 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -465,6 +465,12 @@ int of_map_id(const struct device_node *np, u32 id, const char *map_name, const char *map_mask_name, struct device_node **target, u32 *id_out); =20 +int of_map_iommu_id(const struct device_node *np, u32 id, + struct device_node **target, u32 *id_out); + +int of_map_msi_id(const struct device_node *np, u32 id, + struct device_node **target, u32 *id_out); + phys_addr_t of_dma_get_max_cpu_address(struct device_node *np); =20 struct kimage; @@ -934,6 +940,18 @@ static inline int of_map_id(const struct device_node *= np, u32 id, return -EINVAL; } =20 +static inline int of_map_iommu_id(const struct device_node *np, u32 id, + struct device_node **target, u32 *id_out) +{ + return -EINVAL; +} + +static inline int of_map_msi_id(const struct device_node *np, u32 id, + struct device_node **target, u32 *id_out) +{ + return -EINVAL; +} + static inline phys_addr_t of_dma_get_max_cpu_address(struct device_node *n= p) { return PHYS_ADDR_MAX; --=20 2.34.1 From nobody Sun May 3 14:26:26 2026 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (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 5847334846A for ; Fri, 24 Apr 2026 05:57:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777010272; cv=none; b=rPeLljxjoakDmjV62zz5/ffKVksPHVfohQrZU099+T4pQJEnk5RwXRqrwfrpWAyp+hQ5kfJX/ddiPEt5wDmZmUwOiLgwXrD03FqYv4fAyrv2YfPpkmv7/f3SsoktUcBhQuhi91MxUIOY2pzxMJRdn0EI9IaoBn9DwH2D8XKMFS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777010272; c=relaxed/simple; bh=8nGyFizj14lxyDF8HW6ac6/uoUdkikbwz0y2rpJ/Fhk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FPxh2q6pFfFrcGBPp1dc2x1F/RsysjzJpBx0Hb2rv18MiL5mnTd9u2L7BfX7ly+NqNUrmgxcI9AjUghwpBvxSyMPEv2ZD0zn0QpyYYUZXOh5F2aJZ9Zn3j0vDzm4KRoNo5HaeXemrJZGyoQb5vBA6uo31LO0QG83a8IcPeTFfkA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=jbUw84Gl; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=JTjYmMPp; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="jbUw84Gl"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="JTjYmMPp" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63O4gwNH010073 for ; Fri, 24 Apr 2026 05:57:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= muMUt40tNKB60YlRLz7cGJMkl7zWJcvPAhdHfJ4B7Zc=; b=jbUw84GlFC/3S6Dx oh7sJ04FqBBCxaOzvCIb/8duPS2GSX9jabQSXglozhM1edlHMhqg/UkDcHZK4WBw 0TfgA3X+hQnIoztP8ouas3rPH6/hhRkCRDd+79EjpeXeS6Evlumyv5OUpLnE+PDJ vHdxODTSiZlPGMtt6mOfEyKKvqWNcGwGvwt5aZu2bFIdn2VkCTrk5RpMYU69zYwN +E4sytq7IgcGG/mQ/Lv9QqEPgCdeAxzDi2QwUbMN8StZN0Dsqm9gaLS5z7TFLdjU s3Vo1VkwFRQra3GfZa49CYxkAuGVlbQOuZsOR5/Ii7NCc3b3ETo/e5NXsvkfJ7bb 2z9N/A== Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dqk17brkm-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 24 Apr 2026 05:57:47 +0000 (GMT) Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-2b2e06219cbso94333295ad.3 for ; Thu, 23 Apr 2026 22:57:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1777010266; x=1777615066; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=muMUt40tNKB60YlRLz7cGJMkl7zWJcvPAhdHfJ4B7Zc=; b=JTjYmMPpiDyWmluNvhksu6DUL07ZE/s7aX/rJ34X64I1HxXQWPVVSRuKTvvoQndZBm P4kZTdQUiXj+e5Gwzd8nTis2Q7uV/u/JBaBJ6tQIMlQ8urRVuYJJKf66/Irn6UAgEoOy tpYyranuIgX1rgM9k6JggR6B24Stz/Rs9GRtMgfJiMpHRVJKxlMt23oCFA5CFt9hp/uw YSj3X/BwYDJ0dhSJAKxr96i/GSepXwr3QjwULYQOVh/LoizqZI1Y7rhc3FwAVkcrIjzm S58UdPFCi9wlAqVqFJa9sP8ZCWEKutFpyVuzvyeFBv4kKfzIHz7GZyzXyV9CoqQuRqnT ptrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777010266; x=1777615066; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=muMUt40tNKB60YlRLz7cGJMkl7zWJcvPAhdHfJ4B7Zc=; b=R494KSKFwP4JQoulS59auCGuYSFo2WDQwozs7/LVxHz62n6zO+jjGAZyZly3JTDH6q +OIMBmXHgT/qcutmXOAiUI8cWjkCPy0BRHCRHHQLxN2P9AU89kZsKhxYSO1RVKFgq8ZX FI2+A+OScO9yzESSfcQ1V9ZuNua54UrS0tVRD/yE+N73hVvKWEu+pWpkO8Y/tqyLWSNR z43hux55z+Yz7ZbIS+mP0RIEqlsQarIvRVKhI66i90LoIRFHkYnSHqb8t0trSzkGCgaL EYVDGV4bcuXpEi2rweEfbQptbe+f87Vg4Paz1DQLqK31TuOhLrQvnd6UdX5qWFgdhR3d sdiA== X-Gm-Message-State: AOJu0YyvqavgwPo9X9g8iqr2DkEc/a6QxUZyz2ZmaHrCGCxjkPF3ck5d NUe664rKrtSXWgsywXk2ZJ0vjs51WxjG7wNOA/JgdBunDn1WNpr3NFTsMr4Uuz6nJCw2gdE+ogc h5uXFye/2lSpHOoJzTXoHMefiba5flRyorMVqJzlbCKshBxQpnQcfXgk2Nmw0QV3DKtg= X-Gm-Gg: AeBDiettF2AO5aL06Qf56m+y1tWKtCRMRjloj4bj1SthzaUMLy4xuAAR/66+1YqUR+u gdXiv3POmGDfW2+sQ3x26zY+bRPlMNmTgSYXMsjt1riVx5gAXlCL6z0oA2MIxbPcFiRnKjQ3oT/ AcnDSotQlWkSIlkYMJk59KcJLoLE5bl0gBAyaQnyfrdhHaM0ItYOv+tC/Ihcm9NcRcuG3/KrkFQ JO5gKLNBnNF8nDmd0v70/QesgQGIN+PAxWmPDTlh00YdJVwsbKyU5w7p19k3CWLDVaYtvxk2zax E4PeFV7P3ppviVglYK0EvxMRE+9f5dOt1bBSVquURgtD6hx/UCPryDSocx7elOIdFuXZub+H8aX 7AirHAGrcyfeYX9WFm1UlvUIEAqTeoFOmVlQR95kqcaEwdR+ZyPD8dtwX1NJZ0OXMr9g= X-Received: by 2002:a05:6a21:33a5:b0:3a3:2b7e:a4ab with SMTP id adf61e73a8af0-3a32b7ebae2mr4715376637.44.1777010265669; Thu, 23 Apr 2026 22:57:45 -0700 (PDT) X-Received: by 2002:a05:6a21:33a5:b0:3a3:2b7e:a4ab with SMTP id adf61e73a8af0-3a32b7ebae2mr4715318637.44.1777010265038; Thu, 23 Apr 2026 22:57:45 -0700 (PDT) Received: from hu-vjitta-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c79770512afsm17288101a12.31.2026.04.23.22.57.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 22:57:44 -0700 (PDT) From: Vijayanand Jitta Date: Fri, 24 Apr 2026 11:26:09 +0530 Subject: [PATCH v14 2/3] of: Factor arguments passed to of_map_id() into a struct 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 Message-Id: <20260424-parse_iommu_cells-v14-2-fd02f11b6c38@oss.qualcomm.com> References: <20260424-parse_iommu_cells-v14-0-fd02f11b6c38@oss.qualcomm.com> In-Reply-To: <20260424-parse_iommu_cells-v14-0-fd02f11b6c38@oss.qualcomm.com> To: Nipun Gupta , Nikhil Agarwal , Joerg Roedel , Will Deacon , Robin Murphy , Marc Zyngier , Lorenzo Pieralisi , Thomas Gleixner , Saravana Kannan , Richard Zhu , Lucas Stach , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Manivannan Sadhasivam , Bjorn Helgaas , Frank Li , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Dmitry Baryshkov , Konrad Dybcio , Bjorn Andersson , Rob Herring , Conor Dooley , Krzysztof Kozlowski , Prakash Gupta , Vikash Garodia Cc: linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, xen-devel@lists.xenproject.org, linux-arm-msm@vger.kernel.org, Vijayanand Jitta , Charan Teja Kalla X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777010232; l=18518; i=vijayanand.jitta@oss.qualcomm.com; s=20260301; h=from:subject:message-id; bh=wiBZojo0J7hwv8jza/KpZ8506QAT1cjvfjOKCApa6Wo=; b=dyovb5BdIrhkPQF+mCNMCfJmyuhdwXIWnaGvQc+aQdZ99bljLMJtwDkhvB5KUss3szckMv8f+ cAYk+DkjlsABxrXW1TO23901phEgBZxg3zuTMcERkBMPC35ZqHH7vUK X-Developer-Key: i=vijayanand.jitta@oss.qualcomm.com; a=ed25519; pk=Lpi7Cs3wHe8KZtqvyci7FTOLzsKpEHKGCaPNZw+1zRI= X-Proofpoint-GUID: Qjsq8P_a-H3zY4NloUyCvZ4tooZjG_hR X-Authority-Analysis: v=2.4 cv=R98z39RX c=1 sm=1 tr=0 ts=69eb065b cx=c_pps a=JL+w9abYAAE89/QcEU+0QA==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yx91gb_oNiZeI1HMLzn7:22 a=EUspDBNiAAAA:8 a=8AirrxEcAAAA:8 a=VwQbUJbxAAAA:8 a=YNKo5iN9BcXwmsqDYIQA:9 a=QEXdDO2ut3YA:10 a=324X-CrmTo6CU4MGRt3R:22 a=ST-jHhOKWsTCqRlWije3:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDI0MDA1MSBTYWx0ZWRfX4uUbJGXC1cVX 0b3Z81VHb0wqxnz4YocahFoBJixXJD1V/n5Mxs9xKC/4EolkJdMwOJ5JpA1sUM2wUwMyfylTALg G56e7MPEuvFaVUpxyhvp2LnHjz6G5DSCqQrnvNUzFkjLJysgvmUDuPlfz8WJusj+X4tqi0e49Gf dGG7trR9/Lucw8cOcqZRuYh0/MFGjCMtWUv0deAOywauLS+w0VOBEjuQpIvQWfQAPBKjR80hLHO 8rBLtLs0kpeRXX+UMDOy0C2BFYiPVvyetJszfXC+4s2lGMyCx+Bk0XM6iavjzfcF1I08XjF1rGn +jbA0+AyFHNQqX76bBVxspsCzjurEsDrnxIYgPuktRDKz45wTgiQcCqentP1bpoKfXv4OorVU/8 9rA+Z8Df07Mr9/GaaUDFAsO4AchbRwODvHA9Ipq8atNiGFpMArY+ZS6wonrdl60qTNA+mPFChln blAYhhSP+C82SXzXosw== X-Proofpoint-ORIG-GUID: Qjsq8P_a-H3zY4NloUyCvZ4tooZjG_hR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-23_03,2026-04-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 spamscore=0 clxscore=1015 priorityscore=1501 phishscore=0 malwarescore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2604240051 From: Charan Teja Kalla Change of_map_id() to take a pointer to struct of_phandle_args instead of passing target device node and translated IDs separately. Update all callers accordingly. Add an explicit filter_np parameter to of_map_id() and of_map_msi_id() to separate the filter input from the output. Previously, the target parameter served dual purpose: as an input filter (if non-NULL, only match entries targeting that node) and as an output (receiving the matched node with a reference held). Now filter_np is the explicit input filter and arg->np is the pure output. Previously, of_map_id() would call of_node_put() on the matched node when a filter was provided, making reference ownership inconsistent. Remove this internal of_node_put() call so that of_map_id() now always transfers ownership of the matched node reference to the caller via arg->np. Callers are now consistently responsible for releasing this reference with of_node_put(arg->np) when done. Acked-by: Frank Li Suggested-by: Rob Herring (Arm) Suggested-by: Dmitry Baryshkov Signed-off-by: Charan Teja Kalla Signed-off-by: Vijayanand Jitta --- drivers/cdx/cdx_msi.c | 7 ++-- drivers/iommu/of_iommu.c | 4 +- drivers/irqchip/irq-gic-its-msi-parent.c | 11 ++++-- drivers/of/base.c | 68 +++++++++++++++++-----------= ---- drivers/of/irq.c | 30 +++++++++++--- drivers/pci/controller/dwc/pci-imx6.c | 32 +++++++-------- drivers/pci/controller/pcie-apple.c | 5 ++- drivers/xen/grant-dma-ops.c | 4 +- include/linux/of.h | 14 ++++--- 9 files changed, 104 insertions(+), 71 deletions(-) diff --git a/drivers/cdx/cdx_msi.c b/drivers/cdx/cdx_msi.c index 63b3544ec997..6924e07c7528 100644 --- a/drivers/cdx/cdx_msi.c +++ b/drivers/cdx/cdx_msi.c @@ -121,22 +121,23 @@ static int cdx_msi_prepare(struct irq_domain *msi_dom= ain, struct device *dev, int nvec, msi_alloc_info_t *info) { + struct of_phandle_args msi_spec =3D {}; struct cdx_device *cdx_dev =3D to_cdx_device(dev); struct device *parent =3D cdx_dev->cdx->dev; struct msi_domain_info *msi_info; - u32 dev_id; int ret; =20 /* Retrieve device ID from requestor ID using parent device */ - ret =3D of_map_msi_id(parent->of_node, cdx_dev->msi_dev_id, NULL, &dev_id= ); + ret =3D of_map_msi_id(parent->of_node, cdx_dev->msi_dev_id, NULL, &msi_sp= ec); if (ret) { dev_err(dev, "of_map_id failed for MSI: %d\n", ret); return ret; } + of_node_put(msi_spec.np); =20 #ifdef GENERIC_MSI_DOMAIN_OPS /* Set the device Id to be passed to the GIC-ITS */ - info->scratchpad[0].ul =3D dev_id; + info->scratchpad[0].ul =3D msi_spec.args[0]; #endif =20 msi_info =3D msi_get_domain_info(msi_domain->parent); diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index a511ecf21fcd..a18bb60f6f3d 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -45,10 +45,10 @@ static int of_iommu_configure_dev_id(struct device_node= *master_np, struct device *dev, const u32 *id) { - struct of_phandle_args iommu_spec =3D { .args_count =3D 1 }; + struct of_phandle_args iommu_spec =3D {}; int err; =20 - err =3D of_map_iommu_id(master_np, *id, &iommu_spec.np, iommu_spec.args); + err =3D of_map_iommu_id(master_np, *id, &iommu_spec); if (err) return err; =20 diff --git a/drivers/irqchip/irq-gic-its-msi-parent.c b/drivers/irqchip/irq= -gic-its-msi-parent.c index b63343a227a9..dd5f84b6470a 100644 --- a/drivers/irqchip/irq-gic-its-msi-parent.c +++ b/drivers/irqchip/irq-gic-its-msi-parent.c @@ -152,6 +152,8 @@ static int its_v5_pci_msi_prepare(struct irq_domain *do= main, struct device *dev, static int of_pmsi_get_msi_info(struct irq_domain *domain, struct device *= dev, u32 *dev_id, phys_addr_t *pa) { + struct device_node *msi_ctrl __free(device_node) =3D NULL; + struct of_phandle_args msi_spec =3D {}; struct of_phandle_iterator it; int ret; =20 @@ -178,9 +180,12 @@ static int of_pmsi_get_msi_info(struct irq_domain *dom= ain, struct device *dev, u } } =20 - struct device_node *msi_ctrl __free(device_node) =3D NULL; - - return of_map_msi_id(dev->of_node, dev->id, &msi_ctrl, dev_id); + ret =3D of_map_msi_id(dev->of_node, dev->id, NULL, &msi_spec); + if (!ret) { + msi_ctrl =3D msi_spec.np; + *dev_id =3D msi_spec.args[0]; + } + return ret; } =20 static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev, diff --git a/drivers/of/base.c b/drivers/of/base.c index ae04487bd614..b3d002015192 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2102,36 +2102,37 @@ int of_find_last_cache_level(unsigned int cpu) * @id: device ID to map. * @map_name: property name of the map to use. * @map_mask_name: optional property name of the mask to use. - * @target: optional pointer to a target device node. - * @id_out: optional pointer to receive the translated ID. + * @filter_np: optional device node to filter matches by, or NULL to match= any. + * If non-NULL, only map entries targeting this node will be matched. + * @arg: pointer to a &struct of_phandle_args for the result. On success, + * @arg->args[0] will contain the translated ID. If a map entry was + * matched, @arg->np will be set to the target node with a reference + * held that the caller must release with of_node_put(). * * Given a device ID, look up the appropriate implementation-defined * platform ID and/or the target device which receives transactions on that - * ID, as per the "iommu-map" and "msi-map" bindings. Either of @target or - * @id_out may be NULL if only the other is required. If @target points to - * a non-NULL device node pointer, only entries targeting that node will be - * matched; if it points to a NULL value, it will receive the device node = of - * the first matching target phandle, with a reference held. + * ID, as per the "iommu-map" and "msi-map" bindings. * * Return: 0 on success or a standard error code on failure. */ int of_map_id(const struct device_node *np, u32 id, const char *map_name, const char *map_mask_name, - struct device_node **target, u32 *id_out) + const struct device_node *filter_np, struct of_phandle_args *arg) { u32 map_mask, masked_id; int map_len; const __be32 *map =3D NULL; =20 - if (!np || !map_name || (!target && !id_out)) + if (!np || !map_name || !arg) return -EINVAL; =20 map =3D of_get_property(np, map_name, &map_len); if (!map) { - if (target) + if (filter_np) return -ENODEV; /* Otherwise, no map implies no translation */ - *id_out =3D id; + arg->args[0] =3D id; + arg->args_count =3D 1; return 0; } =20 @@ -2173,18 +2174,14 @@ int of_map_id(const struct device_node *np, u32 id, if (!phandle_node) return -ENODEV; =20 - if (target) { - if (*target) - of_node_put(phandle_node); - else - *target =3D phandle_node; - - if (*target !=3D phandle_node) - continue; + if (filter_np && filter_np !=3D phandle_node) { + of_node_put(phandle_node); + continue; } =20 - if (id_out) - *id_out =3D masked_id - id_base + out_base; + arg->np =3D phandle_node; + arg->args[0] =3D masked_id - id_base + out_base; + arg->args_count =3D 1; =20 pr_debug("%pOF: %s, using mask %08x, id-base: %08x, out-base: %08x, leng= th: %08x, id: %08x -> %08x\n", np, map_name, map_mask, id_base, out_base, @@ -2193,11 +2190,11 @@ int of_map_id(const struct device_node *np, u32 id, } =20 pr_info("%pOF: no %s translation for id 0x%x on %pOF\n", np, map_name, - id, target && *target ? *target : NULL); + id, filter_np); =20 /* Bypasses translation */ - if (id_out) - *id_out =3D id; + arg->args[0] =3D id; + arg->args_count =3D 1; return 0; } EXPORT_SYMBOL_GPL(of_map_id); @@ -2207,17 +2204,19 @@ EXPORT_SYMBOL_GPL(of_map_id); * @np: root complex device node. * @id: Requester ID of the device (e.g. PCI RID/BDF or a platform * stream/device ID) used as the lookup key in the iommu-map table. - * @target: optional pointer to a target device node. - * @id_out: optional pointer to receive the translated ID. + * @arg: pointer to a &struct of_phandle_args for the result. On success, + * @arg->args[0] contains the translated ID. If a map entry was matched, + * @arg->np holds a reference to the target node that the caller must + * release with of_node_put(). * * Convenience wrapper around of_map_id() using "iommu-map" and "iommu-map= -mask". * * Return: 0 on success or a standard error code on failure. */ int of_map_iommu_id(const struct device_node *np, u32 id, - struct device_node **target, u32 *id_out) + struct of_phandle_args *arg) { - return of_map_id(np, id, "iommu-map", "iommu-map-mask", target, id_out); + return of_map_id(np, id, "iommu-map", "iommu-map-mask", NULL, arg); } EXPORT_SYMBOL_GPL(of_map_iommu_id); =20 @@ -2226,16 +2225,21 @@ EXPORT_SYMBOL_GPL(of_map_iommu_id); * @np: root complex device node. * @id: Requester ID of the device (e.g. PCI RID/BDF or a platform * stream/device ID) used as the lookup key in the msi-map table. - * @target: optional pointer to a target device node. - * @id_out: optional pointer to receive the translated ID. + * @filter_np: optional MSI controller node to filter matches by, or NULL + * to match any. If non-NULL, only map entries targeting this node will + * be matched. + * @arg: pointer to a &struct of_phandle_args for the result. On success, + * @arg->args[0] contains the translated ID. If a map entry was matched, + * @arg->np holds a reference to the target node that the caller must + * release with of_node_put(). * * Convenience wrapper around of_map_id() using "msi-map" and "msi-map-mas= k". * * Return: 0 on success or a standard error code on failure. */ int of_map_msi_id(const struct device_node *np, u32 id, - struct device_node **target, u32 *id_out) + const struct device_node *filter_np, struct of_phandle_args *arg) { - return of_map_id(np, id, "msi-map", "msi-map-mask", target, id_out); + return of_map_id(np, id, "msi-map", "msi-map-mask", filter_np, arg); } EXPORT_SYMBOL_GPL(of_map_msi_id); diff --git a/drivers/of/irq.c b/drivers/of/irq.c index e37c1b3f8736..4040467742c4 100644 --- a/drivers/of/irq.c +++ b/drivers/of/irq.c @@ -796,19 +796,22 @@ static int of_check_msi_parent(struct device_node *de= v_node, struct device_node /** * of_msi_xlate - map a MSI ID and find relevant MSI controller node * @dev: device for which the mapping is to be done. - * @msi_np: Pointer to target MSI controller node + * @msi_np: Pointer to target MSI controller node, or NULL if the caller + * only needs the translated ID without receiving the controller= node. + * If non-NULL and pointing to a non-NULL node, only entries tar= geting + * that node will be matched. If non-NULL and pointing to NULL, = it will + * receive the first matching target node with a reference held. * @id_in: Device ID. * * Walk up the device hierarchy looking for devices with a "msi-map" * 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. * * Returns: The mapped MSI id. */ u32 of_msi_xlate(struct device *dev, struct device_node **msi_np, u32 id_i= n) { + struct device_node *local_np =3D NULL; + struct device_node **np =3D msi_np ?: &local_np; struct device *parent_dev; u32 id_out =3D id_in; =20 @@ -817,11 +820,26 @@ u32 of_msi_xlate(struct device *dev, struct device_no= de **msi_np, u32 id_in) * "msi-map" or an "msi-parent" property. */ for (parent_dev =3D dev; parent_dev; parent_dev =3D parent_dev->parent) { - if (!of_map_msi_id(parent_dev->of_node, id_in, msi_np, &id_out)) + struct of_phandle_args msi_spec =3D {}; + + if (!of_map_msi_id(parent_dev->of_node, id_in, *np, &msi_spec)) { + /* + * Pass-through result: no msi-map on this node (or no + * matching entry). Keep walking up the hierarchy. + */ + if (!msi_spec.np) + continue; + id_out =3D msi_spec.args[0]; + if (!*np) + *np =3D msi_spec.np; + else + of_node_put(msi_spec.np); break; - if (!of_check_msi_parent(parent_dev->of_node, msi_np)) + } + if (!of_check_msi_parent(parent_dev->of_node, np)) break; } + of_node_put(local_np); return id_out; } EXPORT_SYMBOL_GPL(of_msi_xlate); diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller= /dwc/pci-imx6.c index bff8289f804a..c0544d9c0921 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -1137,30 +1137,32 @@ static void imx_pcie_remove_lut(struct imx_pcie *im= x_pcie, u16 rid) =20 static int imx_pcie_add_lut_by_rid(struct imx_pcie *imx_pcie, u32 rid) { + struct of_phandle_args iommu_spec =3D {}; + struct of_phandle_args msi_spec =3D {}; struct device *dev =3D imx_pcie->pci->dev; - struct device_node *target; u32 sid_i, sid_m; int err_i, err_m; u32 sid =3D 0; =20 - target =3D NULL; - err_i =3D of_map_iommu_id(dev->of_node, rid, &target, &sid_i); - if (target) { - of_node_put(target); - } else { + err_i =3D of_map_iommu_id(dev->of_node, rid, &iommu_spec); + if (!err_i) + sid_i =3D iommu_spec.args[0]; + of_node_put(iommu_spec.np); + if (!err_i && !iommu_spec.np) { /* - * "target =3D=3D NULL && err_i =3D=3D 0" means RID out of map range. - * Use 1:1 map RID to streamID. Hardware can't support this - * because the streamID is only 6 bits + * "iommu_spec.np =3D=3D NULL && err_i =3D=3D 0" means RID out of map + * range. Use 1:1 map RID to streamID. Hardware can't support + * this because the streamID is only 6 bits. */ err_i =3D -EINVAL; } =20 - target =3D NULL; - err_m =3D of_map_msi_id(dev->of_node, rid, &target, &sid_m); - + err_m =3D of_map_msi_id(dev->of_node, rid, NULL, &msi_spec); + if (!err_m) + sid_m =3D msi_spec.args[0]; + of_node_put(msi_spec.np); /* - * err_m target + * err_m msi_spec.np * 0 NULL RID out of range. Use 1:1 map RID to * streamID, Current hardware can't * support it, so return -EINVAL. @@ -1168,10 +1170,8 @@ static int imx_pcie_add_lut_by_rid(struct imx_pcie *= imx_pcie, u32 rid) * 0 !=3D NULL Get correct streamID from RID * !=3D 0 !=3D NULL Invalid combination */ - if (!err_m && !target) + if (!err_m && !msi_spec.np) return -EINVAL; - else if (target) - of_node_put(target); /* Find streamID map entry for RID in msi-map */ =20 /* * msi-map iommu-map diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/p= cie-apple.c index a0937b7b3c4d..c2cffc0659f4 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -755,6 +755,7 @@ static int apple_pcie_enable_device(struct pci_host_bri= dge *bridge, struct pci_d { u32 sid, rid =3D pci_dev_id(pdev); struct apple_pcie_port *port; + struct of_phandle_args iommu_spec =3D {}; int idx, err; =20 port =3D apple_pcie_get_port(pdev); @@ -764,10 +765,12 @@ static int apple_pcie_enable_device(struct pci_host_b= ridge *bridge, struct pci_d dev_dbg(&pdev->dev, "added to bus %s, index %d\n", pci_name(pdev->bus->self), port->idx); =20 - err =3D of_map_iommu_id(port->pcie->dev->of_node, rid, NULL, &sid); + err =3D of_map_iommu_id(port->pcie->dev->of_node, rid, &iommu_spec); if (err) return err; =20 + of_node_put(iommu_spec.np); + sid =3D iommu_spec.args[0]; mutex_lock(&port->pcie->lock); =20 idx =3D bitmap_find_free_region(port->sid_map, port->sid_map_sz, 0); diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c index 1b7696b2d762..2aa1a772a0ff 100644 --- a/drivers/xen/grant-dma-ops.c +++ b/drivers/xen/grant-dma-ops.c @@ -319,13 +319,13 @@ static int xen_dt_grant_init_backend_domid(struct dev= ice *dev, struct device_node *np, domid_t *backend_domid) { - struct of_phandle_args iommu_spec =3D { .args_count =3D 1 }; + struct of_phandle_args iommu_spec =3D {}; =20 if (dev_is_pci(dev)) { struct pci_dev *pdev =3D to_pci_dev(dev); u32 rid =3D PCI_DEVID(pdev->bus->number, pdev->devfn); =20 - if (of_map_iommu_id(np, rid, &iommu_spec.np, iommu_spec.args)) { + if (of_map_iommu_id(np, rid, &iommu_spec)) { dev_dbg(dev, "Cannot translate ID\n"); return -ESRCH; } diff --git a/include/linux/of.h b/include/linux/of.h index fe841f3cc747..8548cd9eb4f1 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -463,13 +463,13 @@ bool of_console_check(const struct device_node *dn, c= har *name, int index); =20 int of_map_id(const struct device_node *np, u32 id, const char *map_name, const char *map_mask_name, - struct device_node **target, u32 *id_out); + const struct device_node *filter_np, struct of_phandle_args *arg); =20 int of_map_iommu_id(const struct device_node *np, u32 id, - struct device_node **target, u32 *id_out); + struct of_phandle_args *arg); =20 int of_map_msi_id(const struct device_node *np, u32 id, - struct device_node **target, u32 *id_out); + const struct device_node *filter_np, struct of_phandle_args *arg); =20 phys_addr_t of_dma_get_max_cpu_address(struct device_node *np); =20 @@ -935,19 +935,21 @@ static inline void of_property_clear_flag(struct prop= erty *p, unsigned long flag =20 static inline int of_map_id(const struct device_node *np, u32 id, const char *map_name, const char *map_mask_name, - struct device_node **target, u32 *id_out) + const struct device_node *filter_np, + struct of_phandle_args *arg) { return -EINVAL; } =20 static inline int of_map_iommu_id(const struct device_node *np, u32 id, - struct device_node **target, u32 *id_out) + struct of_phandle_args *arg) { return -EINVAL; } =20 static inline int of_map_msi_id(const struct device_node *np, u32 id, - struct device_node **target, u32 *id_out) + const struct device_node *filter_np, + struct of_phandle_args *arg) { return -EINVAL; } --=20 2.34.1 From nobody Sun May 3 14:26:26 2026 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (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 C5F82347BD7 for ; Fri, 24 Apr 2026 05:57:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777010281; cv=none; b=hzzaY9/173io0kIYe7n3IYwD0sAW0+IZfnVh/qkU8BIRPC6kp8b8WXAg/8EstN+Pe6l5b55oW43BT8S6Nu/UcrhDUkDo7BZB2ySxjSUXNjqT0Qle9FbNrI1MwPYeRb8MZtzvc7aulaMRy16sLwTsa7WBUwlBQHzCcLKDwMebtTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777010281; c=relaxed/simple; bh=ByBtVw24LLnPN8MAYOfyMXc8DWgF6s7DZ5ut+Y6Ehww=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gJ0fKwDB+FY7mtZ8/gvCfj3FxOBz3GJ29nEN9SppNoAU2p4efZRkkpsdJAOZoRdirqO4BeSI9S8NQ07+qwS1jWhpGWc0G+YGLPVGpy6pSTf9y9Z26UxPOcXCbGnuFhUevYVHVQ/gJSHU5r8ckZluEHAJWbLlsBzerE1m7gZIvxE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=n55RZJ6J; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=YAiTBmlD; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="n55RZJ6J"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="YAiTBmlD" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63O2GFYA756716 for ; Fri, 24 Apr 2026 05:57:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= fOXXFN9mhZ7JxzI+hTQo1c6CYH+05MRwTlhFigPlnEI=; b=n55RZJ6Jw4rv8neg xJrqVkFw8uPXRCYWQMWIJ0f5DE4gyZ9SLrHuyvkgYDVvsJjDL9y8WneA2vOalYB6 VujLJ/jW7MUMvjOcKLMZ9ZxDBR6Ix2aHSF0xtQZeYssCZRolHc6RqF6AhhFXzCq8 FwKb4clhZXNP08kPn+vJKI9IUa80R51Rd1feVlnDzigW2AFnXM6ryhBkkEXe8PZ8 4L1gQnJBZEi2ppa4qCFrL+OI51556Lb/5fEIM6NfYQN+Jx/ZnhrYxHDj2W/e2BeK sRpWETO/Kxp0WvttNunwhkNH2QrY/Cosf9BgE8TSrd7HS7uK9M55Zl93ztMnLqkY 9/tNGA== Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dqr4bjcer-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 24 Apr 2026 05:57:57 +0000 (GMT) Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-35da4795b3cso14443776a91.2 for ; Thu, 23 Apr 2026 22:57:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1777010277; x=1777615077; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=fOXXFN9mhZ7JxzI+hTQo1c6CYH+05MRwTlhFigPlnEI=; b=YAiTBmlDKFGzq0LvW3AXzgPQGOuIU0p//OMzm9YImvN19dhJrhpH2db0U0rnHnPpNO 1tN64eb/WLStp79svsxmE4NMXZrUB1NeudkIS4pm5AuNFqAgL8iT1r7hSamyTVzGjC+w mAc//dgWsNf/YP7luvNxdCV63cYw7FRgEca5FQ7UEn5wk3OzrYDKbkCHfzr+q692Qm5z O5PouQca2PnmqaY9q81AjqDM0k43AHiKnILEh1VCG4IOkS3hXjqchxODzquTlqDxE8Mx D0UwoiLOqpr0IMHSeABAjPhOgSuUkosyxBBS2NLpg1Z2KD5AhaExuwX66XsVJ0cZIGrf Ekow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777010277; x=1777615077; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=fOXXFN9mhZ7JxzI+hTQo1c6CYH+05MRwTlhFigPlnEI=; b=lJlbd9u8D3mPYe+/DRnXxHQacQjgBTUW3XIu7RU+XBbZnUgvqqG6qDKeRln+3Tx2r8 9grZX88QKEfP9lQovJB+9s8bFS3Nm5+Wac+FUGuFYijV21Sbofe8Z7zSUoYAjOBPLJio /gM2pB+LsC976tTqFHAF+F0Qzo0wj3E51EgReqrlDu7RiXOpZSgzRD0gB/EgefNFvJ0G H6KSQi9p4N5tCIs6pbb5ssxvJPqEObdsUoIqbRk1QTCiLIVlM8jloKT5S09RFDSG/M0A kqhMOtYmbB9gLSzecg/RTviSgXleo+RlJ79W5x8kf44av7JLWBf2K5D8lZ+x7gvd/htC aZJA== X-Gm-Message-State: AOJu0YwmKktjkClAc3LdNEOL9Xo+tYqSW2kF6KKmnePlscOaLpgBKOZL Htd/I5SoSbePhXazq/YwfV2KvZBcC9vjE3TRAPl4IoV2xJE9qgVSbTLLAwtVQiOMuasMnb3GRXU vusWqvn/9184QvTFD54yuxF48F7EL3NlrSJDJ2xb8Gdvoq9i1H6uuHbvzr+JXRA2lvTE= X-Gm-Gg: AeBDies2OaGytkQ7GAovHm6lTuGtG8snhjDybNPGORHKO0inno+l8Bz0KBm67qhdmsW Bv8a6sb5+nWADr4NoggqfTAArQEsuZdgkJhf8JBYVRBSoa7Tw/JEr7T5HQAOxCUqJXo7oXFhG6H Hu7nuUghfxmm8czWT0K2IyD0CfJrH/oG+ZkymiraWx6G0aB6w4racfCG7IUgk1YFJW7HkD3u488 /pwnFubrlHt4n0Ce7zjvcuYlVY3RNhSIifhEDeMEur94uVTWIT6DI+w3W1LT3rsLR/MSz4ywqGn ZVEOfkH4ThlJcfu28vppNKb6iuzmuwBjIxLvVcteCbUjBIQxftZYksmiCYEzQhYa9NsULeDCsKR IEoZ/AsHzg5/GrqLgIORTc71QluvUivD64GSoqPxtlqyOh0D5GASrtzRrF2EHVCkl2JM= X-Received: by 2002:a05:6300:6cd0:10b0:398:8766:4d0a with SMTP id adf61e73a8af0-3a08d7342b0mr21009122637.19.1777010276451; Thu, 23 Apr 2026 22:57:56 -0700 (PDT) X-Received: by 2002:a05:6300:6cd0:10b0:398:8766:4d0a with SMTP id adf61e73a8af0-3a08d7342b0mr21009075637.19.1777010275875; Thu, 23 Apr 2026 22:57:55 -0700 (PDT) Received: from hu-vjitta-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c79770512afsm17288101a12.31.2026.04.23.22.57.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 22:57:55 -0700 (PDT) From: Vijayanand Jitta Date: Fri, 24 Apr 2026 11:26:10 +0530 Subject: [PATCH v14 3/3] of: Respect #{iommu,msi}-cells in maps 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 Message-Id: <20260424-parse_iommu_cells-v14-3-fd02f11b6c38@oss.qualcomm.com> References: <20260424-parse_iommu_cells-v14-0-fd02f11b6c38@oss.qualcomm.com> In-Reply-To: <20260424-parse_iommu_cells-v14-0-fd02f11b6c38@oss.qualcomm.com> To: Nipun Gupta , Nikhil Agarwal , Joerg Roedel , Will Deacon , Robin Murphy , Marc Zyngier , Lorenzo Pieralisi , Thomas Gleixner , Saravana Kannan , Richard Zhu , Lucas Stach , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Manivannan Sadhasivam , Bjorn Helgaas , Frank Li , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Dmitry Baryshkov , Konrad Dybcio , Bjorn Andersson , Rob Herring , Conor Dooley , Krzysztof Kozlowski , Prakash Gupta , Vikash Garodia Cc: linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, xen-devel@lists.xenproject.org, linux-arm-msm@vger.kernel.org, Vijayanand Jitta , Charan Teja Kalla X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777010232; l=12022; i=vijayanand.jitta@oss.qualcomm.com; s=20260301; h=from:subject:message-id; bh=d1eDTLSvaaoV8Pjb6ssN/wlaFmWHAsxlhBaIWB039ns=; b=dvjmg1JeV+d2IiPPXLnSyPZS2iXakbo7vH25RJpgfxHMtQvlf6E20k//Y7tUylU/KmB5QpkoN p1JKaTx7QpWAoc1ISIZabpuZvStHNGLlT1s7gu6I+nkJ5BwVTldmp0L X-Developer-Key: i=vijayanand.jitta@oss.qualcomm.com; a=ed25519; pk=Lpi7Cs3wHe8KZtqvyci7FTOLzsKpEHKGCaPNZw+1zRI= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDI0MDA1MSBTYWx0ZWRfX5D9pIwyXjpYH lib2SrfwobsFcr1kdEXJECqb5JILwBmnEZK2pcyUFNDXDBrDFfaku/EiGr9uiAebMuG4NexQU3e 5IfSgcbP7aGTjDLvHMlSuPICm1c4WNWefQTNs23vBxzuWm466wyFWlgad/fKkwsTmzeazv2ZzAt YyCK+D9lOgHGOdzkygVzsxsHoy2No/B6XR+jOC8xv/5bgeSfTBd7nAhMj648lErGBp6JWZISQRu 8eN23XULYcKaFolPyQO7L3RFx7K6JH9RzEtMF2gBvjnz4PpV5aSdRGoI6peUVmYa8EJGb1/+jc6 LR6+nYC05ev9Q19qU2l2/7OfkQlGy0wqTdcONxVsOPKZH8ISfn0ve/UUFMCiiVm4WjfY85BOoA9 TLuY+A8J3yvMiwWTNWuJFSdKfGCNUx8Hp1SI4qU/NuKjG2xWE0JOyqRY217owZTFsG/B+uSu8gf S83QO8QjATxKEhr+KTQ== X-Authority-Analysis: v=2.4 cv=TtnWQjXh c=1 sm=1 tr=0 ts=69eb0665 cx=c_pps a=RP+M6JBNLl+fLTcSJhASfg==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=3WHJM1ZQz_JShphwDgj5:22 a=7CQSdrXTAAAA:8 a=EUspDBNiAAAA:8 a=klF1l1D6msg2vEcBgDUA:9 a=QEXdDO2ut3YA:10 a=iS9zxrgQBfv6-_F4QbHw:22 a=a-qgeE7W1pNrGK8U0ZQC:22 X-Proofpoint-ORIG-GUID: ojCQuf10I9Atex3M7xPG6tIP_w9gC4u5 X-Proofpoint-GUID: ojCQuf10I9Atex3M7xPG6tIP_w9gC4u5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-23_03,2026-04-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 malwarescore=0 clxscore=1015 adultscore=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2604240051 From: Robin Murphy So far our parsing of {iommu,msi}-map properties has always blindly assumed that the output specifiers will always have exactly 1 cell. This typically does happen to be the case, but is not actually enforced (and the PCI msi-map binding even explicitly states support for 0 or 1 cells) - as a result we've now ended up with dodgy DTs out in the field which depend on this behaviour to map a 1-cell specifier for a 2-cell provider, despite that being bogus per the bindings themselves. Since there is some potential use in being able to map at least single input IDs to multi-cell output specifiers (and properly support 0-cell outputs as well), add support for properly parsing and using the target nodes' #cells values, albeit with the unfortunate complication of still having to work around expectations of the old behaviour too. Since there are multi-cell output specifiers, the callers of of_map_id() may need to get the exact cell output value for further processing. Update of_map_id() to set args_count in the output to reflect the actual number of output specifier cells. Signed-off-by: Robin Murphy Signed-off-by: Charan Teja Kalla Signed-off-by: Vijayanand Jitta --- drivers/of/base.c | 157 +++++++++++++++++++++++++++++++++++++++++--------= ---- include/linux/of.h | 6 +- 2 files changed, 125 insertions(+), 38 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index b3d002015192..2554e4f1a181 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2096,18 +2096,48 @@ int of_find_last_cache_level(unsigned int cpu) return cache_level; } =20 +/* + * Some DTs have an iommu-map targeting a 2-cell IOMMU node while + * specifying only 1 cell. Fortunately they all consist of value '1' + * as the 2nd cell entry with the same target, so check for that pattern. + * + * Example: + * IOMMU node: + * #iommu-cells =3D <2>; + * + * Device node: + * iommu-map =3D <0x0000 &smmu 0x0000 0x1>, + * <0x0100 &smmu 0x0100 0x1>; + */ +static bool of_check_bad_map(const __be32 *map, int len) +{ + __be32 phandle =3D map[1]; + + if (len % 4) + return false; + for (int i =3D 0; i < len; i +=3D 4) { + if (map[i + 1] !=3D phandle || map[i + 3] !=3D cpu_to_be32(1)) + return false; + } + return true; +} + /** * of_map_id - Translate an ID through a downstream mapping. * @np: root complex device node. * @id: device ID to map. * @map_name: property name of the map to use. + * @cells_name: property name of target specifier cells. * @map_mask_name: optional property name of the mask to use. * @filter_np: optional device node to filter matches by, or NULL to match= any. * If non-NULL, only map entries targeting this node will be matched. * @arg: pointer to a &struct of_phandle_args for the result. On success, - * @arg->args[0] will contain the translated ID. If a map entry was - * matched, @arg->np will be set to the target node with a reference - * held that the caller must release with of_node_put(). + * @arg->args_count will be set to the number of output specifier cells + * as defined by @cells_name in the target node, and + * @arg->args[0..args_count-1] will contain the translated output + * specifier values. If a map entry was matched, @arg->np will be set + * to the target node with a reference held that the caller must release + * with of_node_put(). * * Given a device ID, look up the appropriate implementation-defined * platform ID and/or the target device which receives transactions on that @@ -2116,17 +2146,19 @@ int of_find_last_cache_level(unsigned int cpu) * Return: 0 on success or a standard error code on failure. */ int of_map_id(const struct device_node *np, u32 id, - const char *map_name, const char *map_mask_name, + const char *map_name, const char *cells_name, + const char *map_mask_name, const struct device_node *filter_np, struct of_phandle_args *arg) { u32 map_mask, masked_id; - int map_len; + int map_bytes, map_len, offset =3D 0; + bool bad_map =3D false; const __be32 *map =3D NULL; =20 if (!np || !map_name || !arg) return -EINVAL; =20 - map =3D of_get_property(np, map_name, &map_len); + map =3D of_get_property(np, map_name, &map_bytes); if (!map) { if (filter_np) return -ENODEV; @@ -2136,11 +2168,9 @@ int of_map_id(const struct device_node *np, u32 id, return 0; } =20 - if (!map_len || map_len % (4 * sizeof(*map))) { - pr_err("%pOF: Error: Bad %s length: %d\n", np, - map_name, map_len); - return -EINVAL; - } + if (map_bytes % sizeof(*map)) + goto err_map_len; + map_len =3D map_bytes / sizeof(*map); =20 /* The default is to select all bits. */ map_mask =3D 0xffffffff; @@ -2153,39 +2183,84 @@ int of_map_id(const struct device_node *np, u32 id, of_property_read_u32(np, map_mask_name, &map_mask); =20 masked_id =3D map_mask & id; - for ( ; map_len > 0; map_len -=3D 4 * sizeof(*map), map +=3D 4) { + + while (offset < map_len) { struct device_node *phandle_node; - u32 id_base =3D be32_to_cpup(map + 0); - u32 phandle =3D be32_to_cpup(map + 1); - u32 out_base =3D be32_to_cpup(map + 2); - u32 id_len =3D be32_to_cpup(map + 3); + u32 id_base, phandle, id_len, id_off, cells =3D 0; + const __be32 *out_base; + + if (map_len - offset < 2) + goto err_map_len; + + id_base =3D be32_to_cpup(map + offset); =20 if (id_base & ~map_mask) { - pr_err("%pOF: Invalid %s translation - %s-mask (0x%x) ignores id-base (= 0x%x)\n", - np, map_name, map_name, - map_mask, id_base); + pr_err("%pOF: Invalid %s translation - %s (0x%x) ignores id-base (0x%x)= \n", + np, map_name, map_mask_name, map_mask, id_base); return -EFAULT; } =20 - if (masked_id < id_base || masked_id >=3D id_base + id_len) - continue; - + phandle =3D be32_to_cpup(map + offset + 1); phandle_node =3D of_find_node_by_phandle(phandle); if (!phandle_node) return -ENODEV; =20 + if (bad_map) { + cells =3D 1; + } else if (of_property_read_u32(phandle_node, cells_name, &cells)) { + pr_err("%pOF: missing %s property\n", phandle_node, cells_name); + of_node_put(phandle_node); + return -EINVAL; + } + + if (map_len - offset < 3 + cells) { + of_node_put(phandle_node); + goto err_map_len; + } + + if (offset =3D=3D 0 && cells =3D=3D 2) { + bad_map =3D of_check_bad_map(map, map_len); + if (bad_map) { + pr_warn_once("%pOF: %s mismatches target %s, assuming extra cell of 0\= n", + np, map_name, cells_name); + cells =3D 1; + } + } + + out_base =3D map + offset + 2; + offset +=3D 3 + cells; + + id_len =3D be32_to_cpup(map + offset - 1); + if (id_len > 1 && cells > 1) { + /* + * With 1 output cell we reasonably assume its value + * has a linear relationship to the input; with more, + * we'd need help from the provider to know what to do. + */ + pr_err("%pOF: Unsupported %s - cannot handle %d-ID range with %d-cell o= utput specifier\n", + np, map_name, id_len, cells); + of_node_put(phandle_node); + return -EINVAL; + } + id_off =3D masked_id - id_base; + if (masked_id < id_base || id_off >=3D id_len) { + of_node_put(phandle_node); + continue; + } + if (filter_np && filter_np !=3D phandle_node) { of_node_put(phandle_node); continue; } =20 arg->np =3D phandle_node; - arg->args[0] =3D masked_id - id_base + out_base; - arg->args_count =3D 1; + for (int i =3D 0; i < cells; i++) + arg->args[i] =3D id_off + be32_to_cpu(out_base[i]); + arg->args_count =3D cells; =20 pr_debug("%pOF: %s, using mask %08x, id-base: %08x, out-base: %08x, leng= th: %08x, id: %08x -> %08x\n", - np, map_name, map_mask, id_base, out_base, - id_len, id, masked_id - id_base + out_base); + np, map_name, map_mask, id_base, be32_to_cpup(out_base), + id_len, id, id_off + be32_to_cpup(out_base)); return 0; } =20 @@ -2196,6 +2271,10 @@ int of_map_id(const struct device_node *np, u32 id, arg->args[0] =3D id; arg->args_count =3D 1; return 0; + +err_map_len: + pr_err("%pOF: Error: Bad %s length: %d\n", np, map_name, map_bytes); + return -EINVAL; } EXPORT_SYMBOL_GPL(of_map_id); =20 @@ -2205,18 +2284,21 @@ EXPORT_SYMBOL_GPL(of_map_id); * @id: Requester ID of the device (e.g. PCI RID/BDF or a platform * stream/device ID) used as the lookup key in the iommu-map table. * @arg: pointer to a &struct of_phandle_args for the result. On success, - * @arg->args[0] contains the translated ID. If a map entry was matched, - * @arg->np holds a reference to the target node that the caller must - * release with of_node_put(). + * @arg->args_count will be set to the number of output specifier cells + * and @arg->args[0..args_count-1] will contain the translated output + * specifier values. If a map entry was matched, @arg->np holds a + * reference to the target node that the caller must release with + * of_node_put(). * - * Convenience wrapper around of_map_id() using "iommu-map" and "iommu-map= -mask". + * Convenience wrapper around of_map_id() using "iommu-map", "#iommu-cells= ", + * and "iommu-map-mask". * * Return: 0 on success or a standard error code on failure. */ int of_map_iommu_id(const struct device_node *np, u32 id, struct of_phandle_args *arg) { - return of_map_id(np, id, "iommu-map", "iommu-map-mask", NULL, arg); + return of_map_id(np, id, "iommu-map", "#iommu-cells", "iommu-map-mask", N= ULL, arg); } EXPORT_SYMBOL_GPL(of_map_iommu_id); =20 @@ -2229,17 +2311,20 @@ EXPORT_SYMBOL_GPL(of_map_iommu_id); * to match any. If non-NULL, only map entries targeting this node will * be matched. * @arg: pointer to a &struct of_phandle_args for the result. On success, - * @arg->args[0] contains the translated ID. If a map entry was matched, - * @arg->np holds a reference to the target node that the caller must - * release with of_node_put(). + * @arg->args_count will be set to the number of output specifier cells + * and @arg->args[0..args_count-1] will contain the translated output + * specifier values. If a map entry was matched, @arg->np holds a + * reference to the target node that the caller must release with + * of_node_put(). * - * Convenience wrapper around of_map_id() using "msi-map" and "msi-map-mas= k". + * Convenience wrapper around of_map_id() using "msi-map", "#msi-cells", + * and "msi-map-mask". * * Return: 0 on success or a standard error code on failure. */ int of_map_msi_id(const struct device_node *np, u32 id, const struct device_node *filter_np, struct of_phandle_args *arg) { - return of_map_id(np, id, "msi-map", "msi-map-mask", filter_np, arg); + return of_map_id(np, id, "msi-map", "#msi-cells", "msi-map-mask", filter_= np, arg); } EXPORT_SYMBOL_GPL(of_map_msi_id); diff --git a/include/linux/of.h b/include/linux/of.h index 8548cd9eb4f1..51ac8539f2c3 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -462,7 +462,8 @@ const char *of_prop_next_string(const struct property *= prop, const char *cur); bool of_console_check(const struct device_node *dn, char *name, int index); =20 int of_map_id(const struct device_node *np, u32 id, - const char *map_name, const char *map_mask_name, + const char *map_name, const char *cells_name, + const char *map_mask_name, const struct device_node *filter_np, struct of_phandle_args *arg); =20 int of_map_iommu_id(const struct device_node *np, u32 id, @@ -934,7 +935,8 @@ static inline void of_property_clear_flag(struct proper= ty *p, unsigned long flag } =20 static inline int of_map_id(const struct device_node *np, u32 id, - const char *map_name, const char *map_mask_name, + const char *map_name, const char *cells_name, + const char *map_mask_name, const struct device_node *filter_np, struct of_phandle_args *arg) { --=20 2.34.1