summaryrefslogtreecommitdiff
path: root/src/arch/arm64
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/arm64')
-rw-r--r--src/arch/arm64/include/armv8/arch/smp/spinlock.h25
1 files changed, 24 insertions, 1 deletions
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 <arch/barrier.h>
+#include <stdint.h>
+
+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