Skip to content

Commit c0baf32

Browse files
evangreenpalmer-dabbelt
authored andcommitted
RISC-V: hwprobe: Expose Zba, Zbb, and Zbs
Add two new bits to the IMA_EXT_0 key for ZBA, ZBB, and ZBS extensions. These are accurately reported per CPU. Signed-off-by: Evan Green <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Conor Dooley <[email protected]> Reviewed-by: Heiko Stuebner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 82e9c66 commit c0baf32

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

Documentation/riscv/hwprobe.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ The following keys are defined:
6464
* :c:macro:`RISCV_HWPROBE_IMA_C`: The C extension is supported, as defined
6565
by version 2.2 of the RISC-V ISA manual.
6666

67+
* :c:macro:`RISCV_HWPROBE_EXT_ZBA`: The Zba address generation extension is
68+
supported, as defined in version 1.0 of the Bit-Manipulation ISA
69+
extensions.
70+
71+
* :c:macro:`RISCV_HWPROBE_EXT_ZBB`: The Zbb extension is supported, as defined
72+
in version 1.0 of the Bit-Manipulation ISA extensions.
73+
74+
* :c:macro:`RISCV_HWPROBE_EXT_ZBS`: The Zbs extension is supported, as defined
75+
in version 1.0 of the Bit-Manipulation ISA extensions.
76+
6777
* :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: A bitmask that contains performance
6878
information about the selected set of processors.
6979

arch/riscv/include/uapi/asm/hwprobe.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ struct riscv_hwprobe {
2525
#define RISCV_HWPROBE_KEY_IMA_EXT_0 4
2626
#define RISCV_HWPROBE_IMA_FD (1 << 0)
2727
#define RISCV_HWPROBE_IMA_C (1 << 1)
28+
#define RISCV_HWPROBE_EXT_ZBA (1 << 2)
29+
#define RISCV_HWPROBE_EXT_ZBB (1 << 3)
30+
#define RISCV_HWPROBE_EXT_ZBS (1 << 4)
2831
#define RISCV_HWPROBE_KEY_CPUPERF_0 5
2932
#define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0)
3033
#define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0)

arch/riscv/kernel/sys_riscv.c

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,46 @@ static void hwprobe_arch_id(struct riscv_hwprobe *pair,
121121
pair->value = id;
122122
}
123123

124+
static void hwprobe_isa_ext0(struct riscv_hwprobe *pair,
125+
const struct cpumask *cpus)
126+
{
127+
int cpu;
128+
u64 missing = 0;
129+
130+
pair->value = 0;
131+
if (has_fpu())
132+
pair->value |= RISCV_HWPROBE_IMA_FD;
133+
134+
if (riscv_isa_extension_available(NULL, c))
135+
pair->value |= RISCV_HWPROBE_IMA_C;
136+
137+
/*
138+
* Loop through and record extensions that 1) anyone has, and 2) anyone
139+
* doesn't have.
140+
*/
141+
for_each_cpu(cpu, cpus) {
142+
struct riscv_isainfo *isainfo = &hart_isa[cpu];
143+
144+
if (riscv_isa_extension_available(isainfo->isa, ZBA))
145+
pair->value |= RISCV_HWPROBE_EXT_ZBA;
146+
else
147+
missing |= RISCV_HWPROBE_EXT_ZBA;
148+
149+
if (riscv_isa_extension_available(isainfo->isa, ZBB))
150+
pair->value |= RISCV_HWPROBE_EXT_ZBB;
151+
else
152+
missing |= RISCV_HWPROBE_EXT_ZBB;
153+
154+
if (riscv_isa_extension_available(isainfo->isa, ZBS))
155+
pair->value |= RISCV_HWPROBE_EXT_ZBS;
156+
else
157+
missing |= RISCV_HWPROBE_EXT_ZBS;
158+
}
159+
160+
/* Now turn off reporting features if any CPU is missing it. */
161+
pair->value &= ~missing;
162+
}
163+
124164
static u64 hwprobe_misaligned(const struct cpumask *cpus)
125165
{
126166
int cpu;
@@ -164,13 +204,7 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,
164204
break;
165205

166206
case RISCV_HWPROBE_KEY_IMA_EXT_0:
167-
pair->value = 0;
168-
if (has_fpu())
169-
pair->value |= RISCV_HWPROBE_IMA_FD;
170-
171-
if (riscv_isa_extension_available(NULL, c))
172-
pair->value |= RISCV_HWPROBE_IMA_C;
173-
207+
hwprobe_isa_ext0(pair, cpus);
174208
break;
175209

176210
case RISCV_HWPROBE_KEY_CPUPERF_0:

0 commit comments

Comments
 (0)