Skip to content

Commit 2ff075c

Browse files
jlintonarmctmarinas
authored andcommitted
drivers: base: cacheinfo: setup DT cache properties early
The original intent in cacheinfo was that an architecture specific populate_cache_leaves() would probe the hardware and then cache_shared_cpu_map_setup() and cache_override_properties() would provide firmware help to extend/expand upon what was probed. Arm64 was really the only architecture that was working this way, and with the removal of most of the hardware probing logic it became clear that it was possible to simplify the logic a bit. This patch combines the walk of the DT nodes with the code updating the cache size/line_size and nr_sets. cache_override_properties() (which was DT specific) is then removed. The result is that cacheinfo.of_node is no longer used as a temporary place to hold DT references for future calls that update cache properties. That change helps to clarify its one remaining use (matching cacheinfo nodes that represent shared caches) which will be used by the ACPI/PPTT code in the following patches. Tested-by: Ard Biesheuvel <[email protected]> Tested-by: Vijaya Kumar K <[email protected]> Tested-by: Xiongfeng Wang <[email protected]> Tested-by: Tomasz Nowicki <[email protected]> Acked-by: Sudeep Holla <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Acked-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Jeremy Linton <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent d529a18 commit 2ff075c

File tree

2 files changed

+29
-37
lines changed

2 files changed

+29
-37
lines changed

arch/riscv/kernel/cacheinfo.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ static void ci_leaf_init(struct cacheinfo *this_leaf,
2020
struct device_node *node,
2121
enum cache_type type, unsigned int level)
2222
{
23-
this_leaf->of_node = node;
2423
this_leaf->level = level;
2524
this_leaf->type = type;
2625
/* not a sector cache */

drivers/base/cacheinfo.c

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static inline int get_cacheinfo_idx(enum cache_type type)
7171
return type;
7272
}
7373

74-
static void cache_size(struct cacheinfo *this_leaf)
74+
static void cache_size(struct cacheinfo *this_leaf, struct device_node *np)
7575
{
7676
const char *propname;
7777
const __be32 *cache_size;
@@ -80,13 +80,14 @@ static void cache_size(struct cacheinfo *this_leaf)
8080
ct_idx = get_cacheinfo_idx(this_leaf->type);
8181
propname = cache_type_info[ct_idx].size_prop;
8282

83-
cache_size = of_get_property(this_leaf->of_node, propname, NULL);
83+
cache_size = of_get_property(np, propname, NULL);
8484
if (cache_size)
8585
this_leaf->size = of_read_number(cache_size, 1);
8686
}
8787

8888
/* not cache_line_size() because that's a macro in include/linux/cache.h */
89-
static void cache_get_line_size(struct cacheinfo *this_leaf)
89+
static void cache_get_line_size(struct cacheinfo *this_leaf,
90+
struct device_node *np)
9091
{
9192
const __be32 *line_size;
9293
int i, lim, ct_idx;
@@ -98,7 +99,7 @@ static void cache_get_line_size(struct cacheinfo *this_leaf)
9899
const char *propname;
99100

100101
propname = cache_type_info[ct_idx].line_size_props[i];
101-
line_size = of_get_property(this_leaf->of_node, propname, NULL);
102+
line_size = of_get_property(np, propname, NULL);
102103
if (line_size)
103104
break;
104105
}
@@ -107,7 +108,7 @@ static void cache_get_line_size(struct cacheinfo *this_leaf)
107108
this_leaf->coherency_line_size = of_read_number(line_size, 1);
108109
}
109110

110-
static void cache_nr_sets(struct cacheinfo *this_leaf)
111+
static void cache_nr_sets(struct cacheinfo *this_leaf, struct device_node *np)
111112
{
112113
const char *propname;
113114
const __be32 *nr_sets;
@@ -116,7 +117,7 @@ static void cache_nr_sets(struct cacheinfo *this_leaf)
116117
ct_idx = get_cacheinfo_idx(this_leaf->type);
117118
propname = cache_type_info[ct_idx].nr_sets_prop;
118119

119-
nr_sets = of_get_property(this_leaf->of_node, propname, NULL);
120+
nr_sets = of_get_property(np, propname, NULL);
120121
if (nr_sets)
121122
this_leaf->number_of_sets = of_read_number(nr_sets, 1);
122123
}
@@ -135,32 +136,27 @@ static void cache_associativity(struct cacheinfo *this_leaf)
135136
this_leaf->ways_of_associativity = (size / nr_sets) / line_size;
136137
}
137138

138-
static bool cache_node_is_unified(struct cacheinfo *this_leaf)
139+
static bool cache_node_is_unified(struct cacheinfo *this_leaf,
140+
struct device_node *np)
139141
{
140-
return of_property_read_bool(this_leaf->of_node, "cache-unified");
142+
return of_property_read_bool(np, "cache-unified");
141143
}
142144

143-
static void cache_of_override_properties(unsigned int cpu)
145+
static void cache_of_set_props(struct cacheinfo *this_leaf,
146+
struct device_node *np)
144147
{
145-
int index;
146-
struct cacheinfo *this_leaf;
147-
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
148-
149-
for (index = 0; index < cache_leaves(cpu); index++) {
150-
this_leaf = this_cpu_ci->info_list + index;
151-
/*
152-
* init_cache_level must setup the cache level correctly
153-
* overriding the architecturally specified levels, so
154-
* if type is NONE at this stage, it should be unified
155-
*/
156-
if (this_leaf->type == CACHE_TYPE_NOCACHE &&
157-
cache_node_is_unified(this_leaf))
158-
this_leaf->type = CACHE_TYPE_UNIFIED;
159-
cache_size(this_leaf);
160-
cache_get_line_size(this_leaf);
161-
cache_nr_sets(this_leaf);
162-
cache_associativity(this_leaf);
163-
}
148+
/*
149+
* init_cache_level must setup the cache level correctly
150+
* overriding the architecturally specified levels, so
151+
* if type is NONE at this stage, it should be unified
152+
*/
153+
if (this_leaf->type == CACHE_TYPE_NOCACHE &&
154+
cache_node_is_unified(this_leaf, np))
155+
this_leaf->type = CACHE_TYPE_UNIFIED;
156+
cache_size(this_leaf, np);
157+
cache_get_line_size(this_leaf, np);
158+
cache_nr_sets(this_leaf, np);
159+
cache_associativity(this_leaf);
164160
}
165161

166162
static int cache_setup_of_node(unsigned int cpu)
@@ -193,6 +189,7 @@ static int cache_setup_of_node(unsigned int cpu)
193189
np = of_node_get(np);/* cpu node itself */
194190
if (!np)
195191
break;
192+
cache_of_set_props(this_leaf, np);
196193
this_leaf->of_node = np;
197194
index++;
198195
}
@@ -203,7 +200,6 @@ static int cache_setup_of_node(unsigned int cpu)
203200
return 0;
204201
}
205202
#else
206-
static void cache_of_override_properties(unsigned int cpu) { }
207203
static inline int cache_setup_of_node(unsigned int cpu) { return 0; }
208204
static inline bool cache_leaves_are_shared(struct cacheinfo *this_leaf,
209205
struct cacheinfo *sib_leaf)
@@ -286,12 +282,6 @@ static void cache_shared_cpu_map_remove(unsigned int cpu)
286282
}
287283
}
288284

289-
static void cache_override_properties(unsigned int cpu)
290-
{
291-
if (of_have_populated_dt())
292-
return cache_of_override_properties(cpu);
293-
}
294-
295285
static void free_cache_attributes(unsigned int cpu)
296286
{
297287
if (!per_cpu_cacheinfo(cpu))
@@ -325,6 +315,10 @@ static int detect_cache_attributes(unsigned int cpu)
325315
if (per_cpu_cacheinfo(cpu) == NULL)
326316
return -ENOMEM;
327317

318+
/*
319+
* populate_cache_leaves() may completely setup the cache leaves and
320+
* shared_cpu_map or it may leave it partially setup.
321+
*/
328322
ret = populate_cache_leaves(cpu);
329323
if (ret)
330324
goto free_ci;
@@ -338,7 +332,6 @@ static int detect_cache_attributes(unsigned int cpu)
338332
goto free_ci;
339333
}
340334

341-
cache_override_properties(cpu);
342335
return 0;
343336

344337
free_ci:

0 commit comments

Comments
 (0)