blob: 3f2a8360c857f1aae94a13631b2eb099a96795a0 [file] [log] [blame]
Alexander Graf2f4cf5e2009-10-30 05:47:10 +00001/*
2 * Copyright (C) 2009. SUSE Linux Products GmbH. All rights reserved.
3 *
4 * Authors:
5 * Alexander Graf <agraf@suse.de>
6 * Kevin Wolf <mail@kevin-wolf.de>
7 *
8 * Description:
9 * This file is derived from arch/powerpc/kvm/44x.c,
10 * by Hollis Blanchard <hollisb@us.ibm.com>.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License, version 2, as
14 * published by the Free Software Foundation.
15 */
16
17#include <linux/kvm_host.h>
18#include <linux/err.h>
Paul Gortmaker66b15db2011-05-27 10:46:24 -040019#include <linux/export.h>
Stephen Rothwell329d20b2010-04-27 15:49:17 +100020#include <linux/slab.h>
Alexander Graf2f4cf5e2009-10-30 05:47:10 +000021
22#include <asm/reg.h>
23#include <asm/cputable.h>
24#include <asm/cacheflush.h>
25#include <asm/tlbflush.h>
26#include <asm/uaccess.h>
27#include <asm/io.h>
28#include <asm/kvm_ppc.h>
29#include <asm/kvm_book3s.h>
30#include <asm/mmu_context.h>
Paul Mackerras149dbdb2011-06-29 00:16:42 +000031#include <asm/page.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/gfp.h>
Alexander Graf2f4cf5e2009-10-30 05:47:10 +000033#include <linux/sched.h>
34#include <linux/vmalloc.h>
Alexander Graf9fb244a2010-03-24 21:48:32 +010035#include <linux/highmem.h>
Alexander Graf2f4cf5e2009-10-30 05:47:10 +000036
Paul Mackerrasc4befc52011-06-29 00:17:33 +000037#include "trace.h"
38
Alexander Graf2f4cf5e2009-10-30 05:47:10 +000039#define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
40
41/* #define EXIT_DEBUG */
Alexander Graf07b09072010-04-16 00:11:53 +020042
Alexander Graf2f4cf5e2009-10-30 05:47:10 +000043struct kvm_stats_debugfs_item debugfs_entries[] = {
44 { "exits", VCPU_STAT(sum_exits) },
45 { "mmio", VCPU_STAT(mmio_exits) },
46 { "sig", VCPU_STAT(signal_exits) },
47 { "sysc", VCPU_STAT(syscall_exits) },
48 { "inst_emu", VCPU_STAT(emulated_inst_exits) },
49 { "dec", VCPU_STAT(dec_exits) },
50 { "ext_intr", VCPU_STAT(ext_intr_exits) },
51 { "queue_intr", VCPU_STAT(queue_intr) },
52 { "halt_wakeup", VCPU_STAT(halt_wakeup) },
53 { "pf_storage", VCPU_STAT(pf_storage) },
54 { "sp_storage", VCPU_STAT(sp_storage) },
55 { "pf_instruc", VCPU_STAT(pf_instruc) },
56 { "sp_instruc", VCPU_STAT(sp_instruc) },
57 { "ld", VCPU_STAT(ld) },
58 { "ld_slow", VCPU_STAT(ld_slow) },
59 { "st", VCPU_STAT(st) },
60 { "st_slow", VCPU_STAT(st_slow) },
61 { NULL }
62};
63
64void kvmppc_core_load_host_debugstate(struct kvm_vcpu *vcpu)
65{
66}
67
68void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu)
69{
70}
71
Alexander Graf2f4cf5e2009-10-30 05:47:10 +000072void kvmppc_inject_interrupt(struct kvm_vcpu *vcpu, int vec, u64 flags)
73{
Alexander Grafde7906c2010-07-29 14:47:46 +020074 vcpu->arch.shared->srr0 = kvmppc_get_pc(vcpu);
75 vcpu->arch.shared->srr1 = vcpu->arch.shared->msr | flags;
Paul Mackerrasf05ed4d2011-06-29 00:17:58 +000076 kvmppc_set_pc(vcpu, kvmppc_interrupt_offset(vcpu) + vec);
Alexander Graf2f4cf5e2009-10-30 05:47:10 +000077 vcpu->arch.mmu.reset_msr(vcpu);
78}
79
Alexander Graf583617b2009-12-21 20:21:23 +010080static int kvmppc_book3s_vec2irqprio(unsigned int vec)
Alexander Graf2f4cf5e2009-10-30 05:47:10 +000081{
82 unsigned int prio;
83
Alexander Graf2f4cf5e2009-10-30 05:47:10 +000084 switch (vec) {
85 case 0x100: prio = BOOK3S_IRQPRIO_SYSTEM_RESET; break;
86 case 0x200: prio = BOOK3S_IRQPRIO_MACHINE_CHECK; break;
87 case 0x300: prio = BOOK3S_IRQPRIO_DATA_STORAGE; break;
88 case 0x380: prio = BOOK3S_IRQPRIO_DATA_SEGMENT; break;
89 case 0x400: prio = BOOK3S_IRQPRIO_INST_STORAGE; break;
90 case 0x480: prio = BOOK3S_IRQPRIO_INST_SEGMENT; break;
91 case 0x500: prio = BOOK3S_IRQPRIO_EXTERNAL; break;
Alexander Graf17bd1582010-08-30 10:44:15 +020092 case 0x501: prio = BOOK3S_IRQPRIO_EXTERNAL_LEVEL; break;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +000093 case 0x600: prio = BOOK3S_IRQPRIO_ALIGNMENT; break;
94 case 0x700: prio = BOOK3S_IRQPRIO_PROGRAM; break;
95 case 0x800: prio = BOOK3S_IRQPRIO_FP_UNAVAIL; break;
96 case 0x900: prio = BOOK3S_IRQPRIO_DECREMENTER; break;
97 case 0xc00: prio = BOOK3S_IRQPRIO_SYSCALL; break;
98 case 0xd00: prio = BOOK3S_IRQPRIO_DEBUG; break;
99 case 0xf20: prio = BOOK3S_IRQPRIO_ALTIVEC; break;
100 case 0xf40: prio = BOOK3S_IRQPRIO_VSX; break;
101 default: prio = BOOK3S_IRQPRIO_MAX; break;
102 }
103
Alexander Graf583617b2009-12-21 20:21:23 +0100104 return prio;
105}
106
Alexander Graf7706664d2009-12-21 20:21:24 +0100107static void kvmppc_book3s_dequeue_irqprio(struct kvm_vcpu *vcpu,
108 unsigned int vec)
109{
Paul Mackerrasf05ed4d2011-06-29 00:17:58 +0000110 unsigned long old_pending = vcpu->arch.pending_exceptions;
111
Alexander Graf7706664d2009-12-21 20:21:24 +0100112 clear_bit(kvmppc_book3s_vec2irqprio(vec),
113 &vcpu->arch.pending_exceptions);
Alexander Graf9ee18b12010-08-05 12:24:40 +0200114
Paul Mackerrasf05ed4d2011-06-29 00:17:58 +0000115 kvmppc_update_int_pending(vcpu, vcpu->arch.pending_exceptions,
116 old_pending);
Alexander Graf7706664d2009-12-21 20:21:24 +0100117}
118
Alexander Graf583617b2009-12-21 20:21:23 +0100119void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec)
120{
121 vcpu->stat.queue_intr++;
122
123 set_bit(kvmppc_book3s_vec2irqprio(vec),
124 &vcpu->arch.pending_exceptions);
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000125#ifdef EXIT_DEBUG
126 printk(KERN_INFO "Queueing interrupt %x\n", vec);
127#endif
128}
129
130
Alexander Graf25a8a022010-01-08 02:58:07 +0100131void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags)
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000132{
Paul Mackerras3cf658b2011-06-29 00:18:52 +0000133 /* might as well deliver this straight away */
134 kvmppc_inject_interrupt(vcpu, BOOK3S_INTERRUPT_PROGRAM, flags);
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000135}
136
137void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu)
138{
139 kvmppc_book3s_queue_irqprio(vcpu, BOOK3S_INTERRUPT_DECREMENTER);
140}
141
142int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu)
143{
Paul Mackerras44075d92011-05-11 00:38:50 +0000144 return test_bit(BOOK3S_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions);
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000145}
146
Alexander Graf7706664d2009-12-21 20:21:24 +0100147void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu)
148{
149 kvmppc_book3s_dequeue_irqprio(vcpu, BOOK3S_INTERRUPT_DECREMENTER);
150}
151
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000152void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
153 struct kvm_interrupt *irq)
154{
Alexander Graf17bd1582010-08-30 10:44:15 +0200155 unsigned int vec = BOOK3S_INTERRUPT_EXTERNAL;
156
157 if (irq->irq == KVM_INTERRUPT_SET_LEVEL)
158 vec = BOOK3S_INTERRUPT_EXTERNAL_LEVEL;
159
160 kvmppc_book3s_queue_irqprio(vcpu, vec);
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000161}
162
Alexander Graf18978762010-03-24 21:48:18 +0100163void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu,
164 struct kvm_interrupt *irq)
165{
166 kvmppc_book3s_dequeue_irqprio(vcpu, BOOK3S_INTERRUPT_EXTERNAL);
Alexander Graf17bd1582010-08-30 10:44:15 +0200167 kvmppc_book3s_dequeue_irqprio(vcpu, BOOK3S_INTERRUPT_EXTERNAL_LEVEL);
Alexander Graf18978762010-03-24 21:48:18 +0100168}
169
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000170int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu *vcpu, unsigned int priority)
171{
172 int deliver = 1;
173 int vec = 0;
Paul Mackerrasf05ed4d2011-06-29 00:17:58 +0000174 bool crit = kvmppc_critical_section(vcpu);
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000175
176 switch (priority) {
177 case BOOK3S_IRQPRIO_DECREMENTER:
Alexander Graf5c6cedf2010-07-29 14:47:49 +0200178 deliver = (vcpu->arch.shared->msr & MSR_EE) && !crit;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000179 vec = BOOK3S_INTERRUPT_DECREMENTER;
180 break;
181 case BOOK3S_IRQPRIO_EXTERNAL:
Alexander Graf17bd1582010-08-30 10:44:15 +0200182 case BOOK3S_IRQPRIO_EXTERNAL_LEVEL:
Alexander Graf5c6cedf2010-07-29 14:47:49 +0200183 deliver = (vcpu->arch.shared->msr & MSR_EE) && !crit;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000184 vec = BOOK3S_INTERRUPT_EXTERNAL;
185 break;
186 case BOOK3S_IRQPRIO_SYSTEM_RESET:
187 vec = BOOK3S_INTERRUPT_SYSTEM_RESET;
188 break;
189 case BOOK3S_IRQPRIO_MACHINE_CHECK:
190 vec = BOOK3S_INTERRUPT_MACHINE_CHECK;
191 break;
192 case BOOK3S_IRQPRIO_DATA_STORAGE:
193 vec = BOOK3S_INTERRUPT_DATA_STORAGE;
194 break;
195 case BOOK3S_IRQPRIO_INST_STORAGE:
196 vec = BOOK3S_INTERRUPT_INST_STORAGE;
197 break;
198 case BOOK3S_IRQPRIO_DATA_SEGMENT:
199 vec = BOOK3S_INTERRUPT_DATA_SEGMENT;
200 break;
201 case BOOK3S_IRQPRIO_INST_SEGMENT:
202 vec = BOOK3S_INTERRUPT_INST_SEGMENT;
203 break;
204 case BOOK3S_IRQPRIO_ALIGNMENT:
205 vec = BOOK3S_INTERRUPT_ALIGNMENT;
206 break;
207 case BOOK3S_IRQPRIO_PROGRAM:
208 vec = BOOK3S_INTERRUPT_PROGRAM;
209 break;
210 case BOOK3S_IRQPRIO_VSX:
211 vec = BOOK3S_INTERRUPT_VSX;
212 break;
213 case BOOK3S_IRQPRIO_ALTIVEC:
214 vec = BOOK3S_INTERRUPT_ALTIVEC;
215 break;
216 case BOOK3S_IRQPRIO_FP_UNAVAIL:
217 vec = BOOK3S_INTERRUPT_FP_UNAVAIL;
218 break;
219 case BOOK3S_IRQPRIO_SYSCALL:
220 vec = BOOK3S_INTERRUPT_SYSCALL;
221 break;
222 case BOOK3S_IRQPRIO_DEBUG:
223 vec = BOOK3S_INTERRUPT_TRACE;
224 break;
225 case BOOK3S_IRQPRIO_PERFORMANCE_MONITOR:
226 vec = BOOK3S_INTERRUPT_PERFMON;
227 break;
228 default:
229 deliver = 0;
230 printk(KERN_ERR "KVM: Unknown interrupt: 0x%x\n", priority);
231 break;
232 }
233
234#if 0
235 printk(KERN_INFO "Deliver interrupt 0x%x? %x\n", vec, deliver);
236#endif
237
238 if (deliver)
Paul Mackerras3cf658b2011-06-29 00:18:52 +0000239 kvmppc_inject_interrupt(vcpu, vec, 0);
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000240
241 return deliver;
242}
243
Alexander Graf17bd1582010-08-30 10:44:15 +0200244/*
245 * This function determines if an irqprio should be cleared once issued.
246 */
247static bool clear_irqprio(struct kvm_vcpu *vcpu, unsigned int priority)
248{
249 switch (priority) {
250 case BOOK3S_IRQPRIO_DECREMENTER:
251 /* DEC interrupts get cleared by mtdec */
252 return false;
253 case BOOK3S_IRQPRIO_EXTERNAL_LEVEL:
254 /* External interrupts get cleared by userspace */
255 return false;
256 }
257
258 return true;
259}
260
Alexander Grafa8e4ef82012-02-16 14:07:37 +0000261int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000262{
263 unsigned long *pending = &vcpu->arch.pending_exceptions;
Alexander Graf90bba352010-07-29 14:47:51 +0200264 unsigned long old_pending = vcpu->arch.pending_exceptions;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000265 unsigned int priority;
266
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000267#ifdef EXIT_DEBUG
268 if (vcpu->arch.pending_exceptions)
269 printk(KERN_EMERG "KVM: Check pending: %lx\n", vcpu->arch.pending_exceptions);
270#endif
271 priority = __ffs(*pending);
Alexander Grafada7ba12010-04-16 00:11:56 +0200272 while (priority < BOOK3S_IRQPRIO_MAX) {
Alexander Graf7706664d2009-12-21 20:21:24 +0100273 if (kvmppc_book3s_irqprio_deliver(vcpu, priority) &&
Alexander Graf17bd1582010-08-30 10:44:15 +0200274 clear_irqprio(vcpu, priority)) {
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000275 clear_bit(priority, &vcpu->arch.pending_exceptions);
276 break;
277 }
278
279 priority = find_next_bit(pending,
280 BITS_PER_BYTE * sizeof(*pending),
281 priority + 1);
282 }
Alexander Graf90bba352010-07-29 14:47:51 +0200283
284 /* Tell the guest about our interrupt status */
Paul Mackerrasf05ed4d2011-06-29 00:17:58 +0000285 kvmppc_update_int_pending(vcpu, *pending, old_pending);
Alexander Grafa8e4ef82012-02-16 14:07:37 +0000286
287 return 0;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000288}
289
Alexander Grafe8508942010-07-29 14:47:54 +0200290pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn)
291{
292 ulong mp_pa = vcpu->arch.magic_page_pa;
293
Benjamin Herrenschmidtbbcc9c02012-03-13 21:52:44 +0000294 if (!(vcpu->arch.shared->msr & MSR_SF))
295 mp_pa = (uint32_t)mp_pa;
296
Alexander Grafe8508942010-07-29 14:47:54 +0200297 /* Magic page override */
298 if (unlikely(mp_pa) &&
299 unlikely(((gfn << PAGE_SHIFT) & KVM_PAM) ==
300 ((mp_pa & PAGE_MASK) & KVM_PAM))) {
301 ulong shared_page = ((ulong)vcpu->arch.shared) & PAGE_MASK;
302 pfn_t pfn;
303
304 pfn = (pfn_t)virt_to_phys((void*)shared_page) >> PAGE_SHIFT;
305 get_page(pfn_to_page(pfn));
306 return pfn;
307 }
308
309 return gfn_to_pfn(vcpu->kvm, gfn);
310}
311
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000312static int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, bool data,
313 struct kvmppc_pte *pte)
314{
Alexander Graf666e7252010-07-29 14:47:43 +0200315 int relocated = (vcpu->arch.shared->msr & (data ? MSR_DR : MSR_IR));
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000316 int r;
317
318 if (relocated) {
319 r = vcpu->arch.mmu.xlate(vcpu, eaddr, pte, data);
320 } else {
321 pte->eaddr = eaddr;
Alexander Graf28e83b42010-07-29 14:47:52 +0200322 pte->raddr = eaddr & KVM_PAM;
Alexander Graf3eeafd72010-03-24 21:48:17 +0100323 pte->vpage = VSID_REAL | eaddr >> 12;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000324 pte->may_read = true;
325 pte->may_write = true;
326 pte->may_execute = true;
327 r = 0;
328 }
329
330 return r;
331}
332
333static hva_t kvmppc_bad_hva(void)
334{
335 return PAGE_OFFSET;
336}
337
338static hva_t kvmppc_pte_to_hva(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte,
339 bool read)
340{
341 hva_t hpage;
342
343 if (read && !pte->may_read)
344 goto err;
345
346 if (!read && !pte->may_write)
347 goto err;
348
349 hpage = gfn_to_hva(vcpu->kvm, pte->raddr >> PAGE_SHIFT);
350 if (kvm_is_error_hva(hpage))
351 goto err;
352
353 return hpage | (pte->raddr & ~PAGE_MASK);
354err:
355 return kvmppc_bad_hva();
356}
357
Alexander Graf5467a972010-02-19 11:00:38 +0100358int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr,
359 bool data)
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000360{
361 struct kvmppc_pte pte;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000362
363 vcpu->stat.st++;
364
Alexander Graf5467a972010-02-19 11:00:38 +0100365 if (kvmppc_xlate(vcpu, *eaddr, data, &pte))
Alexander Graf9fb244a2010-03-24 21:48:32 +0100366 return -ENOENT;
Alexander Graf5467a972010-02-19 11:00:38 +0100367
368 *eaddr = pte.raddr;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000369
Alexander Graf9fb244a2010-03-24 21:48:32 +0100370 if (!pte.may_write)
371 return -EPERM;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000372
Alexander Graf9fb244a2010-03-24 21:48:32 +0100373 if (kvm_write_guest(vcpu->kvm, pte.raddr, ptr, size))
374 return EMULATE_DO_MMIO;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000375
Alexander Graf5467a972010-02-19 11:00:38 +0100376 return EMULATE_DONE;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000377}
378
Alexander Graf5467a972010-02-19 11:00:38 +0100379int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr,
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000380 bool data)
381{
382 struct kvmppc_pte pte;
Alexander Graf5467a972010-02-19 11:00:38 +0100383 hva_t hva = *eaddr;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000384
385 vcpu->stat.ld++;
386
Alexander Graf5467a972010-02-19 11:00:38 +0100387 if (kvmppc_xlate(vcpu, *eaddr, data, &pte))
388 goto nopte;
389
390 *eaddr = pte.raddr;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000391
392 hva = kvmppc_pte_to_hva(vcpu, &pte, true);
393 if (kvm_is_error_hva(hva))
Alexander Graf5467a972010-02-19 11:00:38 +0100394 goto mmio;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000395
396 if (copy_from_user(ptr, (void __user *)hva, size)) {
397 printk(KERN_INFO "kvmppc_ld at 0x%lx failed\n", hva);
Alexander Graf5467a972010-02-19 11:00:38 +0100398 goto mmio;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000399 }
400
Alexander Graf5467a972010-02-19 11:00:38 +0100401 return EMULATE_DONE;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000402
Alexander Graf5467a972010-02-19 11:00:38 +0100403nopte:
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000404 return -ENOENT;
Alexander Graf5467a972010-02-19 11:00:38 +0100405mmio:
406 return EMULATE_DO_MMIO;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000407}
408
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000409int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
410{
411 return 0;
412}
413
414int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
415{
416 int i;
417
Alexander Grafc7f38f42010-04-16 00:11:40 +0200418 regs->pc = kvmppc_get_pc(vcpu);
Alexander Graf992b5b22010-01-08 02:58:02 +0100419 regs->cr = kvmppc_get_cr(vcpu);
Alexander Grafc7f38f42010-04-16 00:11:40 +0200420 regs->ctr = kvmppc_get_ctr(vcpu);
421 regs->lr = kvmppc_get_lr(vcpu);
Alexander Graf992b5b22010-01-08 02:58:02 +0100422 regs->xer = kvmppc_get_xer(vcpu);
Alexander Graf666e7252010-07-29 14:47:43 +0200423 regs->msr = vcpu->arch.shared->msr;
Alexander Grafde7906c2010-07-29 14:47:46 +0200424 regs->srr0 = vcpu->arch.shared->srr0;
425 regs->srr1 = vcpu->arch.shared->srr1;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000426 regs->pid = vcpu->arch.pid;
Alexander Grafa73a9592010-07-29 14:47:47 +0200427 regs->sprg0 = vcpu->arch.shared->sprg0;
428 regs->sprg1 = vcpu->arch.shared->sprg1;
429 regs->sprg2 = vcpu->arch.shared->sprg2;
430 regs->sprg3 = vcpu->arch.shared->sprg3;
Scott Woodb5904972011-11-08 18:23:30 -0600431 regs->sprg4 = vcpu->arch.shared->sprg4;
432 regs->sprg5 = vcpu->arch.shared->sprg5;
433 regs->sprg6 = vcpu->arch.shared->sprg6;
434 regs->sprg7 = vcpu->arch.shared->sprg7;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000435
436 for (i = 0; i < ARRAY_SIZE(regs->gpr); i++)
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100437 regs->gpr[i] = kvmppc_get_gpr(vcpu, i);
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000438
439 return 0;
440}
441
442int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
443{
444 int i;
445
Alexander Grafc7f38f42010-04-16 00:11:40 +0200446 kvmppc_set_pc(vcpu, regs->pc);
Alexander Graf992b5b22010-01-08 02:58:02 +0100447 kvmppc_set_cr(vcpu, regs->cr);
Alexander Grafc7f38f42010-04-16 00:11:40 +0200448 kvmppc_set_ctr(vcpu, regs->ctr);
449 kvmppc_set_lr(vcpu, regs->lr);
Alexander Graf992b5b22010-01-08 02:58:02 +0100450 kvmppc_set_xer(vcpu, regs->xer);
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000451 kvmppc_set_msr(vcpu, regs->msr);
Alexander Grafde7906c2010-07-29 14:47:46 +0200452 vcpu->arch.shared->srr0 = regs->srr0;
453 vcpu->arch.shared->srr1 = regs->srr1;
Alexander Grafa73a9592010-07-29 14:47:47 +0200454 vcpu->arch.shared->sprg0 = regs->sprg0;
455 vcpu->arch.shared->sprg1 = regs->sprg1;
456 vcpu->arch.shared->sprg2 = regs->sprg2;
457 vcpu->arch.shared->sprg3 = regs->sprg3;
Scott Woodb5904972011-11-08 18:23:30 -0600458 vcpu->arch.shared->sprg4 = regs->sprg4;
459 vcpu->arch.shared->sprg5 = regs->sprg5;
460 vcpu->arch.shared->sprg6 = regs->sprg6;
461 vcpu->arch.shared->sprg7 = regs->sprg7;
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000462
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100463 for (i = 0; i < ARRAY_SIZE(regs->gpr); i++)
464 kvmppc_set_gpr(vcpu, i, regs->gpr[i]);
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000465
466 return 0;
467}
468
Alexander Graf2f4cf5e2009-10-30 05:47:10 +0000469int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
470{
471 return -ENOTSUPP;
472}
473
474int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
475{
476 return -ENOTSUPP;
477}
478
479int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
480 struct kvm_translation *tr)
481{
482 return 0;
483}
484
Scott Wooddfd4d472011-11-17 12:39:59 +0000485void kvmppc_decrementer_func(unsigned long data)
486{
487 struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
488
489 kvmppc_core_queue_dec(vcpu);
490 kvm_vcpu_kick(vcpu);
491}