WIP FPC-III support
[linux/fpc-iii.git] / arch / powerpc / include / asm / qspinlock.h
blobb752d34517b39d37977746fb4f055629913112d9
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_QSPINLOCK_H
3 #define _ASM_POWERPC_QSPINLOCK_H
5 #include <asm-generic/qspinlock_types.h>
6 #include <asm/paravirt.h>
8 #define _Q_PENDING_LOOPS (1 << 9) /* not tuned */
10 #ifdef CONFIG_PARAVIRT_SPINLOCKS
11 extern void native_queued_spin_lock_slowpath(struct qspinlock *lock, u32 val);
12 extern void __pv_queued_spin_lock_slowpath(struct qspinlock *lock, u32 val);
13 extern void __pv_queued_spin_unlock(struct qspinlock *lock);
15 static __always_inline void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
17 if (!is_shared_processor())
18 native_queued_spin_lock_slowpath(lock, val);
19 else
20 __pv_queued_spin_lock_slowpath(lock, val);
23 #define queued_spin_unlock queued_spin_unlock
24 static inline void queued_spin_unlock(struct qspinlock *lock)
26 if (!is_shared_processor())
27 smp_store_release(&lock->locked, 0);
28 else
29 __pv_queued_spin_unlock(lock);
32 #else
33 extern void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val);
34 #endif
36 static __always_inline void queued_spin_lock(struct qspinlock *lock)
38 u32 val = 0;
40 if (likely(atomic_try_cmpxchg_lock(&lock->val, &val, _Q_LOCKED_VAL)))
41 return;
43 queued_spin_lock_slowpath(lock, val);
45 #define queued_spin_lock queued_spin_lock
47 #define smp_mb__after_spinlock() smp_mb()
49 static __always_inline int queued_spin_is_locked(struct qspinlock *lock)
52 * This barrier was added to simple spinlocks by commit 51d7d5205d338,
53 * but it should now be possible to remove it, asm arm64 has done with
54 * commit c6f5d02b6a0f.
56 smp_mb();
57 return atomic_read(&lock->val);
59 #define queued_spin_is_locked queued_spin_is_locked
61 #ifdef CONFIG_PARAVIRT_SPINLOCKS
62 #define SPIN_THRESHOLD (1<<15) /* not tuned */
64 static __always_inline void pv_wait(u8 *ptr, u8 val)
66 if (*ptr != val)
67 return;
68 yield_to_any();
70 * We could pass in a CPU here if waiting in the queue and yield to
71 * the previous CPU in the queue.
75 static __always_inline void pv_kick(int cpu)
77 prod_cpu(cpu);
80 extern void __pv_init_lock_hash(void);
82 static inline void pv_spinlocks_init(void)
84 __pv_init_lock_hash();
87 #endif
89 #include <asm-generic/qspinlock.h>
91 #endif /* _ASM_POWERPC_QSPINLOCK_H */