Skip to content
Closed
46 changes: 41 additions & 5 deletions Documentation/arch/riscv/hwprobe.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ The following keys are defined:
programs (it may still be executed in userspace via a
kernel-controlled mechanism such as the vDSO).

* :c:macro:`RISCV_HWPROBE_BASE_BEHAVIOR_RVA23U64`: Support for all mandatory
extensions of RVA23U64, as defined in the RISC-V Profiles specification
starting from commit 0273f3c921b6 ("rva23/rvb23 ratified").

The RVA23U64 base is based upon the IMA base and therefore IMA extension
keys (e.g. :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_0`:) may be used to probe
optional extensions.

* :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_0`: A bitmask containing extensions
that are compatible with the :c:macro:`RISCV_HWPROBE_BASE_BEHAVIOR_IMA`:
base system behavior.
Expand Down Expand Up @@ -289,6 +297,10 @@ The following keys are defined:
defined in the RISC-V ISA manual starting from commit f88abf1 ("Integrating
load/store pair for RV32 with the main manual") of the riscv-isa-manual.

* :c:macro:`RISCV_HWPROBE_EXT_ZICCLSM`: The Zicclsm extension is supported,
as defined in the RISC-V Profiles specification starting from commit
b1d80660 ("Updated to ratified state.")

* :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: Deprecated. Returns similar values to
:c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF`, but the key was
mistakenly classified as a bitmask rather than a value.
Expand Down Expand Up @@ -358,7 +370,7 @@ The following keys are defined:

* :c:macro:`RISCV_HWPROBE_VENDOR_EXT_XTHEADVECTOR`: The xtheadvector vendor
extension is supported in the T-Head ISA extensions spec starting from
commit a18c801634 ("Add T-Head VECTOR vendor extension. ").
commit a18c801634 ("Add T-Head VECTOR vendor extension. ").

* :c:macro:`RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE`: An unsigned int which
represents the size of the Zicbom block in bytes.
Expand All @@ -371,23 +383,47 @@ The following keys are defined:

* :c:macro:`RISCV_HWPROBE_VENDOR_EXT_XSFVQMACCDOD`: The Xsfqmaccdod vendor
extension is supported in version 1.1 of SiFive Int8 Matrix Multiplication
Extensions Specification.
Extensions Specification.

* :c:macro:`RISCV_HWPROBE_VENDOR_EXT_XSFVQMACCQOQ`: The Xsfqmaccqoq vendor
extension is supported in version 1.1 of SiFive Int8 Matrix Multiplication
Instruction Extensions Specification.
Instruction Extensions Specification.

* :c:macro:`RISCV_HWPROBE_VENDOR_EXT_XSFVFNRCLIPXFQF`: The Xsfvfnrclipxfqf
vendor extension is supported in version 1.0 of SiFive FP32-to-int8 Ranged
Clip Instructions Extensions Specification.
Clip Instructions Extensions Specification.

* :c:macro:`RISCV_HWPROBE_VENDOR_EXT_XSFVFWMACCQQQ`: The Xsfvfwmaccqqq
vendor extension is supported in version 1.0 of Matrix Multiply Accumulate
Instruction Extensions Specification.
Instruction Extensions Specification.

* :c:macro:`RISCV_HWPROBE_KEY_ZICBOP_BLOCK_SIZE`: An unsigned int which
represents the size of the Zicbop block in bytes.

* :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_1`: A bitmask containing additional
extensions that are compatible with the
:c:macro:`RISCV_HWPROBE_BASE_BEHAVIOR_IMA`: base system behavior.

* :c:macro:`RISCV_HWPROBE_EXT_ZICFISS`: The Zicfiss extension is supported,
as defined in version 1.0 of the RISC-V Control-flow Integrity (CFI)
extensions specification, ratified 2024-07.

* :c:macro:`RISCV_HWPROBE_EXT_ZICCAMOA`: The Ziccamoa extension is supported,
as defined in the RISC-V Profiles specification starting from commit
b1d80660 ("Updated to ratified state.")

* :c:macro:`RISCV_HWPROBE_EXT_ZICCIF`: The Ziccif extension is supported,
as defined in the RISC-V Profiles specification starting from commit
b1d80660 ("Updated to ratified state.")

* :c:macro:`RISCV_HWPROBE_EXT_ZICCRSE`: The Ziccrse extension is supported,
as defined in the RISC-V Profiles specification starting from commit
b1d80660 ("Updated to ratified state.")

* :c:macro:`RISCV_HWPROBE_EXT_ZA64RS`: The Za64rs extension is supported,
as defined in the RISC-V Profiles specification starting from commit
b1d80660 ("Updated to ratified state.")

* :c:macro:`RISCV_HWPROBE_EXT_B`: The B extension is supported, as defined
in version 1.0 of the Bit-Manipulation ISA extensions, and implies the
presence of the Zba, Zbb, and Zbs sub-extensions.
14 changes: 14 additions & 0 deletions arch/riscv/include/asm/cpufeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,24 @@ struct riscv_cpuinfo {
unsigned long mimpid;
};

enum {
RISCV_ISA_BASE_IMA,
RISCV_ISA_BASE_RVA23U64,
RISCV_NR_ISA_BASES,
};

/**
* struct riscv_isainfo - per-hart ISA state
* @isa: bitmap of ISA extensions this hart implements
* @isa_bases: bitmap of profile bases this hart conforms to
*/
struct riscv_isainfo {
DECLARE_BITMAP(isa, RISCV_ISA_EXT_MAX);
DECLARE_BITMAP(isa_bases, RISCV_NR_ISA_BASES);
};

extern unsigned long riscv_isa_bases[BITS_TO_LONGS(RISCV_NR_ISA_BASES)];

DECLARE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);

extern const struct seq_operations cpuinfo_op;
Expand Down
23 changes: 14 additions & 9 deletions arch/riscv/include/asm/hwcap.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@

#include <uapi/asm/hwcap.h>

#define RISCV_ISA_EXT_a ('a' - 'a')
#define RISCV_ISA_EXT_c ('c' - 'a')
#define RISCV_ISA_EXT_d ('d' - 'a')
#define RISCV_ISA_EXT_f ('f' - 'a')
#define RISCV_ISA_EXT_h ('h' - 'a')
#define RISCV_ISA_EXT_i ('i' - 'a')
#define RISCV_ISA_EXT_m ('m' - 'a')
#define RISCV_ISA_EXT_q ('q' - 'a')
#define RISCV_ISA_EXT_v ('v' - 'a')
#define RISCV_ISA_EXT_A ('a' - 'a')
#define RISCV_ISA_EXT_B ('b' - 'a')
#define RISCV_ISA_EXT_C ('c' - 'a')
#define RISCV_ISA_EXT_D ('d' - 'a')
#define RISCV_ISA_EXT_F ('f' - 'a')
#define RISCV_ISA_EXT_H ('h' - 'a')
#define RISCV_ISA_EXT_I ('i' - 'a')
#define RISCV_ISA_EXT_M ('m' - 'a')
#define RISCV_ISA_EXT_Q ('q' - 'a')
#define RISCV_ISA_EXT_V ('v' - 'a')

/*
* These macros represent the logical IDs of each multi-letter RISC-V ISA
Expand Down Expand Up @@ -112,6 +113,10 @@
#define RISCV_ISA_EXT_ZCLSD 103
#define RISCV_ISA_EXT_ZICFILP 104
#define RISCV_ISA_EXT_ZICFISS 105
#define RISCV_ISA_EXT_ZICCLSM 106
#define RISCV_ISA_EXT_ZICCAMOA 107
#define RISCV_ISA_EXT_ZICCIF 108
#define RISCV_ISA_EXT_ZA64RS 109

#define RISCV_ISA_EXT_XLINUXENVCFG 127

Expand Down
4 changes: 4 additions & 0 deletions arch/riscv/include/asm/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ long set_tagged_addr_ctrl(struct task_struct *task, unsigned long arg);
long get_tagged_addr_ctrl(struct task_struct *task);
#define SET_TAGGED_ADDR_CTRL(arg) set_tagged_addr_ctrl(current, arg)
#define GET_TAGGED_ADDR_CTRL() get_tagged_addr_ctrl(current)

bool riscv_have_user_pmlen(u8 len);
#else
static inline bool riscv_have_user_pmlen(u8 len) { return false; }
#endif

#endif /* __ASSEMBLER__ */
Expand Down
4 changes: 2 additions & 2 deletions arch/riscv/include/asm/switch_to.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ static inline void __switch_to_fpu(struct task_struct *prev,

static __always_inline bool has_fpu(void)
{
return riscv_has_extension_likely(RISCV_ISA_EXT_f) ||
riscv_has_extension_likely(RISCV_ISA_EXT_d);
return riscv_has_extension_likely(RISCV_ISA_EXT_F) ||
riscv_has_extension_likely(RISCV_ISA_EXT_D);
}
#else
static __always_inline bool has_fpu(void) { return false; }
Expand Down
1 change: 1 addition & 0 deletions arch/riscv/include/uapi/asm/hwcap.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define COMPAT_HWCAP_ISA_F (1 << ('F' - 'A'))
#define COMPAT_HWCAP_ISA_D (1 << ('D' - 'A'))
#define COMPAT_HWCAP_ISA_C (1 << ('C' - 'A'))
#define COMPAT_HWCAP_ISA_B (1 << ('B' - 'A'))
#define COMPAT_HWCAP_ISA_V (1 << ('V' - 'A'))

#endif /* _UAPI_ASM_RISCV_HWCAP_H */
9 changes: 8 additions & 1 deletion arch/riscv/include/uapi/asm/hwprobe.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ struct riscv_hwprobe {
#define RISCV_HWPROBE_KEY_MARCHID 1
#define RISCV_HWPROBE_KEY_MIMPID 2
#define RISCV_HWPROBE_KEY_BASE_BEHAVIOR 3
#define RISCV_HWPROBE_BASE_BEHAVIOR_IMA (1 << 0)
#define RISCV_HWPROBE_BASE_BEHAVIOR_IMA (1 << 0)
#define RISCV_HWPROBE_BASE_BEHAVIOR_RVA23U64 (1 << 1)
#define RISCV_HWPROBE_KEY_IMA_EXT_0 4
#define RISCV_HWPROBE_IMA_FD (1 << 0)
#define RISCV_HWPROBE_IMA_C (1 << 1)
Expand Down Expand Up @@ -116,6 +117,12 @@ struct riscv_hwprobe {
#define RISCV_HWPROBE_KEY_ZICBOP_BLOCK_SIZE 15
#define RISCV_HWPROBE_KEY_IMA_EXT_1 16
#define RISCV_HWPROBE_EXT_ZICFISS (1ULL << 0)
#define RISCV_HWPROBE_EXT_ZICCLSM (1ULL << 1)
#define RISCV_HWPROBE_EXT_ZICCAMOA (1ULL << 2)
#define RISCV_HWPROBE_EXT_ZICCIF (1ULL << 3)
#define RISCV_HWPROBE_EXT_ZICCRSE (1ULL << 4)
#define RISCV_HWPROBE_EXT_ZA64RS (1ULL << 5)
#define RISCV_HWPROBE_EXT_B (1ULL << 6)

/* Increase RISCV_HWPROBE_MAX_KEY when adding items. */

Expand Down
26 changes: 26 additions & 0 deletions arch/riscv/kernel/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,26 @@ static void print_mmu(struct seq_file *f)
seq_printf(f, "mmu\t\t: %s\n", sv_type);
}

static const char * const riscv_isa_base_names[] = {
#ifdef CONFIG_32BIT
[RISCV_ISA_BASE_IMA] = "rv32ima",
#else
[RISCV_ISA_BASE_IMA] = "rv64ima",
#endif
[RISCV_ISA_BASE_RVA23U64] = "rva23u64",
};

static void print_isa_bases(struct seq_file *m, const unsigned long *isa_bases)
{
unsigned int i;

for (i = 0; i < RISCV_NR_ISA_BASES; i++) {
if (test_bit(i, isa_bases))
seq_printf(m, " %s", riscv_isa_base_names[i]);
}
seq_puts(m, "\n");
}

static void *c_start(struct seq_file *m, loff_t *pos)
{
if (*pos == nr_cpu_ids)
Expand Down Expand Up @@ -336,6 +356,9 @@ static int c_show(struct seq_file *m, void *v)
seq_printf(m, "processor\t: %lu\n", cpu_id);
seq_printf(m, "hart\t\t: %lu\n", cpuid_to_hartid_map(cpu_id));

seq_puts(m, "isa bases\t:");
print_isa_bases(m, riscv_isa_bases);

/*
* For historical raisins, the isa: line is limited to the lowest common
* denominator of extensions supported across all harts. A true list of
Expand All @@ -360,6 +383,9 @@ static int c_show(struct seq_file *m, void *v)
seq_printf(m, "marchid\t\t: 0x%lx\n", ci->marchid);
seq_printf(m, "mimpid\t\t: 0x%lx\n", ci->mimpid);

seq_puts(m, "hart isa bases\t:");
print_isa_bases(m, hart_isa[cpu_id].isa_bases);

/*
* Print the ISA extensions specific to this hart, which may show
* additional extensions not present across all harts.
Expand Down
Loading
Loading