[PATCH v2 7/8] of: base: add support to get the device node for the CPU's last level cache
Sudeep Holla
sudeep.holla at arm.com
Wed May 18 02:33:24 PDT 2022
It is useful to have helper function just to get the pointer to the device
node of the last level cache for a given logical cpu. It can be used as
unique firmware identifier for the last level cache.
This is useful to obtain the cpumask/cpumap of all the CPUs sharing the last
level cache using the device node pointer as unique identifier for the last
level cache.
Cc: Rob Herring <robh+dt at kernel.org>
Signed-off-by: Sudeep Holla <sudeep.holla at arm.com>
---
drivers/of/base.c | 33 +++++++++++++++++++++++++--------
include/linux/of.h | 1 +
2 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index d4f98c8469ed..0b6a8c3f9a85 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2072,17 +2072,17 @@ struct device_node *of_find_next_cache_node(const struct device_node *np)
}
/**
- * of_find_last_cache_level - Find the level at which the last cache is
- * present for the given logical cpu
+ * of_find_last_level_cache_node - Find the device node at which the last
+ * cache is present for the given logical cpu
*
- * @cpu: cpu number(logical index) for which the last cache level is needed
+ * @cpu: cpu number(logical index) for which the last cache level's device
+ * node is needed
*
- * Return: The the level at which the last cache is present. It is exactly
- * same as the total number of cache levels for the given logical cpu.
+ * Return: The device node corresponding to the last cache for the given
+ * logical cpu
*/
-int of_find_last_cache_level(unsigned int cpu)
+struct device_node *of_find_last_level_cache_node(unsigned int cpu)
{
- u32 cache_level = 0;
struct device_node *prev = NULL, *np = of_cpu_device_node_get(cpu);
while (np) {
@@ -2091,7 +2091,24 @@ int of_find_last_cache_level(unsigned int cpu)
np = of_find_next_cache_node(np);
}
- of_property_read_u32(prev, "cache-level", &cache_level);
+ return prev;
+}
+
+/**
+ * of_find_last_cache_level - Find the level at which the last cache is
+ * present for the given logical cpu
+ *
+ * @cpu: cpu number(logical index) for which the last cache level is needed
+ *
+ * Return: The level at which the last cache is present. It is exactly
+ * same as the total number of cache levels for the given logical cpu.
+ */
+int of_find_last_cache_level(unsigned int cpu)
+{
+ u32 cache_level = 0;
+ struct device_node *np = of_find_last_level_cache_node(cpu);
+
+ of_property_read_u32(np, "cache-level", &cache_level);
return cache_level;
}
diff --git a/include/linux/of.h b/include/linux/of.h
index 04971e85fbc9..ca0384cf08a3 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -297,6 +297,7 @@ extern struct device_node *of_get_child_by_name(const struct device_node *node,
/* cache lookup */
extern struct device_node *of_find_next_cache_node(const struct device_node *);
+extern struct device_node *of_find_last_level_cache_node(unsigned int cpu);
extern int of_find_last_cache_level(unsigned int cpu);
extern struct device_node *of_find_node_with_property(
struct device_node *from, const char *prop_name);
--
2.36.1
More information about the linux-riscv
mailing list