AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
hpet.c File Reference

x86: the High Precision Event Timer (HPET), as a clock. More...

#include <core/system.h>
#include <core/arch.h>
#include <cpu/sdt.h>
#include <platform/misc.h>

Go to the source code of this file.

Macros

#define HPET_CAP   0x000
#define HPET_CNF   0x010
#define HPET_CNT   0x0F0
#define CNF_ENABLE   0x1
#define CNF_LEGACY   0x2
#define PERIOD_MAX_FS   100000000ULL

Functions

static uint32_t reg32 (unsigned off)
 Reads a 32-bit HPET register.
static void reg32_write (unsigned off, uint32_t val)
 Writes a 32-bit HPET register.
uint64_t x86_hpet_read (void)
 Reads the HPET's 64-bit counter.
uint32_t x86_hpet_read32 (void)
 Reads the low half of the HPET's counter only: a single read, which matters because each read is slow under a hypervisor.
uint64_t x86_hpet_period_fs (void)
 Returns the HPET counter's period.
int x86_hpet_init (void)
 Finds the HPET and starts its counter.

Variables

static volatile uint32_t * regs
static uint64_t period_fs

Detailed Description

x86: the High Precision Event Timer (HPET), as a clock.

Only the HPET's main counter is used, as a clock (sys/clock.c). ACPI's HPET table says where its registers are, which are mapped uncached. It counts at the period its capabilities say (10 ns on QEMU). "Legacy replacement" is left off, so the PIT keeps IRQ 0, and the comparators aren't used.

References: [1] - IA-PC HPET (High Precision Event Timers) Specification, Intel, 1.0a

Definition in file hpet.c.

Macro Definition Documentation

◆ CNF_ENABLE

#define CNF_ENABLE   0x1

Definition at line 24 of file hpet.c.

Referenced by x86_hpet_init().

◆ CNF_LEGACY

#define CNF_LEGACY   0x2

Definition at line 25 of file hpet.c.

Referenced by x86_hpet_init().

◆ HPET_CAP

#define HPET_CAP   0x000

Definition at line 20 of file hpet.c.

Referenced by x86_hpet_init().

◆ HPET_CNF

#define HPET_CNF   0x010

Definition at line 21 of file hpet.c.

Referenced by x86_hpet_init().

◆ HPET_CNT

#define HPET_CNT   0x0F0

Definition at line 22 of file hpet.c.

Referenced by x86_hpet_init(), x86_hpet_read(), and x86_hpet_read32().

◆ PERIOD_MAX_FS

#define PERIOD_MAX_FS   100000000ULL

Definition at line 27 of file hpet.c.

Referenced by x86_hpet_init().

Function Documentation

◆ reg32()

uint32_t reg32 ( unsigned off)
inlinestatic

Reads a 32-bit HPET register.

Definition at line 33 of file hpet.c.

References reg32(), and regs.

Referenced by reg32(), x86_hpet_init(), x86_hpet_read(), and x86_hpet_read32().

◆ reg32_write()

void reg32_write ( unsigned off,
uint32_t val )
inlinestatic

Writes a 32-bit HPET register.

Definition at line 39 of file hpet.c.

References reg32_write(), and regs.

Referenced by reg32_write(), and x86_hpet_init().

◆ x86_hpet_init()

int x86_hpet_init ( void )

Finds the HPET and starts its counter.

Returns
0 once it counts, -ENODEV if there's no usable HPET, or -ENOMEM if its registers couldn't be mapped

Definition at line 90 of file hpet.c.

References acpi_gas::address, acpi_hpet::address, arch_mmio_map(), CNF_ENABLE, CNF_LEGACY, acpi_hpet::header, HPET_CAP, HPET_CNF, HPET_CNT, acpi_sdt_header::length, NULL, period_fs, PERIOD_MAX_FS, printk(), reg32(), reg32_write(), regs, acpi_gas::space, x86_acpi_table(), and x86_hpet_init().

Referenced by x86_clock_init(), and x86_hpet_init().

◆ x86_hpet_period_fs()

uint64_t x86_hpet_period_fs ( void )

Returns the HPET counter's period.

Returns
the period, in femtoseconds

Definition at line 79 of file hpet.c.

References period_fs, and x86_hpet_period_fs().

Referenced by tsc_calibrate(), x86_clock_init(), and x86_hpet_period_fs().

◆ x86_hpet_read()

uint64_t x86_hpet_read ( void )

Reads the HPET's 64-bit counter.

Its two halves are read again until the high half is the same before and after, so that a carry between them can't give a wrong value.

Returns
the counter

Definition at line 51 of file hpet.c.

References HPET_CNT, reg32(), and x86_hpet_read().

Referenced by tsc_calibrate(), and x86_hpet_read().

◆ x86_hpet_read32()

uint32_t x86_hpet_read32 ( void )

Reads the low half of the HPET's counter only: a single read, which matters because each read is slow under a hypervisor.

Returns
the counter's low 32 bits

Definition at line 69 of file hpet.c.

References HPET_CNT, reg32(), and x86_hpet_read32().

Referenced by counter(), and x86_hpet_read32().

Variable Documentation

◆ period_fs

uint64_t period_fs
static

Definition at line 30 of file hpet.c.

Referenced by x86_hpet_init(), and x86_hpet_period_fs().

◆ regs

volatile uint32_t* regs
static

Definition at line 29 of file hpet.c.

Referenced by reg32(), reg32_write(), and x86_hpet_init().