1 // SPDX-License-Identifier: GPL-2.0-only
3 * MIPS cacheinfo support
5 #include <linux/cacheinfo.h>
7 /* Populates leaf and increments to next leaf */
8 #define populate_cache(cache, leaf, c_level, c_type) \
10 leaf->type = c_type; \
11 leaf->level = c_level; \
12 leaf->coherency_line_size = c->cache.linesz; \
13 leaf->number_of_sets = c->cache.sets; \
14 leaf->ways_of_associativity = c->cache.ways; \
15 leaf->size = c->cache.linesz * c->cache.sets * \
20 int init_cache_level(unsigned int cpu
)
22 struct cpuinfo_mips
*c
= ¤t_cpu_data
;
23 struct cpu_cacheinfo
*this_cpu_ci
= get_cpu_cacheinfo(cpu
);
24 int levels
= 0, leaves
= 0;
27 * If Dcache is not set, we assume the cache structures
28 * are not properly initialized.
30 if (c
->dcache
.waysize
)
36 leaves
+= (c
->icache
.waysize
) ? 2 : 1;
38 if (c
->vcache
.waysize
) {
43 if (c
->scache
.waysize
) {
48 if (c
->tcache
.waysize
) {
53 this_cpu_ci
->num_levels
= levels
;
54 this_cpu_ci
->num_leaves
= leaves
;
58 static void fill_cpumask_siblings(int cpu
, cpumask_t
*cpu_map
)
62 for_each_possible_cpu(cpu1
)
63 if (cpus_are_siblings(cpu
, cpu1
))
64 cpumask_set_cpu(cpu1
, cpu_map
);
67 static void fill_cpumask_cluster(int cpu
, cpumask_t
*cpu_map
)
70 int cluster
= cpu_cluster(&cpu_data
[cpu
]);
72 for_each_possible_cpu(cpu1
)
73 if (cpu_cluster(&cpu_data
[cpu1
]) == cluster
)
74 cpumask_set_cpu(cpu1
, cpu_map
);
77 int populate_cache_leaves(unsigned int cpu
)
79 struct cpuinfo_mips
*c
= ¤t_cpu_data
;
80 struct cpu_cacheinfo
*this_cpu_ci
= get_cpu_cacheinfo(cpu
);
81 struct cacheinfo
*this_leaf
= this_cpu_ci
->info_list
;
84 if (c
->icache
.waysize
) {
85 /* I/D caches are per core */
86 fill_cpumask_siblings(cpu
, &this_leaf
->shared_cpu_map
);
87 populate_cache(dcache
, this_leaf
, level
, CACHE_TYPE_DATA
);
88 fill_cpumask_siblings(cpu
, &this_leaf
->shared_cpu_map
);
89 populate_cache(icache
, this_leaf
, level
, CACHE_TYPE_INST
);
92 populate_cache(dcache
, this_leaf
, level
, CACHE_TYPE_UNIFIED
);
96 if (c
->vcache
.waysize
) {
97 /* Vcache is per core as well */
98 fill_cpumask_siblings(cpu
, &this_leaf
->shared_cpu_map
);
99 populate_cache(vcache
, this_leaf
, level
, CACHE_TYPE_UNIFIED
);
103 if (c
->scache
.waysize
) {
104 /* Scache is per cluster */
105 fill_cpumask_cluster(cpu
, &this_leaf
->shared_cpu_map
);
106 populate_cache(scache
, this_leaf
, level
, CACHE_TYPE_UNIFIED
);
110 if (c
->tcache
.waysize
)
111 populate_cache(tcache
, this_leaf
, level
, CACHE_TYPE_UNIFIED
);
113 this_cpu_ci
->cpu_map_populated
= true;