diff mbox series

[U-Boot] armv8: fsl-layerscape: Fix MC reserved memory calculation

Message ID 1504815409-27339-1-git-send-email-york.sun@nxp.com
State Accepted
Commit e9303a4146cdc1761c8156627a8265e43dc0dc58
Delegated to: York Sun
Headers show
Series [U-Boot] armv8: fsl-layerscape: Fix MC reserved memory calculation | expand

Commit Message

York Sun Sept. 7, 2017, 8:16 p.m. UTC
In case high region memory doesn't have enough space for Management
Complex (MC), the return value should indicate a failure so the
caller can handle it accordingly.

Signed-off-by: York Sun <york.sun@nxp.com>
Reported-by: Ebony Zhu <ebony.zhu@nxp.com>
---

 arch/arm/cpu/armv8/fsl-layerscape/cpu.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

Comments

York Sun Sept. 13, 2017, 2:35 a.m. UTC | #1
On 09/07/2017 01:17 PM, York Sun wrote:
> In case high region memory doesn't have enough space for Management
> Complex (MC), the return value should indicate a failure so the
> caller can handle it accordingly.
> 
> Signed-off-by: York Sun <york.sun@nxp.com>
> Reported-by: Ebony Zhu <ebony.zhu@nxp.com>
> ---

Applied to fsl-qoriq master.

York
diff mbox series

Patch

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
index 3c9a5ed..d21a494 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
@@ -619,13 +619,22 @@  void efi_reset_system_init(void)
 
 #endif
 
+/*
+ * Calculate reserved memory with given memory bank
+ * Return aligned memory size on success
+ * Return (ram_size + needed size) for failure
+ */
 phys_size_t board_reserve_ram_top(phys_size_t ram_size)
 {
 	phys_size_t ram_top = ram_size;
 
 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
+	ram_top = mc_get_dram_block_size();
+	if (ram_top > ram_size)
+		return ram_size + ram_top;
+
+	ram_top = ram_size - ram_top;
 	/* The start address of MC reserved memory needs to be aligned. */
-	ram_top -= mc_get_dram_block_size();
 	ram_top &= ~(CONFIG_SYS_MC_RSV_MEM_ALIGN - 1);
 #endif
 
@@ -669,8 +678,8 @@  phys_size_t get_effective_memsize(void)
 	/* Check if we have enough memory for MC */
 	if (rem < board_reserve_ram_top(rem)) {
 		/* Not enough memory in high region to reserve */
-		if (ea_size > board_reserve_ram_top(rem))
-			ea_size -= board_reserve_ram_top(rem);
+		if (ea_size > board_reserve_ram_top(ea_size))
+			ea_size -= board_reserve_ram_top(ea_size);
 		else
 			printf("Error: No enough space for reserved memory.\n");
 	}