1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * ARM64 Spinlock support
4  */
5 #include <stdint.h>
6 
7 #include "spinlock.h"
8 
spin_lock(struct spinlock * lock)9 void spin_lock(struct spinlock *lock)
10 {
11 	int val, res;
12 
13 	asm volatile(
14 	"1:	ldaxr	%w0, [%2]\n"
15 	"	cbnz	%w0, 1b\n"
16 	"	mov	%w0, #1\n"
17 	"	stxr	%w1, %w0, [%2]\n"
18 	"	cbnz	%w1, 1b\n"
19 	: "=&r" (val), "=&r" (res)
20 	: "r" (&lock->v)
21 	: "memory");
22 }
23 
spin_unlock(struct spinlock * lock)24 void spin_unlock(struct spinlock *lock)
25 {
26 	asm volatile("stlr wzr, [%0]\n"	: : "r" (&lock->v) : "memory");
27 }
28