From 106258e89a1f6c10534c13becdfbd52c6acfc955 Mon Sep 17 00:00:00 2001 From: Ye Li Date: Fri, 10 Nov 2017 01:49:56 -0600 Subject: MLK-16797 imx8qm/qxp: Fix memory bank size calculation issue The calculation of memory bank size is wrong when the memory on the board is less than 2GB. It causes memory bank exceeding the real DDR end, and cause crash in kernel. Fix the issue in this patch. Signed-off-by: Ye Li Reviewed-by: Peng Fan (cherry picked from commit 58f55994a406694460767566395e7c160738d431) --- arch/arm/cpu/armv8/imx8/cpu.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/arm/cpu/armv8/imx8/cpu.c b/arch/arm/cpu/armv8/imx8/cpu.c index 9f290258b8..06cd49aa34 100644 --- a/arch/arm/cpu/armv8/imx8/cpu.c +++ b/arch/arm/cpu/armv8/imx8/cpu.c @@ -1105,7 +1105,7 @@ phys_size_t get_effective_memsize(void) if (start >= PHYS_SDRAM_1 && start <= ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE) && (start <= CONFIG_SYS_TEXT_BASE && CONFIG_SYS_TEXT_BASE <= end)){ if ((end + 1) <= ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE)) - return (end - start + 1); + return (end - PHYS_SDRAM_1 + 1); else return PHYS_SDRAM_1_SIZE; } @@ -1133,14 +1133,14 @@ int dram_init(void) if ((end + 1) <= ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE)) gd->ram_size += end - start + 1; else - gd->ram_size += PHYS_SDRAM_1_SIZE; + gd->ram_size += ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE) - start; } else if (start >= PHYS_SDRAM_2 && start <= ((sc_faddr_t)PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE)) { if ((end + 1) <= ((sc_faddr_t)PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE)) gd->ram_size += end - start + 1; else - gd->ram_size += PHYS_SDRAM_2_SIZE; + gd->ram_size += ((sc_faddr_t)PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE) - start; } } } @@ -1193,7 +1193,7 @@ void dram_init_banksize(void) if ((end + 1) <= ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE)) gd->bd->bi_dram[i].size = end - start + 1; else - gd->bd->bi_dram[i].size = PHYS_SDRAM_1_SIZE; + gd->bd->bi_dram[i].size = ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE) - start; dram_bank_sort(i); i++; @@ -1203,7 +1203,7 @@ void dram_init_banksize(void) if ((end + 1) <= ((sc_faddr_t)PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE)) gd->bd->bi_dram[i].size = end - start + 1; else - gd->bd->bi_dram[i].size = PHYS_SDRAM_2_SIZE; + gd->bd->bi_dram[i].size = ((sc_faddr_t)PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE) - start; dram_bank_sort(i); i++; @@ -1234,12 +1234,12 @@ static u64 get_block_size(sc_faddr_t addr_start, sc_faddr_t addr_end) { if (addr_start >= PHYS_SDRAM_1 && addr_start <= ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE)) { if ((addr_end + 1) > ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE)) - return PHYS_SDRAM_1_SIZE; + return ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE) - addr_start; } else if (addr_start >= PHYS_SDRAM_2 && addr_start <= ((sc_faddr_t)PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE)) { if ((addr_end + 1) > ((sc_faddr_t)PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE)) - return PHYS_SDRAM_2_SIZE; + return ((sc_faddr_t)PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE) - addr_start; } return (addr_end - addr_start + 1); -- cgit v1.2.3