Linux Audio

Check our new training course

Loading...
v4.17
 
 1/*
 2 * MIPS cacheinfo support
 3 *
 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.
 7 *
 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.
12 *
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/>.
15 */
16#include <linux/cacheinfo.h>
17
18/* Populates leaf and increments to next leaf */
19#define populate_cache(cache, leaf, c_level, c_type)		\
20do {								\
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 *		\
27		c->cache.ways;					\
28	leaf++;							\
29} while (0)
30
31static int __init_cache_level(unsigned int cpu)
32{
33	struct cpuinfo_mips *c = &current_cpu_data;
34	struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
35	int levels = 0, leaves = 0;
36
37	/*
38	 * If Dcache is not set, we assume the cache structures
39	 * are not properly initialized.
40	 */
41	if (c->dcache.waysize)
42		levels += 1;
43	else
44		return -ENOENT;
45
46
47	leaves += (c->icache.waysize) ? 2 : 1;
48
 
 
 
 
 
49	if (c->scache.waysize) {
50		levels++;
51		leaves++;
52	}
53
54	if (c->tcache.waysize) {
55		levels++;
56		leaves++;
57	}
58
59	this_cpu_ci->num_levels = levels;
60	this_cpu_ci->num_leaves = leaves;
61	return 0;
62}
63
64static int __populate_cache_leaves(unsigned int cpu)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65{
66	struct cpuinfo_mips *c = &current_cpu_data;
67	struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
68	struct cacheinfo *this_leaf = this_cpu_ci->info_list;
 
69
70	if (c->icache.waysize) {
71		populate_cache(dcache, this_leaf, 1, CACHE_TYPE_DATA);
72		populate_cache(icache, this_leaf, 1, CACHE_TYPE_INST);
 
 
 
 
73	} else {
74		populate_cache(dcache, this_leaf, 1, CACHE_TYPE_UNIFIED);
 
75	}
76
77	if (c->scache.waysize)
78		populate_cache(scache, this_leaf, 2, CACHE_TYPE_UNIFIED);
 
 
 
 
 
 
 
 
 
 
 
79
80	if (c->tcache.waysize)
81		populate_cache(tcache, this_leaf, 3, CACHE_TYPE_UNIFIED);
 
 
82
83	return 0;
84}
85
86DEFINE_SMP_CALL_CACHE_FUNCTION(init_cache_level)
87DEFINE_SMP_CALL_CACHE_FUNCTION(populate_cache_leaves)
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * MIPS cacheinfo support
 
 
 
 
 
 
 
 
 
 
 
 
  4 */
  5#include <linux/cacheinfo.h>
  6
  7/* Populates leaf and increments to next leaf */
  8#define populate_cache(cache, leaf, c_level, c_type)		\
  9do {								\
 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 *		\
 16		c->cache.ways;					\
 17	leaf++;							\
 18} while (0)
 19
 20int init_cache_level(unsigned int cpu)
 21{
 22	struct cpuinfo_mips *c = &current_cpu_data;
 23	struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
 24	int levels = 0, leaves = 0;
 25
 26	/*
 27	 * If Dcache is not set, we assume the cache structures
 28	 * are not properly initialized.
 29	 */
 30	if (c->dcache.waysize)
 31		levels += 1;
 32	else
 33		return -ENOENT;
 34
 35
 36	leaves += (c->icache.waysize) ? 2 : 1;
 37
 38	if (c->vcache.waysize) {
 39		levels++;
 40		leaves++;
 41	}
 42
 43	if (c->scache.waysize) {
 44		levels++;
 45		leaves++;
 46	}
 47
 48	if (c->tcache.waysize) {
 49		levels++;
 50		leaves++;
 51	}
 52
 53	this_cpu_ci->num_levels = levels;
 54	this_cpu_ci->num_leaves = leaves;
 55	return 0;
 56}
 57
 58static void fill_cpumask_siblings(int cpu, cpumask_t *cpu_map)
 59{
 60	int cpu1;
 61
 62	for_each_possible_cpu(cpu1)
 63		if (cpus_are_siblings(cpu, cpu1))
 64			cpumask_set_cpu(cpu1, cpu_map);
 65}
 66
 67static void fill_cpumask_cluster(int cpu, cpumask_t *cpu_map)
 68{
 69	int cpu1;
 70	int cluster = cpu_cluster(&cpu_data[cpu]);
 71
 72	for_each_possible_cpu(cpu1)
 73		if (cpu_cluster(&cpu_data[cpu1]) == cluster)
 74			cpumask_set_cpu(cpu1, cpu_map);
 75}
 76
 77int populate_cache_leaves(unsigned int cpu)
 78{
 79	struct cpuinfo_mips *c = &current_cpu_data;
 80	struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
 81	struct cacheinfo *this_leaf = this_cpu_ci->info_list;
 82	int level = 1;
 83
 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);
 90		level++;
 91	} else {
 92		populate_cache(dcache, this_leaf, level, CACHE_TYPE_UNIFIED);
 93		level++;
 94	}
 95
 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);
100		level++;
101	}
102
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);
107		level++;
108	}
109
110	if (c->tcache.waysize)
111		populate_cache(tcache, this_leaf, level, CACHE_TYPE_UNIFIED);
112
113	this_cpu_ci->cpu_map_populated = true;
114
115	return 0;
116}