Added support for reading and writing additional virtual timer registers for vcpu hw read and write accesses. These include the compare value register (CNTV_CVAL) and offset register (CNTV_OFF), each represented as two 32 bit (high and low) registers on aarch32 and as single 64 bit registers on aarch64. Added support for explicitly saving and restoring the virtual timer registers when the vcpu is enabled and disabled. This ensures when the vcpu is switched in and out, the virtual timer registers are restored to a state that is consistent to when it was last run. By default the CNTVOFF register will be updated by the kernel to accumulate the time the VCPU is not running. From the guest this will result in the VCNT register not increasing when the VCPU is suspended. This behavior can be turned off by disabling the KernelArmVtimerUpdateVOffset config option.
60 lines
1.5 KiB
C
60 lines
1.5 KiB
C
/*
|
|
* Copyright 2017, Data61
|
|
* Commonwealth Scientific and Industrial Research Organisation (CSIRO)
|
|
* ABN 41 687 119 230.
|
|
*
|
|
* This software may be distributed and modified according to the terms of
|
|
* the GNU General Public License version 2. Note that NO WARRANTY is provided.
|
|
* See "LICENSE_GPLv2.txt" for details.
|
|
*
|
|
* @TAG(DATA61_GPL)
|
|
*/
|
|
|
|
#ifndef __DRIVERS_TIMER_ARM_GENERIC_H_
|
|
#define __DRIVERS_TIMER_ARM_GENERIC_H_
|
|
|
|
#include <config.h>
|
|
#include <mode/machine.h>
|
|
|
|
/* ARM generic timer implementation */
|
|
#ifdef CONFIG_KERNEL_MCS
|
|
#include <model/statedata.h>
|
|
#include <api/types.h>
|
|
/** DONT_TRANSLATE **/
|
|
static inline ticks_t getCurrentTime(void)
|
|
{
|
|
ticks_t time;
|
|
SYSTEM_READ_64(CNT_CT, time);
|
|
return time;
|
|
}
|
|
|
|
/** DONT_TRANSLATE **/
|
|
static inline void setDeadline(ticks_t deadline)
|
|
{
|
|
assert(deadline >= NODE_STATE(ksCurTime));
|
|
SYSTEM_WRITE_64(CNT_CVAL, deadline);
|
|
}
|
|
|
|
static inline void ackDeadlineIRQ(void)
|
|
{
|
|
ticks_t deadline = UINT64_MAX;
|
|
setDeadline(deadline);
|
|
}
|
|
#else /* CONFIG_KERNEL_MCS */
|
|
#include <arch/machine/timer.h>
|
|
static inline void resetTimer(void)
|
|
{
|
|
SYSTEM_WRITE_WORD(CNT_TVAL, TIMER_RELOAD);
|
|
SYSTEM_WRITE_WORD(CNT_CTL, BIT(0));
|
|
}
|
|
#endif /* !CONFIG_KERNEL_MCS */
|
|
|
|
BOOT_CODE void initGenericTimer(void);
|
|
|
|
#ifdef CONFIG_ARM_HYPERVISOR_SUPPORT
|
|
static uint64_t read_cntpct(void) UNUSED;
|
|
static void save_virt_timer(vcpu_t *vcpu);
|
|
static void restore_virt_timer(vcpu_t *vcpu);
|
|
#endif /* CONFIG_ARM_HYPERVISOR_SUPPORT */
|
|
|
|
#endif /* __DRIVERS_TIMER_ARM_GENERIC_H_ */
|