xref: /openbmc/linux/arch/riscv/include/asm/hwcap.h (revision bbb774d9)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copied from arch/arm64/include/asm/hwcap.h
4  *
5  * Copyright (C) 2012 ARM Ltd.
6  * Copyright (C) 2017 SiFive
7  */
8 #ifndef _ASM_RISCV_HWCAP_H
9 #define _ASM_RISCV_HWCAP_H
10 
11 #include <asm/errno.h>
12 #include <linux/bits.h>
13 #include <uapi/asm/hwcap.h>
14 
15 #ifndef __ASSEMBLY__
16 #include <linux/jump_label.h>
17 /*
18  * This yields a mask that user programs can use to figure out what
19  * instruction set this cpu supports.
20  */
21 #define ELF_HWCAP		(elf_hwcap)
22 
23 enum {
24 	CAP_HWCAP = 1,
25 };
26 
27 extern unsigned long elf_hwcap;
28 
29 #define RISCV_ISA_EXT_a		('a' - 'a')
30 #define RISCV_ISA_EXT_c		('c' - 'a')
31 #define RISCV_ISA_EXT_d		('d' - 'a')
32 #define RISCV_ISA_EXT_f		('f' - 'a')
33 #define RISCV_ISA_EXT_h		('h' - 'a')
34 #define RISCV_ISA_EXT_i		('i' - 'a')
35 #define RISCV_ISA_EXT_m		('m' - 'a')
36 #define RISCV_ISA_EXT_s		('s' - 'a')
37 #define RISCV_ISA_EXT_u		('u' - 'a')
38 
39 /*
40  * Increse this to higher value as kernel support more ISA extensions.
41  */
42 #define RISCV_ISA_EXT_MAX	64
43 #define RISCV_ISA_EXT_NAME_LEN_MAX 32
44 
45 /* The base ID for multi-letter ISA extensions */
46 #define RISCV_ISA_EXT_BASE 26
47 
48 /*
49  * This enum represent the logical ID for each multi-letter RISC-V ISA extension.
50  * The logical ID should start from RISCV_ISA_EXT_BASE and must not exceed
51  * RISCV_ISA_EXT_MAX. 0-25 range is reserved for single letter
52  * extensions while all the multi-letter extensions should define the next
53  * available logical extension id.
54  */
55 enum riscv_isa_ext_id {
56 	RISCV_ISA_EXT_SSCOFPMF = RISCV_ISA_EXT_BASE,
57 	RISCV_ISA_EXT_SVPBMT,
58 	RISCV_ISA_EXT_ZICBOM,
59 	RISCV_ISA_EXT_ZIHINTPAUSE,
60 	RISCV_ISA_EXT_SSTC,
61 	RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX,
62 };
63 
64 /*
65  * This enum represents the logical ID for each RISC-V ISA extension static
66  * keys. We can use static key to optimize code path if some ISA extensions
67  * are available.
68  */
69 enum riscv_isa_ext_key {
70 	RISCV_ISA_EXT_KEY_FPU,		/* For 'F' and 'D' */
71 	RISCV_ISA_EXT_KEY_ZIHINTPAUSE,
72 	RISCV_ISA_EXT_KEY_MAX,
73 };
74 
75 struct riscv_isa_ext_data {
76 	/* Name of the extension displayed to userspace via /proc/cpuinfo */
77 	char uprop[RISCV_ISA_EXT_NAME_LEN_MAX];
78 	/* The logical ISA extension ID */
79 	unsigned int isa_ext_id;
80 };
81 
82 extern struct static_key_false riscv_isa_ext_keys[RISCV_ISA_EXT_KEY_MAX];
83 
84 static __always_inline int riscv_isa_ext2key(int num)
85 {
86 	switch (num) {
87 	case RISCV_ISA_EXT_f:
88 		return RISCV_ISA_EXT_KEY_FPU;
89 	case RISCV_ISA_EXT_d:
90 		return RISCV_ISA_EXT_KEY_FPU;
91 	case RISCV_ISA_EXT_ZIHINTPAUSE:
92 		return RISCV_ISA_EXT_KEY_ZIHINTPAUSE;
93 	default:
94 		return -EINVAL;
95 	}
96 }
97 
98 unsigned long riscv_isa_extension_base(const unsigned long *isa_bitmap);
99 
100 #define riscv_isa_extension_mask(ext) BIT_MASK(RISCV_ISA_EXT_##ext)
101 
102 bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, int bit);
103 #define riscv_isa_extension_available(isa_bitmap, ext)	\
104 	__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_##ext)
105 
106 #endif
107 
108 #endif /* _ASM_RISCV_HWCAP_H */
109