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