1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef __ASM_RISCV_SPINLOCK_H
4 #define __ASM_RISCV_SPINLOCK_H
6 #ifdef CONFIG_QUEUED_SPINLOCKS
7 #define _Q_PENDING_LOOPS (1 << 9)
10 #ifdef CONFIG_RISCV_COMBO_SPINLOCKS
12 #define __no_arch_spinlock_redefine
13 #include <asm/ticket_spinlock.h>
14 #include <asm/qspinlock.h>
15 #include <asm/jump_label.h>
18 * TODO: Use an alternative instead of a static key when we are able to parse
19 * the extensions string earlier in the boot process.
21 DECLARE_STATIC_KEY_TRUE(qspinlock_key);
23 #define SPINLOCK_BASE_DECLARE(op, type, type_lock) \
24 static __always_inline type arch_spin_##op(type_lock lock) \
26 if (static_branch_unlikely(&qspinlock_key)) \
27 return queued_spin_##op(lock); \
28 return ticket_spin_##op(lock); \
31 SPINLOCK_BASE_DECLARE(lock, void, arch_spinlock_t *)
32 SPINLOCK_BASE_DECLARE(unlock, void, arch_spinlock_t *)
33 SPINLOCK_BASE_DECLARE(is_locked, int, arch_spinlock_t *)
34 SPINLOCK_BASE_DECLARE(is_contended, int, arch_spinlock_t *)
35 SPINLOCK_BASE_DECLARE(trylock, bool, arch_spinlock_t *)
36 SPINLOCK_BASE_DECLARE(value_unlocked, int, arch_spinlock_t)
38 #elif defined(CONFIG_RISCV_QUEUED_SPINLOCKS)
40 #include <asm/qspinlock.h>
44 #include <asm/ticket_spinlock.h>
48 #include <asm/qrwlock.h>
50 #endif /* __ASM_RISCV_SPINLOCK_H */