RISC-V: Use the extension probing code to enable the FPU
This pull the static key management code for the FPU into the generic ISA extension probing code, so it can be used by other extensions that need static keys. * 'riscv-static_key' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/palmer/linux: riscv: switch has_fpu() to the unified static key mechanism riscv: introduce unified static key mechanism for ISA extensions
This commit is contained in:
commit
89793a61d8
|
@ -12,6 +12,7 @@
|
|||
#include <uapi/asm/hwcap.h>
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
#include <linux/jump_label.h>
|
||||
/*
|
||||
* This yields a mask that user programs can use to figure out what
|
||||
* instruction set this cpu supports.
|
||||
|
@ -56,6 +57,16 @@ enum riscv_isa_ext_id {
|
|||
RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX,
|
||||
};
|
||||
|
||||
/*
|
||||
* This enum represents the logical ID for each RISC-V ISA extension static
|
||||
* keys. We can use static key to optimize code path if some ISA extensions
|
||||
* are available.
|
||||
*/
|
||||
enum riscv_isa_ext_key {
|
||||
RISCV_ISA_EXT_KEY_FPU, /* For 'F' and 'D' */
|
||||
RISCV_ISA_EXT_KEY_MAX,
|
||||
};
|
||||
|
||||
struct riscv_isa_ext_data {
|
||||
/* Name of the extension displayed to userspace via /proc/cpuinfo */
|
||||
char uprop[RISCV_ISA_EXT_NAME_LEN_MAX];
|
||||
|
@ -63,6 +74,20 @@ struct riscv_isa_ext_data {
|
|||
unsigned int isa_ext_id;
|
||||
};
|
||||
|
||||
extern struct static_key_false riscv_isa_ext_keys[RISCV_ISA_EXT_KEY_MAX];
|
||||
|
||||
static __always_inline int riscv_isa_ext2key(int num)
|
||||
{
|
||||
switch (num) {
|
||||
case RISCV_ISA_EXT_f:
|
||||
return RISCV_ISA_EXT_KEY_FPU;
|
||||
case RISCV_ISA_EXT_d:
|
||||
return RISCV_ISA_EXT_KEY_FPU;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long riscv_isa_extension_base(const unsigned long *isa_bitmap);
|
||||
|
||||
#define riscv_isa_extension_mask(ext) BIT_MASK(RISCV_ISA_EXT_##ext)
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <linux/jump_label.h>
|
||||
#include <linux/sched/task_stack.h>
|
||||
#include <asm/hwcap.h>
|
||||
#include <asm/processor.h>
|
||||
#include <asm/ptrace.h>
|
||||
#include <asm/csr.h>
|
||||
|
@ -56,10 +57,9 @@ static inline void __switch_to_aux(struct task_struct *prev,
|
|||
fstate_restore(next, task_pt_regs(next));
|
||||
}
|
||||
|
||||
extern struct static_key_false cpu_hwcap_fpu;
|
||||
static __always_inline bool has_fpu(void)
|
||||
{
|
||||
return static_branch_likely(&cpu_hwcap_fpu);
|
||||
return static_branch_likely(&riscv_isa_ext_keys[RISCV_ISA_EXT_KEY_FPU]);
|
||||
}
|
||||
#else
|
||||
static __always_inline bool has_fpu(void) { return false; }
|
||||
|
|
|
@ -27,9 +27,8 @@ unsigned long elf_hwcap __read_mostly;
|
|||
/* Host ISA bitmap */
|
||||
static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;
|
||||
|
||||
#ifdef CONFIG_FPU
|
||||
__ro_after_init DEFINE_STATIC_KEY_FALSE(cpu_hwcap_fpu);
|
||||
#endif
|
||||
__ro_after_init DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
|
||||
EXPORT_SYMBOL(riscv_isa_ext_keys);
|
||||
|
||||
/**
|
||||
* riscv_isa_extension_base() - Get base extension word
|
||||
|
@ -238,10 +237,11 @@ void __init riscv_fill_hwcap(void)
|
|||
print_str[j++] = (char)('a' + i);
|
||||
pr_info("riscv: ELF capabilities %s\n", print_str);
|
||||
|
||||
#ifdef CONFIG_FPU
|
||||
if (elf_hwcap & (COMPAT_HWCAP_ISA_F | COMPAT_HWCAP_ISA_D))
|
||||
static_branch_enable(&cpu_hwcap_fpu);
|
||||
#endif
|
||||
for_each_set_bit(i, riscv_isa, RISCV_ISA_EXT_MAX) {
|
||||
j = riscv_isa_ext2key(i);
|
||||
if (j >= 0)
|
||||
static_branch_enable(&riscv_isa_ext_keys[j]);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_RISCV_ALTERNATIVE
|
||||
|
|
Loading…
Reference in New Issue