David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 1 | /* |
David Hu | 1bd1c7b | 2020-05-09 14:13:20 +0800 | [diff] [blame^] | 2 | * Copyright (c) 2019-2021, Arm Limited. All rights reserved. |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
David Hu | 65cbfb8 | 2019-11-15 17:18:12 +0800 | [diff] [blame] | 8 | /* Data types and API definitions in NSPE mailbox library */ |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 9 | |
| 10 | #ifndef __TFM_NS_MAILBOX_H__ |
| 11 | #define __TFM_NS_MAILBOX_H__ |
| 12 | |
| 13 | #include <stdbool.h> |
David Hu | 65cbfb8 | 2019-11-15 17:18:12 +0800 | [diff] [blame] | 14 | #include <stdint.h> |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 15 | #include "tfm_mailbox.h" |
| 16 | |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame] | 17 | #ifdef __cplusplus |
| 18 | extern "C" { |
| 19 | #endif |
| 20 | |
David Hu | 65cbfb8 | 2019-11-15 17:18:12 +0800 | [diff] [blame] | 21 | #ifdef TFM_MULTI_CORE_TEST |
| 22 | /** |
| 23 | * \brief The structure to hold the statistics result of NSPE mailbox |
| 24 | */ |
| 25 | struct ns_mailbox_stats_res_t { |
| 26 | uint8_t avg_nr_slots; /* The value before the decimal point |
| 27 | * in the average number of NSPE |
| 28 | * mailbox slots in use. |
| 29 | */ |
| 30 | uint8_t avg_nr_slots_tenths; /* The first digit value after the |
| 31 | * decimal point in the average |
| 32 | * number of NSPE mailbox slots in use. |
| 33 | */ |
| 34 | }; |
| 35 | #endif |
| 36 | |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 37 | /** |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 38 | * \brief NSPE mailbox initialization |
| 39 | * |
| 40 | * \param[in] queue The base address of NSPE mailbox queue to be |
| 41 | * initialized. |
| 42 | * |
| 43 | * \retval MAILBOX_SUCCESS Operation succeeded. |
| 44 | * \retval Other return code Operation failed with an error code. |
| 45 | */ |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame] | 46 | int32_t tfm_ns_mailbox_init(struct ns_mailbox_queue_t *queue); |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 47 | |
David Hu | 1bd1c7b | 2020-05-09 14:13:20 +0800 | [diff] [blame^] | 48 | /** |
| 49 | * \brief Send PSA client call to SPE via mailbox. Wait and fetch PSA client |
| 50 | * call result. |
| 51 | * |
| 52 | * \param[in] call_type PSA client call type |
| 53 | * \param[in] params Parameters used for PSA client call |
| 54 | * \param[in] client_id Optional client ID of non-secure caller. |
| 55 | * It is required to identify the non-secure caller |
| 56 | * when NSPE OS enforces non-secure task isolation. |
| 57 | * \param[out] reply The buffer written with PSA client call result. |
| 58 | * |
| 59 | * \retval MAILBOX_SUCCESS The PSA client call is completed successfully. |
| 60 | * \retval Other return code Operation failed with an error code. |
| 61 | */ |
| 62 | int32_t tfm_ns_mailbox_client_call(uint32_t call_type, |
| 63 | const struct psa_client_params_t *params, |
| 64 | int32_t client_id, |
| 65 | int32_t *reply); |
| 66 | |
David Hu | 06ebac7 | 2019-09-29 16:01:54 +0800 | [diff] [blame] | 67 | #ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL |
| 68 | /** |
| 69 | * \brief Get the handle of the current non-secure task executing mailbox |
| 70 | * functionalities |
| 71 | * |
| 72 | * \note This function should be implemented according to platform, NS OS |
| 73 | * and actual use scenario. |
| 74 | * This function can be ignored or return NULL if sleep/wake-up mechanism |
| 75 | * is not required in PSA Client API implementation. |
| 76 | * |
| 77 | * \return Return the handle of task. |
| 78 | */ |
| 79 | const void *tfm_ns_mailbox_get_task_handle(void); |
| 80 | #else |
| 81 | static inline const void *tfm_ns_mailbox_get_task_handle(void) |
| 82 | { |
| 83 | return NULL; |
| 84 | } |
| 85 | #endif |
| 86 | |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 87 | /** |
David Hu | 1bd1c7b | 2020-05-09 14:13:20 +0800 | [diff] [blame^] | 88 | * \brief Wake up the owner task of the first replied mailbox message in the |
| 89 | * NSPE mailbox queue. |
David Hu | 3684ee7 | 2019-11-12 18:43:34 +0800 | [diff] [blame] | 90 | * This function is intended to be called inside platform specific |
| 91 | * notification IRQ handler. |
| 92 | * |
| 93 | * \note The replied status of the fetched mailbox message will be cleaned after |
David Hu | 1bd1c7b | 2020-05-09 14:13:20 +0800 | [diff] [blame^] | 94 | * the message is fetched. When this function is called again, it wakes |
| 95 | * the owner task of next replied mailbox message from the NSPE mailbox |
| 96 | * queue. |
David Hu | 3684ee7 | 2019-11-12 18:43:34 +0800 | [diff] [blame] | 97 | * |
David Hu | 1bd1c7b | 2020-05-09 14:13:20 +0800 | [diff] [blame^] | 98 | * \return MAILBOX_SUCCESS The task of the first replied mailbox message |
| 99 | * is found and wake-up signal is sent. |
| 100 | * \return MAILBOX_NO_PEND_EVENT No replied mailbox message is found. |
| 101 | * \return Other return code Failed with an error code |
David Hu | 3684ee7 | 2019-11-12 18:43:34 +0800 | [diff] [blame] | 102 | */ |
David Hu | 1bd1c7b | 2020-05-09 14:13:20 +0800 | [diff] [blame^] | 103 | int32_t tfm_ns_mailbox_wake_reply_owner_isr(void); |
David Hu | f3e2047 | 2019-11-13 17:41:59 +0800 | [diff] [blame] | 104 | |
David Hu | 3684ee7 | 2019-11-12 18:43:34 +0800 | [diff] [blame] | 105 | /** |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 106 | * \brief Platform specific NSPE mailbox initialization. |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame] | 107 | * Invoked by \ref tfm_ns_mailbox_init(). |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 108 | * |
| 109 | * \param[in] queue The base address of NSPE mailbox queue to be |
| 110 | * initialized. |
| 111 | * |
| 112 | * \retval MAILBOX_SUCCESS Operation succeeded. |
| 113 | * \retval Other return code Operation failed with an error code. |
| 114 | */ |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame] | 115 | int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue); |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 116 | |
| 117 | /** |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame] | 118 | * \brief Notify SPE to deal with the PSA client call sent via mailbox |
| 119 | * |
| 120 | * \note The implementation depends on platform specific hardware and use case. |
| 121 | * |
| 122 | * \retval MAILBOX_SUCCESS Operation succeeded. |
| 123 | * \retval Other return code Operation failed with an error code. |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 124 | */ |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame] | 125 | int32_t tfm_ns_mailbox_hal_notify_peer(void); |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 126 | |
| 127 | /** |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame] | 128 | * \brief Enter critical section of NSPE mailbox. |
| 129 | * |
| 130 | * \note The implementation depends on platform specific hardware and use case. |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 131 | */ |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame] | 132 | void tfm_ns_mailbox_hal_enter_critical(void); |
| 133 | |
| 134 | /** |
| 135 | * \brief Exit critical section of NSPE mailbox. |
| 136 | * |
| 137 | * \note The implementation depends on platform specific hardware and use case. |
| 138 | */ |
| 139 | void tfm_ns_mailbox_hal_exit_critical(void); |
| 140 | |
David Hu | c617ba1 | 2019-11-14 17:06:11 +0800 | [diff] [blame] | 141 | /** |
| 142 | * \brief Enter critical section of NSPE mailbox in IRQ handler. |
| 143 | * |
| 144 | * \note The implementation depends on platform specific hardware and use case. |
| 145 | */ |
| 146 | void tfm_ns_mailbox_hal_enter_critical_isr(void); |
| 147 | |
| 148 | /** |
| 149 | * \brief Enter critical section of NSPE mailbox in IRQ handler |
| 150 | * |
| 151 | * \note The implementation depends on platform specific hardware and use case. |
| 152 | */ |
| 153 | void tfm_ns_mailbox_hal_exit_critical_isr(void); |
| 154 | |
David Hu | f3e2047 | 2019-11-13 17:41:59 +0800 | [diff] [blame] | 155 | #ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL |
| 156 | /** |
| 157 | * \brief Performs platform and NS OS specific waiting mechanism to wait for |
| 158 | * the reply of the specified mailbox message to be returned from SPE. |
| 159 | * |
| 160 | * \note This function is implemented by platform and NS OS specific waiting |
David Hu | 1bd1c7b | 2020-05-09 14:13:20 +0800 | [diff] [blame^] | 161 | * mechanism according to use scenario. |
David Hu | f3e2047 | 2019-11-13 17:41:59 +0800 | [diff] [blame] | 162 | * |
| 163 | * \param[in] handle The handle of mailbox message. |
| 164 | */ |
| 165 | void tfm_ns_mailbox_hal_wait_reply(mailbox_msg_handle_t handle); |
David Hu | 1bd1c7b | 2020-05-09 14:13:20 +0800 | [diff] [blame^] | 166 | |
| 167 | /* |
| 168 | * \brief Performs platform and NS OS specific mechanism in a mailbox IRQ |
| 169 | * handler, to wake up a sleeping task which is waiting for its mailbox |
| 170 | * message reply. |
| 171 | * |
| 172 | * \note The underlying platform and NS OS specific function called inside this |
| 173 | * function should be able to work in an IRQ handler. |
| 174 | * |
| 175 | * \note This function is implemented by platform and NS OS specific waiting |
| 176 | * mechanism according to use scenario. |
| 177 | * |
| 178 | * \param[in] task_handle The handle to the task to be woken up. |
| 179 | * \param[in] handle The mailbox handle which can be used as thread |
| 180 | * flag. |
| 181 | */ |
| 182 | void tfm_ns_mailbox_hal_wake_task_isr(const void *task_handle, |
| 183 | mailbox_msg_handle_t handle); |
| 184 | #else |
| 185 | #define tfm_ns_mailbox_hal_wait_reply(handle) do {} while (0) |
David Hu | f3e2047 | 2019-11-13 17:41:59 +0800 | [diff] [blame] | 186 | #endif |
| 187 | |
David Hu | 65cbfb8 | 2019-11-15 17:18:12 +0800 | [diff] [blame] | 188 | #ifdef TFM_MULTI_CORE_TEST |
| 189 | /** |
| 190 | * \brief Initialize the statistics module in TF-M NSPE mailbox. |
| 191 | * |
| 192 | * \note This function is only available when multi-core tests are enabled. |
| 193 | */ |
| 194 | void tfm_ns_mailbox_tx_stats_init(void); |
| 195 | |
| 196 | /** |
| 197 | * \brief Calculate the average number of used NS mailbox queue slots each time |
| 198 | * NS task requires a queue slot to submit mailbox message, which is |
| 199 | * recorded in NS mailbox statisitics module. |
| 200 | * |
| 201 | * \note This function is only available when multi-core tests are enabled. |
| 202 | * |
| 203 | * \param[in] stats_res The buffer to be written with |
| 204 | * \ref ns_mailbox_stats_res_t. |
| 205 | * |
| 206 | * \return Return the calculation result. |
| 207 | */ |
| 208 | void tfm_ns_mailbox_stats_avg_slot(struct ns_mailbox_stats_res_t *stats_res); |
| 209 | #endif |
| 210 | |
David Hu | dbafa3e | 2019-10-22 11:26:37 +0800 | [diff] [blame] | 211 | #ifdef __cplusplus |
| 212 | } |
| 213 | #endif |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 214 | |
| 215 | #endif /* __TFM_NS_MAILBOX_H__ */ |