Skip to content

Commit 40a4d0d

Browse files
a4lgpalmer-dabbelt
authored andcommitted
RISC-V: Extract multi-letter extension names from "riscv, isa"
Currently, there is no usage for version numbers in extensions as any ratified non base ISA extension will always at v1.0. Extract the extension names in place for future parsing. Tested-by: Heiko Stuebner <heiko@sntech.de> Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com> [Improved commit text and comments] Signed-off-by: Atish Patra <atishp@rivosinc.com> Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 2a31c54 commit 40a4d0d

1 file changed

Lines changed: 27 additions & 8 deletions

File tree

arch/riscv/kernel/cpufeature.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,28 @@ void __init riscv_fill_hwcap(void)
124124
ext_long = true;
125125
/* Multi-letter extension must be delimited */
126126
for (; *isa && *isa != '_'; ++isa)
127-
if (!islower(*isa) && !isdigit(*isa))
127+
if (unlikely(!islower(*isa)
128+
&& !isdigit(*isa)))
128129
ext_err = true;
130+
/* Parse backwards */
131+
ext_end = isa;
132+
if (unlikely(ext_err))
133+
break;
134+
if (!isdigit(ext_end[-1]))
135+
break;
136+
/* Skip the minor version */
137+
while (isdigit(*--ext_end))
138+
;
139+
if (ext_end[0] != 'p'
140+
|| !isdigit(ext_end[-1])) {
141+
/* Advance it to offset the pre-decrement */
142+
++ext_end;
143+
break;
144+
}
145+
/* Skip the major version */
146+
while (isdigit(*--ext_end))
147+
;
148+
++ext_end;
129149
break;
130150
default:
131151
if (unlikely(!islower(*ext))) {
@@ -151,14 +171,13 @@ void __init riscv_fill_hwcap(void)
151171
}
152172
if (*isa != '_')
153173
--isa;
154-
/*
155-
* TODO: Full version-aware handling including
156-
* multi-letter extensions will be added in-future.
157-
*/
158-
if (ext_err || ext_long)
174+
175+
if (unlikely(ext_err))
159176
continue;
160-
this_hwcap |= isa2hwcap[(unsigned char)(*ext)];
161-
this_isa |= (1UL << (*ext - 'a'));
177+
if (!ext_long) {
178+
this_hwcap |= isa2hwcap[(unsigned char)(*ext)];
179+
this_isa |= (1UL << (*ext - 'a'));
180+
}
162181
}
163182

164183
/*

0 commit comments

Comments
 (0)