dm: vhpet: add vHPET support

vHPET is used as a source of system timer by UEFI (e.g. OVMF).

This provides an alternative to using vPIT, which OVMF assumes is always
connected to vPIC.

This is ported from Bhyve, with a few changes:

- move to user space, using acrn_timer
- enable timers only when necessary

Origin: FreeBSD
License: BSD-3-Clause
URL: https://svnweb.freebsd.org/
commit: 326257
Purpose: Adding vHPET support.
Maintained-by: External

Tracked-On: #2319
Signed-off-by: Peter Fang <peter.fang@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
This commit is contained in:
Peter Fang
2019-01-10 19:44:30 -08:00
committed by wenlingz
parent 0343da8c70
commit 4642269248
7 changed files with 1045 additions and 34 deletions

View File

@@ -6,6 +6,8 @@
#ifndef _TIMER_H_
#define _TIMER_H_
#include <sys/param.h>
struct acrn_timer {
int32_t fd;
int32_t clockid;
@@ -26,4 +28,28 @@ acrn_timer_settime_abs(struct acrn_timer *timer,
int32_t
acrn_timer_gettime(struct acrn_timer *timer, struct itimerspec *cur_value);
#define NS_PER_SEC (1000000000ULL)
static inline uint64_t
ts_to_ticks(const uint32_t freq, const struct timespec *const ts)
{
uint64_t tv_sec_ticks, tv_nsec_ticks;
tv_sec_ticks = ts->tv_sec * freq;
tv_nsec_ticks = (ts->tv_nsec * freq) / NS_PER_SEC;
return tv_sec_ticks + tv_nsec_ticks;
}
static inline void
ticks_to_ts(const uint32_t freq, const uint64_t ticks,
struct timespec *const ts)
{
uint64_t ns;
ns = howmany(ticks * NS_PER_SEC, freq);
ts->tv_sec = ns / NS_PER_SEC;
ts->tv_nsec = ns % NS_PER_SEC;
}
#endif /* _VTIMER_ */