compiles
This commit is contained in:
+17
-11
@@ -1,9 +1,11 @@
|
||||
#include <zinnia/assert.h>
|
||||
#include <zinnia/clock.h>
|
||||
#include <zinnia/cmdline.h>
|
||||
#include <zinnia/mmio.h>
|
||||
#include <zinnia/pmap.h>
|
||||
#include <zinnia/print.h>
|
||||
#include <zinnia/utils.h>
|
||||
#include <assert.h>
|
||||
#include <zinnia/vma.h>
|
||||
#include <uacpi/acpi.h>
|
||||
#include <uacpi/status.h>
|
||||
#include <uacpi/tables.h>
|
||||
@@ -17,22 +19,22 @@ CMDLINE_OPTION("hpet", hpet_option);
|
||||
|
||||
struct hpet {
|
||||
struct clock clock;
|
||||
struct mmio_view regs;
|
||||
void* regs;
|
||||
uint32_t period;
|
||||
};
|
||||
|
||||
constexpr mmio_reg32 HPET_CAP = {.offset = 0};
|
||||
constexpr mmio_reg32 HPET_CFG = {.offset = 0x10};
|
||||
constexpr mmio_reg32 HPET_COUNTER = {.offset = 0xF0};
|
||||
constexpr uint32_t HPET_CAP = 0x0;
|
||||
constexpr uint32_t HPET_CFG = 0x10;
|
||||
constexpr uint32_t HPET_COUNTER = 0xF0;
|
||||
|
||||
static void hpet_reset(struct clock* c) {
|
||||
struct hpet* hpet = containerof(c, struct hpet, clock);
|
||||
mmio_store(&hpet->regs, HPET_COUNTER, 0u);
|
||||
mmio_write64(hpet->regs + HPET_COUNTER, 0);
|
||||
}
|
||||
|
||||
static uint64_t hpet_get_elapsed_ns(struct clock* c) {
|
||||
struct hpet* hpet = containerof(c, struct hpet, clock);
|
||||
uint64_t counter = mmio_load(&hpet->regs, HPET_COUNTER);
|
||||
uint64_t counter = mmio_read64(hpet->regs + HPET_COUNTER);
|
||||
return (counter * (uint64_t)hpet->period / 1'000'000);
|
||||
}
|
||||
|
||||
@@ -56,13 +58,17 @@ void hpet_init() {
|
||||
assert(!uacpi_table_find_by_signature("HPET", &table), "HPET table not found!\n");
|
||||
|
||||
struct acpi_hpet* hpet = table.ptr;
|
||||
hpet_clock.regs = mmio_new(hpet->address.address, 0x1000);
|
||||
|
||||
uintptr_t vaddr = vm_alloc(0x1000);
|
||||
pmap_map(&kernel_vma.pmap, vaddr, hpet->address.address, PTE_READ | PTE_WRITE, CACHE_MMIO);
|
||||
hpet_clock.regs = (void*)vaddr;
|
||||
|
||||
uacpi_table_unref(&table);
|
||||
kprintf("HPET regs at %p\n", hpet_clock.regs.base);
|
||||
log("x86_64/hpet", "HPET registers mapped at %p\n", hpet_clock.regs);
|
||||
|
||||
mmio_store(&hpet_clock.regs, HPET_CFG, mmio_load(&hpet_clock.regs, HPET_CFG) | 1);
|
||||
mmio_write64(hpet_clock.regs + HPET_CFG, mmio_read64(hpet_clock.regs + HPET_CFG) | 1);
|
||||
|
||||
uint64_t caps = mmio_load(&hpet_clock.regs, HPET_CAP);
|
||||
uint64_t caps = mmio_read64(hpet_clock.regs + HPET_CAP);
|
||||
hpet_clock.period = (caps >> 32) & 0xFFFF'FFFF;
|
||||
|
||||
assert(clock_switch(&hpet_clock.clock), "Unable to switch to HPET!\n");
|
||||
|
||||
Reference in New Issue
Block a user