lse.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_LSE_H
  3. #define __ASM_LSE_H
  4. #include <asm/atomic_ll_sc.h>
  5. #if defined(CONFIG_ARM64_LSE_ATOMICS) && !defined(BUILD_FIPS140_KO)
  6. #define __LSE_PREAMBLE ".arch_extension lse\n"
  7. #include <linux/compiler_types.h>
  8. #include <linux/export.h>
  9. #include <linux/jump_label.h>
  10. #include <linux/stringify.h>
  11. #include <asm/alternative.h>
  12. #include <asm/alternative-macros.h>
  13. #include <asm/atomic_lse.h>
  14. #include <asm/cpucaps.h>
  15. static __always_inline bool system_uses_lse_atomics(void)
  16. {
  17. return alternative_has_feature_likely(ARM64_HAS_LSE_ATOMICS);
  18. }
  19. #define __lse_ll_sc_body(op, ...) \
  20. ({ \
  21. system_uses_lse_atomics() ? \
  22. __lse_##op(__VA_ARGS__) : \
  23. __ll_sc_##op(__VA_ARGS__); \
  24. })
  25. /* In-line patching at runtime */
  26. #define ARM64_LSE_ATOMIC_INSN(llsc, lse) \
  27. ALTERNATIVE(llsc, __LSE_PREAMBLE lse, ARM64_HAS_LSE_ATOMICS)
  28. #else /* CONFIG_ARM64_LSE_ATOMICS */
  29. static inline bool system_uses_lse_atomics(void) { return false; }
  30. #define __lse_ll_sc_body(op, ...) __ll_sc_##op(__VA_ARGS__)
  31. #define ARM64_LSE_ATOMIC_INSN(llsc, lse) llsc
  32. #endif /* CONFIG_ARM64_LSE_ATOMICS */
  33. #endif /* __ASM_LSE_H */