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