Module Name:    src
Committed By:   jmcneill
Date:           Sat Oct 10 19:17:39 UTC 2020

Modified Files:
        src/sys/stand/efiboot: efiacpi.c efifdt.c efifdt.h exec.c version

Log Message:
Support EFI runtime and GOP FB for devicetree (non-ACPI) setups.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/stand/efiboot/efiacpi.c
cvs rdiff -u -r1.24 -r1.25 src/sys/stand/efiboot/efifdt.c
cvs rdiff -u -r1.9 -r1.10 src/sys/stand/efiboot/efifdt.h
cvs rdiff -u -r1.18 -r1.19 src/sys/stand/efiboot/exec.c
cvs rdiff -u -r1.19 -r1.20 src/sys/stand/efiboot/version

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/efiacpi.c
diff -u src/sys/stand/efiboot/efiacpi.c:1.7 src/sys/stand/efiboot/efiacpi.c:1.8
--- src/sys/stand/efiboot/efiacpi.c:1.7	Thu May 14 19:19:08 2020
+++ src/sys/stand/efiboot/efiacpi.c	Sat Oct 10 19:17:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efiacpi.c,v 1.7 2020/05/14 19:19:08 riastradh Exp $ */
+/* $NetBSD: efiacpi.c,v 1.8 2020/10/10 19:17:39 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -155,9 +155,6 @@ efi_acpi_create_fdt(void)
 	fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,acpi-root-table", (uint64_t)(uintptr_t)acpi_root);
 	if (smbios3_table)
 		fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,smbios-table", (uint64_t)(uintptr_t)smbios3_table);
-#ifdef EFIBOOT_RUNTIME_ADDRESS
-	fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-system-table", (uint64_t)(uintptr_t)ST);
-#endif
 
 	fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "acpi");
 	fdt_setprop_string(fdt, fdt_path_offset(fdt, "/acpi"), "compatible", "netbsd,acpi");

Index: src/sys/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.24 src/sys/stand/efiboot/efifdt.c:1.25
--- src/sys/stand/efiboot/efifdt.c:1.24	Sun Jun 21 17:24:26 2020
+++ src/sys/stand/efiboot/efifdt.c	Sat Oct 10 19:17:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.24 2020/06/21 17:24:26 jmcneill Exp $ */
+/* $NetBSD: efifdt.c,v 1.25 2020/10/10 19:17:39 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -30,6 +30,7 @@
 #include "efiboot.h"
 #include "efifdt.h"
 #include "efiblock.h"
+#include "efiacpi.h"
 
 #include <libfdt.h>
 
@@ -55,6 +56,7 @@ static EFI_GUID FdtTableGuid = FDT_TABLE
 #define PRIxUINTN "x"
 #endif
 static void *fdt_data = NULL;
+static size_t fdt_data_size = 512*1024;
 
 int
 efi_fdt_probe(void)
@@ -76,10 +78,23 @@ efi_fdt_probe(void)
 int
 efi_fdt_set_data(void *data)
 {
+	int err;
+
 	if (fdt_check_header(data) != 0)
 		return EINVAL;
 
-	fdt_data = data;
+	fdt_data = alloc(fdt_data_size);
+	if (fdt_data == NULL)
+		return ENOMEM;
+	memset(fdt_data, 0, fdt_data_size);
+
+	err = fdt_open_into(data, fdt_data, fdt_data_size);
+	if (err != 0) {
+		dealloc(fdt_data, fdt_data_size);
+		fdt_data = NULL;
+		return ENXIO;
+	}
+
 	return 0;
 }
 
@@ -202,6 +217,18 @@ efi_fdt_chosen(void)
 }
 
 void
+efi_fdt_system_table(void)
+{
+#ifdef EFIBOOT_RUNTIME_ADDRESS
+	int chosen;
+
+	chosen = efi_fdt_chosen();
+
+	fdt_setprop_u64(fdt_data, chosen, "netbsd,uefi-system-table", (uint64_t)(uintptr_t)ST);
+#endif
+}
+
+void
 efi_fdt_memory_map(void)
 {
 	UINTN nentries = 0, mapkey, descsize;
@@ -278,7 +305,7 @@ efi_fdt_gop(void)
 	EFI_HANDLE *gop_handle;
 	UINTN ngop_handle, n;
 	char buf[48];
-	int fb;
+	int fb, chosen;
 
 	status = LibLocateHandle(ByProtocol, &GraphicsOutputProtocol, NULL, &ngop_handle, &gop_handle);
 	if (EFI_ERROR(status) || ngop_handle == 0)
@@ -311,15 +338,13 @@ efi_fdt_gop(void)
 			continue;
 		}
 
-		fdt_setprop_u32(fdt_data,
-		    fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "#address-cells", 2);
-		fdt_setprop_u32(fdt_data,
-		    fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "#size-cells", 2);
-		fdt_setprop_empty(fdt_data,
-		    fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "ranges");
+		chosen = efi_fdt_chosen();
+		fdt_setprop_u32(fdt_data, chosen, "#address-cells", 2);
+		fdt_setprop_u32(fdt_data, chosen, "#size-cells", 2);
+		fdt_setprop_empty(fdt_data, chosen, "ranges");
 
 		snprintf(buf, sizeof(buf), "framebuffer@%" PRIx64, mode->FrameBufferBase);
-		fb = fdt_add_subnode(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), buf);
+		fb = fdt_add_subnode(fdt_data, chosen, buf);
 		if (fb < 0)
 			panic("FDT: Failed to create framebuffer node");
 
@@ -332,9 +357,13 @@ efi_fdt_gop(void)
 		fdt_appendprop_u32(fdt_data, fb, "stride", mode->Info->PixelsPerScanLine * 4);	/* XXX */
 		fdt_appendprop_string(fdt_data, fb, "format", "a8b8g8r8");
 
-		snprintf(buf, sizeof(buf), "/chosen/framebuffer@%" PRIx64, mode->FrameBufferBase);
-		fdt_setprop_string(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH),
-		    "stdout-path", buf);
+		/*
+		 * In ACPI mode, use GOP as console.
+		 */
+		if (efi_acpi_available()) {
+			snprintf(buf, sizeof(buf), "/chosen/framebuffer@%" PRIx64, mode->FrameBufferBase);
+			fdt_setprop_string(fdt_data, chosen, "stdout-path", buf);
+		}
 
 		return;
 	}

Index: src/sys/stand/efiboot/efifdt.h
diff -u src/sys/stand/efiboot/efifdt.h:1.9 src/sys/stand/efiboot/efifdt.h:1.10
--- src/sys/stand/efiboot/efifdt.h:1.9	Sun Jun 21 17:24:26 2020
+++ src/sys/stand/efiboot/efifdt.h	Sat Oct 10 19:17:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.h,v 1.9 2020/06/21 17:24:26 jmcneill Exp $ */
+/* $NetBSD: efifdt.h,v 1.10 2020/10/10 19:17:39 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <[email protected]>
@@ -42,3 +42,4 @@ void efi_fdt_efirng(u_long, u_long);
 void efi_fdt_module(const char *, u_long, u_long);
 void efi_fdt_init(u_long, u_long);
 void efi_fdt_fini(void);
+void efi_fdt_system_table(void);

Index: src/sys/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.18 src/sys/stand/efiboot/exec.c:1.19
--- src/sys/stand/efiboot/exec.c:1.18	Sun Jun 28 11:39:50 2020
+++ src/sys/stand/efiboot/exec.c	Sat Oct 10 19:17:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.18 2020/06/28 11:39:50 jmcneill Exp $ */
+/* $NetBSD: exec.c,v 1.19 2020/10/10 19:17:39 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -315,10 +315,8 @@ exec_netbsd(const char *fname, const cha
 		efi_fdt_rndseed(rndseed_addr, rndseed_size);
 		efi_fdt_efirng(efirng_addr, efirng_size);
 		efi_fdt_bootargs(args);
-#ifdef EFIBOOT_ACPI
-		if (efi_acpi_available())
-			efi_fdt_gop();
-#endif
+		efi_fdt_system_table();
+		efi_fdt_gop();
 		efi_fdt_memory_map();
 	}
 

Index: src/sys/stand/efiboot/version
diff -u src/sys/stand/efiboot/version:1.19 src/sys/stand/efiboot/version:1.20
--- src/sys/stand/efiboot/version:1.19	Sun Jun 28 11:39:50 2020
+++ src/sys/stand/efiboot/version	Sat Oct 10 19:17:39 2020
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.19 2020/06/28 11:39:50 jmcneill Exp $
+$NetBSD: version,v 1.20 2020/10/10 19:17:39 jmcneill Exp $
 
 NOTE ANY CHANGES YOU MAKE TO THE EFI BOOTLOADER HERE.  The format of this
 file is important - make sure the entries are appended on end, last item
@@ -23,3 +23,4 @@ is taken as the current.
 2.0:	Add boot.cfg support.
 2.1:	Remove efiboot.plist support; support dtoverlay in boot.cfg.
 2.2:	Remove support for storing settings in EFI env vars.
+2.3:	EFI RT and GOP support for devicetree mode.

Reply via email to