Source-Changes-HG archive

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

[src/trunk]: src/sys/stand/efiboot Make EFI runtime services available to the...



details:   https://anonhg.NetBSD.org/src/rev/5399f151e74e
branches:  trunk
changeset: 445413:5399f151e74e
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Oct 28 10:17:47 2018 +0000

description:
Make EFI runtime services available to the kernel. Bump version to 1.5.

diffstat:

 sys/stand/efiboot/bootaa64/Makefile |   4 +-
 sys/stand/efiboot/efiacpi.c         |   5 +-
 sys/stand/efiboot/efiboot.c         |  84 +++++++++++++++++++++++++++++++++++-
 sys/stand/efiboot/exec.c            |   8 ++-
 sys/stand/efiboot/version           |   3 +-
 5 files changed, 95 insertions(+), 9 deletions(-)

diffs (198 lines):

diff -r 58257a42f413 -r 5399f151e74e sys/stand/efiboot/bootaa64/Makefile
--- a/sys/stand/efiboot/bootaa64/Makefile       Sun Oct 28 00:44:37 2018 +0000
+++ b/sys/stand/efiboot/bootaa64/Makefile       Sun Oct 28 10:17:47 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.4 2018/10/21 00:57:38 jmcneill Exp $
+# $NetBSD: Makefile,v 1.5 2018/10/28 10:17:47 jmcneill Exp $
 
 PROG=          bootaa64.efi
 OBJFMT=                binary
@@ -9,6 +9,8 @@
 
 COPTS+=                -mgeneral-regs-only -fno-jump-tables
 CFLAGS+=       -DEFIBOOT_ALIGN=0x200000
+CFLAGS+=       -DEFIBOOT_RUNTIME_ADDRESS=0xffff800000000000L
+CFLAGS+=       -DEFIBOOT_RUNTIME_SIZE=0x40000000UL
 CFLAGS+=       -DEFIBOOT_ACPI
 
 .include "${.CURDIR}/../Makefile.efiboot"
diff -r 58257a42f413 -r 5399f151e74e sys/stand/efiboot/efiacpi.c
--- a/sys/stand/efiboot/efiacpi.c       Sun Oct 28 00:44:37 2018 +0000
+++ b/sys/stand/efiboot/efiacpi.c       Sun Oct 28 10:17:47 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: efiacpi.c,v 1.2 2018/10/23 10:12:59 jmcneill Exp $ */
+/* $NetBSD: efiacpi.c,v 1.3 2018/10/28 10:17:47 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -103,6 +103,9 @@
        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");
diff -r 58257a42f413 -r 5399f151e74e sys/stand/efiboot/efiboot.c
--- a/sys/stand/efiboot/efiboot.c       Sun Oct 28 00:44:37 2018 +0000
+++ b/sys/stand/efiboot/efiboot.c       Sun Oct 28 10:17:47 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.9 2018/10/12 22:08:04 jmcneill Exp $ */
+/* $NetBSD: efiboot.c,v 1.10 2018/10/28 10:17:47 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -34,6 +34,8 @@
 
 #include <sys/reboot.h>
 
+#include <libfdt.h>
+
 EFI_HANDLE IH;
 EFI_DEVICE_PATH *efi_bootdp;
 EFI_LOADED_IMAGE *efi_li;
@@ -41,7 +43,7 @@
 int howto = 0;
 
 static EFI_PHYSICAL_ADDRESS heap_start;
-static UINTN heap_size = 1 * 1024 * 1024;
+static UINTN heap_size = 8 * 1024 * 1024;
 static EFI_EVENT delay_ev = 0;
 
 EFI_STATUS EFIAPI efi_main(EFI_HANDLE, EFI_SYSTEM_TABLE *);
@@ -92,18 +94,92 @@
        return EFI_SUCCESS;
 }
 
+#ifdef EFIBOOT_RUNTIME_ADDRESS
+static uint64_t
+efi_runtime_alloc_va(uint64_t npages)
+{
+       static uint64_t va = EFIBOOT_RUNTIME_ADDRESS;
+       static uint64_t sz = EFIBOOT_RUNTIME_SIZE;
+       uint64_t nva;
+
+       if (sz < (npages * EFI_PAGE_SIZE))
+               panic("efi_acpi_alloc_va: couldn't allocate %" PRIu64 " pages", npages);
+
+       nva = va;
+       va += (npages * EFI_PAGE_SIZE);
+       sz -= (npages * EFI_PAGE_SIZE);
+
+       return nva;
+}
+#endif
+
+#ifdef EFIBOOT_RUNTIME_ADDRESS
+static void
+efi_set_virtual_address_map(EFI_MEMORY_DESCRIPTOR *memmap, UINTN nentries, UINTN mapkey, UINTN descsize, UINT32 descver)
+{
+       EFI_MEMORY_DESCRIPTOR *md, *vmd, *vmemmap;
+       EFI_STATUS status;
+       int n, nrt;
+       void *fdt;
+
+       fdt = efi_fdt_data();
+
+       vmemmap = alloc(nentries * descsize);
+       if (vmemmap == NULL)
+               panic("FATAL: couldn't allocate virtual memory map");
+
+       for (n = 0, nrt = 0, vmd = vmemmap, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
+               if ((md->Attribute & EFI_MEMORY_RUNTIME) == 0)
+                       continue;
+               md->VirtualStart = efi_runtime_alloc_va(md->NumberOfPages);
+
+               switch (md->Type) {
+               case EfiRuntimeServicesCode:
+                       fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-code", md->PhysicalStart);
+                       fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-code", md->VirtualStart);
+                       fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-code", md->NumberOfPages * EFI_PAGE_SIZE);
+                       break;
+               case EfiRuntimeServicesData:
+                       fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-data", md->PhysicalStart);
+                       fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-data", md->VirtualStart);
+                       fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-data", md->NumberOfPages * EFI_PAGE_SIZE);
+                       break;
+               default:
+                       break;
+               }
+
+               *vmd = *md;
+               vmd = NextMemoryDescriptor(vmd, descsize);
+               ++nrt;
+       }
+
+       status = uefi_call_wrapper(RT->SetVirtualAddressMap, 4, nrt * descsize, descsize, descver, vmemmap);
+       if (EFI_ERROR(status)) {
+               printf("WARNING: SetVirtualAddressMap failed\n");
+               return;
+       }
+}
+#endif
+
 void
 efi_cleanup(void)
 {
        EFI_STATUS status;
+       EFI_MEMORY_DESCRIPTOR *memmap;
        UINTN nentries, mapkey, descsize;
        UINT32 descver;
 
-       LibMemoryMap(&nentries, &mapkey, &descsize, &descver);
+       memmap = LibMemoryMap(&nentries, &mapkey, &descsize, &descver);
 
        status = uefi_call_wrapper(BS->ExitBootServices, 2, IH, mapkey);
-       if (EFI_ERROR(status))
+       if (EFI_ERROR(status)) {
                printf("WARNING: ExitBootServices failed\n");
+               return;
+       }
+
+#ifdef EFIBOOT_RUNTIME_ADDRESS
+       efi_set_virtual_address_map(memmap, nentries, mapkey, descsize, descver);
+#endif
 }
 
 void
diff -r 58257a42f413 -r 5399f151e74e sys/stand/efiboot/exec.c
--- a/sys/stand/efiboot/exec.c  Sun Oct 28 00:44:37 2018 +0000
+++ b/sys/stand/efiboot/exec.c  Sun Oct 28 10:17:47 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.7 2018/10/12 22:08:04 jmcneill Exp $ */
+/* $NetBSD: exec.c,v 1.8 2018/10/28 10:17:47 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -168,10 +168,14 @@
                efi_fdt_initrd(initrd_addr, initrd_size);
                efi_fdt_bootargs(args);
                efi_fdt_memory_map();
+       }
+
+       efi_cleanup();
+
+       if (efi_fdt_size() > 0) {
                efi_fdt_fini();
        }
 
-       efi_cleanup();
        efi_boot_kernel(marks);
 
        /* This should not happen.. */
diff -r 58257a42f413 -r 5399f151e74e sys/stand/efiboot/version
--- a/sys/stand/efiboot/version Sun Oct 28 00:44:37 2018 +0000
+++ b/sys/stand/efiboot/version Sun Oct 28 10:17:47 2018 +0000
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.5 2018/10/26 20:56:35 mrg Exp $
+$NetBSD: version,v 1.6 2018/10/28 10:17:47 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
@@ -9,3 +9,4 @@
 1.2:   Add environment variable support.
 1.3:   Add ACPI support.
 1.4:   Add bootfile support.
+1.5:   EFI runtime support.



Home | Main Index | Thread Index | Old Index