xref: /openbmc/linux/arch/arm64/include/asm/lse.h (revision 7f400a1d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_LSE_H
3 #define __ASM_LSE_H
4 
5 #include <asm/atomic_ll_sc.h>
6 
7 #ifdef CONFIG_ARM64_LSE_ATOMICS
8 
9 #define __LSE_PREAMBLE	".arch_extension lse\n"
10 
11 #include <linux/compiler_types.h>
12 #include <linux/export.h>
13 #include <linux/stringify.h>
14 #include <asm/alternative.h>
15 #include <asm/alternative-macros.h>
16 #include <asm/atomic_lse.h>
17 #include <asm/cpucaps.h>
18 
19 static __always_inline bool system_uses_lse_atomics(void)
20 {
21 	return alternative_has_feature_likely(ARM64_HAS_LSE_ATOMICS);
22 }
23 
24 #define __lse_ll_sc_body(op, ...)					\
25 ({									\
26 	system_uses_lse_atomics() ?					\
27 		__lse_##op(__VA_ARGS__) :				\
28 		__ll_sc_##op(__VA_ARGS__);				\
29 })
30 
31 /* In-line patching at runtime */
32 #define ARM64_LSE_ATOMIC_INSN(llsc, lse)				\
33 	ALTERNATIVE(llsc, __LSE_PREAMBLE lse, ARM64_HAS_LSE_ATOMICS)
34 
35 #else	/* CONFIG_ARM64_LSE_ATOMICS */
36 
37 static inline bool system_uses_lse_atomics(void) { return false; }
38 
39 #define __lse_ll_sc_body(op, ...)		__ll_sc_##op(__VA_ARGS__)
40 
41 #define ARM64_LSE_ATOMIC_INSN(llsc, lse)	llsc
42 
43 #endif	/* CONFIG_ARM64_LSE_ATOMICS */
44 #endif	/* __ASM_LSE_H */
45