Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/arch/evbarm/fdt/fdt_machdep.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/arch/evbarm/fdt/fdt_machdep.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.82 retrieving revision 1.83 diff -u -p -r1.82 -r1.83 --- src/sys/arch/evbarm/fdt/fdt_machdep.c 2020/11/28 22:16:23 1.82 +++ src/sys/arch/evbarm/fdt/fdt_machdep.c 2020/12/12 09:27:31 1.83 @@ -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 @@ -27,7 +27,7 @@ */ #include -__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 @@ __KERNEL_RCSID(0, "$NetBSD: fdt_machdep. #include #include #include -#include #include #include +#include #ifdef EFI_RUNTIME #include @@ -172,81 +172,6 @@ static struct consdev earlycons = { #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 @@ fdt_add_boot_physmem(const struct fdt_me #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 @@ fdt_build_bootconfig(uint64_t mem_start, 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 @@ initarm(void *arg) /* 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 @@ initarm(void *arg) 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;