Files
my-os-project2/kernel/hal/x86_64/acpi.c
2025-08-21 00:47:58 +02:00

60 lines
1.3 KiB
C

#include <stddef.h>
#include <stdint.h>
#include "hal/hal.h"
#include "kprintf.h"
#include "dlmalloc/malloc.h"
#include "compiler/attr.h"
#include "acpi.h"
#include "assert.h"
#include "util/util.h"
#include "bootinfo/bootinfo.h"
#include "uacpi/uacpi.h"
// uACPI
void uacpi_kernel_log(uacpi_log_level lvl, const uacpi_char *s) {
char *t = NULL;
switch (lvl) {
case UACPI_LOG_INFO: t = "Info"; break;
case UACPI_LOG_WARN: t = "Warn"; break;
case UACPI_LOG_DEBUG: t = "Dbg"; break;
case UACPI_LOG_ERROR: t = "Err"; break;
case UACPI_LOG_TRACE: t = "Trc"; break;
}
LOG("uACPI", "%s %s", t, s);
}
void uacpi_kernel_unmap(void *addr, uacpi_size len) {
// .
}
void *uacpi_kernel_map(uacpi_phys_addr addr, uacpi_size len) {
return (void *)(BOOT_INFO.hhdm_off + addr);
}
uacpi_status uacpi_kernel_get_rsdp(uacpi_phys_addr *out) {
*out = BOOT_INFO.rsdp;
return UACPI_STATUS_OK;
}
void acpi_init(void) {
uacpi_status r;
size_t tmpbufsize = 0x1000;
void *tmpbuf = dlmalloc(tmpbufsize);
if (tmpbuf == NULL) {
ERR("hal", "could not allocate uACPI tmp buf\n");
hal_hang();
}
r = uacpi_setup_early_table_access(tmpbuf, tmpbufsize);
if (uacpi_unlikely_error(r)) {
ERR("hal", "uACPI init early table failed\n");
hal_hang();
}
LOG("hal", "acpi init\n");
}
/* uint32_t acpi_remapirq(uint32_t irq) { */
/* } */