From nobody Mon Feb 9 00:38:53 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 12C1D21C17D for ; Wed, 31 Dec 2025 11:47:11 +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=1767181633; cv=none; b=J0gh7j3Du6SdlMuENLDcqlAOdpFq14DUO4wsTiNDbejXSyMQvdc7E+QOd0AQjOeONyryB3/ytOtYKW5LRKLOpr0QYpvHbXRrC0GIJgDePWOAD8p/LgEulipJmMmZhj7G9szCmaNT00SfR1ax8CmpsphYDNoRPQuTmOwIbQ9Hwvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767181633; c=relaxed/simple; bh=oZFElJcRCT/LHuAohL0RZew2I27BaYtu2DisIqxwb9U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BmNznInZfi9qU/w/7w/kZyPC+4qhWd8ZHy34Tv8iF+SLgCdh3wk7tzK8s/JPw9FCUulwR9YZ7uHzTxuirLg5x+O2AYh8qQkZZCtIws/abypnwYmFO+TKuBo7gdtz1sDEVvozaZYLXo6qpHnhw+Pz7w/PsppgUlwNjOMKJtCyxRw= 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=V7wx2oRG; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=C120pBaz; 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="V7wx2oRG"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="C120pBaz" 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 5BV78YDn2733360 for ; Wed, 31 Dec 2025 11:47:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=HBOKLq5ltZe y1Irj7CFQtO/EQ6PvqIKX5WfrEQq8PIs=; b=V7wx2oRGpZACWTLeDNNZo8VIUHe yahZ8kS3jtc/Zl2BLVJu1U/n4PXiUuTKlTa1CeZ3rpEx6i1Lxf+ccbz4rK/5gWS5 JX0OJpg/OaDto/RqHuBEEpVPYBxynctDtUCTHkV5NGAyr0BfRg3MMl8mtGpD5W/0 Hk1a3D9x/9CKqoq0Jk3EggKiFGYdvZTEjebwXMnxGCb2f+OCtojx/X0P3+c/qfBv xA9yeSt/Qy0Ywbz9fI6MGDXxuotth1Fp6f0/BWU14MGiLnpQ14SsmQTL5ZZR9C34 HFfFPBUcXG1ec4t2q8EvFpKGg/zLtgzieD0ulFVbuZRmXKxhpca3ahpfKDQ== Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4bcy6agewg-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 31 Dec 2025 11:47:10 +0000 (GMT) Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-7b89ee2c1a4so20452086b3a.2 for ; Wed, 31 Dec 2025 03:47:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1767181630; x=1767786430; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HBOKLq5ltZey1Irj7CFQtO/EQ6PvqIKX5WfrEQq8PIs=; b=C120pBazORtCopemgbWzT+er0mMBXVfApax57kY/41nRRFA2bTSQb06m7TR6YPmd6D /OWt0MEbjqaYrTVeA6SZ0f9yI89DKgONeamEyvZwUYTXVbuUxW+re+BC9lPAZ2VfHqae 13ZllNBUTkIQ5L7CB4SZcNKyP4vrKOoA61ORCHKbs8A3ge5eqt4Oh89hHPZR25fKjs4h /biupZ6hw36j+v2u+Hr3GaOYCGiIQF8T7Sl/WdIGXNIjcs0ZHsrCSLXI9bAd65e+OL45 +p64qJR5WiA6liBGTdi7MJNG/xpMxY2V+z6hxH+v89vdE9LUhD1Mai7CMilw95S2zV45 87yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767181630; x=1767786430; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=HBOKLq5ltZey1Irj7CFQtO/EQ6PvqIKX5WfrEQq8PIs=; b=BnykV4ZHuECSFTt1vyTTMl+UWnVkds2ouofp88GgHdSV1QJK4IU39Ebd+rwIUi69q3 lxp2F0t16MtkrXspbap2iUIlpWgmuZbC8aYQjLKlcnrS1e6YPYjy/ZbY/L0GKi+YnzIr Lofkd3ZjoByfqAF9EppASJ45o1o3GD5FqZJuB/mjk81qjWEkrEw59YoJnenJ+q447op+ b0OEruNYownJ5cvs0bUKLKbTZaiU8OZJHprHX65PrF0pVOnl4k9qFY0vn+XjKBhvb8mP 5+qyLaSSGwCI/5X7BJVbfottdgtqmw+PGIEf9Lnv/M2XcWUyBT48BluFB3OoWPeZH5so qKMA== X-Forwarded-Encrypted: i=1; AJvYcCUwLkJ/iuhp763lRDzBa6P+v9e6tpDpAJvVP1sx9fpMBzRwmrZm+rt/rwYbF8EEAZtiYXIwLV69c5V5S1I=@vger.kernel.org X-Gm-Message-State: AOJu0YzL1w0w+LiaeLR7+z7mCx9LCTyR7kmBh3x1nFsjRyReq/l84fuE UMDlY6tvdbAXL6MqstLatX5rdfaMvP9rzvXZkEt/ZVQEMPI1q1NMzEhX6fc39xUfnClvhEwt0q6 sGiEf2Ff9bdmj7CabJsmAWzaWk90acB6HCvZ+LN6U0fI0ZKyDV6RSZAqaeC3MAtm17qQ= X-Gm-Gg: AY/fxX76VY58q7vXjfQT+ngAfrn/6eS70iJG/sp9HFK+aBMpNpnMebvPs4U1XOYxTb0 ZQjTYvE7ZFZFbm8MVswlk3dJrSfGm/t61FTh3avaDf5pbIel8ElfPqflNzpZuM2aKtuGbuWMjD0 5q/2lAaMU/qRAG5C0wBpUCFhvXcQJb91/0RjTVoJQfkvxCGJfJMITh6Pu9uejRFxdbLYHbT14ce zcU68tF2fRQ/Cg2f6qpds2BjXSpbseNO1rPPC6PExkbFrY13NhDsag9olRFMYMFPvt33s9EcRja L1R2/ycXVr7ZK2I37ymygeM7YvSPc2rn9LTGDiivvndnjinm/rrTC0taGxzZortT98Nm0fhe/z5 ZnS6haXzdVDh9urg89tiG4Q9Sr/T5HEgNeHWFOiZLjaIR X-Received: by 2002:a05:6a00:328a:b0:7ab:8d8a:1024 with SMTP id d2e1a72fcca58-7ff657a10e0mr32995135b3a.7.1767181629858; Wed, 31 Dec 2025 03:47:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IGTIBcnaPBx7tJq37ub/V9si/OnUbrFKHVnF1N4lIDVFtgp8uF+L31a7bYbgS+VyiCTMwNbww== X-Received: by 2002:a05:6a00:328a:b0:7ab:8d8a:1024 with SMTP id d2e1a72fcca58-7ff657a10e0mr32995109b3a.7.1767181629364; Wed, 31 Dec 2025 03:47:09 -0800 (PST) Received: from hu-vjitta-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7ff7b5236b5sm34815656b3a.29.2025.12.31.03.47.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Dec 2025 03:47:09 -0800 (PST) From: Vijayanand Jitta To: robin.murphy@arm.com, will@kernel.org, joro@8bytes.org, robh@kernel.org, dmitry.baryshkov@oss.qualcomm.com, konrad.dybcio@oss.qualcomm.com, bjorn.andersson@oss.qualcomm.com, bod@kernel.org, conor+dt@kernel.org, krzk+dt@kernel.org, saravanak@google.com, prakash.gupta@oss.qualcomm.com, vikash.garodia@oss.qualcomm.com Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Frank Li , Vijayanand Jitta Subject: [PATCH v4 1/3] of: Add convenience wrappers for of_map_id() Date: Wed, 31 Dec 2025 17:12:55 +0530 Message-Id: <20251231114257.2382820-2-vijayanand.jitta@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251231114257.2382820-1-vijayanand.jitta@oss.qualcomm.com> References: <20251231114257.2382820-1-vijayanand.jitta@oss.qualcomm.com> 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 X-Proofpoint-ORIG-GUID: kI9i4qUfM85i3lzJSYG5MckFMpNWhp4i X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMjMxMDEwMyBTYWx0ZWRfX5yNGo1Mso0Gz BNbGI0wPKGv8K32j6wOxFKLqFLOYwjsXHkn+JjW4l+2wkb+Iae7JqdaBTz0hyHEfVBunKhU93Qc V4b7VlOeDQHQcqi02NyIDlkEnSeWdY8WiKhXPQDsmzN2wf1DgifSgzjJjfZnlNh5zI9LiL1i81p KNJ0Tc69kjxGt1JWnE9BTuMWTngT4FiLuytxGXg5G8JPCifkTL/VvCMvDVjZF07jgxAmph6eWch 041Sw43N6SWb6W9aOd+cjOOvUMCxp3OG5U/zxDLoNijmeENmij2cycS8RapFFaiAar5UuzmoSD9 mwy9KiHCobUk/FHhZAP5DZGxek3ym6+ypO5NSsB2JG7V0/DQkkLR3jqzSNq5+OA+2WQPj8vLMQH 1//kuhLZHX0sqamkefTjL/bIoVxelT4VQPT1mHGtzdlNQOTAgBmW0Z/XLUyD4Anl1tVc+SlFot+ 6VN1+n+HTDviHUXOogg== X-Proofpoint-GUID: kI9i4qUfM85i3lzJSYG5MckFMpNWhp4i X-Authority-Analysis: v=2.4 cv=J9GnLQnS c=1 sm=1 tr=0 ts=69550d3e cx=c_pps a=rEQLjTOiSrHUhVqRoksmgQ==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=wP3pNCr1ah4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=7CQSdrXTAAAA:8 a=VwQbUJbxAAAA:8 a=8AirrxEcAAAA:8 a=EUspDBNiAAAA:8 a=wrOk0Nx1w3hKWqktZycA:9 a=2VI0MkxyNR6bbpdq8BZq:22 a=a-qgeE7W1pNrGK8U0ZQC:22 a=ST-jHhOKWsTCqRlWije3:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-12-31_03,2025-12-31_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 adultscore=0 impostorscore=0 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2512120000 definitions=main-2512310103 Content-Type: text/plain; charset="utf-8" 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 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 | 4 ++-- 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 | 14 ++++++++++++++ 8 files changed, 23 insertions(+), 17 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 eb1473f1448a..0884c4cbd245 100644 --- a/drivers/irqchip/irq-gic-its-msi-parent.c +++ b/drivers/irqchip/irq-gic-its-msi-parent.c @@ -166,7 +166,7 @@ static int of_pmsi_get_dev_id(struct irq_domain *domain= , struct device *dev, if (ret) { struct device_node *np =3D NULL; =20 - ret =3D of_map_id(dev->of_node, dev->id, "msi-map", "msi-map-mask", &np,= dev_id); + ret =3D of_map_msi_id(dev->of_node, dev->id, &np, dev_id); if (np) of_node_put(np); } @@ -211,7 +211,7 @@ static int of_v5_pmsi_get_msi_info(struct irq_domain *d= omain, struct device *dev if (ret) { struct device_node *np =3D NULL; =20 - ret =3D of_map_id(dev->of_node, dev->id, "msi-map", "msi-map-mask", &np,= dev_id); + ret =3D of_map_msi_id(dev->of_node, dev->id, &np, dev_id); if (np) { ret =3D its_translate_frame_address(np, pa); of_node_put(np); diff --git a/drivers/of/irq.c b/drivers/of/irq.c index 1cd93549d093..9549dda8f9d6 100644 --- a/drivers/of/irq.c +++ b/drivers/of/irq.c @@ -725,8 +725,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 4668fc9648bf..c8da2e88e9c6 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -1106,8 +1106,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 { @@ -1120,8 +1119,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 0380d300adca..ce21728d6e51 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -791,8 +791,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 29257d2639db..b661f9c1f4fe 100644 --- a/drivers/xen/grant-dma-ops.c +++ b/drivers/xen/grant-dma-ops.c @@ -321,8 +321,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 121a288ca92d..8cd486d89da2 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1435,6 +1435,20 @@ static inline int of_property_read_s32(const struct = device_node *np, return of_property_read_u32(np, propname, (u32*) out_value); } =20 +static inline 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); +} + +static inline 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); +} + #define of_for_each_phandle(it, err, np, ln, cn, cc) \ for (of_phandle_iterator_init((it), (np), (ln), (cn), (cc)), \ err =3D of_phandle_iterator_next(it); \ --=20 2.34.1 From nobody Mon Feb 9 00:38:53 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 36D6831AAAF for ; Wed, 31 Dec 2025 11:47:17 +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=1767181640; cv=none; b=L49HdWP0lvV2AYCVRqpIu8qn/1D+dL+qsmoPHUEbHEpHam938WCNULltDP0h11MqZd6gYU0ALkAtbie6Pw5gkVAMpbKMFpV+ZAg3R2hwNLzfUg8MMK8YcixFj83ZZaF1HLtMt0+FwJ4gQQcv8r2w7V1H4Xar5205bp196mVzsbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767181640; c=relaxed/simple; bh=4voe3YPTzr7o5NUyZmk5stFXxPZFN/b9GYdzr6k2uIw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VCBhW2uic7/iRU6e3ZPVthXGB1Qh3dpbHzWiTnCINcBXpQWNvN73ASdU6TUWGbQ2nbinRx9nYhh++VIhF7mG4BRzq0o1ny5RzFVf55XE1sfaRFsf6mijJtctZpJuCEfum2XApFN8u7K7gCE3p+pONbibphDfQHEerULmchD65ac= 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=PuVP9Oe9; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=aUsE5U2r; 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="PuVP9Oe9"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="aUsE5U2r" 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 5BV78ZDi2733397 for ; Wed, 31 Dec 2025 11:47:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=6otJj073qoL 8N5HQasQT64tA/eYb0f1bGXAj9s5tpa4=; b=PuVP9Oe931HF9BfrSk6BJ9SnqSv t9lmjjMq3AdQXxY6oqZokJfHmUBN8Jp2C7qvdy5eDU3ePsmwL1Ejo2hcBDXBZC2w RKII8T3CIPOiURuU1NZ0FtjpROMUdppPR/aEczq2XosfNRpSmwptmbTDiuCQd+2Y d/XutvrGgw/gALSlI94spFbVltnohUrZECt8uTQnY3Cq58axXH0LlOTQhT/tDSWt 7Pn7jmdokeyQGiViw5ODxZPaC5IWOQms/NvzWPhBbq5FONZPsE+INGwi3ra9DMNU Qdwx6H44EYpPiOXIj/yP8mxFv20y49k8dSi8YK57O6wNx/qumH89Jpxs4Xg== Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4bcy6agewm-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 31 Dec 2025 11:47:16 +0000 (GMT) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2a0f47c0e60so270773675ad.3 for ; Wed, 31 Dec 2025 03:47:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1767181636; x=1767786436; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6otJj073qoL8N5HQasQT64tA/eYb0f1bGXAj9s5tpa4=; b=aUsE5U2rxjlou6SvOiuuqRg0TqystTrcyXeuxQ/LndEGEDs1q+FmNcCFeuds/pChgn 0yE4wKzcwQYui0MZStt+9Sw2GBrTwBD/dMhEiEiip8Lh+PpY4+2HjEanZEpfu5isA1j3 h/Mxv/w142BZn2BB0s2ShBg1wAmpbUaNPIRp6eN4ZkW2KqpqSDgOp0ngOkthD44EirC0 wKVExQ5TSGPtCBBgSoQOXa4p/af7nc+nb9MNfTGVdO3rqAdYoVrjzJWtpC2X9rYVYKVb K1Sdfw9mc8MQ6PNs45M6xYEYQ9E+O8yKiLVEwds5ygs4HhCSSzp6O7btaB+zYlbhL/UC wosQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767181636; x=1767786436; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=6otJj073qoL8N5HQasQT64tA/eYb0f1bGXAj9s5tpa4=; b=kOaREgsrIokF52pGRb8wbO/vlmCA89XAFs/Et8ApmxwL1+XOxkp485ti9V5b0AQfA5 aJwUtg/PmikNXwN8KHHv1us5KEnz89uQQMITsff2rIEMiSUDgITTOmzcWFVu2KY/cxYG pymTZYceH/DBdo22NelM77iompoKz4Z627MV7VjiYeW2b34vi8X9oX/lmQFzyc920fbs aHpFZVkwZRKqse9YfOLAwRQdqHus9HH3WrzdhubAiFAua+9IlbG+XvClLVdZRnr5cVrZ +zBr3HnRBiPBv8qW+FLr+ChVGWn2YeWhdNAi/+4jOxJhPt3im6AjFdiNlYL7nsXH8BnH DX6A== X-Forwarded-Encrypted: i=1; AJvYcCVhrYcCmjQjFpy6JYT3Pc745LleFqM3dqSFLqpTuvoFcGw0leGzQrAoohvoz3b+u5QgGC0N6LLJ14OOktA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw299D9J8btz/eDCavzf2Fwruplnxa3YGAcUeeUJRyz1u7ypoj2 llPvoB4cTiRkOqXaKSJHIcZ4uYD99pRfEbp2WwwZUyuwphRPs43AZG73hAYBnv2K0erRT7g+E2H R2kXwKrnrfWdTuPXkCc2lIPaGoESaBq6H9rwOFy+cY50zrtDzpSRPNKLr/eW/lLEOx7A= X-Gm-Gg: AY/fxX5TQY1v54ZlrJflON7TRjw5rttPwIR6GqFE8ebnwl0e+wmDgNSkCCFSwkP+XX4 ohT4AsIHRjda/14qmM057T8iyCVdCEBCLBd74m0DwTT1mTX+WshUWzoOjpQd43gnjIGvEksYT8D M/HB1o5UqvhvHxu9LoXZrJPEsIJ29fFRCxM9T0jgTnByB0htzhwUt+OCGFkRP2CajqHGRp3W7lY y/LwYnQitvFeMpmXge8ZC5ykceUPB5oyk1uO8Gbpv3qUKqOnflHTddElA3Q1ppjw/X9bvuHITVl x73nPKZ95fvHGeT3Vcpy11k6MYDs0JdKmHlQbaav2oWb/3RUJDukm3Niz2ef64j14xH5Ojb6OAQ UlaCe4NRe5CB0BJEMcocbWdEBH2qYT6D6iPgavC+0ytG2 X-Received: by 2002:a17:902:d541:b0:2a1:388c:ca5b with SMTP id d9443c01a7336-2a2f2a3551emr408014655ad.39.1767181635842; Wed, 31 Dec 2025 03:47:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFWLn2P3f6vWIc7PUxOvAW918ZaEYh57QDdnmvJLDP3aQa+P5h2mP+8Bl8o6ZERBih4KeJq0g== X-Received: by 2002:a17:902:d541:b0:2a1:388c:ca5b with SMTP id d9443c01a7336-2a2f2a3551emr408014375ad.39.1767181635351; Wed, 31 Dec 2025 03:47:15 -0800 (PST) Received: from hu-vjitta-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7ff7b5236b5sm34815656b3a.29.2025.12.31.03.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Dec 2025 03:47:15 -0800 (PST) From: Vijayanand Jitta To: robin.murphy@arm.com, will@kernel.org, joro@8bytes.org, robh@kernel.org, dmitry.baryshkov@oss.qualcomm.com, konrad.dybcio@oss.qualcomm.com, bjorn.andersson@oss.qualcomm.com, bod@kernel.org, conor+dt@kernel.org, krzk+dt@kernel.org, saravanak@google.com, prakash.gupta@oss.qualcomm.com, vikash.garodia@oss.qualcomm.com Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Charan Teja Kalla , Vijayanand Jitta Subject: [PATCH v4 2/3] of: factor arguments passed to of_map_id() into a struct Date: Wed, 31 Dec 2025 17:12:56 +0530 Message-Id: <20251231114257.2382820-3-vijayanand.jitta@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251231114257.2382820-1-vijayanand.jitta@oss.qualcomm.com> References: <20251231114257.2382820-1-vijayanand.jitta@oss.qualcomm.com> 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 X-Proofpoint-ORIG-GUID: OLJLHPOe0KXllIdBwJir9U5xnsns1txP X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMjMxMDEwMyBTYWx0ZWRfX5on3EmeC4W8M 0TWOmFu+9NeGN1yXzU8e8fyEtsiFr1ikgFGPTIc4jO616/7aAlfaYXjTuLwSyIVK6PMyz4D5kND oXKFgCTYMll25wWEwi0lyzcgVpu0eIoZZRixHW3sWnflwfWwPAV2cKyrh/iZdQtZ2lCXT/mJS6M pxBUwMkmj5LEKpsZyuTtGytGWrVc44WBuoUVvrXAgSCBlPUUYApGR/Rg3omuBKDFegsI1fXXqVl zCRwD+KTKCWGAdfDMwru0vOKirdgEXBYpi4GDFaLXTXSHf0SWTXsbhA7yDarrG+wbdR6BvffjwV M+vrv91ZCT8qsWMhSaMKZSvHsVAmIKUnYWAZskOmJ7b/y9jfdBIaTECPd6zD7u4Jwir+uCGPbAP r+dd6oaczJM9aDTHM6kBAZwQCyNu+xNYRqlrRqNSrKUwoj8T8xX1FRQ35s7cGnfINNIUSEnYgoa IRqdYMRan7HNDjp16vw== X-Proofpoint-GUID: OLJLHPOe0KXllIdBwJir9U5xnsns1txP X-Authority-Analysis: v=2.4 cv=J9GnLQnS c=1 sm=1 tr=0 ts=69550d44 cx=c_pps a=IZJwPbhc+fLeJZngyXXI0A==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=wP3pNCr1ah4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=EUspDBNiAAAA:8 a=VwQbUJbxAAAA:8 a=MW3YCBiU85KM78DY1KAA:9 a=uG9DUKGECoFWVXl0Dc02:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-12-31_03,2025-12-31_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 adultscore=0 impostorscore=0 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2512120000 definitions=main-2512310103 Content-Type: text/plain; charset="utf-8" From: Charan Teja Kalla Introduce a new struct type where the optional arguments passed to of_map_id() are Currently embedded as of_phandle_args struct. Subsequent patches add additional arguments to the struct that the caller expects to be filled of_map_id(). Suggested-by: Rob Herring (Arm) Signed-off-by: Charan Teja Kalla Signed-off-by: Vijayanand Jitta --- drivers/iommu/of_iommu.c | 12 ++++++--- drivers/of/base.c | 37 +++++++++++++-------------- drivers/pci/controller/dwc/pci-imx6.c | 6 ++++- drivers/pci/controller/pcie-apple.c | 5 +++- drivers/xen/grant-dma-ops.c | 20 +++++++++------ include/linux/of.h | 24 ++++++++++++----- 6 files changed, 64 insertions(+), 40 deletions(-) diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index a511ecf21fcd..646ac5a67475 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -45,15 +45,19 @@ 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_map_id_arg arg =3D { + .map_args =3D { + .args_count =3D 1, + }, + }; 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, &arg); if (err) return err; =20 - err =3D of_iommu_xlate(dev, &iommu_spec); - of_node_put(iommu_spec.np); + err =3D of_iommu_xlate(dev, &arg.map_args); + of_node_put(arg.map_args.np); return err; } =20 diff --git a/drivers/of/base.c b/drivers/of/base.c index 7043acd971a0..9f327c6b4f6b 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2051,8 +2051,11 @@ 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. + * @arg: contains the optional params, wrapped in a struct of_phandle_args, + * which includes: + * np: pointer to the target device node + * args_count: number of arguments + * args[]: array to receive the translated ID(s). * * Given a device ID, look up the appropriate implementation-defined * platform ID and/or the target device which receives transactions on that @@ -2066,21 +2069,21 @@ int of_find_last_cache_level(unsigned int cpu) */ 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) + struct of_map_id_arg *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 (arg->map_args.np) return -ENODEV; /* Otherwise, no map implies no translation */ - *id_out =3D id; + arg->map_args.args[0] =3D id; return 0; } =20 @@ -2122,18 +2125,15 @@ 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 (arg->map_args.np) + of_node_put(phandle_node); + else + arg->map_args.np =3D phandle_node; =20 - if (*target !=3D phandle_node) - continue; - } + if (arg->map_args.np !=3D phandle_node) + continue; =20 - if (id_out) - *id_out =3D masked_id - id_base + out_base; + arg->map_args.args[0] =3D masked_id - id_base + out_base; =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, @@ -2142,11 +2142,10 @@ 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, arg->map_args.np ? arg->map_args.np : NULL); =20 /* Bypasses translation */ - if (id_out) - *id_out =3D id; + arg->map_args.args[0] =3D id; return 0; } EXPORT_SYMBOL_GPL(of_map_id); diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller= /dwc/pci-imx6.c index c8da2e88e9c6..8dcdde2efb8a 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -1101,12 +1101,16 @@ static int imx_pcie_add_lut_by_rid(struct imx_pcie = *imx_pcie, u32 rid) { struct device *dev =3D imx_pcie->pci->dev; struct device_node *target; + struct of_map_id_arg arg =3D {}; 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); + + arg.map_args.np =3D target; + arg.map_args.args[0] =3D sid_i; + err_i =3D of_map_iommu_id(dev->of_node, rid, &arg); if (target) { of_node_put(target); } else { diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/p= cie-apple.c index ce21728d6e51..dea4a38cb4bb 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -782,6 +782,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_map_id_arg arg =3D {}; int idx, err; =20 port =3D apple_pcie_get_port(pdev); @@ -791,7 +792,9 @@ 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_iommu_id(port->pcie->dev->of_node, rid, NULL, &sid); + arg.map_args.np =3D NULL; + arg.map_args.args[0] =3D sid; + err =3D of_map_iommu_id(port->pcie->dev->of_node, rid, &arg); if (err) return err; =20 diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c index b661f9c1f4fe..86edb11d8d26 100644 --- a/drivers/xen/grant-dma-ops.c +++ b/drivers/xen/grant-dma-ops.c @@ -315,38 +315,42 @@ 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_map_id_arg arg =3D { + .map_args =3D { + .args_count =3D 1, + }, + }; =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, &arg)) { dev_dbg(dev, "Cannot translate ID\n"); return -ESRCH; } } else { if (of_parse_phandle_with_args(np, "iommus", "#iommu-cells", - 0, &iommu_spec)) { + 0, &arg.map_args)) { dev_dbg(dev, "Cannot parse iommus property\n"); return -ESRCH; } } =20 - if (!of_device_is_compatible(iommu_spec.np, "xen,grant-dma") || - iommu_spec.args_count !=3D 1) { + if (!of_device_is_compatible(arg.map_args.np, "xen,grant-dma") || + arg.map_args.args_count !=3D 1) { dev_dbg(dev, "Incompatible IOMMU node\n"); - of_node_put(iommu_spec.np); + of_node_put(arg.map_args.np); return -ESRCH; } =20 - of_node_put(iommu_spec.np); + of_node_put(arg.map_args.np); =20 /* * The endpoint ID here means the ID of the domain where the * corresponding backend is running */ - *backend_domid =3D iommu_spec.args[0]; + *backend_domid =3D arg.map_args.args[0]; =20 return 0; } diff --git a/include/linux/of.h b/include/linux/of.h index 8cd486d89da2..0b0d545b80a3 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -74,6 +74,10 @@ struct of_phandle_args { uint32_t args[MAX_PHANDLE_ARGS]; }; =20 +struct of_map_id_arg { + struct of_phandle_args map_args; +}; + struct of_phandle_iterator { /* Common iterator information */ const char *cells_name; @@ -458,7 +462,7 @@ bool of_console_check(const struct device_node *dn, cha= r *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); + struct of_map_id_arg *arg); =20 phys_addr_t of_dma_get_max_cpu_address(struct device_node *np); =20 @@ -907,7 +911,7 @@ 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, - struct device_node **target, u32 *id_out) + struct of_map_id_arg *arg) { return -EINVAL; } @@ -1436,17 +1440,23 @@ static inline int of_property_read_s32(const struct= device_node *np, } =20 static inline int of_map_iommu_id(const struct device_node *np, u32 id, - struct device_node **target, u32 *id_out) + struct of_map_id_arg *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", arg); } =20 static inline 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); + struct of_map_id_arg arg =3D { + .map_args =3D { + .np =3D *target, + .args_count =3D 1, + .args =3D { *id_out }, + }, + }; + + return of_map_id(np, id, "msi-map", "msi-map-mask", &arg); } =20 #define of_for_each_phandle(it, err, np, ln, cn, cc) \ --=20 2.34.1 From nobody Mon Feb 9 00:38:53 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 EB646320382 for ; Wed, 31 Dec 2025 11:47:23 +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=1767181646; cv=none; b=W/ihD5keEWbWJ8psqaHLTtuwwYqoWAWgykOfDYb5JTsAgYeG2p/+qhvpn8RMzDBVd0Or5eUjfcftThQPeajRFDtdCCg3Y/yoFVmji0GT+UelkaZFWXlZ+Bu/cwOVrfZHOuhISLadCVGmYU/MAbHIHqaUg/FNLpa1WxeMEb88cu8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767181646; c=relaxed/simple; bh=VW6mropM/qgJyRpTP+x0lj/EXDo6KYD94OeJSjBlA9w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oUBnhnLHV5+ETxuCIJINyArFkXWDY62eYcKMxKwteJuRT4xWlvJJcMB1zB7yfNc4IRUPlJEGpNd+kxyAjPF5Bx7HXv0C6aE/nih1SrAX5Gwl5RqwlDLyRTjFyIwO/oAF/axrBYrzlMRd+O+bZqerm7XK83sigFutLPSR90rCSxs= 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=MM0I91e+; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=XNgm5oLY; 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="MM0I91e+"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="XNgm5oLY" Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5BVAi49c3367074 for ; Wed, 31 Dec 2025 11:47:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=/fduSmx6bVt 2bbx1bsoxxix3/liUH4tNQCRD9+FpSBE=; b=MM0I91e+yDwnNrEZLaftb5kmc/w oNdcF5HssLLmp5SqynT0Nd7/HcMXKjanIHvOMNPpVJJfJ8MVeUtTQWgwYEKUaIUc 4SOmkAPBYIyUaN4Ct97HV36iin1ZRBKugCTA3QAN3na46gF9wngHjAEnmFqxhkd+ ZClwM2j225P/oCOrvqJiTSWKUOkK0SH9H+mVMnBCInVV5LkKU28jzY2QDvUJUog7 6aUAHygsguQZiurQk2kdvbgyDqH0RO4Mg3qVQvb8Po4Ss/xIHkBnvyiimd7uM68y A+kiOHFNsWiMQ4ouceAzf5SJmiZ7EtFoUclz8YKRj16/hHtxexQHoHbR33w== Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4bd2bb02vw-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 31 Dec 2025 11:47:22 +0000 (GMT) Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-7b9c91b814cso24542636b3a.2 for ; Wed, 31 Dec 2025 03:47:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1767181641; x=1767786441; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/fduSmx6bVt2bbx1bsoxxix3/liUH4tNQCRD9+FpSBE=; b=XNgm5oLYk/5oXgKsGcfLwIRbwbg7rApaFwIv0+0t+Yusa3PmRRRejsHrULDxktxolh fknZd8/JTSynzelCOmfosWM0rLLIHhH3YHqn6xa7U2SmyYALJkKtqDK1fRpMFHPQEGfd F21hcGlWgy7oCjK6GDTNhswJo3EZQrgv7Hc8AhKcizNR30v/gJ8QWm2z3wn5UVwcLOzg 7p5d4JUY3ZzKGAaBIYLkQUNtWdA2DQW0ARXO8iFMCtcfN0tSCYII6WVnfvFaGVWpEgjz pPxxhgsZiByTuRNRgBBFOx09/+GVN0NqwO9fmVRgh2ugEcKksqSN7WthSfXeX/UEMCYi TiUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767181641; x=1767786441; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=/fduSmx6bVt2bbx1bsoxxix3/liUH4tNQCRD9+FpSBE=; b=QXZMSjDQZnCNvC69dJJiDbHJT0G7TQ3qVBv+AY/5Oz4nIkTxcn/yJMdqcDWf9aXon2 CFh66U8xd6ZuROpWoUaKnBE3302CjCLXYdiJsIyK+JIHPcqSLjkzJW6wo+ZvPm60sDLr SDwvwxBgTD2n1VeekBG+/Vkls9AWQHIQaWyidnVBbX8USwpqF521PYK3ez7XythFcn86 J/NdHZcU8yArv3UV7G8a2rMCBUDjXODfDWHeeVBm1ApGPEhh4ltukHkL5/fSUGIWpqq9 fVUxtd4Csb/z7VJQ+SDptMmqyvvtibG+arIYlSm1gYMdfuXLQsv8BdQKURcFfkaAf5oh kOyg== X-Forwarded-Encrypted: i=1; AJvYcCWgB6N1ycwA6pPrSsKKRBl00eszjqx3s+1+iVKlnZbuwQHUz80E2oMqtE2vAEkFZO/kxLHrLdQigpXpzek=@vger.kernel.org X-Gm-Message-State: AOJu0Yxxpt0fkr7NmF2rS9bAMYLbgHn69VgENX0ZajAJp0GzpZatp/tv xSWz1QvlzIVFjNAZowyiBZCul1QYEwQ+rkxA0IFagUNSWGYR8EYNeaPk6rkRNFR3KCSnqR/a6BR jUnByeJN0Pki2X0f5yj+G5fvoBMfrrh7JuYbkghnqIOdGVo75RH9ADPAj9HrzkVRyWRo= X-Gm-Gg: AY/fxX5L+9w7LZg8n7DyRgnLoy8BRrw3CqW/dzX3AJkUEoriqN/ohFnAEzVgP6Vn7HT 5knziw7eZJgjffyD1AZJQeHHwMcuNzNw9vFpwqdp22ZHD/VxMJ61XgWpTc1FzVSdwzwjMPSU7K1 6tfq/ScXl+cwR+tG8sXN9j4m0HjJqY5UE5u0SwW6jiCl+W6jTywRZEivuuhG05T7pxie044UrQR Oh6dOo8y7yS5J5Iaki60+g+JCO88sVp8gL2qcJC7TAoidWuZjj1WODQ2Ei5UTKwRDG3NotKyzAH qzau9npNL0w5RS55lcenquOLyEdwKFTQCbDjKxRRb4w9PwwTynHLLcBtl3dK5pZZiDnc2vltl87 o1XNXgWhicyazuAeAcjH/U6L1EInS+6eAWYIbn0GUzakX X-Received: by 2002:a05:6a00:ac08:b0:7e8:450c:618c with SMTP id d2e1a72fcca58-7ff664814e0mr33448674b3a.35.1767181641486; Wed, 31 Dec 2025 03:47:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXhl6AsXpl08sOYSrLAsmcJSqisvl+DLZQ5Y0W4wLV7mx8rFuEi4+2RYdP6ARX1JOcRAY4mg== X-Received: by 2002:a05:6a00:ac08:b0:7e8:450c:618c with SMTP id d2e1a72fcca58-7ff664814e0mr33448659b3a.35.1767181641023; Wed, 31 Dec 2025 03:47:21 -0800 (PST) Received: from hu-vjitta-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7ff7b5236b5sm34815656b3a.29.2025.12.31.03.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Dec 2025 03:47:20 -0800 (PST) From: Vijayanand Jitta To: robin.murphy@arm.com, will@kernel.org, joro@8bytes.org, robh@kernel.org, dmitry.baryshkov@oss.qualcomm.com, konrad.dybcio@oss.qualcomm.com, bjorn.andersson@oss.qualcomm.com, bod@kernel.org, conor+dt@kernel.org, krzk+dt@kernel.org, saravanak@google.com, prakash.gupta@oss.qualcomm.com, vikash.garodia@oss.qualcomm.com Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Vijayanand Jitta Subject: [PATCH v4 3/3] of: Respect #{iommu,msi}-cells in maps Date: Wed, 31 Dec 2025 17:12:57 +0530 Message-Id: <20251231114257.2382820-4-vijayanand.jitta@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251231114257.2382820-1-vijayanand.jitta@oss.qualcomm.com> References: <20251231114257.2382820-1-vijayanand.jitta@oss.qualcomm.com> 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 X-Proofpoint-GUID: eKLpf8ROfTw6iHHefHKXhNOy3Z9CJ3CS X-Proofpoint-ORIG-GUID: eKLpf8ROfTw6iHHefHKXhNOy3Z9CJ3CS X-Authority-Analysis: v=2.4 cv=dMKrWeZb c=1 sm=1 tr=0 ts=69550d4a cx=c_pps a=rEQLjTOiSrHUhVqRoksmgQ==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=wP3pNCr1ah4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=7CQSdrXTAAAA:8 a=EUspDBNiAAAA:8 a=wJGdY9mNwEi-N7fqGJcA:9 a=2VI0MkxyNR6bbpdq8BZq:22 a=a-qgeE7W1pNrGK8U0ZQC:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMjMxMDEwMyBTYWx0ZWRfX1kCV6e1UxCT+ xlQ5r+joQnWM70AOWMWZiXtRb9noHz5CMF+ZsLE4BZCmFG5Au2RS7qb0ceoo/9o7Xvk2FORImrQ kQQrjM07XmS7n5Vc1I2AlXufb8tGRqrpoyuulFM5gWNGXKTBFCeL8QuPDmgJ927QrZNuLRBmc80 YrzQmOKps0IIL1lNP8w8fB8bn3HU3VZEfS9ZMV6ofmyrnwN9jrgXVOpurVbF+C554UkjUv5m0g9 crwAGonYH0zpTaXgImnUFReurNu1/C/hStga6nGdVe6c942G9Dv9C17Gnp7dFmHql9xmRAikSzR pz7y9M2kQlQLrbMOjHm7IzWC0LxvMGuOHm/gAQUqri7TvbpYduMHaVzjkaSoU6+/APua9rx0T74 fHGLo+cJ5XT1DORfQBiegBkKH2NRQiO7/3Ny0CONoxz47+HtzDChBO0mPbZAfjLiwKP2aYgAee1 lHaPcMuSGDWKZrWCAbA== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-12-31_03,2025-12-31_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 suspectscore=0 spamscore=0 malwarescore=0 impostorscore=0 adultscore=0 phishscore=0 priorityscore=1501 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2512120000 definitions=main-2512310103 Content-Type: text/plain; charset="utf-8" From: Robin Murphy So far our parsing of {iommu,msi}-map properites has always blindly asusmed 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. Added support for that part --charan Signed-off-by: Robin Murphy Signed-off-by: Vijayanand Jitta --- drivers/iommu/of_iommu.c | 4 +- drivers/of/base.c | 114 +++++++++++++++++++++++++++++++-------- include/linux/of.h | 16 +++--- 3 files changed, 101 insertions(+), 33 deletions(-) diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index 646ac5a67475..768eaddf927b 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -46,9 +46,7 @@ static int of_iommu_configure_dev_id(struct device_node *= master_np, const u32 *id) { struct of_map_id_arg arg =3D { - .map_args =3D { - .args_count =3D 1, - }, + .map_args =3D {}, }; int err; =20 diff --git a/drivers/of/base.c b/drivers/of/base.c index 9f327c6b4f6b..f0507ddb6dae 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2045,11 +2045,38 @@ 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. * @arg: contains the optional params, wrapped in a struct of_phandle_args, * which includes: @@ -2067,18 +2094,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, - struct of_map_id_arg *arg) +int of_map_id(const struct device_node *np, u32 id, const char *map_name, + const char *cells_name, const char *map_mask_name, + struct of_map_id_arg *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 (arg->map_args.np) return -ENODEV; @@ -2087,11 +2115,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; @@ -2104,27 +2130,64 @@ 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, + 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; =20 + 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 && of_property_read_u32(phandle_node, cells_name, &cells)) { + pr_err("%pOF: missing %s property\n", phandle_node, cells_name); + return -EINVAL; + } + + if (map_len - offset < 3 + cells) + 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); + return -EINVAL; + } + id_off =3D masked_id - id_base; + if (masked_id < id_base || id_off >=3D id_len) + continue; + if (arg->map_args.np) of_node_put(phandle_node); else @@ -2133,11 +2196,14 @@ int of_map_id(const struct device_node *np, u32 id, if (arg->map_args.np !=3D phandle_node) continue; =20 - arg->map_args.args[0] =3D masked_id - id_base + out_base; + for (int i =3D 0; i < cells; i++) + arg->map_args.args[i] =3D (id_off + be32_to_cpu(out_base[i])); + + arg->map_args.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 @@ -2147,5 +2213,9 @@ int of_map_id(const struct device_node *np, u32 id, /* Bypasses translation */ arg->map_args.args[0] =3D id; 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); diff --git a/include/linux/of.h b/include/linux/of.h index 0b0d545b80a3..ee07e8642133 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -460,9 +460,9 @@ const char *of_prop_next_string(const struct property *= prop, const char *cur); =20 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, - struct of_map_id_arg *arg); +int of_map_id(const struct device_node *np, u32 id, const char *map_name, + const char *cells_name, const char *map_mask_name, + struct of_map_id_arg *arg); =20 phys_addr_t of_dma_get_max_cpu_address(struct device_node *np); =20 @@ -909,9 +909,9 @@ 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, - struct of_map_id_arg *arg) +static inline int of_map_id(const struct device_node *np, u32 id, const ch= ar *map_name, + const char *cells_name, const char *map_mask_name, + struct of_map_id_arg *arg); { return -EINVAL; } @@ -1442,7 +1442,7 @@ static inline int of_property_read_s32(const struct d= evice_node *np, static inline int of_map_iommu_id(const struct device_node *np, u32 id, struct of_map_id_arg *arg) { - return of_map_id(np, id, "iommu-map", "iommu-map-mask", arg); + return of_map_id(np, id, "iommu-map", "#iommu-cells", "iommu-map-mask", a= rg); } =20 static inline int of_map_msi_id(const struct device_node *np, u32 id, @@ -1456,7 +1456,7 @@ static inline int of_map_msi_id(const struct device_n= ode *np, u32 id, }, }; =20 - return of_map_id(np, id, "msi-map", "msi-map-mask", &arg); + return of_map_id(np, id, "msi-map", "#msi-cells", "msi-map-mask", &arg); } =20 #define of_for_each_phandle(it, err, np, ln, cn, cc) \ --=20 2.34.1