blob: d3506b4001aa7d60ff392464f4673ba007e253b0 [file] [log] [blame]
Christoffer Dall749cf76c2013-01-20 18:28:06 -05001/*
2 * Copyright (C) 2012 - Virtual Open Systems and Columbia University
3 * Author: Christoffer Dall <c.dall@virtualopensystems.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#include <linux/errno.h>
20#include <linux/err.h>
21#include <linux/kvm_host.h>
22#include <linux/module.h>
23#include <linux/vmalloc.h>
24#include <linux/fs.h>
25#include <linux/mman.h>
26#include <linux/sched.h>
27#include <trace/events/kvm.h>
28
29#define CREATE_TRACE_POINTS
30#include "trace.h"
31
32#include <asm/unified.h>
33#include <asm/uaccess.h>
34#include <asm/ptrace.h>
35#include <asm/mman.h>
36#include <asm/cputype.h>
37
38#ifdef REQUIRES_VIRT
39__asm__(".arch_extension virt");
40#endif
41
42int kvm_arch_hardware_enable(void *garbage)
43{
44 return 0;
45}
46
47int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)
48{
49 return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE;
50}
51
52void kvm_arch_hardware_disable(void *garbage)
53{
54}
55
56int kvm_arch_hardware_setup(void)
57{
58 return 0;
59}
60
61void kvm_arch_hardware_unsetup(void)
62{
63}
64
65void kvm_arch_check_processor_compat(void *rtn)
66{
67 *(int *)rtn = 0;
68}
69
70void kvm_arch_sync_events(struct kvm *kvm)
71{
72}
73
74int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
75{
76 if (type)
77 return -EINVAL;
78
79 return 0;
80}
81
82int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)
83{
84 return VM_FAULT_SIGBUS;
85}
86
87void kvm_arch_free_memslot(struct kvm_memory_slot *free,
88 struct kvm_memory_slot *dont)
89{
90}
91
92int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages)
93{
94 return 0;
95}
96
97void kvm_arch_destroy_vm(struct kvm *kvm)
98{
99 int i;
100
101 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
102 if (kvm->vcpus[i]) {
103 kvm_arch_vcpu_free(kvm->vcpus[i]);
104 kvm->vcpus[i] = NULL;
105 }
106 }
107}
108
109int kvm_dev_ioctl_check_extension(long ext)
110{
111 int r;
112 switch (ext) {
113 case KVM_CAP_USER_MEMORY:
114 case KVM_CAP_SYNC_MMU:
115 case KVM_CAP_DESTROY_MEMORY_REGION_WORKS:
116 case KVM_CAP_ONE_REG:
117 r = 1;
118 break;
119 case KVM_CAP_COALESCED_MMIO:
120 r = KVM_COALESCED_MMIO_PAGE_OFFSET;
121 break;
122 case KVM_CAP_NR_VCPUS:
123 r = num_online_cpus();
124 break;
125 case KVM_CAP_MAX_VCPUS:
126 r = KVM_MAX_VCPUS;
127 break;
128 default:
129 r = 0;
130 break;
131 }
132 return r;
133}
134
135long kvm_arch_dev_ioctl(struct file *filp,
136 unsigned int ioctl, unsigned long arg)
137{
138 return -EINVAL;
139}
140
141int kvm_arch_set_memory_region(struct kvm *kvm,
142 struct kvm_userspace_memory_region *mem,
143 struct kvm_memory_slot old,
144 int user_alloc)
145{
146 return 0;
147}
148
149int kvm_arch_prepare_memory_region(struct kvm *kvm,
150 struct kvm_memory_slot *memslot,
151 struct kvm_memory_slot old,
152 struct kvm_userspace_memory_region *mem,
153 int user_alloc)
154{
155 return 0;
156}
157
158void kvm_arch_commit_memory_region(struct kvm *kvm,
159 struct kvm_userspace_memory_region *mem,
160 struct kvm_memory_slot old,
161 int user_alloc)
162{
163}
164
165void kvm_arch_flush_shadow_all(struct kvm *kvm)
166{
167}
168
169void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
170 struct kvm_memory_slot *slot)
171{
172}
173
174struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
175{
176 int err;
177 struct kvm_vcpu *vcpu;
178
179 vcpu = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
180 if (!vcpu) {
181 err = -ENOMEM;
182 goto out;
183 }
184
185 err = kvm_vcpu_init(vcpu, kvm, id);
186 if (err)
187 goto free_vcpu;
188
189 return vcpu;
190free_vcpu:
191 kmem_cache_free(kvm_vcpu_cache, vcpu);
192out:
193 return ERR_PTR(err);
194}
195
196int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
197{
198 return 0;
199}
200
201void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
202{
203}
204
205void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
206{
207 kvm_arch_vcpu_free(vcpu);
208}
209
210int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
211{
212 return 0;
213}
214
215int __attribute_const__ kvm_target_cpu(void)
216{
217 unsigned long implementor = read_cpuid_implementor();
218 unsigned long part_number = read_cpuid_part_number();
219
220 if (implementor != ARM_CPU_IMP_ARM)
221 return -EINVAL;
222
223 switch (part_number) {
224 case ARM_CPU_PART_CORTEX_A15:
225 return KVM_ARM_TARGET_CORTEX_A15;
226 default:
227 return -EINVAL;
228 }
229}
230
231int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
232{
233 return 0;
234}
235
236void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu)
237{
238}
239
240void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
241{
242}
243
244void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
245{
246}
247
248int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
249 struct kvm_guest_debug *dbg)
250{
251 return -EINVAL;
252}
253
254
255int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
256 struct kvm_mp_state *mp_state)
257{
258 return -EINVAL;
259}
260
261int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
262 struct kvm_mp_state *mp_state)
263{
264 return -EINVAL;
265}
266
267int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
268{
269 return 0;
270}
271
272int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
273{
274 return -EINVAL;
275}
276
277long kvm_arch_vcpu_ioctl(struct file *filp,
278 unsigned int ioctl, unsigned long arg)
279{
280 struct kvm_vcpu *vcpu = filp->private_data;
281 void __user *argp = (void __user *)arg;
282
283 switch (ioctl) {
284 case KVM_ARM_VCPU_INIT: {
285 struct kvm_vcpu_init init;
286
287 if (copy_from_user(&init, argp, sizeof(init)))
288 return -EFAULT;
289
290 return kvm_vcpu_set_target(vcpu, &init);
291
292 }
293 case KVM_SET_ONE_REG:
294 case KVM_GET_ONE_REG: {
295 struct kvm_one_reg reg;
296 if (copy_from_user(&reg, argp, sizeof(reg)))
297 return -EFAULT;
298 if (ioctl == KVM_SET_ONE_REG)
299 return kvm_arm_set_reg(vcpu, &reg);
300 else
301 return kvm_arm_get_reg(vcpu, &reg);
302 }
303 case KVM_GET_REG_LIST: {
304 struct kvm_reg_list __user *user_list = argp;
305 struct kvm_reg_list reg_list;
306 unsigned n;
307
308 if (copy_from_user(&reg_list, user_list, sizeof(reg_list)))
309 return -EFAULT;
310 n = reg_list.n;
311 reg_list.n = kvm_arm_num_regs(vcpu);
312 if (copy_to_user(user_list, &reg_list, sizeof(reg_list)))
313 return -EFAULT;
314 if (n < reg_list.n)
315 return -E2BIG;
316 return kvm_arm_copy_reg_indices(vcpu, user_list->reg);
317 }
318 default:
319 return -EINVAL;
320 }
321}
322
323int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
324{
325 return -EINVAL;
326}
327
328long kvm_arch_vm_ioctl(struct file *filp,
329 unsigned int ioctl, unsigned long arg)
330{
331 return -EINVAL;
332}
333
334int kvm_arch_init(void *opaque)
335{
336 return 0;
337}
338
339/* NOP: Compiling as a module not supported */
340void kvm_arch_exit(void)
341{
342}
343
344static int arm_init(void)
345{
346 int rc = kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE);
347 return rc;
348}
349
350module_init(arm_init);