aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/include
diff options
context:
space:
mode:
authorAlexander Graf <agraf@suse.de>2010-04-15 18:11:40 -0400
committerAvi Kivity <avi@redhat.com>2010-05-17 05:18:26 -0400
commitc7f38f46f2a98d232147e47284cb4e7363296a3e (patch)
treeba1de6a9d8398d31807756789d015983c4610b21 /arch/powerpc/include
parent66bb170655799a0149df0844fb8232f27e54323c (diff)
KVM: PPC: Improve indirect svcpu accessors
We already have some inline fuctions we use to access vcpu or svcpu structs, depending on whether we're on booke or book3s. Since we just put a few more registers into the svcpu, we also need to make sure the respective callbacks are available and get used. So this patch moves direct use of the now in the svcpu struct fields to inline function calls. While at it, it also moves the definition of those inline function calls to respective header files for booke and book3s, greatly improving readability. Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/powerpc/include')
-rw-r--r--arch/powerpc/include/asm/kvm_book3s.h98
-rw-r--r--arch/powerpc/include/asm/kvm_booke.h96
-rw-r--r--arch/powerpc/include/asm/kvm_ppc.h79
3 files changed, 195 insertions, 78 deletions
diff --git a/arch/powerpc/include/asm/kvm_book3s.h b/arch/powerpc/include/asm/kvm_book3s.h
index 7670e2a12867..9517b8deafed 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -71,7 +71,7 @@ struct kvmppc_sid_map {
71 71
72struct kvmppc_vcpu_book3s { 72struct kvmppc_vcpu_book3s {
73 struct kvm_vcpu vcpu; 73 struct kvm_vcpu vcpu;
74 struct kvmppc_book3s_shadow_vcpu shadow_vcpu; 74 struct kvmppc_book3s_shadow_vcpu *shadow_vcpu;
75 struct kvmppc_sid_map sid_map[SID_MAP_NUM]; 75 struct kvmppc_sid_map sid_map[SID_MAP_NUM];
76 struct kvmppc_slb slb[64]; 76 struct kvmppc_slb slb[64];
77 struct { 77 struct {
@@ -147,6 +147,94 @@ static inline ulong dsisr(void)
147} 147}
148 148
149extern void kvm_return_point(void); 149extern void kvm_return_point(void);
150static inline struct kvmppc_book3s_shadow_vcpu *to_svcpu(struct kvm_vcpu *vcpu);
151
152static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)
153{
154 if ( num < 14 ) {
155 to_svcpu(vcpu)->gpr[num] = val;
156 to_book3s(vcpu)->shadow_vcpu->gpr[num] = val;
157 } else
158 vcpu->arch.gpr[num] = val;
159}
160
161static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num)
162{
163 if ( num < 14 )
164 return to_svcpu(vcpu)->gpr[num];
165 else
166 return vcpu->arch.gpr[num];
167}
168
169static inline void kvmppc_set_cr(struct kvm_vcpu *vcpu, u32 val)
170{
171 to_svcpu(vcpu)->cr = val;
172 to_book3s(vcpu)->shadow_vcpu->cr = val;
173}
174
175static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu)
176{
177 return to_svcpu(vcpu)->cr;
178}
179
180static inline void kvmppc_set_xer(struct kvm_vcpu *vcpu, u32 val)
181{
182 to_svcpu(vcpu)->xer = val;
183 to_book3s(vcpu)->shadow_vcpu->xer = val;
184}
185
186static inline u32 kvmppc_get_xer(struct kvm_vcpu *vcpu)
187{
188 return to_svcpu(vcpu)->xer;
189}
190
191static inline void kvmppc_set_ctr(struct kvm_vcpu *vcpu, ulong val)
192{
193 to_svcpu(vcpu)->ctr = val;
194}
195
196static inline ulong kvmppc_get_ctr(struct kvm_vcpu *vcpu)
197{
198 return to_svcpu(vcpu)->ctr;
199}
200
201static inline void kvmppc_set_lr(struct kvm_vcpu *vcpu, ulong val)
202{
203 to_svcpu(vcpu)->lr = val;
204}
205
206static inline ulong kvmppc_get_lr(struct kvm_vcpu *vcpu)
207{
208 return to_svcpu(vcpu)->lr;
209}
210
211static inline void kvmppc_set_pc(struct kvm_vcpu *vcpu, ulong val)
212{
213 to_svcpu(vcpu)->pc = val;
214}
215
216static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu)
217{
218 return to_svcpu(vcpu)->pc;
219}
220
221static inline u32 kvmppc_get_last_inst(struct kvm_vcpu *vcpu)
222{
223 ulong pc = kvmppc_get_pc(vcpu);
224 struct kvmppc_book3s_shadow_vcpu *svcpu = to_svcpu(vcpu);
225
226 /* Load the instruction manually if it failed to do so in the
227 * exit path */
228 if (svcpu->last_inst == KVM_INST_FETCH_FAILED)
229 kvmppc_ld(vcpu, &pc, sizeof(u32), &svcpu->last_inst, false);
230
231 return svcpu->last_inst;
232}
233
234static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu)
235{
236 return to_svcpu(vcpu)->fault_dar;
237}
150 238
151/* Magic register values loaded into r3 and r4 before the 'sc' assembly 239/* Magic register values loaded into r3 and r4 before the 'sc' assembly
152 * instruction for the OSI hypercalls */ 240 * instruction for the OSI hypercalls */
@@ -155,4 +243,12 @@ extern void kvm_return_point(void);
155 243
156#define INS_DCBZ 0x7c0007ec 244#define INS_DCBZ 0x7c0007ec
157 245
246/* Also add subarch specific defines */
247
248#ifdef CONFIG_PPC_BOOK3S_32
249#include <asm/kvm_book3s_32.h>
250#else
251#include <asm/kvm_book3s_64.h>
252#endif
253
158#endif /* __ASM_KVM_BOOK3S_H__ */ 254#endif /* __ASM_KVM_BOOK3S_H__ */
diff --git a/arch/powerpc/include/asm/kvm_booke.h b/arch/powerpc/include/asm/kvm_booke.h
new file mode 100644
index 000000000000..9c9ba3d59b1b
--- /dev/null
+++ b/arch/powerpc/include/asm/kvm_booke.h
@@ -0,0 +1,96 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2, as
4 * published by the Free Software Foundation.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14 *
15 * Copyright SUSE Linux Products GmbH 2010
16 *
17 * Authors: Alexander Graf <agraf@suse.de>
18 */
19
20#ifndef __ASM_KVM_BOOKE_H__
21#define __ASM_KVM_BOOKE_H__
22
23#include <linux/types.h>
24#include <linux/kvm_host.h>
25
26static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)
27{
28 vcpu->arch.gpr[num] = val;
29}
30
31static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num)
32{
33 return vcpu->arch.gpr[num];
34}
35
36static inline void kvmppc_set_cr(struct kvm_vcpu *vcpu, u32 val)
37{
38 vcpu->arch.cr = val;
39}
40
41static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu)
42{
43 return vcpu->arch.cr;
44}
45
46static inline void kvmppc_set_xer(struct kvm_vcpu *vcpu, u32 val)
47{
48 vcpu->arch.xer = val;
49}
50
51static inline u32 kvmppc_get_xer(struct kvm_vcpu *vcpu)
52{
53 return vcpu->arch.xer;
54}
55
56static inline u32 kvmppc_get_last_inst(struct kvm_vcpu *vcpu)
57{
58 return vcpu->arch.last_inst;
59}
60
61static inline void kvmppc_set_ctr(struct kvm_vcpu *vcpu, ulong val)
62{
63 vcpu->arch.ctr = val;
64}
65
66static inline ulong kvmppc_get_ctr(struct kvm_vcpu *vcpu)
67{
68 return vcpu->arch.ctr;
69}
70
71static inline void kvmppc_set_lr(struct kvm_vcpu *vcpu, ulong val)
72{
73 vcpu->arch.lr = val;
74}
75
76static inline ulong kvmppc_get_lr(struct kvm_vcpu *vcpu)
77{
78 return vcpu->arch.lr;
79}
80
81static inline void kvmppc_set_pc(struct kvm_vcpu *vcpu, ulong val)
82{
83 vcpu->arch.pc = val;
84}
85
86static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu)
87{
88 return vcpu->arch.pc;
89}
90
91static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu)
92{
93 return vcpu->arch.fault_dear;
94}
95
96#endif /* __ASM_KVM_BOOKE_H__ */
diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h
index 6a2464e4d6b9..edade847b8f8 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -30,6 +30,8 @@
30#include <linux/kvm_host.h> 30#include <linux/kvm_host.h>
31#ifdef CONFIG_PPC_BOOK3S 31#ifdef CONFIG_PPC_BOOK3S
32#include <asm/kvm_book3s.h> 32#include <asm/kvm_book3s.h>
33#else
34#include <asm/kvm_booke.h>
33#endif 35#endif
34 36
35enum emulation_result { 37enum emulation_result {
@@ -138,81 +140,4 @@ static inline u32 kvmppc_set_field(u64 inst, int msb, int lsb, int value)
138 return r; 140 return r;
139} 141}
140 142
141#ifdef CONFIG_PPC_BOOK3S
142
143/* We assume we're always acting on the current vcpu */
144
145static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)
146{
147 if ( num < 14 ) {
148 get_paca()->shadow_vcpu.gpr[num] = val;
149 to_book3s(vcpu)->shadow_vcpu.gpr[num] = val;
150 } else
151 vcpu->arch.gpr[num] = val;
152}
153
154static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num)
155{
156 if ( num < 14 )
157 return get_paca()->shadow_vcpu.gpr[num];
158 else
159 return vcpu->arch.gpr[num];
160}
161
162static inline void kvmppc_set_cr(struct kvm_vcpu *vcpu, u32 val)
163{
164 get_paca()->shadow_vcpu.cr = val;
165 to_book3s(vcpu)->shadow_vcpu.cr = val;
166}
167
168static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu)
169{
170 return get_paca()->shadow_vcpu.cr;
171}
172
173static inline void kvmppc_set_xer(struct kvm_vcpu *vcpu, u32 val)
174{
175 get_paca()->shadow_vcpu.xer = val;
176 to_book3s(vcpu)->shadow_vcpu.xer = val;
177}
178
179static inline u32 kvmppc_get_xer(struct kvm_vcpu *vcpu)
180{
181 return get_paca()->shadow_vcpu.xer;
182}
183
184#else
185
186static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)
187{
188 vcpu->arch.gpr[num] = val;
189}
190
191static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num)
192{
193 return vcpu->arch.gpr[num];
194}
195
196static inline void kvmppc_set_cr(struct kvm_vcpu *vcpu, u32 val)
197{
198 vcpu->arch.cr = val;
199}
200
201static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu)
202{
203 return vcpu->arch.cr;
204}
205
206static inline void kvmppc_set_xer(struct kvm_vcpu *vcpu, u32 val)
207{
208 vcpu->arch.xer = val;
209}
210
211static inline u32 kvmppc_get_xer(struct kvm_vcpu *vcpu)
212{
213 return vcpu->arch.xer;
214}
215
216#endif
217
218#endif /* __POWERPC_KVM_PPC_H__ */ 143#endif /* __POWERPC_KVM_PPC_H__ */