Core: Merge IPC model SP data into library model

Merges the necessary secure partition data for IPC model into library
model. Prepare a common partition data structure for optimization.

Change-Id: I88939faa337588f14f351c284e5a9d625af37fa5
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 ffca849..3a3b2f8 100644
--- a/secure_fw/spm/spm_api.c
+++ b/secure_fw/spm/spm_api.c
@@ -23,6 +23,7 @@
 #define NON_SECURE_INTERNAL_PARTITION_DB_IDX 0
 #define TFM_CORE_INTERNAL_PARTITION_DB_IDX   1
 
+#ifndef TFM_PSA_API
 typedef enum {
     TFM_INIT_FAILURE,
 } sp_error_type_t;
@@ -44,6 +45,7 @@
     uint32_t partition_state;
     uint32_t caller_partition_idx;
 };
+#endif /* !defined(TFM_PSA_API) */
 
 /* Define SPM DB structure */
 #include "secure_fw/services/tfm_spm_db.inc"
@@ -96,11 +98,13 @@
 
 enum spm_err_t tfm_spm_db_init(void)
 {
-   struct spm_partition_desc_t *part_ptr;
+    struct spm_partition_desc_t *part_ptr;
+#ifndef TFM_PSA_API
     static uint32_t ns_interrupt_ctx_stack[
            sizeof(struct interrupted_ctx_stack_frame_t)/sizeof(uint32_t)] = {0};
     static uint32_t tfm_core_interrupt_ctx_stack[
            sizeof(struct interrupted_ctx_stack_frame_t)/sizeof(uint32_t)] = {0};
+#endif /* !defined(TFM_PSA_API) */
 
     /* This function initialises partition db */
 
@@ -137,8 +141,11 @@
     part_ptr->memory_data.rw_start     = psp_stack_bottom;
 #endif
 
+#ifndef TFM_PSA_API
     part_ptr->runtime_data.partition_state = SPM_PARTITION_STATE_UNINIT;
     part_ptr->runtime_data.ctx_stack_ptr = ns_interrupt_ctx_stack;
+#endif /* !defined(TFM_PSA_API) */
+
     tfm_nspm_configure_clients();
 
     /* For the TF-M core environment itself */
@@ -147,8 +154,10 @@
     part_ptr->static_data.partition_id = TFM_SP_CORE_ID;
     part_ptr->static_data.partition_flags =
                     SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_PSA_ROT;
+#ifndef TFM_PSA_API
     part_ptr->runtime_data.partition_state = SPM_PARTITION_STATE_UNINIT;
     part_ptr->runtime_data.ctx_stack_ptr = tfm_core_interrupt_ctx_stack;
+#endif /* !defined(TFM_PSA_API) */
 
     g_spm_partition_db.is_init = 1;
 
diff --git a/secure_fw/spm/spm_api.h b/secure_fw/spm/spm_api.h
index 565e708..adc57f2 100644
--- a/secure_fw/spm/spm_api.h
+++ b/secure_fw/spm/spm_api.h
@@ -12,6 +12,10 @@
 #include "tfm_api.h"
 #include "spm_partition_defs.h"
 #include "secure_fw/core/tfm_secure_api.h"
+#ifdef TFM_PSA_API
+#include "tfm_list.h"
+#include "tfm_wait.h"
+#endif
 
 #define SPM_INVALID_PARTITION_IDX     (~0U)
 
@@ -40,6 +44,7 @@
 #define SPM_PART_FLAG_PSA_ROT 0x02
 #define SPM_PART_FLAG_IPC     0x04
 
+#ifndef TFM_PSA_API
 /**
  * \brief Holds the iovec parameters that are passed to a service
  *
@@ -53,11 +58,17 @@
     size_t out_len;                    /*!< Number psa_outvec objects in out_vec
                                         */
 };
+#endif /* !define(TFM_PSA_API) */
 
 /**
  * \brief Runtime context information of a partition
  */
 struct spm_partition_runtime_data_t {
+#ifdef TFM_PSA_API
+    struct tfm_event_t signal_evnt;     /* Event signal                      */
+    uint32_t signals;                   /* Service signals had been triggered*/
+    struct tfm_list_node_t service_list;/* Service list                      */
+#else /* TFM_PSA_API */
     uint32_t partition_state;
     uint32_t caller_partition_idx;
     int32_t caller_client_id;
@@ -72,15 +83,11 @@
     struct iovec_args_t iovec_args;
     psa_outvec *orig_outvec;
     uint32_t *ctx_stack_ptr;
-    /*
-     * FIXME: There is a 'signal_mask' defined in the structure
-     * 'tfm_spm_ipc_partition_t'. It should be eliminated, and the IPC
-     * implementation should use the 'signal_mask' define in this structure.
-     * However currently the content of 'spm_partition_runtime_data_t' structure
-     * is not maintained by the IPC implementation. This is to be fixed with the
-     * effort of restructuring common code among library and IPC model.
-     */
-    uint32_t signal_mask;
+#endif /* TFM_PSA_API */
+    uint32_t signal_mask;               /*
+                                         * Service signal mask passed by
+                                         * psa_wait()
+                                         */
 };
 
 
diff --git a/secure_fw/spm/spm_db.h b/secure_fw/spm/spm_db.h
index 8b1a00b..7b74aba 100644
--- a/secure_fw/spm/spm_db.h
+++ b/secure_fw/spm/spm_db.h
@@ -39,6 +39,7 @@
  * phase.
  */
 struct spm_partition_static_data_t {
+    int32_t index;                      /* Partition index */
     uint32_t partition_id;
     uint32_t partition_flags;
     uint32_t partition_priority;
@@ -64,7 +65,9 @@
 struct spm_partition_db_t {
     uint32_t is_init;
     uint32_t partition_count;
+#ifndef TFM_PSA_API
     uint32_t running_partition_idx;
+#endif /* !defined(TFM_PSA_API) */
     struct spm_partition_desc_t *partitions;
 };