diff options
author | David Hu <david.hu@arm.com> | 2021-04-06 18:03:33 +0800 |
---|---|---|
committer | David Hu <david.hu@arm.com> | 2021-04-29 08:56:18 +0200 |
commit | f07f3f16c35beed23772e83453a7c08d0b78ddb8 (patch) | |
tree | ba2fdf5865104d1b272af6db21589ac1047c5bc0 /interface/src | |
parent | 7c2a744b3712f481b9dc7ab89bcc0ef5cb30f5fa (diff) | |
download | trusted-firmware-m-f07f3f16c35beed23772e83453a7c08d0b78ddb8.tar.gz |
Interface: Remove NS RTOS specific implementation
Move NS RTOS related interface code to tf-m-test to decouple TF-M from
NS specific implementation.
The removed code includes OS wrapper headers and RTOS specific
implementation.
Export tfm_ns_interface_dispatch() to NS as API to integrate with TF-M
NS interface.
Add an example of tfm_ns_interface_dispatch() implementation.
Change-Id: I9b331c32ac26551bfdbc4996eecd08efc7d7c2c3
Signed-off-by: David Hu <david.hu@arm.com>
Diffstat (limited to 'interface/src')
-rw-r--r-- | interface/src/multi_core/tfm_multi_core_ns_api.c | 7 | ||||
-rw-r--r-- | interface/src/multi_core/tfm_ns_mailbox_rtos_api.c | 116 | ||||
-rw-r--r-- | interface/src/tfm_ns_interface.c | 50 | ||||
-rw-r--r-- | interface/src/tfm_ns_interface.c.example | 58 |
4 files changed, 58 insertions, 173 deletions
diff --git a/interface/src/multi_core/tfm_multi_core_ns_api.c b/interface/src/multi_core/tfm_multi_core_ns_api.c index ce9233c65f..dba68d896a 100644 --- a/interface/src/multi_core/tfm_multi_core_ns_api.c +++ b/interface/src/multi_core/tfm_multi_core_ns_api.c @@ -5,15 +5,8 @@ * */ -#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/multi_core/tfm_ns_mailbox_rtos_api.c b/interface/src/multi_core/tfm_ns_mailbox_rtos_api.c deleted file mode 100644 index 629e108c82..0000000000 --- a/interface/src/multi_core/tfm_ns_mailbox_rtos_api.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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. - */ - -#ifdef TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD -#include "os_wrapper/msg_queue.h" -#else -#include "os_wrapper/semaphore.h" -#endif -#include "os_wrapper/thread.h" - -#include "tfm_ns_mailbox.h" - -/* - * Thread flag to manage wait/wake mechanism in mailbox.、 - * Thread flag can be RTOS specific. - * The following example definition also covers the rule of CMSIS-RTOS2, which - * requires the MSB of thread flags must be 0b0. - */ -#define MAILBOX_THREAD_FLAG 0x5FCA0000 - -#ifndef TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD -#define MAX_SEMAPHORE_COUNT NUM_MAILBOX_QUEUE_SLOT - -static void *ns_lock_handle = NULL; -#endif - -const void *tfm_ns_mailbox_os_get_task_handle(void) -{ - return os_wrapper_thread_get_handle(); -} - -void tfm_ns_mailbox_os_wait_reply(void) -{ - os_wrapper_thread_wait_flag(MAILBOX_THREAD_FLAG, OS_WRAPPER_WAIT_FOREVER); -} - -void tfm_ns_mailbox_os_wake_task_isr(const void *task_handle) -{ - os_wrapper_thread_set_flag_isr((void *)task_handle, MAILBOX_THREAD_FLAG); -} - -#ifdef TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD -void *tfm_ns_mailbox_os_mq_create(size_t msg_size, uint8_t msg_count) -{ - return os_wrapper_msg_queue_create(msg_size, msg_count); -} - -int32_t tfm_ns_mailbox_os_mq_send(void *mq_handle, const void *msg_ptr) -{ - int32_t ret; - - if (!mq_handle || !msg_ptr) { - return MAILBOX_INVAL_PARAMS; - } - - while (1) { - ret = os_wrapper_msg_queue_send(mq_handle, msg_ptr); - if (ret == OS_WRAPPER_SUCCESS) { - return MAILBOX_SUCCESS; - } - } - - return MAILBOX_GENERIC_ERROR; -} - -int32_t tfm_ns_mailbox_os_mq_receive(void *mq_handle, void *msg_ptr) -{ - int32_t ret; - - if (!mq_handle || !msg_ptr) { - return MAILBOX_INVAL_PARAMS; - } - - while (1) { - ret = os_wrapper_msg_queue_receive(mq_handle, msg_ptr); - if (ret == OS_WRAPPER_SUCCESS) { - return MAILBOX_SUCCESS; - } - } - - return MAILBOX_GENERIC_ERROR; -} -#else /* TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD */ -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); -} -#endif /* TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD */ diff --git a/interface/src/tfm_ns_interface.c b/interface/src/tfm_ns_interface.c deleted file mode 100644 index 2f745c23f2..0000000000 --- a/interface/src/tfm_ns_interface.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2017-2021, Arm Limited. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - * - */ -#include <stdint.h> -#include <stdbool.h> - -#include "os_wrapper/mutex.h" - -#include "tfm_api.h" -#include "tfm_ns_interface.h" - -/** - * \brief the ns_lock ID - */ -static void *ns_lock_handle = NULL; - -__attribute__((weak)) -int32_t tfm_ns_interface_dispatch(veneer_fn fn, - uint32_t arg0, uint32_t arg1, - uint32_t arg2, uint32_t arg3) -{ - int32_t result; - - /* TFM request protected by NS lock */ - while (os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER) - != OS_WRAPPER_SUCCESS); - - result = fn(arg0, arg1, arg2, arg3); - - while (os_wrapper_mutex_release(ns_lock_handle) != OS_WRAPPER_SUCCESS); - - return result; -} - -__attribute__((weak)) -enum tfm_status_e tfm_ns_interface_init(void) -{ - void *handle; - - handle = os_wrapper_mutex_create(); - if (!handle) { - return TFM_ERROR_GENERIC; - } - - ns_lock_handle = handle; - return TFM_SUCCESS; -} diff --git a/interface/src/tfm_ns_interface.c.example b/interface/src/tfm_ns_interface.c.example new file mode 100644 index 0000000000..520aba2024 --- /dev/null +++ b/interface/src/tfm_ns_interface.c.example @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2017-2021, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +/* + * An example to implement tfm_ns_interface_dispatch() in NS RTOS to integrate + * TF-M interface on Armv8-M TrustZone based platforms. + * + * In this example, NS OS calls mutex in tfm_ns_interface_dispatch() to + * synchronize multiple NS client calls. + * NS OS pseudo code in this example is not based on any specific RTOS. + * + * Please note that this example cannot be built directly. + */ + +#include <stdint.h> + +/* Include NS RTOS specific mutex declarations */ +#include "mutex.h" +#include "tfm_ns_interface.h" + +/* Static ns lock handle */ +static void *ns_lock_handle = NULL; + +/* Initialize the ns lock */ +int32_t ns_interface_lock_init(...) +{ + /* NS RTOS specific mutex creation/initialization */ + ns_lock_handle = os_mutex_create(...); + if (ns_lock_handle) { + return OS_SUCCESS; + } + + return OS_ERROR; +} + +int32_t tfm_ns_interface_dispatch(veneer_fn fn, + uint32_t arg0, uint32_t arg1, + uint32_t arg2, uint32_t arg3) +{ + int32_t result; + + /* TF-M request protected by NS lock. */ + while (os_mutex_acquire(ns_lock_handle, ...) != OS_SUCCESS); + + result = fn(arg0, arg1, arg2, arg3); + + /* + * Whether to check/handle lock release return code depends on NS RTOS + * specific implementation and usage scenario. + */ + os_mutex_release(ns_lock_handle, ...); + + return result; +} |