Skip to contentSkip to conversation

ARM: imx: Do not hard-code MX8M MMU table DRAM entry offset

PATCH New Marek Vasut 3 participants 3 messages Feb 27, 2021 – Mar 1, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: imx: Do not hard-code MX8M MMU table DRAM entry offset

Instead of hard-coding the offset of DRAM entries in MMU table all over the code, auto-detect the offset. This removes error-prone code which would break e.g. in case the MMU table is modified.

Cc Fabio Estevam <[email protected]>
Cc Peng Fan <[email protected]>
Cc Stefano Babic <[email protected]>
---
 arch/arm/mach-imx/imx8m/soc.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
arch/arm/mach-imx/imx8m/soc.c +16 -3
index 225e4e12500..988355f147c 100644
@@ -161,6 +161,17 @@ static struct mm_region imx8m_mem_map[] = {
 
 struct mm_region *mem_map = imx8m_mem_map;
 
+static unsigned int imx8m_find_dram_entry_in_mem_map(void)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(imx8m_mem_map); i++)
+		if (imx8m_mem_map[i].phys == CONFIG_SYS_SDRAM_BASE)
+			return i;
+
+	hang();	/* Entry not found, this must never happen. */
+}
+
 void enable_caches(void)
 {
 	/* If OPTEE runs, remove OPTEE memory from MMU table to avoid speculative prefetch */
@@ -174,10 +185,11 @@ void enable_caches(void)
 		 * please make sure that entry initial value matches
 		 * imx8m_mem_map for DRAM1
 		 */
-		int entry = 5;
+		int entry = imx8m_find_dram_entry_in_mem_map();
 		u64 attrs = imx8m_mem_map[entry].attrs;
 
-		while (i < CONFIG_NR_DRAM_BANKS && entry < 8) {
+		while (i < CONFIG_NR_DRAM_BANKS &&
+		       entry < ARRAY_SIZE(imx8m_mem_map)) {
 			if (gd->bd->bi_dram[i].start == 0)
 				break;
 			imx8m_mem_map[entry].phys = gd->bd->bi_dram[i].start;
@@ -205,6 +217,7 @@ __weak int board_phys_sdram_size(phys_size_t *size)
 
 int dram_init(void)
 {
+	unsigned int entry = imx8m_find_dram_entry_in_mem_map();
 	phys_size_t sdram_size;
 	int ret;
 
@@ -219,7 +232,7 @@ int dram_init(void)
 		gd->ram_size = sdram_size;
 
 	/* also update the SDRAM size in the mem_map used externally */
-	imx8m_mem_map[5].size = sdram_size;
+	imx8m_mem_map[entry].size = sdram_size;
 
 #ifdef PHYS_SDRAM_2_SIZE
 	gd->ram_size += PHYS_SDRAM_2_SIZE;
Signature · 1 line
2.30.0
reviewer
#1 lore raw

PATCH 1/1 ARM: imx: Do not hard-code MX8M MMU table DRAM entry offset

Hi Marek,

Quoted 10 lines · Marek Vasut

Instead of hard-coding the offset of DRAM entries in MMU table all over the code, auto-detect the offset. This removes error-prone code which would break e.g. in case the MMU table is modified.

Cc Fabio Estevam <[email protected]>
Cc Peng Fan <[email protected]>
Cc Stefano Babic <[email protected]>

This is a much better solution indeed, thanks:

#2 lore raw

PATCH 1/1 ARM: imx: Do not hard-code MX8M MMU table DRAM entry offset

In reply to Marek Vasut
Quoted 9 lines

Instead of hard-coding the offset of DRAM entries in MMU table all over the code, auto-detect the offset. This removes error-prone code which would break e.g. in case the MMU table is modified.

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================