blob: 9f8354ba7e87cb12d1a0bb0195545cb57fdfa2b7 [file] [log] [blame]
David Hu733d8f92019-09-23 15:32:40 +08001/*
Xinyu Zhang2bc4d572021-12-27 16:37:46 +08002 * Copyright (c) 2019-2022, 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
Xinyu Zhangb287ef82021-11-03 18:38:50 +080016/**
17 * \brief This function handles the specific programmer error cases.
18 *
19 * \param[in] status Standard error codes for the SPM.
20 *
21 * \retval void Status will not cause SPM panic
22 * \retval "SPM panic" Following programmer errors are triggered by SP:
23 * \arg PSA_ERROR_PROGRAMMER_ERROR
24 * \arg PSA_ERROR_CONNECTION_REFUSED
25 * \arg PSA_ERROR_CONNECTION_BUSY
26 */
27void spm_handle_programmer_errors(psa_status_t status);
Shawn Shanb222d892021-01-04 17:41:48 +080028
Mingyang Suneeca4652021-07-15 15:19:16 +080029/**
30 * \brief This function get the current PSA RoT lifecycle state.
31 *
32 * \return state The current security lifecycle state of the PSA
33 * RoT. The PSA state and implementation state are
34 * encoded as follows:
35 * \arg state[15:8] – PSA lifecycle state
36 * \arg state[7:0] – IMPLEMENTATION DEFINED state
37 */
38uint32_t tfm_spm_get_lifecycle_state(void);
39
Mingyang Sunb26b2802021-07-07 11:25:00 +080040/* PSA Client API function body, for privileged use only. */
David Hu733d8f92019-09-23 15:32:40 +080041
42/**
43 * \brief handler for \ref psa_framework_version.
44 *
45 * \return version The version of the PSA Framework implementation
46 * that is providing the runtime services.
47 */
Mingyang Sund44522a2020-01-16 16:48:37 +080048uint32_t tfm_spm_client_psa_framework_version(void);
David Hu733d8f92019-09-23 15:32:40 +080049
50/**
51 * \brief handler for \ref psa_version.
52 *
53 * \param[in] sid RoT Service identity.
David Hu733d8f92019-09-23 15:32:40 +080054 *
55 * \retval PSA_VERSION_NONE The RoT Service is not implemented, or the
56 * caller is not permitted to access the service.
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +053057 * \retval > 0 The version of the implemented RoT Service.
David Hu733d8f92019-09-23 15:32:40 +080058 */
Mingyang Sun22a3faf2021-07-09 15:32:47 +080059uint32_t tfm_spm_client_psa_version(uint32_t sid);
David Hu733d8f92019-09-23 15:32:40 +080060
61/**
David Hu733d8f92019-09-23 15:32:40 +080062 * \brief handler for \ref psa_call.
63 *
64 * \param[in] handle Service handle to the established connection,
65 * \ref psa_handle_t
Mingyang Suneeca4652021-07-15 15:19:16 +080066 * \param[in] ctrl_param Parameters combined in uint32_t,
67 * includes request type, in_num and out_num.
David Hu733d8f92019-09-23 15:32:40 +080068 * \param[in] inptr Array of input psa_invec structures.
69 * \ref psa_invec
David Hu733d8f92019-09-23 15:32:40 +080070 * \param[in] outptr Array of output psa_outvec structures.
71 * \ref psa_outvec
David Hu733d8f92019-09-23 15:32:40 +080072 *
73 * \retval PSA_SUCCESS Success.
74 * \retval "Does not return" The call is invalid, one or more of the
75 * following are true:
76 * \arg An invalid handle was passed.
77 * \arg The connection is already handling a request.
78 * \arg An invalid memory reference was provided.
79 * \arg in_num + out_num > PSA_MAX_IOVEC.
80 * \arg The message is unrecognized by the RoT
81 * Service or incorrectly formatted.
82 */
Mingyang Suneeca4652021-07-15 15:19:16 +080083psa_status_t tfm_spm_client_psa_call(psa_handle_t handle,
84 uint32_t ctrl_param,
85 const psa_invec *inptr,
86 psa_outvec *outptr);
David Hu733d8f92019-09-23 15:32:40 +080087
Xinyu Zhang2bc4d572021-12-27 16:37:46 +080088/* Following PSA APIs are only needed by connection-based services */
89#if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1
90
91/**
92 * \brief handler for \ref psa_connect.
93 *
94 * \param[in] sid RoT Service identity.
95 * \param[in] version The version of the RoT Service.
96 *
97 * \retval PSA_SUCCESS Success.
98 * \retval PSA_ERROR_CONNECTION_REFUSED The SPM or RoT Service has refused the
99 * connection.
100 * \retval PSA_ERROR_CONNECTION_BUSY The SPM or RoT Service cannot make the
101 * connection at the moment.
102 * \retval "Does not return" The RoT Service ID and version are not
103 * supported, or the caller is not permitted to
104 * access the service.
105 */
106psa_status_t tfm_spm_client_psa_connect(uint32_t sid, uint32_t version);
107
David Hu733d8f92019-09-23 15:32:40 +0800108/**
109 * \brief handler for \ref psa_close.
110 *
111 * \param[in] handle Service handle to the connection to be closed,
112 * \ref psa_handle_t
David Hu733d8f92019-09-23 15:32:40 +0800113 *
Xinyu Zhangb287ef82021-11-03 18:38:50 +0800114 * \retval PSA_SUCCESS Success.
115 * \retval PSA_ERROR_PROGRAMMER_ERROR The call is invalid, one or more of the
David Hu733d8f92019-09-23 15:32:40 +0800116 * following are true:
Xinyu Zhangb287ef82021-11-03 18:38:50 +0800117 * \arg Called with a stateless handle.
David Hu733d8f92019-09-23 15:32:40 +0800118 * \arg An invalid handle was provided that is not
119 * the null handle.
120 * \arg The connection is handling a request.
121 */
Xinyu Zhangb287ef82021-11-03 18:38:50 +0800122psa_status_t tfm_spm_client_psa_close(psa_handle_t handle);
David Hu733d8f92019-09-23 15:32:40 +0800123
Xinyu Zhang2bc4d572021-12-27 16:37:46 +0800124#endif /* CONFIG_TFM_CONNECTION_BASED_SERVICE_API */
125
Mingyang Sunb26b2802021-07-07 11:25:00 +0800126/* PSA Partition API function body, for privileged use only. */
127
Kevin Pengdef92de2021-11-10 16:14:48 +0800128#if CONFIG_TFM_SPM_BACKEND_IPC == 1 \
129 || CONFIG_TFM_FLIH_API == 1 || CONFIG_TFM_SLIH_API == 1
Mingyang Sunb26b2802021-07-07 11:25:00 +0800130/**
131 * \brief Function body of \ref psa_wait.
132 *
133 * \param[in] signal_mask A set of signals to query. Signals that are not
134 * in this set will be ignored.
135 * \param[in] timeout Specify either blocking \ref PSA_BLOCK or
136 * polling \ref PSA_POLL operation.
137 *
138 * \retval >0 At least one signal is asserted.
139 * \retval 0 No signals are asserted. This is only seen when
140 * a polling timeout is used.
141 */
142psa_signal_t tfm_spm_partition_psa_wait(psa_signal_t signal_mask,
143 uint32_t timeout);
Kevin Pengdef92de2021-11-10 16:14:48 +0800144#endif
Mingyang Sunb26b2802021-07-07 11:25:00 +0800145
Kevin Pengdef92de2021-11-10 16:14:48 +0800146/* This API is only used in IPC backend. */
147#if CONFIG_TFM_SPM_BACKEND_IPC == 1
Mingyang Sunb26b2802021-07-07 11:25:00 +0800148/**
149 * \brief Function body of \ref psa_get.
150 *
151 * \param[in] signal The signal value for an asserted RoT Service.
152 * \param[out] msg Pointer to \ref psa_msg_t object for receiving
153 * the message.
154 *
155 * \retval PSA_SUCCESS Success, *msg will contain the delivered
156 * message.
157 * \retval PSA_ERROR_DOES_NOT_EXIST Message could not be delivered.
158 * \retval "PROGRAMMER ERROR" The call is invalid because one or more of the
159 * following are true:
160 * \arg signal has more than a single bit set.
161 * \arg signal does not correspond to an RoT Service.
162 * \arg The RoT Service signal is not currently
163 * asserted.
164 * \arg The msg pointer provided is not a valid memory
165 * reference.
166 */
167psa_status_t tfm_spm_partition_psa_get(psa_signal_t signal, psa_msg_t *msg);
Kevin Peng613b4172022-02-15 14:41:44 +0800168#endif /* CONFIG_TFM_SPM_BACKEND_IPC == 1 */
Mingyang Sunb26b2802021-07-07 11:25:00 +0800169
170/**
Mingyang Sunb26b2802021-07-07 11:25:00 +0800171 * \brief Function body of \ref psa_read.
172 *
173 * \param[in] msg_handle Handle for the client's message.
174 * \param[in] invec_idx Index of the input vector to read from. Must be
175 * less than \ref PSA_MAX_IOVEC.
176 * \param[out] buffer Buffer in the Secure Partition to copy the
177 * requested data to.
178 * \param[in] num_bytes Maximum number of bytes to be read from the
179 * client input vector.
180 *
181 * \retval >0 Number of bytes copied.
182 * \retval 0 There was no remaining data in this input
183 * vector.
184 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
185 * following are true:
186 * \arg msg_handle is invalid.
187 * \arg msg_handle does not refer to a
188 * \ref PSA_IPC_CALL message.
189 * \arg invec_idx is equal to or greater than
190 * \ref PSA_MAX_IOVEC.
191 * \arg the memory reference for buffer is invalid or
192 * not writable.
193 */
194size_t tfm_spm_partition_psa_read(psa_handle_t msg_handle, uint32_t invec_idx,
195 void *buffer, size_t num_bytes);
196
197/**
198 * \brief Function body of psa_skip.
199 *
200 * \param[in] msg_handle Handle for the client's message.
201 * \param[in] invec_idx Index of input vector to skip from. Must be
202 * less than \ref PSA_MAX_IOVEC.
203 * \param[in] num_bytes Maximum number of bytes to skip in the client
204 * input vector.
205 *
206 * \retval >0 Number of bytes skipped.
207 * \retval 0 There was no remaining data in this input
208 * vector.
209 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
210 * following are true:
211 * \arg msg_handle is invalid.
212 * \arg msg_handle does not refer to a request
213 * message.
214 * \arg invec_idx is equal to or greater than
215 * \ref PSA_MAX_IOVEC.
216 */
217size_t tfm_spm_partition_psa_skip(psa_handle_t msg_handle, uint32_t invec_idx,
218 size_t num_bytes);
219
220/**
221 * \brief Function body of \ref psa_write.
222 *
223 * \param[in] msg_handle Handle for the client's message.
224 * \param[out] outvec_idx Index of output vector in message to write to.
225 * Must be less than \ref PSA_MAX_IOVEC.
226 * \param[in] buffer Buffer with the data to write.
227 * \param[in] num_bytes Number of bytes to write to the client output
228 * vector.
229 *
230 * \retval void Success
231 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
232 * following are true:
233 * \arg msg_handle is invalid.
234 * \arg msg_handle does not refer to a request
235 * message.
236 * \arg outvec_idx is equal to or greater than
237 * \ref PSA_MAX_IOVEC.
238 * \arg The memory reference for buffer is invalid.
239 * \arg The call attempts to write data past the end
240 * of the client output vector.
241 */
242void tfm_spm_partition_psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
243 const void *buffer, size_t num_bytes);
244
245/**
246 * \brief Function body of \ref psa_reply.
247 *
248 * \param[in] msg_handle Handle for the client's message.
249 * \param[in] status Message result value to be reported to the
250 * client.
251 *
Ken Liuf39d8eb2021-10-07 12:55:33 +0800252 * \retval Positive integer Success, the connection handle.
253 * \retval PSA_SUCCESS Success
Mingyang Sunb26b2802021-07-07 11:25:00 +0800254 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
255 * following are true:
256 * \arg msg_handle is invalid.
257 * \arg An invalid status code is specified for the
258 * type of message.
259 */
Ken Liuf39d8eb2021-10-07 12:55:33 +0800260int32_t tfm_spm_partition_psa_reply(psa_handle_t msg_handle,
261 psa_status_t status);
Mingyang Sunb26b2802021-07-07 11:25:00 +0800262
Kevin Peng613b4172022-02-15 14:41:44 +0800263#if CONFIG_TFM_DOORBELL_API == 1
Mingyang Sunb26b2802021-07-07 11:25:00 +0800264/**
265 * \brief Function body of \ref psa_norify.
266 *
267 * \param[in] partition_id Secure Partition ID of the target partition.
268 *
269 * \retval void Success.
270 * \retval "PROGRAMMER ERROR" partition_id does not correspond to a Secure
271 * Partition.
272 */
273void tfm_spm_partition_psa_notify(int32_t partition_id);
274
275/**
276 * \brief Function body of \ref psa_clear.
277 *
278 * \retval void Success.
279 * \retval "PROGRAMMER ERROR" The Secure Partition's doorbell signal is not
280 * currently asserted.
281 */
282void tfm_spm_partition_psa_clear(void);
Kevin Peng613b4172022-02-15 14:41:44 +0800283#endif /* CONFIG_TFM_DOORBELL_API == 1 */
Mingyang Sunb26b2802021-07-07 11:25:00 +0800284
285/**
Mingyang Sunb26b2802021-07-07 11:25:00 +0800286 * \brief Function body of \ref psa_panic.
287 *
288 * \retval "Does not return"
289 */
290void tfm_spm_partition_psa_panic(void);
291
Mingyang Suned5fe7b2022-02-10 17:33:21 +0800292/* psa_set_rhandle is only needed by connection-based services */
293#if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1
294
295/**
296 * \brief Function body of \ref psa_set_rhandle.
297 *
298 * \param[in] msg_handle Handle for the client's message.
299 * \param[in] rhandle Reverse handle allocated by the RoT Service.
300 *
301 * \retval void Success, rhandle will be provided with all
302 * subsequent messages delivered on this
303 * connection.
304 * \retval "PROGRAMMER ERROR" msg_handle is invalid.
305 */
306void tfm_spm_partition_psa_set_rhandle(psa_handle_t msg_handle, void *rhandle);
307
308#endif /* CONFIG_TFM_CONNECTION_BASED_SERVICE_API */
309
310#if CONFIG_TFM_FLIH_API == 1 || CONFIG_TFM_SLIH_API == 1
Mingyang Sunb26b2802021-07-07 11:25:00 +0800311/**
312 * \brief Function body of \ref psa_irq_enable.
313 *
314 * \param[in] irq_signal The signal for the interrupt to be enabled.
315 * This must have a single bit set, which must be the
316 * signal value for an interrupt in the calling Secure
317 * Partition.
318 *
319 * \retval void
320 * \retval "PROGRAMMER ERROR" If one or more of the following are true:
321 * \arg \a irq_signal is not an interrupt signal.
322 * \arg \a irq_signal indicates more than one signal.
323 */
Kevin Peng67a89fd2021-11-25 11:22:02 +0800324void tfm_spm_partition_psa_irq_enable(psa_signal_t irq_signal);
Mingyang Sunb26b2802021-07-07 11:25:00 +0800325
326/**
327 * \brief Function body of psa_irq_disable.
328 *
329 * \param[in] irq_signal The signal for the interrupt to be disabled.
330 * This must have a single bit set, which must be the
331 * signal value for an interrupt in the calling Secure
332 * Partition.
333 *
334 * \retval 0 The interrupt was disabled prior to this call.
335 * 1 The interrupt was enabled prior to this call.
336 * \retval "PROGRAMMER ERROR" If one or more of the following are true:
337 * \arg \a irq_signal is not an interrupt signal.
338 * \arg \a irq_signal indicates more than one signal.
339 *
340 * \note The current implementation always return 1. Do not use the return.
341 */
Kevin Peng67a89fd2021-11-25 11:22:02 +0800342psa_irq_status_t tfm_spm_partition_psa_irq_disable(psa_signal_t irq_signal);
Mingyang Sunb26b2802021-07-07 11:25:00 +0800343
Mingyang Suned5fe7b2022-02-10 17:33:21 +0800344/* This API is only used for FLIH. */
345#if CONFIG_TFM_FLIH_API == 1
Mingyang Sunb26b2802021-07-07 11:25:00 +0800346/**
347 * \brief Function body of \ref psa_reset_signal.
348 *
349 * \param[in] irq_signal The interrupt signal to be reset.
350 * This must have a single bit set, corresponding to a
351 * currently asserted signal for an interrupt that is
352 * defined to use FLIH handling.
353 *
354 * \retval void
355 * \retval "Programmer Error" if one or more of the following are true:
356 * \arg \a irq_signal is not a signal for an interrupt
357 * that is specified with FLIH handling in the Secure
358 * Partition manifest.
359 * \arg \a irq_signal indicates more than one signal.
360 * \arg \a irq_signal is not currently asserted.
361 */
362void tfm_spm_partition_psa_reset_signal(psa_signal_t irq_signal);
Mingyang Suned5fe7b2022-02-10 17:33:21 +0800363#endif
Mingyang Sunb26b2802021-07-07 11:25:00 +0800364
Mingyang Suned5fe7b2022-02-10 17:33:21 +0800365/* This API is only used for SLIH. */
366#if CONFIG_TFM_SLIH_API == 1
Xinyu Zhang2bc4d572021-12-27 16:37:46 +0800367/**
Mingyang Suned5fe7b2022-02-10 17:33:21 +0800368 * \brief Function body of \ref psa_eoi.
Xinyu Zhang2bc4d572021-12-27 16:37:46 +0800369 *
Mingyang Suned5fe7b2022-02-10 17:33:21 +0800370 * \param[in] irq_signal The interrupt signal that has been processed.
Xinyu Zhang2bc4d572021-12-27 16:37:46 +0800371 *
Mingyang Suned5fe7b2022-02-10 17:33:21 +0800372 * \retval void Success.
373 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
374 * following are true:
375 * \arg irq_signal is not an interrupt signal.
376 * \arg irq_signal indicates more than one signal.
377 * \arg irq_signal is not currently asserted.
378 * \arg The interrupt is not using SLIH.
Xinyu Zhang2bc4d572021-12-27 16:37:46 +0800379 */
Mingyang Suned5fe7b2022-02-10 17:33:21 +0800380void tfm_spm_partition_psa_eoi(psa_signal_t irq_signal);
381#endif
382#endif /* CONFIG_TFM_FLIH_API == 1 || CONFIG_TFM_SLIH_API == 1 */
Xinyu Zhang2bc4d572021-12-27 16:37:46 +0800383
Shawn Shan038348e2021-09-08 17:11:04 +0800384#if PSA_FRAMEWORK_HAS_MM_IOVEC
385
386/**
387 * \brief Function body of psa_map_invec.
388 */
389const void *tfm_spm_partition_psa_map_invec(psa_handle_t msg_handle,
390 uint32_t invec_idx);
391
392/**
393 * \brief Function body of psa_unmap_invec.
394 */
395void tfm_spm_partition_psa_unmap_invec(psa_handle_t msg_handle,
396 uint32_t invec_idx);
397
398/**
399 * \brief Function body of psa_map_outvet.
400 */
401void *tfm_spm_partition_psa_map_outvec(psa_handle_t msg_handle,
402 uint32_t outvec_idx);
403
404/**
405 * \brief Function body of psa_unmap_outvec.
406 */
407void tfm_spm_partition_psa_unmap_outvec(psa_handle_t msg_handle,
408 uint32_t outvec_idx, size_t len);
409
410#endif /* PSA_FRAMEWORK_HAS_MM_IOVEC */
411
Mingyang Sun133a7922021-07-08 16:01:26 +0800412#endif /* __PSA_API_H__ */