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>
diff --git a/interface/src/tfm_ns_interface.c.example b/interface/src/tfm_ns_interface.c.example
new file mode 100644
index 0000000..520aba2
--- /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;
+}