Core: Remove Library mode specific functions for IPC model

Below action items are performed to remove library function under IPC
model:
- tfm_spm_partition_init() is only used by library model, correct the
  inappropriate condition in it.
- Condition the library function in tfm_spm_services.c,
  tfm_sst_req_mngr.c and spm_api.c files.
- Delete unused function sst_utils_validate_secure_caller().

Change-Id: I62d956481a19d0d47bfa17a9f63c7b815011d61e
Signed-off-by: Summer Qin <summer.qin@arm.com>
diff --git a/secure_fw/core/tfm_spm_services.c b/secure_fw/core/tfm_spm_services.c
index 13ca9fc..83ff41b 100644
--- a/secure_fw/core/tfm_spm_services.c
+++ b/secure_fw/core/tfm_spm_services.c
@@ -31,6 +31,7 @@
     ns_entry();
 }
 
+#ifndef TFM_PSA_API
 #if defined(__ARM_ARCH_8M_MAIN__)
 __attribute__((naked)) int32_t tfm_core_sfn_request(
                                            const struct tfm_sfn_req_s *desc_ptr)
@@ -151,6 +152,7 @@
         "BX     lr\n"
         : : "I" (TFM_SVC_SET_SHARE_AREA));
 }
+#endif
 
 __attribute__((naked))
 int32_t tfm_core_get_boot_data(uint8_t major_type,
diff --git a/secure_fw/services/secure_storage/sst_utils.c b/secure_fw/services/secure_storage/sst_utils.c
index 2e774b9..992c9a1 100644
--- a/secure_fw/services/secure_storage/sst_utils.c
+++ b/secure_fw/services/secure_storage/sst_utils.c
@@ -44,11 +44,6 @@
     return PSA_PS_SUCCESS;
 }
 
-uint32_t sst_utils_validate_secure_caller(void)
-{
-    return tfm_core_validate_secure_caller();
-}
-
 psa_ps_status_t sst_utils_validate_fid(uint32_t fid)
 {
     if (fid == SST_INVALID_FID) {
diff --git a/secure_fw/services/secure_storage/sst_utils.h b/secure_fw/services/secure_storage/sst_utils.h
index 4c1df73..6bf99a9 100644
--- a/secure_fw/services/secure_storage/sst_utils.h
+++ b/secure_fw/services/secure_storage/sst_utils.h
@@ -108,15 +108,6 @@
 void sst_utils_memset(void *dest, const uint8_t pattern, uint32_t size);
 
 /**
- * \brief Checks if the sst function caller is located in the secure or
- *        non-secure space.
- *
- * \return Returns 0 if the caller is located in the secure area, otherwise
- *         returns unspecified non-zero value if it is in the non-secure area
- */
-uint32_t sst_utils_validate_secure_caller(void);
-
-/**
  * \brief Validates file ID
  *
  * \param[in] fid  File ID
diff --git a/secure_fw/services/secure_storage/tfm_sst_req_mngr.c b/secure_fw/services/secure_storage/tfm_sst_req_mngr.c
index b9d2a3e..4f809f9 100644
--- a/secure_fw/services/secure_storage/tfm_sst_req_mngr.c
+++ b/secure_fw/services/secure_storage/tfm_sst_req_mngr.c
@@ -19,6 +19,7 @@
 #include "flash_layout.h"
 #endif
 
+#ifndef TFM_PSA_API
 /*
  * \brief Indicates whether SST has been initialised.
  */
@@ -274,7 +275,7 @@
     return PSA_SUCCESS;
 }
 
-#ifdef TFM_PSA_API
+#else /* !defined(TFM_PSA_API) */
 typedef psa_status_t (*sst_func_t)(const psa_msg_t *msg);
 static uint8_t asset_data[SST_MAX_ASSET_SIZE] = {0};
 
@@ -468,7 +469,7 @@
         tfm_abort();
     }
 }
-#endif /* TFM_PSA_API */
+#endif /* !defined(TFM_PSA_API) */
 
 psa_ps_status_t tfm_sst_req_mngr_init(void)
 {
@@ -478,7 +479,6 @@
     if (tfm_sst_init() != PSA_PS_SUCCESS) {
         tfm_abort();
     }
-    sst_is_init = true;
 
     while (1) {
         signals = psa_wait(PSA_WAIT_ANY, PSA_BLOCK);
diff --git a/secure_fw/spm/spm_api.c b/secure_fw/spm/spm_api.c
index 4d56a91..78999a8 100644
--- a/secure_fw/spm/spm_api.c
+++ b/secure_fw/spm/spm_api.c
@@ -32,6 +32,7 @@
  * In case of an error in the error handling, a non-zero value have to be
  * returned.
  */
+#ifndef TFM_PSA_API
 static void tfm_spm_partition_err_handler(
     const struct spm_partition_desc_t *partition,
     sp_error_type_t err_type,
@@ -53,6 +54,7 @@
     tfm_spm_partition_set_state(partition->static_data.partition_id,
             SPM_PARTITION_STATE_CLOSED);
 }
+#endif /* !defined(TFM_PSA_API) */
 
 /*
  * This function prevents name clashes between the variable names accessibles in
@@ -154,6 +156,7 @@
     return SPM_ERR_OK;
 }
 
+#ifndef TFM_PSA_API
 enum spm_err_t tfm_spm_partition_init(void)
 {
     struct spm_partition_desc_t *part;
@@ -166,11 +169,6 @@
     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,
@@ -193,10 +191,7 @@
         }
     }
 
-#ifndef TFM_PSA_API
-    /* Not applicable if IPC messaging is used */
     tfm_secure_api_init_done();
-#endif
 
     if (fail_cnt == 0) {
         return SPM_ERR_OK;
@@ -204,6 +199,7 @@
         return SPM_ERR_PARTITION_NOT_AVAILABLE;
     }
 }
+#endif /* !defined(TFM_PSA_API) */
 
 #if (TFM_LVL != 1) || defined(TFM_PSA_API)
 uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx)
@@ -278,15 +274,6 @@
 }
 #endif
 
-void tfm_spm_partition_store_context(uint32_t partition_idx,
-        uint32_t stack_ptr, uint32_t lr)
-{
-    g_spm_partition_db.partitions[partition_idx].
-            runtime_data.stack_ptr = stack_ptr;
-    g_spm_partition_db.partitions[partition_idx].
-            runtime_data.lr = lr;
-}
-
 uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx)
 {
     return g_spm_partition_db.partitions[partition_idx].static_data.
@@ -299,6 +286,16 @@
             partition_flags;
 }
 
+#ifndef TFM_PSA_API
+void tfm_spm_partition_store_context(uint32_t partition_idx,
+        uint32_t stack_ptr, uint32_t lr)
+{
+    g_spm_partition_db.partitions[partition_idx].
+            runtime_data.stack_ptr = stack_ptr;
+    g_spm_partition_db.partitions[partition_idx].
+            runtime_data.lr = lr;
+}
+
 const struct spm_partition_runtime_data_t *
             tfm_spm_partition_get_runtime_data(uint32_t partition_idx)
 {
@@ -328,7 +325,6 @@
             caller_client_id = caller_client_id;
 }
 
-#ifndef TFM_PSA_API
 enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx,
                                            uint32_t share)
 {
@@ -344,7 +340,6 @@
     }
     return ret;
 }
-#endif
 
 enum spm_err_t tfm_spm_partition_set_iovec(uint32_t partition_idx,
                                            const int32_t *args)
@@ -402,6 +397,7 @@
     partition->runtime_data.orig_outvec = 0;
     partition->runtime_data.iovec_api = 0;
 }
+#endif /* !defined(TFM_PSA_API) */
 
 __attribute__((section("SFN")))
 void tfm_spm_partition_change_privilege(uint32_t privileged)
diff --git a/secure_fw/spm/spm_api.h b/secure_fw/spm/spm_api.h
index 106b29f..a15434d 100644
--- a/secure_fw/spm/spm_api.h
+++ b/secure_fw/spm/spm_api.h
@@ -192,6 +192,17 @@
 #endif
 
 /**
+ * \brief Get the id of the partition for its index from the db
+ *
+ * \param[in] partition_idx     Partition index
+ *
+ * \return Partition ID for that partition
+ *
+ * \note This function doesn't check if partition_idx is valid.
+ */
+uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
+
+/**
  * \brief Get the flags associated with a partition
  *
  * \param[in] partition_idx     Partition index
@@ -202,6 +213,7 @@
  */
 uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx);
 
+#ifndef TFM_PSA_API
 /**
  * \brief Get the current runtime data of a partition
  *
@@ -235,17 +247,6 @@
         uint32_t stack_ptr, uint32_t lr);
 
 /**
- * \brief Get the id of the partition for its index from the db
- *
- * \param[in] partition_idx     Partition index
- *
- * \return Partition ID for that partition
- *
- * \note This function doesn't check if partition_idx is valid.
- */
-uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
-
-/**
  * \brief Set the current state of a partition
  *
  * \param[in] partition_idx  Partition index
@@ -314,13 +315,6 @@
                                            const int32_t *args);
 
 /**
- * \brief Initialize partition database
- *
- * \return Error code \ref spm_err_t
- */
-enum spm_err_t tfm_spm_db_init(void);
-
-/**
  * \brief Execute partition init function
  *
  * \return Error code \ref spm_err_t
@@ -335,6 +329,14 @@
  * \note This function doesn't check if partition_idx is valid.
  */
 void tfm_spm_partition_cleanup_context(uint32_t partition_idx);
+#endif /* !defined(TFM_PSA_API) */
+
+/**
+ * \brief Initialize partition database
+ *
+ * \return Error code \ref spm_err_t
+ */
+enum spm_err_t tfm_spm_db_init(void);
 
 /**
  * \brief Change the privilege mode for partition thread mode.