David Hu | cdc51fb | 2021-04-06 18:10:46 +0800 | [diff] [blame^] | 1 | /* |
| 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 | */ |
| 16 | static void *ns_lock_handle = NULL; |
| 17 | |
| 18 | int32_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 | |
| 35 | uint32_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 | } |