arm64: Use architectural system timer.

Change-Id: Ia31a66b2860b8b4d47583ac55053ff3aea8bb2ad
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5279
Reviewed-by: John Scipione <jscipione@gmail.com>
Reviewed-by: Fredrik Holmqvist <fredrik.holmqvist@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
milek7 2022-04-11 02:02:48 +02:00 committed by Adrien Destugues
parent 91ee0332c3
commit ea698ddcbc

View File

@ -5,27 +5,57 @@
#include <boot/stage2.h> #include <boot/stage2.h>
#include <kernel.h> #include <kernel.h>
#include <debug.h> #include <debug.h>
#include <int.h>
#include <timer.h> #include <timer.h>
#include <arch/timer.h> #include <arch/timer.h>
#include <arch/cpu.h> #include <arch/cpu.h>
static uint64 sTimerTicksUS;
static bigtime_t sTimerMaxInterval;
#define TIMER_ARMED (1)
#define TIMER_MASKED (2 | 1)
#define TIMER_IRQ 30
void void
arch_timer_set_hardware_timer(bigtime_t timeout) arch_timer_set_hardware_timer(bigtime_t timeout)
{ {
if (timeout > sTimerMaxInterval)
timeout = sTimerMaxInterval;
WRITE_SPECIALREG(CNTP_TVAL_EL0, timeout * sTimerTicksUS);
WRITE_SPECIALREG(CNTP_CTL_EL0, TIMER_ARMED);
} }
void void
arch_timer_clear_hardware_timer() arch_timer_clear_hardware_timer()
{ {
WRITE_SPECIALREG(CNTP_CTL_EL0, TIMER_MASKED);
}
int32
arch_timer_interrupt(void *data)
{
WRITE_SPECIALREG(CNTP_CTL_EL0, TIMER_MASKED);
return timer_interrupt();
} }
int int
arch_init_timer(kernel_args *args) arch_init_timer(kernel_args *args)
{ {
sTimerTicksUS = READ_SPECIALREG(CNTFRQ_EL0) / 1000000;
sTimerMaxInterval = INT32_MAX / sTimerTicksUS;
WRITE_SPECIALREG(CNTP_CTL_EL0, TIMER_MASKED);
reserve_io_interrupt_vectors(1, TIMER_IRQ, INTERRUPT_TYPE_IRQ);
install_io_interrupt_handler(TIMER_IRQ, &arch_timer_interrupt, NULL, 0);
return B_OK; return B_OK;
} }
@ -33,5 +63,5 @@ arch_init_timer(kernel_args *args)
bigtime_t bigtime_t
system_time(void) system_time(void)
{ {
return 0; return READ_SPECIALREG(CNTPCT_EL0) / sTimerTicksUS;
} }