Core: Remove isolation level 3

Remove functions, process, data which only used in isolation level 3
for library model.

Change-Id: Ia21819d6a6cccb18af316a79658aa3673f2d2420
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 80d6575..2aabaef2 100644
--- a/secure_fw/spm/spm_api.c
+++ b/secure_fw/spm/spm_api.c
@@ -60,7 +60,7 @@
      */
 
     /* For the non secure Execution environment */
-#if (TFM_LVL != 1) || defined(TFM_PSA_API)
+#if TFM_PSA_API
     extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Base[];
     extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Limit[];
     uint32_t psp_stack_bottom = (uint32_t)Image$$ARM_LIB_STACK$$ZI$$Base;
@@ -79,7 +79,7 @@
     part_ptr->static_data.partition_flags = 0;
 #endif
 
-#if (TFM_LVL != 1) || defined(TFM_PSA_API)
+#if TFM_PSA_API
     part_ptr->memory_data.stack_bottom = psp_stack_bottom;
     part_ptr->memory_data.stack_top    = psp_stack_top;
     /* Since RW, ZI and stack are configured as one MPU region, configure
@@ -111,19 +111,6 @@
     return SPM_ERR_OK;
 }
 
-#if (TFM_LVL != 1) || defined(TFM_PSA_API)
-uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx)
-{
-    return g_spm_partition_db.partitions[partition_idx].
-            memory_data.stack_bottom;
-}
-
-uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx)
-{
-    return g_spm_partition_db.partitions[partition_idx].memory_data.stack_top;
-}
-#endif
-
 uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx)
 {
     return g_spm_partition_db.partitions[partition_idx].static_data.
diff --git a/secure_fw/spm/spm_api.h b/secure_fw/spm/spm_api.h
index 55a42cf..7f95339 100644
--- a/secure_fw/spm/spm_api.h
+++ b/secure_fw/spm/spm_api.h
@@ -66,9 +66,6 @@
  * uint32_t[] array
  */
 struct interrupted_ctx_stack_frame_t {
-#if TFM_LVL != 1
-    uint32_t stack_ptr;
-#endif
     uint32_t partition_state;
 };
 
@@ -162,110 +159,6 @@
  */
 uint32_t get_partition_idx(uint32_t partition_id);
 
-#if (TFM_LVL != 1) || defined(TFM_PSA_API)
-/**
- * \brief Get bottom of stack region for a partition
- *
- * \param[in] partition_idx     Partition index
- *
- * \return Stack region bottom value
- *
- * \note This function doesn't check if partition_idx is valid.
- */
-uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx);
-
-/**
- * \brief Get top of stack region for a partition
- *
- * \param[in] partition_idx     Partition index
- *
- * \return Stack region top value
- *
- * \note This function doesn't check if partition_idx is valid.
- */
-uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx);
-#endif
-
-#if (TFM_LVL != 1) && !defined(TFM_PSA_API)
-/**
- * \brief Configure isolated sandbox for a partition
- *
- * \param[in] partition_idx     Partition index
- *
- * \return Error code \ref spm_err_t
- *
- * \note This function doesn't check if partition_idx is valid.
- */
-enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_idx);
-
-/**
- * \brief Deconfigure sandbox for a partition
- *
- * \param[in] partition_idx     Partition index
- *
- * \return Error code \ref spm_err_t
- *
- * \note This function doesn't check if partition_idx is valid.
- */
-enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_idx);
-
-/**
- * \brief Get the start of the zero-initialised region for a partition
- *
- * \param[in] partition_idx     Partition idx
- *
- * \return Start of the zero-initialised region
- *
- * \note This function doesn't check if partition_idx is valid.
- */
-uint32_t tfm_spm_partition_get_zi_start(uint32_t partition_idx);
-
-/**
- * \brief Get the limit of the zero-initialised region for a partition
- *
- * \param[in] partition_idx     Partition idx
- *
- * \return Limit of the zero-initialised region
- *
- * \note This function doesn't check if partition_idx is valid.
- * \note The address returned is not part of the region.
- */
-uint32_t tfm_spm_partition_get_zi_limit(uint32_t partition_idx);
-
-/**
- * \brief Get the start of the read-write region for a partition
- *
- * \param[in] partition_idx     Partition idx
- *
- * \return Start of the read-write region
- *
- * \note This function doesn't check if partition_idx is valid.
- */
-uint32_t tfm_spm_partition_get_rw_start(uint32_t partition_idx);
-
-/**
- * \brief Get the limit of the read-write region for a partition
- *
- * \param[in] partition_idx     Partition idx
- *
- * \return Limit of the read-write region
- *
- * \note This function doesn't check if partition_idx is valid.
- * \note The address returned is not part of the region.
- */
-uint32_t tfm_spm_partition_get_rw_limit(uint32_t partition_idx);
-
-/**
- * \brief Save stack pointer for partition in database
- *
- * \param[in] partition_idx  Partition index
- * \param[in] stack_ptr      Stack pointer to be stored
- *
- * \note This function doesn't check if partition_idx is valid.
- */
-void tfm_spm_partition_set_stack(uint32_t partition_idx, uint32_t stack_ptr);
-#endif /* if (TFM_LVL != 1) && !defined(TFM_PSA_API) */
-
 /**
  * \brief Get the id of the partition for its index from the db
  *
@@ -304,8 +197,7 @@
  *
  * \note Barrier instructions are not called by this function, and if
  *       it is called in thread mode, it might be necessary to call
- *       them after this function returns (just like it is done in
- *       jump_to_ns_code()).
+ *       them after this function returns.
  */
 void tfm_spm_partition_change_privilege(uint32_t privileged);
 
@@ -487,7 +379,28 @@
 
 #ifdef TFM_PSA_API
 /*************************** IPC definitions **************************/
-/*************************** Extended SPM functions **************************/
+
+/**
+ * \brief Get bottom of stack region for a partition
+ *
+ * \param[in] partition_idx     Partition index
+ *
+ * \return Stack region bottom value
+ *
+ * \note This function doesn't check if partition_idx is valid.
+ */
+uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx);
+
+/**
+ * \brief Get top of stack region for a partition
+ *
+ * \param[in] partition_idx     Partition index
+ *
+ * \return Stack region top value
+ *
+ * \note This function doesn't check if partition_idx is valid.
+ */
+uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx);
 
 /**
  * \brief   Get the running partition ID.
diff --git a/secure_fw/spm/spm_api_func.c b/secure_fw/spm/spm_api_func.c
index 3b4fb8c..763a543 100644
--- a/secure_fw/spm/spm_api_func.c
+++ b/secure_fw/spm/spm_api_func.c
@@ -101,15 +101,9 @@
     struct spm_partition_runtime_data_t *runtime_data =
         &g_spm_partition_db.partitions[partition_idx].runtime_data;
     struct interrupted_ctx_stack_frame_t *stack_frame =
-        (struct interrupted_ctx_stack_frame_t *)
-            runtime_data->ctx_stack_ptr;
+        (struct interrupted_ctx_stack_frame_t *)runtime_data->ctx_stack_ptr;
 
     stack_frame->partition_state = runtime_data->partition_state;
-#if TFM_LVL != 1
-    stack_frame->stack_ptr = runtime_data->stack_ptr;
-#endif
-    runtime_data->ctx_stack_ptr +=
-        sizeof(struct interrupted_ctx_stack_frame_t) / sizeof(uint32_t);
 }
 
 void tfm_spm_partition_pop_interrupted_ctx(uint32_t partition_idx)
@@ -118,16 +112,10 @@
         &g_spm_partition_db.partitions[partition_idx].runtime_data;
     struct interrupted_ctx_stack_frame_t *stack_frame;
 
-    runtime_data->ctx_stack_ptr -=
-        sizeof(struct interrupted_ctx_stack_frame_t) / sizeof(uint32_t);
     stack_frame = (struct interrupted_ctx_stack_frame_t *)
                       runtime_data->ctx_stack_ptr;
     tfm_spm_partition_set_state(partition_idx, stack_frame->partition_state);
     stack_frame->partition_state = 0;
-#if TFM_LVL != 1
-    tfm_spm_partition_set_stack(partition_idx, stack_frame->stack_ptr);
-    stack_frame->stack_ptr = 0;
-#endif
 }
 
 void tfm_spm_partition_push_handler_ctx(uint32_t partition_idx)
@@ -164,66 +152,6 @@
     stack_frame->caller_partition_idx = 0;
 }
 
-#if (TFM_LVL != 1)
-enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_idx)
-{
-    struct spm_partition_desc_t *part;
-    if (!g_spm_partition_db.is_init) {
-        return SPM_ERR_PARTITION_DB_NOT_INIT;
-    }
-
-    part = &g_spm_partition_db.partitions[partition_idx];
-
-    return tfm_spm_hal_partition_sandbox_config(&(part->memory_data),
-                                                part->platform_data);
-
-}
-
-enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_idx)
-{
-    /* This function takes a partition id and disables the
-     * SPM partition for that partition
-     */
-
-    struct spm_partition_desc_t *part;
-
-    part = &g_spm_partition_db.partitions[partition_idx];
-
-    return tfm_spm_hal_partition_sandbox_deconfig(&(part->memory_data),
-                                                  part->platform_data);
-}
-
-uint32_t tfm_spm_partition_get_zi_start(uint32_t partition_idx)
-{
-    return g_spm_partition_db.partitions[partition_idx].
-            memory_data.zi_start;
-}
-
-uint32_t tfm_spm_partition_get_zi_limit(uint32_t partition_idx)
-{
-    return g_spm_partition_db.partitions[partition_idx].
-            memory_data.zi_limit;
-}
-
-uint32_t tfm_spm_partition_get_rw_start(uint32_t partition_idx)
-{
-    return g_spm_partition_db.partitions[partition_idx].
-            memory_data.rw_start;
-}
-
-uint32_t tfm_spm_partition_get_rw_limit(uint32_t partition_idx)
-{
-    return g_spm_partition_db.partitions[partition_idx].
-            memory_data.rw_limit;
-}
-
-void tfm_spm_partition_set_stack(uint32_t partition_idx, uint32_t stack_ptr)
-{
-    g_spm_partition_db.partitions[partition_idx].
-            runtime_data.stack_ptr = stack_ptr;
-}
-#endif
-
 void tfm_spm_partition_store_context(uint32_t partition_idx,
         uint32_t stack_ptr, uint32_t lr)
 {
@@ -273,17 +201,9 @@
 enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx,
                                            uint32_t share)
 {
-    enum spm_err_t ret = SPM_ERR_OK;
+    g_spm_partition_db.partitions[partition_idx].runtime_data.share = share;
 
-#if TFM_LVL != 1
-    /* Only need to set configuration on levels higher than 1 */
-    ret = tfm_spm_hal_set_share_region(share);
-#endif
-
-    if (ret == SPM_ERR_OK) {
-        g_spm_partition_db.partitions[partition_idx].runtime_data.share = share;
-    }
-    return ret;
+    return SPM_ERR_OK;
 }
 
 enum spm_err_t tfm_spm_partition_set_iovec(uint32_t partition_idx,
diff --git a/secure_fw/spm/spm_api_ipc.c b/secure_fw/spm/spm_api_ipc.c
index 6443b52..98f6046 100644
--- a/secure_fw/spm/spm_api_ipc.c
+++ b/secure_fw/spm/spm_api_ipc.c
@@ -410,7 +410,17 @@
     return IPC_SUCCESS;
 }
 
-/* SPM extend functions */
+uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx)
+{
+    return g_spm_partition_db.partitions[partition_idx].
+            memory_data.stack_bottom;
+}
+
+uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx)
+{
+    return g_spm_partition_db.partitions[partition_idx].memory_data.stack_top;
+}
+
 uint32_t tfm_spm_partition_get_running_partition_id(void)
 {
     struct tfm_thrd_ctx *pth = tfm_thrd_curr_thread();
diff --git a/secure_fw/spm/spm_db.h b/secure_fw/spm/spm_db.h
index 7b74aba..2ee69f6 100644
--- a/secure_fw/spm/spm_db.h
+++ b/secure_fw/spm/spm_db.h
@@ -54,10 +54,8 @@
     struct spm_partition_static_data_t static_data;
     struct spm_partition_runtime_data_t runtime_data;
     struct tfm_spm_partition_platform_data_t *platform_data;
-#if (TFM_LVL != 1) || defined(TFM_PSA_API)
+#if TFM_PSA_API
     struct tfm_spm_partition_memory_data_t memory_data;
-#endif
-#ifdef TFM_PSA_API
     struct tfm_thrd_ctx sp_thrd;
 #endif
 };
@@ -74,7 +72,7 @@
 /* Macros to pick linker symbols and allow to form the partition data base */
 #define REGION(a, b, c) a##b##c
 #define REGION_NAME(a, b, c) REGION(a, b, c)
-#if (TFM_LVL == 1) && !defined(TFM_PSA_API)
+#ifndef TFM_PSA_API
 #define REGION_DECLARE(a, b, c)
 #else
 #define REGION_DECLARE(a, b, c) extern uint32_t REGION_NAME(a, b, c)