SPM: Separate SPM data structure definitions

Currently IPC and library model use common SPM data structure
definitions in "spm_db.h". To prepare for SPM HAL data structure,
deleting head file "spm_db.h", separate and move SPM database
definitions from this file into individual head file of each
model.

Change-Id: Ieaedd0d136f62251239979d8223dd8710b910e7d
Signed-off-by: Mingyang Sun <mingyang.sun@arm.com>
diff --git a/secure_fw/spm/cmsis_func/include/spm_func.h b/secure_fw/spm/cmsis_func/include/spm_func.h
index 7978f46..a476cb3 100644
--- a/secure_fw/spm/cmsis_func/include/spm_func.h
+++ b/secure_fw/spm/cmsis_func/include/spm_func.h
@@ -9,6 +9,7 @@
 #define __SPM_FUNC_H__
 
 #include <stdint.h>
+#include "spm_partition_defs.h"
 #include "tfm_arch.h"
 #include "psa/client.h"
 
@@ -35,6 +36,11 @@
 #define SPM_PART_FLAG_PSA_ROT           0x02
 #define SPM_PART_FLAG_IPC               0x04
 
+#define TFM_PRIORITY_HIGH               0
+#define TFM_PRIORITY_NORMAL             0x7F
+#define TFM_PRIORITY_LOW                0xFF
+#define TFM_PRIORITY(LEVEL)             TFM_PRIORITY_##LEVEL
+
 enum spm_err_t {
     SPM_ERR_OK = 0,
     SPM_ERR_PARTITION_DB_NOT_INIT,
@@ -92,6 +98,38 @@
 };
 
 /**
+ * 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
+ * phase.
+ */
+struct spm_partition_static_data_t {
+    uint32_t partition_id;
+    uint32_t partition_flags;
+    uint32_t partition_priority;
+    sp_entry_point partition_init;
+    uint32_t dependencies_num;
+    int32_t *p_dependencies;
+};
+
+/**
+ * Holds the fields that define a partition for SPM. The fields are further
+ * divided to structures, to keep the related fields close to each other.
+ */
+struct spm_partition_desc_t {
+    struct spm_partition_runtime_data_t runtime_data;
+    const struct spm_partition_static_data_t *static_data;
+    /** A list of platform_data pointers */
+    const struct tfm_spm_partition_platform_data_t **platform_data_list;
+};
+
+struct spm_partition_db_t {
+    uint32_t is_init;
+    uint32_t partition_count;
+    uint32_t running_partition_idx;
+    struct spm_partition_desc_t *partitions;
+};
+
+/**
  * \brief Save interrupted partition context on ctx stack
  *
  * \param[in] partition_idx  Partition index
diff --git a/secure_fw/spm/cmsis_func/spm_func.c b/secure_fw/spm/cmsis_func/spm_func.c
index c42d195..eae55f0 100644
--- a/secure_fw/spm/cmsis_func/spm_func.c
+++ b/secure_fw/spm/cmsis_func/spm_func.c
@@ -18,7 +18,6 @@
 #include "tfm_secure_api.h"
 #include "tfm_spm_hal.h"
 #include "spm_func.h"
-#include "spm_db.h"
 #include "region_defs.h"
 #include "region.h"
 #include "spm_partition_defs.h"
diff --git a/secure_fw/spm/cmsis_psa/include/spm_ipc.h b/secure_fw/spm/cmsis_psa/include/spm_ipc.h
index 2a42b23..d11aab5 100644
--- a/secure_fw/spm/cmsis_psa/include/spm_ipc.h
+++ b/secure_fw/spm/cmsis_psa/include/spm_ipc.h
@@ -9,6 +9,7 @@
 #define __SPM_IPC_H__
 
 #include <stdint.h>
+#include "spm_partition_defs.h"
 #include "tfm_arch.h"
 #include "tfm_list.h"
 #include "tfm_wait.h"
@@ -24,6 +25,9 @@
 #define TFM_HANDLE_STATUS_ACTIVE        1
 #define TFM_HANDLE_STATUS_CONNECT_ERROR 2
 
+#define PART_REGION_ADDR(partition, region) \
+    (uint32_t)&REGION_NAME(Image$$, partition, region)
+
 #define TFM_CONN_HANDLE_MAX_NUM         16
 
 #define SPM_INVALID_PARTITION_IDX     (~0U)
@@ -36,6 +40,11 @@
 #define SPM_PART_FLAG_PSA_ROT           0x02
 #define SPM_PART_FLAG_IPC               0x04
 
+#define TFM_PRIORITY_HIGH               THRD_PRIOR_HIGHEST
+#define TFM_PRIORITY_NORMAL             THRD_PRIOR_MEDIUM
+#define TFM_PRIORITY_LOW                THRD_PRIOR_LOWEST
+#define TFM_PRIORITY(LEVEL)             TFM_PRIORITY_##LEVEL
+
 enum spm_err_t {
     SPM_ERR_OK = 0,
     SPM_ERR_PARTITION_DB_NOT_INIT,
@@ -60,6 +69,39 @@
                                          */
 };
 
+/**
+ * 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
+ * phase.
+ */
+struct spm_partition_static_data_t {
+    uint32_t psa_framework_version;
+    uint32_t partition_id;
+    uint32_t partition_flags;
+    uint32_t partition_priority;
+    sp_entry_point partition_init;
+    uint32_t dependencies_num;
+    int32_t *p_dependencies;
+};
+
+/**
+ * Holds the fields that define a partition for SPM. The fields are further
+ * divided to structures, to keep the related fields close to each other.
+ */
+struct spm_partition_desc_t {
+    struct spm_partition_runtime_data_t runtime_data;
+    const struct spm_partition_static_data_t *static_data;
+    /** A list of platform_data pointers */
+    const struct tfm_spm_partition_platform_data_t **platform_data_list;
+    const struct tfm_spm_partition_memory_data_t *memory_data;
+};
+
+struct spm_partition_db_t {
+    uint32_t is_init;
+    uint32_t partition_count;
+    struct spm_partition_desc_t *partitions;
+};
+
 /* Service database defined by manifest */
 struct tfm_spm_service_db_t {
     char *name;                     /* Service name                          */
diff --git a/secure_fw/spm/cmsis_psa/spm_ipc.c b/secure_fw/spm/cmsis_psa/spm_ipc.c
index a477a86..cf5ca72 100644
--- a/secure_fw/spm/cmsis_psa/spm_ipc.c
+++ b/secure_fw/spm/cmsis_psa/spm_ipc.c
@@ -22,7 +22,6 @@
 #include "tfm_memory_utils.h"
 #include "spm_ipc.h"
 #include "tfm_peripherals_def.h"
-#include "spm_db.h"
 #include "tfm_core_utils.h"
 #include "spm_psa_client_call.h"
 #include "tfm_rpc.h"
diff --git a/secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c b/secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c
index c4b9327..9cd9a24 100644
--- a/secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c
+++ b/secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c
@@ -7,7 +7,7 @@
 
 #include <string.h>
 #include "region.h"
-#include "spm_db.h"
+#include "spm_ipc.h"
 #include "tfm_api.h"
 #include "tfm_arch.h"
 #include "tfm_core_trustzone.h"
diff --git a/secure_fw/spm/common/init/tfm_boot_data.c b/secure_fw/spm/common/init/tfm_boot_data.c
index 5305554..8057318 100644
--- a/secure_fw/spm/common/init/tfm_boot_data.c
+++ b/secure_fw/spm/common/init/tfm_boot_data.c
@@ -21,7 +21,6 @@
 #include "tfm_wait.h"
 #include "tfm_message_queue.h"
 #include "tfm_spm_hal.h"
-#include "spm_db.h"
 #include "spm_ipc.h"
 #else
 #include "spm_func.h"
diff --git a/secure_fw/spm/include/spm_db.h b/secure_fw/spm/include/spm_db.h
deleted file mode 100644
index a6d58d0..0000000
--- a/secure_fw/spm/include/spm_db.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#ifndef __SPM_DB_H__
-#define __SPM_DB_H__
-
-#include <stdint.h>
-#include "target_cfg.h"
-#ifdef TFM_PSA_API
-#include "tfm_spm_hal.h"
-#include "spm_ipc.h"
-#else
-#include "spm_func.h"
-#endif
-
-struct spm_partition_desc_t;
-struct spm_partition_db_t;
-
-typedef void(*sp_entry_point)(void);
-
-#define TFM_PARTITION_TYPE_APP   "APPLICATION-ROT"
-#define TFM_PARTITION_TYPE_PSA   "PSA-ROT"
-
-#ifdef TFM_PSA_API
-#define TFM_PRIORITY_LOW    THRD_PRIOR_LOWEST
-#define TFM_PRIORITY_NORMAL THRD_PRIOR_MEDIUM
-#define TFM_PRIORITY_HIGH   THRD_PRIOR_HIGHEST
-#else
-#define TFM_PRIORITY_LOW    0xFF
-#define TFM_PRIORITY_NORMAL 0x7F
-#define 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
- * phase.
- */
-struct spm_partition_static_data_t {
-#ifdef TFM_PSA_API
-    uint32_t psa_framework_version;
-#endif /* defined(TFM_PSA_API) */
-    uint32_t partition_id;
-    uint32_t partition_flags;
-    uint32_t partition_priority;
-    sp_entry_point partition_init;
-    uint32_t dependencies_num;
-    int32_t *p_dependencies;
-};
-
-/**
- * Holds the fields that define a partition for SPM. The fields are further
- * divided to structures, to keep the related fields close to each other.
- */
-struct spm_partition_desc_t {
-    struct spm_partition_runtime_data_t runtime_data;
-    const struct spm_partition_static_data_t *static_data;
-    /** A list of platform_data pointers */
-    const struct tfm_spm_partition_platform_data_t **platform_data_list;
-#ifdef TFM_PSA_API
-    const struct tfm_spm_partition_memory_data_t *memory_data;
-#endif
-};
-
-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;
-};
-
-#ifdef TFM_PSA_API
-#define PART_REGION_ADDR(partition, region) \
-    (uint32_t)&REGION_NAME(Image$$, partition, region)
-#endif
-
-#endif /* __SPM_DB_H__ */
diff --git a/secure_fw/spm/include/spm_partition_defs.h b/secure_fw/spm/include/spm_partition_defs.h
index 4e32baf..07f224e 100644
--- a/secure_fw/spm/include/spm_partition_defs.h
+++ b/secure_fw/spm/include/spm_partition_defs.h
@@ -37,4 +37,6 @@
  */
 #define SPM_MAX_PARTITIONS (TFM_MAX_USER_PARTITIONS + TFM_INTERNAL_PARTITIONS)
 
+typedef void(*sp_entry_point)(void);
+
 #endif /* __SPM_PARTITION_DEFS_H__ */