summaryrefslogtreecommitdiffstats
path: root/hal/uacpi.c
blob: 5aea7929f35be29e83b511d526e8ed41af6e0dd0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "arch/x86_64/hal/obj.h"
#include "init.h"
#include "uacpi/uacpi.h"
#include "lib/printf.h"
#include "uacpi/tables.h"
#include <hal/obj.h>

jove_objdir_t s_acpi_objdir = { 0 };

void uacpi_kernel_log(uacpi_log_level lvl, const uacpi_char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);

    kvprintf(fmt, ap);

    va_end(ap);
}

void
uacpi_kernel_init(void)
{
    uint8_t uacpi_buffer[1024];
    uacpi_setup_early_table_access(uacpi_buffer, 1024);

    jove_owned_obj_t *acpi_objdir_obj = objdir_getlocal(_rootdir_obj, ROOTDIR_ACPI_I);
    obj_settype(acpi_objdir_obj, JOVE_OBJ_OBJDIR);
    obj_setvalue(acpi_objdir_obj, (uintptr_t)&s_acpi_objdir);

    size_t num_tables = uacpi_table_count();
    for(size_t i = 0; i < num_tables; i++) {
        uacpi_table table;
        uacpi_status get_res = uacpi_table_get_by_index(i, &table);

        if(get_res != UACPI_STATUS_OK) {
            kprintf("uacpi: Failed to get table %i with code %s\n", i, uacpi_status_to_string(get_res));
            continue;
        }

        jove_owned_obj_t *table_obj = objdir_getlocal(acpi_objdir_obj, i);
        obj_settype(table_obj, JOVE_OBJ_ACPI_TABLE);
        obj_setvalue(table_obj, table.virt_addr);
        obj_release(table_obj);
    }
    obj_release(acpi_objdir_obj);
}