aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2015-04-07 12:09:20 -0400
committerPaolo Bonzini <pbonzini@redhat.com>2015-04-07 12:09:20 -0400
commitbf0fb67cf957fc8ecfaaa2819b7d6a0f795e2ef2 (patch)
tree22697f7deae781dbbacd2e19a5030df2e8551e6a /include
parent8999602d08a804ae9cb271fdd5378f910058112d (diff)
parentd44758c0dfc5993a4b9952935a7eae4c91ebb6b4 (diff)
Merge tag 'kvm-arm-for-4.1' of git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm into 'kvm-next'
KVM/ARM changes for v4.1: - fixes for live migration - irqfd support - kvm-io-bus & vgic rework to enable ioeventfd - page ageing for stage-2 translation - various cleanups
Diffstat (limited to 'include')
-rw-r--r--include/kvm/arm_arch_timer.h31
-rw-r--r--include/kvm/arm_vgic.h117
-rw-r--r--include/kvm/iodev.h76
-rw-r--r--include/linux/kvm_host.h24
4 files changed, 121 insertions, 127 deletions
diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h
index b3f45a578344..e5966758c093 100644
--- a/include/kvm/arm_arch_timer.h
+++ b/include/kvm/arm_arch_timer.h
@@ -24,17 +24,14 @@
24#include <linux/workqueue.h> 24#include <linux/workqueue.h>
25 25
26struct arch_timer_kvm { 26struct arch_timer_kvm {
27#ifdef CONFIG_KVM_ARM_TIMER
28 /* Is the timer enabled */ 27 /* Is the timer enabled */
29 bool enabled; 28 bool enabled;
30 29
31 /* Virtual offset */ 30 /* Virtual offset */
32 cycle_t cntvoff; 31 cycle_t cntvoff;
33#endif
34}; 32};
35 33
36struct arch_timer_cpu { 34struct arch_timer_cpu {
37#ifdef CONFIG_KVM_ARM_TIMER
38 /* Registers: control register, timer value */ 35 /* Registers: control register, timer value */
39 u32 cntv_ctl; /* Saved/restored */ 36 u32 cntv_ctl; /* Saved/restored */
40 cycle_t cntv_cval; /* Saved/restored */ 37 cycle_t cntv_cval; /* Saved/restored */
@@ -55,10 +52,8 @@ struct arch_timer_cpu {
55 52
56 /* Timer IRQ */ 53 /* Timer IRQ */
57 const struct kvm_irq_level *irq; 54 const struct kvm_irq_level *irq;
58#endif
59}; 55};
60 56
61#ifdef CONFIG_KVM_ARM_TIMER
62int kvm_timer_hyp_init(void); 57int kvm_timer_hyp_init(void);
63void kvm_timer_enable(struct kvm *kvm); 58void kvm_timer_enable(struct kvm *kvm);
64void kvm_timer_init(struct kvm *kvm); 59void kvm_timer_init(struct kvm *kvm);
@@ -72,30 +67,6 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu);
72u64 kvm_arm_timer_get_reg(struct kvm_vcpu *, u64 regid); 67u64 kvm_arm_timer_get_reg(struct kvm_vcpu *, u64 regid);
73int kvm_arm_timer_set_reg(struct kvm_vcpu *, u64 regid, u64 value); 68int kvm_arm_timer_set_reg(struct kvm_vcpu *, u64 regid, u64 value);
74 69
75#else 70bool kvm_timer_should_fire(struct kvm_vcpu *vcpu);
76static inline int kvm_timer_hyp_init(void)
77{
78 return 0;
79};
80
81static inline void kvm_timer_enable(struct kvm *kvm) {}
82static inline void kvm_timer_init(struct kvm *kvm) {}
83static inline void kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu,
84 const struct kvm_irq_level *irq) {}
85static inline void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu) {}
86static inline void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu) {}
87static inline void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu) {}
88static inline void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu) {}
89
90static inline int kvm_arm_timer_set_reg(struct kvm_vcpu *vcpu, u64 regid, u64 value)
91{
92 return 0;
93}
94
95static inline u64 kvm_arm_timer_get_reg(struct kvm_vcpu *vcpu, u64 regid)
96{
97 return 0;
98}
99#endif
100 71
101#endif 72#endif
diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h
index 66203b268984..133ea00aa83b 100644
--- a/include/kvm/arm_vgic.h
+++ b/include/kvm/arm_vgic.h
@@ -24,6 +24,7 @@
24#include <linux/irqreturn.h> 24#include <linux/irqreturn.h>
25#include <linux/spinlock.h> 25#include <linux/spinlock.h>
26#include <linux/types.h> 26#include <linux/types.h>
27#include <kvm/iodev.h>
27 28
28#define VGIC_NR_IRQS_LEGACY 256 29#define VGIC_NR_IRQS_LEGACY 256
29#define VGIC_NR_SGIS 16 30#define VGIC_NR_SGIS 16
@@ -140,16 +141,21 @@ struct vgic_params {
140}; 141};
141 142
142struct vgic_vm_ops { 143struct vgic_vm_ops {
143 bool (*handle_mmio)(struct kvm_vcpu *, struct kvm_run *,
144 struct kvm_exit_mmio *);
145 bool (*queue_sgi)(struct kvm_vcpu *, int irq); 144 bool (*queue_sgi)(struct kvm_vcpu *, int irq);
146 void (*add_sgi_source)(struct kvm_vcpu *, int irq, int source); 145 void (*add_sgi_source)(struct kvm_vcpu *, int irq, int source);
147 int (*init_model)(struct kvm *); 146 int (*init_model)(struct kvm *);
148 int (*map_resources)(struct kvm *, const struct vgic_params *); 147 int (*map_resources)(struct kvm *, const struct vgic_params *);
149}; 148};
150 149
150struct vgic_io_device {
151 gpa_t addr;
152 int len;
153 const struct vgic_io_range *reg_ranges;
154 struct kvm_vcpu *redist_vcpu;
155 struct kvm_io_device dev;
156};
157
151struct vgic_dist { 158struct vgic_dist {
152#ifdef CONFIG_KVM_ARM_VGIC
153 spinlock_t lock; 159 spinlock_t lock;
154 bool in_kernel; 160 bool in_kernel;
155 bool ready; 161 bool ready;
@@ -197,6 +203,9 @@ struct vgic_dist {
197 /* Level-triggered interrupt queued on VCPU interface */ 203 /* Level-triggered interrupt queued on VCPU interface */
198 struct vgic_bitmap irq_queued; 204 struct vgic_bitmap irq_queued;
199 205
206 /* Interrupt was active when unqueue from VCPU interface */
207 struct vgic_bitmap irq_active;
208
200 /* Interrupt priority. Not used yet. */ 209 /* Interrupt priority. Not used yet. */
201 struct vgic_bytemap irq_priority; 210 struct vgic_bytemap irq_priority;
202 211
@@ -237,8 +246,12 @@ struct vgic_dist {
237 /* Bitmap indicating which CPU has something pending */ 246 /* Bitmap indicating which CPU has something pending */
238 unsigned long *irq_pending_on_cpu; 247 unsigned long *irq_pending_on_cpu;
239 248
249 /* Bitmap indicating which CPU has active IRQs */
250 unsigned long *irq_active_on_cpu;
251
240 struct vgic_vm_ops vm_ops; 252 struct vgic_vm_ops vm_ops;
241#endif 253 struct vgic_io_device dist_iodev;
254 struct vgic_io_device *redist_iodevs;
242}; 255};
243 256
244struct vgic_v2_cpu_if { 257struct vgic_v2_cpu_if {
@@ -266,13 +279,18 @@ struct vgic_v3_cpu_if {
266}; 279};
267 280
268struct vgic_cpu { 281struct vgic_cpu {
269#ifdef CONFIG_KVM_ARM_VGIC
270 /* per IRQ to LR mapping */ 282 /* per IRQ to LR mapping */
271 u8 *vgic_irq_lr_map; 283 u8 *vgic_irq_lr_map;
272 284
273 /* Pending interrupts on this VCPU */ 285 /* Pending/active/both interrupts on this VCPU */
274 DECLARE_BITMAP( pending_percpu, VGIC_NR_PRIVATE_IRQS); 286 DECLARE_BITMAP( pending_percpu, VGIC_NR_PRIVATE_IRQS);
287 DECLARE_BITMAP( active_percpu, VGIC_NR_PRIVATE_IRQS);
288 DECLARE_BITMAP( pend_act_percpu, VGIC_NR_PRIVATE_IRQS);
289
290 /* Pending/active/both shared interrupts, dynamically sized */
275 unsigned long *pending_shared; 291 unsigned long *pending_shared;
292 unsigned long *active_shared;
293 unsigned long *pend_act_shared;
276 294
277 /* Bitmap of used/free list registers */ 295 /* Bitmap of used/free list registers */
278 DECLARE_BITMAP( lr_used, VGIC_V2_MAX_LRS); 296 DECLARE_BITMAP( lr_used, VGIC_V2_MAX_LRS);
@@ -285,7 +303,6 @@ struct vgic_cpu {
285 struct vgic_v2_cpu_if vgic_v2; 303 struct vgic_v2_cpu_if vgic_v2;
286 struct vgic_v3_cpu_if vgic_v3; 304 struct vgic_v3_cpu_if vgic_v3;
287 }; 305 };
288#endif
289}; 306};
290 307
291#define LR_EMPTY 0xff 308#define LR_EMPTY 0xff
@@ -295,10 +312,7 @@ struct vgic_cpu {
295 312
296struct kvm; 313struct kvm;
297struct kvm_vcpu; 314struct kvm_vcpu;
298struct kvm_run;
299struct kvm_exit_mmio;
300 315
301#ifdef CONFIG_KVM_ARM_VGIC
302int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write); 316int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write);
303int kvm_vgic_hyp_init(void); 317int kvm_vgic_hyp_init(void);
304int kvm_vgic_map_resources(struct kvm *kvm); 318int kvm_vgic_map_resources(struct kvm *kvm);
@@ -312,8 +326,7 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int irq_num,
312 bool level); 326 bool level);
313void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg); 327void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg);
314int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu); 328int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu);
315bool vgic_handle_mmio(struct kvm_vcpu *vcpu, struct kvm_run *run, 329int kvm_vgic_vcpu_active_irq(struct kvm_vcpu *vcpu);
316 struct kvm_exit_mmio *mmio);
317 330
318#define irqchip_in_kernel(k) (!!((k)->arch.vgic.in_kernel)) 331#define irqchip_in_kernel(k) (!!((k)->arch.vgic.in_kernel))
319#define vgic_initialized(k) (!!((k)->arch.vgic.nr_cpus)) 332#define vgic_initialized(k) (!!((k)->arch.vgic.nr_cpus))
@@ -335,84 +348,4 @@ static inline int vgic_v3_probe(struct device_node *vgic_node,
335} 348}
336#endif 349#endif
337 350
338#else
339static inline int kvm_vgic_hyp_init(void)
340{
341 return 0;
342}
343
344static inline int kvm_vgic_set_addr(struct kvm *kvm, unsigned long type, u64 addr)
345{
346 return 0;
347}
348
349static inline int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write)
350{
351 return -ENXIO;
352}
353
354static inline int kvm_vgic_map_resources(struct kvm *kvm)
355{
356 return 0;
357}
358
359static inline int kvm_vgic_create(struct kvm *kvm, u32 type)
360{
361 return 0;
362}
363
364static inline void kvm_vgic_destroy(struct kvm *kvm)
365{
366}
367
368static inline void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu)
369{
370}
371
372static inline int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu)
373{
374 return 0;
375}
376
377static inline void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu) {}
378static inline void kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu) {}
379
380static inline int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid,
381 unsigned int irq_num, bool level)
382{
383 return 0;
384}
385
386static inline int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu)
387{
388 return 0;
389}
390
391static inline bool vgic_handle_mmio(struct kvm_vcpu *vcpu, struct kvm_run *run,
392 struct kvm_exit_mmio *mmio)
393{
394 return false;
395}
396
397static inline int irqchip_in_kernel(struct kvm *kvm)
398{
399 return 0;
400}
401
402static inline bool vgic_initialized(struct kvm *kvm)
403{
404 return true;
405}
406
407static inline bool vgic_ready(struct kvm *kvm)
408{
409 return true;
410}
411
412static inline int kvm_vgic_get_max_vcpus(void)
413{
414 return KVM_MAX_VCPUS;
415}
416#endif
417
418#endif 351#endif
diff --git a/include/kvm/iodev.h b/include/kvm/iodev.h
new file mode 100644
index 000000000000..a6d208b916f5
--- /dev/null
+++ b/include/kvm/iodev.h
@@ -0,0 +1,76 @@
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 as published by
4 * the Free Software Foundation; either version 2 of the License.
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, see <http://www.gnu.org/licenses/>.
13 */
14
15#ifndef __KVM_IODEV_H__
16#define __KVM_IODEV_H__
17
18#include <linux/kvm_types.h>
19#include <linux/errno.h>
20
21struct kvm_io_device;
22struct kvm_vcpu;
23
24/**
25 * kvm_io_device_ops are called under kvm slots_lock.
26 * read and write handlers return 0 if the transaction has been handled,
27 * or non-zero to have it passed to the next device.
28 **/
29struct kvm_io_device_ops {
30 int (*read)(struct kvm_vcpu *vcpu,
31 struct kvm_io_device *this,
32 gpa_t addr,
33 int len,
34 void *val);
35 int (*write)(struct kvm_vcpu *vcpu,
36 struct kvm_io_device *this,
37 gpa_t addr,
38 int len,
39 const void *val);
40 void (*destructor)(struct kvm_io_device *this);
41};
42
43
44struct kvm_io_device {
45 const struct kvm_io_device_ops *ops;
46};
47
48static inline void kvm_iodevice_init(struct kvm_io_device *dev,
49 const struct kvm_io_device_ops *ops)
50{
51 dev->ops = ops;
52}
53
54static inline int kvm_iodevice_read(struct kvm_vcpu *vcpu,
55 struct kvm_io_device *dev, gpa_t addr,
56 int l, void *v)
57{
58 return dev->ops->read ? dev->ops->read(vcpu, dev, addr, l, v)
59 : -EOPNOTSUPP;
60}
61
62static inline int kvm_iodevice_write(struct kvm_vcpu *vcpu,
63 struct kvm_io_device *dev, gpa_t addr,
64 int l, const void *v)
65{
66 return dev->ops->write ? dev->ops->write(vcpu, dev, addr, l, v)
67 : -EOPNOTSUPP;
68}
69
70static inline void kvm_iodevice_destructor(struct kvm_io_device *dev)
71{
72 if (dev->ops->destructor)
73 dev->ops->destructor(dev);
74}
75
76#endif /* __KVM_IODEV_H__ */
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 0f574ebc82f4..27bd53b69080 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -165,12 +165,12 @@ enum kvm_bus {
165 KVM_NR_BUSES 165 KVM_NR_BUSES
166}; 166};
167 167
168int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, 168int kvm_io_bus_write(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr,
169 int len, const void *val); 169 int len, const void *val);
170int kvm_io_bus_write_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, 170int kvm_io_bus_write_cookie(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx,
171 int len, const void *val, long cookie); 171 gpa_t addr, int len, const void *val, long cookie);
172int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, int len, 172int kvm_io_bus_read(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr,
173 void *val); 173 int len, void *val);
174int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, 174int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
175 int len, struct kvm_io_device *dev); 175 int len, struct kvm_io_device *dev);
176int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx, 176int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
@@ -699,6 +699,20 @@ static inline wait_queue_head_t *kvm_arch_vcpu_wq(struct kvm_vcpu *vcpu)
699#endif 699#endif
700} 700}
701 701
702#ifdef __KVM_HAVE_ARCH_INTC_INITIALIZED
703/*
704 * returns true if the virtual interrupt controller is initialized and
705 * ready to accept virtual IRQ. On some architectures the virtual interrupt
706 * controller is dynamically instantiated and this is not always true.
707 */
708bool kvm_arch_intc_initialized(struct kvm *kvm);
709#else
710static inline bool kvm_arch_intc_initialized(struct kvm *kvm)
711{
712 return true;
713}
714#endif
715
702int kvm_arch_init_vm(struct kvm *kvm, unsigned long type); 716int kvm_arch_init_vm(struct kvm *kvm, unsigned long type);
703void kvm_arch_destroy_vm(struct kvm *kvm); 717void kvm_arch_destroy_vm(struct kvm *kvm);
704void kvm_arch_sync_events(struct kvm *kvm); 718void kvm_arch_sync_events(struct kvm *kvm);