xref: /openbmc/linux/arch/powerpc/kvm/book3s_hv.h (revision 267980ea)
1 // SPDX-License-Identifier: GPL-2.0-only
2 
3 /*
4  * Privileged (non-hypervisor) host registers to save.
5  */
6 struct p9_host_os_sprs {
7 	unsigned long iamr;
8 	unsigned long amr;
9 
10 	unsigned int pmc1;
11 	unsigned int pmc2;
12 	unsigned int pmc3;
13 	unsigned int pmc4;
14 	unsigned int pmc5;
15 	unsigned int pmc6;
16 	unsigned long mmcr0;
17 	unsigned long mmcr1;
18 	unsigned long mmcr2;
19 	unsigned long mmcr3;
20 	unsigned long mmcra;
21 	unsigned long siar;
22 	unsigned long sier1;
23 	unsigned long sier2;
24 	unsigned long sier3;
25 	unsigned long sdar;
26 };
27 
nesting_enabled(struct kvm * kvm)28 static inline bool nesting_enabled(struct kvm *kvm)
29 {
30 	return kvm->arch.nested_enable && kvm_is_radix(kvm);
31 }
32 
33 bool load_vcpu_state(struct kvm_vcpu *vcpu,
34 			   struct p9_host_os_sprs *host_os_sprs);
35 void store_vcpu_state(struct kvm_vcpu *vcpu);
36 void save_p9_host_os_sprs(struct p9_host_os_sprs *host_os_sprs);
37 void restore_p9_host_os_sprs(struct kvm_vcpu *vcpu,
38 				    struct p9_host_os_sprs *host_os_sprs);
39 void switch_pmu_to_guest(struct kvm_vcpu *vcpu,
40 			    struct p9_host_os_sprs *host_os_sprs);
41 void switch_pmu_to_host(struct kvm_vcpu *vcpu,
42 			    struct p9_host_os_sprs *host_os_sprs);
43 
44 #ifdef CONFIG_KVM_BOOK3S_HV_P9_TIMING
45 void accumulate_time(struct kvm_vcpu *vcpu, struct kvmhv_tb_accumulator *next);
46 #define start_timing(vcpu, next) accumulate_time(vcpu, next)
47 #define end_timing(vcpu) accumulate_time(vcpu, NULL)
48 #else
49 #define accumulate_time(vcpu, next) do {} while (0)
50 #define start_timing(vcpu, next) do {} while (0)
51 #define end_timing(vcpu) do {} while (0)
52 #endif
53 
__kvmppc_set_msr_hv(struct kvm_vcpu * vcpu,u64 val)54 static inline void __kvmppc_set_msr_hv(struct kvm_vcpu *vcpu, u64 val)
55 {
56 	vcpu->arch.shregs.msr = val;
57 }
58 
__kvmppc_get_msr_hv(struct kvm_vcpu * vcpu)59 static inline u64 __kvmppc_get_msr_hv(struct kvm_vcpu *vcpu)
60 {
61 	return vcpu->arch.shregs.msr;
62 }
63 
64 #define KVMPPC_BOOK3S_HV_VCPU_ACCESSOR_SET(reg, size)			\
65 static inline void kvmppc_set_##reg ##_hv(struct kvm_vcpu *vcpu, u##size val)	\
66 {									\
67 	vcpu->arch.reg = val;						\
68 }
69 
70 #define KVMPPC_BOOK3S_HV_VCPU_ACCESSOR_GET(reg, size)			\
71 static inline u##size kvmppc_get_##reg ##_hv(struct kvm_vcpu *vcpu)	\
72 {									\
73 	return vcpu->arch.reg;						\
74 }
75 
76 #define KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(reg, size)			\
77 	KVMPPC_BOOK3S_HV_VCPU_ACCESSOR_SET(reg, size)			\
78 	KVMPPC_BOOK3S_HV_VCPU_ACCESSOR_GET(reg, size)			\
79 
80 #define KVMPPC_BOOK3S_HV_VCPU_ARRAY_ACCESSOR_SET(reg, size)		\
81 static inline void kvmppc_set_##reg ##_hv(struct kvm_vcpu *vcpu, int i, u##size val)	\
82 {									\
83 	vcpu->arch.reg[i] = val;					\
84 }
85 
86 #define KVMPPC_BOOK3S_HV_VCPU_ARRAY_ACCESSOR_GET(reg, size)		\
87 static inline u##size kvmppc_get_##reg ##_hv(struct kvm_vcpu *vcpu, int i)	\
88 {									\
89 	return vcpu->arch.reg[i];					\
90 }
91 
92 #define KVMPPC_BOOK3S_HV_VCPU_ARRAY_ACCESSOR(reg, size)			\
93 	KVMPPC_BOOK3S_HV_VCPU_ARRAY_ACCESSOR_SET(reg, size)		\
94 	KVMPPC_BOOK3S_HV_VCPU_ARRAY_ACCESSOR_GET(reg, size)		\
95 
96 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(mmcra, 64)
97 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(hfscr, 64)
98 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(fscr, 64)
99 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dscr, 64)
100 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(purr, 64)
101 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(spurr, 64)
102 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(amr, 64)
103 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(uamor, 64)
104 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(siar, 64)
105 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(sdar, 64)
106 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(iamr, 64)
107 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawr0, 64)
108 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawr1, 64)
109 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawrx0, 64)
110 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawrx1, 64)
111 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(ciabr, 64)
112 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(wort, 64)
113 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(ppr, 64)
114 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(ctrl, 64)
115 
116 KVMPPC_BOOK3S_HV_VCPU_ARRAY_ACCESSOR(mmcr, 64)
117 KVMPPC_BOOK3S_HV_VCPU_ARRAY_ACCESSOR(sier, 64)
118 KVMPPC_BOOK3S_HV_VCPU_ARRAY_ACCESSOR(pmc, 32)
119 
120 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(pspb, 32)
121