diff options
Diffstat (limited to 'sys/arch/amd64/amd64/hpet.c')
-rw-r--r-- | sys/arch/amd64/amd64/hpet.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/sys/arch/amd64/amd64/hpet.c b/sys/arch/amd64/amd64/hpet.c index 860e610..3b0ca46 100644 --- a/sys/arch/amd64/amd64/hpet.c +++ b/sys/arch/amd64/amd64/hpet.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team. + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -47,6 +47,7 @@ #define CAP_CLK_PERIOD(caps) (caps >> 32) #define FSEC_PER_SECOND 1000000000000000ULL +#define NSEC_PER_SECOND 1000000000ULL #define USEC_PER_SECOND 1000000ULL static void *hpet_base = NULL; @@ -135,6 +136,20 @@ hpet_time_usec(void) } static size_t +hpet_time_nsec(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 * NSEC_PER_SECOND) / freq; +} + +static size_t hpet_time_sec(void) { return hpet_time_usec() / USEC_PER_SECOND; @@ -157,7 +172,7 @@ hpet_init(void) /* Ensure caps aren't bogus */ caps = hpet_read(HPET_REG_CAPS); if (CAP_REV_ID(caps) == 0) { - pr_error("Found bogus revision, assuming faulty\n"); + pr_error("found bogus revision, assuming faulty\n"); return -1; } if (CAP_CLK_PERIOD(caps) > 0x05F5E100) { @@ -166,7 +181,7 @@ hpet_init(void) * be <= 0x05F5E100. So we'll consider it as bogus * if it exceeds this value */ - pr_error("Found bogus COUNTER_CLK_PERIOD, assuming faulty\n"); + pr_error("found bogus COUNTER_CLK_PERIOD, assuming faulty\n"); return 1; } @@ -180,6 +195,7 @@ hpet_init(void) timer.usleep = hpet_usleep; timer.nsleep = hpet_nsleep; timer.get_time_usec = hpet_time_usec; + timer.get_time_nsec = hpet_time_nsec; timer.get_time_sec = hpet_time_sec; register_timer(TIMER_GP, &timer); return 0; |