]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
lmb: prohibit allocations above ram_top even from same bank
authorSughosh Ganu <sughosh.ganu@linaro.org>
Mon, 2 Dec 2024 07:06:24 +0000 (12:36 +0530)
committerTom Rini <trini@konsulko.com>
Fri, 6 Dec 2024 23:47:23 +0000 (17:47 -0600)
There are platforms which set the value of ram_top based on certain
restrictions that the platform might have in accessing memory above
ram_top, even when the memory region is in the same DRAM bank. So,
even though the LMB allocator works as expected, when trying to
allocate memory above ram_top, prohibit this by marking all memory
above ram_top as reserved, even if the said memory region is from the
same bank.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Tested-by: Andreas Schwab <schwab@suse.de>
lib/lmb.c

index 3a765c11bee6402cd6c8cf541693737c30c7d414..b03237bc06cba1919e2b88800076adaf22536061 100644 (file)
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -606,6 +606,7 @@ static __maybe_unused void lmb_reserve_common_spl(void)
 void lmb_add_memory(void)
 {
        int i;
+       phys_addr_t bank_end;
        phys_size_t size;
        u64 ram_top = gd->ram_top;
        struct bd_info *bd = gd->bd;
@@ -619,6 +620,8 @@ void lmb_add_memory(void)
 
        for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
                size = bd->bi_dram[i].size;
+               bank_end = bd->bi_dram[i].start + size;
+
                if (size) {
                        lmb_add(bd->bi_dram[i].start, size);
 
@@ -630,6 +633,9 @@ void lmb_add_memory(void)
                        if (bd->bi_dram[i].start >= ram_top)
                                lmb_reserve_flags(bd->bi_dram[i].start, size,
                                                  LMB_NOOVERWRITE);
+                       else if (bank_end > ram_top)
+                               lmb_reserve_flags(ram_top, bank_end - ram_top,
+                                                 LMB_NOOVERWRITE);
                }
        }
 }