git: c8b87aa10d68 - main - loader: Move ACPI RSDP detection
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 14 Sep 2025 04:53:49 UTC
The branch main has been updated by imp:
URL: https://cgit.FreeBSD.org/src/commit/?id=c8b87aa10d684111ec4f82b31a262850a28e5eb2
commit c8b87aa10d684111ec4f82b31a262850a28e5eb2
Author: kpowkitty <witchikittikat@gmail.com>
AuthorDate: 2025-08-31 22:30:27 +0000
Commit: Warner Losh <imp@FreeBSD.org>
CommitDate: 2025-09-14 02:24:19 +0000
loader: Move ACPI RSDP detection
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1843
---
stand/efi/acpica/acpi_detect.c | 69 ++++++++++++++++++++++++++++++++++
stand/efi/acpica/include/acpi_detect.h | 41 ++++++++++++++++++++
stand/efi/loader/Makefile | 4 ++
stand/efi/loader/main.c | 42 +--------------------
4 files changed, 116 insertions(+), 40 deletions(-)
diff --git a/stand/efi/acpica/acpi_detect.c b/stand/efi/acpica/acpi_detect.c
new file mode 100644
index 000000000000..1f15a882ff9d
--- /dev/null
+++ b/stand/efi/acpica/acpi_detect.c
@@ -0,0 +1,69 @@
+/*-
+ * Copyright (c) 2014 Ed Maste <emaste@freebsd.org>
+ * Copyright (c) 2025 Kayla Powell <kpowkitty@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/_inttypes.h>
+#include <efi.h>
+#include <acpi.h>
+#include "acpi_detect.h"
+
+/* For ACPI rsdp discovery. */
+EFI_GUID acpi = ACPI_TABLE_GUID;
+EFI_GUID acpi20 = ACPI_20_TABLE_GUID;
+ACPI_TABLE_RSDP *rsdp;
+
+void
+acpi_detect(void)
+{
+ char buf[24];
+ int revision;
+
+ feature_enable(FEATURE_EARLY_ACPI);
+ if ((rsdp = efi_get_table(&acpi20)) == NULL)
+ if ((rsdp = efi_get_table(&acpi)) == NULL)
+ return;
+
+ sprintf(buf, "0x%016"PRIxPTR, (uintptr_t)rsdp);
+ setenv("acpi.rsdp", buf, 1);
+ revision = rsdp->Revision;
+ if (revision == 0)
+ revision = 1;
+ sprintf(buf, "%d", revision);
+ setenv("acpi.revision", buf, 1);
+ strncpy(buf, rsdp->OemId, sizeof(rsdp->OemId));
+ buf[sizeof(rsdp->OemId)] = '\0';
+ setenv("acpi.oem", buf, 1);
+ sprintf(buf, "0x%016x", rsdp->RsdtPhysicalAddress);
+ setenv("acpi.rsdt", buf, 1);
+ if (revision >= 2) {
+ /* XXX extended checksum? */
+ sprintf(buf, "0x%016llx",
+ (unsigned long long)rsdp->XsdtPhysicalAddress);
+ setenv("acpi.xsdt", buf, 1);
+ sprintf(buf, "%d", rsdp->Length);
+ setenv("acpi.xsdt_length", buf, 1);
+ }
+}
diff --git a/stand/efi/acpica/include/acpi_detect.h b/stand/efi/acpica/include/acpi_detect.h
new file mode 100644
index 000000000000..246e790be9fb
--- /dev/null
+++ b/stand/efi/acpica/include/acpi_detect.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2025 Kayla Powell <kpowkitty@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef ACPI_DETECT_H
+#define ACPI_DETECT_H
+
+#include <efi.h>
+#include <efilib.h>
+
+struct ACPI_TABLE_RSDP; // forward declaration
+
+extern EFI_GUID acpi;
+extern EFI_GUID acpi20;
+extern ACPI_TABLE_RSDP *rsdp;
+
+void acpi_detect(void);
+
+#endif
diff --git a/stand/efi/loader/Makefile b/stand/efi/loader/Makefile
index b30c563d4331..b4520b957b74 100644
--- a/stand/efi/loader/Makefile
+++ b/stand/efi/loader/Makefile
@@ -30,6 +30,10 @@ SRCS= autoload.c \
gfx_fb.c \
8x16.c
+SRCS+= acpi_detect.c
+.PATH: ${EFISRC}/acpica
+CFLAGS+= -I${EFISRC}/acpica/include
+
CFLAGS+= -I${.CURDIR}/../loader
.if ${MK_LOADER_ZFS} != "no"
CFLAGS+= -I${ZFSSRC}
diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c
index 304b2e48272c..2e51f15f0b5f 100644
--- a/stand/efi/loader/main.c
+++ b/stand/efi/loader/main.c
@@ -69,6 +69,8 @@
#include "actypes.h"
#include "actbl.h"
+#include <acpi_detect.h>
+
#include "loader_efi.h"
struct arch_switch archsw = { /* MI/MD interface boundary */
@@ -83,8 +85,6 @@ struct arch_switch archsw = { /* MI/MD interface boundary */
.arch_zfs_probe = efi_zfs_probe,
};
-EFI_GUID acpi = ACPI_TABLE_GUID;
-EFI_GUID acpi20 = ACPI_20_TABLE_GUID;
EFI_GUID devid = DEVICE_PATH_PROTOCOL;
EFI_GUID imgid = LOADED_IMAGE_PROTOCOL;
EFI_GUID mps = MPS_TABLE_GUID;
@@ -120,11 +120,6 @@ UINT16 boot_current;
*/
EFI_LOADED_IMAGE *boot_img;
-/*
- * RSDP base table.
- */
-ACPI_TABLE_RSDP *rsdp;
-
static bool
has_keyboard(void)
{
@@ -1129,39 +1124,6 @@ ptov(uintptr_t x)
return ((caddr_t)x);
}
-static void
-acpi_detect(void)
-{
- char buf[24];
- int revision;
-
- feature_enable(FEATURE_EARLY_ACPI);
- if ((rsdp = efi_get_table(&acpi20)) == NULL)
- if ((rsdp = efi_get_table(&acpi)) == NULL)
- return;
-
- sprintf(buf, "0x%016"PRIxPTR, (uintptr_t)rsdp);
- setenv("acpi.rsdp", buf, 1);
- revision = rsdp->Revision;
- if (revision == 0)
- revision = 1;
- sprintf(buf, "%d", revision);
- setenv("acpi.revision", buf, 1);
- strncpy(buf, rsdp->OemId, sizeof(rsdp->OemId));
- buf[sizeof(rsdp->OemId)] = '\0';
- setenv("acpi.oem", buf, 1);
- sprintf(buf, "0x%016x", rsdp->RsdtPhysicalAddress);
- setenv("acpi.rsdt", buf, 1);
- if (revision >= 2) {
- /* XXX extended checksum? */
- sprintf(buf, "0x%016llx",
- (unsigned long long)rsdp->XsdtPhysicalAddress);
- setenv("acpi.xsdt", buf, 1);
- sprintf(buf, "%d", rsdp->Length);
- setenv("acpi.xsdt_length", buf, 1);
- }
-}
-
static void
efi_smbios_detect(void)
{