stm32mp: compute ram_top based on the optee base address

The value of ram_top address currently gets computed in an indirect
manner. The boot_fdt_add_mem_rsv_regions() function gets called first
to reserve the memory region occupied by OP-TEE in the LMB memory
map. This is followed by a call to the lmb_alloc() API, which returns
an address which is below the OP-TEE base address. This address is the
value of ram_top returned by the board_get_usable_ram_top() function.

This has now changed, as the LMB memory map, which is no longer local,
gets set up after relocation. Get the OP-TEE base address by reading
the device tree, and set the ram_top from this value.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
This commit is contained in:
Sughosh Ganu 2024-08-26 17:29:39 +05:30 committed by Tom Rini
parent 5fe9e0deab
commit 8242f14a3e

View file

@ -62,8 +62,10 @@ int dram_init(void)
phys_addr_t board_get_usable_ram_top(phys_size_t total_size) phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
{ {
int ret;
phys_size_t size; phys_size_t size;
phys_addr_t reg; phys_addr_t reg;
u32 optee_start, optee_size;
if (!total_size) if (!total_size)
return gd->ram_top; return gd->ram_top;
@ -73,16 +75,10 @@ phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
* if the effective available memory is bigger * if the effective available memory is bigger
*/ */
gd->ram_top = clamp_val(gd->ram_top, 0, SZ_4G - 1); gd->ram_top = clamp_val(gd->ram_top, 0, SZ_4G - 1);
size = ALIGN(SZ_8M + CONFIG_SYS_MALLOC_LEN + total_size, MMU_SECTION_SIZE);
/* found enough not-reserved memory to relocated U-Boot */ ret = optee_get_reserved_memory(&optee_start, &optee_size);
lmb_add(gd->ram_base, gd->ram_top - gd->ram_base); reg = (!ret ? optee_start : gd->ram_top) - size;
boot_fdt_add_mem_rsv_regions((void *)gd->fdt_blob);
/* add 8M for reserved memory for display, fdt, gd,... */
size = ALIGN(SZ_8M + CONFIG_SYS_MALLOC_LEN + total_size, MMU_SECTION_SIZE),
reg = lmb_alloc(size, MMU_SECTION_SIZE);
if (!reg)
reg = gd->ram_top - size;
/* before relocation, mark the U-Boot memory as cacheable by default */ /* before relocation, mark the U-Boot memory as cacheable by default */
if (!(gd->flags & GD_FLG_RELOC)) if (!(gd->flags & GD_FLG_RELOC))