blob: 48901f0526bcb33e760fc4a0183ccfe0e00feafb [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
8/* API definitions in NSPE mailbox library */
9
10#ifndef __TFM_NS_MAILBOX_H__
11#define __TFM_NS_MAILBOX_H__
12
13#include <stdbool.h>
14#include "tfm_mailbox.h"
15
David Hudbafa3e2019-10-22 11:26:37 +080016#ifdef __cplusplus
17extern "C" {
18#endif
19
David Hu49ec08a2019-09-23 16:13:41 +080020/**
David Hudbafa3e2019-10-22 11:26:37 +080021 * \brief Prepare and send PSA client request to SPE via mailbox.
David Hu49ec08a2019-09-23 16:13:41 +080022 *
23 * \param[in] call_type PSA client call type
24 * \param[in] params Parmaters used for PSA client call
25 * \param[in] client_id Optional client ID of non-secure caller.
26 * It is required to identify the non-secure caller
27 * when NSPE OS enforces non-secure task isolation.
28 *
29 * \retval >= 0 The handle to the mailbox message assigned.
30 * \retval < 0 Operation failed with an error code.
31 */
David Hudbafa3e2019-10-22 11:26:37 +080032mailbox_msg_handle_t tfm_ns_mailbox_tx_client_req(uint32_t call_type,
33 const struct psa_client_params_t *params,
34 int32_t client_id);
David Hu49ec08a2019-09-23 16:13:41 +080035
36/**
David Hudbafa3e2019-10-22 11:26:37 +080037 * \brief Fetch PSA client return result.
David Hu49ec08a2019-09-23 16:13:41 +080038 *
39 * \param[in] handle The handle to the mailbox message
40 * \param[out] reply The address to be written with return result.
41 *
42 * \retval MAILBOX_SUCCESS Successfully get PSA client call return result.
43 * \retval Other return code Operation failed with an error code.
44 */
David Hudbafa3e2019-10-22 11:26:37 +080045int32_t tfm_ns_mailbox_rx_client_reply(mailbox_msg_handle_t handle,
46 int32_t *reply);
David Hu49ec08a2019-09-23 16:13:41 +080047
48/**
49 * \brief Check whether a specific mailbox message has been replied.
50 *
51 * \param[in] handle The handle to the mailbox message
52 *
53 * \retval true The PSA client call return value is replied.
54 * \retval false The PSA client call return value is not
55 * replied yet.
56 */
David Hudbafa3e2019-10-22 11:26:37 +080057bool tfm_ns_mailbox_is_msg_replied(mailbox_msg_handle_t handle);
David Hu49ec08a2019-09-23 16:13:41 +080058
59/**
60 * \brief NSPE mailbox initialization
61 *
62 * \param[in] queue The base address of NSPE mailbox queue to be
63 * initialized.
64 *
65 * \retval MAILBOX_SUCCESS Operation succeeded.
66 * \retval Other return code Operation failed with an error code.
67 */
David Hudbafa3e2019-10-22 11:26:37 +080068int32_t tfm_ns_mailbox_init(struct ns_mailbox_queue_t *queue);
David Hu49ec08a2019-09-23 16:13:41 +080069
David Hu06ebac72019-09-29 16:01:54 +080070#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
71/**
72 * \brief Get the handle of the current non-secure task executing mailbox
73 * functionalities
74 *
75 * \note This function should be implemented according to platform, NS OS
76 * and actual use scenario.
77 * This function can be ignored or return NULL if sleep/wake-up mechanism
78 * is not required in PSA Client API implementation.
79 *
80 * \return Return the handle of task.
81 */
82const void *tfm_ns_mailbox_get_task_handle(void);
83#else
84static inline const void *tfm_ns_mailbox_get_task_handle(void)
85{
86 return NULL;
87}
88#endif
89
David Hu49ec08a2019-09-23 16:13:41 +080090/**
David Hu3684ee72019-11-12 18:43:34 +080091 * \brief Fetch the handle to the first replied mailbox message in the NSPE
92 * mailbox queue.
93 * This function is intended to be called inside platform specific
94 * notification IRQ handler.
95 *
96 * \note The replied status of the fetched mailbox message will be cleaned after
97 * the message is fetched. When this function is called again, it fetches
98 * the next replied mailbox message from the NSPE mailbox queue.
99 *
100 * \return Return the handle to the first replied mailbox message in the
101 * queue.
102 * Return \ref MAILBOX_MSG_NULL_HANDLE if no mailbox message is replied.
103 */
104mailbox_msg_handle_t tfm_ns_mailbox_fetch_reply_msg_isr(void);
105
106/**
107 * \brief Return the handle of owner task of a mailbox message according to the
108 * \ref mailbox_msg_handle_t
109 *
110 * \param[in] handle The handle of mailbox message.
111 *
112 * \return Return the handle value of the owner task.
113 */
114const void *tfm_ns_mailbox_get_msg_owner(mailbox_msg_handle_t handle);
115
David Huf3e20472019-11-13 17:41:59 +0800116#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
117/**
118 * \brief Wait for the reply returned from SPE to the mailbox message specified
119 * by handle
120 *
121 * \param[in] handle The handle of mailbox message.
122 *
123 * \retval MAILBOX_SUCCESS Return from waiting successfully.
124 * \retval Other return code Failed to wait with an error code.
125 */
126int32_t tfm_ns_mailbox_wait_reply(mailbox_msg_handle_t handle);
127#endif
128
David Hu3684ee72019-11-12 18:43:34 +0800129/**
David Hu49ec08a2019-09-23 16:13:41 +0800130 * \brief Platform specific NSPE mailbox initialization.
David Hudbafa3e2019-10-22 11:26:37 +0800131 * Invoked by \ref tfm_ns_mailbox_init().
David Hu49ec08a2019-09-23 16:13:41 +0800132 *
133 * \param[in] queue The base address of NSPE mailbox queue to be
134 * initialized.
135 *
136 * \retval MAILBOX_SUCCESS Operation succeeded.
137 * \retval Other return code Operation failed with an error code.
138 */
David Hudbafa3e2019-10-22 11:26:37 +0800139int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue);
David Hu49ec08a2019-09-23 16:13:41 +0800140
141/**
David Hudbafa3e2019-10-22 11:26:37 +0800142 * \brief Notify SPE to deal with the PSA client call sent via mailbox
143 *
144 * \note The implementation depends on platform specific hardware and use case.
145 *
146 * \retval MAILBOX_SUCCESS Operation succeeded.
147 * \retval Other return code Operation failed with an error code.
David Hu49ec08a2019-09-23 16:13:41 +0800148 */
David Hudbafa3e2019-10-22 11:26:37 +0800149int32_t tfm_ns_mailbox_hal_notify_peer(void);
David Hu49ec08a2019-09-23 16:13:41 +0800150
151/**
David Hudbafa3e2019-10-22 11:26:37 +0800152 * \brief Enter critical section of NSPE mailbox.
153 *
154 * \note The implementation depends on platform specific hardware and use case.
David Hu49ec08a2019-09-23 16:13:41 +0800155 */
David Hudbafa3e2019-10-22 11:26:37 +0800156void tfm_ns_mailbox_hal_enter_critical(void);
157
158/**
159 * \brief Exit critical section of NSPE mailbox.
160 *
161 * \note The implementation depends on platform specific hardware and use case.
162 */
163void tfm_ns_mailbox_hal_exit_critical(void);
164
David Huc617ba12019-11-14 17:06:11 +0800165/**
166 * \brief Enter critical section of NSPE mailbox in IRQ handler.
167 *
168 * \note The implementation depends on platform specific hardware and use case.
169 */
170void tfm_ns_mailbox_hal_enter_critical_isr(void);
171
172/**
173 * \brief Enter critical section of NSPE mailbox in IRQ handler
174 *
175 * \note The implementation depends on platform specific hardware and use case.
176 */
177void tfm_ns_mailbox_hal_exit_critical_isr(void);
178
David Huf3e20472019-11-13 17:41:59 +0800179#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
180/**
181 * \brief Performs platform and NS OS specific waiting mechanism to wait for
182 * the reply of the specified mailbox message to be returned from SPE.
183 *
184 * \note This function is implemented by platform and NS OS specific waiting
185 * mechanism accroding to use scenario.
186 *
187 * \param[in] handle The handle of mailbox message.
188 */
189void tfm_ns_mailbox_hal_wait_reply(mailbox_msg_handle_t handle);
190#endif
191
David Hudbafa3e2019-10-22 11:26:37 +0800192#ifdef __cplusplus
193}
194#endif
David Hu49ec08a2019-09-23 16:13:41 +0800195
196#endif /* __TFM_NS_MAILBOX_H__ */