18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ASM_QSPINLOCK_H
38c2ecf20Sopenharmony_ci#define _ASM_QSPINLOCK_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <asm/paravirt.h>
68c2ecf20Sopenharmony_ci#include <asm-generic/qspinlock_types.h>
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#define _Q_PENDING_LOOPS	(1 << 9)
98c2ecf20Sopenharmony_ci#define queued_spin_unlock queued_spin_unlock
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifdef CONFIG_PARAVIRT_SPINLOCKS
128c2ecf20Sopenharmony_ciextern void native_queued_spin_lock_slowpath(struct qspinlock *lock, u32 val);
138c2ecf20Sopenharmony_ciextern void __pv_init_lock_hash(void);
148c2ecf20Sopenharmony_ciextern void __pv_queued_spin_lock_slowpath(struct qspinlock *lock, u32 val);
158c2ecf20Sopenharmony_ciextern void __pv_queued_spin_unlock(struct qspinlock *lock);
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistatic inline void native_queued_spin_unlock(struct qspinlock *lock)
188c2ecf20Sopenharmony_ci{
198c2ecf20Sopenharmony_ci	compiletime_assert_atomic_type(lock->locked);
208c2ecf20Sopenharmony_ci	c_sync();
218c2ecf20Sopenharmony_ci	WRITE_ONCE(lock->locked, 0);
228c2ecf20Sopenharmony_ci}
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistatic inline void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
258c2ecf20Sopenharmony_ci{
268c2ecf20Sopenharmony_ci	pv_queued_spin_lock_slowpath(lock, val);
278c2ecf20Sopenharmony_ci}
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistatic inline void queued_spin_unlock(struct qspinlock *lock)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	pv_queued_spin_unlock(lock);
328c2ecf20Sopenharmony_ci}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define vcpu_is_preempted vcpu_is_preempted
358c2ecf20Sopenharmony_cistatic inline bool vcpu_is_preempted(long cpu)
368c2ecf20Sopenharmony_ci{
378c2ecf20Sopenharmony_ci	return pv_vcpu_is_preempted(cpu);
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_ci#else
408c2ecf20Sopenharmony_cistatic inline void queued_spin_unlock(struct qspinlock *lock)
418c2ecf20Sopenharmony_ci{
428c2ecf20Sopenharmony_ci	compiletime_assert_atomic_type(lock->locked);
438c2ecf20Sopenharmony_ci	c_sync();
448c2ecf20Sopenharmony_ci	WRITE_ONCE(lock->locked, 0);
458c2ecf20Sopenharmony_ci}
468c2ecf20Sopenharmony_ci#endif
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#include <asm-generic/qspinlock.h>
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#endif /* _ASM_QSPINLOCK_H */
51