blob: 6b64443fa0aec47cd20e4a17793f62a563d5fb08 [file] [log] [blame]
David Hu49ec08a2019-09-23 16:13:41 +08001/*
David Hu1bd1c7b2020-05-09 14:13:20 +08002 * Copyright (c) 2019-2021, 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 Hu49ec08a2019-09-23 16:13:41 +080038 * \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 Hudbafa3e2019-10-22 11:26:37 +080046int32_t tfm_ns_mailbox_init(struct ns_mailbox_queue_t *queue);
David Hu49ec08a2019-09-23 16:13:41 +080047
David Hu1bd1c7b2020-05-09 14:13:20 +080048/**
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 */
62int32_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 Hu49ec08a2019-09-23 16:13:41 +080067/**
David Hu94830372020-05-13 16:37:34 +080068 * \brief Go through mailbox messages already replied by SPE mailbox and
69 * wake up the owner tasks of replied mailbox messages.
David Hu3684ee72019-11-12 18:43:34 +080070 * This function is intended to be called inside platform specific
71 * notification IRQ handler.
72 *
David Hu94830372020-05-13 16:37:34 +080073 * \return MAILBOX_SUCCESS The tasks of replied mailbox messages
74 * were found and wake-up signals were sent.
David Hu1bd1c7b2020-05-09 14:13:20 +080075 * \return MAILBOX_NO_PEND_EVENT No replied mailbox message is found.
76 * \return Other return code Failed with an error code
David Hu3684ee72019-11-12 18:43:34 +080077 */
David Hu1bd1c7b2020-05-09 14:13:20 +080078int32_t tfm_ns_mailbox_wake_reply_owner_isr(void);
David Huf3e20472019-11-13 17:41:59 +080079
David Hu3684ee72019-11-12 18:43:34 +080080/**
David Hu49ec08a2019-09-23 16:13:41 +080081 * \brief Platform specific NSPE mailbox initialization.
David Hudbafa3e2019-10-22 11:26:37 +080082 * Invoked by \ref tfm_ns_mailbox_init().
David Hu49ec08a2019-09-23 16:13:41 +080083 *
84 * \param[in] queue The base address of NSPE mailbox queue to be
85 * initialized.
86 *
87 * \retval MAILBOX_SUCCESS Operation succeeded.
88 * \retval Other return code Operation failed with an error code.
89 */
David Hudbafa3e2019-10-22 11:26:37 +080090int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue);
David Hu49ec08a2019-09-23 16:13:41 +080091
92/**
David Hudbafa3e2019-10-22 11:26:37 +080093 * \brief Notify SPE to deal with the PSA client call sent via mailbox
94 *
95 * \note The implementation depends on platform specific hardware and use case.
96 *
97 * \retval MAILBOX_SUCCESS Operation succeeded.
98 * \retval Other return code Operation failed with an error code.
David Hu49ec08a2019-09-23 16:13:41 +080099 */
David Hudbafa3e2019-10-22 11:26:37 +0800100int32_t tfm_ns_mailbox_hal_notify_peer(void);
David Hu49ec08a2019-09-23 16:13:41 +0800101
102/**
David Hudbafa3e2019-10-22 11:26:37 +0800103 * \brief Enter critical section of NSPE mailbox.
104 *
105 * \note The implementation depends on platform specific hardware and use case.
David Hu49ec08a2019-09-23 16:13:41 +0800106 */
David Hudbafa3e2019-10-22 11:26:37 +0800107void tfm_ns_mailbox_hal_enter_critical(void);
108
109/**
110 * \brief Exit critical section of NSPE mailbox.
111 *
112 * \note The implementation depends on platform specific hardware and use case.
113 */
114void tfm_ns_mailbox_hal_exit_critical(void);
115
David Huc617ba12019-11-14 17:06:11 +0800116/**
117 * \brief Enter critical section of NSPE mailbox in IRQ handler.
118 *
119 * \note The implementation depends on platform specific hardware and use case.
120 */
121void tfm_ns_mailbox_hal_enter_critical_isr(void);
122
123/**
124 * \brief Enter critical section of NSPE mailbox in IRQ handler
125 *
126 * \note The implementation depends on platform specific hardware and use case.
127 */
128void tfm_ns_mailbox_hal_exit_critical_isr(void);
129
David Hu69e590e2020-05-12 17:19:21 +0800130#ifdef FORWARD_PROT_MSG
131static inline int32_t tfm_ns_mailbox_os_lock_init(void)
132{
133 return MAILBOX_SUCCESS;
134}
135
136static inline uint32_t tfm_ns_mailbox_os_lock_acquire(void)
137{
138 return MAILBOX_SUCCESS;
139}
140
141static inline uint32_t tfm_ns_mailbox_os_lock_release(void)
142{
143 return MAILBOX_SUCCESS;
144}
145#else /* FORWARD_PROT_MSG */
146/**
147 * \brief Initialize the multi-core lock for synchronizing PSA client call(s)
148 * The actual implementation depends on the non-secure use scenario.
149 *
150 * \return \ref MAILBOX_SUCCESS on success
151 * \return \ref MAILBOX_GENERIC_ERROR on error
152 */
153int32_t tfm_ns_mailbox_os_lock_init(void);
154
155/**
156 * \brief Acquire the multi-core lock for synchronizing PSA client call(s)
157 * The actual implementation depends on the non-secure use scenario.
158 *
159 * \return \ref MAILBOX_SUCCESS on success
160 * \return \ref MAILBOX_GENERIC_ERROR on error
161 */
162int32_t tfm_ns_mailbox_os_lock_acquire(void);
163
164/**
165 * \brief Release the multi-core lock for synchronizing PSA client call(s)
166 * The actual implementation depends on the non-secure use scenario.
167 *
168 * \return \ref MAILBOX_SUCCESS on success
169 * \return \ref MAILBOX_GENERIC_ERROR on error
170 */
171int32_t tfm_ns_mailbox_os_lock_release(void);
172#endif /* FORWARD_PROT_MSG */
173
David Huf3e20472019-11-13 17:41:59 +0800174#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
175/**
David Hu69e590e2020-05-12 17:19:21 +0800176 * \brief Get the handle of the current non-secure task executing mailbox
177 * functionalities
178 *
179 * \note This function should be implemented according to NS OS and
180 * actual use scenario.
181 * This function can be ignored or return NULL if sleep/wake-up mechanism
182 * is not required in PSA Client API implementation.
183 *
184 * \return Return the handle of task.
185 */
186const void *tfm_ns_mailbox_os_get_task_handle(void);
187
188/**
189 * \brief Performs use scenario and NS OS specific waiting mechanism to wait for
David Hu6730af22020-05-11 19:50:08 +0800190 * the reply to be returned from SPE.
David Huf3e20472019-11-13 17:41:59 +0800191 *
David Hu69e590e2020-05-12 17:19:21 +0800192 * \note This function is implemented by NS OS specific waiting mechanism
193 * according to use scenario.
David Huf3e20472019-11-13 17:41:59 +0800194 */
David Hu6730af22020-05-11 19:50:08 +0800195void tfm_ns_mailbox_os_wait_reply(void);
David Hu1bd1c7b2020-05-09 14:13:20 +0800196
197/*
David Hu69e590e2020-05-12 17:19:21 +0800198 * \brief Performs use scenario and NS OS specific mechanism in a mailbox IRQ
David Hu1bd1c7b2020-05-09 14:13:20 +0800199 * handler, to wake up a sleeping task which is waiting for its mailbox
200 * message reply.
201 *
David Hu69e590e2020-05-12 17:19:21 +0800202 * \note The underlying NS OS specific function called inside this function
203 * should be able to work in an IRQ handler.
David Hu1bd1c7b2020-05-09 14:13:20 +0800204 *
David Hu69e590e2020-05-12 17:19:21 +0800205 * \note This function is implemented by NS OS specific waiting
David Hu1bd1c7b2020-05-09 14:13:20 +0800206 * mechanism according to use scenario.
207 *
208 * \param[in] task_handle The handle to the task to be woken up.
David Hu1bd1c7b2020-05-09 14:13:20 +0800209 */
David Hu6730af22020-05-11 19:50:08 +0800210void tfm_ns_mailbox_os_wake_task_isr(const void *task_handle);
David Hu69e590e2020-05-12 17:19:21 +0800211#else /* TFM_MULTI_CORE_MULTI_CLIENT_CALL */
David Hu6730af22020-05-11 19:50:08 +0800212#define tfm_ns_mailbox_os_wait_reply() do {} while (0)
David Hu69e590e2020-05-12 17:19:21 +0800213
214static inline const void *tfm_ns_mailbox_os_get_task_handle(void)
215{
216 return NULL;
217}
218
David Hu6730af22020-05-11 19:50:08 +0800219#define tfm_ns_mailbox_os_wake_task_isr(task) do {} while (0)
David Hu69e590e2020-05-12 17:19:21 +0800220#endif /* TFM_MULTI_CORE_MULTI_CLIENT_CALL */
David Huf3e20472019-11-13 17:41:59 +0800221
David Hu65cbfb82019-11-15 17:18:12 +0800222#ifdef TFM_MULTI_CORE_TEST
223/**
224 * \brief Initialize the statistics module in TF-M NSPE mailbox.
225 *
226 * \note This function is only available when multi-core tests are enabled.
227 */
228void tfm_ns_mailbox_tx_stats_init(void);
229
230/**
231 * \brief Calculate the average number of used NS mailbox queue slots each time
232 * NS task requires a queue slot to submit mailbox message, which is
233 * recorded in NS mailbox statisitics module.
234 *
235 * \note This function is only available when multi-core tests are enabled.
236 *
237 * \param[in] stats_res The buffer to be written with
238 * \ref ns_mailbox_stats_res_t.
239 *
240 * \return Return the calculation result.
241 */
242void tfm_ns_mailbox_stats_avg_slot(struct ns_mailbox_stats_res_t *stats_res);
243#endif
244
David Hudbafa3e2019-10-22 11:26:37 +0800245#ifdef __cplusplus
246}
247#endif
David Hu49ec08a2019-09-23 16:13:41 +0800248
249#endif /* __TFM_NS_MAILBOX_H__ */