diff options
| author | Ian Moffett <ian@osmora.org> | 2025-11-17 16:48:13 -0500 |
|---|---|---|
| committer | Ian Moffett <ian@osmora.org> | 2025-11-17 16:48:13 -0500 |
| commit | c0875764f2a30ea8c9d7f628f2fe0ab2e66589f8 (patch) | |
| tree | c6948e4a27735a537464c63c483829855cd70a98 | |
| parent | 4c961e20744579a2ba8c4de7ad1e7ecb22702f09 (diff) | |
kern: acpi: Add acpi_read_madt() helper
Signed-off-by: Ian Moffett <ian@osmora.org>
| -rw-r--r-- | sys/acpi/acpi.c | 41 | ||||
| -rw-r--r-- | sys/inc/acpi/acpi.h | 9 |
2 files changed, 50 insertions, 0 deletions
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 <sys/cdefs.h> +#include <sys/errno.h> #include <sys/types.h> #include <kern/panic.h> #include <os/trace.h> @@ -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) { diff --git a/sys/inc/acpi/acpi.h b/sys/inc/acpi/acpi.h index d9a2a47..29837ba 100644 --- a/sys/inc/acpi/acpi.h +++ b/sys/inc/acpi/acpi.h @@ -31,6 +31,7 @@ #define _ACPI_ACPI_H_ 1 #include <sys/types.h> +#include <acpi/tables.h> /* * Initialize the ACPI subsystem @@ -42,4 +43,12 @@ void acpi_init(void); */ void *acpi_query(const char *s); +/* + * Acquire a MADT entry by type + */ +int acpi_read_madt( + uint32_t type, int(*cb)(struct apic_header *h, size_t arg), + size_t arg +); + #endif /* !_ACPI_ACPI_H_ */ |
