summaryrefslogtreecommitdiff
path: root/drivers/of/base.c
diff options
context:
space:
mode:
authorRob Herring <robh@kernel.org>2021-10-06 11:43:21 -0500
committerRob Herring <robh@kernel.org>2021-10-20 13:36:16 -0500
commit795e92ec5fd79027648bd7f779d34bad5b6f2f55 (patch)
tree7ed34ab33981d96f3527ec4b5a49fbc7c08d544c /drivers/of/base.c
parent378be0cca602cbee8aa441a14f836e9e41e25314 (diff)
downloadlwn-795e92ec5fd79027648bd7f779d34bad5b6f2f55.tar.gz
lwn-795e92ec5fd79027648bd7f779d34bad5b6f2f55.zip
of: Add of_get_cpu_hwid() to read hardware ID from CPU nodes
There are various open coded implementions parsing the CPU node 'reg' property which contains the CPU's hardware ID. Introduce a new function, of_get_cpu_hwid(), to read the hardware ID. All the callers should be DT only code, so no need for an empty function. Cc: Frank Rowand <frowand.list@gmail.com> Signed-off-by: Rob Herring <robh@kernel.org> Tested-by: Florian Fainelli <f.fainelli@gmail.com> Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> Link: https://lore.kernel.org/r/20211006164332.1981454-2-robh@kernel.org
Diffstat (limited to 'drivers/of/base.c')
-rw-r--r--drivers/of/base.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index f720c0d246f2..e587ab44be22 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -286,6 +286,28 @@ const void *of_get_property(const struct device_node *np, const char *name,
}
EXPORT_SYMBOL(of_get_property);
+/**
+ * of_get_cpu_hwid - Get the hardware ID from a CPU device node
+ *
+ * @cpun: CPU number(logical index) for which device node is required
+ * @thread: The local thread number to get the hardware ID for.
+ *
+ * Return: The hardware ID for the CPU node or ~0ULL if not found.
+ */
+u64 of_get_cpu_hwid(struct device_node *cpun, unsigned int thread)
+{
+ const __be32 *cell;
+ int ac, len;
+
+ ac = of_n_addr_cells(cpun);
+ cell = of_get_property(cpun, "reg", &len);
+ if (!cell || !ac || ((sizeof(*cell) * ac * (thread + 1)) > len))
+ return ~0ULL;
+
+ cell += ac * thread;
+ return of_read_number(cell, ac);
+}
+
/*
* arch_match_cpu_phys_id - Match the given logical CPU and physical id
*