hpet: handle it not being present

This commit is contained in:
Matheus
2024-09-25 23:22:08 -03:00
parent 423f50c9a7
commit bb910d9e20
2 changed files with 15 additions and 5 deletions
+9 -3
View File
@@ -83,16 +83,22 @@ time_t arch_hpet_init() {
uacpi_table tbl;
struct acpi_hpet *table;
__assert(uacpi_table_find_by_signature("HPET", &tbl) == UACPI_STATUS_OK);
if (uacpi_table_find_by_signature("HPET", &tbl) != UACPI_STATUS_OK) {
printf("hpet: no timers\n");
return 0;
}
table = tbl.ptr;
printf("hpet%lu: %lu bits %lu comparators\n", table->number,
(table->block_id & ACPI_HPET_COUNT_SIZE_CAP) ? 64 : 32,
(table->block_id >> ACPI_HPET_NUMBER_OF_COMPARATORS_SHIFT) & ACPI_HPET_NUMBER_OF_COMPARATORS_MASK);
__assert(table->address.address_space_id == ACPI_AS_ID_SYS_MEM);
__assert((table->address.address & PAGE_SIZE) == 0);
hpet = vmm_map(NULL, PAGE_SIZE, VMM_FLAGS_PHYSICAL, ARCH_MMU_FLAGS_READ | ARCH_MMU_FLAGS_WRITE | ARCH_MMU_FLAGS_NOEXEC, (void *)table->address.address);
uint64_t page_offset = table->address.address % PAGE_SIZE;
hpet = vmm_map(NULL, (PAGE_SIZE + page_offset), VMM_FLAGS_PHYSICAL, ARCH_MMU_FLAGS_READ | ARCH_MMU_FLAGS_WRITE | ARCH_MMU_FLAGS_NOEXEC, (void *)(table->address.address - page_offset));
__assert(hpet);
hpet = (void *)((uintptr_t)hpet + page_offset);
uint64_t capabilities = read64(HPET_REG_CAPS);
+6 -2
View File
@@ -61,9 +61,13 @@ void kernel_entry() {
acpi_early_init();
arch_apic_init();
cpu_initstate();
// XXX fall back to another clock source
time_t u = arch_hpet_init();
timekeeper_init(arch_hpet_ticks, u);
time_t hpet_ticks_per_us = arch_hpet_init();
__assert(hpet_ticks_per_us);
timekeeper_init(arch_hpet_ticks, hpet_ticks_per_us);
arch_apic_timerinit();
sched_init();
arch_smp_wakeup();