[PATCH -next v6 05/10] arm: armv8: mmu: add mem_map_fix_dram_banks
Anshul Dalal
anshuld at ti.com
Fri Sep 5 10:18:56 CEST 2025
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;
+ }
+
+ 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 };
+
+ return 0;
+}
u64 get_tcr(u64 *pips, u64 *pva_bits)
{
int el = get_effective_el();
diff --git a/arch/arm/include/asm/armv8/mmu.h b/arch/arm/include/asm/armv8/mmu.h
index 3807c702fb6..257352f216e 100644
--- a/arch/arm/include/asm/armv8/mmu.h
+++ b/arch/arm/include/asm/armv8/mmu.h
@@ -194,8 +194,18 @@ struct mm_region {
u64 attrs;
};
+/* Used as the memory map for MMU configuration by mmu_setup */
extern struct mm_region *mem_map;
void setup_pgtables(void);
+
+/**
+ * mem_map_fix_dram_banks() - Populate mem_map with entries corresponding to
+ * dram banks as per the gd. This should be called prior to mmu_setup.
+ *
+ * @index: The entry in mem_map to start the over-write
+ * @len: The size of mem_map
+ */
+int mem_map_fix_dram_banks(unsigned int index, unsigned int len, u64 attrs);
u64 get_tcr(u64 *pips, u64 *pva_bits);
/**
--
2.50.1
More information about the U-Boot
mailing list