KVM: Fix the explanation of write_emulated
[linux-2.6-block.git] / arch / powerpc / kvm / booke.c
CommitLineData
bbf45ba5
HB
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 IBM Corp. 2007
16 *
17 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
18 * Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
19 */
20
21#include <linux/errno.h>
22#include <linux/err.h>
23#include <linux/kvm_host.h>
24#include <linux/module.h>
25#include <linux/vmalloc.h>
26#include <linux/fs.h>
7924bd41 27
bbf45ba5
HB
28#include <asm/cputable.h>
29#include <asm/uaccess.h>
30#include <asm/kvm_ppc.h>
73e75b41 31#include "timing.h"
d9fbd03d 32#include <asm/cacheflush.h>
bbf45ba5 33
75f74f0d 34#include "booke.h"
bbf45ba5 35
d9fbd03d
HB
36unsigned long kvmppc_booke_handlers;
37
bbf45ba5
HB
38#define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM
39#define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
40
41struct kvm_stats_debugfs_item debugfs_entries[] = {
bbf45ba5
HB
42 { "mmio", VCPU_STAT(mmio_exits) },
43 { "dcr", VCPU_STAT(dcr_exits) },
44 { "sig", VCPU_STAT(signal_exits) },
bbf45ba5
HB
45 { "itlb_r", VCPU_STAT(itlb_real_miss_exits) },
46 { "itlb_v", VCPU_STAT(itlb_virt_miss_exits) },
47 { "dtlb_r", VCPU_STAT(dtlb_real_miss_exits) },
48 { "dtlb_v", VCPU_STAT(dtlb_virt_miss_exits) },
49 { "sysc", VCPU_STAT(syscall_exits) },
50 { "isi", VCPU_STAT(isi_exits) },
51 { "dsi", VCPU_STAT(dsi_exits) },
52 { "inst_emu", VCPU_STAT(emulated_inst_exits) },
53 { "dec", VCPU_STAT(dec_exits) },
54 { "ext_intr", VCPU_STAT(ext_intr_exits) },
45c5eb67 55 { "halt_wakeup", VCPU_STAT(halt_wakeup) },
bbf45ba5
HB
56 { NULL }
57};
58
bbf45ba5
HB
59/* TODO: use vcpu_printf() */
60void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu)
61{
62 int i;
63
5cf8ca22
HB
64 printk("pc: %08lx msr: %08lx\n", vcpu->arch.pc, vcpu->arch.msr);
65 printk("lr: %08lx ctr: %08lx\n", vcpu->arch.lr, vcpu->arch.ctr);
66 printk("srr0: %08lx srr1: %08lx\n", vcpu->arch.srr0, vcpu->arch.srr1);
bbf45ba5
HB
67
68 printk("exceptions: %08lx\n", vcpu->arch.pending_exceptions);
69
70 for (i = 0; i < 32; i += 4) {
5cf8ca22 71 printk("gpr%02d: %08lx %08lx %08lx %08lx\n", i,
bbf45ba5
HB
72 vcpu->arch.gpr[i],
73 vcpu->arch.gpr[i+1],
74 vcpu->arch.gpr[i+2],
75 vcpu->arch.gpr[i+3]);
76 }
77}
78
d4cf3892
HB
79static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,
80 unsigned int priority)
9dd921cf 81{
9dd921cf
HB
82 set_bit(priority, &vcpu->arch.pending_exceptions);
83}
84
9dd921cf
HB
85void kvmppc_core_queue_program(struct kvm_vcpu *vcpu)
86{
d4cf3892 87 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM);
9dd921cf
HB
88}
89
90void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu)
91{
d4cf3892 92 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DECREMENTER);
9dd921cf
HB
93}
94
95int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu)
96{
d4cf3892 97 return test_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions);
9dd921cf
HB
98}
99
7706664d
AG
100void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu)
101{
102 clear_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions);
103}
104
9dd921cf
HB
105void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
106 struct kvm_interrupt *irq)
107{
d4cf3892 108 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_EXTERNAL);
9dd921cf
HB
109}
110
d4cf3892
HB
111/* Deliver the interrupt of the corresponding priority, if possible. */
112static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,
113 unsigned int priority)
bbf45ba5 114{
d4cf3892
HB
115 int allowed = 0;
116 ulong msr_mask;
117
118 switch (priority) {
119 case BOOKE_IRQPRIO_PROGRAM:
120 case BOOKE_IRQPRIO_DTLB_MISS:
121 case BOOKE_IRQPRIO_ITLB_MISS:
122 case BOOKE_IRQPRIO_SYSCALL:
123 case BOOKE_IRQPRIO_DATA_STORAGE:
124 case BOOKE_IRQPRIO_INST_STORAGE:
125 case BOOKE_IRQPRIO_FP_UNAVAIL:
bb3a8a17
HB
126 case BOOKE_IRQPRIO_SPE_UNAVAIL:
127 case BOOKE_IRQPRIO_SPE_FP_DATA:
128 case BOOKE_IRQPRIO_SPE_FP_ROUND:
d4cf3892
HB
129 case BOOKE_IRQPRIO_AP_UNAVAIL:
130 case BOOKE_IRQPRIO_ALIGNMENT:
131 allowed = 1;
132 msr_mask = MSR_CE|MSR_ME|MSR_DE;
bbf45ba5 133 break;
d4cf3892
HB
134 case BOOKE_IRQPRIO_CRITICAL:
135 case BOOKE_IRQPRIO_WATCHDOG:
136 allowed = vcpu->arch.msr & MSR_CE;
137 msr_mask = MSR_ME;
bbf45ba5 138 break;
d4cf3892
HB
139 case BOOKE_IRQPRIO_MACHINE_CHECK:
140 allowed = vcpu->arch.msr & MSR_ME;
141 msr_mask = 0;
bbf45ba5 142 break;
d4cf3892
HB
143 case BOOKE_IRQPRIO_EXTERNAL:
144 case BOOKE_IRQPRIO_DECREMENTER:
145 case BOOKE_IRQPRIO_FIT:
146 allowed = vcpu->arch.msr & MSR_EE;
147 msr_mask = MSR_CE|MSR_ME|MSR_DE;
bbf45ba5 148 break;
d4cf3892
HB
149 case BOOKE_IRQPRIO_DEBUG:
150 allowed = vcpu->arch.msr & MSR_DE;
151 msr_mask = MSR_ME;
bbf45ba5 152 break;
bbf45ba5
HB
153 }
154
d4cf3892
HB
155 if (allowed) {
156 vcpu->arch.srr0 = vcpu->arch.pc;
157 vcpu->arch.srr1 = vcpu->arch.msr;
158 vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[priority];
159 kvmppc_set_msr(vcpu, vcpu->arch.msr & msr_mask);
bbf45ba5 160
d4cf3892 161 clear_bit(priority, &vcpu->arch.pending_exceptions);
bbf45ba5
HB
162 }
163
d4cf3892 164 return allowed;
bbf45ba5
HB
165}
166
167/* Check pending exceptions and deliver one, if possible. */
9dd921cf 168void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)
bbf45ba5
HB
169{
170 unsigned long *pending = &vcpu->arch.pending_exceptions;
bbf45ba5
HB
171 unsigned int priority;
172
9ab80843 173 priority = __ffs(*pending);
bdc89f13 174 while (priority <= BOOKE_IRQPRIO_MAX) {
d4cf3892 175 if (kvmppc_booke_irqprio_deliver(vcpu, priority))
bbf45ba5 176 break;
bbf45ba5
HB
177
178 priority = find_next_bit(pending,
179 BITS_PER_BYTE * sizeof(*pending),
180 priority + 1);
181 }
182}
183
bbf45ba5
HB
184/**
185 * kvmppc_handle_exit
186 *
187 * Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV)
188 */
189int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
190 unsigned int exit_nr)
191{
192 enum emulation_result er;
193 int r = RESUME_HOST;
194
73e75b41
HB
195 /* update before a new last_exit_type is rewritten */
196 kvmppc_update_timing_stats(vcpu);
197
bbf45ba5
HB
198 local_irq_enable();
199
200 run->exit_reason = KVM_EXIT_UNKNOWN;
201 run->ready_for_interrupt_injection = 1;
202
203 switch (exit_nr) {
204 case BOOKE_INTERRUPT_MACHINE_CHECK:
205 printk("MACHINE CHECK: %lx\n", mfspr(SPRN_MCSR));
206 kvmppc_dump_vcpu(vcpu);
207 r = RESUME_HOST;
208 break;
209
210 case BOOKE_INTERRUPT_EXTERNAL:
7b701591 211 kvmppc_account_exit(vcpu, EXT_INTR_EXITS);
1b6766c7
HB
212 if (need_resched())
213 cond_resched();
214 r = RESUME_GUEST;
215 break;
216
bbf45ba5
HB
217 case BOOKE_INTERRUPT_DECREMENTER:
218 /* Since we switched IVPR back to the host's value, the host
219 * handled this interrupt the moment we enabled interrupts.
220 * Now we just offer it a chance to reschedule the guest. */
7b701591 221 kvmppc_account_exit(vcpu, DEC_EXITS);
bbf45ba5
HB
222 if (need_resched())
223 cond_resched();
bbf45ba5
HB
224 r = RESUME_GUEST;
225 break;
226
227 case BOOKE_INTERRUPT_PROGRAM:
228 if (vcpu->arch.msr & MSR_PR) {
229 /* Program traps generated by user-level software must be handled
230 * by the guest kernel. */
231 vcpu->arch.esr = vcpu->arch.fault_esr;
d4cf3892 232 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM);
bbf45ba5 233 r = RESUME_GUEST;
7b701591 234 kvmppc_account_exit(vcpu, USR_PR_INST);
bbf45ba5
HB
235 break;
236 }
237
238 er = kvmppc_emulate_instruction(run, vcpu);
239 switch (er) {
240 case EMULATE_DONE:
73e75b41 241 /* don't overwrite subtypes, just account kvm_stats */
7b701591 242 kvmppc_account_exit_stat(vcpu, EMULATED_INST_EXITS);
bbf45ba5
HB
243 /* Future optimization: only reload non-volatiles if
244 * they were actually modified by emulation. */
bbf45ba5
HB
245 r = RESUME_GUEST_NV;
246 break;
247 case EMULATE_DO_DCR:
248 run->exit_reason = KVM_EXIT_DCR;
249 r = RESUME_HOST;
250 break;
251 case EMULATE_FAIL:
252 /* XXX Deliver Program interrupt to guest. */
5cf8ca22 253 printk(KERN_CRIT "%s: emulation at %lx failed (%08x)\n",
bbf45ba5
HB
254 __func__, vcpu->arch.pc, vcpu->arch.last_inst);
255 /* For debugging, encode the failing instruction and
256 * report it to userspace. */
257 run->hw.hardware_exit_reason = ~0ULL << 32;
258 run->hw.hardware_exit_reason |= vcpu->arch.last_inst;
259 r = RESUME_HOST;
260 break;
261 default:
262 BUG();
263 }
264 break;
265
de368dce 266 case BOOKE_INTERRUPT_FP_UNAVAIL:
d4cf3892 267 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_FP_UNAVAIL);
7b701591 268 kvmppc_account_exit(vcpu, FP_UNAVAIL);
de368dce
CE
269 r = RESUME_GUEST;
270 break;
271
bb3a8a17
HB
272 case BOOKE_INTERRUPT_SPE_UNAVAIL:
273 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_UNAVAIL);
274 r = RESUME_GUEST;
275 break;
276
277 case BOOKE_INTERRUPT_SPE_FP_DATA:
278 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_DATA);
279 r = RESUME_GUEST;
280 break;
281
282 case BOOKE_INTERRUPT_SPE_FP_ROUND:
283 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_ROUND);
284 r = RESUME_GUEST;
285 break;
286
bbf45ba5
HB
287 case BOOKE_INTERRUPT_DATA_STORAGE:
288 vcpu->arch.dear = vcpu->arch.fault_dear;
289 vcpu->arch.esr = vcpu->arch.fault_esr;
d4cf3892 290 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DATA_STORAGE);
7b701591 291 kvmppc_account_exit(vcpu, DSI_EXITS);
bbf45ba5
HB
292 r = RESUME_GUEST;
293 break;
294
295 case BOOKE_INTERRUPT_INST_STORAGE:
296 vcpu->arch.esr = vcpu->arch.fault_esr;
d4cf3892 297 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_INST_STORAGE);
7b701591 298 kvmppc_account_exit(vcpu, ISI_EXITS);
bbf45ba5
HB
299 r = RESUME_GUEST;
300 break;
301
302 case BOOKE_INTERRUPT_SYSCALL:
d4cf3892 303 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SYSCALL);
7b701591 304 kvmppc_account_exit(vcpu, SYSCALL_EXITS);
bbf45ba5
HB
305 r = RESUME_GUEST;
306 break;
307
308 case BOOKE_INTERRUPT_DTLB_MISS: {
bbf45ba5 309 unsigned long eaddr = vcpu->arch.fault_dear;
7924bd41 310 int gtlb_index;
475e7cdd 311 gpa_t gpaddr;
bbf45ba5
HB
312 gfn_t gfn;
313
314 /* Check the guest TLB. */
fa86b8dd 315 gtlb_index = kvmppc_mmu_dtlb_index(vcpu, eaddr);
7924bd41 316 if (gtlb_index < 0) {
bbf45ba5 317 /* The guest didn't have a mapping for it. */
d4cf3892 318 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DTLB_MISS);
bbf45ba5
HB
319 vcpu->arch.dear = vcpu->arch.fault_dear;
320 vcpu->arch.esr = vcpu->arch.fault_esr;
b52a638c 321 kvmppc_mmu_dtlb_miss(vcpu);
7b701591 322 kvmppc_account_exit(vcpu, DTLB_REAL_MISS_EXITS);
bbf45ba5
HB
323 r = RESUME_GUEST;
324 break;
325 }
326
be8d1cae 327 gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr);
475e7cdd 328 gfn = gpaddr >> PAGE_SHIFT;
bbf45ba5
HB
329
330 if (kvm_is_visible_gfn(vcpu->kvm, gfn)) {
331 /* The guest TLB had a mapping, but the shadow TLB
332 * didn't, and it is RAM. This could be because:
333 * a) the entry is mapping the host kernel, or
334 * b) the guest used a large mapping which we're faking
335 * Either way, we need to satisfy the fault without
336 * invoking the guest. */
58a96214 337 kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index);
7b701591 338 kvmppc_account_exit(vcpu, DTLB_VIRT_MISS_EXITS);
bbf45ba5
HB
339 r = RESUME_GUEST;
340 } else {
341 /* Guest has mapped and accessed a page which is not
342 * actually RAM. */
475e7cdd 343 vcpu->arch.paddr_accessed = gpaddr;
bbf45ba5 344 r = kvmppc_emulate_mmio(run, vcpu);
7b701591 345 kvmppc_account_exit(vcpu, MMIO_EXITS);
bbf45ba5
HB
346 }
347
348 break;
349 }
350
351 case BOOKE_INTERRUPT_ITLB_MISS: {
bbf45ba5 352 unsigned long eaddr = vcpu->arch.pc;
89168618 353 gpa_t gpaddr;
bbf45ba5 354 gfn_t gfn;
7924bd41 355 int gtlb_index;
bbf45ba5
HB
356
357 r = RESUME_GUEST;
358
359 /* Check the guest TLB. */
fa86b8dd 360 gtlb_index = kvmppc_mmu_itlb_index(vcpu, eaddr);
7924bd41 361 if (gtlb_index < 0) {
bbf45ba5 362 /* The guest didn't have a mapping for it. */
d4cf3892 363 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ITLB_MISS);
b52a638c 364 kvmppc_mmu_itlb_miss(vcpu);
7b701591 365 kvmppc_account_exit(vcpu, ITLB_REAL_MISS_EXITS);
bbf45ba5
HB
366 break;
367 }
368
7b701591 369 kvmppc_account_exit(vcpu, ITLB_VIRT_MISS_EXITS);
bbf45ba5 370
be8d1cae 371 gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr);
89168618 372 gfn = gpaddr >> PAGE_SHIFT;
bbf45ba5
HB
373
374 if (kvm_is_visible_gfn(vcpu->kvm, gfn)) {
375 /* The guest TLB had a mapping, but the shadow TLB
376 * didn't. This could be because:
377 * a) the entry is mapping the host kernel, or
378 * b) the guest used a large mapping which we're faking
379 * Either way, we need to satisfy the fault without
380 * invoking the guest. */
58a96214 381 kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index);
bbf45ba5
HB
382 } else {
383 /* Guest mapped and leaped at non-RAM! */
d4cf3892 384 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_MACHINE_CHECK);
bbf45ba5
HB
385 }
386
387 break;
388 }
389
6a0ab738
HB
390 case BOOKE_INTERRUPT_DEBUG: {
391 u32 dbsr;
392
393 vcpu->arch.pc = mfspr(SPRN_CSRR0);
394
395 /* clear IAC events in DBSR register */
396 dbsr = mfspr(SPRN_DBSR);
397 dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
398 mtspr(SPRN_DBSR, dbsr);
399
400 run->exit_reason = KVM_EXIT_DEBUG;
7b701591 401 kvmppc_account_exit(vcpu, DEBUG_EXITS);
6a0ab738
HB
402 r = RESUME_HOST;
403 break;
404 }
405
bbf45ba5
HB
406 default:
407 printk(KERN_EMERG "exit_nr %d\n", exit_nr);
408 BUG();
409 }
410
411 local_irq_disable();
412
9dd921cf 413 kvmppc_core_deliver_interrupts(vcpu);
bbf45ba5 414
bbf45ba5
HB
415 if (!(r & RESUME_HOST)) {
416 /* To avoid clobbering exit_reason, only check for signals if
417 * we aren't already exiting to userspace for some other
418 * reason. */
419 if (signal_pending(current)) {
420 run->exit_reason = KVM_EXIT_INTR;
421 r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
7b701591 422 kvmppc_account_exit(vcpu, SIGNAL_EXITS);
bbf45ba5
HB
423 }
424 }
425
426 return r;
427}
428
429/* Initial guest state: 16MB mapping 0 -> 0, PC = 0, MSR = 0, R1 = 16MB */
430int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
431{
bbf45ba5
HB
432 vcpu->arch.pc = 0;
433 vcpu->arch.msr = 0;
434 vcpu->arch.gpr[1] = (16<<20) - 8; /* -8 for the callee-save LR slot */
435
49dd2c49
HB
436 vcpu->arch.shadow_pid = 1;
437
bbf45ba5
HB
438 /* Eye-catching number so we know if the guest takes an interrupt
439 * before it's programmed its own IVPR. */
440 vcpu->arch.ivpr = 0x55550000;
441
73e75b41
HB
442 kvmppc_init_timing_stats(vcpu);
443
5cbb5106 444 return kvmppc_core_vcpu_setup(vcpu);
bbf45ba5
HB
445}
446
447int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
448{
449 int i;
450
451 regs->pc = vcpu->arch.pc;
452 regs->cr = vcpu->arch.cr;
453 regs->ctr = vcpu->arch.ctr;
454 regs->lr = vcpu->arch.lr;
455 regs->xer = vcpu->arch.xer;
456 regs->msr = vcpu->arch.msr;
457 regs->srr0 = vcpu->arch.srr0;
458 regs->srr1 = vcpu->arch.srr1;
459 regs->pid = vcpu->arch.pid;
460 regs->sprg0 = vcpu->arch.sprg0;
461 regs->sprg1 = vcpu->arch.sprg1;
462 regs->sprg2 = vcpu->arch.sprg2;
463 regs->sprg3 = vcpu->arch.sprg3;
464 regs->sprg5 = vcpu->arch.sprg4;
465 regs->sprg6 = vcpu->arch.sprg5;
466 regs->sprg7 = vcpu->arch.sprg6;
467
468 for (i = 0; i < ARRAY_SIZE(regs->gpr); i++)
469 regs->gpr[i] = vcpu->arch.gpr[i];
470
471 return 0;
472}
473
474int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
475{
476 int i;
477
478 vcpu->arch.pc = regs->pc;
479 vcpu->arch.cr = regs->cr;
480 vcpu->arch.ctr = regs->ctr;
481 vcpu->arch.lr = regs->lr;
482 vcpu->arch.xer = regs->xer;
b8fd68ac 483 kvmppc_set_msr(vcpu, regs->msr);
bbf45ba5
HB
484 vcpu->arch.srr0 = regs->srr0;
485 vcpu->arch.srr1 = regs->srr1;
486 vcpu->arch.sprg0 = regs->sprg0;
487 vcpu->arch.sprg1 = regs->sprg1;
488 vcpu->arch.sprg2 = regs->sprg2;
489 vcpu->arch.sprg3 = regs->sprg3;
490 vcpu->arch.sprg5 = regs->sprg4;
491 vcpu->arch.sprg6 = regs->sprg5;
492 vcpu->arch.sprg7 = regs->sprg6;
493
494 for (i = 0; i < ARRAY_SIZE(vcpu->arch.gpr); i++)
495 vcpu->arch.gpr[i] = regs->gpr[i];
496
497 return 0;
498}
499
500int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
501 struct kvm_sregs *sregs)
502{
503 return -ENOTSUPP;
504}
505
506int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
507 struct kvm_sregs *sregs)
508{
509 return -ENOTSUPP;
510}
511
512int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
513{
514 return -ENOTSUPP;
515}
516
517int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
518{
519 return -ENOTSUPP;
520}
521
bbf45ba5
HB
522int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
523 struct kvm_translation *tr)
524{
5cbb5106 525 return kvmppc_core_vcpu_translate(vcpu, tr);
bbf45ba5 526}
d9fbd03d 527
4e755758
AG
528int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
529{
530 return -ENOTSUPP;
531}
532
2986b8c7 533int __init kvmppc_booke_init(void)
d9fbd03d
HB
534{
535 unsigned long ivor[16];
536 unsigned long max_ivor = 0;
537 int i;
538
539 /* We install our own exception handlers by hijacking IVPR. IVPR must
540 * be 16-bit aligned, so we need a 64KB allocation. */
541 kvmppc_booke_handlers = __get_free_pages(GFP_KERNEL | __GFP_ZERO,
542 VCPU_SIZE_ORDER);
543 if (!kvmppc_booke_handlers)
544 return -ENOMEM;
545
546 /* XXX make sure our handlers are smaller than Linux's */
547
548 /* Copy our interrupt handlers to match host IVORs. That way we don't
549 * have to swap the IVORs on every guest/host transition. */
550 ivor[0] = mfspr(SPRN_IVOR0);
551 ivor[1] = mfspr(SPRN_IVOR1);
552 ivor[2] = mfspr(SPRN_IVOR2);
553 ivor[3] = mfspr(SPRN_IVOR3);
554 ivor[4] = mfspr(SPRN_IVOR4);
555 ivor[5] = mfspr(SPRN_IVOR5);
556 ivor[6] = mfspr(SPRN_IVOR6);
557 ivor[7] = mfspr(SPRN_IVOR7);
558 ivor[8] = mfspr(SPRN_IVOR8);
559 ivor[9] = mfspr(SPRN_IVOR9);
560 ivor[10] = mfspr(SPRN_IVOR10);
561 ivor[11] = mfspr(SPRN_IVOR11);
562 ivor[12] = mfspr(SPRN_IVOR12);
563 ivor[13] = mfspr(SPRN_IVOR13);
564 ivor[14] = mfspr(SPRN_IVOR14);
565 ivor[15] = mfspr(SPRN_IVOR15);
566
567 for (i = 0; i < 16; i++) {
568 if (ivor[i] > max_ivor)
569 max_ivor = ivor[i];
570
571 memcpy((void *)kvmppc_booke_handlers + ivor[i],
572 kvmppc_handlers_start + i * kvmppc_handler_len,
573 kvmppc_handler_len);
574 }
575 flush_icache_range(kvmppc_booke_handlers,
576 kvmppc_booke_handlers + max_ivor + kvmppc_handler_len);
577
db93f574 578 return 0;
d9fbd03d
HB
579}
580
db93f574 581void __exit kvmppc_booke_exit(void)
d9fbd03d
HB
582{
583 free_pages(kvmppc_booke_handlers, VCPU_SIZE_ORDER);
584 kvm_exit();
585}