Skip to content

Commit 12e7fbb

Browse files
ConchuODAlexandre Ghiti
authored andcommitted
RISC-V: add f & d extension validation checks
Using Clement's new validation callbacks, support checking that dependencies have been satisfied for the floating point extensions. The check for "d" might be slightly confusingly shorter than that of "f", despite "d" depending on "f". This is because the requirement that a hart supporting double precision must also support single precision, should be validated by dt-bindings etc, not the kernel but lack of support for single precision only is a limitation of the kernel. Tested-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Clément Léger <cleger@rivosinc.com> Signed-off-by: Conor Dooley <conor.dooley@microchip.com> Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> Link: https://lore.kernel.org/r/20250312-reptile-platinum-62ee0f444a32@spud Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
1 parent 38077ec commit 12e7fbb

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

arch/riscv/kernel/cpufeature.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,33 @@ static int riscv_ext_zicboz_validate(const struct riscv_isa_ext_data *data,
109109
return 0;
110110
}
111111

112+
static int riscv_ext_f_validate(const struct riscv_isa_ext_data *data,
113+
const unsigned long *isa_bitmap)
114+
{
115+
if (!IS_ENABLED(CONFIG_FPU))
116+
return -EINVAL;
117+
118+
/*
119+
* Due to extension ordering, d is checked before f, so no deferral
120+
* is required.
121+
*/
122+
if (!__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_d)) {
123+
pr_warn_once("This kernel does not support systems with F but not D\n");
124+
return -EINVAL;
125+
}
126+
127+
return 0;
128+
}
129+
130+
static int riscv_ext_d_validate(const struct riscv_isa_ext_data *data,
131+
const unsigned long *isa_bitmap)
132+
{
133+
if (!IS_ENABLED(CONFIG_FPU))
134+
return -EINVAL;
135+
136+
return 0;
137+
}
138+
112139
static int riscv_ext_vector_x_validate(const struct riscv_isa_ext_data *data,
113140
const unsigned long *isa_bitmap)
114141
{
@@ -371,8 +398,8 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
371398
__RISCV_ISA_EXT_DATA(i, RISCV_ISA_EXT_i),
372399
__RISCV_ISA_EXT_DATA(m, RISCV_ISA_EXT_m),
373400
__RISCV_ISA_EXT_DATA(a, RISCV_ISA_EXT_a),
374-
__RISCV_ISA_EXT_DATA(f, RISCV_ISA_EXT_f),
375-
__RISCV_ISA_EXT_DATA(d, RISCV_ISA_EXT_d),
401+
__RISCV_ISA_EXT_DATA_VALIDATE(f, RISCV_ISA_EXT_f, riscv_ext_f_validate),
402+
__RISCV_ISA_EXT_DATA_VALIDATE(d, RISCV_ISA_EXT_d, riscv_ext_d_validate),
376403
__RISCV_ISA_EXT_DATA(q, RISCV_ISA_EXT_q),
377404
__RISCV_ISA_EXT_SUPERSET(c, RISCV_ISA_EXT_c, riscv_c_exts),
378405
__RISCV_ISA_EXT_SUPERSET_VALIDATE(v, RISCV_ISA_EXT_v, riscv_v_exts, riscv_ext_vector_float_validate),

0 commit comments

Comments
 (0)