[msm7630] Add support to detect physical memory usable by apps proc

Modem bootloader places information about physical memory regions
that are usable by apps in shared memory.  This information is available
in shared memory before apps processor is brought out of reset.

Add support to read this "ram partition table" and check for physical
memory chunks that are set as read/write for apps processor, exclude the
apps bootloader area and give the rest to Linux kernel using atags.

As a result, if modem physical memory requirement reduces, then apps
bootloader does not have to change.  Apps can pick up the extra memory
made available by detecting this from ram partition table.

Change-Id: I6abd85cd57710ceda89d4f125e3dffc59e7078b7
diff --git a/target/msm7630_surf/atags.c b/target/msm7630_surf/atags.c
index 93cecd7..b5264ec 100644
--- a/target/msm7630_surf/atags.c
+++ b/target/msm7630_surf/atags.c
@@ -30,100 +30,70 @@
 #include <debug.h>
 #include <smem.h>
 
-#define EBI1_SIZE_60M         0x03C00000
-#define EBI1_ADDR_2M          0x00200000
-#define EBI0_SIZE_14M         0x00E00000
-#define EBI0_ADDR_114M        0x07200000
-#define EBI0_SIZE_8M          0x00800000
-#define EBI0_ADDR_120M        0x07800000
-#define EBI1_SIZE_128M        0x08000000
 #define EBI1_ADDR_128M        0x08000000
-#define EBI1_ADDR_1G          0x40000000
+#define SIZE_1M               0x00100000
 
-static int msm7x30_lpddr1 = -1;
-static int target_is_msm7x30_lpddr1(void);
-int target_is_emmc_boot(void);
 
-int target_is_msm7x30_lpddr1(void)
-{
-    struct smem_board_info_v4 board_info_v4;
-    unsigned int board_info_len = 0;
-    unsigned smem_status;
-    char *build_type;
-    unsigned format = 0;
-
-    if (msm7x30_lpddr1 != -1)
-    {
-        return msm7x30_lpddr1;
-    }
-
-    smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
-					       &format, sizeof(format), 0);
-    if(smem_status)
-    {
-      dprintf(CRITICAL, "ERROR: unable to read shared memory for offset entry\n");
-    }
-
-    if ((format == 3) || (format == 4))
-    {
-        if (format == 4)
-	    board_info_len = sizeof(board_info_v4);
-	else
-	    board_info_len = sizeof(board_info_v4.board_info_v3);
-
-        smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
-					&board_info_v4, board_info_len);
-        if(smem_status)
-        {
-            dprintf(CRITICAL, "ERROR: unable to read shared memory for Hardware Platform\n");
-        }
-    }
-
-    msm7x30_lpddr1 = 1;
-
-    build_type  = (char *)(board_info_v4.board_info_v3.build_id) + 8;
-    if (*build_type == 'A')
-    {
-        msm7x30_lpddr1 = 0;
-    }
-
-    return msm7x30_lpddr1;
-}
+static int scratch_addr = -1;
+int smem_ram_ptable_init(struct smem_ram_ptable *);
 
 unsigned* target_atag_mem(unsigned* ptr)
 {
-    /* ATAG_MEM for 51MB + [6MB if nand boot] + 128MB setup */
-    *ptr++ = 4;
-    *ptr++ = 0x54410002;
-    *ptr++ = EBI1_SIZE_60M;
-    *ptr++ = EBI1_ADDR_2M;
+    struct smem_ram_ptable ram_ptable;
+    unsigned i = 0;
 
-    /* Reclaim EFS partition used in EMMC for NAND boot */
-    if (target_is_emmc_boot())
+    if (smem_ram_ptable_init(&ram_ptable))
     {
-        *ptr++ = 4;
-        *ptr++ = 0x54410002;
-        *ptr++ = EBI0_SIZE_8M;
-        *ptr++ = EBI0_ADDR_120M;
+        for (i = 0; i < ram_ptable.len; i++)
+        {
+            if ((ram_ptable.parts[i].attr == READWRITE)
+                && (ram_ptable.parts[i].domain == APPS_DOMAIN)
+                && (ram_ptable.parts[i].start != 0x0)
+                && (!(ram_ptable.parts[i].size < SIZE_1M)))
+            {
+                /* ATAG_MEM */
+                *ptr++ = 4;
+                *ptr++ = 0x54410002;
+                *ptr++ = ram_ptable.parts[i].size;
+                *ptr++ = ram_ptable.parts[i].start;
+            }
+        }
     }
     else
     {
-        *ptr++ = 4;
-        *ptr++ = 0x54410002;
-        *ptr++ = EBI0_SIZE_14M;
-        *ptr++ = EBI0_ADDR_114M;
+        dprintf(CRITICAL, "ERROR: Unable to read RAM partition\n");
+        ASSERT(0);
     }
 
-    /* ATAG_MEM */
-    *ptr++ = 4;
-    *ptr++ = 0x54410002;
-    *ptr++ = EBI1_SIZE_128M;
-    *ptr++ = (target_is_msm7x30_lpddr1()) ? EBI1_ADDR_128M : EBI1_ADDR_1G;
-
     return ptr;
 }
 
 void *target_get_scratch_address(void)
 {
-    return (void *)((target_is_msm7x30_lpddr1()) ? EBI1_ADDR_128M : EBI1_ADDR_1G);
+    struct smem_ram_ptable ram_ptable;
+    unsigned i = 0;
+
+    if (smem_ram_ptable_init(&ram_ptable))
+    {
+        for (i = 0; i < ram_ptable.len; i++)
+        {
+            if ((ram_ptable.parts[i].attr == READWRITE)
+                && (ram_ptable.parts[i].domain == APPS_DOMAIN)
+                && (ram_ptable.parts[i].start != 0x0))
+            {
+                if (ram_ptable.parts[i].size >= FASTBOOT_BUF_SIZE)
+                {
+                    scratch_addr = ram_ptable.parts[i].start;
+                    break;
+                }
+            }
+        }
+    }
+    else
+    {
+        dprintf(CRITICAL, "ERROR: Unable to read RAM partition\n");
+        ASSERT(0);
+    }
+
+    return (void *)((scratch_addr == -1) ? EBI1_ADDR_128M : scratch_addr);
 }