Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Will Deacon | c09d6a0 | 2015-02-03 16:14:13 +0000 | [diff] [blame] | 2 | #ifndef __ASM_LSE_H |
| 3 | #define __ASM_LSE_H |
| 4 | |
Will Deacon | 0533f97 | 2019-08-29 11:49:10 +0100 | [diff] [blame] | 5 | #include <asm/atomic_ll_sc.h> |
| 6 | |
Ard Biesheuvel | bd7d13c | 2021-07-12 07:49:03 +0000 | [diff] [blame] | 7 | #if defined(CONFIG_ARM64_LSE_ATOMICS) && !defined(BUILD_FIPS140_KO) |
Will Deacon | c09d6a0 | 2015-02-03 16:14:13 +0000 | [diff] [blame] | 8 | |
Vincenzo Frascino | dd1f630 | 2020-02-18 16:49:06 +0000 | [diff] [blame] | 9 | #define __LSE_PREAMBLE ".arch_extension lse\n" |
Will Deacon | c09d6a0 | 2015-02-03 16:14:13 +0000 | [diff] [blame] | 10 | |
Will Deacon | 8a624f1 | 2018-02-19 13:08:56 +0000 | [diff] [blame] | 11 | #include <linux/compiler_types.h> |
| 12 | #include <linux/export.h> |
Will Deacon | 0533f97 | 2019-08-29 11:49:10 +0100 | [diff] [blame] | 13 | #include <linux/jump_label.h> |
Will Deacon | c09d6a0 | 2015-02-03 16:14:13 +0000 | [diff] [blame] | 14 | #include <linux/stringify.h> |
Will Deacon | c09d6a0 | 2015-02-03 16:14:13 +0000 | [diff] [blame] | 15 | #include <asm/alternative.h> |
Will Deacon | 0533f97 | 2019-08-29 11:49:10 +0100 | [diff] [blame] | 16 | #include <asm/atomic_lse.h> |
Will Deacon | 8a624f1 | 2018-02-19 13:08:56 +0000 | [diff] [blame] | 17 | #include <asm/cpucaps.h> |
Will Deacon | c09d6a0 | 2015-02-03 16:14:13 +0000 | [diff] [blame] | 18 | |
Will Deacon | 0533f97 | 2019-08-29 11:49:10 +0100 | [diff] [blame] | 19 | extern struct static_key_false cpu_hwcap_keys[ARM64_NCAPS]; |
| 20 | extern struct static_key_false arm64_const_caps_ready; |
| 21 | |
| 22 | static inline bool system_uses_lse_atomics(void) |
| 23 | { |
| 24 | return (static_branch_likely(&arm64_const_caps_ready)) && |
| 25 | static_branch_likely(&cpu_hwcap_keys[ARM64_HAS_LSE_ATOMICS]); |
| 26 | } |
| 27 | |
| 28 | #define __lse_ll_sc_body(op, ...) \ |
| 29 | ({ \ |
| 30 | system_uses_lse_atomics() ? \ |
| 31 | __lse_##op(__VA_ARGS__) : \ |
| 32 | __ll_sc_##op(__VA_ARGS__); \ |
| 33 | }) |
| 34 | |
Will Deacon | c09d6a0 | 2015-02-03 16:14:13 +0000 | [diff] [blame] | 35 | /* In-line patching at runtime */ |
| 36 | #define ARM64_LSE_ATOMIC_INSN(llsc, lse) \ |
Sami Tolvanen | e0d5896 | 2019-10-31 12:57:05 -0700 | [diff] [blame] | 37 | ALTERNATIVE(llsc, __LSE_PREAMBLE lse, ARM64_HAS_LSE_ATOMICS) |
Will Deacon | c09d6a0 | 2015-02-03 16:14:13 +0000 | [diff] [blame] | 38 | |
Catalin Marinas | 395af86 | 2020-01-15 11:30:08 +0000 | [diff] [blame] | 39 | #else /* CONFIG_ARM64_LSE_ATOMICS */ |
Will Deacon | 084f903 | 2015-02-12 04:17:37 +0000 | [diff] [blame] | 40 | |
Will Deacon | 0533f97 | 2019-08-29 11:49:10 +0100 | [diff] [blame] | 41 | static inline bool system_uses_lse_atomics(void) { return false; } |
| 42 | |
| 43 | #define __lse_ll_sc_body(op, ...) __ll_sc_##op(__VA_ARGS__) |
| 44 | |
Will Deacon | c09d6a0 | 2015-02-03 16:14:13 +0000 | [diff] [blame] | 45 | #define ARM64_LSE_ATOMIC_INSN(llsc, lse) llsc |
| 46 | |
Catalin Marinas | 395af86 | 2020-01-15 11:30:08 +0000 | [diff] [blame] | 47 | #endif /* CONFIG_ARM64_LSE_ATOMICS */ |
Will Deacon | c09d6a0 | 2015-02-03 16:14:13 +0000 | [diff] [blame] | 48 | #endif /* __ASM_LSE_H */ |