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 __ASSEMBLER__
9 void handle_exception(int trap, void (*func)(struct pt_regs *, void *), void *);
10 void do_handle_exception(struct pt_regs *regs);
11 #endif /* __ASSEMBLER__ */
12
13 extern bool host_is_tcg;
14 extern bool host_is_kvm;
15
16 extern bool cpu_has_hv;
17 extern bool cpu_has_power_mce;
18 extern bool cpu_has_siar;
19 extern bool cpu_has_heai;
20 extern bool cpu_has_radix;
21 extern bool cpu_has_prefix;
22 extern bool cpu_has_sc_lev;
23 extern bool cpu_has_pause_short;
24
25 bool in_usermode(void);
26
mfspr(int nr)27 static inline uint64_t mfspr(int nr)
28 {
29 uint64_t ret;
30
31 asm volatile("mfspr %0,%1" : "=r"(ret) : "i"(nr) : "memory");
32
33 return ret;
34 }
35
mtspr(int nr,uint64_t val)36 static inline void mtspr(int nr, uint64_t val)
37 {
38 asm volatile("mtspr %0,%1" : : "i"(nr), "r"(val) : "memory");
39 }
40
mfmsr(void)41 static inline uint64_t mfmsr(void)
42 {
43 uint64_t msr;
44
45 asm volatile ("mfmsr %[msr]" : [msr] "=r" (msr) :: "memory");
46
47 return msr;
48 }
49
mtmsr(uint64_t msr)50 static inline void mtmsr(uint64_t msr)
51 {
52 asm volatile ("mtmsrd %[msr]" :: [msr] "r" (msr) : "memory");
53 }
54
local_irq_enable(void)55 static inline void local_irq_enable(void)
56 {
57 unsigned long msr;
58
59 assert(!in_usermode());
60
61 asm volatile(
62 " mfmsr %0 \n \
63 ori %0,%0,%1 \n \
64 mtmsrd %0,1 "
65 : "=r"(msr) : "i"(MSR_EE): "memory");
66 }
67
local_irq_disable(void)68 static inline void local_irq_disable(void)
69 {
70 unsigned long msr;
71
72 assert(!in_usermode());
73
74 asm volatile(
75 " mfmsr %0 \n \
76 andc %0,%0,%1 \n \
77 mtmsrd %0,1 "
78 : "=r"(msr) : "r"(MSR_EE): "memory");
79 }
80
81 /*
82 * This returns true on PowerNV / OPAL machines which run in hypervisor
83 * mode. False on pseries / PAPR machines that run in guest mode.
84 */
machine_is_powernv(void)85 static inline bool machine_is_powernv(void)
86 {
87 return cpu_has_hv;
88 }
89
90 /*
91 * This returns true on pseries / PAPR / KVM machines which run under a
92 * hypervisor or QEMU pseries machine. False for PowerNV / OPAL.
93 */
machine_is_pseries(void)94 static inline bool machine_is_pseries(void)
95 {
96 return !machine_is_powernv();
97 }
98
99 void enable_mcheck(void);
100 void disable_mcheck(void);
101
102 void enter_usermode(void);
103 void exit_usermode(void);
104
105 #endif /* _ASMPOWERPC_PROCESSOR_H_ */
106