xref: /kvm-unit-tests/lib/powerpc/asm/processor.h (revision 386ed5c2f9e98a2605817748c44c0cefa60dc88e)
1 #ifndef _ASMPOWERPC_PROCESSOR_H_
2 #define _ASMPOWERPC_PROCESSOR_H_
3 
4 #include <libcflat.h>
5 #include <asm/ptrace.h>
6 #include <asm/reg.h>
7 
8 #ifndef __ASSEMBLY__
9 void handle_exception(int trap, void (*func)(struct pt_regs *, void *), void *);
10 void do_handle_exception(struct pt_regs *regs);
11 #endif /* __ASSEMBLY__ */
12 
13 extern bool cpu_has_hv;
14 extern bool cpu_has_power_mce;
15 extern bool cpu_has_siar;
16 extern bool cpu_has_heai;
17 extern bool cpu_has_prefix;
18 extern bool cpu_has_sc_lev;
19 extern bool cpu_has_pause_short;
20 
21 static inline uint64_t mfspr(int nr)
22 {
23 	uint64_t ret;
24 
25 	asm volatile("mfspr %0,%1" : "=r"(ret) : "i"(nr) : "memory");
26 
27 	return ret;
28 }
29 
30 static inline void mtspr(int nr, uint64_t val)
31 {
32 	asm volatile("mtspr %0,%1" : : "i"(nr), "r"(val) : "memory");
33 }
34 
35 static inline uint64_t mfmsr(void)
36 {
37 	uint64_t msr;
38 
39 	asm volatile ("mfmsr %[msr]" : [msr] "=r" (msr) :: "memory");
40 
41 	return msr;
42 }
43 
44 static inline void mtmsr(uint64_t msr)
45 {
46 	asm volatile ("mtmsrd %[msr]" :: [msr] "r" (msr) : "memory");
47 }
48 
49 static inline void local_irq_enable(void)
50 {
51 	unsigned long msr;
52 
53 	asm volatile(
54 "		mfmsr	%0		\n \
55 		ori	%0,%0,%1	\n \
56 		mtmsrd	%0,1		"
57 		: "=r"(msr) : "i"(MSR_EE): "memory");
58 }
59 
60 static inline void local_irq_disable(void)
61 {
62 	unsigned long msr;
63 
64 	asm volatile(
65 "		mfmsr	%0		\n \
66 		andc	%0,%0,%1	\n \
67 		mtmsrd	%0,1		"
68 		: "=r"(msr) : "r"(MSR_EE): "memory");
69 }
70 
71 /*
72  * This returns true on PowerNV / OPAL machines which run in hypervisor
73  * mode. False on pseries / PAPR machines that run in guest mode.
74  */
75 static inline bool machine_is_powernv(void)
76 {
77 	return cpu_has_hv;
78 }
79 
80 /*
81  * This returns true on pseries / PAPR / KVM machines which run under a
82  * hypervisor or QEMU pseries machine. False for PowerNV / OPAL.
83  */
84 static inline bool machine_is_pseries(void)
85 {
86 	return !machine_is_powernv();
87 }
88 
89 void enable_mcheck(void);
90 void disable_mcheck(void);
91 
92 #endif /* _ASMPOWERPC_PROCESSOR_H_ */
93