Skip to contentSkip to conversation

arm: sunxi: dram: restore previous value in DRAM

PATCH In review Andrei Lalaev 2 participants 2 messages Feb 13, 2022 – Apr 24, 2022

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

PATCH 1/1 arm: sunxi: dram: restore previous value in DRAM

It's better to restore previous value at offset because otherwise the function can corrupt memory reserved by Linux (e.g. ramoops).

---
 arch/arm/mach-sunxi/dram_helpers.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
arch/arm/mach-sunxi/dram_helpers.c +11 -3
index 2c873192e6..ed6db14f3c 100644
@@ -32,12 +32,20 @@ void mctl_await_completion(u32 *reg, u32 mask, u32 val)
 #ifndef CONFIG_MACH_SUNIV
 bool mctl_mem_matches(u32 offset)
 {
+	ulong addr = CONFIG_SYS_SDRAM_BASE + offset;
+	u32 prev_val = readl(addr);
+	bool ret = false;
+
 	/* Try to write different values to RAM at two addresses */
 	writel(0, CONFIG_SYS_SDRAM_BASE);
-	writel(0xaa55aa55, (ulong)CONFIG_SYS_SDRAM_BASE + offset);
+	writel(0xaa55aa55, addr);
 	dsb();
 	/* Check if the same value is actually observed when reading back */
-	return readl(CONFIG_SYS_SDRAM_BASE) ==
-	       readl((ulong)CONFIG_SYS_SDRAM_BASE + offset);
+	ret = readl(CONFIG_SYS_SDRAM_BASE) == readl(addr);
+
+	/* Restore previous value */
+	writel(prev_val, addr);
+
+	return ret;
 }
 #endif
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 2 lines · Andrei Lalaev

It's better to restore previous value at offset because otherwise the function can corrupt memory reserved by Linux (e.g. ramoops).

With this patch, does ramoops work for you? and on which hardware? If so, I am definitely in favor of applying this patch.

I'm a bit surprised that DRAM contents are maintained (this isn't the only place where they could be destroyed). I suppose the reset state of the PRCM enables pad hold, which would put the DRAM in self-refresh. So we just have to be careful during DRAM controller init.

Regards,
Samuel

Quoted 34 lines
---
 arch/arm/mach-sunxi/dram_helpers.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
arch/arm/mach-sunxi/dram_helpers.c +11 -3
index 2c873192e6..ed6db14f3c 100644
@@ -32,12 +32,20 @@ void mctl_await_completion(u32 *reg, u32 mask, u32 val)
 #ifndef CONFIG_MACH_SUNIV
 bool mctl_mem_matches(u32 offset)
 {
+	ulong addr = CONFIG_SYS_SDRAM_BASE + offset;
+	u32 prev_val = readl(addr);
+	bool ret = false;
+
 	/* Try to write different values to RAM at two addresses */
 	writel(0, CONFIG_SYS_SDRAM_BASE);
-	writel(0xaa55aa55, (ulong)CONFIG_SYS_SDRAM_BASE + offset);
+	writel(0xaa55aa55, addr);
 	dsb();
 	/* Check if the same value is actually observed when reading back */
-	return readl(CONFIG_SYS_SDRAM_BASE) ==
-	       readl((ulong)CONFIG_SYS_SDRAM_BASE + offset);
+	ret = readl(CONFIG_SYS_SDRAM_BASE) == readl(addr);
+
+	/* Restore previous value */
+	writel(prev_val, addr);
+
+	return ret;
 }
 #endif