mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2026-06-13 15:03:58 +03:00
lmb: make LMB memory map persistent and global
The current LMB API's for allocating and reserving memory use a per-caller based memory view. Memory allocated by a caller can then be overwritten by another caller. Make these allocations and reservations persistent using the alloced list data structure. Two alloced lists are declared -- one for the available(free) memory, and one for the used memory. Once full, the list can then be extended at runtime. [sjg: Use a stack to store pointer of lmb struct when running lmb tests] Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Signed-off-by: Simon Glass <sjg@chromium.org> [sjg: Optimise the logic to add a region in lmb_add_region_flags()]
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
* Copyright 2023 Marek Vasut <marek.vasut+renesas@mailbox.org>
|
||||
*/
|
||||
|
||||
#include <alist.h>
|
||||
#include <console.h>
|
||||
#include <mapmem.h>
|
||||
#include <asm/global_data.h>
|
||||
@@ -99,44 +100,39 @@ static int test_video_info(struct unit_test_state *uts)
|
||||
}
|
||||
|
||||
static int lmb_test_dump_region(struct unit_test_state *uts,
|
||||
struct lmb_region *rgn, char *name)
|
||||
struct alist *lmb_rgn_lst, char *name)
|
||||
{
|
||||
struct lmb_region *rgn = lmb_rgn_lst->data;
|
||||
unsigned long long base, size, end;
|
||||
enum lmb_flags flags;
|
||||
int i;
|
||||
|
||||
ut_assert_nextline(" %s.cnt = 0x%lx / max = 0x%lx", name, rgn->cnt, rgn->max);
|
||||
ut_assert_nextline(" %s.count = 0x%hx", name, lmb_rgn_lst->count);
|
||||
|
||||
for (i = 0; i < rgn->cnt; i++) {
|
||||
base = rgn->region[i].base;
|
||||
size = rgn->region[i].size;
|
||||
for (i = 0; i < lmb_rgn_lst->count; i++) {
|
||||
base = rgn[i].base;
|
||||
size = rgn[i].size;
|
||||
end = base + size - 1;
|
||||
flags = rgn->region[i].flags;
|
||||
flags = rgn[i].flags;
|
||||
|
||||
/*
|
||||
* this entry includes the stack (get_sp()) on many platforms
|
||||
* so will different each time lmb_init_and_reserve() is called.
|
||||
* We could instead have the bdinfo command put its lmb region
|
||||
* in a known location, so we can check it directly, rather than
|
||||
* calling lmb_init_and_reserve() to create a new (and hopefully
|
||||
* identical one). But for now this seems good enough.
|
||||
*/
|
||||
if (!IS_ENABLED(CONFIG_SANDBOX) && i == 3) {
|
||||
ut_assert_nextlinen(" %s[%d]\t[", name, i);
|
||||
continue;
|
||||
}
|
||||
ut_assert_nextline(" %s[%d]\t[0x%llx-0x%llx], 0x%08llx bytes flags: %x",
|
||||
name, i, base, end, size, flags);
|
||||
ut_assert_nextlinen(" %s[%d]\t[0x%llx-0x%llx], 0x%08llx bytes flags: ",
|
||||
name, i, base, end, size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lmb_test_dump_all(struct unit_test_state *uts, struct lmb *lmb)
|
||||
static int lmb_test_dump_all(struct unit_test_state *uts)
|
||||
{
|
||||
struct lmb *lmb = lmb_get();
|
||||
|
||||
ut_assert_nextline("lmb_dump_all:");
|
||||
ut_assertok(lmb_test_dump_region(uts, &lmb->memory, "memory"));
|
||||
ut_assertok(lmb_test_dump_region(uts, &lmb->reserved, "reserved"));
|
||||
ut_assertok(lmb_test_dump_region(uts, &lmb->free_mem, "memory"));
|
||||
ut_assertok(lmb_test_dump_region(uts, &lmb->used_mem, "reserved"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -198,10 +194,7 @@ static int bdinfo_test_all(struct unit_test_state *uts)
|
||||
#endif
|
||||
|
||||
if (IS_ENABLED(CONFIG_LMB) && gd->fdt_blob) {
|
||||
struct lmb lmb;
|
||||
|
||||
lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
|
||||
ut_assertok(lmb_test_dump_all(uts, &lmb));
|
||||
ut_assertok(lmb_test_dump_all(uts));
|
||||
if (IS_ENABLED(CONFIG_OF_REAL))
|
||||
ut_assert_nextline("devicetree = %s", fdtdec_get_srcname());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user