aboutsummaryrefslogtreecommitdiff
path: root/interface
diff options
context:
space:
mode:
Diffstat (limited to 'interface')
-rw-r--r--interface/include/tfm_mailbox.h3
-rw-r--r--interface/include/tfm_multi_core_api.h16
-rw-r--r--interface/include/tfm_ns_mailbox.h121
-rw-r--r--interface/src/tfm_multi_core_psa_ns_api.c129
-rw-r--r--interface/src/tfm_ns_mailbox.c150
5 files changed, 167 insertions, 252 deletions
diff --git a/interface/include/tfm_mailbox.h b/interface/include/tfm_mailbox.h
index 3d128f40b2..71f8ae77a9 100644
--- a/interface/include/tfm_mailbox.h
+++ b/interface/include/tfm_mailbox.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -73,6 +73,7 @@ extern "C" {
#define MAILBOX_CHAN_BUSY (INT32_MIN + 5)
#define MAILBOX_CALLBACK_REG_ERROR (INT32_MIN + 6)
#define MAILBOX_INIT_ERROR (INT32_MIN + 7)
+#define MAILBOX_GENERIC_ERROR (INT32_MIN + 8)
/*
* This structure holds the parameters used in a PSA client call.
diff --git a/interface/include/tfm_multi_core_api.h b/interface/include/tfm_multi_core_api.h
index da76b62ec8..908b1376cf 100644
--- a/interface/include/tfm_multi_core_api.h
+++ b/interface/include/tfm_multi_core_api.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -14,6 +14,8 @@ extern "C" {
#include <stdint.h>
+#include "os_wrapper/common.h"
+
/**
* \brief Called on the non-secure CPU.
* Flags that the non-secure side has completed its initialization.
@@ -36,6 +38,17 @@ int32_t tfm_ns_wait_for_s_cpu_ready(void);
*/
int32_t tfm_platform_ns_wait_for_s_cpu_ready(void);
+#ifdef FORWARD_PROT_MSG
+static inline uint32_t tfm_ns_multi_core_lock_acquire(void)
+{
+ return OS_WRAPPER_SUCCESS;
+}
+
+static inline uint32_t tfm_ns_multi_core_lock_release(void)
+{
+ return OS_WRAPPER_SUCCESS;
+}
+#else /* FORWARD_PROT_MSG */
/**
* \brief Acquire the multi-core lock for synchronizing PSA client call(s)
* The actual implementation depends on the use scenario.
@@ -53,6 +66,7 @@ uint32_t tfm_ns_multi_core_lock_acquire(void);
* \return \ref OS_WRAPPER_ERROR on error
*/
uint32_t tfm_ns_multi_core_lock_release(void);
+#endif /* FORWARD_PROT_MSG */
#ifdef __cplusplus
}
diff --git a/interface/include/tfm_ns_mailbox.h b/interface/include/tfm_ns_mailbox.h
index ba902aa977..bdca18c99e 100644
--- a/interface/include/tfm_ns_mailbox.h
+++ b/interface/include/tfm_ns_mailbox.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -35,54 +35,34 @@ struct ns_mailbox_stats_res_t {
#endif
/**
- * \brief Prepare and send PSA client request to SPE via mailbox.
- *
- * \param[in] call_type PSA client call type
- * \param[in] params Parmaters used for PSA client call
- * \param[in] client_id Optional client ID of non-secure caller.
- * It is required to identify the non-secure caller
- * when NSPE OS enforces non-secure task isolation.
- *
- * \retval >= 0 The handle to the mailbox message assigned.
- * \retval < 0 Operation failed with an error code.
- */
-mailbox_msg_handle_t tfm_ns_mailbox_tx_client_req(uint32_t call_type,
- const struct psa_client_params_t *params,
- int32_t client_id);
-
-/**
- * \brief Fetch PSA client return result.
+ * \brief NSPE mailbox initialization
*
- * \param[in] handle The handle to the mailbox message
- * \param[out] reply The address to be written with return result.
+ * \param[in] queue The base address of NSPE mailbox queue to be
+ * initialized.
*
- * \retval MAILBOX_SUCCESS Successfully get PSA client call return result.
+ * \retval MAILBOX_SUCCESS Operation succeeded.
* \retval Other return code Operation failed with an error code.
*/
-int32_t tfm_ns_mailbox_rx_client_reply(mailbox_msg_handle_t handle,
- int32_t *reply);
-
-/**
- * \brief Check whether a specific mailbox message has been replied.
- *
- * \param[in] handle The handle to the mailbox message
- *
- * \retval true The PSA client call return value is replied.
- * \retval false The PSA client call return value is not
- * replied yet.
- */
-bool tfm_ns_mailbox_is_msg_replied(mailbox_msg_handle_t handle);
+int32_t tfm_ns_mailbox_init(struct ns_mailbox_queue_t *queue);
/**
- * \brief NSPE mailbox initialization
+ * \brief Send PSA client call to SPE via mailbox. Wait and fetch PSA client
+ * call result.
*
- * \param[in] queue The base address of NSPE mailbox queue to be
- * initialized.
+ * \param[in] call_type PSA client call type
+ * \param[in] params Parameters used for PSA client call
+ * \param[in] client_id Optional client ID of non-secure caller.
+ * It is required to identify the non-secure caller
+ * when NSPE OS enforces non-secure task isolation.
+ * \param[out] reply The buffer written with PSA client call result.
*
- * \retval MAILBOX_SUCCESS Operation succeeded.
+ * \retval MAILBOX_SUCCESS The PSA client call is completed successfully.
* \retval Other return code Operation failed with an error code.
*/
-int32_t tfm_ns_mailbox_init(struct ns_mailbox_queue_t *queue);
+int32_t tfm_ns_mailbox_client_call(uint32_t call_type,
+ const struct psa_client_params_t *params,
+ int32_t client_id,
+ int32_t *reply);
#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
/**
@@ -105,43 +85,22 @@ static inline const void *tfm_ns_mailbox_get_task_handle(void)
#endif
/**
- * \brief Fetch the handle to the first replied mailbox message in the NSPE
- * mailbox queue.
+ * \brief Wake up the owner task of the first replied mailbox message in the
+ * NSPE mailbox queue.
* This function is intended to be called inside platform specific
* notification IRQ handler.
*
* \note The replied status of the fetched mailbox message will be cleaned after
- * the message is fetched. When this function is called again, it fetches
- * the next replied mailbox message from the NSPE mailbox queue.
+ * the message is fetched. When this function is called again, it wakes
+ * the owner task of next replied mailbox message from the NSPE mailbox
+ * queue.
*
- * \return Return the handle to the first replied mailbox message in the
- * queue.
- * Return \ref MAILBOX_MSG_NULL_HANDLE if no mailbox message is replied.
+ * \return MAILBOX_SUCCESS The task of the first replied mailbox message
+ * is found and wake-up signal is sent.
+ * \return MAILBOX_NO_PEND_EVENT No replied mailbox message is found.
+ * \return Other return code Failed with an error code
*/
-mailbox_msg_handle_t tfm_ns_mailbox_fetch_reply_msg_isr(void);
-
-/**
- * \brief Return the handle of owner task of a mailbox message according to the
- * \ref mailbox_msg_handle_t
- *
- * \param[in] handle The handle of mailbox message.
- *
- * \return Return the handle value of the owner task.
- */
-const void *tfm_ns_mailbox_get_msg_owner(mailbox_msg_handle_t handle);
-
-#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
-/**
- * \brief Wait for the reply returned from SPE to the mailbox message specified
- * by handle
- *
- * \param[in] handle The handle of mailbox message.
- *
- * \retval MAILBOX_SUCCESS Return from waiting successfully.
- * \retval Other return code Failed to wait with an error code.
- */
-int32_t tfm_ns_mailbox_wait_reply(mailbox_msg_handle_t handle);
-#endif
+int32_t tfm_ns_mailbox_wake_reply_owner_isr(void);
/**
* \brief Platform specific NSPE mailbox initialization.
@@ -199,11 +158,31 @@ void tfm_ns_mailbox_hal_exit_critical_isr(void);
* the reply of the specified mailbox message to be returned from SPE.
*
* \note This function is implemented by platform and NS OS specific waiting
- * mechanism accroding to use scenario.
+ * mechanism according to use scenario.
*
* \param[in] handle The handle of mailbox message.
*/
void tfm_ns_mailbox_hal_wait_reply(mailbox_msg_handle_t handle);
+
+/*
+ * \brief Performs platform and NS OS specific mechanism in a mailbox IRQ
+ * handler, to wake up a sleeping task which is waiting for its mailbox
+ * message reply.
+ *
+ * \note The underlying platform and NS OS specific function called inside this
+ * function should be able to work in an IRQ handler.
+ *
+ * \note This function is implemented by platform and NS OS specific waiting
+ * mechanism according to use scenario.
+ *
+ * \param[in] task_handle The handle to the task to be woken up.
+ * \param[in] handle The mailbox handle which can be used as thread
+ * flag.
+ */
+void tfm_ns_mailbox_hal_wake_task_isr(const void *task_handle,
+ mailbox_msg_handle_t handle);
+#else
+#define tfm_ns_mailbox_hal_wait_reply(handle) do {} while (0)
#endif
#ifdef TFM_MULTI_CORE_TEST
diff --git a/interface/src/tfm_multi_core_psa_ns_api.c b/interface/src/tfm_multi_core_psa_ns_api.c
index c99555e8b6..91d393540b 100644
--- a/interface/src/tfm_multi_core_psa_ns_api.c
+++ b/interface/src/tfm_multi_core_psa_ns_api.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -8,12 +8,9 @@
#include <stdint.h>
#include <stdbool.h>
-#include "os_wrapper/mutex.h"
-
#include "psa/client.h"
#include "psa/error.h"
#include "tfm_api.h"
-#include "tfm_multi_core_api.h"
#include "tfm_ns_mailbox.h"
/*
@@ -38,123 +35,58 @@
*/
#define PSA_INTER_CORE_COMM_ERR (INT32_MIN + 0xFF)
-static void mailbox_wait_reply(mailbox_msg_handle_t handle)
-{
- /*
- * If the system can support multiple outstanding NS PSA Client calls, call
- * tfm_ns_mailbox_wait_reply() to sleep and wait for reply. The NS side
- * should implement tfm_ns_mailbox_hal_wait_reply() and wake-up mechanism.
- * Otherwise, by default, call tfm_ns_mailbox_is_msg_replied() to simply
- * poll the reply status of the mailbox message of current thread.
- */
-#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
- tfm_ns_mailbox_wait_reply(handle);
-#else
- while (!tfm_ns_mailbox_is_msg_replied(handle)) {
- }
-#endif
-}
-
/**** API functions ****/
uint32_t psa_framework_version(void)
{
struct psa_client_params_t params;
- mailbox_msg_handle_t handle;
uint32_t version;
int32_t ret;
- 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) {
- tfm_ns_multi_core_lock_release();
- return PSA_VERSION_NONE;
- }
-
- mailbox_wait_reply(handle);
-
- ret = tfm_ns_mailbox_rx_client_reply(handle, (int32_t *)&version);
+ ret = tfm_ns_mailbox_client_call(MAILBOX_PSA_FRAMEWORK_VERSION,
+ &params, NON_SECURE_CLIENT_ID,
+ (int32_t *)&version);
if (ret != MAILBOX_SUCCESS) {
version = PSA_VERSION_NONE;
}
- if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
- return PSA_VERSION_NONE;
- }
-
return version;
}
uint32_t psa_version(uint32_t sid)
{
struct psa_client_params_t params;
- mailbox_msg_handle_t handle;
uint32_t version;
int32_t ret;
params.psa_version_params.sid = sid;
- 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) {
- tfm_ns_multi_core_lock_release();
- return PSA_VERSION_NONE;
- }
-
- mailbox_wait_reply(handle);
-
- ret = tfm_ns_mailbox_rx_client_reply(handle, (int32_t *)&version);
+ ret = tfm_ns_mailbox_client_call(MAILBOX_PSA_VERSION, &params,
+ NON_SECURE_CLIENT_ID,
+ (int32_t *)&version);
if (ret != MAILBOX_SUCCESS) {
version = PSA_VERSION_NONE;
}
- if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
- return PSA_VERSION_NONE;
- }
-
return version;
}
psa_handle_t psa_connect(uint32_t sid, uint32_t version)
{
struct psa_client_params_t params;
- mailbox_msg_handle_t handle;
psa_handle_t psa_handle;
int32_t ret;
params.psa_connect_params.sid = sid;
params.psa_connect_params.version = version;
- 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) {
- tfm_ns_multi_core_lock_release();
- return PSA_NULL_HANDLE;
- }
-
- mailbox_wait_reply(handle);
-
- ret = tfm_ns_mailbox_rx_client_reply(handle, (int32_t *)&psa_handle);
+ ret = tfm_ns_mailbox_client_call(MAILBOX_PSA_CONNECT, &params,
+ NON_SECURE_CLIENT_ID,
+ (int32_t *)&psa_handle);
if (ret != MAILBOX_SUCCESS) {
psa_handle = PSA_NULL_HANDLE;
}
- if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
- return PSA_NULL_HANDLE;
- }
-
return psa_handle;
}
@@ -163,7 +95,6 @@ psa_status_t psa_call(psa_handle_t handle, int32_t type,
psa_outvec *out_vec, size_t out_len)
{
struct psa_client_params_t params;
- mailbox_msg_handle_t msg_handle;
int32_t ret;
psa_status_t status;
@@ -174,53 +105,23 @@ 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 (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) {
- tfm_ns_multi_core_lock_release();
- return PSA_INTER_CORE_COMM_ERR;
- }
-
- mailbox_wait_reply(msg_handle);
-
- ret = tfm_ns_mailbox_rx_client_reply(msg_handle, (int32_t *)&status);
+ ret = tfm_ns_mailbox_client_call(MAILBOX_PSA_CALL, &params,
+ NON_SECURE_CLIENT_ID,
+ (int32_t *)&status);
if (ret != MAILBOX_SUCCESS) {
status = PSA_INTER_CORE_COMM_ERR;
}
- if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
- return PSA_ERROR_GENERIC_ERROR;
- }
-
return status;
}
void psa_close(psa_handle_t handle)
{
struct psa_client_params_t params;
- mailbox_msg_handle_t msg_handle;
int32_t reply;
params.psa_close_params.handle = handle;
- 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) {
- tfm_ns_multi_core_lock_release();
- return;
- }
-
- mailbox_wait_reply(msg_handle);
-
- (void)tfm_ns_mailbox_rx_client_reply(msg_handle, &reply);
-
- tfm_ns_multi_core_lock_release();
+ (void)tfm_ns_mailbox_client_call(MAILBOX_PSA_CLOSE, &params,
+ NON_SECURE_CLIENT_ID, &reply);
}
diff --git a/interface/src/tfm_ns_mailbox.c b/interface/src/tfm_ns_mailbox.c
index 60758b2d7d..4e44fae8d6 100644
--- a/interface/src/tfm_ns_mailbox.c
+++ b/interface/src/tfm_ns_mailbox.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -8,12 +8,15 @@
#include <string.h>
#include "cmsis_compiler.h"
+#include "os_wrapper/common.h"
+#include "tfm_multi_core_api.h"
#include "tfm_ns_mailbox.h"
-#include "tfm_plat_ns.h"
/* The pointer to NSPE mailbox queue */
static struct ns_mailbox_queue_t *mailbox_queue_ptr = NULL;
+static int32_t mailbox_wait_reply(mailbox_msg_handle_t handle);
+
static inline void clear_queue_slot_empty(uint8_t idx)
{
if (idx < NUM_MAILBOX_QUEUE_SLOT) {
@@ -35,8 +38,8 @@ static inline void set_queue_slot_pend(uint8_t idx)
}
}
-static inline int32_t get_mailbox_msg_handle(uint8_t idx,
- mailbox_msg_handle_t *handle)
+static int32_t get_mailbox_msg_handle(uint8_t idx,
+ mailbox_msg_handle_t *handle)
{
if ((idx >= NUM_MAILBOX_QUEUE_SLOT) || !handle) {
return MAILBOX_INVAL_PARAMS;
@@ -66,6 +69,15 @@ static inline void clear_queue_slot_replied(uint8_t idx)
}
}
+static inline bool is_queue_slot_replied(uint8_t idx)
+{
+ if (idx < NUM_MAILBOX_QUEUE_SLOT) {
+ return mailbox_queue_ptr->replied_slots & (1UL << idx);
+ }
+
+ return false;
+}
+
static inline void set_queue_slot_woken(uint8_t idx)
{
if (idx < NUM_MAILBOX_QUEUE_SLOT) {
@@ -89,7 +101,7 @@ static inline void clear_queue_slot_woken(uint8_t idx)
}
}
-static uint8_t acquire_empty_slot(const struct ns_mailbox_queue_t *queue)
+static uint8_t acquire_empty_slot(struct ns_mailbox_queue_t *queue)
{
uint8_t idx;
mailbox_queue_status_t status;
@@ -193,23 +205,15 @@ void tfm_ns_mailbox_stats_avg_slot(struct ns_mailbox_stats_res_t *stats_res)
}
#endif
-mailbox_msg_handle_t tfm_ns_mailbox_tx_client_req(uint32_t call_type,
- const struct psa_client_params_t *params,
- int32_t client_id)
+static int32_t mailbox_tx_client_req(uint32_t call_type,
+ const struct psa_client_params_t *params,
+ int32_t client_id,
+ mailbox_msg_handle_t *handle)
{
uint8_t idx;
struct mailbox_msg_t *msg_ptr;
- mailbox_msg_handle_t handle;
const void *task_handle;
- if (!mailbox_queue_ptr) {
- return MAILBOX_MSG_NULL_HANDLE;
- }
-
- if (!params) {
- return MAILBOX_MSG_NULL_HANDLE;
- }
-
idx = acquire_empty_slot(mailbox_queue_ptr);
if (idx >= NUM_MAILBOX_QUEUE_SLOT) {
return MAILBOX_QUEUE_FULL;
@@ -233,7 +237,7 @@ mailbox_msg_handle_t tfm_ns_mailbox_tx_client_req(uint32_t call_type,
task_handle = tfm_ns_mailbox_get_task_handle();
set_msg_owner(idx, task_handle);
- get_mailbox_msg_handle(idx, &handle);
+ get_mailbox_msg_handle(idx, handle);
tfm_ns_mailbox_hal_enter_critical();
set_queue_slot_pend(idx);
@@ -241,19 +245,15 @@ mailbox_msg_handle_t tfm_ns_mailbox_tx_client_req(uint32_t call_type,
tfm_ns_mailbox_hal_notify_peer();
- return handle;
+ return MAILBOX_SUCCESS;
}
-int32_t tfm_ns_mailbox_rx_client_reply(mailbox_msg_handle_t handle,
+static int32_t mailbox_rx_client_reply(mailbox_msg_handle_t handle,
int32_t *reply)
{
uint8_t idx;
int32_t ret;
- if (!mailbox_queue_ptr) {
- return MAILBOX_INVAL_PARAMS;
- }
-
if ((handle == MAILBOX_MSG_NULL_HANDLE) || (!reply)) {
return MAILBOX_INVAL_PARAMS;
}
@@ -269,7 +269,6 @@ int32_t tfm_ns_mailbox_rx_client_reply(mailbox_msg_handle_t handle,
set_msg_owner(idx, NULL);
tfm_ns_mailbox_hal_enter_critical();
- clear_queue_slot_replied(idx);
clear_queue_slot_woken(idx);
/*
* Make sure that the empty flag is set after all the other status flags are
@@ -281,44 +280,59 @@ int32_t tfm_ns_mailbox_rx_client_reply(mailbox_msg_handle_t handle,
return MAILBOX_SUCCESS;
}
-bool tfm_ns_mailbox_is_msg_replied(mailbox_msg_handle_t handle)
+int32_t tfm_ns_mailbox_client_call(uint32_t call_type,
+ const struct psa_client_params_t *params,
+ int32_t client_id,
+ int32_t *reply)
{
- uint8_t idx;
+ mailbox_msg_handle_t handle = MAILBOX_MSG_NULL_HANDLE;
+ int32_t reply_buf = 0x0;
int32_t ret;
- mailbox_queue_status_t status;
if (!mailbox_queue_ptr) {
- return false;
+ return MAILBOX_INIT_ERROR;
}
- if (handle == MAILBOX_MSG_NULL_HANDLE) {
- return false;
+ if (!params || !reply) {
+ return MAILBOX_INVAL_PARAMS;
}
- ret = get_mailbox_msg_idx(handle, &idx);
+ if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
+ return MAILBOX_QUEUE_FULL;
+ }
+
+ /* It requires SVCall if NS mailbox is put in privileged mode. */
+ ret = mailbox_tx_client_req(call_type, params, client_id, &handle);
if (ret != MAILBOX_SUCCESS) {
- return false;
+ goto exit;
}
- tfm_ns_mailbox_hal_enter_critical();
- status = mailbox_queue_ptr->replied_slots;
- tfm_ns_mailbox_hal_exit_critical();
+ mailbox_wait_reply(handle);
- if (status & (1 << idx)) {
- return true;
+ /* It requires SVCall if NS mailbox is put in privileged mode. */
+ ret = mailbox_rx_client_reply(handle, &reply_buf);
+ if (ret == MAILBOX_SUCCESS) {
+ *reply = reply_buf;
}
- return false;
+exit:
+ if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
+ return MAILBOX_GENERIC_ERROR;
+ }
+
+ return ret;
}
-mailbox_msg_handle_t tfm_ns_mailbox_fetch_reply_msg_isr(void)
+#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
+int32_t tfm_ns_mailbox_wake_reply_owner_isr(void)
{
uint8_t idx;
+ int32_t ret;
mailbox_msg_handle_t handle;
mailbox_queue_status_t replied_status;
if (!mailbox_queue_ptr) {
- return MAILBOX_MSG_NULL_HANDLE;
+ return MAILBOX_INIT_ERROR;
}
tfm_ns_mailbox_hal_enter_critical_isr();
@@ -326,7 +340,7 @@ mailbox_msg_handle_t tfm_ns_mailbox_fetch_reply_msg_isr(void)
tfm_ns_mailbox_hal_exit_critical_isr();
if (!replied_status) {
- return MAILBOX_MSG_NULL_HANDLE;
+ return MAILBOX_NO_PEND_EVENT;
}
for (idx = 0; idx < NUM_MAILBOX_QUEUE_SLOT; idx++) {
@@ -337,29 +351,26 @@ mailbox_msg_handle_t tfm_ns_mailbox_fetch_reply_msg_isr(void)
set_queue_slot_woken(idx);
tfm_ns_mailbox_hal_exit_critical_isr();
- if (get_mailbox_msg_handle(idx, &handle) == MAILBOX_SUCCESS) {
- return handle;
- }
+ break;
}
}
- return MAILBOX_MSG_NULL_HANDLE;
-}
-
-const void *tfm_ns_mailbox_get_msg_owner(mailbox_msg_handle_t handle)
-{
- uint8_t idx;
-
- if (get_mailbox_msg_idx(handle, &idx) != MAILBOX_SUCCESS) {
- return NULL;
+ /* In theory, it won't occur. Just in case */
+ if (idx == NUM_MAILBOX_QUEUE_SLOT) {
+ return MAILBOX_NO_PEND_EVENT;
}
- if (idx < NUM_MAILBOX_QUEUE_SLOT) {
- return mailbox_queue_ptr->queue[idx].owner;
+ ret = get_mailbox_msg_handle(idx, &handle);
+ if (ret != MAILBOX_SUCCESS) {
+ return ret;
}
- return NULL;
+ tfm_ns_mailbox_hal_wake_task_isr(mailbox_queue_ptr->queue[idx].owner,
+ handle);
+
+ return MAILBOX_SUCCESS;
}
+#endif
int32_t tfm_ns_mailbox_init(struct ns_mailbox_queue_t *queue)
{
@@ -394,16 +405,11 @@ int32_t tfm_ns_mailbox_init(struct ns_mailbox_queue_t *queue)
return ret;
}
-#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
-int32_t tfm_ns_mailbox_wait_reply(mailbox_msg_handle_t handle)
+static int32_t mailbox_wait_reply(mailbox_msg_handle_t handle)
{
uint8_t idx;
int32_t ret;
- if (!mailbox_queue_ptr) {
- return MAILBOX_INVAL_PARAMS;
- }
-
if (handle == MAILBOX_MSG_NULL_HANDLE) {
return MAILBOX_INVAL_PARAMS;
}
@@ -422,13 +428,27 @@ int32_t tfm_ns_mailbox_wait_reply(mailbox_msg_handle_t handle)
* woken up by reply event, rather than other events.
*/
tfm_ns_mailbox_hal_enter_critical();
+ /*
+ * It requires SVCall to access NS mailbox flags if NS mailbox is put
+ * in privileged mode.
+ * An alternative is to let NS thread allocate its own is_woken flag.
+ * But a spinlock-like mechanism is still required.
+ */
+#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
if (is_queue_slot_woken(idx)) {
- tfm_ns_mailbox_hal_exit_critical();
+ clear_queue_slot_woken(idx);
break;
}
+#else
+ if (is_queue_slot_replied(idx)) {
+ clear_queue_slot_replied(idx);
+ break;
+ }
+#endif
tfm_ns_mailbox_hal_exit_critical();
}
+ tfm_ns_mailbox_hal_exit_critical();
+
return MAILBOX_SUCCESS;
}
-#endif