1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_LSE_H
3 #define __ASM_LSE_H
4 
5 #if defined(CONFIG_AS_LSE) && defined(CONFIG_ARM64_LSE_ATOMICS)
6 
7 #include <linux/compiler_types.h>
8 #include <linux/export.h>
9 #include <linux/stringify.h>
10 #include <asm/alternative.h>
11 #include <asm/cpucaps.h>
12 
13 #ifdef __ASSEMBLER__
14 
15 .arch_extension	lse
16 
17 .macro alt_lse, llsc, lse
18 	alternative_insn "\llsc", "\lse", ARM64_HAS_LSE_ATOMICS
19 .endm
20 
21 #else	/* __ASSEMBLER__ */
22 
23 __asm__(".arch_extension	lse");
24 
25 /* Move the ll/sc atomics out-of-line */
26 #define __LL_SC_INLINE		notrace
27 #define __LL_SC_PREFIX(x)	__ll_sc_##x
28 #define __LL_SC_EXPORT(x)	EXPORT_SYMBOL(__LL_SC_PREFIX(x))
29 
30 /* Macro for constructing calls to out-of-line ll/sc atomics */
31 #define __LL_SC_CALL(op)	"bl\t" __stringify(__LL_SC_PREFIX(op)) "\n"
32 #define __LL_SC_CLOBBERS	"x16", "x17", "x30"
33 
34 /* In-line patching at runtime */
35 #define ARM64_LSE_ATOMIC_INSN(llsc, lse)				\
36 	ALTERNATIVE(llsc, lse, ARM64_HAS_LSE_ATOMICS)
37 
38 #endif	/* __ASSEMBLER__ */
39 #else	/* CONFIG_AS_LSE && CONFIG_ARM64_LSE_ATOMICS */
40 
41 #ifdef __ASSEMBLER__
42 
43 .macro alt_lse, llsc, lse
44 	\llsc
45 .endm
46 
47 #else	/* __ASSEMBLER__ */
48 
49 #define __LL_SC_INLINE		static inline
50 #define __LL_SC_PREFIX(x)	x
51 #define __LL_SC_EXPORT(x)
52 
53 #define ARM64_LSE_ATOMIC_INSN(llsc, lse)	llsc
54 
55 #endif	/* __ASSEMBLER__ */
56 #endif	/* CONFIG_AS_LSE && CONFIG_ARM64_LSE_ATOMICS */
57 #endif	/* __ASM_LSE_H */
58