Skip to content

Commit 73448ae

Browse files
RISC-V: Some Svpbmt fixes and cleanups
Some additionals comments and notes from autobuilders received after the series got applied, warranted some changes. * 'riscv-svpbmt' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/palmer/linux: riscv: remove usage of function-pointers from cpufeatures and t-head errata riscv: make patch-function pointer more generic in cpu_manufacturer_info struct riscv: Improve description for RISCV_ISA_SVPBMT Kconfig symbol riscv: drop cpufeature_apply_feature tracking variable riscv: fix dependency for t-head errata
2 parents 89793a6 + 1771c8c commit 73448ae

File tree

5 files changed

+40
-63
lines changed

5 files changed

+40
-63
lines changed

arch/riscv/Kconfig

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,13 @@ config RISCV_ISA_SVPBMT
364364
select RISCV_ALTERNATIVE
365365
default y
366366
help
367-
Adds support to dynamically detect the presence of the SVPBMT extension
368-
(Supervisor-mode: page-based memory types) and enable its usage.
367+
Adds support to dynamically detect the presence of the SVPBMT
368+
ISA-extension (Supervisor-mode: page-based memory types) and
369+
enable its usage.
370+
371+
The memory type for a page contains a combination of attributes
372+
that indicate the cacheability, idempotency, and ordering
373+
properties for access to that page.
369374

370375
The SVPBMT extension is only available on 64Bit cpus.
371376

arch/riscv/Kconfig.erratas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ config ERRATA_SIFIVE_CIP_1200
3535

3636
config ERRATA_THEAD
3737
bool "T-HEAD errata"
38+
depends on !XIP_KERNEL
3839
select RISCV_ALTERNATIVE
3940
help
4041
All T-HEAD errata Kconfig depend on this Kconfig. Disabling

arch/riscv/errata/thead/errata.c

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,26 @@
1414
#include <asm/patch.h>
1515
#include <asm/vendorid_list.h>
1616

17-
struct errata_info {
18-
char name[ERRATA_STRING_LENGTH_MAX];
19-
bool (*check_func)(unsigned long arch_id, unsigned long impid);
20-
unsigned int stage;
21-
};
22-
23-
static bool errata_mt_check_func(unsigned long arch_id, unsigned long impid)
17+
static bool errata_probe_pbmt(unsigned int stage,
18+
unsigned long arch_id, unsigned long impid)
2419
{
2520
if (arch_id != 0 || impid != 0)
2621
return false;
27-
return true;
28-
}
2922

30-
static const struct errata_info errata_list[ERRATA_THEAD_NUMBER] = {
31-
{
32-
.name = "memory-types",
33-
.stage = RISCV_ALTERNATIVES_EARLY_BOOT,
34-
.check_func = errata_mt_check_func
35-
},
36-
};
23+
if (stage == RISCV_ALTERNATIVES_EARLY_BOOT ||
24+
stage == RISCV_ALTERNATIVES_MODULE)
25+
return true;
26+
27+
return false;
28+
}
3729

38-
static u32 thead_errata_probe(unsigned int stage, unsigned long archid, unsigned long impid)
30+
static u32 thead_errata_probe(unsigned int stage,
31+
unsigned long archid, unsigned long impid)
3932
{
40-
const struct errata_info *info;
4133
u32 cpu_req_errata = 0;
42-
int idx;
43-
44-
for (idx = 0; idx < ERRATA_THEAD_NUMBER; idx++) {
45-
info = &errata_list[idx];
4634

47-
if ((stage == RISCV_ALTERNATIVES_MODULE ||
48-
info->stage == stage) && info->check_func(archid, impid))
49-
cpu_req_errata |= (1U << idx);
50-
}
35+
if (errata_probe_pbmt(stage, archid, impid))
36+
cpu_req_errata |= (1U << ERRATA_THEAD_PBMT);
5137

5238
return cpu_req_errata;
5339
}

arch/riscv/kernel/alternative.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct cpu_manufacturer_info_t {
2020
unsigned long vendor_id;
2121
unsigned long arch_id;
2222
unsigned long imp_id;
23-
void (*vendor_patch_func)(struct alt_entry *begin, struct alt_entry *end,
23+
void (*patch_func)(struct alt_entry *begin, struct alt_entry *end,
2424
unsigned long archid, unsigned long impid,
2525
unsigned int stage);
2626
};
@@ -40,16 +40,16 @@ static void __init_or_module riscv_fill_cpu_mfr_info(struct cpu_manufacturer_inf
4040
switch (cpu_mfr_info->vendor_id) {
4141
#ifdef CONFIG_ERRATA_SIFIVE
4242
case SIFIVE_VENDOR_ID:
43-
cpu_mfr_info->vendor_patch_func = sifive_errata_patch_func;
43+
cpu_mfr_info->patch_func = sifive_errata_patch_func;
4444
break;
4545
#endif
4646
#ifdef CONFIG_ERRATA_THEAD
4747
case THEAD_VENDOR_ID:
48-
cpu_mfr_info->vendor_patch_func = thead_errata_patch_func;
48+
cpu_mfr_info->patch_func = thead_errata_patch_func;
4949
break;
5050
#endif
5151
default:
52-
cpu_mfr_info->vendor_patch_func = NULL;
52+
cpu_mfr_info->patch_func = NULL;
5353
}
5454
}
5555

@@ -68,13 +68,13 @@ static void __init_or_module _apply_alternatives(struct alt_entry *begin,
6868

6969
riscv_cpufeature_patch_func(begin, end, stage);
7070

71-
if (!cpu_mfr_info.vendor_patch_func)
71+
if (!cpu_mfr_info.patch_func)
7272
return;
7373

74-
cpu_mfr_info.vendor_patch_func(begin, end,
75-
cpu_mfr_info.arch_id,
76-
cpu_mfr_info.imp_id,
77-
stage);
74+
cpu_mfr_info.patch_func(begin, end,
75+
cpu_mfr_info.arch_id,
76+
cpu_mfr_info.imp_id,
77+
stage);
7878
}
7979

8080
void __init apply_boot_alternatives(void)

arch/riscv/kernel/cpufeature.c

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,7 @@ void __init riscv_fill_hwcap(void)
245245
}
246246

247247
#ifdef CONFIG_RISCV_ALTERNATIVE
248-
struct cpufeature_info {
249-
char name[ERRATA_STRING_LENGTH_MAX];
250-
bool (*check_func)(unsigned int stage);
251-
};
252-
253-
static bool __init_or_module cpufeature_svpbmt_check_func(unsigned int stage)
248+
static bool __init_or_module cpufeature_probe_svpbmt(unsigned int stage)
254249
{
255250
#ifdef CONFIG_RISCV_ISA_SVPBMT
256251
switch (stage) {
@@ -264,26 +259,19 @@ static bool __init_or_module cpufeature_svpbmt_check_func(unsigned int stage)
264259
return false;
265260
}
266261

267-
static const struct cpufeature_info __initdata_or_module
268-
cpufeature_list[CPUFEATURE_NUMBER] = {
269-
{
270-
.name = "svpbmt",
271-
.check_func = cpufeature_svpbmt_check_func
272-
},
273-
};
274-
262+
/*
263+
* Probe presence of individual extensions.
264+
*
265+
* This code may also be executed before kernel relocation, so we cannot use
266+
* addresses generated by the address-of operator as they won't be valid in
267+
* this context.
268+
*/
275269
static u32 __init_or_module cpufeature_probe(unsigned int stage)
276270
{
277-
const struct cpufeature_info *info;
278271
u32 cpu_req_feature = 0;
279-
int idx;
280-
281-
for (idx = 0; idx < CPUFEATURE_NUMBER; idx++) {
282-
info = &cpufeature_list[idx];
283272

284-
if (info->check_func(stage))
285-
cpu_req_feature |= (1U << idx);
286-
}
273+
if (cpufeature_probe_svpbmt(stage))
274+
cpu_req_feature |= (1U << CPUFEATURE_SVPBMT);
287275

288276
return cpu_req_feature;
289277
}
@@ -293,7 +281,6 @@ void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin,
293281
unsigned int stage)
294282
{
295283
u32 cpu_req_feature = cpufeature_probe(stage);
296-
u32 cpu_apply_feature = 0;
297284
struct alt_entry *alt;
298285
u32 tmp;
299286

@@ -307,10 +294,8 @@ void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin,
307294
}
308295

309296
tmp = (1U << alt->errata_id);
310-
if (cpu_req_feature & tmp) {
297+
if (cpu_req_feature & tmp)
311298
patch_text_nosync(alt->old_ptr, alt->alt_ptr, alt->alt_len);
312-
cpu_apply_feature |= tmp;
313-
}
314299
}
315300
}
316301
#endif

0 commit comments

Comments
 (0)