blob: 75dbaeb2efa350061c9f4457b988da353ecfcc1d [file] [log] [blame]
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -05001/*
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
Scott Wood4cd35f62011-06-14 18:34:31 -050016 * Copyright 2010-2011 Freescale Semiconductor, Inc.
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050017 *
18 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
19 * Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
Scott Woodd30f6e42011-12-20 15:34:43 +000020 * Scott Wood <scottwood@freescale.com>
21 * Varun Sethi <varun.sethi@freescale.com>
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050022 */
23
24#include <linux/errno.h>
25#include <linux/err.h>
26#include <linux/kvm_host.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/gfp.h>
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050028#include <linux/module.h>
29#include <linux/vmalloc.h>
30#include <linux/fs.h>
Hollis Blanchard7924bd42008-12-02 15:51:55 -060031
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050032#include <asm/cputable.h>
33#include <asm/uaccess.h>
34#include <asm/kvm_ppc.h>
Hollis Blanchardd9fbd032008-11-05 09:36:13 -060035#include <asm/cacheflush.h>
Scott Woodd30f6e42011-12-20 15:34:43 +000036#include <asm/dbell.h>
37#include <asm/hw_irq.h>
38#include <asm/irq.h>
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050039
Scott Woodd30f6e42011-12-20 15:34:43 +000040#include "timing.h"
Hollis Blanchard75f74f02008-11-05 09:36:16 -060041#include "booke.h"
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050042
Hollis Blanchardd9fbd032008-11-05 09:36:13 -060043unsigned long kvmppc_booke_handlers;
44
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050045#define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM
46#define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
47
48struct kvm_stats_debugfs_item debugfs_entries[] = {
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050049 { "mmio", VCPU_STAT(mmio_exits) },
50 { "dcr", VCPU_STAT(dcr_exits) },
51 { "sig", VCPU_STAT(signal_exits) },
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050052 { "itlb_r", VCPU_STAT(itlb_real_miss_exits) },
53 { "itlb_v", VCPU_STAT(itlb_virt_miss_exits) },
54 { "dtlb_r", VCPU_STAT(dtlb_real_miss_exits) },
55 { "dtlb_v", VCPU_STAT(dtlb_virt_miss_exits) },
56 { "sysc", VCPU_STAT(syscall_exits) },
57 { "isi", VCPU_STAT(isi_exits) },
58 { "dsi", VCPU_STAT(dsi_exits) },
59 { "inst_emu", VCPU_STAT(emulated_inst_exits) },
60 { "dec", VCPU_STAT(dec_exits) },
61 { "ext_intr", VCPU_STAT(ext_intr_exits) },
Hollis Blanchard45c5eb62008-04-25 17:55:49 -050062 { "halt_wakeup", VCPU_STAT(halt_wakeup) },
Scott Woodd30f6e42011-12-20 15:34:43 +000063 { "doorbell", VCPU_STAT(dbell_exits) },
64 { "guest doorbell", VCPU_STAT(gdbell_exits) },
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050065 { NULL }
66};
67
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050068/* TODO: use vcpu_printf() */
69void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu)
70{
71 int i;
72
Alexander Graf666e7252010-07-29 14:47:43 +020073 printk("pc: %08lx msr: %08llx\n", vcpu->arch.pc, vcpu->arch.shared->msr);
Hollis Blanchard5cf8ca22008-11-05 09:36:19 -060074 printk("lr: %08lx ctr: %08lx\n", vcpu->arch.lr, vcpu->arch.ctr);
Alexander Grafde7906c2010-07-29 14:47:46 +020075 printk("srr0: %08llx srr1: %08llx\n", vcpu->arch.shared->srr0,
76 vcpu->arch.shared->srr1);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050077
78 printk("exceptions: %08lx\n", vcpu->arch.pending_exceptions);
79
80 for (i = 0; i < 32; i += 4) {
Hollis Blanchard5cf8ca22008-11-05 09:36:19 -060081 printk("gpr%02d: %08lx %08lx %08lx %08lx\n", i,
Alexander Graf8e5b26b2010-01-08 02:58:01 +010082 kvmppc_get_gpr(vcpu, i),
83 kvmppc_get_gpr(vcpu, i+1),
84 kvmppc_get_gpr(vcpu, i+2),
85 kvmppc_get_gpr(vcpu, i+3));
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050086 }
87}
88
Scott Wood4cd35f62011-06-14 18:34:31 -050089#ifdef CONFIG_SPE
90void kvmppc_vcpu_disable_spe(struct kvm_vcpu *vcpu)
91{
92 preempt_disable();
93 enable_kernel_spe();
94 kvmppc_save_guest_spe(vcpu);
95 vcpu->arch.shadow_msr &= ~MSR_SPE;
96 preempt_enable();
97}
98
99static void kvmppc_vcpu_enable_spe(struct kvm_vcpu *vcpu)
100{
101 preempt_disable();
102 enable_kernel_spe();
103 kvmppc_load_guest_spe(vcpu);
104 vcpu->arch.shadow_msr |= MSR_SPE;
105 preempt_enable();
106}
107
108static void kvmppc_vcpu_sync_spe(struct kvm_vcpu *vcpu)
109{
110 if (vcpu->arch.shared->msr & MSR_SPE) {
111 if (!(vcpu->arch.shadow_msr & MSR_SPE))
112 kvmppc_vcpu_enable_spe(vcpu);
113 } else if (vcpu->arch.shadow_msr & MSR_SPE) {
114 kvmppc_vcpu_disable_spe(vcpu);
115 }
116}
117#else
118static void kvmppc_vcpu_sync_spe(struct kvm_vcpu *vcpu)
119{
120}
121#endif
122
Liu Yudd9ebf1f2011-06-14 18:35:14 -0500123/*
124 * Helper function for "full" MSR writes. No need to call this if only
125 * EE/CE/ME/DE/RI are changing.
126 */
Scott Wood4cd35f62011-06-14 18:34:31 -0500127void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr)
128{
Liu Yudd9ebf1f2011-06-14 18:35:14 -0500129 u32 old_msr = vcpu->arch.shared->msr;
Scott Wood4cd35f62011-06-14 18:34:31 -0500130
Scott Woodd30f6e42011-12-20 15:34:43 +0000131#ifdef CONFIG_KVM_BOOKE_HV
132 new_msr |= MSR_GS;
133#endif
134
Scott Wood4cd35f62011-06-14 18:34:31 -0500135 vcpu->arch.shared->msr = new_msr;
136
Liu Yudd9ebf1f2011-06-14 18:35:14 -0500137 kvmppc_mmu_msr_notify(vcpu, old_msr);
Scott Wood4cd35f62011-06-14 18:34:31 -0500138 kvmppc_vcpu_sync_spe(vcpu);
139}
140
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600141static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,
142 unsigned int priority)
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600143{
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600144 set_bit(priority, &vcpu->arch.pending_exceptions);
145}
146
Liu Yudaf5e272010-02-02 19:44:35 +0800147static void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu,
148 ulong dear_flags, ulong esr_flags)
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600149{
Liu Yudaf5e272010-02-02 19:44:35 +0800150 vcpu->arch.queued_dear = dear_flags;
151 vcpu->arch.queued_esr = esr_flags;
152 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DTLB_MISS);
153}
154
155static void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu,
156 ulong dear_flags, ulong esr_flags)
157{
158 vcpu->arch.queued_dear = dear_flags;
159 vcpu->arch.queued_esr = esr_flags;
160 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DATA_STORAGE);
161}
162
163static void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu,
164 ulong esr_flags)
165{
166 vcpu->arch.queued_esr = esr_flags;
167 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_INST_STORAGE);
168}
169
170void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong esr_flags)
171{
172 vcpu->arch.queued_esr = esr_flags;
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600173 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM);
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600174}
175
176void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu)
177{
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600178 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DECREMENTER);
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600179}
180
181int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu)
182{
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600183 return test_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions);
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600184}
185
Alexander Graf7706664d2009-12-21 20:21:24 +0100186void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu)
187{
188 clear_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions);
189}
190
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600191void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
192 struct kvm_interrupt *irq)
193{
Alexander Grafc5335f12010-08-30 14:03:24 +0200194 unsigned int prio = BOOKE_IRQPRIO_EXTERNAL;
195
196 if (irq->irq == KVM_INTERRUPT_SET_LEVEL)
197 prio = BOOKE_IRQPRIO_EXTERNAL_LEVEL;
198
199 kvmppc_booke_queue_irqprio(vcpu, prio);
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600200}
201
Alexander Graf4496f972010-04-07 10:03:25 +0200202void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu,
203 struct kvm_interrupt *irq)
204{
205 clear_bit(BOOKE_IRQPRIO_EXTERNAL, &vcpu->arch.pending_exceptions);
Alexander Grafc5335f12010-08-30 14:03:24 +0200206 clear_bit(BOOKE_IRQPRIO_EXTERNAL_LEVEL, &vcpu->arch.pending_exceptions);
Alexander Graf4496f972010-04-07 10:03:25 +0200207}
208
Scott Woodd30f6e42011-12-20 15:34:43 +0000209static void set_guest_srr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1)
210{
211#ifdef CONFIG_KVM_BOOKE_HV
212 mtspr(SPRN_GSRR0, srr0);
213 mtspr(SPRN_GSRR1, srr1);
214#else
215 vcpu->arch.shared->srr0 = srr0;
216 vcpu->arch.shared->srr1 = srr1;
217#endif
218}
219
220static void set_guest_csrr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1)
221{
222 vcpu->arch.csrr0 = srr0;
223 vcpu->arch.csrr1 = srr1;
224}
225
226static void set_guest_dsrr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1)
227{
228 if (cpu_has_feature(CPU_FTR_DEBUG_LVL_EXC)) {
229 vcpu->arch.dsrr0 = srr0;
230 vcpu->arch.dsrr1 = srr1;
231 } else {
232 set_guest_csrr(vcpu, srr0, srr1);
233 }
234}
235
236static void set_guest_mcsrr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1)
237{
238 vcpu->arch.mcsrr0 = srr0;
239 vcpu->arch.mcsrr1 = srr1;
240}
241
242static unsigned long get_guest_dear(struct kvm_vcpu *vcpu)
243{
244#ifdef CONFIG_KVM_BOOKE_HV
245 return mfspr(SPRN_GDEAR);
246#else
247 return vcpu->arch.shared->dar;
248#endif
249}
250
251static void set_guest_dear(struct kvm_vcpu *vcpu, unsigned long dear)
252{
253#ifdef CONFIG_KVM_BOOKE_HV
254 mtspr(SPRN_GDEAR, dear);
255#else
256 vcpu->arch.shared->dar = dear;
257#endif
258}
259
260static unsigned long get_guest_esr(struct kvm_vcpu *vcpu)
261{
262#ifdef CONFIG_KVM_BOOKE_HV
263 return mfspr(SPRN_GESR);
264#else
265 return vcpu->arch.shared->esr;
266#endif
267}
268
269static void set_guest_esr(struct kvm_vcpu *vcpu, u32 esr)
270{
271#ifdef CONFIG_KVM_BOOKE_HV
272 mtspr(SPRN_GESR, esr);
273#else
274 vcpu->arch.shared->esr = esr;
275#endif
276}
277
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600278/* Deliver the interrupt of the corresponding priority, if possible. */
279static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,
280 unsigned int priority)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500281{
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600282 int allowed = 0;
Asias He6045be52010-06-19 16:52:12 +0800283 ulong uninitialized_var(msr_mask);
Liu Yudaf5e272010-02-02 19:44:35 +0800284 bool update_esr = false, update_dear = false;
Alexander Graf5c6cedf2010-07-29 14:47:49 +0200285 ulong crit_raw = vcpu->arch.shared->critical;
286 ulong crit_r1 = kvmppc_get_gpr(vcpu, 1);
287 bool crit;
Alexander Grafc5335f12010-08-30 14:03:24 +0200288 bool keep_irq = false;
Scott Woodd30f6e42011-12-20 15:34:43 +0000289 enum int_class int_class;
Alexander Graf5c6cedf2010-07-29 14:47:49 +0200290
291 /* Truncate crit indicators in 32 bit mode */
292 if (!(vcpu->arch.shared->msr & MSR_SF)) {
293 crit_raw &= 0xffffffff;
294 crit_r1 &= 0xffffffff;
295 }
296
297 /* Critical section when crit == r1 */
298 crit = (crit_raw == crit_r1);
299 /* ... and we're in supervisor mode */
300 crit = crit && !(vcpu->arch.shared->msr & MSR_PR);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500301
Alexander Grafc5335f12010-08-30 14:03:24 +0200302 if (priority == BOOKE_IRQPRIO_EXTERNAL_LEVEL) {
303 priority = BOOKE_IRQPRIO_EXTERNAL;
304 keep_irq = true;
305 }
306
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600307 switch (priority) {
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600308 case BOOKE_IRQPRIO_DTLB_MISS:
Liu Yudaf5e272010-02-02 19:44:35 +0800309 case BOOKE_IRQPRIO_DATA_STORAGE:
310 update_dear = true;
311 /* fall through */
312 case BOOKE_IRQPRIO_INST_STORAGE:
313 case BOOKE_IRQPRIO_PROGRAM:
314 update_esr = true;
315 /* fall through */
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600316 case BOOKE_IRQPRIO_ITLB_MISS:
317 case BOOKE_IRQPRIO_SYSCALL:
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600318 case BOOKE_IRQPRIO_FP_UNAVAIL:
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600319 case BOOKE_IRQPRIO_SPE_UNAVAIL:
320 case BOOKE_IRQPRIO_SPE_FP_DATA:
321 case BOOKE_IRQPRIO_SPE_FP_ROUND:
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600322 case BOOKE_IRQPRIO_AP_UNAVAIL:
323 case BOOKE_IRQPRIO_ALIGNMENT:
324 allowed = 1;
Scott Woodd30f6e42011-12-20 15:34:43 +0000325 msr_mask = MSR_GS | MSR_CE | MSR_ME | MSR_DE;
326 int_class = INT_CLASS_NONCRIT;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500327 break;
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600328 case BOOKE_IRQPRIO_CRITICAL:
Alexander Graf666e7252010-07-29 14:47:43 +0200329 allowed = vcpu->arch.shared->msr & MSR_CE;
Scott Woodd30f6e42011-12-20 15:34:43 +0000330 allowed = allowed && !crit;
331 msr_mask = MSR_GS | MSR_ME;
332 int_class = INT_CLASS_CRIT;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500333 break;
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600334 case BOOKE_IRQPRIO_MACHINE_CHECK:
Alexander Graf666e7252010-07-29 14:47:43 +0200335 allowed = vcpu->arch.shared->msr & MSR_ME;
Scott Woodd30f6e42011-12-20 15:34:43 +0000336 allowed = allowed && !crit;
337 msr_mask = MSR_GS;
338 int_class = INT_CLASS_MC;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500339 break;
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600340 case BOOKE_IRQPRIO_DECREMENTER:
341 case BOOKE_IRQPRIO_FIT:
Scott Wooddfd4d472011-11-17 12:39:59 +0000342 keep_irq = true;
343 /* fall through */
344 case BOOKE_IRQPRIO_EXTERNAL:
Alexander Graf666e7252010-07-29 14:47:43 +0200345 allowed = vcpu->arch.shared->msr & MSR_EE;
Alexander Graf5c6cedf2010-07-29 14:47:49 +0200346 allowed = allowed && !crit;
Scott Woodd30f6e42011-12-20 15:34:43 +0000347 msr_mask = MSR_GS | MSR_CE | MSR_ME | MSR_DE;
348 int_class = INT_CLASS_NONCRIT;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500349 break;
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600350 case BOOKE_IRQPRIO_DEBUG:
Alexander Graf666e7252010-07-29 14:47:43 +0200351 allowed = vcpu->arch.shared->msr & MSR_DE;
Scott Woodd30f6e42011-12-20 15:34:43 +0000352 allowed = allowed && !crit;
353 msr_mask = MSR_GS | MSR_ME;
354 int_class = INT_CLASS_CRIT;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500355 break;
356 }
357
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600358 if (allowed) {
Scott Woodd30f6e42011-12-20 15:34:43 +0000359 switch (int_class) {
360 case INT_CLASS_NONCRIT:
361 set_guest_srr(vcpu, vcpu->arch.pc,
362 vcpu->arch.shared->msr);
363 break;
364 case INT_CLASS_CRIT:
365 set_guest_csrr(vcpu, vcpu->arch.pc,
366 vcpu->arch.shared->msr);
367 break;
368 case INT_CLASS_DBG:
369 set_guest_dsrr(vcpu, vcpu->arch.pc,
370 vcpu->arch.shared->msr);
371 break;
372 case INT_CLASS_MC:
373 set_guest_mcsrr(vcpu, vcpu->arch.pc,
374 vcpu->arch.shared->msr);
375 break;
376 }
377
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600378 vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[priority];
Liu Yudaf5e272010-02-02 19:44:35 +0800379 if (update_esr == true)
Scott Woodd30f6e42011-12-20 15:34:43 +0000380 set_guest_esr(vcpu, vcpu->arch.queued_esr);
Liu Yudaf5e272010-02-02 19:44:35 +0800381 if (update_dear == true)
Scott Woodd30f6e42011-12-20 15:34:43 +0000382 set_guest_dear(vcpu, vcpu->arch.queued_dear);
Alexander Graf666e7252010-07-29 14:47:43 +0200383 kvmppc_set_msr(vcpu, vcpu->arch.shared->msr & msr_mask);
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600384
Alexander Grafc5335f12010-08-30 14:03:24 +0200385 if (!keep_irq)
386 clear_bit(priority, &vcpu->arch.pending_exceptions);
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600387 }
388
Scott Woodd30f6e42011-12-20 15:34:43 +0000389#ifdef CONFIG_KVM_BOOKE_HV
390 /*
391 * If an interrupt is pending but masked, raise a guest doorbell
392 * so that we are notified when the guest enables the relevant
393 * MSR bit.
394 */
395 if (vcpu->arch.pending_exceptions & BOOKE_IRQMASK_EE)
396 kvmppc_set_pending_interrupt(vcpu, INT_CLASS_NONCRIT);
397 if (vcpu->arch.pending_exceptions & BOOKE_IRQMASK_CE)
398 kvmppc_set_pending_interrupt(vcpu, INT_CLASS_CRIT);
399 if (vcpu->arch.pending_exceptions & BOOKE_IRQPRIO_MACHINE_CHECK)
400 kvmppc_set_pending_interrupt(vcpu, INT_CLASS_MC);
401#endif
402
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600403 return allowed;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500404}
405
Scott Wooddfd4d472011-11-17 12:39:59 +0000406static void update_timer_ints(struct kvm_vcpu *vcpu)
407{
408 if ((vcpu->arch.tcr & TCR_DIE) && (vcpu->arch.tsr & TSR_DIS))
409 kvmppc_core_queue_dec(vcpu);
410 else
411 kvmppc_core_dequeue_dec(vcpu);
412}
413
Scott Woodc59a6a32011-11-08 18:23:25 -0600414static void kvmppc_core_check_exceptions(struct kvm_vcpu *vcpu)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500415{
416 unsigned long *pending = &vcpu->arch.pending_exceptions;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500417 unsigned int priority;
418
Scott Wooddfd4d472011-11-17 12:39:59 +0000419 if (vcpu->requests) {
420 if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu)) {
421 smp_mb();
422 update_timer_ints(vcpu);
423 }
424 }
425
Hollis Blanchard9ab80842008-11-05 09:36:22 -0600426 priority = __ffs(*pending);
Hollis Blanchardbdc89f12009-01-03 16:23:12 -0600427 while (priority <= BOOKE_IRQPRIO_MAX) {
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600428 if (kvmppc_booke_irqprio_deliver(vcpu, priority))
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500429 break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500430
431 priority = find_next_bit(pending,
432 BITS_PER_BYTE * sizeof(*pending),
433 priority + 1);
434 }
Alexander Graf90bba352010-07-29 14:47:51 +0200435
436 /* Tell the guest about our interrupt status */
Scott Wood29ac26e2011-11-08 18:23:27 -0600437 vcpu->arch.shared->int_pending = !!*pending;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500438}
439
Scott Woodc59a6a32011-11-08 18:23:25 -0600440/* Check pending exceptions and deliver one, if possible. */
441void kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
442{
443 WARN_ON_ONCE(!irqs_disabled());
444
445 kvmppc_core_check_exceptions(vcpu);
446
447 if (vcpu->arch.shared->msr & MSR_WE) {
448 local_irq_enable();
449 kvm_vcpu_block(vcpu);
450 local_irq_disable();
451
452 kvmppc_set_exit_type(vcpu, EMULATED_MTMSRWE_EXITS);
453 kvmppc_core_check_exceptions(vcpu);
454 };
455}
456
Paul Mackerrasdf6909e52011-06-29 00:19:50 +0000457int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
458{
459 int ret;
460
Alexander Grafaf8f38b2011-08-10 13:57:08 +0200461 if (!vcpu->arch.sane) {
462 kvm_run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
463 return -EINVAL;
464 }
465
Scott Woodd30f6e42011-12-20 15:34:43 +0000466 if (!current->thread.kvm_vcpu) {
467 WARN(1, "no vcpu\n");
468 return -EPERM;
469 }
470
Paul Mackerrasdf6909e52011-06-29 00:19:50 +0000471 local_irq_disable();
Scott Wood1d1ef222011-11-08 16:11:59 -0600472
Scott Wood25051b52011-11-08 18:23:23 -0600473 kvmppc_core_prepare_to_enter(vcpu);
474
Scott Wood1d1ef222011-11-08 16:11:59 -0600475 if (signal_pending(current)) {
476 kvm_run->exit_reason = KVM_EXIT_INTR;
477 ret = -EINTR;
478 goto out;
479 }
480
Paul Mackerrasdf6909e52011-06-29 00:19:50 +0000481 kvm_guest_enter();
482 ret = __kvmppc_vcpu_run(kvm_run, vcpu);
483 kvm_guest_exit();
Paul Mackerrasdf6909e52011-06-29 00:19:50 +0000484
Scott Wood1d1ef222011-11-08 16:11:59 -0600485out:
486 local_irq_enable();
Paul Mackerrasdf6909e52011-06-29 00:19:50 +0000487 return ret;
488}
489
Scott Woodd30f6e42011-12-20 15:34:43 +0000490static int emulation_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
491{
492 enum emulation_result er;
493
494 er = kvmppc_emulate_instruction(run, vcpu);
495 switch (er) {
496 case EMULATE_DONE:
497 /* don't overwrite subtypes, just account kvm_stats */
498 kvmppc_account_exit_stat(vcpu, EMULATED_INST_EXITS);
499 /* Future optimization: only reload non-volatiles if
500 * they were actually modified by emulation. */
501 return RESUME_GUEST_NV;
502
503 case EMULATE_DO_DCR:
504 run->exit_reason = KVM_EXIT_DCR;
505 return RESUME_HOST;
506
507 case EMULATE_FAIL:
508 /* XXX Deliver Program interrupt to guest. */
509 printk(KERN_CRIT "%s: emulation at %lx failed (%08x)\n",
510 __func__, vcpu->arch.pc, vcpu->arch.last_inst);
511 /* For debugging, encode the failing instruction and
512 * report it to userspace. */
513 run->hw.hardware_exit_reason = ~0ULL << 32;
514 run->hw.hardware_exit_reason |= vcpu->arch.last_inst;
515 return RESUME_HOST;
516
517 default:
518 BUG();
519 }
520}
521
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500522/**
523 * kvmppc_handle_exit
524 *
525 * Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV)
526 */
527int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
528 unsigned int exit_nr)
529{
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500530 int r = RESUME_HOST;
531
Hollis Blanchard73e75b42008-12-02 15:51:57 -0600532 /* update before a new last_exit_type is rewritten */
533 kvmppc_update_timing_stats(vcpu);
534
Scott Woodd30f6e42011-12-20 15:34:43 +0000535 switch (exit_nr) {
536 case BOOKE_INTERRUPT_EXTERNAL:
537 do_IRQ(current->thread.regs);
538 break;
539
540 case BOOKE_INTERRUPT_DECREMENTER:
541 timer_interrupt(current->thread.regs);
542 break;
543
544#if defined(CONFIG_PPC_FSL_BOOK3E) || defined(CONFIG_PPC_BOOK3E_64)
545 case BOOKE_INTERRUPT_DOORBELL:
546 doorbell_exception(current->thread.regs);
547 break;
548#endif
549 case BOOKE_INTERRUPT_MACHINE_CHECK:
550 /* FIXME */
551 break;
552 }
553
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500554 local_irq_enable();
555
556 run->exit_reason = KVM_EXIT_UNKNOWN;
557 run->ready_for_interrupt_injection = 1;
558
559 switch (exit_nr) {
560 case BOOKE_INTERRUPT_MACHINE_CHECK:
Scott Woodd30f6e42011-12-20 15:34:43 +0000561 kvm_resched(vcpu);
562 r = RESUME_GUEST;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500563 break;
564
565 case BOOKE_INTERRUPT_EXTERNAL:
Hollis Blanchard7b701592008-12-02 15:51:58 -0600566 kvmppc_account_exit(vcpu, EXT_INTR_EXITS);
Scott Woodd30f6e42011-12-20 15:34:43 +0000567 kvm_resched(vcpu);
Hollis Blanchard1b6766c2008-11-05 09:36:21 -0600568 r = RESUME_GUEST;
569 break;
570
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500571 case BOOKE_INTERRUPT_DECREMENTER:
Hollis Blanchard7b701592008-12-02 15:51:58 -0600572 kvmppc_account_exit(vcpu, DEC_EXITS);
Scott Woodd30f6e42011-12-20 15:34:43 +0000573 kvm_resched(vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500574 r = RESUME_GUEST;
575 break;
576
Scott Woodd30f6e42011-12-20 15:34:43 +0000577 case BOOKE_INTERRUPT_DOORBELL:
578 kvmppc_account_exit(vcpu, DBELL_EXITS);
579 kvm_resched(vcpu);
580 r = RESUME_GUEST;
581 break;
582
583 case BOOKE_INTERRUPT_GUEST_DBELL_CRIT:
584 kvmppc_account_exit(vcpu, GDBELL_EXITS);
585
586 /*
587 * We are here because there is a pending guest interrupt
588 * which could not be delivered as MSR_CE or MSR_ME was not
589 * set. Once we break from here we will retry delivery.
590 */
591 r = RESUME_GUEST;
592 break;
593
594 case BOOKE_INTERRUPT_GUEST_DBELL:
595 kvmppc_account_exit(vcpu, GDBELL_EXITS);
596
597 /*
598 * We are here because there is a pending guest interrupt
599 * which could not be delivered as MSR_EE was not set. Once
600 * we break from here we will retry delivery.
601 */
602 r = RESUME_GUEST;
603 break;
604
605 case BOOKE_INTERRUPT_HV_PRIV:
606 r = emulation_exit(run, vcpu);
607 break;
608
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500609 case BOOKE_INTERRUPT_PROGRAM:
Scott Woodd30f6e42011-12-20 15:34:43 +0000610 if (vcpu->arch.shared->msr & (MSR_PR | MSR_GS)) {
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500611 /* Program traps generated by user-level software must be handled
612 * by the guest kernel. */
Liu Yudaf5e272010-02-02 19:44:35 +0800613 kvmppc_core_queue_program(vcpu, vcpu->arch.fault_esr);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500614 r = RESUME_GUEST;
Hollis Blanchard7b701592008-12-02 15:51:58 -0600615 kvmppc_account_exit(vcpu, USR_PR_INST);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500616 break;
617 }
618
Scott Woodd30f6e42011-12-20 15:34:43 +0000619 r = emulation_exit(run, vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500620 break;
621
Christian Ehrhardtde368dc2008-04-29 18:18:23 +0200622 case BOOKE_INTERRUPT_FP_UNAVAIL:
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600623 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_FP_UNAVAIL);
Hollis Blanchard7b701592008-12-02 15:51:58 -0600624 kvmppc_account_exit(vcpu, FP_UNAVAIL);
Christian Ehrhardtde368dc2008-04-29 18:18:23 +0200625 r = RESUME_GUEST;
626 break;
627
Scott Wood4cd35f62011-06-14 18:34:31 -0500628#ifdef CONFIG_SPE
629 case BOOKE_INTERRUPT_SPE_UNAVAIL: {
630 if (vcpu->arch.shared->msr & MSR_SPE)
631 kvmppc_vcpu_enable_spe(vcpu);
632 else
633 kvmppc_booke_queue_irqprio(vcpu,
634 BOOKE_IRQPRIO_SPE_UNAVAIL);
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600635 r = RESUME_GUEST;
636 break;
Scott Wood4cd35f62011-06-14 18:34:31 -0500637 }
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600638
639 case BOOKE_INTERRUPT_SPE_FP_DATA:
640 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_DATA);
641 r = RESUME_GUEST;
642 break;
643
644 case BOOKE_INTERRUPT_SPE_FP_ROUND:
645 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_ROUND);
646 r = RESUME_GUEST;
647 break;
Scott Wood4cd35f62011-06-14 18:34:31 -0500648#else
649 case BOOKE_INTERRUPT_SPE_UNAVAIL:
650 /*
651 * Guest wants SPE, but host kernel doesn't support it. Send
652 * an "unimplemented operation" program check to the guest.
653 */
654 kvmppc_core_queue_program(vcpu, ESR_PUO | ESR_SPV);
655 r = RESUME_GUEST;
656 break;
657
658 /*
659 * These really should never happen without CONFIG_SPE,
660 * as we should never enable the real MSR[SPE] in the guest.
661 */
662 case BOOKE_INTERRUPT_SPE_FP_DATA:
663 case BOOKE_INTERRUPT_SPE_FP_ROUND:
664 printk(KERN_CRIT "%s: unexpected SPE interrupt %u at %08lx\n",
665 __func__, exit_nr, vcpu->arch.pc);
666 run->hw.hardware_exit_reason = exit_nr;
667 r = RESUME_HOST;
668 break;
669#endif
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600670
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500671 case BOOKE_INTERRUPT_DATA_STORAGE:
Liu Yudaf5e272010-02-02 19:44:35 +0800672 kvmppc_core_queue_data_storage(vcpu, vcpu->arch.fault_dear,
673 vcpu->arch.fault_esr);
Hollis Blanchard7b701592008-12-02 15:51:58 -0600674 kvmppc_account_exit(vcpu, DSI_EXITS);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500675 r = RESUME_GUEST;
676 break;
677
678 case BOOKE_INTERRUPT_INST_STORAGE:
Liu Yudaf5e272010-02-02 19:44:35 +0800679 kvmppc_core_queue_inst_storage(vcpu, vcpu->arch.fault_esr);
Hollis Blanchard7b701592008-12-02 15:51:58 -0600680 kvmppc_account_exit(vcpu, ISI_EXITS);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500681 r = RESUME_GUEST;
682 break;
683
Scott Woodd30f6e42011-12-20 15:34:43 +0000684#ifdef CONFIG_KVM_BOOKE_HV
685 case BOOKE_INTERRUPT_HV_SYSCALL:
686 if (!(vcpu->arch.shared->msr & MSR_PR)) {
687 kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu));
688 } else {
689 /*
690 * hcall from guest userspace -- send privileged
691 * instruction program check.
692 */
693 kvmppc_core_queue_program(vcpu, ESR_PPR);
694 }
695
696 r = RESUME_GUEST;
697 break;
698#else
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500699 case BOOKE_INTERRUPT_SYSCALL:
Alexander Graf2a342ed2010-07-29 14:47:48 +0200700 if (!(vcpu->arch.shared->msr & MSR_PR) &&
701 (((u32)kvmppc_get_gpr(vcpu, 0)) == KVM_SC_MAGIC_R0)) {
702 /* KVM PV hypercalls */
703 kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu));
704 r = RESUME_GUEST;
705 } else {
706 /* Guest syscalls */
707 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SYSCALL);
708 }
Hollis Blanchard7b701592008-12-02 15:51:58 -0600709 kvmppc_account_exit(vcpu, SYSCALL_EXITS);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500710 r = RESUME_GUEST;
711 break;
Scott Woodd30f6e42011-12-20 15:34:43 +0000712#endif
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500713
714 case BOOKE_INTERRUPT_DTLB_MISS: {
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500715 unsigned long eaddr = vcpu->arch.fault_dear;
Hollis Blanchard7924bd42008-12-02 15:51:55 -0600716 int gtlb_index;
Hollis Blanchard475e7cd2009-01-03 16:23:00 -0600717 gpa_t gpaddr;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500718 gfn_t gfn;
719
Scott Wooda4cd8b22011-06-14 18:34:41 -0500720#ifdef CONFIG_KVM_E500
721 if (!(vcpu->arch.shared->msr & MSR_PR) &&
722 (eaddr & PAGE_MASK) == vcpu->arch.magic_page_ea) {
723 kvmppc_map_magic(vcpu);
724 kvmppc_account_exit(vcpu, DTLB_VIRT_MISS_EXITS);
725 r = RESUME_GUEST;
726
727 break;
728 }
729#endif
730
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500731 /* Check the guest TLB. */
Hollis Blanchardfa86b8d2009-01-03 16:23:03 -0600732 gtlb_index = kvmppc_mmu_dtlb_index(vcpu, eaddr);
Hollis Blanchard7924bd42008-12-02 15:51:55 -0600733 if (gtlb_index < 0) {
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500734 /* The guest didn't have a mapping for it. */
Liu Yudaf5e272010-02-02 19:44:35 +0800735 kvmppc_core_queue_dtlb_miss(vcpu,
736 vcpu->arch.fault_dear,
737 vcpu->arch.fault_esr);
Hollis Blanchardb52a6382009-01-03 16:23:11 -0600738 kvmppc_mmu_dtlb_miss(vcpu);
Hollis Blanchard7b701592008-12-02 15:51:58 -0600739 kvmppc_account_exit(vcpu, DTLB_REAL_MISS_EXITS);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500740 r = RESUME_GUEST;
741 break;
742 }
743
Hollis Blanchardbe8d1ca2009-01-03 16:23:02 -0600744 gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr);
Hollis Blanchard475e7cd2009-01-03 16:23:00 -0600745 gfn = gpaddr >> PAGE_SHIFT;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500746
747 if (kvm_is_visible_gfn(vcpu->kvm, gfn)) {
748 /* The guest TLB had a mapping, but the shadow TLB
749 * didn't, and it is RAM. This could be because:
750 * a) the entry is mapping the host kernel, or
751 * b) the guest used a large mapping which we're faking
752 * Either way, we need to satisfy the fault without
753 * invoking the guest. */
Hollis Blanchard58a96212009-01-03 16:23:01 -0600754 kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index);
Hollis Blanchard7b701592008-12-02 15:51:58 -0600755 kvmppc_account_exit(vcpu, DTLB_VIRT_MISS_EXITS);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500756 r = RESUME_GUEST;
757 } else {
758 /* Guest has mapped and accessed a page which is not
759 * actually RAM. */
Hollis Blanchard475e7cd2009-01-03 16:23:00 -0600760 vcpu->arch.paddr_accessed = gpaddr;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500761 r = kvmppc_emulate_mmio(run, vcpu);
Hollis Blanchard7b701592008-12-02 15:51:58 -0600762 kvmppc_account_exit(vcpu, MMIO_EXITS);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500763 }
764
765 break;
766 }
767
768 case BOOKE_INTERRUPT_ITLB_MISS: {
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500769 unsigned long eaddr = vcpu->arch.pc;
Hollis Blanchard89168612008-12-02 15:51:53 -0600770 gpa_t gpaddr;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500771 gfn_t gfn;
Hollis Blanchard7924bd42008-12-02 15:51:55 -0600772 int gtlb_index;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500773
774 r = RESUME_GUEST;
775
776 /* Check the guest TLB. */
Hollis Blanchardfa86b8d2009-01-03 16:23:03 -0600777 gtlb_index = kvmppc_mmu_itlb_index(vcpu, eaddr);
Hollis Blanchard7924bd42008-12-02 15:51:55 -0600778 if (gtlb_index < 0) {
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500779 /* The guest didn't have a mapping for it. */
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600780 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ITLB_MISS);
Hollis Blanchardb52a6382009-01-03 16:23:11 -0600781 kvmppc_mmu_itlb_miss(vcpu);
Hollis Blanchard7b701592008-12-02 15:51:58 -0600782 kvmppc_account_exit(vcpu, ITLB_REAL_MISS_EXITS);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500783 break;
784 }
785
Hollis Blanchard7b701592008-12-02 15:51:58 -0600786 kvmppc_account_exit(vcpu, ITLB_VIRT_MISS_EXITS);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500787
Hollis Blanchardbe8d1ca2009-01-03 16:23:02 -0600788 gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr);
Hollis Blanchard89168612008-12-02 15:51:53 -0600789 gfn = gpaddr >> PAGE_SHIFT;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500790
791 if (kvm_is_visible_gfn(vcpu->kvm, gfn)) {
792 /* The guest TLB had a mapping, but the shadow TLB
793 * didn't. This could be because:
794 * a) the entry is mapping the host kernel, or
795 * b) the guest used a large mapping which we're faking
796 * Either way, we need to satisfy the fault without
797 * invoking the guest. */
Hollis Blanchard58a96212009-01-03 16:23:01 -0600798 kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500799 } else {
800 /* Guest mapped and leaped at non-RAM! */
Hollis Blanchardd4cf3892008-11-05 09:36:23 -0600801 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_MACHINE_CHECK);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500802 }
803
804 break;
805 }
806
Hollis Blanchard6a0ab732008-07-25 13:54:49 -0500807 case BOOKE_INTERRUPT_DEBUG: {
808 u32 dbsr;
809
810 vcpu->arch.pc = mfspr(SPRN_CSRR0);
811
812 /* clear IAC events in DBSR register */
813 dbsr = mfspr(SPRN_DBSR);
814 dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
815 mtspr(SPRN_DBSR, dbsr);
816
817 run->exit_reason = KVM_EXIT_DEBUG;
Hollis Blanchard7b701592008-12-02 15:51:58 -0600818 kvmppc_account_exit(vcpu, DEBUG_EXITS);
Hollis Blanchard6a0ab732008-07-25 13:54:49 -0500819 r = RESUME_HOST;
820 break;
821 }
822
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500823 default:
824 printk(KERN_EMERG "exit_nr %d\n", exit_nr);
825 BUG();
826 }
827
828 local_irq_disable();
829
Scott Wood7e28e602011-11-08 18:23:20 -0600830 kvmppc_core_prepare_to_enter(vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500831
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500832 if (!(r & RESUME_HOST)) {
833 /* To avoid clobbering exit_reason, only check for signals if
834 * we aren't already exiting to userspace for some other
835 * reason. */
836 if (signal_pending(current)) {
837 run->exit_reason = KVM_EXIT_INTR;
838 r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
Hollis Blanchard7b701592008-12-02 15:51:58 -0600839 kvmppc_account_exit(vcpu, SIGNAL_EXITS);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500840 }
841 }
842
843 return r;
844}
845
846/* Initial guest state: 16MB mapping 0 -> 0, PC = 0, MSR = 0, R1 = 16MB */
847int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
848{
Hollis Blanchard082decf2010-08-07 10:33:56 -0700849 int i;
Alexander Grafaf8f38b2011-08-10 13:57:08 +0200850 int r;
Hollis Blanchard082decf2010-08-07 10:33:56 -0700851
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500852 vcpu->arch.pc = 0;
Scott Woodb5904972011-11-08 18:23:30 -0600853 vcpu->arch.shared->pir = vcpu->vcpu_id;
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100854 kvmppc_set_gpr(vcpu, 1, (16<<20) - 8); /* -8 for the callee-save LR slot */
Scott Woodd30f6e42011-12-20 15:34:43 +0000855 kvmppc_set_msr(vcpu, 0);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500856
Scott Woodd30f6e42011-12-20 15:34:43 +0000857#ifndef CONFIG_KVM_BOOKE_HV
858 vcpu->arch.shadow_msr = MSR_USER | MSR_DE | MSR_IS | MSR_DS;
Hollis Blanchard49dd2c42008-07-25 13:54:53 -0500859 vcpu->arch.shadow_pid = 1;
Scott Woodd30f6e42011-12-20 15:34:43 +0000860 vcpu->arch.shared->msr = 0;
861#endif
Hollis Blanchard49dd2c42008-07-25 13:54:53 -0500862
Hollis Blanchard082decf2010-08-07 10:33:56 -0700863 /* Eye-catching numbers so we know if the guest takes an interrupt
864 * before it's programmed its own IVPR/IVORs. */
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500865 vcpu->arch.ivpr = 0x55550000;
Hollis Blanchard082decf2010-08-07 10:33:56 -0700866 for (i = 0; i < BOOKE_IRQPRIO_MAX; i++)
867 vcpu->arch.ivor[i] = 0x7700 | i * 4;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500868
Hollis Blanchard73e75b42008-12-02 15:51:57 -0600869 kvmppc_init_timing_stats(vcpu);
870
Alexander Grafaf8f38b2011-08-10 13:57:08 +0200871 r = kvmppc_core_vcpu_setup(vcpu);
872 kvmppc_sanity_check(vcpu);
873 return r;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500874}
875
876int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
877{
878 int i;
879
880 regs->pc = vcpu->arch.pc;
Alexander Graf992b5b22010-01-08 02:58:02 +0100881 regs->cr = kvmppc_get_cr(vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500882 regs->ctr = vcpu->arch.ctr;
883 regs->lr = vcpu->arch.lr;
Alexander Graf992b5b22010-01-08 02:58:02 +0100884 regs->xer = kvmppc_get_xer(vcpu);
Alexander Graf666e7252010-07-29 14:47:43 +0200885 regs->msr = vcpu->arch.shared->msr;
Alexander Grafde7906c2010-07-29 14:47:46 +0200886 regs->srr0 = vcpu->arch.shared->srr0;
887 regs->srr1 = vcpu->arch.shared->srr1;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500888 regs->pid = vcpu->arch.pid;
Alexander Grafa73a9592010-07-29 14:47:47 +0200889 regs->sprg0 = vcpu->arch.shared->sprg0;
890 regs->sprg1 = vcpu->arch.shared->sprg1;
891 regs->sprg2 = vcpu->arch.shared->sprg2;
892 regs->sprg3 = vcpu->arch.shared->sprg3;
Scott Woodb5904972011-11-08 18:23:30 -0600893 regs->sprg4 = vcpu->arch.shared->sprg4;
894 regs->sprg5 = vcpu->arch.shared->sprg5;
895 regs->sprg6 = vcpu->arch.shared->sprg6;
896 regs->sprg7 = vcpu->arch.shared->sprg7;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500897
898 for (i = 0; i < ARRAY_SIZE(regs->gpr); i++)
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100899 regs->gpr[i] = kvmppc_get_gpr(vcpu, i);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500900
901 return 0;
902}
903
904int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
905{
906 int i;
907
908 vcpu->arch.pc = regs->pc;
Alexander Graf992b5b22010-01-08 02:58:02 +0100909 kvmppc_set_cr(vcpu, regs->cr);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500910 vcpu->arch.ctr = regs->ctr;
911 vcpu->arch.lr = regs->lr;
Alexander Graf992b5b22010-01-08 02:58:02 +0100912 kvmppc_set_xer(vcpu, regs->xer);
Hollis Blanchardb8fd68a2008-11-05 09:36:20 -0600913 kvmppc_set_msr(vcpu, regs->msr);
Alexander Grafde7906c2010-07-29 14:47:46 +0200914 vcpu->arch.shared->srr0 = regs->srr0;
915 vcpu->arch.shared->srr1 = regs->srr1;
Scott Wood5ce941e2011-04-27 17:24:21 -0500916 kvmppc_set_pid(vcpu, regs->pid);
Alexander Grafa73a9592010-07-29 14:47:47 +0200917 vcpu->arch.shared->sprg0 = regs->sprg0;
918 vcpu->arch.shared->sprg1 = regs->sprg1;
919 vcpu->arch.shared->sprg2 = regs->sprg2;
920 vcpu->arch.shared->sprg3 = regs->sprg3;
Scott Woodb5904972011-11-08 18:23:30 -0600921 vcpu->arch.shared->sprg4 = regs->sprg4;
922 vcpu->arch.shared->sprg5 = regs->sprg5;
923 vcpu->arch.shared->sprg6 = regs->sprg6;
924 vcpu->arch.shared->sprg7 = regs->sprg7;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500925
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100926 for (i = 0; i < ARRAY_SIZE(regs->gpr); i++)
927 kvmppc_set_gpr(vcpu, i, regs->gpr[i]);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500928
929 return 0;
930}
931
Scott Wood5ce941e2011-04-27 17:24:21 -0500932static void get_sregs_base(struct kvm_vcpu *vcpu,
933 struct kvm_sregs *sregs)
934{
935 u64 tb = get_tb();
936
937 sregs->u.e.features |= KVM_SREGS_E_BASE;
938
939 sregs->u.e.csrr0 = vcpu->arch.csrr0;
940 sregs->u.e.csrr1 = vcpu->arch.csrr1;
941 sregs->u.e.mcsr = vcpu->arch.mcsr;
Scott Woodd30f6e42011-12-20 15:34:43 +0000942 sregs->u.e.esr = get_guest_esr(vcpu);
943 sregs->u.e.dear = get_guest_dear(vcpu);
Scott Wood5ce941e2011-04-27 17:24:21 -0500944 sregs->u.e.tsr = vcpu->arch.tsr;
945 sregs->u.e.tcr = vcpu->arch.tcr;
946 sregs->u.e.dec = kvmppc_get_dec(vcpu, tb);
947 sregs->u.e.tb = tb;
948 sregs->u.e.vrsave = vcpu->arch.vrsave;
949}
950
951static int set_sregs_base(struct kvm_vcpu *vcpu,
952 struct kvm_sregs *sregs)
953{
954 if (!(sregs->u.e.features & KVM_SREGS_E_BASE))
955 return 0;
956
957 vcpu->arch.csrr0 = sregs->u.e.csrr0;
958 vcpu->arch.csrr1 = sregs->u.e.csrr1;
959 vcpu->arch.mcsr = sregs->u.e.mcsr;
Scott Woodd30f6e42011-12-20 15:34:43 +0000960 set_guest_esr(vcpu, sregs->u.e.esr);
961 set_guest_dear(vcpu, sregs->u.e.dear);
Scott Wood5ce941e2011-04-27 17:24:21 -0500962 vcpu->arch.vrsave = sregs->u.e.vrsave;
Scott Wooddfd4d472011-11-17 12:39:59 +0000963 kvmppc_set_tcr(vcpu, sregs->u.e.tcr);
Scott Wood5ce941e2011-04-27 17:24:21 -0500964
Scott Wooddfd4d472011-11-17 12:39:59 +0000965 if (sregs->u.e.update_special & KVM_SREGS_E_UPDATE_DEC) {
Scott Wood5ce941e2011-04-27 17:24:21 -0500966 vcpu->arch.dec = sregs->u.e.dec;
Scott Wooddfd4d472011-11-17 12:39:59 +0000967 kvmppc_emulate_dec(vcpu);
968 }
Scott Wood5ce941e2011-04-27 17:24:21 -0500969
970 if (sregs->u.e.update_special & KVM_SREGS_E_UPDATE_TSR) {
Scott Wooddfd4d472011-11-17 12:39:59 +0000971 vcpu->arch.tsr = sregs->u.e.tsr;
972 update_timer_ints(vcpu);
Scott Wood5ce941e2011-04-27 17:24:21 -0500973 }
974
975 return 0;
976}
977
978static void get_sregs_arch206(struct kvm_vcpu *vcpu,
979 struct kvm_sregs *sregs)
980{
981 sregs->u.e.features |= KVM_SREGS_E_ARCH206;
982
Scott Wood841741f2011-09-02 17:39:37 -0500983 sregs->u.e.pir = vcpu->vcpu_id;
Scott Wood5ce941e2011-04-27 17:24:21 -0500984 sregs->u.e.mcsrr0 = vcpu->arch.mcsrr0;
985 sregs->u.e.mcsrr1 = vcpu->arch.mcsrr1;
986 sregs->u.e.decar = vcpu->arch.decar;
987 sregs->u.e.ivpr = vcpu->arch.ivpr;
988}
989
990static int set_sregs_arch206(struct kvm_vcpu *vcpu,
991 struct kvm_sregs *sregs)
992{
993 if (!(sregs->u.e.features & KVM_SREGS_E_ARCH206))
994 return 0;
995
Scott Wood841741f2011-09-02 17:39:37 -0500996 if (sregs->u.e.pir != vcpu->vcpu_id)
Scott Wood5ce941e2011-04-27 17:24:21 -0500997 return -EINVAL;
998
999 vcpu->arch.mcsrr0 = sregs->u.e.mcsrr0;
1000 vcpu->arch.mcsrr1 = sregs->u.e.mcsrr1;
1001 vcpu->arch.decar = sregs->u.e.decar;
1002 vcpu->arch.ivpr = sregs->u.e.ivpr;
1003
1004 return 0;
1005}
1006
1007void kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
1008{
1009 sregs->u.e.features |= KVM_SREGS_E_IVOR;
1010
1011 sregs->u.e.ivor_low[0] = vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL];
1012 sregs->u.e.ivor_low[1] = vcpu->arch.ivor[BOOKE_IRQPRIO_MACHINE_CHECK];
1013 sregs->u.e.ivor_low[2] = vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE];
1014 sregs->u.e.ivor_low[3] = vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE];
1015 sregs->u.e.ivor_low[4] = vcpu->arch.ivor[BOOKE_IRQPRIO_EXTERNAL];
1016 sregs->u.e.ivor_low[5] = vcpu->arch.ivor[BOOKE_IRQPRIO_ALIGNMENT];
1017 sregs->u.e.ivor_low[6] = vcpu->arch.ivor[BOOKE_IRQPRIO_PROGRAM];
1018 sregs->u.e.ivor_low[7] = vcpu->arch.ivor[BOOKE_IRQPRIO_FP_UNAVAIL];
1019 sregs->u.e.ivor_low[8] = vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL];
1020 sregs->u.e.ivor_low[9] = vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL];
1021 sregs->u.e.ivor_low[10] = vcpu->arch.ivor[BOOKE_IRQPRIO_DECREMENTER];
1022 sregs->u.e.ivor_low[11] = vcpu->arch.ivor[BOOKE_IRQPRIO_FIT];
1023 sregs->u.e.ivor_low[12] = vcpu->arch.ivor[BOOKE_IRQPRIO_WATCHDOG];
1024 sregs->u.e.ivor_low[13] = vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS];
1025 sregs->u.e.ivor_low[14] = vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS];
1026 sregs->u.e.ivor_low[15] = vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG];
1027}
1028
1029int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
1030{
1031 if (!(sregs->u.e.features & KVM_SREGS_E_IVOR))
1032 return 0;
1033
1034 vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL] = sregs->u.e.ivor_low[0];
1035 vcpu->arch.ivor[BOOKE_IRQPRIO_MACHINE_CHECK] = sregs->u.e.ivor_low[1];
1036 vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE] = sregs->u.e.ivor_low[2];
1037 vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE] = sregs->u.e.ivor_low[3];
1038 vcpu->arch.ivor[BOOKE_IRQPRIO_EXTERNAL] = sregs->u.e.ivor_low[4];
1039 vcpu->arch.ivor[BOOKE_IRQPRIO_ALIGNMENT] = sregs->u.e.ivor_low[5];
1040 vcpu->arch.ivor[BOOKE_IRQPRIO_PROGRAM] = sregs->u.e.ivor_low[6];
1041 vcpu->arch.ivor[BOOKE_IRQPRIO_FP_UNAVAIL] = sregs->u.e.ivor_low[7];
1042 vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL] = sregs->u.e.ivor_low[8];
1043 vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL] = sregs->u.e.ivor_low[9];
1044 vcpu->arch.ivor[BOOKE_IRQPRIO_DECREMENTER] = sregs->u.e.ivor_low[10];
1045 vcpu->arch.ivor[BOOKE_IRQPRIO_FIT] = sregs->u.e.ivor_low[11];
1046 vcpu->arch.ivor[BOOKE_IRQPRIO_WATCHDOG] = sregs->u.e.ivor_low[12];
1047 vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS] = sregs->u.e.ivor_low[13];
1048 vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS] = sregs->u.e.ivor_low[14];
1049 vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG] = sregs->u.e.ivor_low[15];
1050
1051 return 0;
1052}
1053
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -05001054int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
1055 struct kvm_sregs *sregs)
1056{
Scott Wood5ce941e2011-04-27 17:24:21 -05001057 sregs->pvr = vcpu->arch.pvr;
1058
1059 get_sregs_base(vcpu, sregs);
1060 get_sregs_arch206(vcpu, sregs);
1061 kvmppc_core_get_sregs(vcpu, sregs);
1062 return 0;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -05001063}
1064
1065int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
1066 struct kvm_sregs *sregs)
1067{
Scott Wood5ce941e2011-04-27 17:24:21 -05001068 int ret;
1069
1070 if (vcpu->arch.pvr != sregs->pvr)
1071 return -EINVAL;
1072
1073 ret = set_sregs_base(vcpu, sregs);
1074 if (ret < 0)
1075 return ret;
1076
1077 ret = set_sregs_arch206(vcpu, sregs);
1078 if (ret < 0)
1079 return ret;
1080
1081 return kvmppc_core_set_sregs(vcpu, sregs);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -05001082}
1083
Paul Mackerras31f34382011-12-12 12:26:50 +00001084int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
1085{
1086 return -EINVAL;
1087}
1088
1089int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
1090{
1091 return -EINVAL;
1092}
1093
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -05001094int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
1095{
1096 return -ENOTSUPP;
1097}
1098
1099int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
1100{
1101 return -ENOTSUPP;
1102}
1103
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -05001104int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
1105 struct kvm_translation *tr)
1106{
Avi Kivity98001d82010-05-13 11:05:49 +03001107 int r;
1108
Avi Kivity98001d82010-05-13 11:05:49 +03001109 r = kvmppc_core_vcpu_translate(vcpu, tr);
Avi Kivity98001d82010-05-13 11:05:49 +03001110 return r;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -05001111}
Hollis Blanchardd9fbd032008-11-05 09:36:13 -06001112
Alexander Graf4e755752009-10-30 05:47:01 +00001113int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
1114{
1115 return -ENOTSUPP;
1116}
1117
Paul Mackerrasf9e05542011-06-29 00:19:22 +00001118int kvmppc_core_prepare_memory_region(struct kvm *kvm,
1119 struct kvm_userspace_memory_region *mem)
1120{
1121 return 0;
1122}
1123
1124void kvmppc_core_commit_memory_region(struct kvm *kvm,
1125 struct kvm_userspace_memory_region *mem)
1126{
1127}
1128
Scott Wooddfd4d472011-11-17 12:39:59 +00001129void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr)
1130{
1131 vcpu->arch.tcr = new_tcr;
1132 update_timer_ints(vcpu);
1133}
1134
1135void kvmppc_set_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits)
1136{
1137 set_bits(tsr_bits, &vcpu->arch.tsr);
1138 smp_wmb();
1139 kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu);
1140 kvm_vcpu_kick(vcpu);
1141}
1142
1143void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits)
1144{
1145 clear_bits(tsr_bits, &vcpu->arch.tsr);
1146 update_timer_ints(vcpu);
1147}
1148
1149void kvmppc_decrementer_func(unsigned long data)
1150{
1151 struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
1152
1153 kvmppc_set_tsr_bits(vcpu, TSR_DIS);
1154}
1155
Scott Wood94fa9d92011-12-20 15:34:22 +00001156void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
1157{
Scott Woodd30f6e42011-12-20 15:34:43 +00001158 current->thread.kvm_vcpu = vcpu;
Scott Wood94fa9d92011-12-20 15:34:22 +00001159}
1160
1161void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu)
1162{
Scott Woodd30f6e42011-12-20 15:34:43 +00001163 current->thread.kvm_vcpu = NULL;
Scott Wood94fa9d92011-12-20 15:34:22 +00001164}
1165
Stephen Rothwell2986b8c2009-06-02 11:46:14 +10001166int __init kvmppc_booke_init(void)
Hollis Blanchardd9fbd032008-11-05 09:36:13 -06001167{
Scott Woodd30f6e42011-12-20 15:34:43 +00001168#ifndef CONFIG_KVM_BOOKE_HV
Hollis Blanchardd9fbd032008-11-05 09:36:13 -06001169 unsigned long ivor[16];
1170 unsigned long max_ivor = 0;
1171 int i;
1172
1173 /* We install our own exception handlers by hijacking IVPR. IVPR must
1174 * be 16-bit aligned, so we need a 64KB allocation. */
1175 kvmppc_booke_handlers = __get_free_pages(GFP_KERNEL | __GFP_ZERO,
1176 VCPU_SIZE_ORDER);
1177 if (!kvmppc_booke_handlers)
1178 return -ENOMEM;
1179
1180 /* XXX make sure our handlers are smaller than Linux's */
1181
1182 /* Copy our interrupt handlers to match host IVORs. That way we don't
1183 * have to swap the IVORs on every guest/host transition. */
1184 ivor[0] = mfspr(SPRN_IVOR0);
1185 ivor[1] = mfspr(SPRN_IVOR1);
1186 ivor[2] = mfspr(SPRN_IVOR2);
1187 ivor[3] = mfspr(SPRN_IVOR3);
1188 ivor[4] = mfspr(SPRN_IVOR4);
1189 ivor[5] = mfspr(SPRN_IVOR5);
1190 ivor[6] = mfspr(SPRN_IVOR6);
1191 ivor[7] = mfspr(SPRN_IVOR7);
1192 ivor[8] = mfspr(SPRN_IVOR8);
1193 ivor[9] = mfspr(SPRN_IVOR9);
1194 ivor[10] = mfspr(SPRN_IVOR10);
1195 ivor[11] = mfspr(SPRN_IVOR11);
1196 ivor[12] = mfspr(SPRN_IVOR12);
1197 ivor[13] = mfspr(SPRN_IVOR13);
1198 ivor[14] = mfspr(SPRN_IVOR14);
1199 ivor[15] = mfspr(SPRN_IVOR15);
1200
1201 for (i = 0; i < 16; i++) {
1202 if (ivor[i] > max_ivor)
1203 max_ivor = ivor[i];
1204
1205 memcpy((void *)kvmppc_booke_handlers + ivor[i],
1206 kvmppc_handlers_start + i * kvmppc_handler_len,
1207 kvmppc_handler_len);
1208 }
1209 flush_icache_range(kvmppc_booke_handlers,
1210 kvmppc_booke_handlers + max_ivor + kvmppc_handler_len);
Scott Woodd30f6e42011-12-20 15:34:43 +00001211#endif /* !BOOKE_HV */
Hollis Blancharddb93f572008-11-05 09:36:18 -06001212 return 0;
Hollis Blanchardd9fbd032008-11-05 09:36:13 -06001213}
1214
Hollis Blancharddb93f572008-11-05 09:36:18 -06001215void __exit kvmppc_booke_exit(void)
Hollis Blanchardd9fbd032008-11-05 09:36:13 -06001216{
1217 free_pages(kvmppc_booke_handlers, VCPU_SIZE_ORDER);
1218 kvm_exit();
1219}