From 1325356f5783dbb3b0bc59bba6da8e714bbd7bb5 Mon Sep 17 00:00:00 2001 From: ian Date: Mon, 17 Jul 2023 05:21:04 +0000 Subject: kernel/acpi: Add ACPI subroutines git-svn-id: https://svn.vegaa.systems/svn/vega-Vega/trunk@26 a8a8aea2-181d-ee11-89e8-15fd0e089fc4 --- sys/firmware/acpi/acpi_subr.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/sys/firmware/acpi/acpi_subr.c b/sys/firmware/acpi/acpi_subr.c index d9ea694..7212602 100644 --- a/sys/firmware/acpi/acpi_subr.c +++ b/sys/firmware/acpi/acpi_subr.c @@ -31,6 +31,8 @@ #include #include +#include +#include bool acpi_is_checksum_valid(struct acpi_header *hdr) @@ -45,3 +47,37 @@ acpi_is_checksum_valid(struct acpi_header *hdr) /* Sum of table (from header to end) must be zero!! */ return sum == 0; } + +/* + * Looks up an ACPI table with a specific + * signature e.g "APIC" for MADT (if present). + * + * @query: The specific query to make e.g "APIC" + */ +void * +acpi_query(const char *query) +{ + struct acpi_header *hdr; + struct acpi_root_sdt *root_sdt; + size_t root_sdt_len, signature_len; + + root_sdt = acpi_get_root_sdt(); + root_sdt_len = acpi_get_root_sdt_len(); + + /* + * XXX: Just a reminder, sizeof() is compile time. + * There will be no actual reading, + * so this is safe. + */ + signature_len = sizeof(hdr->signature); + + for (size_t i = 0; i < root_sdt_len; ++i) { + hdr = (struct acpi_header *)PHYS_TO_VIRT(root_sdt->tables[i]); + + if (memcmp(hdr->signature, query, signature_len) == 0) { + return (void *)hdr; + } + } + + return NULL; +} -- cgit v1.2.3