From 21816ed9be88cb293c9b136d96824dba17b0b2c3 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 20 Apr 2026 10:35:51 -0400 Subject: [PATCH] sp1: acpi: Add ACPI init groundwork Signed-off-by: Ian Moffett --- usr/src/sp1/common/io/acpi/acpi_init.c | 82 ++++++++++++++++++++++++++ usr/src/sp1/common/os/main.c | 4 ++ usr/src/sp1/head/io/acpi/acpi.h | 20 +++++++ 3 files changed, 106 insertions(+) create mode 100644 usr/src/sp1/common/io/acpi/acpi_init.c create mode 100644 usr/src/sp1/head/io/acpi/acpi.h diff --git a/usr/src/sp1/common/io/acpi/acpi_init.c b/usr/src/sp1/common/io/acpi/acpi_init.c new file mode 100644 index 0000000..90fc15b --- /dev/null +++ b/usr/src/sp1/common/io/acpi/acpi_init.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2026, Mirocom Laboratories + * All rights reserved. + * + * The following sources are CONFIDENTIAL and PROPRIETARY + * property of Mirocom Laboratories. Unauthorized copying, + * use, distrubution or modification of this file, in whole + * and in part, is strictly prohibited without the prior written + * consent from Mirocom Laboratories. + */ + +#include +#include +#include +#include +#include +#include + +#define pr_trace(fmt, ...) \ + printf("acpi: " fmt, ##__VA_ARGS__) + +static struct acpi_rsdp *rsdp = NULL; +static struct acpi_root_sdt *root_sdt = NULL; +static size_t root_sdt_entries = 0; + +/* + * Verify the RSDP structure + */ +static void +rsdp_verify(void) +{ + uint8_t major; + uint8_t csum = 0; + + /* + * Some implementations like those found in emulators may + * have their revision set to zero alongside ACPI 1.0 behavior. + * If we encounter a zeroed revision, just bump it up by one. + */ + if ((major = rsdp->revision) == 0) { + ++major; + } + + /* Print the version and compute checksum */ + pr_trace("detected acpi %d.0 by %.6s\n", major, rsdp->oemid); + for (size_t i = 0; i < rsdp->length; ++i) { + csum += ((uint8_t *)rsdp)[i]; + } + + /* Is the checksum valid? */ + if ((csum & 0xFF) != 0) { + knot("bad checksum %x for acpi rsdp\n", csum); + } +} + +void +acpi_init(void) +{ + struct bpt_protovar pv; + status_t status; + struct acpi_header *hdr; + uintptr_t pma; + + status = bpt_get_protovar(&pv); + if (status != STATUS_SUCCESS) { + knot("could not obtain protovar\n"); + } + + rsdp = pv.rsdp; + rsdp_verify(); + + /* Select the correct root sdt */ + if (rsdp->revision < 2) { + pr_trace("using rsdt as root sdt\n"); + root_sdt = pma_to_vma((uintptr_t)rsdp->rsdt_addr); + root_sdt_entries = (root_sdt->hdr.length - sizeof(root_sdt->hdr)) / 4; + } else { + pr_trace("using xsdt as root sdt\n"); + root_sdt = pma_to_vma((uintptr_t)rsdp->xsdt_addr); + root_sdt_entries = (root_sdt->hdr.length - sizeof(root_sdt->hdr)) / 8; + } +} diff --git a/usr/src/sp1/common/os/main.c b/usr/src/sp1/common/os/main.c index a3b3c3c..044813d 100644 --- a/usr/src/sp1/common/os/main.c +++ b/usr/src/sp1/common/os/main.c @@ -10,6 +10,7 @@ */ #include +#include #include #include #include @@ -56,6 +57,9 @@ main(void) /* Initialize virtual memory management */ mm_vm_init(); + /* Initialize ACPI */ + acpi_init(); + printf("[*] sp1 is pre-alpha\n"); printf("[*] knotting kernel...\n"); knot("end of kernel reached - halting\n"); diff --git a/usr/src/sp1/head/io/acpi/acpi.h b/usr/src/sp1/head/io/acpi/acpi.h new file mode 100644 index 0000000..03fecc0 --- /dev/null +++ b/usr/src/sp1/head/io/acpi/acpi.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2026, Mirocom Laboratories + * All rights reserved. + * + * The following sources are CONFIDENTIAL and PROPRIETARY + * property of Mirocom Laboratories. Unauthorized copying, + * use, distrubution or modification of this file, in whole + * and in part, is strictly prohibited without the prior written + * consent from Mirocom Laboratories. + */ + +#ifndef _ACPI_ACPI_H_ +#define _ACPI_ACPI_H_ 1 + +/* + * Initialize ACPI, panics on failure + */ +void acpi_init(void); + +#endif /* !_ACPI_ACPI_H_ */