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 struct device_node *prev = NULL;
32 int levels = 0, leaves = 0, level;
34 if (of_property_read_bool(np, "cache-size"))
36 if (of_property_read_bool(np, "i-cache-size"))
38 if (of_property_read_bool(np, "d-cache-size"))
44 while ((np = of_find_next_cache_node(np))) {
47 if (!of_device_is_compatible(np, "cache"))
49 if (of_property_read_u32(np, "cache-level", &level))
53 if (of_property_read_bool(np, "cache-size"))
55 if (of_property_read_bool(np, "i-cache-size"))
57 if (of_property_read_bool(np, "d-cache-size"))
63 this_cpu_ci->num_levels = levels;
64 this_cpu_ci->num_leaves = leaves;
69 static int __populate_cache_leaves(unsigned int cpu)
71 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
72 struct cacheinfo *this_leaf = this_cpu_ci->info_list;
73 struct device_node *np = of_cpu_device_node_get(cpu);
74 struct device_node *prev = NULL;
75 int levels = 1, level = 1;
77 if (of_property_read_bool(np, "cache-size"))
78 ci_leaf_init(this_leaf++, np, CACHE_TYPE_UNIFIED, level);
79 if (of_property_read_bool(np, "i-cache-size"))
80 ci_leaf_init(this_leaf++, np, CACHE_TYPE_INST, level);
81 if (of_property_read_bool(np, "d-cache-size"))
82 ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level);
85 while ((np = of_find_next_cache_node(np))) {
88 if (!of_device_is_compatible(np, "cache"))
90 if (of_property_read_u32(np, "cache-level", &level))
94 if (of_property_read_bool(np, "cache-size"))
95 ci_leaf_init(this_leaf++, np, CACHE_TYPE_UNIFIED, level);
96 if (of_property_read_bool(np, "i-cache-size"))
97 ci_leaf_init(this_leaf++, np, CACHE_TYPE_INST, level);
98 if (of_property_read_bool(np, "d-cache-size"))
99 ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level);
107 DEFINE_SMP_CALL_CACHE_FUNCTION(init_cache_level)
108 DEFINE_SMP_CALL_CACHE_FUNCTION(populate_cache_leaves)