SPM: Sort out tfm_secure_api.c file
- Rename 'tfm_utils.h' to 'utilities.h'.
- Rename 'tfm_spm_services_api.h'to 'tfm_spm_services.h'.
- Move 'tfm_secure_api.c' from spm/runtime to spm/model_func and
sort out the content
Change-Id: Ie8831e2b1430eab6a2edc9b6c0487ef14f2fafc6
Signed-off-by: Summer Qin <summer.qin@arm.com>
diff --git a/secure_fw/spm/model_func/CMakeLists.inc b/secure_fw/spm/model_func/CMakeLists.inc
index e700a9f..2160e86 100644
--- a/secure_fw/spm/model_func/CMakeLists.inc
+++ b/secure_fw/spm/model_func/CMakeLists.inc
@@ -37,12 +37,12 @@
"${SFW_SPM_INIT_DIR}/tfm_boot_data.c"
"${SFW_SPM_INIT_DIR}/tfm_core.c"
"${SFW_FUNC_SPM_DIR}/tfm_core_svcalls_func.c"
- "${SFW_FUNC_SPM_DIR}/../runtime/tfm_secure_api.c"
+ "${SFW_FUNC_SPM_DIR}/tfm_secure_api.c"
"${SFW_FUNC_SPM_DIR}/../runtime/tfm_spm_services.c"
"${SFW_FUNC_SPM_DIR}/../runtime/spm_api.c"
"${SFW_FUNC_SPM_DIR}/spm_func.c"
"${SFW_FUNC_SPM_DIR}/tfm_nspm_func.c"
- "${SFW_FUNC_SPM_DIR}/../runtime/tfm_utils.c"
+ "${SFW_FUNC_SPM_DIR}/../runtime/utilities.c"
"${SFW_FUNC_SPM_DIR}/../runtime/tfm_core_mem_check.c"
"${SFW_FUNC_SPM_DIR}/../runtime/tfm_core_utils.c"
"${SFW_FUNC_SPM_DIR}/tfm_veneers.c"
diff --git a/secure_fw/spm/model_func/spm_func.c b/secure_fw/spm/model_func/spm_func.c
index 890e0b2..3d4491e 100644
--- a/secure_fw/spm/model_func/spm_func.c
+++ b/secure_fw/spm/model_func/spm_func.c
@@ -21,7 +21,7 @@
#include "spm_db.h"
#include "region_defs.h"
#include "region.h"
-#include "tfm/tfm_spm_services_api.h"
+#include "tfm/tfm_spm_services.h"
#include "tfm_spm_db_func.inc"
#define EXC_RETURN_SECURE_FUNCTION 0xFFFFFFFD
@@ -38,7 +38,7 @@
* This is the "Big Lock" on the secure side, to guarantee single entry
* to SPE
*/
-extern int32_t tfm_secure_lock;
+static int32_t tfm_secure_lock;
static int32_t tfm_secure_api_initializing = 1;
static uint32_t *prepare_partition_iovec_ctx(
diff --git a/secure_fw/spm/model_func/tfm_secure_api.c b/secure_fw/spm/model_func/tfm_secure_api.c
new file mode 100644
index 0000000..d4fe179
--- /dev/null
+++ b/secure_fw/spm/model_func/tfm_secure_api.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include <stdbool.h>
+#include "spm_api.h"
+#include "tfm_secure_api.h"
+
+void tfm_secure_api_error_handler(void)
+{
+ ERROR_MSG("Security violation when calling secure API");
+ tfm_core_panic();
+}
+
+int32_t tfm_core_partition_request(uint32_t id, bool is_ns, void *fn,
+ int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4)
+{
+ int32_t args[4] = {arg1, arg2, arg3, arg4};
+ struct tfm_sfn_req_s desc, *desc_ptr = &desc;
+
+ desc.sp_id = id;
+ desc.sfn = (sfn_t) fn;
+ desc.args = args;
+ desc.ns_caller = is_ns;
+
+ if (__get_active_exc_num() != EXC_NUM_THREAD_MODE) {
+ /* The veneer of a secure service had been called from Handler mode.
+ * This violates TF-M's programming model, and is considered an
+ * unrecoverable error.
+ */
+ tfm_core_panic();
+ } else {
+ if (desc.ns_caller) {
+ return tfm_core_sfn_request(desc_ptr);
+ } else {
+ return tfm_spm_sfn_request_thread_mode(desc_ptr);
+ }
+ }
+ return TFM_ERROR_GENERIC;
+}