10 #include "cmsis_compiler.h"
12 #include "tfm_plat_ns.h"
17 static inline void clear_queue_slot_empty(uint8_t idx)
24 static inline void set_queue_slot_empty(uint8_t idx)
31 static inline void set_queue_slot_pend(uint8_t idx)
38 static inline int32_t get_mailbox_msg_handle(uint8_t idx,
57 *idx = (uint8_t)(handle - 1);
62 static inline void clear_queue_slot_replied(uint8_t idx)
69 static inline void set_queue_slot_woken(uint8_t idx)
76 static inline bool is_queue_slot_woken(uint8_t idx)
85 static inline void clear_queue_slot_woken(uint8_t idx)
107 if (status & (1 << idx)) {
112 clear_queue_slot_empty(idx);
119 static void set_msg_owner(uint8_t idx,
const void *owner)
121 if (idx < NUM_MAILBOX_QUEUE_SLOT) {
126 #ifdef TFM_MULTI_CORE_TEST
131 static inline void ns_mailbox_spin_lock(
void)
136 static inline void ns_mailbox_spin_unlock(
void)
141 void tfm_ns_mailbox_tx_stats_init(
void)
143 if (!mailbox_queue_ptr) {
147 mailbox_queue_ptr->nr_tx = 0;
148 mailbox_queue_ptr->nr_used_slots = 0;
154 uint8_t idx, nr_empty = 0;
167 if (empty_status & (0x1UL << idx)) {
173 ns_mailbox_spin_lock();
174 ns_queue->nr_used_slots += (NUM_MAILBOX_QUEUE_SLOT - nr_empty);
176 ns_mailbox_spin_unlock();
179 void tfm_ns_mailbox_stats_avg_slot(
struct ns_mailbox_stats_res_t *stats_res)
181 uint32_t nr_used_slots, nr_tx;
183 if (!mailbox_queue_ptr || !stats_res) {
187 nr_used_slots = mailbox_queue_ptr->nr_used_slots;
188 nr_tx = mailbox_queue_ptr->nr_tx;
190 stats_res->avg_nr_slots = nr_used_slots / nr_tx;
191 nr_used_slots %= nr_tx;
192 stats_res->avg_nr_slots_tenths = nr_used_slots * 10 / nr_tx;
203 const void *task_handle;
205 if (!mailbox_queue_ptr) {
213 idx = acquire_empty_slot(mailbox_queue_ptr);
214 if (idx >= NUM_MAILBOX_QUEUE_SLOT) {
218 #ifdef TFM_MULTI_CORE_TEST
219 mailbox_tx_stats_update(mailbox_queue_ptr);
223 msg_ptr = &mailbox_queue_ptr->
queue[idx].
msg;
233 task_handle = tfm_ns_mailbox_get_task_handle();
234 set_msg_owner(idx, task_handle);
236 get_mailbox_msg_handle(idx, &handle);
239 set_queue_slot_pend(idx);
253 if (!mailbox_queue_ptr) {
261 ret = get_mailbox_msg_idx(handle, &idx);
269 set_msg_owner(idx, NULL);
272 clear_queue_slot_replied(idx);
273 clear_queue_slot_woken(idx);
278 set_queue_slot_empty(idx);
290 if (!mailbox_queue_ptr) {
298 ret = get_mailbox_msg_idx(handle, &idx);
307 if (status & (1 << idx)) {
320 if (!mailbox_queue_ptr) {
328 if (!replied_status) {
334 if (replied_status & (0x1UL << idx)) {
336 clear_queue_slot_replied(idx);
337 set_queue_slot_woken(idx);
357 if (idx < NUM_MAILBOX_QUEUE_SLOT) {
377 memset(queue, 0,
sizeof(*queue));
385 mailbox_queue_ptr = queue;
390 #ifdef TFM_MULTI_CORE_TEST
391 tfm_ns_mailbox_tx_stats_init();
397 #ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
403 if (!mailbox_queue_ptr) {
411 ret = get_mailbox_msg_idx(handle, &idx);
417 tfm_ns_mailbox_hal_wait_reply(handle);
425 if (is_queue_slot_woken(idx)) {
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)
Prepare and send PSA client request to SPE via mailbox.
struct mailbox_reply_t reply
mailbox_queue_status_t replied_slots
#define MAILBOX_INVAL_PARAMS
struct psa_client_params_t params
mailbox_queue_status_t empty_slots
int32_t tfm_ns_mailbox_hal_notify_peer(void)
Notify SPE to deal with the PSA client call sent via mailbox.
mailbox_queue_status_t pend_slots
mailbox_msg_handle_t tfm_ns_mailbox_fetch_reply_msg_isr(void)
Fetch the handle to the first replied mailbox message in the NSPE mailbox queue. This function is int...
int32_t tfm_ns_mailbox_init(struct ns_mailbox_queue_t *queue)
NSPE mailbox initialization.
struct ns_mailbox_slot_t queue[(1)]
#define NUM_MAILBOX_QUEUE_SLOT
void tfm_ns_mailbox_hal_enter_critical(void)
Enter critical section of NSPE mailbox.
uint32_t mailbox_queue_status_t
#define MAILBOX_QUEUE_FULL
int32_t mailbox_msg_handle_t
void tfm_ns_mailbox_hal_exit_critical_isr(void)
Enter critical section of NSPE mailbox in IRQ handler.
int32_t tfm_ns_mailbox_rx_client_reply(mailbox_msg_handle_t handle, int32_t *reply)
Fetch PSA client return result.
bool tfm_ns_mailbox_is_msg_replied(mailbox_msg_handle_t handle)
Check whether a specific mailbox message has been replied.
void tfm_ns_mailbox_hal_enter_critical_isr(void)
Enter critical section of NSPE mailbox in IRQ handler.
void * memcpy(void *dest, const void *src, size_t n)
int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue)
Platform specific NSPE mailbox initialization. Invoked by tfm_ns_mailbox_init().
#define MAILBOX_MSG_NULL_HANDLE
const void * tfm_ns_mailbox_get_msg_owner(mailbox_msg_handle_t handle)
Return the handle of owner task of a mailbox message according to the mailbox_msg_handle_t.
void tfm_ns_mailbox_hal_exit_critical(void)
Exit critical section of NSPE mailbox.
void * memset(void *s, int c, size_t n)