X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/8c06c883e7b13c115d5ff207f79d4b68fccd5ad6..35a7d633d3f16c1e0539af6ca5d8e7482926cd93:/lunaix-os/hal/acpi/acpi.c diff --git a/lunaix-os/hal/acpi/acpi.c b/lunaix-os/hal/acpi/acpi.c index 67915fa..b4faf63 100644 --- a/lunaix-os/hal/acpi/acpi.c +++ b/lunaix-os/hal/acpi/acpi.c @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -15,48 +16,6 @@ LOG_MODULE("ACPI") int acpi_rsdp_validate(acpi_rsdp_t* rsdp); -acpi_rsdp_t* -acpi_locate_rsdp(); - -int -acpi_init() -{ - acpi_rsdp_t* rsdp = acpi_locate_rsdp(); - - assert_msg(rsdp, "Fail to locate ACPI_RSDP"); - assert_msg(acpi_rsdp_validate(rsdp), "Invalid ACPI_RSDP (checksum failed)"); - - acpi_rsdt_t* rsdt = rsdp->rsdt; - - ctx = vzalloc(sizeof(acpi_context)); - assert_msg(ctx, "Fail to create ACPI context"); - - strncpy(ctx->oem_id, rsdt->header.oem_id, 6); - ctx->oem_id[6] = '\0'; - - size_t entry_n = (rsdt->header.length - sizeof(acpi_sdthdr_t)) >> 2; - for (size_t i = 0; i < entry_n; i++) { - acpi_sdthdr_t* sdthdr = - (acpi_sdthdr_t*)((acpi_apic_t**)&(rsdt->entry))[i]; - switch (sdthdr->signature) { - case ACPI_MADT_SIG: - madt_parse((acpi_madt_t*)sdthdr, ctx); - break; - case ACPI_FADT_SIG: - // FADT just a plain structure, no need to parse. - ctx->fadt = *(acpi_fadt_t*)sdthdr; - break; - case ACPI_MCFG_SIG: - mcfg_parse(sdthdr, ctx); - break; - default: - break; - } - } - - return 0; -} - acpi_context* acpi_get_context() { @@ -106,4 +65,44 @@ acpi_locate_rsdp() } return rsdp; -} \ No newline at end of file +} + +static int +__gather_acpi_table() +{ + acpi_rsdp_t* rsdp = acpi_locate_rsdp(); + + assert_msg(rsdp, "Fail to locate ACPI_RSDP"); + assert_msg(acpi_rsdp_validate(rsdp), "Invalid ACPI_RSDP (checksum failed)"); + + acpi_rsdt_t* rsdt = rsdp->rsdt; + + ctx = vzalloc(sizeof(acpi_context)); + assert_msg(ctx, "Fail to create ACPI context"); + + strncpy(ctx->oem_id, rsdt->header.oem_id, 6); + ctx->oem_id[6] = '\0'; + + size_t entry_n = (rsdt->header.length - sizeof(acpi_sdthdr_t)) >> 2; + for (size_t i = 0; i < entry_n; i++) { + acpi_sdthdr_t* sdthdr = __acpi_sdthdr(rsdt->entry[i]); + switch (sdthdr->signature) { + case ACPI_MADT_SIG: + madt_parse(__acpi_madt(sdthdr), ctx); + break; + case ACPI_FADT_SIG: + // FADT just a plain structure, no need to parse. + ctx->fadt = *__acpi_fadt(sdthdr); + break; + case ACPI_MCFG_SIG: + mcfg_parse(sdthdr, ctx); + break; + default: + break; + } + } + + return 0; +} + +owloysius_fetch_init(__gather_acpi_table, on_sysconf); \ No newline at end of file