blob: 9492cc0813a7dc41d3bb2d3d47e16c6d4c7f22d7 [file] [log] [blame]
Soby Mathew748be1d2016-05-05 14:10:46 +01001/*
2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathew748be1d2016-05-05 14:10:46 +01005 */
6
7#include <asm_macros.S>
8
9 .globl spin_lock
10 .globl spin_unlock
11
Etienne Carriere70b1c2f2017-11-05 22:55:47 +010012#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
Soby Mathew748be1d2016-05-05 14:10:46 +010023
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]
Etienne Carriere70b1c2f2017-11-05 22:55:47 +010041 COND_SEV()
Soby Mathew748be1d2016-05-05 14:10:46 +010042 bx lr
43endfunc spin_unlock