blob: 97ab3526600bba4c96700d96c383aab042cd1294 [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
128/**
129 * \brief Function body of \ref psa_wait.
130 *
131 * \param[in] signal_mask A set of signals to query. Signals that are not
132 * in this set will be ignored.
133 * \param[in] timeout Specify either blocking \ref PSA_BLOCK or
134 * polling \ref PSA_POLL operation.
135 *
136 * \retval >0 At least one signal is asserted.
137 * \retval 0 No signals are asserted. This is only seen when
138 * a polling timeout is used.
139 */
140psa_signal_t tfm_spm_partition_psa_wait(psa_signal_t signal_mask,
141 uint32_t timeout);
142
143/**
144 * \brief Function body of \ref psa_get.
145 *
146 * \param[in] signal The signal value for an asserted RoT Service.
147 * \param[out] msg Pointer to \ref psa_msg_t object for receiving
148 * the message.
149 *
150 * \retval PSA_SUCCESS Success, *msg will contain the delivered
151 * message.
152 * \retval PSA_ERROR_DOES_NOT_EXIST Message could not be delivered.
153 * \retval "PROGRAMMER ERROR" The call is invalid because one or more of the
154 * following are true:
155 * \arg signal has more than a single bit set.
156 * \arg signal does not correspond to an RoT Service.
157 * \arg The RoT Service signal is not currently
158 * asserted.
159 * \arg The msg pointer provided is not a valid memory
160 * reference.
161 */
162psa_status_t tfm_spm_partition_psa_get(psa_signal_t signal, psa_msg_t *msg);
163
164/**
Mingyang Sunb26b2802021-07-07 11:25:00 +0800165 * \brief Function body of \ref psa_read.
166 *
167 * \param[in] msg_handle Handle for the client's message.
168 * \param[in] invec_idx Index of the input vector to read from. Must be
169 * less than \ref PSA_MAX_IOVEC.
170 * \param[out] buffer Buffer in the Secure Partition to copy the
171 * requested data to.
172 * \param[in] num_bytes Maximum number of bytes to be read from the
173 * client input vector.
174 *
175 * \retval >0 Number of bytes copied.
176 * \retval 0 There was no remaining data in this input
177 * vector.
178 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
179 * following are true:
180 * \arg msg_handle is invalid.
181 * \arg msg_handle does not refer to a
182 * \ref PSA_IPC_CALL message.
183 * \arg invec_idx is equal to or greater than
184 * \ref PSA_MAX_IOVEC.
185 * \arg the memory reference for buffer is invalid or
186 * not writable.
187 */
188size_t tfm_spm_partition_psa_read(psa_handle_t msg_handle, uint32_t invec_idx,
189 void *buffer, size_t num_bytes);
190
191/**
192 * \brief Function body of psa_skip.
193 *
194 * \param[in] msg_handle Handle for the client's message.
195 * \param[in] invec_idx Index of input vector to skip from. Must be
196 * less than \ref PSA_MAX_IOVEC.
197 * \param[in] num_bytes Maximum number of bytes to skip in the client
198 * input vector.
199 *
200 * \retval >0 Number of bytes skipped.
201 * \retval 0 There was no remaining data in this input
202 * vector.
203 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
204 * following are true:
205 * \arg msg_handle is invalid.
206 * \arg msg_handle does not refer to a request
207 * message.
208 * \arg invec_idx is equal to or greater than
209 * \ref PSA_MAX_IOVEC.
210 */
211size_t tfm_spm_partition_psa_skip(psa_handle_t msg_handle, uint32_t invec_idx,
212 size_t num_bytes);
213
214/**
215 * \brief Function body of \ref psa_write.
216 *
217 * \param[in] msg_handle Handle for the client's message.
218 * \param[out] outvec_idx Index of output vector in message to write to.
219 * Must be less than \ref PSA_MAX_IOVEC.
220 * \param[in] buffer Buffer with the data to write.
221 * \param[in] num_bytes Number of bytes to write to the client output
222 * vector.
223 *
224 * \retval void Success
225 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
226 * following are true:
227 * \arg msg_handle is invalid.
228 * \arg msg_handle does not refer to a request
229 * message.
230 * \arg outvec_idx is equal to or greater than
231 * \ref PSA_MAX_IOVEC.
232 * \arg The memory reference for buffer is invalid.
233 * \arg The call attempts to write data past the end
234 * of the client output vector.
235 */
236void tfm_spm_partition_psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
237 const void *buffer, size_t num_bytes);
238
239/**
240 * \brief Function body of \ref psa_reply.
241 *
242 * \param[in] msg_handle Handle for the client's message.
243 * \param[in] status Message result value to be reported to the
244 * client.
245 *
Ken Liuf39d8eb2021-10-07 12:55:33 +0800246 * \retval Positive integer Success, the connection handle.
247 * \retval PSA_SUCCESS Success
Mingyang Sunb26b2802021-07-07 11:25:00 +0800248 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
249 * following are true:
250 * \arg msg_handle is invalid.
251 * \arg An invalid status code is specified for the
252 * type of message.
253 */
Ken Liuf39d8eb2021-10-07 12:55:33 +0800254int32_t tfm_spm_partition_psa_reply(psa_handle_t msg_handle,
255 psa_status_t status);
Mingyang Sunb26b2802021-07-07 11:25:00 +0800256
257/**
258 * \brief Function body of \ref psa_norify.
259 *
260 * \param[in] partition_id Secure Partition ID of the target partition.
261 *
262 * \retval void Success.
263 * \retval "PROGRAMMER ERROR" partition_id does not correspond to a Secure
264 * Partition.
265 */
266void tfm_spm_partition_psa_notify(int32_t partition_id);
267
268/**
269 * \brief Function body of \ref psa_clear.
270 *
271 * \retval void Success.
272 * \retval "PROGRAMMER ERROR" The Secure Partition's doorbell signal is not
273 * currently asserted.
274 */
275void tfm_spm_partition_psa_clear(void);
276
277/**
278 * \brief Function body of \ref psa_eoi.
279 *
280 * \param[in] irq_signal The interrupt signal that has been processed.
281 *
282 * \retval void Success.
283 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
284 * following are true:
285 * \arg irq_signal is not an interrupt signal.
286 * \arg irq_signal indicates more than one signal.
287 * \arg irq_signal is not currently asserted.
288 * \arg The interrupt is not using SLIH.
289 */
290void tfm_spm_partition_psa_eoi(psa_signal_t irq_signal);
291
292/**
293 * \brief Function body of \ref psa_panic.
294 *
295 * \retval "Does not return"
296 */
297void tfm_spm_partition_psa_panic(void);
298
299/**
300 * \brief Function body of \ref psa_irq_enable.
301 *
302 * \param[in] irq_signal The signal for the interrupt to be enabled.
303 * This must have a single bit set, which must be the
304 * signal value for an interrupt in the calling Secure
305 * Partition.
306 *
307 * \retval void
308 * \retval "PROGRAMMER ERROR" If one or more of the following are true:
309 * \arg \a irq_signal is not an interrupt signal.
310 * \arg \a irq_signal indicates more than one signal.
311 */
Kevin Peng67a89fd2021-11-25 11:22:02 +0800312void tfm_spm_partition_psa_irq_enable(psa_signal_t irq_signal);
Mingyang Sunb26b2802021-07-07 11:25:00 +0800313
314/**
315 * \brief Function body of psa_irq_disable.
316 *
317 * \param[in] irq_signal The signal for the interrupt to be disabled.
318 * This must have a single bit set, which must be the
319 * signal value for an interrupt in the calling Secure
320 * Partition.
321 *
322 * \retval 0 The interrupt was disabled prior to this call.
323 * 1 The interrupt was enabled prior to this call.
324 * \retval "PROGRAMMER ERROR" If one or more of the following are true:
325 * \arg \a irq_signal is not an interrupt signal.
326 * \arg \a irq_signal indicates more than one signal.
327 *
328 * \note The current implementation always return 1. Do not use the return.
329 */
Kevin Peng67a89fd2021-11-25 11:22:02 +0800330psa_irq_status_t tfm_spm_partition_psa_irq_disable(psa_signal_t irq_signal);
Mingyang Sunb26b2802021-07-07 11:25:00 +0800331
332/**
333 * \brief Function body of \ref psa_reset_signal.
334 *
335 * \param[in] irq_signal The interrupt signal to be reset.
336 * This must have a single bit set, corresponding to a
337 * currently asserted signal for an interrupt that is
338 * defined to use FLIH handling.
339 *
340 * \retval void
341 * \retval "Programmer Error" if one or more of the following are true:
342 * \arg \a irq_signal is not a signal for an interrupt
343 * that is specified with FLIH handling in the Secure
344 * Partition manifest.
345 * \arg \a irq_signal indicates more than one signal.
346 * \arg \a irq_signal is not currently asserted.
347 */
348void tfm_spm_partition_psa_reset_signal(psa_signal_t irq_signal);
349
Xinyu Zhang2bc4d572021-12-27 16:37:46 +0800350/* psa_set_rhandle is only needed by connection-based services */
351#if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1
352
353/**
354 * \brief Function body of \ref psa_set_rhandle.
355 *
356 * \param[in] msg_handle Handle for the client's message.
357 * \param[in] rhandle Reverse handle allocated by the RoT Service.
358 *
359 * \retval void Success, rhandle will be provided with all
360 * subsequent messages delivered on this
361 * connection.
362 * \retval "PROGRAMMER ERROR" msg_handle is invalid.
363 */
364void tfm_spm_partition_psa_set_rhandle(psa_handle_t msg_handle, void *rhandle);
365
366#endif /* CONFIG_TFM_CONNECTION_BASED_SERVICE_API */
367
Shawn Shan038348e2021-09-08 17:11:04 +0800368#if PSA_FRAMEWORK_HAS_MM_IOVEC
369
370/**
371 * \brief Function body of psa_map_invec.
372 */
373const void *tfm_spm_partition_psa_map_invec(psa_handle_t msg_handle,
374 uint32_t invec_idx);
375
376/**
377 * \brief Function body of psa_unmap_invec.
378 */
379void tfm_spm_partition_psa_unmap_invec(psa_handle_t msg_handle,
380 uint32_t invec_idx);
381
382/**
383 * \brief Function body of psa_map_outvet.
384 */
385void *tfm_spm_partition_psa_map_outvec(psa_handle_t msg_handle,
386 uint32_t outvec_idx);
387
388/**
389 * \brief Function body of psa_unmap_outvec.
390 */
391void tfm_spm_partition_psa_unmap_outvec(psa_handle_t msg_handle,
392 uint32_t outvec_idx, size_t len);
393
394#endif /* PSA_FRAMEWORK_HAS_MM_IOVEC */
395
Mingyang Sun133a7922021-07-08 16:01:26 +0800396#endif /* __PSA_API_H__ */