blob: ba902aa97740ef5e18c65329fc42f949726c1b50 [file] [log] [blame]
David Hu49ec08a2019-09-23 16:13:41 +08001/*
David Hu06ebac72019-09-29 16:01:54 +08002 * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
David Hu49ec08a2019-09-23 16:13:41 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
David Hu65cbfb82019-11-15 17:18:12 +08008/* Data types and API definitions in NSPE mailbox library */
David Hu49ec08a2019-09-23 16:13:41 +08009
10#ifndef __TFM_NS_MAILBOX_H__
11#define __TFM_NS_MAILBOX_H__
12
13#include <stdbool.h>
David Hu65cbfb82019-11-15 17:18:12 +080014#include <stdint.h>
David Hu49ec08a2019-09-23 16:13:41 +080015#include "tfm_mailbox.h"
16
David Hudbafa3e2019-10-22 11:26:37 +080017#ifdef __cplusplus
18extern "C" {
19#endif
20
David Hu65cbfb82019-11-15 17:18:12 +080021#ifdef TFM_MULTI_CORE_TEST
22/**
23 * \brief The structure to hold the statistics result of NSPE mailbox
24 */
25struct 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 Hu49ec08a2019-09-23 16:13:41 +080037/**
David Hudbafa3e2019-10-22 11:26:37 +080038 * \brief Prepare and send PSA client request to SPE via mailbox.
David Hu49ec08a2019-09-23 16:13:41 +080039 *
40 * \param[in] call_type PSA client call type
41 * \param[in] params Parmaters used for PSA client call
42 * \param[in] client_id Optional client ID of non-secure caller.
43 * It is required to identify the non-secure caller
44 * when NSPE OS enforces non-secure task isolation.
45 *
46 * \retval >= 0 The handle to the mailbox message assigned.
47 * \retval < 0 Operation failed with an error code.
48 */
David Hudbafa3e2019-10-22 11:26:37 +080049mailbox_msg_handle_t tfm_ns_mailbox_tx_client_req(uint32_t call_type,
50 const struct psa_client_params_t *params,
51 int32_t client_id);
David Hu49ec08a2019-09-23 16:13:41 +080052
53/**
David Hudbafa3e2019-10-22 11:26:37 +080054 * \brief Fetch PSA client return result.
David Hu49ec08a2019-09-23 16:13:41 +080055 *
56 * \param[in] handle The handle to the mailbox message
57 * \param[out] reply The address to be written with return result.
58 *
59 * \retval MAILBOX_SUCCESS Successfully get PSA client call return result.
60 * \retval Other return code Operation failed with an error code.
61 */
David Hudbafa3e2019-10-22 11:26:37 +080062int32_t tfm_ns_mailbox_rx_client_reply(mailbox_msg_handle_t handle,
63 int32_t *reply);
David Hu49ec08a2019-09-23 16:13:41 +080064
65/**
66 * \brief Check whether a specific mailbox message has been replied.
67 *
68 * \param[in] handle The handle to the mailbox message
69 *
70 * \retval true The PSA client call return value is replied.
71 * \retval false The PSA client call return value is not
72 * replied yet.
73 */
David Hudbafa3e2019-10-22 11:26:37 +080074bool tfm_ns_mailbox_is_msg_replied(mailbox_msg_handle_t handle);
David Hu49ec08a2019-09-23 16:13:41 +080075
76/**
77 * \brief NSPE mailbox initialization
78 *
79 * \param[in] queue The base address of NSPE mailbox queue to be
80 * initialized.
81 *
82 * \retval MAILBOX_SUCCESS Operation succeeded.
83 * \retval Other return code Operation failed with an error code.
84 */
David Hudbafa3e2019-10-22 11:26:37 +080085int32_t tfm_ns_mailbox_init(struct ns_mailbox_queue_t *queue);
David Hu49ec08a2019-09-23 16:13:41 +080086
David Hu06ebac72019-09-29 16:01:54 +080087#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
88/**
89 * \brief Get the handle of the current non-secure task executing mailbox
90 * functionalities
91 *
92 * \note This function should be implemented according to platform, NS OS
93 * and actual use scenario.
94 * This function can be ignored or return NULL if sleep/wake-up mechanism
95 * is not required in PSA Client API implementation.
96 *
97 * \return Return the handle of task.
98 */
99const void *tfm_ns_mailbox_get_task_handle(void);
100#else
101static inline const void *tfm_ns_mailbox_get_task_handle(void)
102{
103 return NULL;
104}
105#endif
106
David Hu49ec08a2019-09-23 16:13:41 +0800107/**
David Hu3684ee72019-11-12 18:43:34 +0800108 * \brief Fetch the handle to the first replied mailbox message in the NSPE
109 * mailbox queue.
110 * This function is intended to be called inside platform specific
111 * notification IRQ handler.
112 *
113 * \note The replied status of the fetched mailbox message will be cleaned after
114 * the message is fetched. When this function is called again, it fetches
115 * the next replied mailbox message from the NSPE mailbox queue.
116 *
117 * \return Return the handle to the first replied mailbox message in the
118 * queue.
119 * Return \ref MAILBOX_MSG_NULL_HANDLE if no mailbox message is replied.
120 */
121mailbox_msg_handle_t tfm_ns_mailbox_fetch_reply_msg_isr(void);
122
123/**
124 * \brief Return the handle of owner task of a mailbox message according to the
125 * \ref mailbox_msg_handle_t
126 *
127 * \param[in] handle The handle of mailbox message.
128 *
129 * \return Return the handle value of the owner task.
130 */
131const void *tfm_ns_mailbox_get_msg_owner(mailbox_msg_handle_t handle);
132
David Huf3e20472019-11-13 17:41:59 +0800133#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
134/**
135 * \brief Wait for the reply returned from SPE to the mailbox message specified
136 * by handle
137 *
138 * \param[in] handle The handle of mailbox message.
139 *
140 * \retval MAILBOX_SUCCESS Return from waiting successfully.
141 * \retval Other return code Failed to wait with an error code.
142 */
143int32_t tfm_ns_mailbox_wait_reply(mailbox_msg_handle_t handle);
144#endif
145
David Hu3684ee72019-11-12 18:43:34 +0800146/**
David Hu49ec08a2019-09-23 16:13:41 +0800147 * \brief Platform specific NSPE mailbox initialization.
David Hudbafa3e2019-10-22 11:26:37 +0800148 * Invoked by \ref tfm_ns_mailbox_init().
David Hu49ec08a2019-09-23 16:13:41 +0800149 *
150 * \param[in] queue The base address of NSPE mailbox queue to be
151 * initialized.
152 *
153 * \retval MAILBOX_SUCCESS Operation succeeded.
154 * \retval Other return code Operation failed with an error code.
155 */
David Hudbafa3e2019-10-22 11:26:37 +0800156int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue);
David Hu49ec08a2019-09-23 16:13:41 +0800157
158/**
David Hudbafa3e2019-10-22 11:26:37 +0800159 * \brief Notify SPE to deal with the PSA client call sent via mailbox
160 *
161 * \note The implementation depends on platform specific hardware and use case.
162 *
163 * \retval MAILBOX_SUCCESS Operation succeeded.
164 * \retval Other return code Operation failed with an error code.
David Hu49ec08a2019-09-23 16:13:41 +0800165 */
David Hudbafa3e2019-10-22 11:26:37 +0800166int32_t tfm_ns_mailbox_hal_notify_peer(void);
David Hu49ec08a2019-09-23 16:13:41 +0800167
168/**
David Hudbafa3e2019-10-22 11:26:37 +0800169 * \brief Enter critical section of NSPE mailbox.
170 *
171 * \note The implementation depends on platform specific hardware and use case.
David Hu49ec08a2019-09-23 16:13:41 +0800172 */
David Hudbafa3e2019-10-22 11:26:37 +0800173void tfm_ns_mailbox_hal_enter_critical(void);
174
175/**
176 * \brief Exit critical section of NSPE mailbox.
177 *
178 * \note The implementation depends on platform specific hardware and use case.
179 */
180void tfm_ns_mailbox_hal_exit_critical(void);
181
David Huc617ba12019-11-14 17:06:11 +0800182/**
183 * \brief Enter critical section of NSPE mailbox in IRQ handler.
184 *
185 * \note The implementation depends on platform specific hardware and use case.
186 */
187void tfm_ns_mailbox_hal_enter_critical_isr(void);
188
189/**
190 * \brief Enter critical section of NSPE mailbox in IRQ handler
191 *
192 * \note The implementation depends on platform specific hardware and use case.
193 */
194void tfm_ns_mailbox_hal_exit_critical_isr(void);
195
David Huf3e20472019-11-13 17:41:59 +0800196#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
197/**
198 * \brief Performs platform and NS OS specific waiting mechanism to wait for
199 * the reply of the specified mailbox message to be returned from SPE.
200 *
201 * \note This function is implemented by platform and NS OS specific waiting
202 * mechanism accroding to use scenario.
203 *
204 * \param[in] handle The handle of mailbox message.
205 */
206void tfm_ns_mailbox_hal_wait_reply(mailbox_msg_handle_t handle);
207#endif
208
David Hu65cbfb82019-11-15 17:18:12 +0800209#ifdef TFM_MULTI_CORE_TEST
210/**
211 * \brief Initialize the statistics module in TF-M NSPE mailbox.
212 *
213 * \note This function is only available when multi-core tests are enabled.
214 */
215void tfm_ns_mailbox_tx_stats_init(void);
216
217/**
218 * \brief Calculate the average number of used NS mailbox queue slots each time
219 * NS task requires a queue slot to submit mailbox message, which is
220 * recorded in NS mailbox statisitics module.
221 *
222 * \note This function is only available when multi-core tests are enabled.
223 *
224 * \param[in] stats_res The buffer to be written with
225 * \ref ns_mailbox_stats_res_t.
226 *
227 * \return Return the calculation result.
228 */
229void tfm_ns_mailbox_stats_avg_slot(struct ns_mailbox_stats_res_t *stats_res);
230#endif
231
David Hudbafa3e2019-10-22 11:26:37 +0800232#ifdef __cplusplus
233}
234#endif
David Hu49ec08a2019-09-23 16:13:41 +0800235
236#endif /* __TFM_NS_MAILBOX_H__ */