blob: 520aba2024aef794e66d2c15017c7e2b6d281c47 [file] [log] [blame]
David Huf07f3f12021-04-06 18:03:33 +08001/*
2 * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8/*
9 * An example to implement tfm_ns_interface_dispatch() in NS RTOS to integrate
10 * TF-M interface on Armv8-M TrustZone based platforms.
11 *
12 * In this example, NS OS calls mutex in tfm_ns_interface_dispatch() to
13 * synchronize multiple NS client calls.
14 * NS OS pseudo code in this example is not based on any specific RTOS.
15 *
16 * Please note that this example cannot be built directly.
17 */
18
19#include <stdint.h>
20
21/* Include NS RTOS specific mutex declarations */
22#include "mutex.h"
23#include "tfm_ns_interface.h"
24
25/* Static ns lock handle */
26static void *ns_lock_handle = NULL;
27
28/* Initialize the ns lock */
29int32_t ns_interface_lock_init(...)
30{
31 /* NS RTOS specific mutex creation/initialization */
32 ns_lock_handle = os_mutex_create(...);
33 if (ns_lock_handle) {
34 return OS_SUCCESS;
35 }
36
37 return OS_ERROR;
38}
39
40int32_t tfm_ns_interface_dispatch(veneer_fn fn,
41 uint32_t arg0, uint32_t arg1,
42 uint32_t arg2, uint32_t arg3)
43{
44 int32_t result;
45
46 /* TF-M request protected by NS lock. */
47 while (os_mutex_acquire(ns_lock_handle, ...) != OS_SUCCESS);
48
49 result = fn(arg0, arg1, arg2, arg3);
50
51 /*
52 * Whether to check/handle lock release return code depends on NS RTOS
53 * specific implementation and usage scenario.
54 */
55 os_mutex_release(ns_lock_handle, ...);
56
57 return result;
58}