From 814733350edbf2539ff2673b5db3d839b16cb36e Mon Sep 17 00:00:00 2001 From: Chris Guikema Date: Wed, 25 Oct 2023 15:44:26 -0400 Subject: [PATCH] init: add hooks for hpet emulation This allows VMs to emulate the HPET for higher-precision timing. Signed-off-by: Chris Guikema --- camkes_vm_helpers.cmake | 1 + components/Init/src/main.c | 18 ++++++++++++++++++ components/Init/src/timers.h | 5 +++++ 3 files changed, 24 insertions(+) diff --git a/camkes_vm_helpers.cmake b/camkes_vm_helpers.cmake index 5aac4647..9f742fa6 100644 --- a/camkes_vm_helpers.cmake +++ b/camkes_vm_helpers.cmake @@ -39,6 +39,7 @@ function(DeclareCAmkESVM init_component) sel4allocman sel4vm sel4vmmplatsupport + sel4vmmplatsupport_Config sel4_autoconf camkes_vmm_Config virtqueue diff --git a/components/Init/src/main.c b/components/Init/src/main.c index 1e726e26..af56b93a 100644 --- a/components/Init/src/main.c +++ b/components/Init/src/main.c @@ -34,12 +34,14 @@ #include #include +#include #include #include #include #include #include #include +#include #include @@ -438,6 +440,7 @@ static device_notify_t *device_notify_list = NULL; void pit_timer_interrupt(void); void rtc_timer_interrupt(uint32_t); void serial_timer_interrupt(uint32_t); +void hpet_timer_interrupt(uint32_t); static seL4_Word irq_badges[16] = { VM_PIC_BADGE_IRQ_0, @@ -483,6 +486,11 @@ static int handle_async_event(vm_t *vm, seL4_Word badge, UNUSED seL4_MessageInfo TIMER_MORE_CHARS))) { serial_timer_interrupt(completed); } +#ifdef CONFIG_VMM_USE_HPET + if (completed & (BIT(TIMER_HPET0) | BIT(TIMER_HPET1) | BIT(TIMER_HPET2))) { + hpet_timer_interrupt(completed); + } +#endif } if ((badge & serial_getchar_notification_badge()) == serial_getchar_notification_badge()) { serial_character_interrupt(); @@ -698,6 +706,16 @@ void *main_continued(void *arg) ZF_LOGI("RTC pre init"); rtc_pre_init(); +#ifdef CONFIG_VMM_USE_HPET + ZF_LOGI("HPET pre init\n"); + uint64_t tsc_frequency = init_timer_tsc_frequency(); + hpet_pre_init(tsc_frequency, + TIMER_HPET0, + init_timer_oneshot_relative, + init_timer_stop); + vm_create_hpet(&vm); +#endif + error = vmm_io_port_init(&io_ports, FREE_IOPORT_START); if (error) { ZF_LOGF_IF(error, "Failed to initialise VMM ioport management"); diff --git a/components/Init/src/timers.h b/components/Init/src/timers.h index 66cc26d6..422c35e6 100644 --- a/components/Init/src/timers.h +++ b/components/Init/src/timers.h @@ -24,3 +24,8 @@ #define TIMER_TRANSMIT_TIMER 6 #define TIMER_MODEM_STATUS_TIMER 7 #define TIMER_MORE_CHARS 8 + +/* hpet timer */ +#define TIMER_HPET0 9 +#define TIMER_HPET1 10 +#define TIMER_HPET2 11