Merge remote-tracking branch 'feature-ipc' into 'master'

* Remote feature-ipc: (31 commits)
  Platform: Correct region name
  Core: Add ZI and RW regions for seucre data in memory check
  Core: free connection handle in psa_reply
  Core: Support set reverse handle during connecting
  Core: Fix thread list handling
  Core: Config isolation for partitions with PSA API
  Core: Implement the IPC Secure Client API
  Core: Implement PSA service functions
  Core: Add memory check function for IPC
  Core: Adapt PSA API veneer with implemented handler
  Platform: Align region name in armclang and gcc
  Core: Add secure partition manager for IPC
  Core: Enhance manifest to align with PSA
  Core: Add IPC Client and Service Secure Partition
  Core: Add list, message queue, and pool functions
  Core: Fundamental components for secure IPC
  Core: Update IPC implementation framework
  Core: Align with PSA FF specification 1.0-beta-0
  Crypto: Conditional reference PSA types by PSA FF version
  Cmake: Disable regression tests for IPC configuration
  ...

Change-Id: I6527765ab71fe30e7e9fe93c705d899730970789
Signed-off-by: Edison Ai <edison.ai@arm.com>
diff --git a/secure_fw/spm/spm_api.c b/secure_fw/spm/spm_api.c
index efc4306..ff4eb11 100644
--- a/secure_fw/spm/spm_api.c
+++ b/secure_fw/spm/spm_api.c
@@ -118,7 +118,7 @@
             g_spm_partition_db.partition_count]);
     part_ptr->static_data.partition_id = TFM_SP_CORE_ID;
     part_ptr->static_data.partition_flags =
-                    SPM_PART_FLAG_SECURE | SPM_PART_FLAG_TRUSTED;
+                    SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_PSA_ROT;
     part_ptr->runtime_data.partition_state = SPM_PARTITION_STATE_UNINIT;
     ++g_spm_partition_db.partition_count;
 
@@ -142,6 +142,11 @@
     for (idx = 0; idx < g_spm_partition_db.partition_count; ++idx) {
         part = &g_spm_partition_db.partitions[idx];
         tfm_spm_hal_configure_default_isolation(part->platform_data);
+#ifdef TFM_PSA_API
+        if (part->static_data.partition_flags & SPM_PART_FLAG_IPC) {
+            continue;
+        }
+#endif
         if (part->static_data.partition_init == NULL) {
             tfm_spm_partition_set_state(idx, SPM_PARTITION_STATE_IDLE);
             tfm_spm_partition_set_caller_partition_idx(idx,
diff --git a/secure_fw/spm/spm_api.h b/secure_fw/spm/spm_api.h
index 0fa4c86..89d4564 100644
--- a/secure_fw/spm/spm_api.h
+++ b/secure_fw/spm/spm_api.h
@@ -33,8 +33,9 @@
 };
 
 enum spm_part_flag_mask_t {
-    SPM_PART_FLAG_SECURE  = 0x01,
-    SPM_PART_FLAG_TRUSTED = 0x02,
+    SPM_PART_FLAG_APP_ROT = 0x01,
+    SPM_PART_FLAG_PSA_ROT = 0x02,
+    SPM_PART_FLAG_IPC     = 0x04
 };
 
 /**
diff --git a/secure_fw/spm/spm_db.h b/secure_fw/spm/spm_db.h
index 512ede1..6b28f94 100644
--- a/secure_fw/spm/spm_db.h
+++ b/secure_fw/spm/spm_db.h
@@ -8,8 +8,37 @@
 #ifndef __SPM_DB_H__
 #define __SPM_DB_H__
 
+
+#ifdef TFM_PSA_API
+#include "tfm_thread.h"
+#endif
+
+struct spm_partition_desc_t;
+struct spm_partition_db_t;
+
 typedef psa_status_t(*sp_init_function)(void);
 
+#define TFM_PARTITION_TYPE_APP   "APPLICATION-ROT"
+#define TFM_PARTITION_TYPE_PSA   "PSA-ROT"
+
+#define TFM_STACK_SIZE  1024
+
+#ifdef TFM_PSA_API
+enum tfm_partition_priority {
+    TFM_PRIORITY_LOW = THRD_PRIOR_LOWEST,
+    TFM_PRIORITY_NORMAL = THRD_PRIOR_MEDIUM,
+    TFM_PRIORITY_HIGH = THRD_PRIOR_HIGHEST,
+};
+#else
+enum tfm_partition_priority {
+    TFM_PRIORITY_LOW = 0xFF,
+    TFM_PRIORITY_NORMAL = 0x7F,
+    TFM_PRIORITY_HIGH = 0,
+};
+#endif
+
+#define TFM_PRIORITY(LEVEL)      TFM_PRIORITY_##LEVEL
+
 /**
  * Holds the fields of the partition DB used by the SPM code. The values of
  * these fields are calculated at compile time, and set during initialisation
@@ -18,6 +47,7 @@
 struct spm_partition_static_data_t {
     uint32_t partition_id;
     uint32_t partition_flags;
+    uint32_t partition_priority;
     sp_init_function partition_init;
 };
 
@@ -32,6 +62,15 @@
 #if TFM_LVL != 1
     struct tfm_spm_partition_memory_data_t memory_data;
 #endif
+#ifdef TFM_PSA_API
+    struct tfm_thrd_ctx sp_thrd;
+    /*
+     * FixMe: Hard code stack is not aligned with the definition in the
+     * manifest. It will use the partition stacks in the linker scripts/sct
+     * files include Level 1 to 3.
+     */
+    uint8_t stack[TFM_STACK_SIZE] __attribute__((aligned(8)));
+#endif
 };
 
 /* Macros to pick linker symbols and allow to form the partition data base */
diff --git a/secure_fw/spm/spm_db_setup.h b/secure_fw/spm/spm_db_setup.h
index f4102cf1..d79fed9 100644
--- a/secure_fw/spm/spm_db_setup.h
+++ b/secure_fw/spm/spm_db_setup.h
@@ -31,10 +31,11 @@
     struct spm_partition_desc_t partitions[SPM_MAX_PARTITIONS];
 };
 
-#define PARTITION_INIT_STATIC_DATA(data, partition, flags) \
-    do {                                                   \
-        data.partition_id    = partition##_ID;             \
-        data.partition_flags = flags;                      \
+#define PARTITION_INIT_STATIC_DATA(data, partition, flags, id, priority)      \
+    do {                                                                      \
+        data.partition_id    = partition##_ID;                                \
+        data.partition_flags = flags;                                         \
+        data.partition_priority = TFM_PRIORITY(priority);                     \
     } while (0)
 
 #if TFM_LVL == 1
@@ -75,7 +76,7 @@
     } while (0)
 #endif
 
-#define PARTITION_DECLARE(partition, flags)                                  \
+#define PARTITION_DECLARE(partition, flag, type, id, priority)               \
     do {                                                                     \
         REGION_DECLARE(Image$$, partition, $$Base);                          \
         REGION_DECLARE(Image$$, partition, $$Limit);                         \
@@ -87,13 +88,24 @@
         REGION_DECLARE(Image$$, partition, _DATA$$ZI$$Limit);                \
         REGION_DECLARE(Image$$, partition, _STACK$$ZI$$Base);                \
         REGION_DECLARE(Image$$, partition, _STACK$$ZI$$Limit);               \
+        int32_t flags = flag;                                                \
+        if (tfm_memcmp(type, TFM_PARTITION_TYPE_APP,                         \
+            strlen(TFM_PARTITION_TYPE_APP)) == 0) {                          \
+            flags |= SPM_PART_FLAG_APP_ROT;                                  \
+        } else if (tfm_memcmp(type, TFM_PARTITION_TYPE_PSA,                  \
+                   strlen(TFM_PARTITION_TYPE_PSA)) == 0) {                   \
+            flags |= SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_APP_ROT;          \
+        } else {                                                             \
+            return SPM_ERR_INVALID_CONFIG;                                   \
+        }                                                                    \
         struct spm_partition_desc_t *part_ptr;                               \
         if (g_spm_partition_db.partition_count >= SPM_MAX_PARTITIONS) {      \
             return SPM_ERR_INVALID_CONFIG;                                   \
         }                                                                    \
         part_ptr = &(g_spm_partition_db.partitions[                          \
             g_spm_partition_db.partition_count]);                            \
-        PARTITION_INIT_STATIC_DATA(part_ptr->static_data, partition, flags); \
+        PARTITION_INIT_STATIC_DATA(part_ptr->static_data, partition, flags,  \
+                                   id, priority);                            \
         PARTITION_INIT_RUNTIME_DATA(part_ptr->runtime_data, partition);      \
         PARTITION_INIT_MEMORY_DATA(part_ptr->memory_data, partition);        \
         ++g_spm_partition_db.partition_count;                                \