aboutsummaryrefslogtreecommitdiff
path: root/interface/src
diff options
context:
space:
mode:
authorDavid Hu <david.hu@arm.com>2020-05-12 17:19:21 +0800
committerDavid Hu <david.hu@arm.com>2021-01-22 02:21:55 +0000
commit69e590e99041fc54d465a3317cef2b8348ec02bd (patch)
treedd5e9635708fabb371ec7bfdf3c75e317ab8a520 /interface/src
parent1bd1c7bfd4acee0405b0273748ddce677436b7b2 (diff)
downloadtrusted-firmware-m-69e590e99041fc54d465a3317cef2b8348ec02bd.tar.gz
Dualcpu: Move NS mailbox thread management to RTOS specific file
The NS mailbox thread management is NS RTOS specific. - Add a new tfm_ns_mailbox_rtos_api.c to collect all the NS mailbox APIs which rely on RTOS specific implementations. - Move those API implementations from platform to tfm_ns_mailbox_rtos_api.c. - Rename those APIs to replace HAL keyword with OS keyword, to indicate that their implementations are RTOS specific. Change-Id: Ic2885bc1676964719d1524b39d6518444610e1aa Signed-off-by: David Hu <david.hu@arm.com>
Diffstat (limited to 'interface/src')
-rw-r--r--interface/src/tfm_multi_core_api.c45
-rw-r--r--interface/src/tfm_multi_core_ns_api.c20
-rw-r--r--interface/src/tfm_ns_mailbox.c19
-rw-r--r--interface/src/tfm_ns_mailbox_rtos_api.c62
4 files changed, 93 insertions, 53 deletions
diff --git a/interface/src/tfm_multi_core_api.c b/interface/src/tfm_multi_core_api.c
deleted file mode 100644
index c3deb50da7..0000000000
--- a/interface/src/tfm_multi_core_api.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2019, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#include "os_wrapper/semaphore.h"
-
-#include "tfm_api.h"
-#include "tfm_mailbox.h"
-#include "tfm_multi_core_api.h"
-
-#define MAX_SEMAPHORE_COUNT NUM_MAILBOX_QUEUE_SLOT
-
-static void *ns_lock_handle = NULL;
-
-__attribute__((weak))
-enum tfm_status_e tfm_ns_interface_init(void)
-{
- ns_lock_handle = os_wrapper_semaphore_create(MAX_SEMAPHORE_COUNT,
- MAX_SEMAPHORE_COUNT,
- NULL);
- if (!ns_lock_handle) {
- return TFM_ERROR_GENERIC;
- }
-
- return TFM_SUCCESS;
-}
-
-int32_t tfm_ns_wait_for_s_cpu_ready(void)
-{
- return tfm_platform_ns_wait_for_s_cpu_ready();
-}
-
-uint32_t tfm_ns_multi_core_lock_acquire(void)
-{
- return os_wrapper_semaphore_acquire(ns_lock_handle,
- OS_WRAPPER_WAIT_FOREVER);
-}
-
-uint32_t tfm_ns_multi_core_lock_release(void)
-{
- return os_wrapper_semaphore_release(ns_lock_handle);
-}
diff --git a/interface/src/tfm_multi_core_ns_api.c b/interface/src/tfm_multi_core_ns_api.c
new file mode 100644
index 0000000000..ce9233c65f
--- /dev/null
+++ b/interface/src/tfm_multi_core_ns_api.c
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "tfm_api.h"
+#include "tfm_multi_core_api.h"
+
+__attribute__((weak))
+enum tfm_status_e tfm_ns_interface_init(void)
+{
+ return TFM_SUCCESS;
+}
+
+int32_t tfm_ns_wait_for_s_cpu_ready(void)
+{
+ return tfm_platform_ns_wait_for_s_cpu_ready();
+}
diff --git a/interface/src/tfm_ns_mailbox.c b/interface/src/tfm_ns_mailbox.c
index 4e44fae8d6..b256fa2027 100644
--- a/interface/src/tfm_ns_mailbox.c
+++ b/interface/src/tfm_ns_mailbox.c
@@ -8,8 +8,6 @@
#include <string.h>
#include "cmsis_compiler.h"
-#include "os_wrapper/common.h"
-#include "tfm_multi_core_api.h"
#include "tfm_ns_mailbox.h"
/* The pointer to NSPE mailbox queue */
@@ -234,7 +232,7 @@ static int32_t mailbox_tx_client_req(uint32_t call_type,
* Fetch the current task handle. The task will be woken up according the
* handle value set in the owner field.
*/
- task_handle = tfm_ns_mailbox_get_task_handle();
+ task_handle = tfm_ns_mailbox_os_get_task_handle();
set_msg_owner(idx, task_handle);
get_mailbox_msg_handle(idx, handle);
@@ -297,7 +295,7 @@ int32_t tfm_ns_mailbox_client_call(uint32_t call_type,
return MAILBOX_INVAL_PARAMS;
}
- if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
+ if (tfm_ns_mailbox_os_lock_acquire() != MAILBOX_SUCCESS) {
return MAILBOX_QUEUE_FULL;
}
@@ -316,7 +314,7 @@ int32_t tfm_ns_mailbox_client_call(uint32_t call_type,
}
exit:
- if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
+ if (tfm_ns_mailbox_os_lock_release() != MAILBOX_SUCCESS) {
return MAILBOX_GENERIC_ERROR;
}
@@ -365,8 +363,8 @@ int32_t tfm_ns_mailbox_wake_reply_owner_isr(void)
return ret;
}
- tfm_ns_mailbox_hal_wake_task_isr(mailbox_queue_ptr->queue[idx].owner,
- handle);
+ tfm_ns_mailbox_os_wake_task_isr(mailbox_queue_ptr->queue[idx].owner,
+ handle);
return MAILBOX_SUCCESS;
}
@@ -397,6 +395,11 @@ int32_t tfm_ns_mailbox_init(struct ns_mailbox_queue_t *queue)
/* Platform specific initialization. */
ret = tfm_ns_mailbox_hal_init(queue);
+ if (ret != MAILBOX_SUCCESS) {
+ return ret;
+ }
+
+ ret = tfm_ns_mailbox_os_lock_init();
#ifdef TFM_MULTI_CORE_TEST
tfm_ns_mailbox_tx_stats_init();
@@ -420,7 +423,7 @@ static int32_t mailbox_wait_reply(mailbox_msg_handle_t handle)
}
while (1) {
- tfm_ns_mailbox_hal_wait_reply(handle);
+ tfm_ns_mailbox_os_wait_reply(handle);
/*
* Woken up from sleep
diff --git a/interface/src/tfm_ns_mailbox_rtos_api.c b/interface/src/tfm_ns_mailbox_rtos_api.c
new file mode 100644
index 0000000000..1e9e8d2dda
--- /dev/null
+++ b/interface/src/tfm_ns_mailbox_rtos_api.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+/*
+ * This file is a reference implementation of Non-secure mailbox RTOS API.
+ * This reference implementation is based on TF-M ROTS wrapper API.
+ * It can be replaced by RTOS specific implementation.
+ */
+
+#include "os_wrapper/semaphore.h"
+#include "os_wrapper/thread.h"
+
+#include "tfm_ns_mailbox.h"
+
+#define MAX_SEMAPHORE_COUNT NUM_MAILBOX_QUEUE_SLOT
+
+static void *ns_lock_handle = NULL;
+
+#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
+const void *tfm_ns_mailbox_os_get_task_handle(void)
+{
+ return os_wrapper_thread_get_handle();
+}
+
+void tfm_ns_mailbox_os_wait_reply(mailbox_msg_handle_t handle)
+{
+ os_wrapper_thread_wait_flag((uint32_t)handle, OS_WRAPPER_WAIT_FOREVER);
+}
+
+void tfm_ns_mailbox_os_wake_task_isr(const void *task_handle,
+ mailbox_msg_handle_t handle)
+{
+ os_wrapper_thread_set_flag_isr((void *)task_handle, (uint32_t)handle);
+}
+#endif /* TFM_MULTI_CORE_MULTI_CLIENT_CALL */
+
+int32_t tfm_ns_mailbox_os_lock_init(void)
+{
+ ns_lock_handle = os_wrapper_semaphore_create(MAX_SEMAPHORE_COUNT,
+ MAX_SEMAPHORE_COUNT,
+ NULL);
+ if (!ns_lock_handle) {
+ return MAILBOX_GENERIC_ERROR;
+ }
+
+ return MAILBOX_SUCCESS;
+}
+
+int32_t tfm_ns_mailbox_os_lock_acquire(void)
+{
+ return os_wrapper_semaphore_acquire(ns_lock_handle,
+ OS_WRAPPER_WAIT_FOREVER);
+}
+
+int32_t tfm_ns_mailbox_os_lock_release(void)
+{
+ return os_wrapper_semaphore_release(ns_lock_handle);
+}