From: Marek Vasut <[email protected]> Introduce function fdtdec_setup_mem_ram_top(), which determines the topmost address in the last DRAM bank, to be assigned into gd->ram_top in order to relocate U-Boot to the actual end of all DRAM. This makes use of iterator function fdtdec_setup_mem_for_each_bank() introduced in previous commit.
Reviewed-by: Ilias Apalodimas <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]> Signed-off-by: Marek Vasut <[email protected]> --- include/fdtdec.h | 16 ++++++++++++++++ lib/fdtdec.c | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/fdtdec.h b/include/fdtdec.h index d9fcd037ed26..26e40c3cdb46 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -933,6 +933,22 @@ int fdtdec_setup_mem_size_base(void); */ int fdtdec_setup_mem_size_base_lowest(void); +/** + * fdtdec_setup_mem_ram_top() - decode and setup gd->ram_top to highest address + * available in any memory bank + * + * Decode the /memory 'reg' property to determine the highest end of the memory + * bank and populate the global data ram_top with it. + * + * This function should be called from a boards board_get_usable_ram_top(). + * This helper function allows for boards to query the device tree for topmost + * DRAM address. + * + * Return: 0 if OK, -EINVAL if the /memory node or reg property is missing or + * invalid + */ +int fdtdec_setup_mem_ram_top(void); + /** * fdtdec_setup_memory_banksize() - decode and populate gd->bd->bi_dram * diff --git a/lib/fdtdec.c b/lib/fdtdec.c index d820f75b031d..bdb26d8fb75b 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1162,6 +1162,24 @@ int fdtdec_setup_mem_size_base_lowest(void) return fdtdec_setup_mem_for_each_bank(fdtdec_setup_mem_size_base_lowest_bankfn); } +static void fdtdec_setup_mem_ram_top_bankfn(struct resource *res, int bank) +{ + if ((res->end + 1) > gd->ram_top) + gd->ram_top = res->end + 1; +} + +int fdtdec_setup_mem_ram_top(void) +{ + phys_addr_t old_top = gd->ram_top; + int ret; + + ret = fdtdec_setup_mem_for_each_bank(fdtdec_setup_mem_ram_top_bankfn); + if (ret) + gd->ram_top = old_top; + + return ret; +} + static int uncompress_blob(const void *src, ulong sz_src, void **dstp) { #if CONFIG_IS_ENABLED(MULTI_DTB_FIT_GZIP) ||\ -- 2.53.0

