blob: 2f745c23f262d5d7a00fb1fb1392b47764cb69e5 [file] [log] [blame]
Kevin Pengc86dec02019-07-23 16:15:57 +08001/*
Kevin Peng5ec79652021-01-27 10:01:31 +08002 * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
Kevin Pengc86dec02019-07-23 16:15:57 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7#include <stdint.h>
8#include <stdbool.h>
9
Kevin Peng477fa942019-07-29 10:55:17 +080010#include "os_wrapper/mutex.h"
Kevin Pengc86dec02019-07-23 16:15:57 +080011
12#include "tfm_api.h"
13#include "tfm_ns_interface.h"
14
15/**
16 * \brief the ns_lock ID
17 */
Kevin Peng383e8402019-08-05 16:35:44 +080018static void *ns_lock_handle = NULL;
Kevin Pengc86dec02019-07-23 16:15:57 +080019
20__attribute__((weak))
21int32_t tfm_ns_interface_dispatch(veneer_fn fn,
22 uint32_t arg0, uint32_t arg1,
23 uint32_t arg2, uint32_t arg3)
24{
25 int32_t result;
26
27 /* TFM request protected by NS lock */
Kevin Peng5ec79652021-01-27 10:01:31 +080028 while (os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER)
29 != OS_WRAPPER_SUCCESS);
Kevin Pengc86dec02019-07-23 16:15:57 +080030
31 result = fn(arg0, arg1, arg2, arg3);
32
Kevin Peng5ec79652021-01-27 10:01:31 +080033 while (os_wrapper_mutex_release(ns_lock_handle) != OS_WRAPPER_SUCCESS);
Kevin Pengc86dec02019-07-23 16:15:57 +080034
35 return result;
36}
37
38__attribute__((weak))
39enum tfm_status_e tfm_ns_interface_init(void)
40{
Kevin Peng383e8402019-08-05 16:35:44 +080041 void *handle;
Kevin Pengc86dec02019-07-23 16:15:57 +080042
Kevin Peng383e8402019-08-05 16:35:44 +080043 handle = os_wrapper_mutex_create();
44 if (!handle) {
Kevin Pengc86dec02019-07-23 16:15:57 +080045 return TFM_ERROR_GENERIC;
46 }
47
Kevin Peng383e8402019-08-05 16:35:44 +080048 ns_lock_handle = handle;
Kevin Pengc86dec02019-07-23 16:15:57 +080049 return TFM_SUCCESS;
50}