diff options
-rw-r--r-- | interface/include/tfm_mailbox.h | 5 | ||||
-rw-r--r-- | interface/include/tfm_ns_mailbox.h | 15 | ||||
-rw-r--r-- | interface/src/tfm_ns_mailbox.c | 83 | ||||
-rw-r--r-- | interface/src/tfm_ns_mailbox_rtos_api.c | 17 | ||||
-rw-r--r-- | secure_fw/spm/cmsis_psa/tfm_spe_mailbox.h | 7 |
5 files changed, 36 insertions, 91 deletions
diff --git a/interface/include/tfm_mailbox.h b/interface/include/tfm_mailbox.h index 71f8ae77a9..45eb97ef21 100644 --- a/interface/include/tfm_mailbox.h +++ b/interface/include/tfm_mailbox.h @@ -119,11 +119,6 @@ struct mailbox_msg_t { */ }; -/* A handle to a mailbox message in use */ -typedef int32_t mailbox_msg_handle_t; - -#define MAILBOX_MSG_NULL_HANDLE ((mailbox_msg_handle_t)0) - /* * Mailbox reply structure in non-secure memory * to hold the PSA client call return result from SPE diff --git a/interface/include/tfm_ns_mailbox.h b/interface/include/tfm_ns_mailbox.h index a2902d6ab5..114000f8a5 100644 --- a/interface/include/tfm_ns_mailbox.h +++ b/interface/include/tfm_ns_mailbox.h @@ -192,14 +192,12 @@ const void *tfm_ns_mailbox_os_get_task_handle(void); /** * \brief Performs use scenario and NS OS specific waiting mechanism to wait for - * the reply of the specified mailbox message to be returned from SPE. + * the reply to be returned from SPE. * * \note This function is implemented by NS OS specific waiting mechanism * according to use scenario. - * - * \param[in] handle The handle of mailbox message. */ -void tfm_ns_mailbox_os_wait_reply(mailbox_msg_handle_t handle); +void tfm_ns_mailbox_os_wait_reply(void); /* * \brief Performs use scenario and NS OS specific mechanism in a mailbox IRQ @@ -213,20 +211,17 @@ void tfm_ns_mailbox_os_wait_reply(mailbox_msg_handle_t handle); * 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_os_wake_task_isr(const void *task_handle, - mailbox_msg_handle_t handle); +void tfm_ns_mailbox_os_wake_task_isr(const void *task_handle); #else /* TFM_MULTI_CORE_MULTI_CLIENT_CALL */ -#define tfm_ns_mailbox_os_wait_reply(handle) do {} while (0) +#define tfm_ns_mailbox_os_wait_reply() do {} while (0) static inline const void *tfm_ns_mailbox_os_get_task_handle(void) { return NULL; } -#define tfm_ns_mailbox_os_wake_task_isr(task, handle) do {} while (0) +#define tfm_ns_mailbox_os_wake_task_isr(task) do {} while (0) #endif /* TFM_MULTI_CORE_MULTI_CLIENT_CALL */ #ifdef TFM_MULTI_CORE_TEST diff --git a/interface/src/tfm_ns_mailbox.c b/interface/src/tfm_ns_mailbox.c index b256fa2027..f8f4298b9c 100644 --- a/interface/src/tfm_ns_mailbox.c +++ b/interface/src/tfm_ns_mailbox.c @@ -13,7 +13,7 @@ /* 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 int32_t mailbox_wait_reply(uint8_t idx); static inline void clear_queue_slot_empty(uint8_t idx) { @@ -36,30 +36,6 @@ static inline void set_queue_slot_pend(uint8_t idx) } } -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; - } - - *handle = (mailbox_msg_handle_t)(idx + 1); - - return MAILBOX_SUCCESS; -} - -static inline int32_t get_mailbox_msg_idx(mailbox_msg_handle_t handle, - uint8_t *idx) -{ - if ((handle == MAILBOX_MSG_NULL_HANDLE) || !idx) { - return MAILBOX_INVAL_PARAMS; - } - - *idx = (uint8_t)(handle - 1); - - return MAILBOX_SUCCESS; -} - static inline void clear_queue_slot_replied(uint8_t idx) { if (idx < NUM_MAILBOX_QUEUE_SLOT) { @@ -206,7 +182,7 @@ void tfm_ns_mailbox_stats_avg_slot(struct ns_mailbox_stats_res_t *stats_res) 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 *slot_idx) { uint8_t idx; struct mailbox_msg_t *msg_ptr; @@ -235,32 +211,19 @@ static int32_t mailbox_tx_client_req(uint32_t call_type, task_handle = tfm_ns_mailbox_os_get_task_handle(); set_msg_owner(idx, task_handle); - get_mailbox_msg_handle(idx, handle); - tfm_ns_mailbox_hal_enter_critical(); set_queue_slot_pend(idx); tfm_ns_mailbox_hal_exit_critical(); tfm_ns_mailbox_hal_notify_peer(); + *slot_idx = idx; + return MAILBOX_SUCCESS; } -static int32_t mailbox_rx_client_reply(mailbox_msg_handle_t handle, - int32_t *reply) +static int32_t mailbox_rx_client_reply(uint8_t idx, int32_t *reply) { - uint8_t idx; - int32_t ret; - - if ((handle == MAILBOX_MSG_NULL_HANDLE) || (!reply)) { - return MAILBOX_INVAL_PARAMS; - } - - ret = get_mailbox_msg_idx(handle, &idx); - if (ret != MAILBOX_SUCCESS) { - return ret; - } - *reply = mailbox_queue_ptr->queue[idx].reply.return_val; /* Clear up the owner field */ @@ -283,7 +246,7 @@ int32_t tfm_ns_mailbox_client_call(uint32_t call_type, int32_t client_id, int32_t *reply) { - mailbox_msg_handle_t handle = MAILBOX_MSG_NULL_HANDLE; + uint8_t slot_idx = NUM_MAILBOX_QUEUE_SLOT; int32_t reply_buf = 0x0; int32_t ret; @@ -300,15 +263,15 @@ int32_t tfm_ns_mailbox_client_call(uint32_t call_type, } /* It requires SVCall if NS mailbox is put in privileged mode. */ - ret = mailbox_tx_client_req(call_type, params, client_id, &handle); + ret = mailbox_tx_client_req(call_type, params, client_id, &slot_idx); if (ret != MAILBOX_SUCCESS) { goto exit; } - mailbox_wait_reply(handle); + mailbox_wait_reply(slot_idx); /* It requires SVCall if NS mailbox is put in privileged mode. */ - ret = mailbox_rx_client_reply(handle, &reply_buf); + ret = mailbox_rx_client_reply(slot_idx, &reply_buf); if (ret == MAILBOX_SUCCESS) { *reply = reply_buf; } @@ -325,8 +288,6 @@ exit: 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) { @@ -354,17 +315,11 @@ int32_t tfm_ns_mailbox_wake_reply_owner_isr(void) } /* In theory, it won't occur. Just in case */ - if (idx == NUM_MAILBOX_QUEUE_SLOT) { + if (idx >= NUM_MAILBOX_QUEUE_SLOT) { return MAILBOX_NO_PEND_EVENT; } - ret = get_mailbox_msg_handle(idx, &handle); - if (ret != MAILBOX_SUCCESS) { - return ret; - } - - tfm_ns_mailbox_os_wake_task_isr(mailbox_queue_ptr->queue[idx].owner, - handle); + tfm_ns_mailbox_os_wake_task_isr(mailbox_queue_ptr->queue[idx].owner); return MAILBOX_SUCCESS; } @@ -408,22 +363,10 @@ int32_t tfm_ns_mailbox_init(struct ns_mailbox_queue_t *queue) return ret; } -static int32_t mailbox_wait_reply(mailbox_msg_handle_t handle) +static int32_t mailbox_wait_reply(uint8_t idx) { - uint8_t idx; - int32_t ret; - - if (handle == MAILBOX_MSG_NULL_HANDLE) { - return MAILBOX_INVAL_PARAMS; - } - - ret = get_mailbox_msg_idx(handle, &idx); - if (ret != MAILBOX_SUCCESS) { - return ret; - } - while (1) { - tfm_ns_mailbox_os_wait_reply(handle); + tfm_ns_mailbox_os_wait_reply(); /* * Woken up from sleep diff --git a/interface/src/tfm_ns_mailbox_rtos_api.c b/interface/src/tfm_ns_mailbox_rtos_api.c index 1e9e8d2dda..f7d23d2bc4 100644 --- a/interface/src/tfm_ns_mailbox_rtos_api.c +++ b/interface/src/tfm_ns_mailbox_rtos_api.c @@ -18,6 +18,14 @@ #define MAX_SEMAPHORE_COUNT NUM_MAILBOX_QUEUE_SLOT +/* + * Thread flag to manage wait/wake mechanism in mailbox.、 + * Thread flag can be RTOS specific. + * The following example definition also covers the rule of CMSIS-RTOS2, which + * requires the MSB of thread flags must be 0b0. + */ +#define MAILBOX_THREAD_FLAG 0x5FCA0000 + static void *ns_lock_handle = NULL; #ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL @@ -26,15 +34,14 @@ const void *tfm_ns_mailbox_os_get_task_handle(void) return os_wrapper_thread_get_handle(); } -void tfm_ns_mailbox_os_wait_reply(mailbox_msg_handle_t handle) +void tfm_ns_mailbox_os_wait_reply(void) { - os_wrapper_thread_wait_flag((uint32_t)handle, OS_WRAPPER_WAIT_FOREVER); + os_wrapper_thread_wait_flag(MAILBOX_THREAD_FLAG, OS_WRAPPER_WAIT_FOREVER); } -void tfm_ns_mailbox_os_wake_task_isr(const void *task_handle, - mailbox_msg_handle_t handle) +void tfm_ns_mailbox_os_wake_task_isr(const void *task_handle) { - os_wrapper_thread_set_flag_isr((void *)task_handle, (uint32_t)handle); + os_wrapper_thread_set_flag_isr((void *)task_handle, MAILBOX_THREAD_FLAG); } #endif /* TFM_MULTI_CORE_MULTI_CLIENT_CALL */ diff --git a/secure_fw/spm/cmsis_psa/tfm_spe_mailbox.h b/secure_fw/spm/cmsis_psa/tfm_spe_mailbox.h index fd07907117..f3e47eb9c0 100644 --- a/secure_fw/spm/cmsis_psa/tfm_spe_mailbox.h +++ b/secure_fw/spm/cmsis_psa/tfm_spe_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 * @@ -10,6 +10,11 @@ #include "tfm_mailbox.h" +/* A handle to a mailbox message in use */ +typedef int32_t mailbox_msg_handle_t; + +#define MAILBOX_MSG_NULL_HANDLE ((mailbox_msg_handle_t)0) + /* A single slot structure in SPE mailbox queue */ struct secure_mailbox_slot_t { struct mailbox_msg_t msg; |