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 #include <asm/kvm_guest.h>
14 #include <asm/cputhreads.h>
16 DECLARE_STATIC_KEY_FALSE(shared_processor
);
18 static inline bool is_shared_processor(void)
20 return static_branch_unlikely(&shared_processor
);
23 /* If bit 0 is set, the cpu has been preempted */
24 static inline u32
yield_count_of(int cpu
)
26 __be32 yield_count
= READ_ONCE(lppaca_of(cpu
).yield_count
);
27 return be32_to_cpu(yield_count
);
30 static inline void yield_to_preempted(int cpu
, u32 yield_count
)
32 plpar_hcall_norets(H_CONFER
, get_hard_smp_processor_id(cpu
), yield_count
);
35 static inline void prod_cpu(int cpu
)
37 plpar_hcall_norets(H_PROD
, get_hard_smp_processor_id(cpu
));
40 static inline void yield_to_any(void)
42 plpar_hcall_norets(H_CONFER
, -1, 0);
45 static inline bool is_shared_processor(void)
50 static inline u32
yield_count_of(int cpu
)
55 extern void ___bad_yield_to_preempted(void);
56 static inline void yield_to_preempted(int cpu
, u32 yield_count
)
58 ___bad_yield_to_preempted(); /* This would be a bug */
61 extern void ___bad_yield_to_any(void);
62 static inline void yield_to_any(void)
64 ___bad_yield_to_any(); /* This would be a bug */
67 extern void ___bad_prod_cpu(void);
68 static inline void prod_cpu(int cpu
)
70 ___bad_prod_cpu(); /* This would be a bug */
75 #define vcpu_is_preempted vcpu_is_preempted
76 static inline bool vcpu_is_preempted(int cpu
)
78 if (!is_shared_processor())
81 #ifdef CONFIG_PPC_SPLPAR
82 if (!is_kvm_guest()) {
83 int first_cpu
= cpu_first_thread_sibling(smp_processor_id());
86 * Preemption can only happen at core granularity. This CPU
87 * is not preempted if one of the CPU of this core is not
90 if (cpu_first_thread_sibling(cpu
) == first_cpu
)
95 if (yield_count_of(cpu
) & 1)
100 static inline bool pv_is_native_spin_unlock(void)
102 return !is_shared_processor();
105 #endif /* _ASM_POWERPC_PARAVIRT_H */