aboutsummaryrefslogtreecommitdiff
path: root/sys/arch/amd64/amd64/hpet.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/arch/amd64/amd64/hpet.c')
-rw-r--r--sys/arch/amd64/amd64/hpet.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/sys/arch/amd64/amd64/hpet.c b/sys/arch/amd64/amd64/hpet.c
index 71557eb..f63b47e 100644
--- a/sys/arch/amd64/amd64/hpet.c
+++ b/sys/arch/amd64/amd64/hpet.c
@@ -51,6 +51,9 @@ __KERNEL_META("$Hyra$: hpet.c, Ian Marco Moffett, "
#define CAP_VENDOR_ID(caps) __SHIFTOUT(caps, 0xFFFF << 16)
#define CAP_CLK_PERIOD(caps) (caps >> 32)
+#define FSEC_PER_SECOND 1000000000000000ULL
+#define USEC_PER_SECOND 1000000ULL
+
static struct timer timer = { 0 };
static struct hpet *acpi_hpet = NULL;
static void *hpet_base = NULL;
@@ -129,6 +132,26 @@ hpet_nsleep(size_t ns)
return hpet_sleep(ns, 1000000);
}
+static size_t
+hpet_time_usec(void)
+{
+ uint64_t period, freq, caps;
+ uint64_t counter;
+
+ caps = hpet_read(HPET_REG_CAPS);
+ period = CAP_CLK_PERIOD(caps);
+ freq = FSEC_PER_SECOND / period;
+
+ counter = hpet_read(HPET_REG_MAIN_COUNTER);
+ return (counter * USEC_PER_SECOND) / freq;
+}
+
+static size_t
+hpet_time_sec(void)
+{
+ return hpet_time_usec() / USEC_PER_SECOND;
+}
+
int
hpet_init(void)
{
@@ -172,6 +195,8 @@ hpet_init(void)
timer.msleep = hpet_msleep;
timer.usleep = hpet_usleep;
timer.nsleep = hpet_nsleep;
+ timer.get_time_usec = hpet_time_usec;
+ timer.get_time_sec = hpet_time_sec;
register_timer(TIMER_GP, &timer);
/* Not faulty */