stos/amd64: hpet: Add MdHpetTimeUsec() helper

Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
Chloe M.
2026-06-27 06:47:29 +00:00
parent 97ea4fad69
commit ef72c9d6d5
2 changed files with 20 additions and 0 deletions
+15
View File
@@ -14,6 +14,7 @@
#include <mm/vmm.h>
#include <ke/knot.h>
#include <ex/trace.h>
#include <units.h>
#define DTRACE(Fmt, ...) \
TRACE("[ HPET ]: " Fmt, ##__VA_ARGS__)
@@ -57,6 +58,20 @@ HpetReadq(UCHAR Register)
return MMIORead64(RegBase);
}
USIZE
MdHpetTimeUsec(VOID)
{
UQUAD Period, Freq, Caps;
UQUAD Counter;
Caps = HpetReadq(HPET_GENERAL_CAP);
Period = (Caps >> HPET_PERIOD_SHIFT) & HPET_PERIOD_MASK;
Freq = FSEC_PER_SECOND / Period;
Counter = HpetReadq(HPET_MAIN_COUNTER);
return (Counter * USEC_PER_SECOND) / Freq;
}
VOID
MdHpetInit(VOID)
{
+5
View File
@@ -16,4 +16,9 @@
*/
VOID MdHpetInit(VOID);
/*
* Obtain the elapsed time in microseconds
*/
USIZE MdHpetTimeUsec(VOID);
#endif /* !_MACHINE_HPET_H_ */