From dbab8cbc31ffbcf4193defae4e8fd7d26e8ae519 Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Sat, 6 Sep 2014 01:24:38 -0500 Subject: [PATCH] arm64: add spinlock implementation Provide a simple spinlock implentation for arm64. A value of 0 is unlocked and a value of 1 is locked. BUG=chrome-os-partner:31761 BRANCH=None TEST=Built and ran SMP bringup on ryu. Change-Id: Ie88a715a6b51cd38a5fdd830583dae528cc49d67 Signed-off-by: Patrick Georgi Original-Commit-Id: 14dab94610c96d6b1530c64d661833f8e613101c Original-Change-Id: I3bf2d80b91112d04442455ff0fa3f16900b7327f Original-Signed-off-by: Aaron Durbin Original-Reviewed-on: https://chromium-review.googlesource.com/216923 Original-Reviewed-by: Furquan Shaikh Reviewed-on: http://review.coreboot.org/9040 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer --- .../arm64/include/armv8/arch/smp/spinlock.h | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/arch/arm64/include/armv8/arch/smp/spinlock.h b/src/arch/arm64/include/armv8/arch/smp/spinlock.h index 8a89d1f011..10278e72ae 100644 --- a/src/arch/arm64/include/armv8/arch/smp/spinlock.h +++ b/src/arch/arm64/include/armv8/arch/smp/spinlock.h @@ -1,6 +1,29 @@ #ifndef ARCH_SMP_SPINLOCK_H #define ARCH_SMP_SPINLOCK_H -#error "spinlocks: implement this for ARM64" +#include +#include + +typedef struct { + volatile uint32_t lock; +} spinlock_t; + +#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 } +#define DECLARE_SPIN_LOCK(x) static spinlock_t x = SPIN_LOCK_UNLOCKED; + +static inline void spin_lock(spinlock_t *spin) +{ + while (1) { + if (load_acquire_exclusive(&spin->lock) != 0) + continue; + if (store_release_exclusive(&spin->lock, 1)) + break; + } +} + +static inline void spin_unlock(spinlock_t *spin) +{ + store_release(&spin->lock, 0); +} #endif