Skip to content

Commit 5fa2353

Browse files
sudeep-hollawildea01
authored andcommitted
of: base: add support to find the level of the last cache
It is useful to have helper function just to get the number of cache levels for a given logical cpu. We can obtain the same by just checking the level at which the last cache is present. This patch adds support to find the level of the last cache for a given cpu. It will be used on ARM64 platform where the device tree provides the information for the additional non-architected/transparent/external last level caches that are not integrated with the processors. Cc: Mark Rutland <mark.rutland@arm.com> Suggested-by: Rob Herring <robh+dt@kernel.org> Acked-by: Rob Herring <robh+dt@kernel.org> Tested-by: Tan Xiaojun <tanxiaojun@huawei.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com> [will: use u32 instead of int for cache_level] Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent fa5ce3d commit 5fa2353

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

drivers/of/base.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/cpu.h>
2626
#include <linux/module.h>
2727
#include <linux/of.h>
28+
#include <linux/of_device.h>
2829
#include <linux/of_graph.h>
2930
#include <linux/spinlock.h>
3031
#include <linux/slab.h>
@@ -2267,6 +2268,31 @@ struct device_node *of_find_next_cache_node(const struct device_node *np)
22672268
return NULL;
22682269
}
22692270

2271+
/**
2272+
* of_find_last_cache_level - Find the level at which the last cache is
2273+
* present for the given logical cpu
2274+
*
2275+
* @cpu: cpu number(logical index) for which the last cache level is needed
2276+
*
2277+
* Returns the the level at which the last cache is present. It is exactly
2278+
* same as the total number of cache levels for the given logical cpu.
2279+
*/
2280+
int of_find_last_cache_level(unsigned int cpu)
2281+
{
2282+
u32 cache_level = 0;
2283+
struct device_node *prev = NULL, *np = of_cpu_device_node_get(cpu);
2284+
2285+
while (np) {
2286+
prev = np;
2287+
of_node_put(np);
2288+
np = of_find_next_cache_node(np);
2289+
}
2290+
2291+
of_property_read_u32(prev, "cache-level", &cache_level);
2292+
2293+
return cache_level;
2294+
}
2295+
22702296
/**
22712297
* of_graph_parse_endpoint() - parse common endpoint node properties
22722298
* @node: pointer to endpoint device_node

include/linux/of.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ extern struct device_node *of_get_child_by_name(const struct device_node *node,
280280

281281
/* cache lookup */
282282
extern struct device_node *of_find_next_cache_node(const struct device_node *);
283+
extern int of_find_last_cache_level(unsigned int cpu);
283284
extern struct device_node *of_find_node_with_property(
284285
struct device_node *from, const char *prop_name);
285286

0 commit comments

Comments
 (0)