Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/stand/efiboot Add ACPI support (enable with -DEFIBOOT_AC...



details:   https://anonhg.NetBSD.org/src/rev/bbe12b05db63
branches:  trunk
changeset: 836338:bbe12b05db63
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Fri Oct 12 22:08:04 2018 +0000

description:
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.

diffstat:

 sys/stand/efiboot/Makefile.efiboot  |    4 +-
 sys/stand/efiboot/boot.c            |    4 +-
 sys/stand/efiboot/bootaa64/Makefile |    3 +-
 sys/stand/efiboot/efiacpi.c         |  100 ++++++++++++++++++++++++++++++++++++
 sys/stand/efiboot/efiacpi.h         |   35 ++++++++++++
 sys/stand/efiboot/efiboot.c         |    4 +-
 sys/stand/efiboot/exec.c            |    8 ++-
 7 files changed, 152 insertions(+), 6 deletions(-)

diffs (257 lines):

diff -r d909317c8780 -r bbe12b05db63 sys/stand/efiboot/Makefile.efiboot
--- a/sys/stand/efiboot/Makefile.efiboot        Fri Oct 12 21:46:32 2018 +0000
+++ b/sys/stand/efiboot/Makefile.efiboot        Fri Oct 12 22:08:04 2018 +0000
@@ -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 @@
 .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
diff -r d909317c8780 -r bbe12b05db63 sys/stand/efiboot/boot.c
--- a/sys/stand/efiboot/boot.c  Fri Oct 12 21:46:32 2018 +0000
+++ b/sys/stand/efiboot/boot.c  Fri Oct 12 22:08:04 2018 +0000
@@ -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 <nonaka%netbsd.org@localhost>
@@ -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 @@
        }
 
        efi_fdt_show();
+       efi_acpi_show();
 }
 
 void
diff -r d909317c8780 -r bbe12b05db63 sys/stand/efiboot/bootaa64/Makefile
--- a/sys/stand/efiboot/bootaa64/Makefile       Fri Oct 12 21:46:32 2018 +0000
+++ b/sys/stand/efiboot/bootaa64/Makefile       Fri Oct 12 22:08:04 2018 +0000
@@ -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 @@
 
 COPTS+=                -mgeneral-regs-only -fno-jump-tables
 CFLAGS+=       -DEFIBOOT_ALIGN=0x200000
+#CFLAGS+=      -DEFIBOOT_ACPI
 
 .include "${.CURDIR}/../Makefile.efiboot"
 
diff -r d909317c8780 -r bbe12b05db63 sys/stand/efiboot/efiacpi.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/stand/efiboot/efiacpi.c       Fri Oct 12 22:08:04 2018 +0000
@@ -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 <jmcneill%invisible.ca@localhost>.
+ *
+ * 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);
+}
diff -r d909317c8780 -r bbe12b05db63 sys/stand/efiboot/efiacpi.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/stand/efiboot/efiacpi.h       Fri Oct 12 22:08:04 2018 +0000
@@ -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 <jmcneill%invisible.ca@localhost>.
+ *
+ * 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);
diff -r d909317c8780 -r bbe12b05db63 sys/stand/efiboot/efiboot.c
--- a/sys/stand/efiboot/efiboot.c       Fri Oct 12 21:46:32 2018 +0000
+++ b/sys/stand/efiboot/efiboot.c       Fri Oct 12 22:08:04 2018 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -30,6 +30,7 @@
 #include "efifile.h"
 #include "efiblock.h"
 #include "efifdt.h"
+#include "efiacpi.h"
 
 #include <sys/reboot.h>
 
@@ -79,6 +80,7 @@
        Print(L"Image file        : %s\n", DevicePathToStr(efi_li->FilePath));
 #endif
 
+       efi_acpi_probe();
        efi_fdt_probe();
        efi_file_system_probe();
        efi_block_probe();
diff -r d909317c8780 -r bbe12b05db63 sys/stand/efiboot/exec.c
--- a/sys/stand/efiboot/exec.c  Fri Oct 12 21:46:32 2018 +0000
+++ b/sys/stand/efiboot/exec.c  Fri Oct 12 22:08:04 2018 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -28,6 +28,7 @@
 
 #include "efiboot.h"
 #include "efifdt.h"
+#include "efiacpi.h"
 
 #include <sys/reboot.h>
 
@@ -152,6 +153,11 @@
        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;



Home | Main Index | Thread Index | Old Index