2 * MIPS cacheinfo support
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
9 * kind, whether express or implied; without even the implied warranty
10 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #include <linux/cacheinfo.h>
18 /* Populates leaf and increments to next leaf */
19 #define populate_cache(cache, leaf, c_level, c_type) \
21 leaf->type = c_type; \
22 leaf->level = c_level; \
23 leaf->coherency_line_size = c->cache.linesz; \
24 leaf->number_of_sets = c->cache.sets; \
25 leaf->ways_of_associativity = c->cache.ways; \
26 leaf->size = c->cache.linesz * c->cache.sets * \
31 int init_cache_level(unsigned int cpu)
33 struct cpuinfo_mips *c = ¤t_cpu_data;
34 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
35 int levels = 0, leaves = 0;
38 * If Dcache is not set, we assume the cache structures
39 * are not properly initialized.
41 if (c->dcache.waysize)
47 leaves += (c->icache.waysize) ? 2 : 1;
49 if (c->scache.waysize) {
54 if (c->tcache.waysize) {
59 this_cpu_ci->num_levels = levels;
60 this_cpu_ci->num_leaves = leaves;
64 static void fill_cpumask_siblings(int cpu, cpumask_t *cpu_map)
68 for_each_possible_cpu(cpu1)
69 if (cpus_are_siblings(cpu, cpu1))
70 cpumask_set_cpu(cpu1, cpu_map);
73 static void fill_cpumask_cluster(int cpu, cpumask_t *cpu_map)
76 int cluster = cpu_cluster(&cpu_data[cpu]);
78 for_each_possible_cpu(cpu1)
79 if (cpu_cluster(&cpu_data[cpu1]) == cluster)
80 cpumask_set_cpu(cpu1, cpu_map);
83 int populate_cache_leaves(unsigned int cpu)
85 struct cpuinfo_mips *c = ¤t_cpu_data;
86 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
87 struct cacheinfo *this_leaf = this_cpu_ci->info_list;
89 if (c->icache.waysize) {
90 /* L1 caches are per core */
91 fill_cpumask_siblings(cpu, &this_leaf->shared_cpu_map);
92 populate_cache(dcache, this_leaf, 1, CACHE_TYPE_DATA);
93 fill_cpumask_siblings(cpu, &this_leaf->shared_cpu_map);
94 populate_cache(icache, this_leaf, 1, CACHE_TYPE_INST);
96 populate_cache(dcache, this_leaf, 1, CACHE_TYPE_UNIFIED);
99 if (c->scache.waysize) {
100 /* L2 cache is per cluster */
101 fill_cpumask_cluster(cpu, &this_leaf->shared_cpu_map);
102 populate_cache(scache, this_leaf, 2, CACHE_TYPE_UNIFIED);
105 if (c->tcache.waysize)
106 populate_cache(tcache, this_leaf, 3, CACHE_TYPE_UNIFIED);
108 this_cpu_ci->cpu_map_populated = true;