spinlock.S 802 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2016, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <asm_macros.S>
  7. .globl spin_lock
  8. .globl spin_unlock
  9. #if ARM_ARCH_AT_LEAST(8, 0)
  10. /*
  11. * According to the ARMv8-A Architecture Reference Manual, "when the global
  12. * monitor for a PE changes from Exclusive Access state to Open Access state,
  13. * an event is generated.". This applies to both AArch32 and AArch64 modes of
  14. * ARMv8-A. As a result, no explicit SEV with unlock is required.
  15. */
  16. #define COND_SEV()
  17. #else
  18. #define COND_SEV() sev
  19. #endif
  20. func spin_lock
  21. mov r2, #1
  22. 1:
  23. ldrex r1, [r0]
  24. cmp r1, #0
  25. wfene
  26. strexeq r1, r2, [r0]
  27. cmpeq r1, #0
  28. bne 1b
  29. dmb
  30. bx lr
  31. endfunc spin_lock
  32. func spin_unlock
  33. mov r1, #0
  34. stl r1, [r0]
  35. COND_SEV()
  36. bx lr
  37. endfunc spin_unlock