2 * Copyright (C) 2017 SiFive
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <linux/cacheinfo.h>
15 #include <linux/cpu.h>
17 #include <linux/of_device.h>
19 static void ci_leaf_init(struct cacheinfo *this_leaf,
20 struct device_node *node,
21 enum cache_type type, unsigned int level)
23 this_leaf->level = level;
24 this_leaf->type = type;
27 static int __init_cache_level(unsigned int cpu)
29 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
30 struct device_node *np = of_cpu_device_node_get(cpu);
31 int levels = 0, leaves = 0, level;
33 if (of_property_read_bool(np, "cache-size"))
35 if (of_property_read_bool(np, "i-cache-size"))
37 if (of_property_read_bool(np, "d-cache-size"))
42 while ((np = of_find_next_cache_node(np))) {
43 if (!of_device_is_compatible(np, "cache"))
45 if (of_property_read_u32(np, "cache-level", &level))
49 if (of_property_read_bool(np, "cache-size"))
51 if (of_property_read_bool(np, "i-cache-size"))
53 if (of_property_read_bool(np, "d-cache-size"))
58 this_cpu_ci->num_levels = levels;
59 this_cpu_ci->num_leaves = leaves;
63 static int __populate_cache_leaves(unsigned int cpu)
65 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
66 struct cacheinfo *this_leaf = this_cpu_ci->info_list;
67 struct device_node *np = of_cpu_device_node_get(cpu);
68 int levels = 1, level = 1;
70 if (of_property_read_bool(np, "cache-size"))
71 ci_leaf_init(this_leaf++, np, CACHE_TYPE_UNIFIED, level);
72 if (of_property_read_bool(np, "i-cache-size"))
73 ci_leaf_init(this_leaf++, np, CACHE_TYPE_INST, level);
74 if (of_property_read_bool(np, "d-cache-size"))
75 ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level);
77 while ((np = of_find_next_cache_node(np))) {
78 if (!of_device_is_compatible(np, "cache"))
80 if (of_property_read_u32(np, "cache-level", &level))
84 if (of_property_read_bool(np, "cache-size"))
85 ci_leaf_init(this_leaf++, np, CACHE_TYPE_UNIFIED, level);
86 if (of_property_read_bool(np, "i-cache-size"))
87 ci_leaf_init(this_leaf++, np, CACHE_TYPE_INST, level);
88 if (of_property_read_bool(np, "d-cache-size"))
89 ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level);
96 DEFINE_SMP_CALL_CACHE_FUNCTION(init_cache_level)
97 DEFINE_SMP_CALL_CACHE_FUNCTION(populate_cache_leaves)