Core: Move thread context into runtime data struct

Move the struct tfm_thrd_ctx sp_thrd into struct
spm_partition_runtime_data_t runtime_data.

Change-Id: Id9dac3f509994029732855098baf1b03e21f5e2c
Signed-off-by: Summer Qin <summer.qin@arm.com>
diff --git a/secure_fw/spm/spm_api.h b/secure_fw/spm/spm_api.h
index 75b921c..aebcc5a 100644
--- a/secure_fw/spm/spm_api.h
+++ b/secure_fw/spm/spm_api.h
@@ -18,6 +18,7 @@
 #include "tfm_wait.h"
 #include "tfm_message_queue.h"
 #include "tfm_secure_api.h"
+#include "tfm_thread.h"
 #endif
 
 #define SPM_INVALID_PARTITION_IDX     (~0U)
@@ -86,6 +87,7 @@
     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                      */
+    struct tfm_thrd_ctx sp_thrd;        /* Thread context                    */
 #else /* TFM_PSA_API */
     uint32_t partition_state;
     uint32_t caller_partition_idx;
diff --git a/secure_fw/spm/spm_api_ipc.c b/secure_fw/spm/spm_api_ipc.c
index 7f773d2..6a7231f 100644
--- a/secure_fw/spm/spm_api_ipc.c
+++ b/secure_fw/spm/spm_api_ipc.c
@@ -376,16 +376,19 @@
 {
     struct tfm_thrd_ctx *pth = tfm_thrd_curr_thread();
     struct spm_partition_desc_t *partition;
+    struct spm_partition_runtime_data_t *r_data;
 
-    partition = TFM_GET_CONTAINER_PTR(pth, struct spm_partition_desc_t,
-                                      sp_thrd);
+    r_data = TFM_GET_CONTAINER_PTR(pth, struct spm_partition_runtime_data_t,
+                                   sp_thrd);
+    partition = TFM_GET_CONTAINER_PTR(r_data, struct spm_partition_desc_t,
+                                      runtime_data);
     return partition->static_data->partition_id;
 }
 
 static struct tfm_thrd_ctx *
     tfm_spm_partition_get_thread_info(uint32_t partition_idx)
 {
-    return &g_spm_partition_db.partitions[partition_idx].sp_thrd;
+    return &g_spm_partition_db.partitions[partition_idx].runtime_data.sp_thrd;
 }
 
 static tfm_thrd_func_t
@@ -525,6 +528,7 @@
 {
 #if TFM_LVL == 2
     struct spm_partition_desc_t *p_next_partition;
+    struct spm_partition_runtime_data_t *r_data;
     uint32_t is_privileged;
 #endif
     struct tfm_thrd_ctx *pth_next = tfm_thrd_next_thread();
@@ -532,9 +536,12 @@
 
     if (pth_next != NULL && pth_curr != pth_next) {
 #if TFM_LVL == 2
-        p_next_partition = TFM_GET_CONTAINER_PTR(pth_next,
+        r_data = TFM_GET_CONTAINER_PTR(pth_next,
+                                       struct spm_partition_runtime_data_t,
+                                       sp_thrd);
+        p_next_partition = TFM_GET_CONTAINER_PTR(r_data,
                                                  struct spm_partition_desc_t,
-                                                 sp_thrd);
+                                                 runtime_data);
 
         if (p_next_partition->static_data->partition_flags &
             SPM_PART_FLAG_PSA_ROT) {
diff --git a/secure_fw/spm/spm_db.h b/secure_fw/spm/spm_db.h
index 90e071c..8a907a4 100644
--- a/secure_fw/spm/spm_db.h
+++ b/secure_fw/spm/spm_db.h
@@ -8,11 +8,6 @@
 #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;
 
@@ -55,7 +50,6 @@
     const struct tfm_spm_partition_platform_data_t *platform_data;
 #if TFM_PSA_API
     const struct tfm_spm_partition_memory_data_t *memory_data;
-    struct tfm_thrd_ctx sp_thrd;
 #endif
 };