summaryrefslogtreecommitdiff
path: root/include/sbi/riscv_locks.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/sbi/riscv_locks.h')
-rw-r--r--include/sbi/riscv_locks.h33
1 files changed, 22 insertions, 11 deletions
diff --git a/include/sbi/riscv_locks.h b/include/sbi/riscv_locks.h
index faa9676..492935f 100644
--- a/include/sbi/riscv_locks.h
+++ b/include/sbi/riscv_locks.h
@@ -2,26 +2,37 @@
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2019 Western Digital Corporation or its affiliates.
- *
- * Authors:
- * Anup Patel <anup.patel@wdc.com>
+ * Copyright (c) 2021 Christoph Müllner <cmuellner@linux.com>
*/
#ifndef __RISCV_LOCKS_H__
#define __RISCV_LOCKS_H__
+#include <sbi/sbi_types.h>
+
+#define TICKET_SHIFT 16
+
typedef struct {
- volatile long lock;
-} spinlock_t;
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ u16 next;
+ u16 owner;
+#else
+ u16 owner;
+ u16 next;
+#endif
+} __aligned(4) spinlock_t;
+
+#define __SPIN_LOCK_UNLOCKED \
+ (spinlock_t) { 0, 0 }
-#define __RISCV_SPIN_UNLOCKED 0
+#define SPIN_LOCK_INIT(x) \
+ x = __SPIN_LOCK_UNLOCKED
-#define SPIN_LOCK_INIT(x) (x).lock = __RISCV_SPIN_UNLOCKED
+#define SPIN_LOCK_INITIALIZER \
+ __SPIN_LOCK_UNLOCKED
-#define SPIN_LOCK_INITIALIZER \
- { \
- .lock = __RISCV_SPIN_UNLOCKED, \
- }
+#define DEFINE_SPIN_LOCK(x) \
+ spinlock_t SPIN_LOCK_INIT(x)
int spin_lock_check(spinlock_t *lock);