mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-19 04:02:05 +00:00
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>
56 lines
1.2 KiB
C
56 lines
1.2 KiB
C
/*
|
|
* Copyright (C) <2018> Intel Corporation
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#ifndef _TIMER_H_
|
|
#define _TIMER_H_
|
|
|
|
#include <sys/param.h>
|
|
|
|
struct acrn_timer {
|
|
int32_t fd;
|
|
int32_t clockid;
|
|
struct mevent *mevp;
|
|
void (*callback)(void *, uint64_t);
|
|
void *callback_param;
|
|
};
|
|
|
|
int32_t
|
|
acrn_timer_init(struct acrn_timer *timer, void (*cb)(void *, uint64_t), void *param);
|
|
void
|
|
acrn_timer_deinit(struct acrn_timer *timer);
|
|
int32_t
|
|
acrn_timer_settime(struct acrn_timer *timer, const struct itimerspec *new_value);
|
|
int32_t
|
|
acrn_timer_settime_abs(struct acrn_timer *timer,
|
|
const struct itimerspec *new_value);
|
|
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_ */
|