platform: project: msm8996: Add support for 6gb ddr

Add support for 6gb ddr and update the kernel load address based on the
size of the ddr.

CRs-Fixed: 961081
Change-Id: I460aa3c87d3d1f45492a854527d25c190de535c9
diff --git a/include/platform.h b/include/platform.h
index 945ed27..07b1c04 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -87,4 +87,5 @@
 bool is_device_locked();
 bool platform_is_mdmcalifornium();
 bool platform_is_sdxhedgehog();
+uint64_t platform_get_ddr_start();
 #endif
diff --git a/platform/msm8996/include/platform/iomap.h b/platform/msm8996/include/platform/iomap.h
index 3a3b12b..1b90c86 100644
--- a/platform/msm8996/include/platform/iomap.h
+++ b/platform/msm8996/include/platform/iomap.h
@@ -681,4 +681,10 @@
 #define LPASS_LPAIF_RDDMA_BUFF_LEN0  0x0910D008
 #define LPASS_LPAIF_RDDMA_PER_LEN0   0x0910D010
 #define LPASS_LPAIF_DEBUG_CTL        0x0910000C
+
+#define DDR_START                    platform_get_ddr_start()
+#define ABOOT_FORCE_KERNEL_ADDR      (DDR_START + 0x8000)
+#define ABOOT_FORCE_RAMDISK_ADDR     (DDR_START + 0x2200000)
+#define ABOOT_FORCE_TAGS_ADDR        (DDR_START + 0x2000000)
+#define ABOOT_FORCE_KERNEL64_ADDR    (DDR_START + 0x80000)
 #endif
diff --git a/platform/msm8996/platform.c b/platform/msm8996/platform.c
index 0542cdc..8ef3df2 100644
--- a/platform/msm8996/platform.c
+++ b/platform/msm8996/platform.c
@@ -68,7 +68,7 @@
 /*       Physical addr,    Virtual addr,     Mapping type ,              Size (in MB),            Flags */
     {    0x00000000,        0x00000000,       MMU_L2_NS_SECTION_MAPPING,  512,                IOMAP_MEMORY},
     {    MEMBASE,           MEMBASE,          MMU_L2_NS_SECTION_MAPPING,  (MEMSIZE / MB),      LK_MEMORY},
-    {    KERNEL_ADDR,       KERNEL_ADDR,      MMU_L2_NS_SECTION_MAPPING,  KERNEL_SIZE,         SCRATCH_MEMORY},
+    {    MIPI_FB_ADDR,      MIPI_FB_ADDR,     MMU_L2_NS_SECTION_MAPPING,  40,                  LK_MEMORY},
     {    SCRATCH_ADDR,      SCRATCH_ADDR,     MMU_L2_NS_SECTION_MAPPING,  SCRATCH_SIZE,        SCRATCH_MEMORY},
     {    MSM_SHARED_BASE,   MSM_SHARED_BASE,  MMU_L2_NS_SECTION_MAPPING,  MSM_SHARED_SIZE,     COMMON_MEMORY},
     {    RPMB_SND_RCV_BUF,  RPMB_SND_RCV_BUF, MMU_L2_NS_SECTION_MAPPING,  RPMB_SND_RCV_BUF_SZ, IOMAP_MEMORY},
@@ -115,6 +115,30 @@
 {
 	int i;
 	int table_sz = ARRAY_SIZE(default_mmu_section_table);
+	mmu_section_t kernel_mmu_section_table;
+	uint64_t ddr_size = smem_get_ddr_size();
+
+	switch(ddr_size)
+	{
+		case MEM_4GB:
+		case MEM_3GB:
+			ddr_start = 0x80000000;
+			break;
+		case MEM_6GB:
+			ddr_start = 0x40000000;
+			break;
+		default:
+			dprintf(CRITICAL, "Unsupported ddr\n");
+			ASSERT(0);
+	};
+
+	kernel_mmu_section_table.paddress = ddr_start;
+	kernel_mmu_section_table.vaddress = ddr_start;
+	kernel_mmu_section_table.type = MMU_L2_NS_SECTION_MAPPING;
+	kernel_mmu_section_table.size = 88;
+	kernel_mmu_section_table.flags = SCRATCH_MEMORY;
+
+	arm_mmu_map_entry(&kernel_mmu_section_table);
 
 	/* Map default memory needed for lk , scratch, rpmb & iomap */
 	for (i = 0 ; i < table_sz; i++)
diff --git a/platform/msm_shared/include/mmu.h b/platform/msm_shared/include/mmu.h
index 9154066..f6579a4 100644
--- a/platform/msm_shared/include/mmu.h
+++ b/platform/msm_shared/include/mmu.h
@@ -32,6 +32,7 @@
 #include <sys/types.h>
 #include <arch/arm/mmu.h>
 
+#define MEM_6GB      0x180000000
 #define MEM_4GB      0x100000000
 #define MEM_3GB      0xC0000000
 
diff --git a/project/msm8996.mk b/project/msm8996.mk
index de818bb..2147ba6 100644
--- a/project/msm8996.mk
+++ b/project/msm8996.mk
@@ -37,11 +37,6 @@
 
 DEFINES += ABOOT_IGNORE_BOOT_HEADER_ADDRS=1
 
-DEFINES += ABOOT_FORCE_KERNEL_ADDR=0x80080000
-DEFINES += ABOOT_FORCE_RAMDISK_ADDR=0x82200000
-DEFINES += ABOOT_FORCE_TAGS_ADDR=0x82000000
-DEFINES += ABOOT_FORCE_KERNEL64_ADDR=0x80080000
-
 DEFINES += USB_RESET_FROM_CLK=1
 DEFINES += USE_BOOTDEV_CMDLINE=1
 DEFINES += ENABLE_WBC=1
diff --git a/target/msm8996/rules.mk b/target/msm8996/rules.mk
index a261eb5..bfb8ff1 100644
--- a/target/msm8996/rules.mk
+++ b/target/msm8996/rules.mk
@@ -51,8 +51,6 @@
 	BASE_ADDR=$(BASE_ADDR) \
 	TAGS_ADDR=$(TAGS_ADDR) \
 	RAMDISK_ADDR=$(RAMDISK_ADDR) \
-	KERNEL_ADDR=$(KERNEL_ADDR) \
-	KERNEL_SIZE=$(KERNEL_SIZE) \
 	SCRATCH_ADDR=$(SCRATCH_ADDR) \
 	SCRATCH_SIZE=$(SCRATCH_SIZE) \
 	L1_PT_SZ=$(L1_PT_SZ) \