blob: 29d0719bd2edd9e1d74d53aa2d6be01a3408af2e [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Will Deaconc09d6a02015-02-03 16:14:13 +00002#ifndef __ASM_LSE_H
3#define __ASM_LSE_H
4
Will Deacon0533f972019-08-29 11:49:10 +01005#include <asm/atomic_ll_sc.h>
6
Ard Biesheuvelbd7d13c2021-07-12 07:49:03 +00007#if defined(CONFIG_ARM64_LSE_ATOMICS) && !defined(BUILD_FIPS140_KO)
Will Deaconc09d6a02015-02-03 16:14:13 +00008
Vincenzo Frascinodd1f6302020-02-18 16:49:06 +00009#define __LSE_PREAMBLE ".arch_extension lse\n"
Will Deaconc09d6a02015-02-03 16:14:13 +000010
Will Deacon8a624f12018-02-19 13:08:56 +000011#include <linux/compiler_types.h>
12#include <linux/export.h>
Will Deacon0533f972019-08-29 11:49:10 +010013#include <linux/jump_label.h>
Will Deaconc09d6a02015-02-03 16:14:13 +000014#include <linux/stringify.h>
Will Deaconc09d6a02015-02-03 16:14:13 +000015#include <asm/alternative.h>
Will Deacon0533f972019-08-29 11:49:10 +010016#include <asm/atomic_lse.h>
Will Deacon8a624f12018-02-19 13:08:56 +000017#include <asm/cpucaps.h>
Will Deaconc09d6a02015-02-03 16:14:13 +000018
Will Deacon0533f972019-08-29 11:49:10 +010019extern struct static_key_false cpu_hwcap_keys[ARM64_NCAPS];
20extern struct static_key_false arm64_const_caps_ready;
21
22static 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 Deaconc09d6a02015-02-03 16:14:13 +000035/* In-line patching at runtime */
36#define ARM64_LSE_ATOMIC_INSN(llsc, lse) \
Sami Tolvanene0d58962019-10-31 12:57:05 -070037 ALTERNATIVE(llsc, __LSE_PREAMBLE lse, ARM64_HAS_LSE_ATOMICS)
Will Deaconc09d6a02015-02-03 16:14:13 +000038
Catalin Marinas395af862020-01-15 11:30:08 +000039#else /* CONFIG_ARM64_LSE_ATOMICS */
Will Deacon084f9032015-02-12 04:17:37 +000040
Will Deacon0533f972019-08-29 11:49:10 +010041static inline bool system_uses_lse_atomics(void) { return false; }
42
43#define __lse_ll_sc_body(op, ...) __ll_sc_##op(__VA_ARGS__)
44
Will Deaconc09d6a02015-02-03 16:14:13 +000045#define ARM64_LSE_ATOMIC_INSN(llsc, lse) llsc
46
Catalin Marinas395af862020-01-15 11:30:08 +000047#endif /* CONFIG_ARM64_LSE_ATOMICS */
Will Deaconc09d6a02015-02-03 16:14:13 +000048#endif /* __ASM_LSE_H */