Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/aarch64 replace KSEG pages mapping code with generi...



details:   https://anonhg.NetBSD.org/src/rev/3e12662c49c6
branches:  trunk
changeset: 969750:3e12662c49c6
user:      ryo <ryo%NetBSD.org@localhost>
date:      Sat Feb 29 21:09:11 2020 +0000

description:
replace KSEG pages mapping code with generic function pmapboot_enter_range()

diffstat:

 sys/arch/aarch64/aarch64/aarch64_machdep.c |  75 ++------------------------
 sys/arch/aarch64/aarch64/pmapboot.c        |  84 +++++++++++++++++++++++++++++-
 sys/arch/aarch64/include/pmap.h            |   4 +-
 3 files changed, 91 insertions(+), 72 deletions(-)

diffs (220 lines):

diff -r 40aeeb9868d8 -r 3e12662c49c6 sys/arch/aarch64/aarch64/aarch64_machdep.c
--- a/sys/arch/aarch64/aarch64/aarch64_machdep.c        Sat Feb 29 20:44:15 2020 +0000
+++ b/sys/arch/aarch64/aarch64/aarch64_machdep.c        Sat Feb 29 21:09:11 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: aarch64_machdep.c,v 1.38 2020/01/22 17:15:53 skrll Exp $ */
+/* $NetBSD: aarch64_machdep.c,v 1.39 2020/02/29 21:09:11 ryo 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.38 2020/01/22 17:15:53 skrll Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.39 2020/02/29 21:09:11 ryo Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_ddb.h"
@@ -134,77 +134,14 @@
            LX_BLKPAG_PXN |
            LX_BLKPAG_UXN;
        for (blk = 0; blk < bootconfig.dramblocks; blk++) {
-               uint64_t start, end, left, mapsize, nblocks;
+               uint64_t start, end;
 
                start = trunc_page(bootconfig.dram[blk].address);
                end = round_page(bootconfig.dram[blk].address +
                    (uint64_t)bootconfig.dram[blk].pages * PAGE_SIZE);
-               left = end - start;
-
-               /* align the start address to L2 blocksize */
-               nblocks = ulmin(left / L3_SIZE,
-                   Ln_ENTRIES - __SHIFTOUT(start, L3_ADDR_BITS));
-               if (((start & L3_ADDR_BITS) != 0) && (nblocks > 0)) {
-                       mapsize = nblocks * L3_SIZE;
-                       VPRINTF("Creating KSEG tables for %016lx-%016lx (L3)\n",
-                           start, start + mapsize - 1);
-                       pmapboot_enter(AARCH64_PA_TO_KVA(start), start,
-                           mapsize, L3_SIZE, ksegattr,
-                           PMAPBOOT_ENTER_NOOVERWRITE, bootpage_alloc, NULL);
-
-                       start += mapsize;
-                       left -= mapsize;
-               }
-
-               /* align the start address to L1 blocksize */
-               nblocks = ulmin(left / L2_SIZE,
-                   Ln_ENTRIES - __SHIFTOUT(start, L2_ADDR_BITS));
-               if (((start & L2_ADDR_BITS) != 0) && (nblocks > 0)) {
-                       mapsize = nblocks * L2_SIZE;
-                       VPRINTF("Creating KSEG tables for %016lx-%016lx (L2)\n",
-                           start, start + mapsize - 1);
-                       pmapboot_enter(AARCH64_PA_TO_KVA(start), start,
-                           mapsize, L2_SIZE, ksegattr,
-                           PMAPBOOT_ENTER_NOOVERWRITE, bootpage_alloc, NULL);
-                       start += mapsize;
-                       left -= mapsize;
-               }
-
-               nblocks = left / L1_SIZE;
-               if (nblocks > 0) {
-                       mapsize = nblocks * L1_SIZE;
-                       VPRINTF("Creating KSEG tables for %016lx-%016lx (L1)\n",
-                           start, start + mapsize - 1);
-                       pmapboot_enter(AARCH64_PA_TO_KVA(start), start,
-                           mapsize, L1_SIZE, ksegattr,
-                           PMAPBOOT_ENTER_NOOVERWRITE, bootpage_alloc, NULL);
-                       start += mapsize;
-                       left -= mapsize;
-               }
-
-               if ((left & L2_ADDR_BITS) != 0) {
-                       nblocks = left / L2_SIZE;
-                       mapsize = nblocks * L2_SIZE;
-                       VPRINTF("Creating KSEG tables for %016lx-%016lx (L2)\n",
-                           start, start + mapsize - 1);
-                       pmapboot_enter(AARCH64_PA_TO_KVA(start), start,
-                           mapsize, L2_SIZE, ksegattr,
-                           PMAPBOOT_ENTER_NOOVERWRITE, bootpage_alloc, NULL);
-                       start += mapsize;
-                       left -= mapsize;
-               }
-
-               if ((left & L3_ADDR_BITS) != 0) {
-                       nblocks = left / L3_SIZE;
-                       mapsize = nblocks * L3_SIZE;
-                       VPRINTF("Creating KSEG tables for %016lx-%016lx (L3)\n",
-                           start, start + mapsize - 1);
-                       pmapboot_enter(AARCH64_PA_TO_KVA(start), start,
-                           mapsize, L3_SIZE, ksegattr,
-                           PMAPBOOT_ENTER_NOOVERWRITE, bootpage_alloc, NULL);
-                       start += mapsize;
-                       left -= mapsize;
-               }
+               pmapboot_enter_range(AARCH64_PA_TO_KVA(start), start,
+                   end - start, ksegattr, PMAPBOOT_ENTER_NOOVERWRITE,
+                   bootpage_alloc, printf);
        }
        aarch64_dcache_wbinv_all();
 
diff -r 40aeeb9868d8 -r 3e12662c49c6 sys/arch/aarch64/aarch64/pmapboot.c
--- a/sys/arch/aarch64/aarch64/pmapboot.c       Sat Feb 29 20:44:15 2020 +0000
+++ b/sys/arch/aarch64/aarch64/pmapboot.c       Sat Feb 29 21:09:11 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmapboot.c,v 1.4 2019/07/18 06:47:36 skrll Exp $       */
+/*     $NetBSD: pmapboot.c,v 1.5 2020/02/29 21:09:11 ryo Exp $ */
 
 /*
  * Copyright (c) 2018 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmapboot.c,v 1.4 2019/07/18 06:47:36 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmapboot.c,v 1.5 2020/02/29 21:09:11 ryo Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_ddb.h"
@@ -422,3 +422,83 @@
 
        return nskip;
 }
+
+int
+pmapboot_enter_range(vaddr_t va, paddr_t pa, psize_t size, pt_entry_t attr,
+    uint64_t flags, pd_entry_t *(*physpage_allocator)(void),
+    void (*pr)(const char *, ...) __printflike(1, 2))
+{
+       vaddr_t vend;
+       vsize_t left, mapsize, nblocks;
+       int nskip = 0;
+
+       va = trunc_page(va);
+       vend = round_page(va + size);
+       left = vend - va;
+
+       /* align the start address to L2 blocksize */
+       nblocks = ulmin(left / L3_SIZE,
+           Ln_ENTRIES - __SHIFTOUT(va, L3_ADDR_BITS));
+       if (((va & L3_ADDR_BITS) != 0) && (nblocks > 0)) {
+               mapsize = nblocks * L3_SIZE;
+               VPRINTF("Creating L3 tables: %016lx-%016lx : %016lx-%016lx\n",
+                   va, va + mapsize - 1, pa, pa + mapsize - 1);
+               nskip += pmapboot_enter(va, pa, mapsize, L3_SIZE, attr, flags,
+                   physpage_allocator, NULL);
+               va += mapsize;
+               pa += mapsize;
+               left -= mapsize;
+       }
+
+       /* align the start address to L1 blocksize */
+       nblocks = ulmin(left / L2_SIZE,
+           Ln_ENTRIES - __SHIFTOUT(va, L2_ADDR_BITS));
+       if (((va & L2_ADDR_BITS) != 0) && (nblocks > 0)) {
+               mapsize = nblocks * L2_SIZE;
+               VPRINTF("Creating L2 tables: %016lx-%016lx : %016lx-%016lx\n",
+                   va, va + mapsize - 1, pa, pa + mapsize - 1);
+               nskip += pmapboot_enter(va, pa, mapsize, L2_SIZE, attr, flags,
+                   physpage_allocator, NULL);
+               va += mapsize;
+               pa += mapsize;
+               left -= mapsize;
+       }
+
+       nblocks = left / L1_SIZE;
+       if (nblocks > 0) {
+               mapsize = nblocks * L1_SIZE;
+               VPRINTF("Creating L1 tables: %016lx-%016lx : %016lx-%016lx\n",
+                   va, va + mapsize - 1, pa, pa + mapsize - 1);
+               nskip += pmapboot_enter(va, pa, mapsize, L1_SIZE, attr, flags,
+                   physpage_allocator, NULL);
+               va += mapsize;
+               pa += mapsize;
+               left -= mapsize;
+       }
+
+       if ((left & L2_ADDR_BITS) != 0) {
+               nblocks = left / L2_SIZE;
+               mapsize = nblocks * L2_SIZE;
+               VPRINTF("Creating L2 tables: %016lx-%016lx : %016lx-%016lx\n",
+                   va, va + mapsize - 1, pa, pa + mapsize - 1);
+               nskip += pmapboot_enter(va, pa, mapsize, L2_SIZE, attr, flags,
+                   physpage_allocator, NULL);
+               va += mapsize;
+               pa += mapsize;
+               left -= mapsize;
+       }
+
+       if ((left & L3_ADDR_BITS) != 0) {
+               nblocks = left / L3_SIZE;
+               mapsize = nblocks * L3_SIZE;
+               VPRINTF("Creating L3 tables: %016lx-%016lx : %016lx-%016lx\n",
+                   va, va + mapsize - 1, pa, pa + mapsize - 1);
+               nskip += pmapboot_enter(va, pa, mapsize, L3_SIZE, attr, flags,
+                   physpage_allocator, NULL);
+               va += mapsize;
+               pa += mapsize;
+               left -= mapsize;
+       }
+
+       return nskip;
+}
diff -r 40aeeb9868d8 -r 3e12662c49c6 sys/arch/aarch64/include/pmap.h
--- a/sys/arch/aarch64/include/pmap.h   Sat Feb 29 20:44:15 2020 +0000
+++ b/sys/arch/aarch64/include/pmap.h   Sat Feb 29 21:09:11 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.34 2020/02/10 19:04:01 ryo Exp $ */
+/* $NetBSD: pmap.h,v 1.35 2020/02/29 21:09:11 ryo Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -173,6 +173,8 @@
     void (*pr)(const char *, ...) __printflike(1, 2));
 #define PMAPBOOT_ENTER_NOBLOCK         0x00000001
 #define PMAPBOOT_ENTER_NOOVERWRITE     0x00000002
+int pmapboot_enter_range(vaddr_t, paddr_t, psize_t, pt_entry_t, uint64_t,
+    pd_entry_t *(*)(void), void (*)(const char *, ...) __printflike(1, 2));
 int pmapboot_protect(vaddr_t, vaddr_t, vm_prot_t);
 void pmap_db_pte_print(pt_entry_t, int,
     void (*pr)(const char *, ...) __printflike(1, 2));



Home | Main Index | Thread Index | Old Index