[PATCH -next v6 05/10] arm: armv8: mmu: add mem_map_fix_dram_banks
Anshul Dalal
anshuld at ti.com
Fri Sep 12 08:38:30 CEST 2025
Hi Ilias,
On Fri Sep 12, 2025 at 12:03 PM IST, Ilias Apalodimas wrote:
> Hi Anshul,
>
> On Fri, 5 Sept 2025 at 11:19, Anshul Dalal <anshuld at ti.com> wrote:
>>
>> For armv8, U-Boot uses a static map defined as 'mem_map' for configuring
>> the MMU as part of mmu_setup.
>>
>> But since the exact configuration of memory banks might not be known at
>> build time, many platforms such as imx9, versal2 etc. utilize
>> gd->bd->bi_dram to configure the static map at runtime.
>>
>> Therefore this patch adds a new API mem_map_fix_dram_banks that modifies
>> the static map in a similar way. Allowing for anyone to map all dram
>> banks by just passing the index to last entry in their mem_map and it's
>> length.
>>
>> Signed-off-by: Anshul Dalal <anshuld at ti.com>
>> ---
>> arch/arm/cpu/armv8/cache_v8.c | 27 +++++++++++++++++++++++++++
>> arch/arm/include/asm/armv8/mmu.h | 10 ++++++++++
>> 2 files changed, 37 insertions(+)
>>
>> diff --git a/arch/arm/cpu/armv8/cache_v8.c b/arch/arm/cpu/armv8/cache_v8.c
>> index 6e662395a83..edb895da1f2 100644
>> --- a/arch/arm/cpu/armv8/cache_v8.c
>> +++ b/arch/arm/cpu/armv8/cache_v8.c
>> @@ -58,6 +58,33 @@ static int get_effective_el(void)
>> return el;
>> }
>>
>> +int mem_map_fix_dram_banks(unsigned int index, unsigned int len, u64 attrs)
>> +{
>> + unsigned int i;
>> + int ret = fdtdec_setup_memory_banksize();
>> +
>> + if (ret) {
>> + printf("%s: Failed to setup dram banks\n", __func__);
>> + return ret;
>> + }
>> +
>> + if (index + CONFIG_NR_DRAM_BANKS >= len) {
>> + printf("%s: Not sufficient space in memory map\n", __func__);
>> + return -ENOMEM;
>> + }
>
> The length of the mem_map array is configured at compile time.
> So this is going to fail for all existing boards unless someone
> explicitly changes the size of their struct mm_region.
> I think if we go down that path, we need to change the error message
> as well and point them to the right direction
>
>> +
>> + for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
>> + mem_map[index].virt = gd->bd->bi_dram[i].start;
>> + mem_map[index].phys = gd->bd->bi_dram[i].start;
>> + mem_map[index].size = gd->bd->bi_dram[i].size;
>> + mem_map[index].attrs = attrs;
>> + index++;
>> + }
>> +
>> + mem_map[index] = (const struct mm_region){ 0 };
>
> Why do you need the const?
> Can we do
> memset(&mem_map[index], 0, sizeof(mem_map[index]));
> instead?
>
Yeah, we could do that instead. But it essentially achieves the same
thing, right?
Regards,
Anshul
More information about the U-Boot
mailing list