blob: 3bd401bcaa60a3856171963ffec3a37fe78a57d4 [file] [log] [blame]
David Hucdc51fb2021-04-06 18:10:46 +08001/*
2 * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7#include <stdint.h>
8
9#include "os_wrapper/mutex.h"
10
11#include "tfm_ns_interface.h"
12
13/**
14 * \brief the ns_lock ID
15 */
16static void *ns_lock_handle = NULL;
17
18int32_t tfm_ns_interface_dispatch(veneer_fn fn,
19 uint32_t arg0, uint32_t arg1,
20 uint32_t arg2, uint32_t arg3)
21{
22 int32_t result;
23
24 /* TFM request protected by NS lock */
25 while (os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER)
26 != OS_WRAPPER_SUCCESS);
27
28 result = fn(arg0, arg1, arg2, arg3);
29
30 while (os_wrapper_mutex_release(ns_lock_handle) != OS_WRAPPER_SUCCESS);
31
32 return result;
33}
34
35uint32_t tfm_ns_interface_init(void)
36{
37 void *handle;
38
39 handle = os_wrapper_mutex_create();
40 if (!handle) {
41 return OS_WRAPPER_ERROR;
42 }
43
44 ns_lock_handle = handle;
45 return OS_WRAPPER_SUCCESS;
46}