1 /*
2 * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
3 * Copyright (c) 2023 Cypress Semiconductor Corporation (an Infineon company)
4 * or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 *
8 */
9
10 /* This file provides implementation of TF-M NS os wrapper functions for the
11 * RTOS use case. This implementation provides multithread safety, so it
12 * can be used in RTOS environment.
13 */
14
15 #include <stdint.h>
16
17 #include "os_wrapper/mutex.h"
18
19 #include "tfm_ns_interface.h"
20
21 /**
22 * \brief the ns_lock ID
23 */
24 static void *ns_lock_handle = NULL;
25
tfm_ns_interface_dispatch(veneer_fn fn,uint32_t arg0,uint32_t arg1,uint32_t arg2,uint32_t arg3)26 int32_t tfm_ns_interface_dispatch(veneer_fn fn,
27 uint32_t arg0, uint32_t arg1,
28 uint32_t arg2, uint32_t arg3)
29 {
30 int32_t result;
31
32 /* TFM request protected by NS lock */
33 while (os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER)
34 != OS_WRAPPER_SUCCESS) {
35 }
36
37 result = fn(arg0, arg1, arg2, arg3);
38
39 while (os_wrapper_mutex_release(ns_lock_handle) != OS_WRAPPER_SUCCESS) {
40 }
41
42 return result;
43 }
44
tfm_ns_interface_init(void)45 uint32_t tfm_ns_interface_init(void)
46 {
47 void *handle;
48
49 handle = os_wrapper_mutex_create();
50 if (!handle) {
51 return OS_WRAPPER_ERROR;
52 }
53
54 ns_lock_handle = handle;
55 return OS_WRAPPER_SUCCESS;
56 }
57