Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/fdt Move evbarm/fdt/fdt_memory.[ch] to sys/dev/fdt a...



details:   https://anonhg.NetBSD.org/src/rev/7bedceb03852
branches:  trunk
changeset: 979039:7bedceb03852
user:      skrll <skrll%NetBSD.org@localhost>
date:      Sat Dec 12 09:27:31 2020 +0000

description:
Move evbarm/fdt/fdt_memory.[ch] to sys/dev/fdt and simplify the api and
some operations.  This allows other architectures to use it.

diffstat:

 sys/arch/aarch64/aarch64/aarch64_machdep.c |    8 +-
 sys/arch/arm/arm32/arm32_kvminit.c         |    9 +-
 sys/arch/evbarm/conf/files.fdt             |    3 +-
 sys/arch/evbarm/fdt/fdt_machdep.c          |  117 ++-----------
 sys/arch/evbarm/fdt/fdt_memory.c           |  172 --------------------
 sys/arch/evbarm/fdt/fdt_memory.h           |   44 -----
 sys/arch/evbarm/fdt/platform.h             |    6 +-
 sys/dev/fdt/fdt_memory.c                   |  244 +++++++++++++++++++++++++++++
 sys/dev/fdt/fdt_memory.h                   |   48 +++++
 sys/dev/fdt/files.fdt                      |    5 +-
 10 files changed, 330 insertions(+), 326 deletions(-)

diffs (truncated from 857 to 300 lines):

diff -r 20e2b60d522f -r 7bedceb03852 sys/arch/aarch64/aarch64/aarch64_machdep.c
--- a/sys/arch/aarch64/aarch64/aarch64_machdep.c        Sat Dec 12 05:48:55 2020 +0000
+++ b/sys/arch/aarch64/aarch64/aarch64_machdep.c        Sat Dec 12 09:27:31 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: aarch64_machdep.c,v 1.55 2020/12/09 08:51:05 skrll Exp $ */
+/* $NetBSD: aarch64_machdep.c,v 1.56 2020/12/12 09:27:31 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.55 2020/12/09 08:51:05 skrll Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.56 2020/12/12 09:27:31 skrll Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -72,8 +72,8 @@
 #include <aarch64/vmparam.h>
 #include <aarch64/kcore.h>
 
-#include <arch/evbarm/fdt/platform.h>
 #include <arm/fdt/arm_fdtvar.h>
+#include <dev/fdt/fdt_memory.h>
 
 #ifdef VERBOSE_INIT_ARM
 #define VPRINTF(...)   printf(__VA_ARGS__)
@@ -193,7 +193,7 @@
 
        VPRINTF("%s: kernel phys start %lx end %lx+%lx\n", __func__,
            kernstart_phys, kernend_phys, kernend_extra);
-       fdt_add_reserved_memory_range(kernstart_phys,
+       fdt_memory_remove_range(kernstart_phys,
             kernend_phys - kernstart_phys + kernend_extra);
 }
 
diff -r 20e2b60d522f -r 7bedceb03852 sys/arch/arm/arm32/arm32_kvminit.c
--- a/sys/arch/arm/arm32/arm32_kvminit.c        Sat Dec 12 05:48:55 2020 +0000
+++ b/sys/arch/arm/arm32/arm32_kvminit.c        Sat Dec 12 09:27:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arm32_kvminit.c,v 1.66 2020/10/30 18:54:36 skrll Exp $ */
+/*     $NetBSD: arm32_kvminit.c,v 1.67 2020/12/12 09:27:31 skrll Exp $ */
 
 /*
  * Copyright (c) 2002, 2003, 2005  Genetec Corporation.  All rights reserved.
@@ -127,7 +127,7 @@
 #include "opt_multiprocessor.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: arm32_kvminit.c,v 1.66 2020/10/30 18:54:36 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arm32_kvminit.c,v 1.67 2020/12/12 09:27:31 skrll Exp $");
 
 #include <sys/param.h>
 
@@ -150,6 +150,7 @@
 #if defined(FDT)
 #include <arch/evbarm/fdt/platform.h>
 #include <arm/fdt/arm_fdtvar.h>
+#include <dev/fdt/fdt_memory.h>
 #endif
 
 #ifdef MULTIPROCESSOR
@@ -251,7 +252,7 @@
        bmi->bmi_kernelend = kernelend;
 
 #if defined(FDT)
-       fdt_add_reserved_memory_range(bmi->bmi_kernelstart,
+       fdt_memory_remove_range(bmi->bmi_kernelstart,
            bmi->bmi_kernelend - bmi->bmi_kernelstart);
 #endif
 
@@ -400,7 +401,7 @@
        KASSERT((armreg_ttbr_read() & ~(L1_TABLE_SIZE - 1)) != free_pv->pv_pa);
 
 #if defined(FDT)
-       fdt_add_reserved_memory_range(free_pv->pv_pa, nbytes);
+       fdt_memory_remove_range(free_pv->pv_pa, nbytes);
 #endif
        pv->pv_pa = free_pv->pv_pa;
        pv->pv_va = free_pv->pv_va;
diff -r 20e2b60d522f -r 7bedceb03852 sys/arch/evbarm/conf/files.fdt
--- a/sys/arch/evbarm/conf/files.fdt    Sat Dec 12 05:48:55 2020 +0000
+++ b/sys/arch/evbarm/conf/files.fdt    Sat Dec 12 09:27:31 2020 +0000
@@ -1,10 +1,9 @@
-#      $NetBSD: files.fdt,v 1.6 2020/02/20 01:35:55 jmcneill Exp $
+#      $NetBSD: files.fdt,v 1.7 2020/12/12 09:27:31 skrll Exp $
 #
 # FDT-based kernel configuration info
 #
 
 file   arch/evbarm/fdt/fdt_dma_machdep.c       fdt
 file   arch/evbarm/fdt/fdt_machdep.c           fdt
-file   arch/evbarm/fdt/fdt_memory.c            fdt
 
 include "arch/arm/fdt/files.fdt"
diff -r 20e2b60d522f -r 7bedceb03852 sys/arch/evbarm/fdt/fdt_machdep.c
--- a/sys/arch/evbarm/fdt/fdt_machdep.c Sat Dec 12 05:48:55 2020 +0000
+++ b/sys/arch/evbarm/fdt/fdt_machdep.c Sat Dec 12 09:27:31 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_machdep.c,v 1.82 2020/11/28 22:16:23 riastradh Exp $ */
+/* $NetBSD: fdt_machdep.c,v 1.83 2020/12/12 09:27:31 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.82 2020/11/28 22:16:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.83 2020/12/12 09:27:31 skrll Exp $");
 
 #include "opt_machdep.h"
 #include "opt_bootconfig.h"
@@ -89,10 +89,10 @@
 #include <evbarm/include/autoconf.h>
 #include <evbarm/fdt/machdep.h>
 #include <evbarm/fdt/platform.h>
-#include <evbarm/fdt/fdt_memory.h>
 
 #include <arm/fdt/arm_fdtvar.h>
 #include <dev/fdt/fdt_private.h>
+#include <dev/fdt/fdt_memory.h>
 
 #ifdef EFI_RUNTIME
 #include <arm/arm/efi_runtime.h>
@@ -172,81 +172,6 @@
 #define VPRINTF(...)   __nothing
 #endif
 
-/*
- * Get all of physical memory, including holes.
- */
-static void
-fdt_get_memory(uint64_t *pstart, uint64_t *pend)
-{
-       const int memory = OF_finddevice("/memory");
-       uint64_t cur_addr, cur_size;
-       int index;
-
-       /* Assume the first entry is the start of memory */
-       if (fdtbus_get_reg64(memory, 0, &cur_addr, &cur_size) != 0)
-               panic("Cannot determine memory size");
-
-       *pstart = cur_addr;
-       *pend = cur_addr + cur_size;
-
-       VPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n",
-           0, *pstart, *pend - *pstart);
-
-       for (index = 1;
-            fdtbus_get_reg64(memory, index, &cur_addr, &cur_size) == 0;
-            index++) {
-               VPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n",
-                   index, cur_addr, cur_size);
-
-               if (cur_addr + cur_size > *pend)
-                       *pend = cur_addr + cur_size;
-       }
-}
-
-void
-fdt_add_reserved_memory_range(uint64_t addr, uint64_t size)
-{
-       fdt_memory_remove_range(addr, size);
-}
-
-/*
- * Exclude memory ranges from memory config from the device tree
- */
-static void
-fdt_add_reserved_memory(uint64_t min_addr, uint64_t max_addr)
-{
-       uint64_t lstart = 0, lend = 0;
-       uint64_t addr, size;
-       int index, error;
-
-       const int num = fdt_num_mem_rsv(fdtbus_get_data());
-       for (index = 0; index <= num; index++) {
-               error = fdt_get_mem_rsv(fdtbus_get_data(), index,
-                   &addr, &size);
-               if (error != 0)
-                       continue;
-               if (lstart <= addr && addr <= lend) {
-                       size -= (lend - addr);
-                       addr = lend;
-               }
-               if (size == 0)
-                       continue;
-               if (addr + size <= min_addr)
-                       continue;
-               if (addr >= max_addr)
-                       continue;
-               if (addr < min_addr) {
-                       size -= (min_addr - addr);
-                       addr = min_addr;
-               }
-               if (addr + size > max_addr)
-                       size = max_addr - addr;
-               fdt_add_reserved_memory_range(addr, size);
-               lstart = addr;
-               lend = addr + size;
-       }
-}
-
 static void
 fdt_add_dram_blocks(const struct fdt_memory *m, void *arg)
 {
@@ -293,29 +218,28 @@
 #endif
 }
 
+
+static void
+fdt_print_memory(const struct fdt_memory *m, void *arg)
+{
+
+       VPRINTF("FDT /memory @ 0x%" PRIx64 " size 0x%" PRIx64 "\n",
+           m->start, m->end - m->start);
+}
+
+
 /*
  * Define usable memory regions.
  */
 static void
 fdt_build_bootconfig(uint64_t mem_start, uint64_t mem_end)
 {
-       const int memory = OF_finddevice("/memory");
        BootConfig *bc = &bootconfig;
+
        uint64_t addr, size;
        int index;
 
-       for (index = 0;
-            fdtbus_get_reg64(memory, index, &addr, &size) == 0;
-            index++) {
-               if (addr >= mem_end || size == 0)
-                       continue;
-               if (addr + size > mem_end)
-                       size = mem_end - addr;
-
-               fdt_memory_add_range(addr, size);
-       }
-
-       fdt_add_reserved_memory(mem_start, mem_end);
+       fdt_memory_remove_reserved(mem_start, mem_end);
 
        const uint64_t initrd_size =
            round_page(initrd_end) - trunc_page(initrd_start);
@@ -338,7 +262,7 @@
                for (index = 0;
                     fdtbus_get_reg64(framebuffer, index, &addr, &size) == 0;
                     index++) {
-                       fdt_add_reserved_memory_range(addr, size);
+                       fdt_memory_remove_range(addr, size);
                }
        }
 
@@ -576,6 +500,7 @@
        /* If the DTB is too big, try to pack it in place first. */
        if (fdt_totalsize(fdt_addr_r) > sizeof(fdt_data))
                (void)fdt_pack(__UNCONST(fdt_addr_r));
+
        error = fdt_open_into(fdt_addr_r, fdt_data, sizeof(fdt_data));
        if (error != 0)
                panic("fdt_move failed: %s", fdt_strerror(error));
@@ -656,13 +581,17 @@
        parse_mi_bootargs(mi_bootargs);
 #endif
 
-       fdt_get_memory(&memory_start, &memory_end);
+       fdt_memory_get(&memory_start, &memory_end);
+
+       fdt_memory_foreach(fdt_print_memory, NULL);
 
 #if !defined(_LP64)
        /* Cannot map memory above 4GB (remove last page as well) */
        const uint64_t memory_limit = 0x100000000ULL - PAGE_SIZE;
-       if (memory_end > memory_limit)
+       if (memory_end > memory_limit) {
+               fdt_memory_remove_range(memory_limit , memory_end);
                memory_end = memory_limit;
+       }
 #endif
        uint64_t memory_size = memory_end - memory_start;
 
diff -r 20e2b60d522f -r 7bedceb03852 sys/arch/evbarm/fdt/fdt_memory.c
--- a/sys/arch/evbarm/fdt/fdt_memory.c  Sat Dec 12 05:48:55 2020 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,172 +0,0 @@
-/* $NetBSD: fdt_memory.c,v 1.4 2020/01/27 01:15:09 jmcneill Exp $ */
-
-/*-
- * Copyright (c) 2018 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Jared McNeill <jmcneill%invisible.ca@localhost>.
- *



Home | Main Index | Thread Index | Old Index