Skip to contentSkip to conversation

soc: aspeed: Fail probe of lpc-ctrl if reserved memory is not aligned

PATCH Superseded Andrew Jeffery 1 participant 2 messages Oct 16, 2019

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 soc: aspeed: Fail probe of lpc-ctrl if reserved memory is not aligned

Alignment is a hardware constraint of the LPC2AHB bridge, and misaligned reserved memory will present as corrupted data.

---
v2: Cosmetic fixes pointed out by Milton

 arch/arm/boot/dts/aspeed-bmc-opp-romulus.dts |  2 +-
 drivers/soc/aspeed/aspeed-lpc-ctrl.c         | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
arch/arm/boot/dts/aspeed-bmc-opp-romulus.dts +1 -1
index a2eef507ffbb..635744a76884 100644
@@ -28,7 +28,7 @@
 
 		flash_memory: region@98000000 {
 			no-map;
-			reg = <0x98000000 0x04000000>; /* 64M */
+			reg = <0x99000000 0x04000000>; /* 64M */
 		};
 
 		coldfire_memory: codefire_memory@9ef00000 {
drivers/soc/aspeed/aspeed-lpc-ctrl.c +13 -0
index 12e4421dee37..f4ac14c40518 100644
@@ -4,6 +4,7 @@
  */
 
 #include <linux/clk.h>
+#include <linux/log2.h>
 #include <linux/mfd/syscon.h>
 #include <linux/miscdevice.h>
 #include <linux/mm.h>
@@ -241,6 +242,18 @@ static int aspeed_lpc_ctrl_probe(struct platform_device *pdev)
 
 		lpc_ctrl->mem_size = resource_size(&resm);
 		lpc_ctrl->mem_base = resm.start;
+
+		if (!is_power_of_2(lpc_ctrl->mem_size)) {
+			dev_err(dev, "Reserved memory size must be a power of 2, got %zu\n",
+			       lpc_ctrl->mem_size);
+			return -EINVAL;
+		}
+
+		if (!IS_ALIGNED(lpc_ctrl->mem_base, lpc_ctrl->mem_size)) {
+			dev_err(dev, "Reserved memory must be naturally aligned for size %zu\n",
+			       lpc_ctrl->mem_size);
+			return -EINVAL;
+		}
 	}
 
 	lpc_ctrl->regmap = syscon_node_to_regmap(
Signature · 1 line
2.20.1
#1 lore raw
Quoted 17 lines · Andrew Jeffery

Alignment is a hardware constraint of the LPC2AHB bridge, and misaligned reserved memory will present as corrupted data.

---
v2: Cosmetic fixes pointed out by Milton

 arch/arm/boot/dts/aspeed-bmc-opp-romulus.dts |  2 +-
 drivers/soc/aspeed/aspeed-lpc-ctrl.c         | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
arch/arm/boot/dts/aspeed-bmc-opp-romulus.dts +0 -0
index a2eef507ffbb..635744a76884 100644

arch/arm/boot/dts/aspeed-bmc-opp-romulus.dts line 33

Quoted 7 lines
arch/arm/boot/dts/aspeed-bmc-opp-romulus.dts +1 -1
@@ -28,7 +28,7 @@
 
 		flash_memory: region@98000000 {
 			no-map;
-			reg = <0x98000000 0x04000000>; /* 64M */
+			reg = <0x99000000 0x04000000>; /* 64M */
 		};
 

Agh, v3 inbound.