From nobody Fri Dec 19 17:53:02 2025 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 B44992C0276 for ; Thu, 4 Dec 2025 09:55:50 +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=1764842152; cv=none; b=Iitt8BK64jQTlbgswmKiPKs40F+D+COsS69X1q5ENKa1Bli9hcNzZ4JAEMi7AzJ92ZowF76VcIvrjwgZTeygKdEOjSg2Vcso2ijZb1jx/m8ot0/73NDQxbIkp3trIxphdWlpQV+pdfnX1lvSpnAN0eGJjQYMk+07xeiyTQ6TqqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764842152; c=relaxed/simple; bh=Q5WRkKpyNFdbwHCAdlIO1JtLhoqGJ6yKGFP0g8RLsAU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IR2CLPqUueif+vFwYzbAZm3ePM/JQLeOnpTcEWQiKFN0OA4PfSzQgGxhw2R+YuXhioBoodLBrJkhXsUbrRbXBTc39uXVKgXqUJQCbD7aCobhm1eiHeoIQfN+hfuKpm2fKj0NfFByQ2w2XtNFmk7mARH+PudCyWYv5aCCr+pmyrY= 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=ccbgS7Tr; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=jJQlhhqk; 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="ccbgS7Tr"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="jJQlhhqk" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5B475w7i514856 for ; Thu, 4 Dec 2025 09:55:49 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=RTHii2RLOwx Qg87de6ltvKhXlBHDtZXgHyW74oiIDH8=; b=ccbgS7TrD/txKOXrC+7Ky0N5IHE WW7nfIV8WgcibHa31F654e0SBk/lyEFbyzuk/fLUv+u85TlyZZZAwSeY20cr98M9 7gUo3GxVfkB7q7xVHyG/GHEXDrKrSJSPw2p8bkGDGRFHL+EkOUmagHbTjZYRTyGk S8uu7VqW71klRBgiSGhp1XSu+KaGVb/yvjqC6wFzcevZrJ0N+GZQLVrx9zDBO5cl Ac32ZjywAakm/AwyPbDJVG+EUQB4Gk8gGgaK7MU9+uxU1LRAgJeYTly9V8x7ZZ/Z wgL7b2RnKN2TcKFAe3vSDZScNOA2A/cq5HMQHF4gvZC0sn2M7NnLPnwpAlw== Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4au5m30jxy-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 04 Dec 2025 09:55:49 +0000 (GMT) Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-7ba92341f38so788173b3a.0 for ; Thu, 04 Dec 2025 01:55:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1764842148; x=1765446948; 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=RTHii2RLOwxQg87de6ltvKhXlBHDtZXgHyW74oiIDH8=; b=jJQlhhqkbxj6ItbnJu142YNowtw2tjQwtNc6br+YEV0YkRum4lgcIWRGEq2ulo5m+k X2j7yxkKhduvCkzvhYj4TGLwx/CahaC4Bx8N40gi7lkfg2x80laFoNLzjChcjspLAtKh 9SCVlvOyP83V4ZDsxLbyB7SFgJ+aXhVPVF4qlpagnhpjHMtC6oorFvJqr7UK9ubvXNFL riircJ3L3liKAj1fx6uBAecpPjsz1GaNQXcGkfX2K2o1X0T/nNmxqXx0exmMTcCTkLEY AIFKXCY33RzYlQi85nkQ6mtC5XD7u2w04dfcqKZBRwMyjb/lBtP6kMhL0KB/LCTpkWU7 GZ4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764842148; x=1765446948; 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=RTHii2RLOwxQg87de6ltvKhXlBHDtZXgHyW74oiIDH8=; b=JFSJggmajRF+nd+WR8RkjCNWwrgNGAQ8FblG6OgPAgQzLskuaBu4tIiwiKETj2S/ZI IGkWCL6yTYk4wvAbjoPqvR0GWvNrjd6zuFbSeSs8EuldLOx+4SEF8Zby+u41ZsRp7vo5 Fn46oLNey1WCEJrjU/vztZaS+RAVA3arSECmJKSs/oNqFTBexgTzfi53s9lCtxlKcGZs aMWprq5vf8qYZc4614/sWzd+xzc2QkjSM92vxNEefaK6HDSDloPDiyG+E93UzU+IWGlB ZUX4XnaZF1cD3lMJYC7wgEV4n5+rTD695YvGFEoCVB/+aiHNb4KUN6Km69wXdpzMpOtf 0rEQ== X-Forwarded-Encrypted: i=1; AJvYcCU6AAvoBILkcyNMrH7KiDwBuyfdoZN6rbYzyjr/iY7b4KBwEM4uDauEOewqTRQeit7Meou4VpA1OVfGO2c=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+K1KQzoktmssBhdV8oU1LSdVbGAgXY6L4CQ2dQsHKZN3OWJhB ZMY8CnYJ3Qqa3J3kCWs9AMbl+xbN0KGH/iQxpBRLgHGZxFGjGTP4BYSlwkSVe8vZ2ZxVJIUm8yI nWfveqmmjWLUHo7msnrO8cle9arzH+IuVugVksouTS77Csa34HkaABqas9eJJxVVE4+M= X-Gm-Gg: ASbGncvH86jnL8PbSNWQsi5582kdMitJlr65Zw6DPiR/gVwKMGUwhJRqq6MM7/IzlXJ M7fxEY32K94oAhKRUEgWc4xXSrAleDQ+Ag70gL411VKgq58axiDbXLyQNtBUYy0jBDSC89kaURs HMZnd5z86Xo4DXOCE8c7M4yrQdtGCsiRQnoeyXL0kLOMvC9pN8rwaLG8+hYjRUHCqnCcMR4gmMB rbdKVC3mfAL9rOBqWxGfy0nL8oAChhPrEGzfDVj0VaTowWj5L9WbvJf+VX/LjKNff4WzWLbUt6Y Wn2lqTQxEyrRpxofRdXFH6wvrtIxUxvDZRNPu/o4sVf88RfVwah4l9OPo3iFCneMa8xzBtOiLXk SdOMWx4Fg03r1FgwKbsvAXD8E0HnD9xke106hJ1mYL+EJ X-Received: by 2002:a05:6a20:914f:b0:35d:3533:3dc3 with SMTP id adf61e73a8af0-364034d65e7mr3167146637.0.1764842148339; Thu, 04 Dec 2025 01:55:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IF3bSXLdxVXUYRIgsjlgz0h6EiUD4YFBwgWd3A851Q4FLR+fZ2b9jkBuDemkSTpDV7tY93+Yw== X-Received: by 2002:a05:6a20:914f:b0:35d:3533:3dc3 with SMTP id adf61e73a8af0-364034d65e7mr3167110637.0.1764842147824; Thu, 04 Dec 2025 01:55:47 -0800 (PST) Received: from hu-vjitta-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-bf6817389fdsm1380436a12.1.2025.12.04.01.55.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Dec 2025 01:55:47 -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, charan.kalla@oss.qualcomm.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@oss.qualcomm.com Subject: [PATCH v2 1/3] of: Add convenience wrappers for of_map_id() Date: Thu, 4 Dec 2025 15:25:28 +0530 Message-Id: <20251204095530.8627-2-vijayanand.jitta@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251204095530.8627-1-vijayanand.jitta@oss.qualcomm.com> References: <20251204095530.8627-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: adP6aLHFNV59yRcNLCkXYizqruhxGiy5 X-Proofpoint-ORIG-GUID: adP6aLHFNV59yRcNLCkXYizqruhxGiy5 X-Authority-Analysis: v=2.4 cv=esHSD4pX c=1 sm=1 tr=0 ts=69315aa5 cx=c_pps a=m5Vt/hrsBiPMCU0y4gIsQw==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=wP3pNCr1ah4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=7CQSdrXTAAAA:8 a=EUspDBNiAAAA:8 a=zC5qE-s5kk4CCBLE0fQA:9 a=IoOABgeZipijB_acs4fv:22 a=a-qgeE7W1pNrGK8U0ZQC:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMjA0MDA4MSBTYWx0ZWRfXxY4lKUxD9cck y7wrXx2XiL16GzAMN/FB8U8GFslfOBabiHXMy4WlXTIwtT33xxtsIx7SkGnLkAzzUycHnjjgp5s K9KpG3KM8G4CaEOpjcYvb6YX5kjoGvCFAyxjXyCYbRGuM0cuaf6Hs/e9EDoMPFA5INAYotlKPXy BKpN3BR0AEKYUA4g4W1ax5zD0B9uXTXQwuKihJROdbYUA92sWuSyLeJDjkGSte2jw4n9coGeur8 LtKN89XpTwP/42zPuJXiEstzcQkId78989S49R8OM6cDCSsSdMRbp9IU8fm5uFn8UUe/2KL5w45 EtRGA6KZbXFFQq6Q9DRaWzTukInub32pyr6NADET0SIErkdX26l0gmTUGtYTJ6X1cQBcSu11Z1m y25xx3Dq+wWghI7aVKzxUw7jq4vqaQ== 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-04_02,2025-12-03_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1011 adultscore=0 malwarescore=0 suspectscore=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2510240001 definitions=main-2512040081 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. Signed-off-by: Robin Murphy Signed-off-by: Vijayanand Jitta Reviewed-by: Rob Herring (Arm) --- 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 Fri Dec 19 17:53:02 2025 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 906BB33120A for ; Thu, 4 Dec 2025 09:55:56 +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=1764842158; cv=none; b=az4Dvivx4kaR5LAj4AANPLRIoSG2oD6BhVsSdeKBaKLZguYhARUN6BnRSSYI2O+7f9ebwpjpcjXBdnaOh1x2zJ/Xg62TwYX/q+KKHkldYJnA9i6l+Vf5Qjb7TeXg+p7jgyVwMhboBIGEBYtRdiA+UGjFbDOjyftlAcLgqnXDxgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764842158; c=relaxed/simple; bh=6PyyETF8k40quxwBmvqxGNRspbk5r7aeCKVnubAF4nA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q0ZhbfCgzps3PAwf0OYSvXJ02mgdvGyEJRoJGB+2soG8likQZE6GwBDeMuznAvj3xEvgIqc8WHtu+SMobPg4rJ0Lme4GMTrW0/I7tOD+2575T7smBBrIt8ZWhqFmfGYgR3Bek9VlzarfFnAHBdSZXCiwspMTwRqErcmOFZxM49I= 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=Mzvi5N+g; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=evcSTP7v; 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="Mzvi5N+g"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="evcSTP7v" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5B468gKE560123 for ; Thu, 4 Dec 2025 09:55:55 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=4j1Hi40g4e6 iwRM+cXGeU/TgM79ai7droalmMWQn/KY=; b=Mzvi5N+gFxr5HBTEWfWw51cdLDK 7TfXsrxF2dcqm9s9VHEbR6pKkUY+KUzvM2vanfqRBlEdszBumkxfRA8U7ywDs4XE Hv8R7m8KWJKbeW05solzTwyiAFp+84UkrtoqVAIG8ui3k9lflcT0hDS7dIP87dHX aqTJSE2BBooufyBxa4uxT7LsiadnWWC+ViIXQa1LyLjIUBwpPnsvrijb0FV0M4vX 2dPWmSmCgZ1qhhQVqknxvitW4unl4v9EQBXGbZbtIJg2wAfKu+mmVo0TaDLhq+FT hPlin362FKJjEOsU1W3FaIsF7H80iaN8afAznjvW/EDmKXDmaxg+uio/S1w== 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 4attmhaet5-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 04 Dec 2025 09:55:55 +0000 (GMT) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2980ef53fc5so18316245ad.1 for ; Thu, 04 Dec 2025 01:55:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1764842154; x=1765446954; 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=4j1Hi40g4e6iwRM+cXGeU/TgM79ai7droalmMWQn/KY=; b=evcSTP7vrMrQcViyY1t9f7p5kyyKK8vpeZM+eaoHDT2Z9Yhs+8UTKikZvyolLfT831 yI/mq4nxQzAdzglXJUuHEYM7Q0Ou4/eDtz3MyrhN0lYjuvGRYnnDxqYnTH/ENtyPuEI4 497zQtcks8xu37NyZrzqoQEoVdlGobZUNCxaY154a5A8E0JICM4+n7hC3adY93zolHmT dc001iL6sOVykbFh6f7T2sDZRVRcjQ41mn7Sm5YXR6IW2OG9yTQixuTjj935EcRAHgDn 8cC1B0W7gXghe78cFUd2mr3lOKTp2mgDamxBkAhtkogO4j83fiP21ictF1NBOtkHg55+ 3+Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764842154; x=1765446954; 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=4j1Hi40g4e6iwRM+cXGeU/TgM79ai7droalmMWQn/KY=; b=t0FxP448dJ5E1Qd4w1qmq4gyDnW0CWCcXpiBBwZ3w/zHj24+7ix6GyBK/CPaWIUSgD bNaXTDwHRBMKAL8I0mcGcQ1JsB1pbN1NDQVYhkYCLvgGqjER7nBBZ6u3QE/+j2Spj2NJ euYAdZxPXn5yXjmzymtOYuJqAMwXZrtKWVnAoGOoODARdjwSu7XrRz88BCyxS92rYy9S E3mgxdeD1kWXHXMSxWCe6AekatXGA4YgBuLqcWnTOjhw7AbY206GljyvFbbIIhZIDhiG 6fYrCMsZy2Y7u/7bawI1Xbp5qFEQxzGSCZ4IlZQwtvoZTCfx1VtZAkB6hcZKpBt03VYg r19w== X-Forwarded-Encrypted: i=1; AJvYcCVxuhKhVMf5GIBJcWTG7aj2wt3e+vMS+M0PwSQbBbGBmf4Xrlk8P+1m6o/GUTYjZK3irgPBpBGX3jzXKR8=@vger.kernel.org X-Gm-Message-State: AOJu0Ywrdvq8aNzOVbCDqkhOT2vDuz9b0i/cpZDv9V5oQe3O3fcR4Xza qCv8rMLYhL5jP/WeHQbTj3iYMAj1t8RLtYw5ixaZhLXU+j4QHayypi0opoH03zNlYAB+P2Z9SCz W7iqr7EJVg5v//i1rkoqG6usqveTYdHLDK5MnUMt64ViSNnf96YfKuAgL66kzMoER4HM= X-Gm-Gg: ASbGncvSppnMI7E/uQd0XA2t4XcpDj7CPsmpAMFwsOgdLJ4nb/Ce+uujRNRfhp+aC40 hHQjW1DO9LhSPC9IXwuvzdvCx8JpzkrvWu2mBOCJ1y4WqnUAnNCj0ChOWijZ4ZqQEg4IxkRRBkQ MsEvDyJJpMWGV4F4U74ljHtG1SyLIUHodELub+P1B3OTStHxSOCfgjZf6MPXEe5pkUuZJFsSTpl p1Ei8+Qrp3bGeyBgND6dT8fKTtMBstsdg2u33yAYBX5PkWhnFVHVef2fdQpu/x9YseP1UL5XtQ7 m4Fl3Uu9v+G1tvHfLmM+59VErDaR3JhfLUCQVisnhMvpJefFcnvGCYIzHCNhvNevAZpiVbn6LJg rjFADEvhrvr282d311evBEMnxo6pYms9i/Cps0/XeW6lC X-Received: by 2002:a17:903:240c:b0:295:4d50:aaab with SMTP id d9443c01a7336-29d682e400cmr56474595ad.20.1764842154337; Thu, 04 Dec 2025 01:55:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmnx0tg7Ob7VxFE7lJfcQbFgCacVT6NfmWVYjlbUz1vyx71fsGDZgckt+aMRDyp2ueVvMt+g== X-Received: by 2002:a17:903:240c:b0:295:4d50:aaab with SMTP id d9443c01a7336-29d682e400cmr56474365ad.20.1764842153817; Thu, 04 Dec 2025 01:55:53 -0800 (PST) Received: from hu-vjitta-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-bf6817389fdsm1380436a12.1.2025.12.04.01.55.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Dec 2025 01:55:53 -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, charan.kalla@oss.qualcomm.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@oss.qualcomm.com Subject: [PATCH v2 2/3] of: factor arguments passed to of_map_id() into a struct Date: Thu, 4 Dec 2025 15:25:29 +0530 Message-Id: <20251204095530.8627-3-vijayanand.jitta@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251204095530.8627-1-vijayanand.jitta@oss.qualcomm.com> References: <20251204095530.8627-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: vlGHkWhlGD6h1A1QdXz4tKS7TiqARcSl X-Authority-Analysis: v=2.4 cv=NcTrFmD4 c=1 sm=1 tr=0 ts=69315aab 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=TItJH5Yx5ZyhTHJNrZAA:9 a=uG9DUKGECoFWVXl0Dc02:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMjA0MDA4MSBTYWx0ZWRfX/5Oud9oO6FSO 5XYN/3t2Pqihu3GlzDKD8+1bPPCK/uCDdPZ7PfxB7oU0+l+VY23G9JOQo3rB9dI4S5cGjlmiGuU 2fvdBbOvBbP2LKmd2/L17dcNJEHsmP9w1zvavR6Ri6LYKZs2ild3/rI3dsXgT0cpxCaVpnS/2mh sjXm7pqzZPBHTUNmaxcuD0HNIoZljLfu+xdrz9LQSoucWkRZZhn5yb0G8zJMS8pFN+kl4XfOUvn US5VQulE18n3BWe2XEKA1+zD5awvMUtNsurB63sgCIvceUWMhxZ/t2ihp8YYoKfOm+khj1jqoWb Xp3g+SwHjuHBr7meAvRXQkveyifpqE2drGP6RftIGrVQjRvgfCA7oHYHLo1tj+8GZAjhUyK9t0F L+EFDsJi+MIBWwe5e3Y6Fus9UUcqEQ== X-Proofpoint-ORIG-GUID: vlGHkWhlGD6h1A1QdXz4tKS7TiqARcSl 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-04_02,2025-12-03_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 suspectscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 bulkscore=0 phishscore=0 adultscore=0 lowpriorityscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2510240001 definitions=main-2512040081 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 in struct. Subsequent patches add additional arguments to the struct that the caller expects to be filled of_map_id(). Signed-off-by: Charan Teja Kalla Signed-off-by: Vijayanand Jitta --- drivers/iommu/of_iommu.c | 6 +++++- drivers/of/base.c | 31 ++++++++++++++------------- drivers/pci/controller/dwc/pci-imx6.c | 6 +++++- drivers/pci/controller/pcie-apple.c | 5 ++++- drivers/xen/grant-dma-ops.c | 5 ++++- include/linux/of.h | 23 ++++++++++++++------ 6 files changed, 50 insertions(+), 26 deletions(-) diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index a511ecf21fcd..eac62bc441c5 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -46,9 +46,13 @@ static int of_iommu_configure_dev_id(struct device_node = *master_np, const u32 *id) { struct of_phandle_args iommu_spec =3D { .args_count =3D 1 }; + struct of_map_id_arg arg =3D { + .target =3D &iommu_spec.np, + .id_out =3D iommu_spec.args, + }; 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 diff --git a/drivers/of/base.c b/drivers/of/base.c index 7043acd971a0..b8f78a9e6a09 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2051,8 +2051,9 @@ 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, @target which is a pointer + * to the target device node and id_out which is a pointer + * to receive the translated ID. * * Given a device ID, look up the appropriate implementation-defined * platform ID and/or the target device which receives transactions on that @@ -2066,21 +2067,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 || (!arg->target && !arg->id_out)) return -EINVAL; =20 map =3D of_get_property(np, map_name, &map_len); if (!map) { - if (target) + if (arg->target) return -ENODEV; /* Otherwise, no map implies no translation */ - *id_out =3D id; + *arg->id_out =3D id; return 0; } =20 @@ -2122,18 +2123,18 @@ int of_map_id(const struct device_node *np, u32 id, if (!phandle_node) return -ENODEV; =20 - if (target) { - if (*target) + if (arg->target) { + if (*arg->target) of_node_put(phandle_node); else - *target =3D phandle_node; + *arg->target =3D phandle_node; =20 - if (*target !=3D phandle_node) + if (*arg->target !=3D phandle_node) continue; } =20 - if (id_out) - *id_out =3D masked_id - id_base + out_base; + if (arg->id_out) + *arg->id_out =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 +2143,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, arg->target && *arg->target ? *arg->target : NULL); =20 /* Bypasses translation */ - if (id_out) - *id_out =3D id; + if (arg->id_out) + *arg->id_out =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..7b54295e553b 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.target =3D ⌖ + arg.id_out =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..965f65ce8ad3 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.target =3D NULL; + arg.id_out =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..179f6f43a57b 100644 --- a/drivers/xen/grant-dma-ops.c +++ b/drivers/xen/grant-dma-ops.c @@ -319,9 +319,12 @@ static int xen_dt_grant_init_backend_domid(struct devi= ce *dev, =20 if (dev_is_pci(dev)) { struct pci_dev *pdev =3D to_pci_dev(dev); + struct of_map_id_arg arg =3D {}; u32 rid =3D PCI_DEVID(pdev->bus->number, pdev->devfn); =20 - if (of_map_iommu_id(np, rid, &iommu_spec.np, iommu_spec.args)) { + arg.target =3D &iommu_spec.np; + arg.id_out =3D iommu_spec.args; + if (of_map_iommu_id(np, rid, &arg)) { dev_dbg(dev, "Cannot translate ID\n"); return -ESRCH; } diff --git a/include/linux/of.h b/include/linux/of.h index 8cd486d89da2..21bdce2b37ca 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -25,6 +25,12 @@ typedef u32 phandle; typedef u32 ihandle; =20 +struct device_node; +struct of_map_id_arg { + struct device_node **target; + u32 *id_out; +}; + struct property { char *name; int length; @@ -458,7 +464,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 +913,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 +1442,20 @@ 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 { + .target =3D target, + .id_out =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 Fri Dec 19 17:53:02 2025 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 633F3335091 for ; Thu, 4 Dec 2025 09:56:02 +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=1764842164; cv=none; b=Xe3iHAWxbkiNPCgTNbLfjp3BoSgqMlYsV/KhI/mPE1zWupAcC9YquHsC65tzw/mM9awOGMsA9VrMw6HQs7Yka3c52nsciIxAf8Ks60/nBK+MV2l5CMdkNszeAXlRt9Basl65GVxto8/Rq8vc4M5POa896bW7iUAZXmAsW2pLGmk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764842164; c=relaxed/simple; bh=W5lyyNmfp6UKUuUv/Eii8aDsSFV+WQxv8+LLuHk8rYY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UPt3EjODLAxOoqU9UpIsPwIgddCy93rsFKgye2ETlVMJtFWgR3ekxH5CFvyQfWPxt2isAnafydCEf6bK+JJFZJxf+lJ3JeARDzWbBKLxMQyPQo34PkKD7jtGx/Nx3iQYthIyyL8X/XBtxnI0R/cjrRP2zIzzqxhw7DAMmV/haFc= 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=X87Q4Ckn; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=GPNW5ysQ; 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="X87Q4Ckn"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="GPNW5ysQ" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5B476Yu8516631 for ; Thu, 4 Dec 2025 09:56:01 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=JnENtJ+iZ79 uchkVcBp6bsOZyLCfXJzqxwSJpI7IA/U=; b=X87Q4Ckn8Y8TbXY0g+Yn+suSIOS ZSgoJ7vhPLWX8SOUnfPpibKdKG8PS+bfxcED8TFQDlA2q4JIDhnecLN2JZXMAvef Gy3+XDkCegnJXm9l2xtV2B1XnvLkXBbP+xjdKfPMapfj0AeWQC9UP94HU6DBpB0E qudQ2wKT/UJEw6ix1xtMiU9FQgRk9TlY/guijrP/Lvv2lNlcS2KnycHhs+WXybTN dMYORby++O+TR7toqxexTqNwisX9tHGObHx3ZFFyJ+SitUnGBOKfMDYFJ576NtyF kzrS7OPv9vQT8FJRZz7+jxPpRRRfaBjA2aHcVoXFvnagGVrfJCG2iwy1tTA== Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4au5m30jys-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 04 Dec 2025 09:56:00 +0000 (GMT) Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-7baaf371585so1190525b3a.0 for ; Thu, 04 Dec 2025 01:56:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1764842160; x=1765446960; 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=JnENtJ+iZ79uchkVcBp6bsOZyLCfXJzqxwSJpI7IA/U=; b=GPNW5ysQHKxp3JB50qGMv6sL6IqDdyThW7+/e0/UiT96m0c42NT68rSedCQsds/Y6T UGfWPs489tUjFtqEQYqU1/WCU3g8mMekcBQEXehWsmZ/OO2jK05BPK19JR9Ku6Klh7Kp /qTVkNAdFD/SmJFJ9xA1anaZ0Nmt0oXxXZtBGonxo4qE+VUY6yV3tPolUoYdcok70/xs 6scHWE4hDMoJTrjd5m+diWUoiGDmkzUuSDMjOXsy+WHjXK6oxUjL5YddPCAUBrSIeHgz 44xWoqDymx08YQbJyNFB6tkYpUBZnm8Fd7LcgpZ4wPoHwgpzEDm86hpDQ8mPVbtT6dUM AerA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764842160; x=1765446960; 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=JnENtJ+iZ79uchkVcBp6bsOZyLCfXJzqxwSJpI7IA/U=; b=BjE7G1/6AaVWxiac502H2e+S6BK55NsBJvLZuoCIazCJgNxRQwx8WKHE/bAIa7xX5s kM9uO2EIeHhqZ2sp7s+3Xhtn8v6L8ZeO5Tp9tA08MIg44nwoKwcImLRN3Jg1faQBoUTR qz9NbtU1l1waxpJjP+E4xfes0hARkEeWkP23Vl91+kEEgN4F3ju/AflzvbKtZwtZjz0t CGKlYzmtFduZHexQk7SwSxO1sdgUtZOvUSYjFgByeIAz9jbUD5ypWiKv73cNLHs3JjhC bl7AfxOf0r7shp25fGsNu/Dkt7S/AV1UAjjzjKGXJIgc7A2jQpXSDBVOYvxHrsgL6E9M yeug== X-Forwarded-Encrypted: i=1; AJvYcCXCDsr93HFEsuQPBa81vHiwS/RNTBRG52L9aNYLUC3RQOCiVQs8y1o3IO6oAgXsvtxGJ65rdgKNG19/wWo=@vger.kernel.org X-Gm-Message-State: AOJu0YyEEwKJXIQBdrbcrScoqb32aswLeOJnXTxW30ucoTmhpIGwexly wemkefbDTLQcAj6wk6D3HqCmPw8erzT/WjUvxBO11GHzmSVtl6aVf5yCb4EvmT9BrExIIl8CieF 9ZMU4F93ei2Bscv6M+B2ZyCC5Dsfgknk0ul6lCc0h+SuuIK/d6MovMKiYZEWw7FjrbUM= X-Gm-Gg: ASbGncsjJIKLK2a0sT1pCoZln+1ubMM6aq44WdZPKT3bF0Q7+6fiILbqeG6r8GAVfcr 1j9Gcosfpx16CGqcxcWHwSdV0Hm24Zqmy0OUQNc5vrHOQFnhKZbmCJyCbyvEGmdkn1r4L4WHH0M wClNYYkzmluo03JTBYkkmvEZgbuL79c8X9SeA7lSHrKw6saKwr4prIuUlq6fN1N0R4uVk5pmV8Q 75QmpgDFXKHJvOLBiPm5GG8zNobm2UWo/rOqgxqeiLMkPOvdwlj79GNOfkbs1kBVDmmKJD0/gRQ dFGmbfRBW8gzh9r0ICrnS1m9T5UyipRY9w2usmDQmRZ1JDcEiHRHFckW/oBCZYCzHSGnnt0dZL6 5AADmxidk03EhJbzqO1IMSGI24xKh3DFt9YewmZauzvqc X-Received: by 2002:a05:6a20:9194:b0:35d:7f01:676e with SMTP id adf61e73a8af0-36403377aacmr3512848637.28.1764842159960; Thu, 04 Dec 2025 01:55:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IFAVOEGXDdRdUDtAq8q+67DZiWaMBd8MEEIViFxr3XA9wPBlJn9bcZYZSOW03hDspNS7NqXIA== X-Received: by 2002:a05:6a20:9194:b0:35d:7f01:676e with SMTP id adf61e73a8af0-36403377aacmr3512834637.28.1764842159446; Thu, 04 Dec 2025 01:55:59 -0800 (PST) Received: from hu-vjitta-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-bf6817389fdsm1380436a12.1.2025.12.04.01.55.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Dec 2025 01:55:59 -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, charan.kalla@oss.qualcomm.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@oss.qualcomm.com Subject: [PATCH v2 3/3] of: Respect #{iommu,msi}-cells in maps Date: Thu, 4 Dec 2025 15:25:30 +0530 Message-Id: <20251204095530.8627-4-vijayanand.jitta@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251204095530.8627-1-vijayanand.jitta@oss.qualcomm.com> References: <20251204095530.8627-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: rtZ6ZeOuN7Oau1RGLb4QPUskmIdhEUxn X-Proofpoint-ORIG-GUID: rtZ6ZeOuN7Oau1RGLb4QPUskmIdhEUxn X-Authority-Analysis: v=2.4 cv=esHSD4pX c=1 sm=1 tr=0 ts=69315ab1 cx=c_pps a=m5Vt/hrsBiPMCU0y4gIsQw==: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=IoOABgeZipijB_acs4fv:22 a=a-qgeE7W1pNrGK8U0ZQC:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMjA0MDA4MSBTYWx0ZWRfX9pVpxpq7Ekt5 ZETX6648M3x9JrepJNCd7QAdC2v9it6YWxCAFXAnA4j9I37EVOPYuPgAawv3insOjeXyptMdKBX hBrZab8jIVZV/9Ws+2LNoe8UiI3LhO+YzodvIaPWwbiq8x2yMdsrmOnPvfJ3ONYjBwxzG9BmkqU xxapGvZXggivHHC05g9+8Gb4w730GeKMm4dN5ix3M6R570jQB2UBlJ74v56UbBYOdnS/B5z+kEH 55HpkXtZzeDx39KbjRv7qfDDQKBxoe1aEKoMBPcF1W5ckihbCXYKBvZIwhhi2LFR01e9M/Rs1dF 8ibh9LyS4JHB1sp7YuhTZY0P5K0Vnyhig4pqiiTVHOkI12TYAYJjCwW8tMdoLXblEloJXcAnaCI WId/wCKdUqaO8tQTSCC5Z7Cnk5cUdQ== 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-04_02,2025-12-03_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1011 adultscore=0 malwarescore=0 suspectscore=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2510240001 definitions=main-2512040081 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 | 3 +- drivers/of/base.c | 107 ++++++++++++++++++++++++++++++--------- include/linux/of.h | 17 ++++--- 3 files changed, 94 insertions(+), 33 deletions(-) diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index eac62bc441c5..48759cf1d900 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -45,10 +45,11 @@ 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 {}; struct of_map_id_arg arg =3D { .target =3D &iommu_spec.np, .id_out =3D iommu_spec.args, + .map_cells =3D &iommu_spec.args_count, }; int err; =20 diff --git a/drivers/of/base.c b/drivers/of/base.c index b8f78a9e6a09..68a7d6ddba66 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2045,11 +2045,30 @@ 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 length =3D=3D 1 + * entries with the same target, so check for that pattern. + */ +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, @target which is a pointer * to the target device node and id_out which is a pointer @@ -2065,18 +2084,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 || (!arg->target && !arg->id_out)) 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->target) return -ENODEV; @@ -2085,11 +2105,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; @@ -2102,27 +2120,62 @@ 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, cells, id_len, id_off; + const __be32 *out_base; + + if (map_len - offset < 2) + goto err_map_len; =20 + id_base =3D be32_to_cpup(map + offset); 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; - + 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->target) { if (*arg->target) of_node_put(phandle_node); @@ -2133,12 +2186,14 @@ int of_map_id(const struct device_node *np, u32 id, continue; } =20 - if (arg->id_out) - *arg->id_out =3D masked_id - id_base + out_base; + for (int i =3D 0; arg->id_out && i < cells; i++) + arg->id_out[i] =3D id_off + be32_to_cpu(out_base[i]); =20 + if (arg->map_cells) + *arg->map_cells =3D cells; 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 @@ -2149,5 +2204,9 @@ int of_map_id(const struct device_node *np, u32 id, if (arg->id_out) *arg->id_out =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 21bdce2b37ca..1981509c7918 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -29,6 +29,7 @@ struct device_node; struct of_map_id_arg { struct device_node **target; u32 *id_out; + u32 *map_cells; }; =20 struct property { @@ -462,9 +463,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 @@ -911,9 +912,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; } @@ -1444,7 +1445,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, @@ -1455,7 +1456,7 @@ static inline int of_map_msi_id(const struct device_n= ode *np, u32 id, .id_out =3D id_out, }; =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