KVM: PPC: Book3S HV: Use accessors for VCPU registers
[platform/kernel/linux-starfive.git] / arch / powerpc / kvm / book3s_hv.h
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
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
54 #define KVMPPC_BOOK3S_HV_VCPU_ACCESSOR_SET(reg, size)                   \
55 static inline void kvmppc_set_##reg ##_hv(struct kvm_vcpu *vcpu, u##size val)   \
56 {                                                                       \
57         vcpu->arch.reg = val;                                           \
58 }
59
60 #define KVMPPC_BOOK3S_HV_VCPU_ACCESSOR_GET(reg, size)                   \
61 static inline u##size kvmppc_get_##reg ##_hv(struct kvm_vcpu *vcpu)     \
62 {                                                                       \
63         return vcpu->arch.reg;                                          \
64 }
65
66 #define KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(reg, size)                       \
67         KVMPPC_BOOK3S_HV_VCPU_ACCESSOR_SET(reg, size)                   \
68         KVMPPC_BOOK3S_HV_VCPU_ACCESSOR_GET(reg, size)                   \
69
70 #define KVMPPC_BOOK3S_HV_VCPU_ARRAY_ACCESSOR_SET(reg, size)             \
71 static inline void kvmppc_set_##reg ##_hv(struct kvm_vcpu *vcpu, int i, u##size val)    \
72 {                                                                       \
73         vcpu->arch.reg[i] = val;                                        \
74 }
75
76 #define KVMPPC_BOOK3S_HV_VCPU_ARRAY_ACCESSOR_GET(reg, size)             \
77 static inline u##size kvmppc_get_##reg ##_hv(struct kvm_vcpu *vcpu, int i)      \
78 {                                                                       \
79         return vcpu->arch.reg[i];                                       \
80 }
81
82 #define KVMPPC_BOOK3S_HV_VCPU_ARRAY_ACCESSOR(reg, size)                 \
83         KVMPPC_BOOK3S_HV_VCPU_ARRAY_ACCESSOR_SET(reg, size)             \
84         KVMPPC_BOOK3S_HV_VCPU_ARRAY_ACCESSOR_GET(reg, size)             \
85
86 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(mmcra, 64)
87 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(hfscr, 64)
88 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(fscr, 64)
89 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dscr, 64)
90 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(purr, 64)
91 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(spurr, 64)
92 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(amr, 64)
93 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(uamor, 64)
94 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(siar, 64)
95 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(sdar, 64)
96 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(iamr, 64)
97 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawr0, 64)
98 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawr1, 64)
99 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawrx0, 64)
100 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawrx1, 64)
101 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(ciabr, 64)
102 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(wort, 64)
103 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(ppr, 64)
104 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(ctrl, 64)
105
106 KVMPPC_BOOK3S_HV_VCPU_ARRAY_ACCESSOR(mmcr, 64)
107 KVMPPC_BOOK3S_HV_VCPU_ARRAY_ACCESSOR(sier, 64)
108 KVMPPC_BOOK3S_HV_VCPU_ARRAY_ACCESSOR(pmc, 32)
109
110 KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(pspb, 32)