aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hu <david.hu@arm.com>2019-11-27 10:54:21 +0800
committerDavid Hu <david.hu@arm.com>2019-11-27 10:54:21 +0800
commitd2bd378461e526b90eaf8ad10e285a9e04fb9de8 (patch)
tree55d65900a418333dde44b1de8ed38b615f59fda2
parent7be8356309e41eb77231648d5225491e7f56d312 (diff)
downloadtrusted-firmware-m-d2bd378461e526b90eaf8ad10e285a9e04fb9de8.tar.gz
Dualcpu: Update lock operations in NS PSA Client call interface
Update the lock initialization, acquisition and release inside NS PSA Client call interface, to align with the latest implementation on master branch. Change-Id: Icfd4da19d8c061e7566c31b9b882caf95f922840 Signed-off-by: David Hu <david.hu@arm.com>
-rw-r--r--interface/include/tfm_multi_core_api.h20
-rw-r--r--interface/src/tfm_multi_core_api.c19
-rw-r--r--interface/src/tfm_multi_core_psa_ns_api.c38
3 files changed, 49 insertions, 28 deletions
diff --git a/interface/include/tfm_multi_core_api.h b/interface/include/tfm_multi_core_api.h
index 64b1ed651e..365260f557 100644
--- a/interface/include/tfm_multi_core_api.h
+++ b/interface/include/tfm_multi_core_api.h
@@ -8,6 +8,8 @@
#ifndef __TFM_MULTI_CORE_API__
#define __TFM_MULTI_CORE_API__
+#include <stdint.h>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -33,6 +35,24 @@ int tfm_ns_wait_for_s_cpu_ready(void);
*/
int tfm_platform_ns_wait_for_s_cpu_ready(void);
+/**
+ * \brief Acquire the multi-core lock for synchronizing PSA client call(s)
+ * The actual implementation depends on the use scenario.
+ *
+ * \return \ref OS_WRAPPER_SUCCESS on success
+ * \return \ref OS_WRAPPER_ERROR on error
+ */
+uint32_t tfm_ns_multi_core_lock_acquire(void);
+
+/**
+ * \brief Release the multi-core lock for synchronizing PSA client call(s)
+ * The actual implementation depends on the use scenario.
+ *
+ * \return \ref OS_WRAPPER_SUCCESS on success
+ * \return \ref OS_WRAPPER_ERROR on error
+ */
+uint32_t tfm_ns_multi_core_lock_release(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/interface/src/tfm_multi_core_api.c b/interface/src/tfm_multi_core_api.c
index bd1dc2c723..057e7c38da 100644
--- a/interface/src/tfm_multi_core_api.c
+++ b/interface/src/tfm_multi_core_api.c
@@ -10,19 +10,16 @@
#include "tfm_api.h"
#include "tfm_multi_core_api.h"
-void *ns_lock_handle = NULL;
+static void *ns_lock_handle = NULL;
__attribute__((weak))
enum tfm_status_e tfm_ns_interface_init(void)
{
- void *handle;
-
- handle = os_wrapper_mutex_create();
- if (!handle) {
+ ns_lock_handle = os_wrapper_mutex_create();
+ if (!ns_lock_handle) {
return TFM_ERROR_GENERIC;
}
- ns_lock_handle = handle;
return TFM_SUCCESS;
}
@@ -30,3 +27,13 @@ int tfm_ns_wait_for_s_cpu_ready(void)
{
return tfm_platform_ns_wait_for_s_cpu_ready();
}
+
+uint32_t tfm_ns_multi_core_lock_acquire(void)
+{
+ return os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER);
+}
+
+uint32_t tfm_ns_multi_core_lock_release(void)
+{
+ return os_wrapper_mutex_release(ns_lock_handle);
+}
diff --git a/interface/src/tfm_multi_core_psa_ns_api.c b/interface/src/tfm_multi_core_psa_ns_api.c
index dc80c55ec5..9660d08435 100644
--- a/interface/src/tfm_multi_core_psa_ns_api.c
+++ b/interface/src/tfm_multi_core_psa_ns_api.c
@@ -13,6 +13,7 @@
#include "psa/client.h"
#include "psa/error.h"
#include "tfm_api.h"
+#include "tfm_multi_core_api.h"
#include "tfm_ns_mailbox.h"
/*
@@ -37,8 +38,6 @@
*/
#define PSA_INTER_CORE_COMM_ERR (INT32_MIN + 0xFF)
-extern void *ns_lock_handle;
-
static void mailbox_wait_reply(mailbox_msg_handle_t handle)
{
while (!tfm_ns_mailbox_is_msg_replied(handle)) {};
@@ -53,15 +52,14 @@ uint32_t psa_framework_version(void)
uint32_t version;
int32_t ret;
- if (os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER)
- != OS_WRAPPER_SUCCESS) {
+ if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
return PSA_VERSION_NONE;
}
handle = tfm_ns_mailbox_tx_client_req(MAILBOX_PSA_FRAMEWORK_VERSION,
&params, NON_SECURE_CLIENT_ID);
if (handle < 0) {
- os_wrapper_mutex_release(ns_lock_handle);
+ tfm_ns_multi_core_lock_release();
return PSA_VERSION_NONE;
}
@@ -72,7 +70,7 @@ uint32_t psa_framework_version(void)
version = PSA_VERSION_NONE;
}
- if (os_wrapper_mutex_release(ns_lock_handle) != OS_WRAPPER_SUCCESS) {
+ if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
return PSA_VERSION_NONE;
}
@@ -88,15 +86,14 @@ uint32_t psa_version(uint32_t sid)
params.psa_version_params.sid = sid;
- if (os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER)
- != OS_WRAPPER_SUCCESS) {
+ if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
return PSA_VERSION_NONE;
}
handle = tfm_ns_mailbox_tx_client_req(MAILBOX_PSA_VERSION, &params,
NON_SECURE_CLIENT_ID);
if (handle < 0) {
- os_wrapper_mutex_release(ns_lock_handle);
+ tfm_ns_multi_core_lock_release();
return PSA_VERSION_NONE;
}
@@ -107,7 +104,7 @@ uint32_t psa_version(uint32_t sid)
version = PSA_VERSION_NONE;
}
- if (os_wrapper_mutex_release(ns_lock_handle) != OS_WRAPPER_SUCCESS) {
+ if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
return PSA_VERSION_NONE;
}
@@ -124,15 +121,14 @@ psa_handle_t psa_connect(uint32_t sid, uint32_t minor_version)
params.psa_connect_params.sid = sid;
params.psa_connect_params.minor_version = minor_version;
- if (os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER)
- != OS_WRAPPER_SUCCESS) {
+ if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
return PSA_NULL_HANDLE;
}
handle = tfm_ns_mailbox_tx_client_req(MAILBOX_PSA_CONNECT, &params,
NON_SECURE_CLIENT_ID);
if (handle < 0) {
- os_wrapper_mutex_release(ns_lock_handle);
+ tfm_ns_multi_core_lock_release();
return PSA_NULL_HANDLE;
}
@@ -143,7 +139,7 @@ psa_handle_t psa_connect(uint32_t sid, uint32_t minor_version)
psa_handle = PSA_NULL_HANDLE;
}
- if (os_wrapper_mutex_release(ns_lock_handle) != OS_WRAPPER_SUCCESS) {
+ if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
return PSA_NULL_HANDLE;
}
@@ -166,15 +162,14 @@ psa_status_t psa_call(psa_handle_t handle, int32_t type,
params.psa_call_params.out_vec = out_vec;
params.psa_call_params.out_len = out_len;
- if (os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER)
- != OS_WRAPPER_SUCCESS) {
+ if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
return PSA_ERROR_GENERIC_ERROR;
}
msg_handle = tfm_ns_mailbox_tx_client_req(MAILBOX_PSA_CALL, &params,
NON_SECURE_CLIENT_ID);
if (msg_handle < 0) {
- os_wrapper_mutex_release(ns_lock_handle);
+ tfm_ns_multi_core_lock_release();
return PSA_INTER_CORE_COMM_ERR;
}
@@ -185,7 +180,7 @@ psa_status_t psa_call(psa_handle_t handle, int32_t type,
status = PSA_INTER_CORE_COMM_ERR;
}
- if (os_wrapper_mutex_release(ns_lock_handle) != OS_WRAPPER_SUCCESS) {
+ if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
return PSA_ERROR_GENERIC_ERROR;
}
@@ -200,15 +195,14 @@ void psa_close(psa_handle_t handle)
params.psa_close_params.handle = handle;
- if (os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER)
- != OS_WRAPPER_SUCCESS) {
+ if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
return;
}
msg_handle = tfm_ns_mailbox_tx_client_req(MAILBOX_PSA_CLOSE, &params,
NON_SECURE_CLIENT_ID);
if (msg_handle < 0) {
- os_wrapper_mutex_release(ns_lock_handle);
+ tfm_ns_multi_core_lock_release();
return;
}
@@ -216,5 +210,5 @@ void psa_close(psa_handle_t handle)
(void)tfm_ns_mailbox_rx_client_reply(msg_handle, &reply);
- os_wrapper_mutex_release(ns_lock_handle);
+ tfm_ns_multi_core_lock_release();
}