Skip to content

Commit

Permalink
init: add hooks for hpet emulation
Browse files Browse the repository at this point in the history
This allows VMs to emulate the HPET for higher-precision timing.

Signed-off-by: Chris Guikema <[email protected]>
  • Loading branch information
chrisguikema committed Oct 25, 2023
1 parent 2941a4b commit 8147333
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions camkes_vm_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function(DeclareCAmkESVM init_component)
sel4allocman
sel4vm
sel4vmmplatsupport
sel4vmmplatsupport_Config
sel4_autoconf
camkes_vmm_Config
virtqueue
Expand Down
18 changes: 18 additions & 0 deletions components/Init/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
#include <sel4vm/arch/ioports.h>
#include <sel4vm/guest_irq_controller.h>

#include <sel4vmmplatsupport/gen_config.h>
#include <sel4vmmplatsupport/guest_memory_util.h>
#include <sel4vmmplatsupport/ioports.h>
#include <sel4vmmplatsupport/drivers/pci.h>
#include <sel4vmmplatsupport/drivers/pci_helper.h>
#include <sel4vmmplatsupport/drivers/cross_vm_connection.h>
#include <sel4vmmplatsupport/arch/drivers/vmm_pci_helper.h>
#include <sel4vmmplatsupport/arch/hpet.h>

#include <sel4vm/arch/vmcall.h>

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand Down
5 changes: 5 additions & 0 deletions components/Init/src/timers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8147333

Please sign in to comment.