Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm/acpi acpi_md_OsMapMemory can be used for both n...



details:   https://anonhg.NetBSD.org/src/rev/a72764916c7c
branches:  trunk
changeset: 462940:a72764916c7c
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Thu Aug 01 13:13:51 2019 +0000

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

diffstat:

 sys/arch/arm/acpi/acpi_machdep.c |  51 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 48 insertions(+), 3 deletions(-)

diffs (87 lines):

diff -r 0afe1155ce6a -r a72764916c7c sys/arch/arm/acpi/acpi_machdep.c
--- a/sys/arch/arm/acpi/acpi_machdep.c  Thu Aug 01 13:11:16 2019 +0000
+++ b/sys/arch/arm/acpi/acpi_machdep.c  Thu Aug 01 13:13:51 2019 +0000
@@ -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.7 2019/08/01 13:13:51 jmcneill 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.7 2019/08/01 13:13:51 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -50,6 +50,8 @@
 #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,45 @@
 
 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 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)) {
+                       if ((attr & EFI_MD_ATTR_UC) != 0)
+                               return PMAP_DEV;        /* Not cacheable means Device-nGnRnE */
+                       else if ((attr & EFI_MD_ATTR_WC) != 0)
+                               return PMAP_WRITE_COMBINE;
+                       else if ((attr & EFI_MD_ATTR_WT) != 0)
+                               return 0;       /* XXX */
+                       else if ((attr & EFI_MD_ATTR_WB) != 0)
+                               return PMAP_WRITE_BACK;
+                       else
+                               return PMAP_DEV;
+               }
+
+               map += 7;
+               len -= 28;
+       }
+
+       /* Not found; assume device memory */
+       return PMAP_DEV;
+}
+
 ACPI_STATUS
 acpi_md_OsInitialize(void)
 {
@@ -105,8 +146,12 @@
        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));



Home | Main Index | Thread Index | Old Index