]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
lmb: introduce a function to add memory to the lmb memory map
authorSughosh Ganu <sughosh.ganu@linaro.org>
Mon, 26 Aug 2024 11:59:23 +0000 (17:29 +0530)
committerTom Rini <trini@konsulko.com>
Tue, 3 Sep 2024 20:08:50 +0000 (14:08 -0600)
Introduce a function lmb_add_memory() to add available memory to the
LMB memory map. Call this function during board init once the LMB data
structures have been initialised.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
include/lmb.h
lib/lmb.c

index cc2c426c13bc1f3828f7333e563a5e0c2a54968a..70191456e5eaee9a445e764438aea934565e0b48 100644 (file)
@@ -66,6 +66,17 @@ int lmb_init(void);
 void lmb_init_and_reserve(struct bd_info *bd, void *fdt_blob);
 void lmb_init_and_reserve_range(phys_addr_t base, phys_size_t size,
                                void *fdt_blob);
+
+/**
+ * lmb_add_memory() - Add memory range for LMB allocations
+ *
+ * Add the entire available memory range to the pool of memory that
+ * can be used by the LMB module for allocations.
+ *
+ * Return: None
+ */
+void lmb_add_memory(void);
+
 long lmb_add(phys_addr_t base, phys_size_t size);
 long lmb_reserve(phys_addr_t base, phys_size_t size);
 /**
index 8be0c1a58352ff1fb29e2e1e810634f625745db1..44ecf96811cd573ca4c14d672f6f597bd03ea24b 100644 (file)
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -246,6 +246,43 @@ void lmb_init_and_reserve_range(phys_addr_t base, phys_size_t size,
        lmb_reserve_common(fdt_blob);
 }
 
+/**
+ * lmb_add_memory() - Add memory range for LMB allocations
+ *
+ * Add the entire available memory range to the pool of memory that
+ * can be used by the LMB module for allocations.
+ *
+ * Return: None
+ */
+void lmb_add_memory(void)
+{
+       int i;
+       phys_size_t size;
+       phys_addr_t rgn_top;
+       u64 ram_top = gd->ram_top;
+       struct bd_info *bd = gd->bd;
+
+       /* Assume a 4GB ram_top if not defined */
+       if (!ram_top)
+               ram_top = 0x100000000ULL;
+
+       for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
+               size = bd->bi_dram[i].size;
+               if (size) {
+                       if (bd->bi_dram[i].start > ram_top)
+                               continue;
+
+                       rgn_top = bd->bi_dram[i].start +
+                               bd->bi_dram[i].size;
+
+                       if (rgn_top > ram_top)
+                               size -= rgn_top - ram_top;
+
+                       lmb_add(bd->bi_dram[i].start, size);
+               }
+       }
+}
+
 static long lmb_resize_regions(struct alist *lmb_rgn_lst,
                               unsigned long idx_start,
                               phys_addr_t base, phys_size_t size)
@@ -696,6 +733,8 @@ int lmb_init(void)
                return ret;
        }
 
+       lmb_add_memory();
+
        return 0;
 }