blob: 520aba2024aef794e66d2c15017c7e2b6d281c47 [file] [log] [blame]
/*
* Copyright (c) 2017-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
/*
* An example to implement tfm_ns_interface_dispatch() in NS RTOS to integrate
* TF-M interface on Armv8-M TrustZone based platforms.
*
* In this example, NS OS calls mutex in tfm_ns_interface_dispatch() to
* synchronize multiple NS client calls.
* NS OS pseudo code in this example is not based on any specific RTOS.
*
* Please note that this example cannot be built directly.
*/
#include <stdint.h>
/* Include NS RTOS specific mutex declarations */
#include "mutex.h"
#include "tfm_ns_interface.h"
/* Static ns lock handle */
static void *ns_lock_handle = NULL;
/* Initialize the ns lock */
int32_t ns_interface_lock_init(...)
{
/* NS RTOS specific mutex creation/initialization */
ns_lock_handle = os_mutex_create(...);
if (ns_lock_handle) {
return OS_SUCCESS;
}
return OS_ERROR;
}
int32_t tfm_ns_interface_dispatch(veneer_fn fn,
uint32_t arg0, uint32_t arg1,
uint32_t arg2, uint32_t arg3)
{
int32_t result;
/* TF-M request protected by NS lock. */
while (os_mutex_acquire(ns_lock_handle, ...) != OS_SUCCESS);
result = fn(arg0, arg1, arg2, arg3);
/*
* Whether to check/handle lock release return code depends on NS RTOS
* specific implementation and usage scenario.
*/
os_mutex_release(ns_lock_handle, ...);
return result;
}