Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Refactor code to split aarch{32,64} kernel page tab...



details:   https://anonhg.NetBSD.org/src/rev/674e6a3664f1
branches:  trunk
changeset: 991887:674e6a3664f1
user:      skrll <skrll%NetBSD.org@localhost>
date:      Sun Aug 05 06:48:50 2018 +0000

description:
Refactor code to split aarch{32,64} kernel page tables and VM setup.  This
will help re-build the kernel page tables on aarch64 with correct section
mappings.

diffstat:

 sys/arch/aarch64/aarch64/aarch64_machdep.c |  41 +++++++++++++++++--
 sys/arch/aarch64/include/machdep.h         |   3 +-
 sys/arch/arm/arm32/arm32_machdep.c         |  62 ++++++++++++++++++++++++++++-
 sys/arch/arm/include/arm32/machdep.h       |   4 +-
 sys/arch/evbarm/fdt/fdt_machdep.c          |  54 ++-----------------------
 5 files changed, 105 insertions(+), 59 deletions(-)

diffs (truncated from 303 to 300 lines):

diff -r c215d427f775 -r 674e6a3664f1 sys/arch/aarch64/aarch64/aarch64_machdep.c
--- a/sys/arch/aarch64/aarch64/aarch64_machdep.c        Sun Aug 05 06:18:05 2018 +0000
+++ b/sys/arch/aarch64/aarch64/aarch64_machdep.c        Sun Aug 05 06:48:50 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: aarch64_machdep.c,v 1.7 2018/07/17 12:40:00 christos Exp $ */
+/* $NetBSD: aarch64_machdep.c,v 1.8 2018/08/05 06:48:50 skrll Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.7 2018/07/17 12:40:00 christos Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.8 2018/08/05 06:48:50 skrll Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_ddb.h"
@@ -60,6 +60,14 @@
 #include <aarch64/pte.h>
 #include <aarch64/vmparam.h>
 
+#include <arch/evbarm/fdt/platform.h>
+
+#ifdef VERBOSE_INIT_ARM
+#define VPRINTF(...)   printf(__VA_ARGS__)
+#else
+#define VPRINTF(...)   do { } while (/* CONSTCOND */ 0)
+#endif
+
 char cpu_model[32];
 char machine[] = MACHINE;
 char machine_arch[] = MACHINE_ARCH;
@@ -85,6 +93,31 @@
 /* filled in before cleaning bss. keep in .data */
 u_long kern_vtopdiff __attribute__((__section__(".data")));
 
+void
+cpu_kernel_vm_init(uint64_t memory_start, uint64_t memory_size)
+{
+
+       extern char __kernel_text[];
+       extern char _end[];
+
+       vaddr_t kernstart = trunc_page((vaddr_t)__kernel_text);
+       vaddr_t kernend = round_page((vaddr_t)_end);
+
+       paddr_t kernstart_phys = KERN_VTOPHYS(kernstart);
+       paddr_t kernend_phys = KERN_VTOPHYS(kernend);
+
+       VPRINTF("%s: kernel phys start %lx end %lx\n", __func__,
+           kernstart_phys, kernend_phys);
+
+        fdt_add_reserved_memory_range(kernstart_phys,
+            kernend_phys - kernstart_phys);
+
+       /*
+        * XXX whole bunch of stuff to map kernel correctly
+        */
+}
+
+
 
 /*
  * Upper region: 0xffff_ffff_ffff_ffff  Top of virtual memory
@@ -143,8 +176,7 @@
        physical_start = bootconfig.dram[0].address;
        physical_end = physical_start + ptoa(bootconfig.dram[0].pages);
 
-#ifdef VERBOSE_INIT_ARM
-       printf(
+       VPRINTF(
            "------------------------------------------\n"
            "kern_vtopdiff         = 0x%016lx\n"
            "physical_start        = 0x%016lx\n"
@@ -171,7 +203,6 @@
            kernend,
            kernend_l2,
            VM_MAX_KERNEL_ADDRESS);
-#endif
 
        /*
         * msgbuf is always allocated from bottom of 1st memory block.
diff -r c215d427f775 -r 674e6a3664f1 sys/arch/aarch64/include/machdep.h
--- a/sys/arch/aarch64/include/machdep.h        Sun Aug 05 06:18:05 2018 +0000
+++ b/sys/arch/aarch64/include/machdep.h        Sun Aug 05 06:48:50 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.h,v 1.3 2018/07/19 18:27:26 christos Exp $     */
+/*     $NetBSD: machdep.h,v 1.4 2018/08/05 06:48:50 skrll Exp $        */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -70,6 +70,7 @@
 #endif
 
 vaddr_t initarm_common(vaddr_t, vsize_t, const struct boot_physmem *, size_t);
+void cpu_kernel_vm_init(paddr_t, psize_t);
 
 void parse_mi_bootargs(char *);
 void dumpsys(void);
diff -r c215d427f775 -r 674e6a3664f1 sys/arch/arm/arm32/arm32_machdep.c
--- a/sys/arch/arm/arm32/arm32_machdep.c        Sun Aug 05 06:18:05 2018 +0000
+++ b/sys/arch/arm/arm32/arm32_machdep.c        Sun Aug 05 06:48:50 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arm32_machdep.c,v 1.116 2018/07/31 07:00:48 skrll Exp $        */
+/*     $NetBSD: arm32_machdep.c,v 1.117 2018/08/05 06:48:50 skrll Exp $        */
 
 /*
  * Copyright (c) 1994-1998 Mark Brinicombe.
@@ -42,9 +42,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: arm32_machdep.c,v 1.116 2018/07/31 07:00:48 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arm32_machdep.c,v 1.117 2018/08/05 06:48:50 skrll Exp $");
 
 #include "opt_arm_debug.h"
+#include "opt_fdt.h"
 #include "opt_modular.h"
 #include "opt_md.h"
 #include "opt_pmap_debug.h"
@@ -81,13 +82,17 @@
 #include <machine/bootconfig.h>
 #include <machine/pcb.h>
 
+#if defined(FDT)
+#include <arm/fdt/arm_fdtvar.h>
+#include <arch/evbarm/fdt/platform.h>
+#endif
+
 #ifdef VERBOSE_INIT_ARM
 #define VPRINTF(...)   printf(__VA_ARGS__)
 #else
 #define VPRINTF(...)   do { } while (/* CONSTCOND */ 0)
 #endif
 
-
 void (*cpu_reset_address)(void);       /* Used by locore */
 paddr_t cpu_reset_address_paddr;       /* Used by locore */
 
@@ -763,3 +768,54 @@
        return true;
 #endif
 }
+
+#if defined(FDT)
+extern char KERNEL_BASE_phys[];
+#define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys)
+
+void
+cpu_kernel_vm_init(paddr_t memory_start, psize_t memory_size)
+{
+       const struct arm_platform *plat = arm_fdt_platform();
+
+#ifdef VERBOSE_INIT_ARM
+       extern char _end[];
+
+       const vaddr_t kernend = round_page((vaddr_t)_end);
+
+       const paddr_t kernstart_phys = KERNEL_BASE_PHYS;
+       const paddr_t kernend_phys = KERN_VTOPHYS(kernend);
+#endif
+
+       VPRINTF("KERNEL_BASE=0x%x, "
+           "KERNEL_VM_BASE=0x%x, "
+           "KERNEL_VM_BASE - KERNEL_BASE=0x%x, "
+           "KERNEL_BASE_VOFFSET=0x%x\n",
+           KERNEL_BASE,
+           KERNEL_VM_BASE,
+           KERNEL_VM_BASE - KERNEL_BASE,
+           KERNEL_BASE_VOFFSET);
+
+       VPRINTF("%s: kernel phys start %lx end %lx\n", __func__,
+           kernstart_phys, kernend_phys);
+
+#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
+       const bool mapallmem_p = true;
+#ifndef PMAP_NEED_ALLOC_POOLPAGE
+       if (memory_size > KERNEL_VM_BASE - KERNEL_BASE) {
+               VPRINTF("%s: dropping RAM size from %luMB to %uMB\n",
+                   __func__, (unsigned long) (memory_size >> 20),
+                   (KERNEL_VM_BASE - KERNEL_BASE) >> 20);
+               memory_size = KERNEL_VM_BASE - KERNEL_BASE;
+       }
+#endif
+#else
+       const bool mapallmem_p = false;
+#endif
+
+       arm32_bootmem_init(memory_start, memory_size, KERNEL_BASE_PHYS);
+       arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0,
+           plat->devmap(), mapallmem_p);
+}
+#endif
+
diff -r c215d427f775 -r 674e6a3664f1 sys/arch/arm/include/arm32/machdep.h
--- a/sys/arch/arm/include/arm32/machdep.h      Sun Aug 05 06:18:05 2018 +0000
+++ b/sys/arch/arm/include/arm32/machdep.h      Sun Aug 05 06:48:50 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.h,v 1.25 2018/08/05 06:18:05 skrll Exp $ */
+/* $NetBSD: machdep.h,v 1.26 2018/08/05 06:48:50 skrll Exp $ */
 
 #ifndef _ARM32_MACHDEP_H_
 #define _ARM32_MACHDEP_H_
@@ -88,6 +88,8 @@
 #define KERN_VTOPHYS(va)       aarch32_kern_vtophys(va)
 #define KERN_PHYSTOV(pa)       aarch32_kern_phystov(pa)
 
+void cpu_kernel_vm_init(paddr_t, psize_t);
+
 void arm32_bootmem_init(paddr_t memstart, psize_t memsize, paddr_t kernelstart);
 void arm32_kernel_vm_init(vaddr_t kvm_base, vaddr_t vectors,
        vaddr_t iovbase /* (can be zero) */,
diff -r c215d427f775 -r 674e6a3664f1 sys/arch/evbarm/fdt/fdt_machdep.c
--- a/sys/arch/evbarm/fdt/fdt_machdep.c Sun Aug 05 06:18:05 2018 +0000
+++ b/sys/arch/evbarm/fdt/fdt_machdep.c Sun Aug 05 06:48:50 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_machdep.c,v 1.30 2018/08/03 13:48:24 skrll Exp $ */
+/* $NetBSD: fdt_machdep.c,v 1.31 2018/08/05 06:48:50 skrll Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.30 2018/08/03 13:48:24 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.31 2018/08/05 06:48:50 skrll Exp $");
 
 #include "opt_machdep.h"
 #include "opt_bootconfig.h"
@@ -419,17 +419,6 @@
        parse_mi_bootargs(mi_bootargs);
 #endif
 
-#ifndef __aarch64__
-       VPRINTF("KERNEL_BASE=0x%x, "
-               "KERNEL_VM_BASE=0x%x, "
-               "KERNEL_VM_BASE - KERNEL_BASE=0x%x, "
-               "KERNEL_BASE_VOFFSET=0x%x\n",
-               KERNEL_BASE,
-               KERNEL_VM_BASE,
-               KERNEL_VM_BASE - KERNEL_BASE,
-               KERNEL_BASE_VOFFSET);
-#endif
-
        fdt_get_memory(&memory_start, &memory_end);
 
 #if !defined(_LP64)
@@ -437,24 +426,8 @@
        if (memory_end >= 0x100000000ULL)
                memory_end = 0x100000000ULL - PAGE_SIZE;
 
+#endif
        uint64_t memory_size = memory_end - memory_start;
-#endif
-
-#ifndef __aarch64__
-#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
-       const bool mapallmem_p = true;
-#ifndef PMAP_NEED_ALLOC_POOLPAGE
-       if (memory_size > KERNEL_VM_BASE - KERNEL_BASE) {
-               VPRINTF("%s: dropping RAM size from %luMB to %uMB\n",
-                   __func__, (unsigned long) (memory_size >> 20),
-                   (KERNEL_VM_BASE - KERNEL_BASE) >> 20);
-               memory_size = KERNEL_VM_BASE - KERNEL_BASE;
-       }
-#endif
-#else
-       const bool mapallmem_p = false;
-#endif
-#endif
 
        /* Parse ramdisk info */
        fdt_probe_initrd(&initrd_start, &initrd_end);
@@ -465,25 +438,8 @@
         */
        fdt_build_bootconfig(memory_start, memory_end);
 
-#ifdef __aarch64__
-       extern char __kernel_text[];
-       extern char _end[];
-
-       vaddr_t kernstart = trunc_page((vaddr_t)__kernel_text);
-       vaddr_t kernend = round_page((vaddr_t)_end);
-
-       paddr_t kernstart_phys = KERN_VTOPHYS(kernstart);
-       paddr_t kernend_phys = KERN_VTOPHYS(kernend);
-
-       VPRINTF("%s: kernel phys start %lx end %lx\n", __func__, kernstart_phys, kernend_phys);
-
-        fdt_add_reserved_memory_range(kernstart_phys,
-            kernend_phys - kernstart_phys);
-#else
-       arm32_bootmem_init(memory_start, memory_size, KERNEL_BASE_PHYS);
-       arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0,
-           plat->devmap(), mapallmem_p);
-#endif
+       /* Perform PT build and VM init */
+       cpu_kernel_vm_init(memory_start, memory_size);



Home | Main Index | Thread Index | Old Index