1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef _ASM_POWERPC_PARAVIRT_H
3 #define _ASM_POWERPC_PARAVIRT_H
5 #include <linux/jump_label.h>
9 #include <asm/hvcall.h>
12 #ifdef CONFIG_PPC_SPLPAR
13 DECLARE_STATIC_KEY_FALSE(shared_processor);
15 static inline bool is_shared_processor(void)
17 return static_branch_unlikely(&shared_processor);
20 /* If bit 0 is set, the cpu has been preempted */
21 static inline u32 yield_count_of(int cpu)
23 __be32 yield_count = READ_ONCE(lppaca_of(cpu).yield_count);
24 return be32_to_cpu(yield_count);
27 static inline void yield_to_preempted(int cpu, u32 yield_count)
29 plpar_hcall_norets(H_CONFER, get_hard_smp_processor_id(cpu), yield_count);
32 static inline void prod_cpu(int cpu)
34 plpar_hcall_norets(H_PROD, get_hard_smp_processor_id(cpu));
37 static inline void yield_to_any(void)
39 plpar_hcall_norets(H_CONFER, -1, 0);
42 static inline bool is_shared_processor(void)
47 static inline u32 yield_count_of(int cpu)
52 extern void ___bad_yield_to_preempted(void);
53 static inline void yield_to_preempted(int cpu, u32 yield_count)
55 ___bad_yield_to_preempted(); /* This would be a bug */
58 extern void ___bad_yield_to_any(void);
59 static inline void yield_to_any(void)
61 ___bad_yield_to_any(); /* This would be a bug */
64 extern void ___bad_prod_cpu(void);
65 static inline void prod_cpu(int cpu)
67 ___bad_prod_cpu(); /* This would be a bug */
72 #define vcpu_is_preempted vcpu_is_preempted
73 static inline bool vcpu_is_preempted(int cpu)
75 if (!is_shared_processor())
77 if (yield_count_of(cpu) & 1)
82 static inline bool pv_is_native_spin_unlock(void)
84 return !is_shared_processor();
87 #endif /* _ASM_POWERPC_PARAVIRT_H */