From c0875764f2a30ea8c9d7f628f2fe0ab2e66589f8 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 17 Nov 2025 16:48:13 -0500 Subject: kern: acpi: Add acpi_read_madt() helper Signed-off-by: Ian Moffett --- sys/acpi/acpi.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'sys/acpi') diff --git a/sys/acpi/acpi.c b/sys/acpi/acpi.c index f60435b..ac02e5e 100644 --- a/sys/acpi/acpi.c +++ b/sys/acpi/acpi.c @@ -28,6 +28,7 @@ */ #include +#include #include #include #include @@ -111,6 +112,46 @@ acpi_query(const char *s) return NULL; } +int +acpi_read_madt(uint32_t type, int(*cb)(struct apic_header *, size_t), size_t arg) +{ + static struct acpi_madt *madt; + struct apic_header *hdr; + uint8_t *cur, *end; + int retval; + + if (cb == NULL) { + return -EINVAL; + } + + if (madt == NULL) { + madt = acpi_query("APIC"); + } + + if (madt == NULL) { + panic("acpi: could not read MADT\n"); + } + + cur = (uint8_t *)(madt + 1); + end = (uint8_t *)madt + madt->hdr.length; + + while (cur < end) { + hdr = (void *)cur; + + if (hdr->type == type) { + retval = cb(hdr, arg); + } + + if (retval >= 0) { + return retval; + } + + cur += hdr->length; + } + + return -1; +} + void acpi_init(void) { -- cgit v1.2.3