blob: bdca18c99e1fdaebdce884029b487f43488c4b65 [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 Hu06ebac72019-09-29 16:01:54 +080067#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 */
79const void *tfm_ns_mailbox_get_task_handle(void);
80#else
81static inline const void *tfm_ns_mailbox_get_task_handle(void)
82{
83 return NULL;
84}
85#endif
86
David Hu49ec08a2019-09-23 16:13:41 +080087/**
David Hu1bd1c7b2020-05-09 14:13:20 +080088 * \brief Wake up the owner task of the first replied mailbox message in the
89 * NSPE mailbox queue.
David Hu3684ee72019-11-12 18:43:34 +080090 * 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 Hu1bd1c7b2020-05-09 14:13:20 +080094 * 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 Hu3684ee72019-11-12 18:43:34 +080097 *
David Hu1bd1c7b2020-05-09 14:13:20 +080098 * \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 Hu3684ee72019-11-12 18:43:34 +0800102 */
David Hu1bd1c7b2020-05-09 14:13:20 +0800103int32_t tfm_ns_mailbox_wake_reply_owner_isr(void);
David Huf3e20472019-11-13 17:41:59 +0800104
David Hu3684ee72019-11-12 18:43:34 +0800105/**
David Hu49ec08a2019-09-23 16:13:41 +0800106 * \brief Platform specific NSPE mailbox initialization.
David Hudbafa3e2019-10-22 11:26:37 +0800107 * Invoked by \ref tfm_ns_mailbox_init().
David Hu49ec08a2019-09-23 16:13:41 +0800108 *
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 Hudbafa3e2019-10-22 11:26:37 +0800115int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue);
David Hu49ec08a2019-09-23 16:13:41 +0800116
117/**
David Hudbafa3e2019-10-22 11:26:37 +0800118 * \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 Hu49ec08a2019-09-23 16:13:41 +0800124 */
David Hudbafa3e2019-10-22 11:26:37 +0800125int32_t tfm_ns_mailbox_hal_notify_peer(void);
David Hu49ec08a2019-09-23 16:13:41 +0800126
127/**
David Hudbafa3e2019-10-22 11:26:37 +0800128 * \brief Enter critical section of NSPE mailbox.
129 *
130 * \note The implementation depends on platform specific hardware and use case.
David Hu49ec08a2019-09-23 16:13:41 +0800131 */
David Hudbafa3e2019-10-22 11:26:37 +0800132void 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 */
139void tfm_ns_mailbox_hal_exit_critical(void);
140
David Huc617ba12019-11-14 17:06:11 +0800141/**
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 */
146void 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 */
153void tfm_ns_mailbox_hal_exit_critical_isr(void);
154
David Huf3e20472019-11-13 17:41:59 +0800155#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 Hu1bd1c7b2020-05-09 14:13:20 +0800161 * mechanism according to use scenario.
David Huf3e20472019-11-13 17:41:59 +0800162 *
163 * \param[in] handle The handle of mailbox message.
164 */
165void tfm_ns_mailbox_hal_wait_reply(mailbox_msg_handle_t handle);
David Hu1bd1c7b2020-05-09 14:13:20 +0800166
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 */
182void 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 Huf3e20472019-11-13 17:41:59 +0800186#endif
187
David Hu65cbfb82019-11-15 17:18:12 +0800188#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 */
194void 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 */
208void tfm_ns_mailbox_stats_avg_slot(struct ns_mailbox_stats_res_t *stats_res);
209#endif
210
David Hudbafa3e2019-10-22 11:26:37 +0800211#ifdef __cplusplus
212}
213#endif
David Hu49ec08a2019-09-23 16:13:41 +0800214
215#endif /* __TFM_NS_MAILBOX_H__ */