Module Name:    src
Committed By:   jmcneill
Date:           Fri Oct 12 22:08:04 UTC 2018

Modified Files:
        src/sys/stand/efiboot: Makefile.efiboot boot.c efiboot.c exec.c
        src/sys/stand/efiboot/bootaa64: Makefile
Added Files:
        src/sys/stand/efiboot: efiacpi.c efiacpi.h

Log Message:
Add ACPI support (enable with -DEFIBOOT_ACPI, currently disabled).

When UEFI reports that ACPI tables are available, generate a DTB with
compatible string "netbsd,generic-acpi" and pass this to the booted
kernel.

The DTB contains a /chosen property "netbsd,acpi-root-table" that contains
the physical address of the ACPI RSDP, along with a special /acpi node
with compatible string "netbsd,acpi" for the kernel to attach an acpi(4)
device driver.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.9 -r1.10 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/efiacpi.c \
    src/sys/stand/efiboot/efiacpi.h
cvs rdiff -u -r1.8 -r1.9 src/sys/stand/efiboot/efiboot.c
cvs rdiff -u -r1.6 -r1.7 src/sys/stand/efiboot/exec.c
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/bootaa64/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/stand/efiboot/Makefile.efiboot
diff -u src/sys/stand/efiboot/Makefile.efiboot:1.5 src/sys/stand/efiboot/Makefile.efiboot:1.6
--- src/sys/stand/efiboot/Makefile.efiboot:1.5	Sat Sep 15 17:06:32 2018
+++ src/sys/stand/efiboot/Makefile.efiboot	Fri Oct 12 22:08:04 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.5 2018/09/15 17:06:32 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.6 2018/10/12 22:08:04 jmcneill Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -22,7 +22,7 @@ AFLAGS.start.S= ${${ACTIVE_CC} == "clang
 .PATH: ${EFIDIR}/gnuefi
 SOURCES=	crt0-efi-${GNUEFIARCH}.S reloc_${GNUEFIARCH}.c
 SOURCES+=	boot.c conf.c console.c dev_net.c devopen.c exec.c panic.c prompt.c
-SOURCES+=	efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c efifile.c efiblock.c efinet.c efipxe.c
+SOURCES+=	efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c efifile.c efiblock.c efinet.c efipxe.c efiacpi.c
 
 .PATH: ${S}/external/bsd/libfdt/dist
 CPPFLAGS+=	-I${S}/external/bsd/libfdt/dist

Index: src/sys/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.9 src/sys/stand/efiboot/boot.c:1.10
--- src/sys/stand/efiboot/boot.c:1.9	Sun Sep  9 18:00:20 2018
+++ src/sys/stand/efiboot/boot.c	Fri Oct 12 22:08:04 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.9 2018/09/09 18:00:20 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.10 2018/10/12 22:08:04 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org>
@@ -30,6 +30,7 @@
 #include "efiboot.h"
 #include "efiblock.h"
 #include "efifdt.h"
+#include "efiacpi.h"
 #include "efienv.h"
 
 #include <sys/bootblock.h>
@@ -210,6 +211,7 @@ command_version(char *arg)
 	}
 
 	efi_fdt_show();
+	efi_acpi_show();
 }
 
 void

Index: src/sys/stand/efiboot/efiboot.c
diff -u src/sys/stand/efiboot/efiboot.c:1.8 src/sys/stand/efiboot/efiboot.c:1.9
--- src/sys/stand/efiboot/efiboot.c:1.8	Sat Sep 15 17:06:32 2018
+++ src/sys/stand/efiboot/efiboot.c	Fri Oct 12 22:08:04 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.8 2018/09/15 17:06:32 jmcneill Exp $ */
+/* $NetBSD: efiboot.c,v 1.9 2018/10/12 22:08:04 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcne...@invisible.ca>
@@ -30,6 +30,7 @@
 #include "efifile.h"
 #include "efiblock.h"
 #include "efifdt.h"
+#include "efiacpi.h"
 
 #include <sys/reboot.h>
 
@@ -79,6 +80,7 @@ efi_main(EFI_HANDLE imageHandle, EFI_SYS
 	Print(L"Image file        : %s\n", DevicePathToStr(efi_li->FilePath));
 #endif
 
+	efi_acpi_probe();
 	efi_fdt_probe();
 	efi_file_system_probe();
 	efi_block_probe();

Index: src/sys/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.6 src/sys/stand/efiboot/exec.c:1.7
--- src/sys/stand/efiboot/exec.c:1.6	Sat Sep 15 17:06:32 2018
+++ src/sys/stand/efiboot/exec.c	Fri Oct 12 22:08:04 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.6 2018/09/15 17:06:32 jmcneill Exp $ */
+/* $NetBSD: exec.c,v 1.7 2018/10/12 22:08:04 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcne...@invisible.ca>
@@ -28,6 +28,7 @@
 
 #include "efiboot.h"
 #include "efifdt.h"
+#include "efiacpi.h"
 
 #include <sys/reboot.h>
 
@@ -152,6 +153,11 @@ exec_netbsd(const char *fname, const cha
 	close(fd);
 	load_offset = 0;
 
+#ifdef EFIBOOT_ACPI
+	if (efi_acpi_available()) {
+		efi_acpi_create_fdt();
+	} else
+#endif
 	if (dtb_addr && efi_fdt_set_data((void *)dtb_addr) != 0) {
 		printf("boot: invalid DTB data\n");
 		goto cleanup;

Index: src/sys/stand/efiboot/bootaa64/Makefile
diff -u src/sys/stand/efiboot/bootaa64/Makefile:1.2 src/sys/stand/efiboot/bootaa64/Makefile:1.3
--- src/sys/stand/efiboot/bootaa64/Makefile:1.2	Mon Aug 27 22:40:51 2018
+++ src/sys/stand/efiboot/bootaa64/Makefile	Fri Oct 12 22:08:04 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2018/08/27 22:40:51 jmcneill Exp $
+# $NetBSD: Makefile,v 1.3 2018/10/12 22:08:04 jmcneill Exp $
 
 PROG=		bootaa64.efi
 OBJFMT=		binary
@@ -9,6 +9,7 @@ EXTRA_SOURCES+=	cache.S
 
 COPTS+=		-mgeneral-regs-only -fno-jump-tables
 CFLAGS+=	-DEFIBOOT_ALIGN=0x200000
+#CFLAGS+=	-DEFIBOOT_ACPI
 
 .include "${.CURDIR}/../Makefile.efiboot"
 

Added files:

Index: src/sys/stand/efiboot/efiacpi.c
diff -u /dev/null src/sys/stand/efiboot/efiacpi.c:1.1
--- /dev/null	Fri Oct 12 22:08:04 2018
+++ src/sys/stand/efiboot/efiacpi.c	Fri Oct 12 22:08:04 2018
@@ -0,0 +1,100 @@
+/* $NetBSD: efiacpi.c,v 1.1 2018/10/12 22:08:04 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared McNeill <jmcne...@invisible.ca>.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "efiboot.h"
+#include "efiacpi.h"
+#include "efifdt.h"
+
+#include <libfdt.h>
+
+#define	ACPI_FDT_SIZE	(64 * 1024)
+
+static EFI_GUID Acpi20TableGuid = ACPI_20_TABLE_GUID;
+
+static void *acpi_root = NULL;
+
+int
+efi_acpi_probe(void)
+{
+	EFI_STATUS status;
+
+	status = LibGetSystemConfigurationTable(&Acpi20TableGuid, &acpi_root);
+	if (EFI_ERROR(status))
+		return EIO;
+
+	return 0;
+}
+
+int
+efi_acpi_available(void)
+{
+	return acpi_root != NULL;
+}
+
+void
+efi_acpi_show(void)
+{
+	if (!efi_acpi_available())
+		return;
+
+	printf("ACPI: RSDP %p\n", acpi_root);
+}
+
+int
+efi_acpi_create_fdt(void)
+{
+	int error;
+	void *fdt;
+
+	if (acpi_root == NULL)
+		return EINVAL;
+
+	fdt = AllocatePool(ACPI_FDT_SIZE);
+	if (fdt == NULL)
+		return ENOMEM;
+
+	error = fdt_create_empty_tree(fdt, ACPI_FDT_SIZE);
+	if (error)
+		return EIO;
+
+	fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "compatible", "netbsd,generic-acpi");
+	fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model", "ACPI");
+	fdt_setprop_cell(fdt, fdt_path_offset(fdt, "/"), "#address-cells", 2);
+	fdt_setprop_cell(fdt, fdt_path_offset(fdt, "/"), "#size-cells", 2);
+
+	fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "chosen");
+	fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,acpi-root-table", (uint64_t)(uintptr_t)acpi_root);
+
+	fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "acpi");
+	fdt_setprop_string(fdt, fdt_path_offset(fdt, "/acpi"), "compatible", "netbsd,acpi");
+
+	return efi_fdt_set_data(fdt);
+}
Index: src/sys/stand/efiboot/efiacpi.h
diff -u /dev/null src/sys/stand/efiboot/efiacpi.h:1.1
--- /dev/null	Fri Oct 12 22:08:04 2018
+++ src/sys/stand/efiboot/efiacpi.h	Fri Oct 12 22:08:04 2018
@@ -0,0 +1,35 @@
+/* $NetBSD: efiacpi.h,v 1.1 2018/10/12 22:08:04 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared McNeill <jmcne...@invisible.ca>.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+int efi_acpi_probe(void);
+void efi_acpi_show(void);
+int efi_acpi_available(void);
+int efi_acpi_create_fdt(void);

Reply via email to