xref: /linux/arch/arm64/include/asm/cpucaps.h (revision 0678df8271820bcf8fb4f877129f05d68a237de4)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef __ASM_CPUCAPS_H
4 #define __ASM_CPUCAPS_H
5 
6 #include <asm/cpucap-defs.h>
7 
8 #ifndef __ASSEMBLY__
9 #include <linux/types.h>
10 /*
11  * Check whether a cpucap is possible at compiletime.
12  */
13 static __always_inline bool
14 cpucap_is_possible(const unsigned int cap)
15 {
16 	compiletime_assert(__builtin_constant_p(cap),
17 			   "cap must be a constant");
18 	compiletime_assert(cap < ARM64_NCAPS,
19 			   "cap must be < ARM64_NCAPS");
20 
21 	switch (cap) {
22 	case ARM64_HAS_PAN:
23 		return IS_ENABLED(CONFIG_ARM64_PAN);
24 	case ARM64_HAS_EPAN:
25 		return IS_ENABLED(CONFIG_ARM64_EPAN);
26 	case ARM64_SVE:
27 		return IS_ENABLED(CONFIG_ARM64_SVE);
28 	case ARM64_SME:
29 	case ARM64_SME2:
30 	case ARM64_SME_FA64:
31 		return IS_ENABLED(CONFIG_ARM64_SME);
32 	case ARM64_HAS_CNP:
33 		return IS_ENABLED(CONFIG_ARM64_CNP);
34 	case ARM64_HAS_ADDRESS_AUTH:
35 	case ARM64_HAS_GENERIC_AUTH:
36 		return IS_ENABLED(CONFIG_ARM64_PTR_AUTH);
37 	case ARM64_HAS_GIC_PRIO_MASKING:
38 		return IS_ENABLED(CONFIG_ARM64_PSEUDO_NMI);
39 	case ARM64_MTE:
40 		return IS_ENABLED(CONFIG_ARM64_MTE);
41 	case ARM64_BTI:
42 		return IS_ENABLED(CONFIG_ARM64_BTI);
43 	case ARM64_HAS_TLB_RANGE:
44 		return IS_ENABLED(CONFIG_ARM64_TLB_RANGE);
45 	case ARM64_UNMAP_KERNEL_AT_EL0:
46 		return IS_ENABLED(CONFIG_UNMAP_KERNEL_AT_EL0);
47 	case ARM64_WORKAROUND_843419:
48 		return IS_ENABLED(CONFIG_ARM64_ERRATUM_843419);
49 	case ARM64_WORKAROUND_1742098:
50 		return IS_ENABLED(CONFIG_ARM64_ERRATUM_1742098);
51 	case ARM64_WORKAROUND_2645198:
52 		return IS_ENABLED(CONFIG_ARM64_ERRATUM_2645198);
53 	case ARM64_WORKAROUND_2658417:
54 		return IS_ENABLED(CONFIG_ARM64_ERRATUM_2658417);
55 	case ARM64_WORKAROUND_CAVIUM_23154:
56 		return IS_ENABLED(CONFIG_CAVIUM_ERRATUM_23154);
57 	case ARM64_WORKAROUND_NVIDIA_CARMEL_CNP:
58 		return IS_ENABLED(CONFIG_NVIDIA_CARMEL_CNP_ERRATUM);
59 	case ARM64_WORKAROUND_REPEAT_TLBI:
60 		return IS_ENABLED(CONFIG_ARM64_WORKAROUND_REPEAT_TLBI);
61 	}
62 
63 	return true;
64 }
65 #endif /* __ASSEMBLY__ */
66 
67 #endif /* __ASM_CPUCAPS_H */
68