blob: fecfe043458d145330f42435562030791e682add [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
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>
Alexander Graf544c6762009-11-02 12:02:31 +000026#include <linux/hrtimer.h>
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050027#include <linux/fs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050029#include <asm/cputable.h>
30#include <asm/uaccess.h>
31#include <asm/kvm_ppc.h>
Hollis Blanchard83aae4a2008-07-25 13:54:52 -050032#include <asm/tlbflush.h>
Hollis Blanchard73e75b42008-12-02 15:51:57 -060033#include "timing.h"
Paul Mackerrasfad7b9b2008-12-23 14:57:26 +110034#include "../mm/mmu_decl.h"
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050035
Marcelo Tosatti46f43c62009-06-18 11:47:27 -030036#define CREATE_TRACE_POINTS
37#include "trace.h"
38
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050039int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
40{
Alexander Graf666e7252010-07-29 14:47:43 +020041 return !(v->arch.shared->msr & MSR_WE) ||
42 !!(v->arch.pending_exceptions);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050043}
44
Alexander Graf2a342ed2010-07-29 14:47:48 +020045int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
46{
47 int nr = kvmppc_get_gpr(vcpu, 11);
48 int r;
49 unsigned long __maybe_unused param1 = kvmppc_get_gpr(vcpu, 3);
50 unsigned long __maybe_unused param2 = kvmppc_get_gpr(vcpu, 4);
51 unsigned long __maybe_unused param3 = kvmppc_get_gpr(vcpu, 5);
52 unsigned long __maybe_unused param4 = kvmppc_get_gpr(vcpu, 6);
53 unsigned long r2 = 0;
54
55 if (!(vcpu->arch.shared->msr & MSR_SF)) {
56 /* 32 bit mode */
57 param1 &= 0xffffffff;
58 param2 &= 0xffffffff;
59 param3 &= 0xffffffff;
60 param4 &= 0xffffffff;
61 }
62
63 switch (nr) {
Alexander Graf5fc87402010-07-29 14:47:55 +020064 case HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE:
65 {
66 vcpu->arch.magic_page_pa = param1;
67 vcpu->arch.magic_page_ea = param2;
68
69 r = HC_EV_SUCCESS;
70 break;
71 }
Alexander Graf2a342ed2010-07-29 14:47:48 +020072 case HC_VENDOR_KVM | KVM_HC_FEATURES:
73 r = HC_EV_SUCCESS;
Alexander Graf5fc87402010-07-29 14:47:55 +020074#if defined(CONFIG_PPC_BOOK3S) /* XXX Missing magic page on BookE */
75 r2 |= (1 << KVM_FEATURE_MAGIC_PAGE);
76#endif
Alexander Graf2a342ed2010-07-29 14:47:48 +020077
78 /* Second return value is in r4 */
79 kvmppc_set_gpr(vcpu, 4, r2);
80 break;
81 default:
82 r = HC_EV_UNIMPLEMENTED;
83 break;
84 }
85
86 return r;
87}
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050088
89int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu)
90{
91 enum emulation_result er;
92 int r;
93
94 er = kvmppc_emulate_instruction(run, vcpu);
95 switch (er) {
96 case EMULATE_DONE:
97 /* Future optimization: only reload non-volatiles if they were
98 * actually modified. */
99 r = RESUME_GUEST_NV;
100 break;
101 case EMULATE_DO_MMIO:
102 run->exit_reason = KVM_EXIT_MMIO;
103 /* We must reload nonvolatiles because "update" load/store
104 * instructions modify register state. */
105 /* Future optimization: only reload non-volatiles if they were
106 * actually modified. */
107 r = RESUME_HOST_NV;
108 break;
109 case EMULATE_FAIL:
110 /* XXX Deliver Program interrupt to guest. */
111 printk(KERN_EMERG "%s: emulation failed (%08x)\n", __func__,
Alexander Grafc7f38f42010-04-16 00:11:40 +0200112 kvmppc_get_last_inst(vcpu));
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500113 r = RESUME_HOST;
114 break;
115 default:
116 BUG();
117 }
118
119 return r;
120}
121
Alexander Graf10474ae2009-09-15 11:37:46 +0200122int kvm_arch_hardware_enable(void *garbage)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500123{
Alexander Graf10474ae2009-09-15 11:37:46 +0200124 return 0;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500125}
126
127void kvm_arch_hardware_disable(void *garbage)
128{
129}
130
131int kvm_arch_hardware_setup(void)
132{
133 return 0;
134}
135
136void kvm_arch_hardware_unsetup(void)
137{
138}
139
140void kvm_arch_check_processor_compat(void *rtn)
141{
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600142 *(int *)rtn = kvmppc_core_check_processor_compat();
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500143}
144
145struct kvm *kvm_arch_create_vm(void)
146{
147 struct kvm *kvm;
148
149 kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL);
150 if (!kvm)
151 return ERR_PTR(-ENOMEM);
152
153 return kvm;
154}
155
156static void kvmppc_free_vcpus(struct kvm *kvm)
157{
158 unsigned int i;
Gleb Natapov988a2ca2009-06-09 15:56:29 +0300159 struct kvm_vcpu *vcpu;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500160
Gleb Natapov988a2ca2009-06-09 15:56:29 +0300161 kvm_for_each_vcpu(i, vcpu, kvm)
162 kvm_arch_vcpu_free(vcpu);
163
164 mutex_lock(&kvm->lock);
165 for (i = 0; i < atomic_read(&kvm->online_vcpus); i++)
166 kvm->vcpus[i] = NULL;
167
168 atomic_set(&kvm->online_vcpus, 0);
169 mutex_unlock(&kvm->lock);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500170}
171
Sheng Yangad8ba2c2009-01-06 10:03:02 +0800172void kvm_arch_sync_events(struct kvm *kvm)
173{
174}
175
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500176void kvm_arch_destroy_vm(struct kvm *kvm)
177{
178 kvmppc_free_vcpus(kvm);
179 kvm_free_physmem(kvm);
Marcelo Tosatti64749202010-01-19 12:45:23 -0200180 cleanup_srcu_struct(&kvm->srcu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500181 kfree(kvm);
182}
183
184int kvm_dev_ioctl_check_extension(long ext)
185{
186 int r;
187
188 switch (ext) {
Alexander Grafe15a1132009-11-30 03:02:02 +0000189 case KVM_CAP_PPC_SEGSTATE:
Alexander Grafc10207f2010-02-19 11:00:45 +0100190 case KVM_CAP_PPC_PAIRED_SINGLES:
Alexander Graf18978762010-03-24 21:48:18 +0100191 case KVM_CAP_PPC_UNSET_IRQ:
Alexander Graf71fbfd52010-03-24 21:48:29 +0100192 case KVM_CAP_ENABLE_CAP:
Alexander Grafad0a0482010-03-24 21:48:30 +0100193 case KVM_CAP_PPC_OSI:
Alexander Grafe15a1132009-11-30 03:02:02 +0000194 r = 1;
195 break;
Laurent Vivier588968b2008-05-30 16:05:56 +0200196 case KVM_CAP_COALESCED_MMIO:
197 r = KVM_COALESCED_MMIO_PAGE_OFFSET;
198 break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500199 default:
200 r = 0;
201 break;
202 }
203 return r;
204
205}
206
207long kvm_arch_dev_ioctl(struct file *filp,
208 unsigned int ioctl, unsigned long arg)
209{
210 return -EINVAL;
211}
212
Marcelo Tosattif7784b82009-12-23 14:35:18 -0200213int kvm_arch_prepare_memory_region(struct kvm *kvm,
214 struct kvm_memory_slot *memslot,
215 struct kvm_memory_slot old,
216 struct kvm_userspace_memory_region *mem,
217 int user_alloc)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500218{
219 return 0;
220}
221
Marcelo Tosattif7784b82009-12-23 14:35:18 -0200222void kvm_arch_commit_memory_region(struct kvm *kvm,
223 struct kvm_userspace_memory_region *mem,
224 struct kvm_memory_slot old,
225 int user_alloc)
226{
227 return;
228}
229
230
Marcelo Tosatti34d4cb82008-07-10 20:49:31 -0300231void kvm_arch_flush_shadow(struct kvm *kvm)
232{
233}
234
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500235struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
236{
Hollis Blanchard73e75b42008-12-02 15:51:57 -0600237 struct kvm_vcpu *vcpu;
238 vcpu = kvmppc_core_vcpu_create(kvm, id);
Wei Yongjun06056bf2010-03-09 14:13:43 +0800239 if (!IS_ERR(vcpu))
240 kvmppc_create_vcpu_debugfs(vcpu, id);
Hollis Blanchard73e75b42008-12-02 15:51:57 -0600241 return vcpu;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500242}
243
244void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
245{
Alexander Grafa5954052010-02-22 16:52:14 +0100246 /* Make sure we're not using the vcpu anymore */
247 hrtimer_cancel(&vcpu->arch.dec_timer);
248 tasklet_kill(&vcpu->arch.tasklet);
249
Hollis Blanchard73e75b42008-12-02 15:51:57 -0600250 kvmppc_remove_vcpu_debugfs(vcpu);
Hollis Blancharddb93f572008-11-05 09:36:18 -0600251 kvmppc_core_vcpu_free(vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500252}
253
254void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
255{
256 kvm_arch_vcpu_free(vcpu);
257}
258
259int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
260{
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600261 return kvmppc_core_pending_dec(vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500262}
263
264static void kvmppc_decrementer_func(unsigned long data)
265{
266 struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
267
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600268 kvmppc_core_queue_dec(vcpu);
Hollis Blanchard45c5eb62008-04-25 17:55:49 -0500269
270 if (waitqueue_active(&vcpu->wq)) {
271 wake_up_interruptible(&vcpu->wq);
272 vcpu->stat.halt_wakeup++;
273 }
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500274}
275
Alexander Graf544c6762009-11-02 12:02:31 +0000276/*
277 * low level hrtimer wake routine. Because this runs in hardirq context
278 * we schedule a tasklet to do the real work.
279 */
280enum hrtimer_restart kvmppc_decrementer_wakeup(struct hrtimer *timer)
281{
282 struct kvm_vcpu *vcpu;
283
284 vcpu = container_of(timer, struct kvm_vcpu, arch.dec_timer);
285 tasklet_schedule(&vcpu->arch.tasklet);
286
287 return HRTIMER_NORESTART;
288}
289
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500290int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
291{
Alexander Graf544c6762009-11-02 12:02:31 +0000292 hrtimer_init(&vcpu->arch.dec_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
293 tasklet_init(&vcpu->arch.tasklet, kvmppc_decrementer_func, (ulong)vcpu);
294 vcpu->arch.dec_timer.function = kvmppc_decrementer_wakeup;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500295
296 return 0;
297}
298
299void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu)
300{
Hollis Blanchardecc09812009-01-03 16:22:59 -0600301 kvmppc_mmu_destroy(vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500302}
303
304void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
305{
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600306 kvmppc_core_vcpu_load(vcpu, cpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500307}
308
309void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
310{
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600311 kvmppc_core_vcpu_put(vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500312}
313
Jan Kiszkad0bfb942008-12-15 13:52:10 +0100314int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
Hollis Blanchardf5d09062009-01-04 13:51:09 -0600315 struct kvm_guest_debug *dbg)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500316{
Hollis Blanchardf5d09062009-01-04 13:51:09 -0600317 return -EINVAL;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500318}
319
320static void kvmppc_complete_dcr_load(struct kvm_vcpu *vcpu,
321 struct kvm_run *run)
322{
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100323 kvmppc_set_gpr(vcpu, vcpu->arch.io_gpr, run->dcr.data);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500324}
325
326static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu,
327 struct kvm_run *run)
328{
Denis Kirjanov69b61832010-06-11 11:23:26 +0000329 u64 uninitialized_var(gpr);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500330
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100331 if (run->mmio.len > sizeof(gpr)) {
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500332 printk(KERN_ERR "bad MMIO length: %d\n", run->mmio.len);
333 return;
334 }
335
336 if (vcpu->arch.mmio_is_bigendian) {
337 switch (run->mmio.len) {
Alexander Grafb104d062010-02-19 11:00:29 +0100338 case 8: gpr = *(u64 *)run->mmio.data; break;
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100339 case 4: gpr = *(u32 *)run->mmio.data; break;
340 case 2: gpr = *(u16 *)run->mmio.data; break;
341 case 1: gpr = *(u8 *)run->mmio.data; break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500342 }
343 } else {
344 /* Convert BE data from userland back to LE. */
345 switch (run->mmio.len) {
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100346 case 4: gpr = ld_le32((u32 *)run->mmio.data); break;
347 case 2: gpr = ld_le16((u16 *)run->mmio.data); break;
348 case 1: gpr = *(u8 *)run->mmio.data; break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500349 }
350 }
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100351
Alexander Graf3587d532010-02-19 11:00:30 +0100352 if (vcpu->arch.mmio_sign_extend) {
353 switch (run->mmio.len) {
354#ifdef CONFIG_PPC64
355 case 4:
356 gpr = (s64)(s32)gpr;
357 break;
358#endif
359 case 2:
360 gpr = (s64)(s16)gpr;
361 break;
362 case 1:
363 gpr = (s64)(s8)gpr;
364 break;
365 }
366 }
367
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100368 kvmppc_set_gpr(vcpu, vcpu->arch.io_gpr, gpr);
Alexander Grafb104d062010-02-19 11:00:29 +0100369
370 switch (vcpu->arch.io_gpr & KVM_REG_EXT_MASK) {
371 case KVM_REG_GPR:
372 kvmppc_set_gpr(vcpu, vcpu->arch.io_gpr, gpr);
373 break;
374 case KVM_REG_FPR:
375 vcpu->arch.fpr[vcpu->arch.io_gpr & KVM_REG_MASK] = gpr;
376 break;
Alexander Graf287d5612010-04-01 15:33:21 +0200377#ifdef CONFIG_PPC_BOOK3S
Alexander Grafb104d062010-02-19 11:00:29 +0100378 case KVM_REG_QPR:
379 vcpu->arch.qpr[vcpu->arch.io_gpr & KVM_REG_MASK] = gpr;
380 break;
381 case KVM_REG_FQPR:
382 vcpu->arch.fpr[vcpu->arch.io_gpr & KVM_REG_MASK] = gpr;
383 vcpu->arch.qpr[vcpu->arch.io_gpr & KVM_REG_MASK] = gpr;
384 break;
Alexander Graf287d5612010-04-01 15:33:21 +0200385#endif
Alexander Grafb104d062010-02-19 11:00:29 +0100386 default:
387 BUG();
388 }
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500389}
390
391int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
392 unsigned int rt, unsigned int bytes, int is_bigendian)
393{
394 if (bytes > sizeof(run->mmio.data)) {
395 printk(KERN_ERR "%s: bad MMIO length: %d\n", __func__,
396 run->mmio.len);
397 }
398
399 run->mmio.phys_addr = vcpu->arch.paddr_accessed;
400 run->mmio.len = bytes;
401 run->mmio.is_write = 0;
402
403 vcpu->arch.io_gpr = rt;
404 vcpu->arch.mmio_is_bigendian = is_bigendian;
405 vcpu->mmio_needed = 1;
406 vcpu->mmio_is_write = 0;
Alexander Graf3587d532010-02-19 11:00:30 +0100407 vcpu->arch.mmio_sign_extend = 0;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500408
409 return EMULATE_DO_MMIO;
410}
411
Alexander Graf3587d532010-02-19 11:00:30 +0100412/* Same as above, but sign extends */
413int kvmppc_handle_loads(struct kvm_run *run, struct kvm_vcpu *vcpu,
414 unsigned int rt, unsigned int bytes, int is_bigendian)
415{
416 int r;
417
418 r = kvmppc_handle_load(run, vcpu, rt, bytes, is_bigendian);
419 vcpu->arch.mmio_sign_extend = 1;
420
421 return r;
422}
423
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500424int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
Alexander Grafb104d062010-02-19 11:00:29 +0100425 u64 val, unsigned int bytes, int is_bigendian)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500426{
427 void *data = run->mmio.data;
428
429 if (bytes > sizeof(run->mmio.data)) {
430 printk(KERN_ERR "%s: bad MMIO length: %d\n", __func__,
431 run->mmio.len);
432 }
433
434 run->mmio.phys_addr = vcpu->arch.paddr_accessed;
435 run->mmio.len = bytes;
436 run->mmio.is_write = 1;
437 vcpu->mmio_needed = 1;
438 vcpu->mmio_is_write = 1;
439
440 /* Store the value at the lowest bytes in 'data'. */
441 if (is_bigendian) {
442 switch (bytes) {
Alexander Grafb104d062010-02-19 11:00:29 +0100443 case 8: *(u64 *)data = val; break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500444 case 4: *(u32 *)data = val; break;
445 case 2: *(u16 *)data = val; break;
446 case 1: *(u8 *)data = val; break;
447 }
448 } else {
449 /* Store LE value into 'data'. */
450 switch (bytes) {
451 case 4: st_le32(data, val); break;
452 case 2: st_le16(data, val); break;
453 case 1: *(u8 *)data = val; break;
454 }
455 }
456
457 return EMULATE_DO_MMIO;
458}
459
460int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
461{
462 int r;
463 sigset_t sigsaved;
464
465 if (vcpu->sigset_active)
466 sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
467
468 if (vcpu->mmio_needed) {
469 if (!vcpu->mmio_is_write)
470 kvmppc_complete_mmio_load(vcpu, run);
471 vcpu->mmio_needed = 0;
472 } else if (vcpu->arch.dcr_needed) {
473 if (!vcpu->arch.dcr_is_write)
474 kvmppc_complete_dcr_load(vcpu, run);
475 vcpu->arch.dcr_needed = 0;
Alexander Grafad0a0482010-03-24 21:48:30 +0100476 } else if (vcpu->arch.osi_needed) {
477 u64 *gprs = run->osi.gprs;
478 int i;
479
480 for (i = 0; i < 32; i++)
481 kvmppc_set_gpr(vcpu, i, gprs[i]);
482 vcpu->arch.osi_needed = 0;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500483 }
484
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600485 kvmppc_core_deliver_interrupts(vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500486
487 local_irq_disable();
488 kvm_guest_enter();
489 r = __kvmppc_vcpu_run(run, vcpu);
490 kvm_guest_exit();
491 local_irq_enable();
492
493 if (vcpu->sigset_active)
494 sigprocmask(SIG_SETMASK, &sigsaved, NULL);
495
496 return r;
497}
498
499int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq)
500{
Alexander Graf18978762010-03-24 21:48:18 +0100501 if (irq->irq == KVM_INTERRUPT_UNSET)
502 kvmppc_core_dequeue_external(vcpu, irq);
503 else
504 kvmppc_core_queue_external(vcpu, irq);
Hollis Blanchard45c5eb62008-04-25 17:55:49 -0500505
506 if (waitqueue_active(&vcpu->wq)) {
507 wake_up_interruptible(&vcpu->wq);
508 vcpu->stat.halt_wakeup++;
509 }
510
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500511 return 0;
512}
513
Alexander Graf71fbfd52010-03-24 21:48:29 +0100514static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
515 struct kvm_enable_cap *cap)
516{
517 int r;
518
519 if (cap->flags)
520 return -EINVAL;
521
522 switch (cap->cap) {
Alexander Grafad0a0482010-03-24 21:48:30 +0100523 case KVM_CAP_PPC_OSI:
524 r = 0;
525 vcpu->arch.osi_enabled = true;
526 break;
Alexander Graf71fbfd52010-03-24 21:48:29 +0100527 default:
528 r = -EINVAL;
529 break;
530 }
531
532 return r;
533}
534
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500535int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
536 struct kvm_mp_state *mp_state)
537{
538 return -EINVAL;
539}
540
541int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
542 struct kvm_mp_state *mp_state)
543{
544 return -EINVAL;
545}
546
547long kvm_arch_vcpu_ioctl(struct file *filp,
548 unsigned int ioctl, unsigned long arg)
549{
550 struct kvm_vcpu *vcpu = filp->private_data;
551 void __user *argp = (void __user *)arg;
552 long r;
553
Avi Kivity93736622010-05-13 12:35:17 +0300554 switch (ioctl) {
555 case KVM_INTERRUPT: {
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500556 struct kvm_interrupt irq;
557 r = -EFAULT;
558 if (copy_from_user(&irq, argp, sizeof(irq)))
Avi Kivity93736622010-05-13 12:35:17 +0300559 goto out;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500560 r = kvm_vcpu_ioctl_interrupt(vcpu, &irq);
Avi Kivity93736622010-05-13 12:35:17 +0300561 goto out;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500562 }
Avi Kivity19483d12010-05-13 12:30:43 +0300563
Alexander Graf71fbfd52010-03-24 21:48:29 +0100564 case KVM_ENABLE_CAP:
565 {
566 struct kvm_enable_cap cap;
567 r = -EFAULT;
568 if (copy_from_user(&cap, argp, sizeof(cap)))
569 goto out;
570 r = kvm_vcpu_ioctl_enable_cap(vcpu, &cap);
571 break;
572 }
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500573 default:
574 r = -EINVAL;
575 }
576
577out:
578 return r;
579}
580
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500581long kvm_arch_vm_ioctl(struct file *filp,
582 unsigned int ioctl, unsigned long arg)
583{
584 long r;
585
586 switch (ioctl) {
587 default:
Avi Kivity367e1312009-08-26 14:57:07 +0300588 r = -ENOTTY;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500589 }
590
591 return r;
592}
593
594int kvm_arch_init(void *opaque)
595{
596 return 0;
597}
598
599void kvm_arch_exit(void)
600{
601}