From: Charan Teja Kalla <charan.kalla@oss.qualcomm.com>
To: Robin Murphy <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
Subject: Re: [PATCH 0/6] of: iommu-map parsing for multi-cell IOMMU
Date: Fri, 21 Nov 2025 11:24:07 +0530 [thread overview]
Message-ID: <74c2bdbe-1346-4229-b9dd-694b3063b1bb@oss.qualcomm.com> (raw)
In-Reply-To: <e6fb7000-7aac-45b6-b4f9-c9efa2a98d57@oss.qualcomm.com>
On 11/12/2025 8:12 PM, Charan Teja Kalla wrote:
> Hi Robin,
>
> Don't want to bother you with my ideas, but I can't think of other ways
> to handle such cases of multi-map than the below. I just tried this code on
> Qemu on top of your patches(with some nit compilation fixes) and just checked
> if devices are added to the iommu groups.
>
Hello Robin,
Not sure If this is early to ask for feedback, but waiting for your
valuable inputs here. Thanks in advance.
> ----------------------8888---------------------------------------------
>
> diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c
> index a511ecf21fcd..ac005e70de7d 100644
> --- a/drivers/iommu/of_iommu.c
> +++ b/drivers/iommu/of_iommu.c
> @@ -16,6 +16,7 @@
> #include <linux/pci.h>
> #include <linux/slab.h>
> #include <linux/fsl/mc.h>
> +#include <linux/platform_device.h>
>
> #include "iommu-priv.h"
>
> @@ -41,6 +42,18 @@ static int of_iommu_xlate(struct device *dev,
> return ret;
> }
>
> +static int of_iommu_configure_cb(void *arg, u32 *id_out)
> +{
> + struct of_phandle_args *iommu_spec =
> + (struct of_phandle_args *)((void *)id_out - offsetof(struct of_phandle_args, args));
> + struct device *dev = arg;
> + int err;
> +
> + err = of_iommu_xlate(dev, iommu_spec);
> + of_node_put(iommu_spec->np);
> + return err;
> +}
> +
> static int of_iommu_configure_dev_id(struct device_node *master_np,
> struct device *dev,
> const u32 *id)
> @@ -48,12 +61,10 @@ static int of_iommu_configure_dev_id(struct device_node *master_np,
> struct of_phandle_args iommu_spec = { .args_count = 1 };
> int err;
>
> - err = of_map_iommu_id(master_np, *id, &iommu_spec.np, iommu_spec.args);
> + err = of_map_iommu_id(master_np, *id, &iommu_spec.np, iommu_spec.args,
> + dev_is_platform(dev) ? true : false, dev, of_iommu_configure_cb);
> - if (err)
> - return err;
> -
> - err = of_iommu_xlate(dev, &iommu_spec);
> - of_node_put(iommu_spec.np);
> return err;
> }
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index a4fd4a4f720b..8abe36c17309 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -2085,16 +2085,21 @@ static bool of_check_bad_map(const __be32 *map, int len)
> */
> 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 device_node **target, u32 *id_out)
> + struct device_node **target, u32 *id_out, bool multi_map,
> + void *arg, of_map_id_cb cb)
> {
> u32 map_mask, masked_id;
> int map_bytes, map_len, offset = 0;
> bool bad_map = false;
> const __be32 *map = NULL;
> + bool mapped_multi_id = false;
>
> if (!np || !map_name || !cells_name || (!target && !id_out))
> return -EINVAL;
>
> + if (multi_map && !cb)
> + return -EINVAL;
> +
> map = of_get_property(np, map_name, &map_bytes);
> if (!map) {
> if (target)
> @@ -2189,16 +2194,29 @@ int of_map_id(const struct device_node *np, u32 id, const char *map_name,
> 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, be32_to_cpup(out_base),
> id_len, id, id_off + be32_to_cpup(out_base));
> - return 0;
> +
> + if (multi_map) {
> + if (cb(arg, id_out))
> + return -EINVAL;
> +
> + mapped_multi_id = true;
> + continue;
> + }
> +
> + goto translated;
> }
>
> + if (mapped_multi_id)
> + return 0;
> +
> pr_info("%pOF: no %s translation for id 0x%x on %pOF\n", np, map_name,
> id, target && *target ? *target : NULL);
>
> /* Bypasses translation */
> if (id_out)
> *id_out = id;
> - return 0;
> +translated:
> + return cb ? cb(arg, id_out) : 0;
>
> err_map_len:
> pr_err("%pOF: Error: Bad %s length: %d\n", np, map_name, map_bytes);
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 183be897b088..84a24c2a1041 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -24,6 +24,7 @@
>
> typedef u32 phandle;
> typedef u32 ihandle;
> +typedef int (*of_map_id_cb)(void *arg, u32 *id_out);
>
> struct property {
> char *name;
> @@ -458,7 +459,8 @@ 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 *cells_name, const char *map_mask_name,
> - struct device_node **target, u32 *id_out);
> + struct device_node **target, u32 *id_out,
> + bool multi_map, void *arg, of_map_id_cb cb);
>
> phys_addr_t of_dma_get_max_cpu_address(struct device_node *np);
>
> @@ -1436,17 +1438,18 @@ 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 device_node **target, u32 *id_out,
> + bool multi_map, void *arg, of_map_id_cb cb)
> {
> return of_map_id(np, id, "iommu-map", "#iommu-cells", "iommu-map-mask",
> - target, id_out);
> + target, id_out, multi_map, arg, cb);
> }
>
> 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-cells", "msi-map-mask",
> - target, id_out);
> + target, id_out, false, NULL, NULL);
> }
>
> #define of_for_each_phandle(it, err, np, ln, cn, cc)
> -----------------------------------------------------------------------
>
> full patch is at: https://github.com/charan-kalla-oss/linux-next/commits/refs/for/iommu_map
next prev parent reply other threads:[~2025-11-21 5:54 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-04 8:50 Charan Teja Kalla
2025-11-04 8:51 ` [PATCH 1/6] of: create a wrapper for of_map_id() Charan Teja Kalla
2025-11-04 8:51 ` [PATCH 2/6] of: introduce wrapper function to query the cell count Charan Teja Kalla
2025-11-05 17:35 ` Robin Murphy
2025-11-04 8:51 ` [PATCH 3/6] of: parse #<name>-cells property to get " Charan Teja Kalla
2025-11-04 8:51 ` [PATCH 4/6] of: detect and handle legacy iommu-map parsing Charan Teja Kalla
2025-11-04 8:51 ` [PATCH 5/6] of: add infra to parse iommu-map per IOMMU cell count Charan Teja Kalla
2025-11-04 10:46 ` kernel test robot
2025-11-04 10:57 ` Charan Teja Kalla
2025-11-04 13:02 ` kernel test robot
2025-11-06 15:03 ` Dan Carpenter
2025-11-04 8:51 ` [PATCH 6/6] of: use correct iommu-map parsing logic from of_iommu layer Charan Teja Kalla
2025-11-05 18:20 ` Robin Murphy
2025-11-05 17:28 ` [PATCH 0/6] of: iommu-map parsing for multi-cell IOMMU Robin Murphy
2025-11-11 18:27 ` Charan Teja Kalla
2025-11-12 14:42 ` Charan Teja Kalla
2025-11-21 5:54 ` Charan Teja Kalla [this message]
2025-11-24 16:42 ` Robin Murphy
2025-11-24 16:51 ` Robin Murphy
2025-11-26 17:30 ` Charan Teja Kalla
2025-11-07 8:07 ` Krzysztof Kozlowski
2025-11-11 18:45 ` Charan Teja Kalla
2025-11-11 20:39 ` Rob Herring
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=74c2bdbe-1346-4229-b9dd-694b3063b1bb@oss.qualcomm.com \
--to=charan.kalla@oss.qualcomm.com \
--cc=bjorn.andersson@oss.qualcomm.com \
--cc=bod@kernel.org \
--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=saravanak@google.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
all inboxes | Powered by JetHome®