From: Charan Teja Kalla <charan.kalla@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,
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 <charan.kalla@oss.qualcomm.com>
Subject: [PATCH 3/6] of: parse #<name>-cells property to get the cell count
Date: Tue, 4 Nov 2025 14:21:02 +0530 [thread overview]
Message-ID: <d2caaf822fde3565e4e67158da751fc97afbaa92.1762235099.git.charan.kalla@oss.qualcomm.com> (raw)
In-Reply-To: <cover.1762235099.git.charan.kalla@oss.qualcomm.com>
Implement the generic function, of_map_id_cell_count(), that can
parse and return the number of cells represented by #<name>-cells,
eg: #msi-cells, #iommu-cells.
Since the second argument of a property that is parsed by the
of_map_id() is always phandle, that represents a controller, probe
it to get the #<name>-cells property.
Further patches properly consume cell count value returned by this
wrapper and this patch just returns 1 irrespective of cells value, thus
no functional changes.
Signed-off-by: Charan Teja Kalla <charan.kalla@oss.qualcomm.com>
---
drivers/of/base.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 5e76abcc7940..e5ba8a318769 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2045,9 +2045,43 @@ int of_find_last_cache_level(unsigned int cpu)
return cache_level;
}
+/**
+ * of_map_id_cell_count - parse the cell count.
+ *
+ * @map: pointer to the property data that needs to be translated, eg: msi-map/iommu-map.
+ * @map_name: name to identify the details of @map.
+ * @map_len: length of @map in bytes.
+ *
+ * Return: number of cells that the caller should be considered while parsing
+ * the @map. It is > 0 for success, 0 for failure.
+ */
static int of_map_id_cell_count(const __be32 *map, const char *map_name,
int map_len)
{
+ const char *cells_prop_name __free(kfree) = NULL;
+ struct device_node *node __free(device_node) = NULL;
+ u32 cells;
+ int ret;
+
+ /* map + 1 is a controller. */
+ node = of_find_node_by_phandle(be32_to_cpup(map + 1));
+ if (!node) {
+ pr_err("Failed to find controller node from phandle\n");
+ return 0;
+ }
+
+ /* get #<name>-cells property from #<name>-map */
+ cells_prop_name = kasprintf(GFP_KERNEL, "#%.*scells",
+ (int)strlen(map_name) - 3, map_name);
+ if (!cells_prop_name)
+ return 0;
+
+ ret = of_property_read_u32(node, cells_prop_name, &cells);
+ if (ret) {
+ pr_err("%pOF: Failed to read %s property\n", node, cells_prop_name);
+ return 0;
+ }
+
return 1;
}
--
2.34.1
next prev parent reply other threads:[~2025-11-04 8:51 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-04 8:50 [PATCH 0/6] of: iommu-map parsing for multi-cell IOMMU 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 ` Charan Teja Kalla [this message]
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
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=d2caaf822fde3565e4e67158da751fc97afbaa92.1762235099.git.charan.kalla@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®