From: Vijayanand Jitta <vijayanand.jitta@oss.qualcomm.com>
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 [thread overview]
Message-ID: <20251204095530.8627-3-vijayanand.jitta@oss.qualcomm.com> (raw)
In-Reply-To: <20251204095530.8627-1-vijayanand.jitta@oss.qualcomm.com>
From: Charan Teja Kalla <charan.kalla@oss.qualcomm.com>
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 <charan.kalla@oss.qualcomm.com>
Signed-off-by: Vijayanand Jitta <vijayanand.jitta@oss.qualcomm.com>
---
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 = { .args_count = 1 };
+ struct of_map_id_arg arg = {
+ .target = &iommu_spec.np,
+ .id_out = iommu_spec.args,
+ };
int err;
- err = of_map_iommu_id(master_np, *id, &iommu_spec.np, iommu_spec.args);
+ err = of_map_iommu_id(master_np, *id, &arg);
if (err)
return err;
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 = NULL;
- if (!np || !map_name || (!target && !id_out))
+ if (!np || !map_name || !arg || (!arg->target && !arg->id_out))
return -EINVAL;
map = 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 = id;
+ *arg->id_out = id;
return 0;
}
@@ -2122,18 +2123,18 @@ int of_map_id(const struct device_node *np, u32 id,
if (!phandle_node)
return -ENODEV;
- if (target) {
- if (*target)
+ if (arg->target) {
+ if (*arg->target)
of_node_put(phandle_node);
else
- *target = phandle_node;
+ *arg->target = phandle_node;
- if (*target != phandle_node)
+ if (*arg->target != phandle_node)
continue;
}
- if (id_out)
- *id_out = masked_id - id_base + out_base;
+ if (arg->id_out)
+ *arg->id_out = masked_id - id_base + out_base;
pr_debug("%pOF: %s, using mask %08x, id-base: %08x, out-base: %08x, length: %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,
}
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);
/* Bypasses translation */
- if (id_out)
- *id_out = id;
+ if (arg->id_out)
+ *arg->id_out = 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 = imx_pcie->pci->dev;
struct device_node *target;
+ struct of_map_id_arg arg = {};
u32 sid_i, sid_m;
int err_i, err_m;
u32 sid = 0;
target = NULL;
- err_i = of_map_iommu_id(dev->of_node, rid, &target, &sid_i);
+
+ arg.target = ⌖
+ arg.id_out = &sid_i;
+ err_i = 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/pcie-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_bridge *bridge, struct pci_d
{
u32 sid, rid = pci_dev_id(pdev);
struct apple_pcie_port *port;
+ struct of_map_id_arg arg = {};
int idx, err;
port = apple_pcie_get_port(pdev);
@@ -791,7 +792,9 @@ static int apple_pcie_enable_device(struct pci_host_bridge *bridge, struct pci_d
dev_dbg(&pdev->dev, "added to bus %s, index %d\n",
pci_name(pdev->bus->self), port->idx);
- err = of_map_iommu_id(port->pcie->dev->of_node, rid, NULL, &sid);
+ arg.target = NULL;
+ arg.id_out = &sid;
+ err = of_map_iommu_id(port->pcie->dev->of_node, rid, &arg);
if (err)
return err;
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 device *dev,
if (dev_is_pci(dev)) {
struct pci_dev *pdev = to_pci_dev(dev);
+ struct of_map_id_arg arg = {};
u32 rid = PCI_DEVID(pdev->bus->number, pdev->devfn);
- if (of_map_iommu_id(np, rid, &iommu_spec.np, iommu_spec.args)) {
+ arg.target = &iommu_spec.np;
+ arg.id_out = 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;
+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, char *name, int index);
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);
phys_addr_t of_dma_get_max_cpu_address(struct device_node *np);
@@ -907,7 +913,7 @@ static inline void of_property_clear_flag(struct property *p, unsigned long flag
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,
}
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);
}
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 = {
+ .target = target,
+ .id_out = id_out,
+ };
+
+ return of_map_id(np, id, "msi-map", "msi-map-mask", &arg);
}
#define of_for_each_phandle(it, err, np, ln, cn, cc) \
--
2.34.1
next prev parent reply other threads:[~2025-12-04 9:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-04 9:55 [PATCH v2 0/3] of: parsing of multi #{iommu,msi}-cells in maps Vijayanand Jitta
2025-12-04 9:55 ` [PATCH v2 1/3] of: Add convenience wrappers for of_map_id() Vijayanand Jitta
2025-12-09 19:59 ` Rob Herring (Arm)
2025-12-04 9:55 ` Vijayanand Jitta [this message]
2025-12-05 16:47 ` [PATCH v2 2/3] of: factor arguments passed to of_map_id() into a struct Dmitry Baryshkov
2025-12-08 13:40 ` Vijayanand Jitta
2025-12-09 20:02 ` Rob Herring
2025-12-10 10:29 ` Vijayanand Jitta
2025-12-04 9:55 ` [PATCH v2 3/3] of: Respect #{iommu,msi}-cells in maps Vijayanand Jitta
2025-12-05 3:28 ` kernel test robot
2025-12-05 4:01 ` kernel test robot
2025-12-05 4:33 ` kernel test robot
2025-12-09 20:17 ` Rob Herring
2025-12-10 10:27 ` Vijayanand Jitta
2025-12-10 21:04 ` Rob Herring
2025-12-11 5:31 ` Vijayanand Jitta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251204095530.8627-3-vijayanand.jitta@oss.qualcomm.com \
--to=vijayanand.jitta@oss.qualcomm.com \
--cc=bjorn.andersson@oss.qualcomm.com \
--cc=bod@kernel.org \
--cc=charan.kalla@oss.qualcomm.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=prakash.gupta@oss.qualcomm.com \
--cc=robh@kernel.org \
--cc=robin.murphy@arm.com \
--cc=vikash.garodia@oss.qualcomm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).