blob: 114000f8a578da9229db49f230e59f67bc8652cf [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 Hu1bd1c7b2020-05-09 14:13:20 +080068 * \brief Wake up the owner task of the first replied mailbox message in the
69 * NSPE mailbox queue.
David Hu3684ee72019-11-12 18:43:34 +080070 * This function is intended to be called inside platform specific
71 * notification IRQ handler.
72 *
73 * \note The replied status of the fetched mailbox message will be cleaned after
David Hu1bd1c7b2020-05-09 14:13:20 +080074 * the message is fetched. When this function is called again, it wakes
75 * the owner task of next replied mailbox message from the NSPE mailbox
76 * queue.
David Hu3684ee72019-11-12 18:43:34 +080077 *
David Hu1bd1c7b2020-05-09 14:13:20 +080078 * \return MAILBOX_SUCCESS The task of the first replied mailbox message
79 * is found and wake-up signal is sent.
80 * \return MAILBOX_NO_PEND_EVENT No replied mailbox message is found.
81 * \return Other return code Failed with an error code
David Hu3684ee72019-11-12 18:43:34 +080082 */
David Hu1bd1c7b2020-05-09 14:13:20 +080083int32_t tfm_ns_mailbox_wake_reply_owner_isr(void);
David Huf3e20472019-11-13 17:41:59 +080084
David Hu3684ee72019-11-12 18:43:34 +080085/**
David Hu49ec08a2019-09-23 16:13:41 +080086 * \brief Platform specific NSPE mailbox initialization.
David Hudbafa3e2019-10-22 11:26:37 +080087 * Invoked by \ref tfm_ns_mailbox_init().
David Hu49ec08a2019-09-23 16:13:41 +080088 *
89 * \param[in] queue The base address of NSPE mailbox queue to be
90 * initialized.
91 *
92 * \retval MAILBOX_SUCCESS Operation succeeded.
93 * \retval Other return code Operation failed with an error code.
94 */
David Hudbafa3e2019-10-22 11:26:37 +080095int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue);
David Hu49ec08a2019-09-23 16:13:41 +080096
97/**
David Hudbafa3e2019-10-22 11:26:37 +080098 * \brief Notify SPE to deal with the PSA client call sent via mailbox
99 *
100 * \note The implementation depends on platform specific hardware and use case.
101 *
102 * \retval MAILBOX_SUCCESS Operation succeeded.
103 * \retval Other return code Operation failed with an error code.
David Hu49ec08a2019-09-23 16:13:41 +0800104 */
David Hudbafa3e2019-10-22 11:26:37 +0800105int32_t tfm_ns_mailbox_hal_notify_peer(void);
David Hu49ec08a2019-09-23 16:13:41 +0800106
107/**
David Hudbafa3e2019-10-22 11:26:37 +0800108 * \brief Enter critical section of NSPE mailbox.
109 *
110 * \note The implementation depends on platform specific hardware and use case.
David Hu49ec08a2019-09-23 16:13:41 +0800111 */
David Hudbafa3e2019-10-22 11:26:37 +0800112void tfm_ns_mailbox_hal_enter_critical(void);
113
114/**
115 * \brief Exit critical section of NSPE mailbox.
116 *
117 * \note The implementation depends on platform specific hardware and use case.
118 */
119void tfm_ns_mailbox_hal_exit_critical(void);
120
David Huc617ba12019-11-14 17:06:11 +0800121/**
122 * \brief Enter critical section of NSPE mailbox in IRQ handler.
123 *
124 * \note The implementation depends on platform specific hardware and use case.
125 */
126void tfm_ns_mailbox_hal_enter_critical_isr(void);
127
128/**
129 * \brief Enter critical section of NSPE mailbox in IRQ handler
130 *
131 * \note The implementation depends on platform specific hardware and use case.
132 */
133void tfm_ns_mailbox_hal_exit_critical_isr(void);
134
David Hu69e590e2020-05-12 17:19:21 +0800135#ifdef FORWARD_PROT_MSG
136static inline int32_t tfm_ns_mailbox_os_lock_init(void)
137{
138 return MAILBOX_SUCCESS;
139}
140
141static inline uint32_t tfm_ns_mailbox_os_lock_acquire(void)
142{
143 return MAILBOX_SUCCESS;
144}
145
146static inline uint32_t tfm_ns_mailbox_os_lock_release(void)
147{
148 return MAILBOX_SUCCESS;
149}
150#else /* FORWARD_PROT_MSG */
151/**
152 * \brief Initialize the multi-core lock for synchronizing PSA client call(s)
153 * The actual implementation depends on the non-secure use scenario.
154 *
155 * \return \ref MAILBOX_SUCCESS on success
156 * \return \ref MAILBOX_GENERIC_ERROR on error
157 */
158int32_t tfm_ns_mailbox_os_lock_init(void);
159
160/**
161 * \brief Acquire the multi-core lock for synchronizing PSA client call(s)
162 * The actual implementation depends on the non-secure use scenario.
163 *
164 * \return \ref MAILBOX_SUCCESS on success
165 * \return \ref MAILBOX_GENERIC_ERROR on error
166 */
167int32_t tfm_ns_mailbox_os_lock_acquire(void);
168
169/**
170 * \brief Release the multi-core lock for synchronizing PSA client call(s)
171 * The actual implementation depends on the non-secure use scenario.
172 *
173 * \return \ref MAILBOX_SUCCESS on success
174 * \return \ref MAILBOX_GENERIC_ERROR on error
175 */
176int32_t tfm_ns_mailbox_os_lock_release(void);
177#endif /* FORWARD_PROT_MSG */
178
David Huf3e20472019-11-13 17:41:59 +0800179#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
180/**
David Hu69e590e2020-05-12 17:19:21 +0800181 * \brief Get the handle of the current non-secure task executing mailbox
182 * functionalities
183 *
184 * \note This function should be implemented according to NS OS and
185 * actual use scenario.
186 * This function can be ignored or return NULL if sleep/wake-up mechanism
187 * is not required in PSA Client API implementation.
188 *
189 * \return Return the handle of task.
190 */
191const void *tfm_ns_mailbox_os_get_task_handle(void);
192
193/**
194 * \brief Performs use scenario and NS OS specific waiting mechanism to wait for
David Hu6730af22020-05-11 19:50:08 +0800195 * the reply to be returned from SPE.
David Huf3e20472019-11-13 17:41:59 +0800196 *
David Hu69e590e2020-05-12 17:19:21 +0800197 * \note This function is implemented by NS OS specific waiting mechanism
198 * according to use scenario.
David Huf3e20472019-11-13 17:41:59 +0800199 */
David Hu6730af22020-05-11 19:50:08 +0800200void tfm_ns_mailbox_os_wait_reply(void);
David Hu1bd1c7b2020-05-09 14:13:20 +0800201
202/*
David Hu69e590e2020-05-12 17:19:21 +0800203 * \brief Performs use scenario and NS OS specific mechanism in a mailbox IRQ
David Hu1bd1c7b2020-05-09 14:13:20 +0800204 * handler, to wake up a sleeping task which is waiting for its mailbox
205 * message reply.
206 *
David Hu69e590e2020-05-12 17:19:21 +0800207 * \note The underlying NS OS specific function called inside this function
208 * should be able to work in an IRQ handler.
David Hu1bd1c7b2020-05-09 14:13:20 +0800209 *
David Hu69e590e2020-05-12 17:19:21 +0800210 * \note This function is implemented by NS OS specific waiting
David Hu1bd1c7b2020-05-09 14:13:20 +0800211 * mechanism according to use scenario.
212 *
213 * \param[in] task_handle The handle to the task to be woken up.
David Hu1bd1c7b2020-05-09 14:13:20 +0800214 */
David Hu6730af22020-05-11 19:50:08 +0800215void tfm_ns_mailbox_os_wake_task_isr(const void *task_handle);
David Hu69e590e2020-05-12 17:19:21 +0800216#else /* TFM_MULTI_CORE_MULTI_CLIENT_CALL */
David Hu6730af22020-05-11 19:50:08 +0800217#define tfm_ns_mailbox_os_wait_reply() do {} while (0)
David Hu69e590e2020-05-12 17:19:21 +0800218
219static inline const void *tfm_ns_mailbox_os_get_task_handle(void)
220{
221 return NULL;
222}
223
David Hu6730af22020-05-11 19:50:08 +0800224#define tfm_ns_mailbox_os_wake_task_isr(task) do {} while (0)
David Hu69e590e2020-05-12 17:19:21 +0800225#endif /* TFM_MULTI_CORE_MULTI_CLIENT_CALL */
David Huf3e20472019-11-13 17:41:59 +0800226
David Hu65cbfb82019-11-15 17:18:12 +0800227#ifdef TFM_MULTI_CORE_TEST
228/**
229 * \brief Initialize the statistics module in TF-M NSPE mailbox.
230 *
231 * \note This function is only available when multi-core tests are enabled.
232 */
233void tfm_ns_mailbox_tx_stats_init(void);
234
235/**
236 * \brief Calculate the average number of used NS mailbox queue slots each time
237 * NS task requires a queue slot to submit mailbox message, which is
238 * recorded in NS mailbox statisitics module.
239 *
240 * \note This function is only available when multi-core tests are enabled.
241 *
242 * \param[in] stats_res The buffer to be written with
243 * \ref ns_mailbox_stats_res_t.
244 *
245 * \return Return the calculation result.
246 */
247void tfm_ns_mailbox_stats_avg_slot(struct ns_mailbox_stats_res_t *stats_res);
248#endif
249
David Hudbafa3e2019-10-22 11:26:37 +0800250#ifdef __cplusplus
251}
252#endif
David Hu49ec08a2019-09-23 16:13:41 +0800253
254#endif /* __TFM_NS_MAILBOX_H__ */