Module Name:    src
Committed By:   martin
Date:           Sun Aug  4 11:37:56 UTC 2019

Modified Files:
        src/sys/arch/arm/acpi [netbsd-9]: acpi_machdep.c
        src/sys/stand/efiboot [netbsd-9]: efiacpi.c efifdt.c version

Log Message:
Pull up following revision(s) (requested by jmcneill in ticket #3):

        sys/stand/efiboot/efiacpi.c: revision 1.4
        sys/stand/efiboot/efifdt.c: revision 1.18
        sys/stand/efiboot/version: revision 1.12
        sys/arch/arm/acpi/acpi_machdep.c: revision 1.7
        sys/arch/arm/acpi/acpi_machdep.c: revision 1.8

Add full UEFI memory map to the /chosen node.

 -

acpi_md_OsMapMemory can be used for both normal and device memory. Use the
UEFI memory map to determine how to map a given region.

Always map ACPI table memory as normal memory. Always map device memory as 
device memory.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.6.6.1 src/sys/arch/arm/acpi/acpi_machdep.c
cvs rdiff -u -r1.3 -r1.3.6.1 src/sys/stand/efiboot/efiacpi.c
cvs rdiff -u -r1.17 -r1.17.2.1 src/sys/stand/efiboot/efifdt.c
cvs rdiff -u -r1.11 -r1.11.2.1 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/arch/arm/acpi/acpi_machdep.c
diff -u src/sys/arch/arm/acpi/acpi_machdep.c:1.6 src/sys/arch/arm/acpi/acpi_machdep.c:1.6.6.1
--- src/sys/arch/arm/acpi/acpi_machdep.c:1.6	Fri Nov 16 23:03:55 2018
+++ src/sys/arch/arm/acpi/acpi_machdep.c	Sun Aug  4 11:37:56 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_machdep.c,v 1.6 2018/11/16 23:03:55 jmcneill Exp $ */
+/* $NetBSD: acpi_machdep.c,v 1.6.6.1 2019/08/04 11:37:56 martin Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include "pci.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.6 2018/11/16 23:03:55 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.6.6.1 2019/08/04 11:37:56 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -50,6 +50,8 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_machdep
 #include <dev/acpi/acpi_mcfg.h>
 #endif
 
+#include <arm/arm/efi_runtime.h>
+
 #include <arm/pic/picvar.h>
 
 #include <arm/locore.h>
@@ -58,6 +60,55 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_machdep
 
 extern struct bus_space arm_generic_bs_tag;
 
+static int
+acpi_md_pmapflags(paddr_t pa)
+{
+	int len;
+
+	const int chosen = OF_finddevice("/chosen");
+	if (chosen == -1)
+		return 0;
+
+	const uint32_t *map = fdtbus_get_prop(chosen, "netbsd,uefi-memmap", &len);
+	if (map == NULL)
+		return 0;
+
+	while (len >= 28) {
+		const uint32_t type = be32dec(&map[0]);
+		const uint64_t phys_start = be64dec(&map[1]);
+		const uint64_t num_pages = be64dec(&map[3]);
+		const uint64_t attr = be64dec(&map[5]);
+
+		if (pa >= phys_start && pa < phys_start + (num_pages * EFI_PAGE_SIZE)) {
+			switch (type) {
+			case EFI_MD_TYPE_RECLAIM:
+				/* ACPI table memory */
+				return PMAP_WRITE_BACK;
+
+			case EFI_MD_TYPE_IOMEM:
+			case EFI_MD_TYPE_IOPORT:
+				return PMAP_DEV;
+
+			default:
+				if ((attr & EFI_MD_ATTR_WB) != 0)
+					return PMAP_WRITE_BACK;
+				else if ((attr & EFI_MD_ATTR_WC) != 0)
+					return PMAP_WRITE_COMBINE;
+				else if ((attr & EFI_MD_ATTR_WT) != 0)
+					return 0;	/* XXX */
+
+				return PMAP_DEV;
+			}
+		}
+
+		map += 7;
+		len -= 28;
+	}
+
+	/* Not found; assume device memory */
+	return PMAP_DEV;
+}
+
 ACPI_STATUS
 acpi_md_OsInitialize(void)
 {
@@ -105,8 +156,12 @@ acpi_md_OsMapMemory(ACPI_PHYSICAL_ADDRES
 	if (va == 0)
 		return AE_NO_MEMORY;
 
+	const int pmapflags = acpi_md_pmapflags(spa);
+
+	aprint_debug("%s: 0x%lx 0x%x flags = %#x\n", __func__, pa, size, pmapflags);
+
 	for (curpa = spa, curva = va; curpa < epa; curpa += PAGE_SIZE, curva += PAGE_SIZE)
-		pmap_kenter_pa(curva, curpa, VM_PROT_READ | VM_PROT_WRITE, 0);
+		pmap_kenter_pa(curva, curpa, VM_PROT_READ | VM_PROT_WRITE, pmapflags);
 	pmap_update(pmap_kernel());
 
 	*vap = (void *)(va + (pa - spa));

Index: src/sys/stand/efiboot/efiacpi.c
diff -u src/sys/stand/efiboot/efiacpi.c:1.3 src/sys/stand/efiboot/efiacpi.c:1.3.6.1
--- src/sys/stand/efiboot/efiacpi.c:1.3	Sun Oct 28 10:17:47 2018
+++ src/sys/stand/efiboot/efiacpi.c	Sun Aug  4 11:37:56 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: efiacpi.c,v 1.3 2018/10/28 10:17:47 jmcneill Exp $ */
+/* $NetBSD: efiacpi.c,v 1.3.6.1 2019/08/04 11:37:56 martin Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <libfdt.h>
 
-#define	ACPI_FDT_SIZE	(64 * 1024)
+#define	ACPI_FDT_SIZE	(128 * 1024)
 
 static EFI_GUID Acpi20TableGuid = ACPI_20_TABLE_GUID;
 static EFI_GUID Smbios3TableGuid = SMBIOS3_TABLE_GUID;

Index: src/sys/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.17 src/sys/stand/efiboot/efifdt.c:1.17.2.1
--- src/sys/stand/efiboot/efifdt.c:1.17	Thu Jul 25 11:44:14 2019
+++ src/sys/stand/efiboot/efifdt.c	Sun Aug  4 11:37:56 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.17 2019/07/25 11:44:14 skrll Exp $ */
+/* $NetBSD: efifdt.c,v 1.17.2.1 2019/08/04 11:37:56 martin Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -206,14 +206,14 @@ efi_fdt_memory_map(void)
 
 	memmap = LibMemoryMap(&nentries, &mapkey, &descsize, &descver);
 	for (n = 0, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
+		fdt_appendprop_u32(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->Type);
+		fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->PhysicalStart);
+		fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->NumberOfPages);
+		fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->Attribute);
+
 		if ((md->Attribute & EFI_MEMORY_RUNTIME) != 0)
 			continue;
 
-		fdt_appendprop_u32(fdt_data, chosen, "netbsd,uefi-memory-map", md->Type);
-		fdt_appendprop_u64(fdt_data, chosen, "netbsd,uefi-memory-map", md->PhysicalStart);
-		fdt_appendprop_u64(fdt_data, chosen, "netbsd,uefi-memory-map", md->NumberOfPages);
-		fdt_appendprop_u64(fdt_data, chosen, "netbsd,uefi-memory-map", md->Attribute);
-
 		if ((md->Attribute & EFI_MEMORY_WB) == 0)
 			continue;
 		if (!FDT_MEMORY_USABLE(md))

Index: src/sys/stand/efiboot/version
diff -u src/sys/stand/efiboot/version:1.11 src/sys/stand/efiboot/version:1.11.2.1
--- src/sys/stand/efiboot/version:1.11	Wed Jul 24 11:40:36 2019
+++ src/sys/stand/efiboot/version	Sun Aug  4 11:37:56 2019
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.11 2019/07/24 11:40:36 jmcneill Exp $
+$NetBSD: version,v 1.11.2.1 2019/08/04 11:37:56 martin 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
@@ -15,3 +15,4 @@ is taken as the current.
 1.8:	Add support for "bootargs" environment variable.
 1.9:	Add support for efiboot.plist and loading device tree overlays.
 1.10:	Add support for EFI GOP framebuffers in ACPI mode.
+1.11:	Add full UEFI memory map to /chosen node.

Reply via email to