Skip to content

Commit 73bde0c

Browse files
Merge patch series "riscv: alternative/cpufeature related cleanups"
Andrew Jones <ajones@ventanamicro.com> says: This series has no intended functional change. These cleanups were found while renaming errata_id to patch_id in order to better convey that its purpose is larger than errata (it's also for cpufeatures). * b4-shazam-merge: riscv: cpufeature: Drop errata_list.h and other unused includes riscv: lib: Include hwcap.h directly riscv: alternatives: Rename errata_id to patch_id riscv: alternatives: Remove unnecessary define and unused struct riscv: Rename Kconfig.erratas to Kconfig.errata riscv: Clarify RISCV_ALTERNATIVE help text Link: https://lore.kernel.org/r/20230224154601.88163-1-ajones@ventanamicro.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2 parents 4a4c459 + 816a697 commit 73bde0c

10 files changed

Lines changed: 54 additions & 69 deletions

File tree

arch/riscv/Kconfig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ config AS_HAS_INSN
245245
def_bool $(as-instr,.insn r 51$(comma) 0$(comma) 0$(comma) t0$(comma) t0$(comma) zero)
246246

247247
source "arch/riscv/Kconfig.socs"
248-
source "arch/riscv/Kconfig.erratas"
248+
source "arch/riscv/Kconfig.errata"
249249

250250
menu "Platform type"
251251

@@ -378,9 +378,9 @@ config RISCV_ALTERNATIVE
378378
depends on !XIP_KERNEL
379379
help
380380
This Kconfig allows the kernel to automatically patch the
381-
errata required by the execution platform at run time. The
382-
code patching is performed once in the boot stages. It means
383-
that the overhead from this mechanism is just taken once.
381+
erratum or cpufeature required by the execution platform at run
382+
time. The code patching overhead is minimal, as it's only done
383+
once at boot and once on each module load.
384384

385385
config RISCV_ALTERNATIVE_EARLY
386386
bool

arch/riscv/errata/sifive/errata.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <asm/errata_list.h>
1515

1616
struct errata_info_t {
17-
char name[ERRATA_STRING_LENGTH_MAX];
17+
char name[32];
1818
bool (*check_func)(unsigned long arch_id, unsigned long impid);
1919
};
2020

@@ -101,12 +101,12 @@ void __init_or_module sifive_errata_patch_func(struct alt_entry *begin,
101101
for (alt = begin; alt < end; alt++) {
102102
if (alt->vendor_id != SIFIVE_VENDOR_ID)
103103
continue;
104-
if (alt->errata_id >= ERRATA_SIFIVE_NUMBER) {
105-
WARN(1, "This errata id:%d is not in kernel errata list", alt->errata_id);
104+
if (alt->patch_id >= ERRATA_SIFIVE_NUMBER) {
105+
WARN(1, "This errata id:%d is not in kernel errata list", alt->patch_id);
106106
continue;
107107
}
108108

109-
tmp = (1U << alt->errata_id);
109+
tmp = (1U << alt->patch_id);
110110
if (cpu_req_errata & tmp) {
111111
mutex_lock(&text_mutex);
112112
patch_text_nosync(ALT_OLD_PTR(alt), ALT_ALT_PTR(alt),

arch/riscv/errata/thead/errata.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ void __init_or_module thead_errata_patch_func(struct alt_entry *begin, struct al
9393
for (alt = begin; alt < end; alt++) {
9494
if (alt->vendor_id != THEAD_VENDOR_ID)
9595
continue;
96-
if (alt->errata_id >= ERRATA_THEAD_NUMBER)
96+
if (alt->patch_id >= ERRATA_THEAD_NUMBER)
9797
continue;
9898

99-
tmp = (1U << alt->errata_id);
99+
tmp = (1U << alt->patch_id);
100100
if (cpu_req_errata & tmp) {
101101
oldptr = ALT_OLD_PTR(alt);
102102
altptr = ALT_ALT_PTR(alt);

arch/riscv/include/asm/alternative-macros.h

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66

77
#ifdef __ASSEMBLY__
88

9-
.macro ALT_ENTRY oldptr newptr vendor_id errata_id new_len
9+
.macro ALT_ENTRY oldptr newptr vendor_id patch_id new_len
1010
.4byte \oldptr - .
1111
.4byte \newptr - .
1212
.2byte \vendor_id
1313
.2byte \new_len
14-
.4byte \errata_id
14+
.4byte \patch_id
1515
.endm
1616

17-
.macro ALT_NEW_CONTENT vendor_id, errata_id, enable = 1, new_c : vararg
17+
.macro ALT_NEW_CONTENT vendor_id, patch_id, enable = 1, new_c : vararg
1818
.if \enable
1919
.pushsection .alternative, "a"
20-
ALT_ENTRY 886b, 888f, \vendor_id, \errata_id, 889f - 888f
20+
ALT_ENTRY 886b, 888f, \vendor_id, \patch_id, 889f - 888f
2121
.popsection
2222
.subsection 1
2323
888 :
@@ -33,21 +33,21 @@
3333
.endif
3434
.endm
3535

36-
.macro ALTERNATIVE_CFG old_c, new_c, vendor_id, errata_id, enable
36+
.macro ALTERNATIVE_CFG old_c, new_c, vendor_id, patch_id, enable
3737
886 :
3838
.option push
3939
.option norvc
4040
.option norelax
4141
\old_c
4242
.option pop
4343
887 :
44-
ALT_NEW_CONTENT \vendor_id, \errata_id, \enable, \new_c
44+
ALT_NEW_CONTENT \vendor_id, \patch_id, \enable, \new_c
4545
.endm
4646

47-
.macro ALTERNATIVE_CFG_2 old_c, new_c_1, vendor_id_1, errata_id_1, enable_1, \
48-
new_c_2, vendor_id_2, errata_id_2, enable_2
49-
ALTERNATIVE_CFG "\old_c", "\new_c_1", \vendor_id_1, \errata_id_1, \enable_1
50-
ALT_NEW_CONTENT \vendor_id_2, \errata_id_2, \enable_2, \new_c_2
47+
.macro ALTERNATIVE_CFG_2 old_c, new_c_1, vendor_id_1, patch_id_1, enable_1, \
48+
new_c_2, vendor_id_2, patch_id_2, enable_2
49+
ALTERNATIVE_CFG "\old_c", "\new_c_1", \vendor_id_1, \patch_id_1, \enable_1
50+
ALT_NEW_CONTENT \vendor_id_2, \patch_id_2, \enable_2, \new_c_2
5151
.endm
5252

5353
#define __ALTERNATIVE_CFG(...) ALTERNATIVE_CFG __VA_ARGS__
@@ -58,17 +58,17 @@
5858
#include <asm/asm.h>
5959
#include <linux/stringify.h>
6060

61-
#define ALT_ENTRY(oldptr, newptr, vendor_id, errata_id, newlen) \
61+
#define ALT_ENTRY(oldptr, newptr, vendor_id, patch_id, newlen) \
6262
".4byte ((" oldptr ") - .) \n" \
6363
".4byte ((" newptr ") - .) \n" \
6464
".2byte " vendor_id "\n" \
6565
".2byte " newlen "\n" \
66-
".4byte " errata_id "\n"
66+
".4byte " patch_id "\n"
6767

68-
#define ALT_NEW_CONTENT(vendor_id, errata_id, enable, new_c) \
68+
#define ALT_NEW_CONTENT(vendor_id, patch_id, enable, new_c) \
6969
".if " __stringify(enable) " == 1\n" \
7070
".pushsection .alternative, \"a\"\n" \
71-
ALT_ENTRY("886b", "888f", __stringify(vendor_id), __stringify(errata_id), "889f - 888f") \
71+
ALT_ENTRY("886b", "888f", __stringify(vendor_id), __stringify(patch_id), "889f - 888f") \
7272
".popsection\n" \
7373
".subsection 1\n" \
7474
"888 :\n" \
@@ -83,30 +83,30 @@
8383
".previous\n" \
8484
".endif\n"
8585

86-
#define __ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, enable) \
86+
#define __ALTERNATIVE_CFG(old_c, new_c, vendor_id, patch_id, enable) \
8787
"886 :\n" \
8888
".option push\n" \
8989
".option norvc\n" \
9090
".option norelax\n" \
9191
old_c "\n" \
9292
".option pop\n" \
9393
"887 :\n" \
94-
ALT_NEW_CONTENT(vendor_id, errata_id, enable, new_c)
94+
ALT_NEW_CONTENT(vendor_id, patch_id, enable, new_c)
9595

96-
#define __ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, enable_1, \
97-
new_c_2, vendor_id_2, errata_id_2, enable_2) \
98-
__ALTERNATIVE_CFG(old_c, new_c_1, vendor_id_1, errata_id_1, enable_1) \
99-
ALT_NEW_CONTENT(vendor_id_2, errata_id_2, enable_2, new_c_2)
96+
#define __ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, patch_id_1, enable_1, \
97+
new_c_2, vendor_id_2, patch_id_2, enable_2) \
98+
__ALTERNATIVE_CFG(old_c, new_c_1, vendor_id_1, patch_id_1, enable_1) \
99+
ALT_NEW_CONTENT(vendor_id_2, patch_id_2, enable_2, new_c_2)
100100

101101
#endif /* __ASSEMBLY__ */
102102

103-
#define _ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, CONFIG_k) \
104-
__ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, IS_ENABLED(CONFIG_k))
103+
#define _ALTERNATIVE_CFG(old_c, new_c, vendor_id, patch_id, CONFIG_k) \
104+
__ALTERNATIVE_CFG(old_c, new_c, vendor_id, patch_id, IS_ENABLED(CONFIG_k))
105105

106-
#define _ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, CONFIG_k_1, \
107-
new_c_2, vendor_id_2, errata_id_2, CONFIG_k_2) \
108-
__ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, IS_ENABLED(CONFIG_k_1), \
109-
new_c_2, vendor_id_2, errata_id_2, IS_ENABLED(CONFIG_k_2))
106+
#define _ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, patch_id_1, CONFIG_k_1, \
107+
new_c_2, vendor_id_2, patch_id_2, CONFIG_k_2) \
108+
__ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, patch_id_1, IS_ENABLED(CONFIG_k_1), \
109+
new_c_2, vendor_id_2, patch_id_2, IS_ENABLED(CONFIG_k_2))
110110

111111
#else /* CONFIG_RISCV_ALTERNATIVE */
112112
#ifdef __ASSEMBLY__
@@ -137,19 +137,19 @@
137137

138138
/*
139139
* Usage:
140-
* ALTERNATIVE(old_content, new_content, vendor_id, errata_id, CONFIG_k)
140+
* ALTERNATIVE(old_content, new_content, vendor_id, patch_id, CONFIG_k)
141141
* in the assembly code. Otherwise,
142-
* asm(ALTERNATIVE(old_content, new_content, vendor_id, errata_id, CONFIG_k));
142+
* asm(ALTERNATIVE(old_content, new_content, vendor_id, patch_id, CONFIG_k));
143143
*
144144
* old_content: The old content which is probably replaced with new content.
145145
* new_content: The new content.
146146
* vendor_id: The CPU vendor ID.
147-
* errata_id: The errata ID.
148-
* CONFIG_k: The Kconfig of this errata. When Kconfig is disabled, the old
147+
* patch_id: The patch ID (erratum ID or cpufeature ID).
148+
* CONFIG_k: The Kconfig of this patch ID. When Kconfig is disabled, the old
149149
* content will alwyas be executed.
150150
*/
151-
#define ALTERNATIVE(old_content, new_content, vendor_id, errata_id, CONFIG_k) \
152-
_ALTERNATIVE_CFG(old_content, new_content, vendor_id, errata_id, CONFIG_k)
151+
#define ALTERNATIVE(old_content, new_content, vendor_id, patch_id, CONFIG_k) \
152+
_ALTERNATIVE_CFG(old_content, new_content, vendor_id, patch_id, CONFIG_k)
153153

154154
/*
155155
* A vendor wants to replace an old_content, but another vendor has used
@@ -158,9 +158,9 @@
158158
* on the following sample code and then replace ALTERNATIVE() with
159159
* ALTERNATIVE_2() to append its customized content.
160160
*/
161-
#define ALTERNATIVE_2(old_content, new_content_1, vendor_id_1, errata_id_1, CONFIG_k_1, \
162-
new_content_2, vendor_id_2, errata_id_2, CONFIG_k_2) \
163-
_ALTERNATIVE_CFG_2(old_content, new_content_1, vendor_id_1, errata_id_1, CONFIG_k_1, \
164-
new_content_2, vendor_id_2, errata_id_2, CONFIG_k_2)
161+
#define ALTERNATIVE_2(old_content, new_content_1, vendor_id_1, patch_id_1, CONFIG_k_1, \
162+
new_content_2, vendor_id_2, patch_id_2, CONFIG_k_2) \
163+
_ALTERNATIVE_CFG_2(old_content, new_content_1, vendor_id_1, patch_id_1, CONFIG_k_1, \
164+
new_content_2, vendor_id_2, patch_id_2, CONFIG_k_2)
165165

166166
#endif

arch/riscv/include/asm/alternative.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
#ifndef __ASM_ALTERNATIVE_H
77
#define __ASM_ALTERNATIVE_H
88

9-
#define ERRATA_STRING_LENGTH_MAX 32
10-
119
#include <asm/alternative-macros.h>
1210

1311
#ifndef __ASSEMBLY__
@@ -38,14 +36,9 @@ void riscv_alternative_fix_offsets(void *alt_ptr, unsigned int len,
3836
struct alt_entry {
3937
s32 old_offset; /* offset relative to original instruction or data */
4038
s32 alt_offset; /* offset relative to replacement instruction or data */
41-
u16 vendor_id; /* cpu vendor id */
39+
u16 vendor_id; /* CPU vendor ID */
4240
u16 alt_len; /* The replacement size */
43-
u32 errata_id; /* The errata id */
44-
};
45-
46-
struct errata_checkfunc_id {
47-
unsigned long vendor_id;
48-
bool (*func)(struct alt_entry *alt);
41+
u32 patch_id; /* The patch ID (erratum ID or cpufeature ID) */
4942
};
5043

5144
void sifive_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,

arch/riscv/kernel/cpufeature.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,15 @@
88

99
#include <linux/bitmap.h>
1010
#include <linux/ctype.h>
11-
#include <linux/libfdt.h>
1211
#include <linux/log2.h>
1312
#include <linux/memory.h>
1413
#include <linux/module.h>
1514
#include <linux/of.h>
1615
#include <asm/alternative.h>
1716
#include <asm/cacheflush.h>
18-
#include <asm/errata_list.h>
1917
#include <asm/hwcap.h>
2018
#include <asm/patch.h>
21-
#include <asm/pgtable.h>
2219
#include <asm/processor.h>
23-
#include <asm/smp.h>
24-
#include <asm/switch_to.h>
2520

2621
#define NUM_ALPHA_EXTS ('z' - 'a' + 1)
2722

@@ -283,13 +278,13 @@ void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin,
283278
for (alt = begin; alt < end; alt++) {
284279
if (alt->vendor_id != 0)
285280
continue;
286-
if (alt->errata_id >= RISCV_ISA_EXT_MAX) {
281+
if (alt->patch_id >= RISCV_ISA_EXT_MAX) {
287282
WARN(1, "This extension id:%d is not in ISA extension list",
288-
alt->errata_id);
283+
alt->patch_id);
289284
continue;
290285
}
291286

292-
if (!__riscv_isa_extension_available(NULL, alt->errata_id))
287+
if (!__riscv_isa_extension_available(NULL, alt->patch_id))
293288
continue;
294289

295290
oldptr = ALT_OLD_PTR(alt);

arch/riscv/lib/strcmp.S

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
#include <linux/linkage.h>
44
#include <asm/asm.h>
5-
#include <asm-generic/export.h>
65
#include <asm/alternative-macros.h>
7-
#include <asm/errata_list.h>
6+
#include <asm/hwcap.h>
87

98
/* int strcmp(const char *cs, const char *ct) */
109
SYM_FUNC_START(strcmp)

arch/riscv/lib/strlen.S

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
#include <linux/linkage.h>
44
#include <asm/asm.h>
5-
#include <asm-generic/export.h>
65
#include <asm/alternative-macros.h>
7-
#include <asm/errata_list.h>
6+
#include <asm/hwcap.h>
87

98
/* int strlen(const char *s) */
109
SYM_FUNC_START(strlen)

arch/riscv/lib/strncmp.S

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
#include <linux/linkage.h>
44
#include <asm/asm.h>
5-
#include <asm-generic/export.h>
65
#include <asm/alternative-macros.h>
7-
#include <asm/errata_list.h>
6+
#include <asm/hwcap.h>
87

98
/* int strncmp(const char *cs, const char *ct, size_t count) */
109
SYM_FUNC_START(strncmp)

0 commit comments

Comments
 (0)