1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2017 SiFive
6 #include <linux/cacheinfo.h>
9 #include <linux/of_device.h>
11 static void ci_leaf_init(struct cacheinfo *this_leaf,
12 struct device_node *node,
13 enum cache_type type, unsigned int level)
15 this_leaf->level = level;
16 this_leaf->type = type;
19 static int __init_cache_level(unsigned int cpu)
21 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
22 struct device_node *np = of_cpu_device_node_get(cpu);
23 struct device_node *prev = NULL;
24 int levels = 0, leaves = 0, level;
26 if (of_property_read_bool(np, "cache-size"))
28 if (of_property_read_bool(np, "i-cache-size"))
30 if (of_property_read_bool(np, "d-cache-size"))
36 while ((np = of_find_next_cache_node(np))) {
39 if (!of_device_is_compatible(np, "cache"))
41 if (of_property_read_u32(np, "cache-level", &level))
45 if (of_property_read_bool(np, "cache-size"))
47 if (of_property_read_bool(np, "i-cache-size"))
49 if (of_property_read_bool(np, "d-cache-size"))
55 this_cpu_ci->num_levels = levels;
56 this_cpu_ci->num_leaves = leaves;
61 static int __populate_cache_leaves(unsigned int cpu)
63 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
64 struct cacheinfo *this_leaf = this_cpu_ci->info_list;
65 struct device_node *np = of_cpu_device_node_get(cpu);
66 struct device_node *prev = NULL;
67 int levels = 1, level = 1;
69 if (of_property_read_bool(np, "cache-size"))
70 ci_leaf_init(this_leaf++, np, CACHE_TYPE_UNIFIED, level);
71 if (of_property_read_bool(np, "i-cache-size"))
72 ci_leaf_init(this_leaf++, np, CACHE_TYPE_INST, level);
73 if (of_property_read_bool(np, "d-cache-size"))
74 ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level);
77 while ((np = of_find_next_cache_node(np))) {
80 if (!of_device_is_compatible(np, "cache"))
82 if (of_property_read_u32(np, "cache-level", &level))
86 if (of_property_read_bool(np, "cache-size"))
87 ci_leaf_init(this_leaf++, np, CACHE_TYPE_UNIFIED, level);
88 if (of_property_read_bool(np, "i-cache-size"))
89 ci_leaf_init(this_leaf++, np, CACHE_TYPE_INST, level);
90 if (of_property_read_bool(np, "d-cache-size"))
91 ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level);
99 DEFINE_SMP_CALL_CACHE_FUNCTION(init_cache_level)
100 DEFINE_SMP_CALL_CACHE_FUNCTION(populate_cache_leaves)