blob: 9ed6d0f78b486473438874f8a9847a5fd6398ef6 [file] [log] [blame]
David Hu733d8f92019-09-23 15:32:40 +08001/*
Shawn Shanb222d892021-01-04 17:41:48 +08002 * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
David Hu733d8f92019-09-23 15:32:40 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Mingyang Sun133a7922021-07-08 16:01:26 +08008#ifndef __PSA_API_H__
9#define __PSA_API_H__
David Hu733d8f92019-09-23 15:32:40 +080010
11#include <stdint.h>
Mingyang Sun7397b4f2020-06-17 15:07:45 +080012#include <stdbool.h>
David Hu733d8f92019-09-23 15:32:40 +080013#include "psa/client.h"
Mingyang Sunb26b2802021-07-07 11:25:00 +080014#include "psa/service.h"
David Hu733d8f92019-09-23 15:32:40 +080015
Shawn Shanb222d892021-01-04 17:41:48 +080016#define PROGRAMMER_ERROR_NULL
17#define TFM_PROGRAMMER_ERROR(ns_caller, error_status) \
18 do { \
19 if (ns_caller) { \
20 return error_status; \
21 } else { \
22 tfm_core_panic(); \
23 } \
24 } while (0)
25
Mingyang Suneeca4652021-07-15 15:19:16 +080026/**
27 * \brief This function get the current PSA RoT lifecycle state.
28 *
29 * \return state The current security lifecycle state of the PSA
30 * RoT. The PSA state and implementation state are
31 * encoded as follows:
32 * \arg state[15:8] – PSA lifecycle state
33 * \arg state[7:0] – IMPLEMENTATION DEFINED state
34 */
35uint32_t tfm_spm_get_lifecycle_state(void);
36
Mingyang Sunb26b2802021-07-07 11:25:00 +080037/* PSA Client API function body, for privileged use only. */
David Hu733d8f92019-09-23 15:32:40 +080038
39/**
40 * \brief handler for \ref psa_framework_version.
41 *
42 * \return version The version of the PSA Framework implementation
43 * that is providing the runtime services.
44 */
Mingyang Sund44522a2020-01-16 16:48:37 +080045uint32_t tfm_spm_client_psa_framework_version(void);
David Hu733d8f92019-09-23 15:32:40 +080046
47/**
48 * \brief handler for \ref psa_version.
49 *
50 * \param[in] sid RoT Service identity.
David Hu733d8f92019-09-23 15:32:40 +080051 *
52 * \retval PSA_VERSION_NONE The RoT Service is not implemented, or the
53 * caller is not permitted to access the service.
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +053054 * \retval > 0 The version of the implemented RoT Service.
David Hu733d8f92019-09-23 15:32:40 +080055 */
Mingyang Sun22a3faf2021-07-09 15:32:47 +080056uint32_t tfm_spm_client_psa_version(uint32_t sid);
David Hu733d8f92019-09-23 15:32:40 +080057
58/**
59 * \brief handler for \ref psa_connect.
60 *
61 * \param[in] sid RoT Service identity.
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +053062 * \param[in] version The version of the RoT Service.
David Hu733d8f92019-09-23 15:32:40 +080063 *
64 * \retval PSA_SUCCESS Success.
65 * \retval PSA_ERROR_CONNECTION_REFUSED The SPM or RoT Service has refused the
66 * connection.
67 * \retval PSA_ERROR_CONNECTION_BUSY The SPM or RoT Service cannot make the
68 * connection at the moment.
69 * \retval "Does not return" The RoT Service ID and version are not
70 * supported, or the caller is not permitted to
71 * access the service.
72 */
Mingyang Sun22a3faf2021-07-09 15:32:47 +080073psa_status_t tfm_spm_client_psa_connect(uint32_t sid, uint32_t version);
David Hu733d8f92019-09-23 15:32:40 +080074
75/**
76 * \brief handler for \ref psa_call.
77 *
78 * \param[in] handle Service handle to the established connection,
79 * \ref psa_handle_t
Mingyang Suneeca4652021-07-15 15:19:16 +080080 * \param[in] ctrl_param Parameters combined in uint32_t,
81 * includes request type, in_num and out_num.
David Hu733d8f92019-09-23 15:32:40 +080082 * \param[in] inptr Array of input psa_invec structures.
83 * \ref psa_invec
David Hu733d8f92019-09-23 15:32:40 +080084 * \param[in] outptr Array of output psa_outvec structures.
85 * \ref psa_outvec
David Hu733d8f92019-09-23 15:32:40 +080086 *
87 * \retval PSA_SUCCESS Success.
88 * \retval "Does not return" The call is invalid, one or more of the
89 * following are true:
90 * \arg An invalid handle was passed.
91 * \arg The connection is already handling a request.
92 * \arg An invalid memory reference was provided.
93 * \arg in_num + out_num > PSA_MAX_IOVEC.
94 * \arg The message is unrecognized by the RoT
95 * Service or incorrectly formatted.
96 */
Mingyang Suneeca4652021-07-15 15:19:16 +080097psa_status_t tfm_spm_client_psa_call(psa_handle_t handle,
98 uint32_t ctrl_param,
99 const psa_invec *inptr,
100 psa_outvec *outptr);
David Hu733d8f92019-09-23 15:32:40 +0800101
102/**
103 * \brief handler for \ref psa_close.
104 *
105 * \param[in] handle Service handle to the connection to be closed,
106 * \ref psa_handle_t
David Hu733d8f92019-09-23 15:32:40 +0800107 *
108 * \retval void Success.
109 * \retval "Does not return" The call is invalid, one or more of the
110 * following are true:
111 * \arg An invalid handle was provided that is not
112 * the null handle.
113 * \arg The connection is handling a request.
114 */
Mingyang Sun22a3faf2021-07-09 15:32:47 +0800115void tfm_spm_client_psa_close(psa_handle_t handle);
David Hu733d8f92019-09-23 15:32:40 +0800116
Mingyang Sunb26b2802021-07-07 11:25:00 +0800117/* PSA Partition API function body, for privileged use only. */
118
119/**
120 * \brief Function body of \ref psa_wait.
121 *
122 * \param[in] signal_mask A set of signals to query. Signals that are not
123 * in this set will be ignored.
124 * \param[in] timeout Specify either blocking \ref PSA_BLOCK or
125 * polling \ref PSA_POLL operation.
126 *
127 * \retval >0 At least one signal is asserted.
128 * \retval 0 No signals are asserted. This is only seen when
129 * a polling timeout is used.
130 */
131psa_signal_t tfm_spm_partition_psa_wait(psa_signal_t signal_mask,
132 uint32_t timeout);
133
134/**
135 * \brief Function body of \ref psa_get.
136 *
137 * \param[in] signal The signal value for an asserted RoT Service.
138 * \param[out] msg Pointer to \ref psa_msg_t object for receiving
139 * the message.
140 *
141 * \retval PSA_SUCCESS Success, *msg will contain the delivered
142 * message.
143 * \retval PSA_ERROR_DOES_NOT_EXIST Message could not be delivered.
144 * \retval "PROGRAMMER ERROR" The call is invalid because one or more of the
145 * following are true:
146 * \arg signal has more than a single bit set.
147 * \arg signal does not correspond to an RoT Service.
148 * \arg The RoT Service signal is not currently
149 * asserted.
150 * \arg The msg pointer provided is not a valid memory
151 * reference.
152 */
153psa_status_t tfm_spm_partition_psa_get(psa_signal_t signal, psa_msg_t *msg);
154
155/**
156 * \brief Function body of \ref psa_set_rhandle.
157 *
158 * \param[in] msg_handle Handle for the client's message.
159 * \param[in] rhandle Reverse handle allocated by the RoT Service.
160 *
161 * \retval void Success, rhandle will be provided with all
162 * subsequent messages delivered on this
163 * connection.
164 * \retval "PROGRAMMER ERROR" msg_handle is invalid.
165 */
166void tfm_spm_partition_psa_set_rhandle(psa_handle_t msg_handle, void *rhandle);
167
168/**
169 * \brief Function body of \ref psa_read.
170 *
171 * \param[in] msg_handle Handle for the client's message.
172 * \param[in] invec_idx Index of the input vector to read from. Must be
173 * less than \ref PSA_MAX_IOVEC.
174 * \param[out] buffer Buffer in the Secure Partition to copy the
175 * requested data to.
176 * \param[in] num_bytes Maximum number of bytes to be read from the
177 * client input vector.
178 *
179 * \retval >0 Number of bytes copied.
180 * \retval 0 There was no remaining data in this input
181 * vector.
182 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
183 * following are true:
184 * \arg msg_handle is invalid.
185 * \arg msg_handle does not refer to a
186 * \ref PSA_IPC_CALL message.
187 * \arg invec_idx is equal to or greater than
188 * \ref PSA_MAX_IOVEC.
189 * \arg the memory reference for buffer is invalid or
190 * not writable.
191 */
192size_t tfm_spm_partition_psa_read(psa_handle_t msg_handle, uint32_t invec_idx,
193 void *buffer, size_t num_bytes);
194
195/**
196 * \brief Function body of psa_skip.
197 *
198 * \param[in] msg_handle Handle for the client's message.
199 * \param[in] invec_idx Index of input vector to skip from. Must be
200 * less than \ref PSA_MAX_IOVEC.
201 * \param[in] num_bytes Maximum number of bytes to skip in the client
202 * input vector.
203 *
204 * \retval >0 Number of bytes skipped.
205 * \retval 0 There was no remaining data in this input
206 * vector.
207 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
208 * following are true:
209 * \arg msg_handle is invalid.
210 * \arg msg_handle does not refer to a request
211 * message.
212 * \arg invec_idx is equal to or greater than
213 * \ref PSA_MAX_IOVEC.
214 */
215size_t tfm_spm_partition_psa_skip(psa_handle_t msg_handle, uint32_t invec_idx,
216 size_t num_bytes);
217
218/**
219 * \brief Function body of \ref psa_write.
220 *
221 * \param[in] msg_handle Handle for the client's message.
222 * \param[out] outvec_idx Index of output vector in message to write to.
223 * Must be less than \ref PSA_MAX_IOVEC.
224 * \param[in] buffer Buffer with the data to write.
225 * \param[in] num_bytes Number of bytes to write to the client output
226 * vector.
227 *
228 * \retval void Success
229 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
230 * following are true:
231 * \arg msg_handle is invalid.
232 * \arg msg_handle does not refer to a request
233 * message.
234 * \arg outvec_idx is equal to or greater than
235 * \ref PSA_MAX_IOVEC.
236 * \arg The memory reference for buffer is invalid.
237 * \arg The call attempts to write data past the end
238 * of the client output vector.
239 */
240void tfm_spm_partition_psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
241 const void *buffer, size_t num_bytes);
242
243/**
244 * \brief Function body of \ref psa_reply.
245 *
246 * \param[in] msg_handle Handle for the client's message.
247 * \param[in] status Message result value to be reported to the
248 * client.
249 *
250 * \retval void Success.
251 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
252 * following are true:
253 * \arg msg_handle is invalid.
254 * \arg An invalid status code is specified for the
255 * type of message.
256 */
257void tfm_spm_partition_psa_reply(psa_handle_t msg_handle, psa_status_t status);
258
259/**
260 * \brief Function body of \ref psa_norify.
261 *
262 * \param[in] partition_id Secure Partition ID of the target partition.
263 *
264 * \retval void Success.
265 * \retval "PROGRAMMER ERROR" partition_id does not correspond to a Secure
266 * Partition.
267 */
268void tfm_spm_partition_psa_notify(int32_t partition_id);
269
270/**
271 * \brief Function body of \ref psa_clear.
272 *
273 * \retval void Success.
274 * \retval "PROGRAMMER ERROR" The Secure Partition's doorbell signal is not
275 * currently asserted.
276 */
277void tfm_spm_partition_psa_clear(void);
278
279/**
280 * \brief Function body of \ref psa_eoi.
281 *
282 * \param[in] irq_signal The interrupt signal that has been processed.
283 *
284 * \retval void Success.
285 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
286 * following are true:
287 * \arg irq_signal is not an interrupt signal.
288 * \arg irq_signal indicates more than one signal.
289 * \arg irq_signal is not currently asserted.
290 * \arg The interrupt is not using SLIH.
291 */
292void tfm_spm_partition_psa_eoi(psa_signal_t irq_signal);
293
294/**
295 * \brief Function body of \ref psa_panic.
296 *
297 * \retval "Does not return"
298 */
299void tfm_spm_partition_psa_panic(void);
300
301/**
302 * \brief Function body of \ref psa_irq_enable.
303 *
304 * \param[in] irq_signal The signal for the interrupt to be enabled.
305 * This must have a single bit set, which must be the
306 * signal value for an interrupt in the calling Secure
307 * Partition.
308 *
309 * \retval void
310 * \retval "PROGRAMMER ERROR" If one or more of the following are true:
311 * \arg \a irq_signal is not an interrupt signal.
312 * \arg \a irq_signal indicates more than one signal.
313 */
314void tfm_spm_partition_irq_enable(psa_signal_t irq_signal);
315
316/**
317 * \brief Function body of psa_irq_disable.
318 *
319 * \param[in] irq_signal The signal for the interrupt to be disabled.
320 * This must have a single bit set, which must be the
321 * signal value for an interrupt in the calling Secure
322 * Partition.
323 *
324 * \retval 0 The interrupt was disabled prior to this call.
325 * 1 The interrupt was enabled prior to this call.
326 * \retval "PROGRAMMER ERROR" If one or more of the following are true:
327 * \arg \a irq_signal is not an interrupt signal.
328 * \arg \a irq_signal indicates more than one signal.
329 *
330 * \note The current implementation always return 1. Do not use the return.
331 */
332psa_irq_status_t tfm_spm_partition_irq_disable(psa_signal_t irq_signal);
333
334/**
335 * \brief Function body of \ref psa_reset_signal.
336 *
337 * \param[in] irq_signal The interrupt signal to be reset.
338 * This must have a single bit set, corresponding to a
339 * currently asserted signal for an interrupt that is
340 * defined to use FLIH handling.
341 *
342 * \retval void
343 * \retval "Programmer Error" if one or more of the following are true:
344 * \arg \a irq_signal is not a signal for an interrupt
345 * that is specified with FLIH handling in the Secure
346 * Partition manifest.
347 * \arg \a irq_signal indicates more than one signal.
348 * \arg \a irq_signal is not currently asserted.
349 */
350void tfm_spm_partition_psa_reset_signal(psa_signal_t irq_signal);
351
Mingyang Sun133a7922021-07-08 16:01:26 +0800352#endif /* __PSA_API_H__ */