aboutsummaryrefslogtreecommitdiffstats
path: root/include/kvm/arm_arch_timer.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/kvm/arm_arch_timer.h')
-rw-r--r--include/kvm/arm_arch_timer.h68
1 files changed, 49 insertions, 19 deletions
diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h
index 33771352dcd6..05a18dd265b5 100644
--- a/include/kvm/arm_arch_timer.h
+++ b/include/kvm/arm_arch_timer.h
@@ -22,7 +22,22 @@
22#include <linux/clocksource.h> 22#include <linux/clocksource.h>
23#include <linux/hrtimer.h> 23#include <linux/hrtimer.h>
24 24
25enum kvm_arch_timers {
26 TIMER_PTIMER,
27 TIMER_VTIMER,
28 NR_KVM_TIMERS
29};
30
31enum kvm_arch_timer_regs {
32 TIMER_REG_CNT,
33 TIMER_REG_CVAL,
34 TIMER_REG_TVAL,
35 TIMER_REG_CTL,
36};
37
25struct arch_timer_context { 38struct arch_timer_context {
39 struct kvm_vcpu *vcpu;
40
26 /* Registers: control register, timer value */ 41 /* Registers: control register, timer value */
27 u32 cnt_ctl; 42 u32 cnt_ctl;
28 u64 cnt_cval; 43 u64 cnt_cval;
@@ -30,30 +45,36 @@ struct arch_timer_context {
30 /* Timer IRQ */ 45 /* Timer IRQ */
31 struct kvm_irq_level irq; 46 struct kvm_irq_level irq;
32 47
48 /* Virtual offset */
49 u64 cntvoff;
50
51 /* Emulated Timer (may be unused) */
52 struct hrtimer hrtimer;
53
33 /* 54 /*
34 * We have multiple paths which can save/restore the timer state 55 * We have multiple paths which can save/restore the timer state onto
35 * onto the hardware, so we need some way of keeping track of 56 * the hardware, so we need some way of keeping track of where the
36 * where the latest state is. 57 * latest state is.
37 *
38 * loaded == true: State is loaded on the hardware registers.
39 * loaded == false: State is stored in memory.
40 */ 58 */
41 bool loaded; 59 bool loaded;
42 60
43 /* Virtual offset */ 61 /* Duplicated state from arch_timer.c for convenience */
44 u64 cntvoff; 62 u32 host_timer_irq;
63 u32 host_timer_irq_flags;
64};
65
66struct timer_map {
67 struct arch_timer_context *direct_vtimer;
68 struct arch_timer_context *direct_ptimer;
69 struct arch_timer_context *emul_ptimer;
45}; 70};
46 71
47struct arch_timer_cpu { 72struct arch_timer_cpu {
48 struct arch_timer_context vtimer; 73 struct arch_timer_context timers[NR_KVM_TIMERS];
49 struct arch_timer_context ptimer;
50 74
51 /* Background timer used when the guest is not running */ 75 /* Background timer used when the guest is not running */
52 struct hrtimer bg_timer; 76 struct hrtimer bg_timer;
53 77
54 /* Physical timer emulation */
55 struct hrtimer phys_timer;
56
57 /* Is the timer enabled */ 78 /* Is the timer enabled */
58 bool enabled; 79 bool enabled;
59}; 80};
@@ -76,9 +97,6 @@ int kvm_arm_timer_has_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr);
76 97
77bool kvm_timer_is_pending(struct kvm_vcpu *vcpu); 98bool kvm_timer_is_pending(struct kvm_vcpu *vcpu);
78 99
79void kvm_timer_schedule(struct kvm_vcpu *vcpu);
80void kvm_timer_unschedule(struct kvm_vcpu *vcpu);
81
82u64 kvm_phys_timer_read(void); 100u64 kvm_phys_timer_read(void);
83 101
84void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu); 102void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu);
@@ -88,7 +106,19 @@ void kvm_timer_init_vhe(void);
88 106
89bool kvm_arch_timer_get_input_level(int vintid); 107bool kvm_arch_timer_get_input_level(int vintid);
90 108
91#define vcpu_vtimer(v) (&(v)->arch.timer_cpu.vtimer) 109#define vcpu_timer(v) (&(v)->arch.timer_cpu)
92#define vcpu_ptimer(v) (&(v)->arch.timer_cpu.ptimer) 110#define vcpu_get_timer(v,t) (&vcpu_timer(v)->timers[(t)])
111#define vcpu_vtimer(v) (&(v)->arch.timer_cpu.timers[TIMER_VTIMER])
112#define vcpu_ptimer(v) (&(v)->arch.timer_cpu.timers[TIMER_PTIMER])
113
114#define arch_timer_ctx_index(ctx) ((ctx) - vcpu_timer((ctx)->vcpu)->timers)
115
116u64 kvm_arm_timer_read_sysreg(struct kvm_vcpu *vcpu,
117 enum kvm_arch_timers tmr,
118 enum kvm_arch_timer_regs treg);
119void kvm_arm_timer_write_sysreg(struct kvm_vcpu *vcpu,
120 enum kvm_arch_timers tmr,
121 enum kvm_arch_timer_regs treg,
122 u64 val);
93 123
94#endif 124#endif