Skip to content

Commit

Permalink
KVM: arm/arm64: Rework the timer code to use a timer_map
Browse files Browse the repository at this point in the history
We are currently emulating two timers in two different ways.  When we
add support for nested virtualization in the future, we are going to be
emulating either two timers in two diffferent ways, or four timers in a
single way.

We need a unified data structure to keep track of how we map virtual
state to physical state and we need to cleanup some of the timer code to
operate more independently on a struct arch_timer_context instead of
trying to consider the global state of the VCPU and recomputing all
state.

Co-written with Marc Zyngier <marc.zyngier@arm.com>

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@arm.com>
  • Loading branch information
Christoffer Dall authored and Marc Zyngier committed Feb 19, 2019
1 parent 9e01dc7 commit bee038a
Show file tree
Hide file tree
Showing 3 changed files with 278 additions and 145 deletions.
23 changes: 13 additions & 10 deletions include/kvm/arm_arch_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,24 @@ struct arch_timer_context {
/* Emulated Timer (may be unused) */
struct hrtimer hrtimer;

/*
* We have multiple paths which can save/restore the timer state onto
* the hardware, so we need some way of keeping track of where the
* latest state is.
*/
bool loaded;

/* Duplicated state from arch_timer.c for convenience */
u32 host_timer_irq;
u32 host_timer_irq_flags;
};

struct timer_map {
struct arch_timer_context *direct_vtimer;
struct arch_timer_context *direct_ptimer;
struct arch_timer_context *emul_ptimer;
};

struct arch_timer_cpu {
struct arch_timer_context timers[NR_KVM_TIMERS];

Expand All @@ -64,16 +77,6 @@ struct arch_timer_cpu {

/* Is the timer enabled */
bool enabled;

/*
* We have multiple paths which can save/restore the timer state
* onto the hardware, so we need some way of keeping track of
* where the latest state is.
*
* loaded == true: State is loaded on the hardware registers.
* loaded == false: State is stored in memory.
*/
bool loaded;
};

int kvm_timer_hyp_init(bool);
Expand Down
Loading

0 comments on commit bee038a

Please sign in to comment.