platform: msm_shared: Add support for smem_ram_ptable_v1
Add support for smem_ram_ptable_v1 to support 64 bit addresses.
Created new accessor apis to query smem for version, length of ptable
and new apis to read and copy the ram_ptable.
Change-Id: I3ec94caa32a766f5a34aef39f26d800a338de67f
diff --git a/platform/msm_shared/smem.h b/platform/msm_shared/smem.h
old mode 100755
new mode 100644
index 0f032dd..ae105e7
--- a/platform/msm_shared/smem.h
+++ b/platform/msm_shared/smem.h
@@ -37,6 +37,20 @@
#define SMEM_V8_SMEM_MAX_PMIC_DEVICES 3
#define SMEM_MAX_PMIC_DEVICES SMEM_V8_SMEM_MAX_PMIC_DEVICES
+#define SMEM_RAM_PTABLE_VERSION_OFFSET 8
+
+#define RAM_PART_NAME_LENGTH 16
+#define RAM_NUM_PART_ENTRIES 32
+
+#define _SMEM_RAM_PTABLE_MAGIC_1 0x9DA5E0A8
+#define _SMEM_RAM_PTABLE_MAGIC_2 0xAF9EC4E2
+
+enum smem_ram_ptable_version
+{
+ SMEM_RAM_PTABLE_VERSION_0,
+ SMEM_RAM_PTABLE_VERSION_1,
+};
+
struct smem_proc_comm {
unsigned command;
unsigned status;
@@ -437,28 +451,33 @@
struct smem_ram_ptn {
char name[16];
- unsigned start;
- unsigned size;
+ uint32_t start;
+ uint32_t size;
+ uint32_t attr; /* RAM Partition attribute: READ_ONLY, READWRITE etc.*/
+ uint32_t category; /* RAM Partition category: EBI0, EBI1, IRAM, IMEM */
+ uint32_t domain; /* RAM Partition domain: APPS, MODEM, APPS & MODEM (SHARED) etc. */
+ uint32_t type; /* RAM Partition type: system, bootloader, appsboot, apps etc. */
+ uint32_t num_partitions;/* Number of memory partitions */
+ uint32_t reserved3;
+ uint32_t reserved4;
+ uint32_t reserved5;
+} __attribute__ ((__packed__));
- /* RAM Partition attribute: READ_ONLY, READWRITE etc. */
- unsigned attr;
-
- /* RAM Partition category: EBI0, EBI1, IRAM, IMEM */
- unsigned category;
-
- /* RAM Partition domain: APPS, MODEM, APPS & MODEM (SHARED) etc. */
- unsigned domain;
-
- /* RAM Partition type: system, bootloader, appsboot, apps etc. */
- unsigned type;
-
- /* reserved for future expansion without changing version number */
- unsigned reserved2, reserved3, reserved4, reserved5;
+struct smem_ram_ptn_v1 {
+ char name[RAM_PART_NAME_LENGTH];
+ uint64_t start;
+ uint64_t size;
+ uint32_t attr; /* RAM Partition attribute: READ_ONLY, READWRITE etc.*/
+ uint32_t category; /* RAM Partition category: EBI0, EBI1, IRAM, IMEM */
+ uint32_t domain; /* RAM Partition domain: APPS, MODEM, APPS & MODEM (SHARED) etc. */
+ uint32_t type; /* RAM Partition type: system, bootloader, appsboot, apps etc. */
+ uint32_t num_partitions;/* Number of memory partitions */
+ uint32_t reserved3;
+ uint32_t reserved4; /* Reserved for future use */
+ uint32_t reserved5; /* Reserved for future use */
} __attribute__ ((__packed__));
struct smem_ram_ptable {
-#define _SMEM_RAM_PTABLE_MAGIC_1 0x9DA5E0A8
-#define _SMEM_RAM_PTABLE_MAGIC_2 0xAF9EC4E2
unsigned magic[2];
unsigned version;
unsigned reserved1;
@@ -467,6 +486,20 @@
unsigned buf;
} __attribute__ ((__packed__));
+struct smem_ram_ptable_hdr
+{
+ uint32_t magic[2];
+ uint32_t version;
+ uint32_t reserved1;
+ uint32_t len;
+} __attribute__ ((__packed__));
+
+struct smem_ram_ptable_v1 {
+ struct smem_ram_ptable_hdr hdr;
+ uint32_t reserved2; /* Added for 8 bytes alignment of header */
+ struct smem_ram_ptn_v1 parts[RAM_NUM_PART_ENTRIES];
+} __attribute__ ((__packed__));
+
/* Power on reason/status info */
#define PWR_ON_EVENT_RTC_ALARM 0x2
#define PWR_ON_EVENT_USB_CHG 0x20
@@ -495,7 +528,13 @@
struct smem_ptn parts[SMEM_PTABLE_MAX_PARTS];
} __attribute__ ((__packed__));
+typedef struct smem_ram_ptable_v1 ram_partition_table;
+typedef struct smem_ram_ptn_v1 ram_partition;
+
unsigned smem_read_alloc_entry_offset(smem_mem_type_t type, void *buf, int len, int offset);
int smem_ram_ptable_init(struct smem_ram_ptable *smem_ram_ptable);
-
+int smem_ram_ptable_init_v1(); /* Used on platforms that use ram ptable v1 */
+void smem_get_ram_ptable_entry(ram_partition*, uint32_t entry);
+uint32_t smem_get_ram_ptable_version(void);
+uint32_t smem_get_ram_ptable_len(void);
#endif /* __PLATFORM_MSM_SHARED_SMEM_H */
diff --git a/platform/msm_shared/smem_ptable.c b/platform/msm_shared/smem_ptable.c
index 291b242..6ec563a 100644
--- a/platform/msm_shared/smem_ptable.c
+++ b/platform/msm_shared/smem_ptable.c
@@ -42,6 +42,8 @@
static struct smem_ptable smem_ptable;
static unsigned smem_apps_flash_start = 0xFFFFFFFF;
+static ram_partition_table ptable;
+
static void dump_smem_ptable(void)
{
unsigned i;
@@ -150,6 +152,44 @@
}
}
+static void smem_copy_ram_ptable(void *buf)
+{
+ struct smem_ram_ptable *table_v0;
+ struct smem_ram_ptable_v1 *table_v1;
+ uint32_t pentry = 0;
+
+ ptable.hdr = *(struct smem_ram_ptable_hdr*)buf;
+
+ /* Perform member to member copy from smem_ram_ptable to wrapper struct ram_ptable */
+ if(ptable.hdr.version == SMEM_RAM_PTABLE_VERSION_1)
+ {
+ table_v1 = (struct smem_ram_ptable_v1*)buf;
+
+ memcpy(&ptable, table_v1, sizeof(ram_partition_table));
+ }
+ else if(ptable.hdr.version == SMEM_RAM_PTABLE_VERSION_0)
+ {
+ table_v0 = (struct smem_ram_ptable*)buf;
+
+ for(pentry = 0; pentry < ((struct smem_ram_ptable_hdr*)buf)->len; pentry++)
+ {
+ ptable.parts[pentry].start = table_v0->parts[pentry].start;
+ ptable.parts[pentry].size = table_v0->parts[pentry].size;
+ ptable.parts[pentry].attr = table_v0->parts[pentry].attr;
+ ptable.parts[pentry].category = table_v0->parts[pentry].category;
+ ptable.parts[pentry].domain = table_v0->parts[pentry].domain;
+ ptable.parts[pentry].type = table_v0->parts[pentry].type;
+ ptable.parts[pentry].num_partitions = table_v0->parts[pentry].num_partitions;
+ }
+
+ }
+ else
+ {
+ dprintf(CRITICAL,"ERROR: Unknown smem ram ptable version: %u", ptable.hdr.version);
+ ASSERT(0);
+ }
+}
+
/* RAM Partition table from SMEM */
int smem_ram_ptable_init(struct smem_ram_ptable *smem_ram_ptable)
{
@@ -168,5 +208,71 @@
dprintf(SPEW, "smem ram ptable found: ver: %d len: %d\n",
smem_ram_ptable->version, smem_ram_ptable->len);
+ smem_copy_ram_ptable((void*)smem_ram_ptable);
+
return 1;
}
+
+/* RAM Partition table from SMEM */
+static uint32_t buffer[sizeof(struct smem_ram_ptable_v1)];
+int smem_ram_ptable_init_v1()
+{
+ uint32_t i;
+ uint32_t ret;
+ uint32_t version;
+ uint32_t smem_ram_ptable_size;
+ struct smem_ram_ptable_hdr *ram_ptable_hdr;
+
+ /* Check smem ram partition table version and decide on length of ram_ptable */
+ ret = smem_read_alloc_entry_offset(SMEM_USABLE_RAM_PARTITION_TABLE,
+ &version,
+ sizeof(version),
+ SMEM_RAM_PTABLE_VERSION_OFFSET);
+
+ if(ret)
+ return 0;
+
+ if(version == SMEM_RAM_PTABLE_VERSION_1)
+ smem_ram_ptable_size = sizeof(struct smem_ram_ptable_v1);
+ else if(version == SMEM_RAM_PTABLE_VERSION_0)
+ smem_ram_ptable_size = sizeof(struct smem_ram_ptable);
+ else
+ {
+ dprintf(CRITICAL,"ERROR: Wrong smem_ram_ptable version: %u", version);
+ ASSERT(0);
+ }
+
+ i = smem_read_alloc_entry(SMEM_USABLE_RAM_PARTITION_TABLE,
+ (void*)buffer,
+ smem_ram_ptable_size);
+ if (i != 0)
+ return 0;
+
+ ram_ptable_hdr = (struct smem_ram_ptable_hdr *)buffer;
+
+ if (ram_ptable_hdr->magic[0] != _SMEM_RAM_PTABLE_MAGIC_1 ||
+ ram_ptable_hdr->magic[1] != _SMEM_RAM_PTABLE_MAGIC_2)
+ return 0;
+
+ smem_copy_ram_ptable((void*)buffer);
+
+ dprintf(SPEW, "smem ram ptable found: ver: %u len: %u\n",
+ ram_ptable_hdr->version, ram_ptable_hdr->len);
+
+ return 1;
+}
+
+void smem_get_ram_ptable_entry(ram_partition *ptn, uint32_t entry)
+{
+ memcpy(ptn, &(ptable.parts[entry]), sizeof(ram_partition));
+}
+
+uint32_t smem_get_ram_ptable_len(void)
+{
+ return ptable.hdr.len;
+}
+
+uint32_t smem_get_ram_ptable_version(void)
+{
+ return ptable.hdr.version;
+}