aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hu <david.hu@arm.com>2021-04-06 18:03:33 +0800
committerDavid Hu <david.hu@arm.com>2021-04-29 08:56:18 +0200
commitf07f3f16c35beed23772e83453a7c08d0b78ddb8 (patch)
treeba2fdf5865104d1b272af6db21589ac1047c5bc0
parent7c2a744b3712f481b9dc7ab89bcc0ef5cb30f5fa (diff)
downloadtrusted-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>
-rw-r--r--cmake/install.cmake15
-rw-r--r--interface/CMakeLists.txt1
-rw-r--r--interface/include/os_wrapper/common.h26
-rw-r--r--interface/include/os_wrapper/msg_queue.h70
-rw-r--r--interface/include/os_wrapper/mutex.h62
-rw-r--r--interface/include/os_wrapper/semaphore.h64
-rw-r--r--interface/include/os_wrapper/thread.h103
-rw-r--r--interface/include/os_wrapper/tick.h28
-rw-r--r--interface/include/tfm_ns_interface.h22
-rw-r--r--interface/src/multi_core/tfm_multi_core_ns_api.c7
-rw-r--r--interface/src/multi_core/tfm_ns_mailbox_rtos_api.c116
-rw-r--r--interface/src/tfm_ns_interface.c50
-rw-r--r--interface/src/tfm_ns_interface.c.example58
13 files changed, 68 insertions, 554 deletions
diff --git a/cmake/install.cmake b/cmake/install.cmake
index 048c90094..b7941441d 100644
--- a/cmake/install.cmake
+++ b/cmake/install.cmake
@@ -34,14 +34,6 @@ install(FILES ${INTERFACE_INC_DIR}/psa/client.h
${INTERFACE_INC_DIR}/psa/error.h
DESTINATION ${INSTALL_INTERFACE_INC_DIR}/psa)
-install(FILES ${INTERFACE_INC_DIR}/os_wrapper/common.h
- ${INTERFACE_INC_DIR}/os_wrapper/msg_queue.h
- ${INTERFACE_INC_DIR}/os_wrapper/mutex.h
- ${INTERFACE_INC_DIR}/os_wrapper/semaphore.h
- ${INTERFACE_INC_DIR}/os_wrapper/thread.h
- ${INTERFACE_INC_DIR}/os_wrapper/tick.h
- DESTINATION ${INSTALL_INTERFACE_INC_DIR}/os_wrapper)
-
install(FILES ${CMAKE_BINARY_DIR}/generated/interface/include/psa_manifest/sid.h
DESTINATION ${INSTALL_INTERFACE_INC_DIR}/psa_manifest)
@@ -124,18 +116,17 @@ if (TFM_MULTI_CORE_TOPOLOGY)
install(FILES ${INTERFACE_SRC_DIR}/multi_core/tfm_ns_mailbox.c
${INTERFACE_SRC_DIR}/multi_core/tfm_multi_core_ns_api.c
${INTERFACE_SRC_DIR}/multi_core/tfm_multi_core_psa_ns_api.c
- ${INTERFACE_SRC_DIR}/multi_core/tfm_ns_mailbox_rtos_api.c
${INTERFACE_SRC_DIR}/multi_core/tfm_ns_mailbox_thread.c
${INTERFACE_SRC_DIR}/multi_core/tfm_ns_mailbox_test.c
DESTINATION ${INSTALL_INTERFACE_SRC_DIR})
else()
- install(FILES ${INTERFACE_SRC_DIR}/tfm_ns_interface.c
- DESTINATION ${INSTALL_INTERFACE_SRC_DIR})
-
if(TFM_PSA_API)
install(FILES ${INTERFACE_SRC_DIR}/tfm_psa_ns_api.c
DESTINATION ${INSTALL_INTERFACE_SRC_DIR})
endif()
+
+ install(FILES ${INTERFACE_SRC_DIR}/tfm_ns_interface.c.example
+ DESTINATION ${INSTALL_INTERFACE_SRC_DIR})
endif()
if (TFM_NS_CLIENT_IDENTIFICATION)
diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt
index 16e6504ee..06eec16a8 100644
--- a/interface/CMakeLists.txt
+++ b/interface/CMakeLists.txt
@@ -26,7 +26,6 @@ target_include_directories(psa_interface
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_BINARY_DIR}/generated/interface/include
- ${CMAKE_CURRENT_SOURCE_DIR}/include/os_wrapper
$<$<OR:$<BOOL:${FORWARD_PROT_MSG}>,$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>>:${CMAKE_CURRENT_SOURCE_DIR}/include/multi_core>
)
diff --git a/interface/include/os_wrapper/common.h b/interface/include/os_wrapper/common.h
deleted file mode 100644
index 649472303..000000000
--- a/interface/include/os_wrapper/common.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#ifndef __OS_WRAPPER_COMMON_H__
-#define __OS_WRAPPER_COMMON_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdint.h>
-
-#define OS_WRAPPER_SUCCESS (0x0)
-#define OS_WRAPPER_ERROR (0xFFFFFFFFU)
-#define OS_WRAPPER_WAIT_FOREVER (0xFFFFFFFFU)
-#define OS_WRAPPER_DEFAULT_STACK_SIZE (-1)
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __OS_WRAPPER_COMMON_H__ */
diff --git a/interface/include/os_wrapper/msg_queue.h b/interface/include/os_wrapper/msg_queue.h
deleted file mode 100644
index ac69773f1..000000000
--- a/interface/include/os_wrapper/msg_queue.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#ifndef __OS_WRAPPER_MSG_QUEUE_H__
-#define __OS_WRAPPER_MSG_QUEUE_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stddef.h>
-
-#include "common.h"
-
-/**
- * \brief Create and initialize a message queue
- *
- * \param[in] msg_size The maximum message size in bytes
- * \param[in] msg_count The maximum number of messages in queue
- *
- * \return Returns handle of the message queue created, or NULL in case of error
- */
-void *os_wrapper_msg_queue_create(size_t msg_size, uint8_t msg_count);
-
-/**
- * \brief Send a message via message queue
- *
- * \param[in] mq_handle The handle of message queue
- * \param[in] msg_ptr The pointer to the message to be sent
- *
- * \return \ref OS_WRAPPER_SUCCESS if the message is successfully sent, or
- * \ref OS_WRAPPER_ERROR in case of error
- *
- * \note The message size must be the same as the value set in
- * \ref os_wrapper_msg_queue_create.
- *
- * \note Time out value is not specified here. Whether the function is blocked
- * or returns instantly depends on the actual implementation and usage
- * scenario.
- */
-int32_t os_wrapper_msg_queue_send(void *mq_handle,
- const void *msg_ptr);
-
-/**
- * \brief Receive a message from message queue
- *
- * \param[in] mq_handle The handle of message queue
- * \param[in] msg_ptr The pointer to buffer for message to be received
- *
- * \return \ref OS_WRAPPER_SUCCESS if the message is successfully received, or
- * \ref OS_WRAPPER_ERROR in case of error
- *
- * \note The message size is the same as the value set in
- * \ref os_wrapper_msg_queue_create.
- *
- * \note The function should be blocked until a message is received from message
- * queue, unless an error occurs.
- */
-int32_t os_wrapper_msg_queue_receive(void *mq_handle,
- void *msg_ptr);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __OS_WRAPPER_MSG_QUEUE_H__ */
diff --git a/interface/include/os_wrapper/mutex.h b/interface/include/os_wrapper/mutex.h
deleted file mode 100644
index e55ef706e..000000000
--- a/interface/include/os_wrapper/mutex.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#ifndef __OS_WRAPPER_MUTEX_H__
-#define __OS_WRAPPER_MUTEX_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "common.h"
-
-/**
- * \brief Creates a mutex for mutual exclusion of resources
- *
- * \return The handle of the created mutex on success or NULL on error
- */
-void *os_wrapper_mutex_create(void);
-
-/**
- * \brief Acquires a mutex that is created by \ref os_wrapper_mutex_create()
- *
- * \param[in] handle The handle of the mutex to acquire. Should be one of the
- * handles returned by \ref os_wrapper_mutex_create()
- * \param[in] timeout The maximum amount of time(in tick periods) for the
- * thread to wait for the mutex to be available.
- * If timeout is zero, the function will return immediately.
- * Setting timeout to \ref OS_WRAPPER_WAIT_FOREVER will
- * cause the thread to wait indefinitely
- *
- * \return \ref OS_WRAPPER_SUCCESS on success or \ref OS_WRAPPER_ERROR on error
- */
-uint32_t os_wrapper_mutex_acquire(void *handle, uint32_t timeout);
-
-/**
- * \brief Releases the mutex acquired previously
- *
-
- * \param[in] handle The handle of the mutex that has been acquired
- *
- * \return \ref OS_WRAPPER_SUCCESS on success or \ref OS_WRAPPER_ERROR on error
- */
-uint32_t os_wrapper_mutex_release(void *handle);
-
-/**
- * \brief Deletes a mutex that is created by \ref os_wrapper_mutex_create()
- *
- * \param[in] handle The handle of the mutex to be deleted
- *
- * \return \ref OS_WRAPPER_SUCCESS on success or \ref OS_WRAPPER_ERROR on error
- */
-uint32_t os_wrapper_mutex_delete(void *handle);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __OS_WRAPPER_MUTEX_H__ */
diff --git a/interface/include/os_wrapper/semaphore.h b/interface/include/os_wrapper/semaphore.h
deleted file mode 100644
index 83d88cac6..000000000
--- a/interface/include/os_wrapper/semaphore.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#ifndef __OS_WRAPPER_SEMAPHORE_H__
-#define __OS_WRAPPER_SEMAPHORE_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "common.h"
-
-/**
- * \brief Creates a new semaphore
- *
- * \param[in] max_count Highest count of the semaphore
- * \param[in] initial_count Starting count of the available semaphore
- * \param[in] name Name of the semaphore
- *
- * \return Returns handle of the semaphore created, or NULL in case of error
- */
-void *os_wrapper_semaphore_create(uint32_t max_count, uint32_t initial_count,
- const char *name);
-
-/**
- * \brief Acquires the semaphore
- *
- * \param[in] hanlde Semaphore handle
- * \param[in] timeout Timeout value
- *
- * \return \ref OS_WRAPPER_SUCCESS in case of successful acquision, or
- * \ref OS_WRAPPER_ERROR in case of error
- */
-uint32_t os_wrapper_semaphore_acquire(void *handle, uint32_t timeout);
-
-/**
- * \brief Releases the semaphore
- *
- * \param[in] hanlde Semaphore handle
- *
- * \return \ref OS_WRAPPER_SUCCESS in case of successful release, or
- * \ref OS_WRAPPER_ERROR in case of error
- */
-uint32_t os_wrapper_semaphore_release(void *handle);
-
-/**
- * \brief Deletes the semaphore
- *
- * \param[in] handle Semaphore handle
- *
- * \return \ref OS_WRAPPER_SUCCESS in case of successful release, or
- * \ref OS_WRAPPER_ERROR in case of error
- */
-uint32_t os_wrapper_semaphore_delete(void *handle);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __OS_WRAPPER_SEMAPHORE_H__ */
diff --git a/interface/include/os_wrapper/thread.h b/interface/include/os_wrapper/thread.h
deleted file mode 100644
index a493593a6..000000000
--- a/interface/include/os_wrapper/thread.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#ifndef __OS_WRAPPER_THREAD_H__
-#define __OS_WRAPPER_THREAD_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "common.h"
-
-/* prototype for the thread entry function */
-typedef void (*os_wrapper_thread_func) (void *argument);
-
-/**
- * \brief Creates a new thread
- *
- * \param[in] name Name of the thread
- * \param[in] stack_size Size of stack to be allocated for this thread. It can
- * be \ref OS_WRAPPER_DEFAULT_STACK_SIZE to use the
- * default value provided by the underlying RTOS
- * \param[in] func Pointer to the function invoked by thread
- * \param[in] arg Argument to pass to the function invoked by thread
- * \param[in] priority Initial thread priority
- *
- * \return Returns the thread handle created, or NULL in case of error
- */
-void *os_wrapper_thread_new(const char *name, int32_t stack_size,
- os_wrapper_thread_func func, void *arg,
- uint32_t priority);
-/**
- * \brief Gets current thread handle
- *
- * \return Returns the thread handle, or NULL in case of error
- */
-void *os_wrapper_thread_get_handle(void);
-
-/**
- * \brief Gets thread priority
- *
- * \param[in] handle Thread handle
- * \param[out] priority The priority of the thread
- *
- * \return Returns \ref OS_WRAPPER_SUCCESS on success, or \ref OS_WRAPPER_ERROR
- * in case of error
- */
-uint32_t os_wrapper_thread_get_priority(void *handle, uint32_t *priority);
-
-/**
- * \brief Exits the calling thread
- */
-void os_wrapper_thread_exit(void);
-
-/**
- * \brief Set the event flags for synchronizing a thread specified by handle.
- *
- * \note This function may not be allowed to be called from Interrupt Service
- * Routines.
- *
- * \param[in] handle Thread handle to be notified
- * \param[in] flags Event flags value
- *
- * \return Returns \ref OS_WRAPPER_SUCCESS on success, or \ref OS_WRAPPER_ERROR
- * in case of error
- */
-uint32_t os_wrapper_thread_set_flag(void *handle, uint32_t flags);
-
-/**
- * \brief Set the event flags in an interrupt handler for synchronizing a thread
- * specified by handle.
- *
- * \param[in] handle Thread handle to be notified
- * \param[in] flags Event flags value
- *
- * \return Returns \ref OS_WRAPPER_SUCCESS on success, or \ref OS_WRAPPER_ERROR
- * in case of error
- */
-uint32_t os_wrapper_thread_set_flag_isr(void *handle, uint32_t flags);
-
-/**
- * \brief Wait for the event flags for synchronizing threads.
- *
- * \note This function may not be allowed to be called from Interrupt Service
- * Routines.
- *
- * \param[in] flags Specify the flags to wait for
- * \param[in] timeout Timeout value
- *
- * \return Returns \ref OS_WRAPPER_SUCCESS on success, or \ref OS_WRAPPER_ERROR
- * in case of error
- */
-uint32_t os_wrapper_thread_wait_flag(uint32_t flags, uint32_t timeout);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __OS_WRAPPER_THREAD_H__ */
diff --git a/interface/include/os_wrapper/tick.h b/interface/include/os_wrapper/tick.h
deleted file mode 100644
index b377b0e5f..000000000
--- a/interface/include/os_wrapper/tick.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2020, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#ifndef __OS_WRAPPER_TICK_H__
-#define __OS_WRAPPER_TICK_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "common.h"
-
-/**
- * \brief Return RTOS current tick count
- *
- * \return The current tick count
- */
-uint32_t os_wrapper_get_tick(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __OS_WRAPPER_TICK_H__ */
diff --git a/interface/include/tfm_ns_interface.h b/interface/include/tfm_ns_interface.h
index 1dd069257..fa0cc3174 100644
--- a/interface/include/tfm_ns_interface.h
+++ b/interface/include/tfm_ns_interface.h
@@ -24,11 +24,14 @@ typedef int32_t (*veneer_fn) (uint32_t arg0, uint32_t arg1,
* desired veneer function, to be called with the parameters
* described from arg0 to arg3.
*
+ * \note NSPE shall implement this dispatcher according to NS specific
+ * implementation and actual usage scenario.
+ *
* \param[in] fn Function pointer to the veneer function desired
- * \param[in] arg0 Argument 0
- * \param[in] arg1 Argument 1
- * \param[in] arg2 Argument 2
- * \param[in] arg3 Argument 3
+ * \param[in] arg0 Argument 0 of fn
+ * \param[in] arg1 Argument 1 of fn
+ * \param[in] arg2 Argument 2 of fn
+ * \param[in] arg3 Argument 3 of fn
*
* \return Returns the same return value of the requested veneer function
*
@@ -40,17 +43,6 @@ int32_t tfm_ns_interface_dispatch(veneer_fn fn,
uint32_t arg0, uint32_t arg1,
uint32_t arg2, uint32_t arg3);
-/**
- * \brief NS interface, Initialise the NS interface
- *
- * \details This function needs to be called from the NS world to
- * properly initialise the NS interface towards TF-M. This
- * function will initialise all the objects required for
- * runtime dispatching of TF-M requests to services
- *
- * \return A value according to \ref enum tfm_status_e
- */
-enum tfm_status_e tfm_ns_interface_init(void);
#ifdef __cplusplus
}
#endif
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 ce9233c65..dba68d896 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 629e108c8..000000000
--- 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 2f745c23f..000000000
--- 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 000000000..520aba202
--- /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;
+}