blob: 0322fa9624bda56a959a15f6975d2fe84ec73549 [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
Mingyang Sun4609ac72022-02-08 18:56:35 +0800143/* This API is only used in IPC backend. */
144#if CONFIG_TFM_SPM_BACKEND_IPC == 1
Mingyang Sunb26b2802021-07-07 11:25:00 +0800145/**
146 * \brief Function body of \ref psa_get.
147 *
148 * \param[in] signal The signal value for an asserted RoT Service.
149 * \param[out] msg Pointer to \ref psa_msg_t object for receiving
150 * the message.
151 *
152 * \retval PSA_SUCCESS Success, *msg will contain the delivered
153 * message.
154 * \retval PSA_ERROR_DOES_NOT_EXIST Message could not be delivered.
155 * \retval "PROGRAMMER ERROR" The call is invalid because one or more of the
156 * following are true:
157 * \arg signal has more than a single bit set.
158 * \arg signal does not correspond to an RoT Service.
159 * \arg The RoT Service signal is not currently
160 * asserted.
161 * \arg The msg pointer provided is not a valid memory
162 * reference.
163 */
164psa_status_t tfm_spm_partition_psa_get(psa_signal_t signal, psa_msg_t *msg);
Mingyang Sun4609ac72022-02-08 18:56:35 +0800165#endif
Mingyang Sunb26b2802021-07-07 11:25:00 +0800166
167/**
Mingyang Sunb26b2802021-07-07 11:25:00 +0800168 * \brief Function body of \ref psa_read.
169 *
170 * \param[in] msg_handle Handle for the client's message.
171 * \param[in] invec_idx Index of the input vector to read from. Must be
172 * less than \ref PSA_MAX_IOVEC.
173 * \param[out] buffer Buffer in the Secure Partition to copy the
174 * requested data to.
175 * \param[in] num_bytes Maximum number of bytes to be read from the
176 * client input vector.
177 *
178 * \retval >0 Number of bytes copied.
179 * \retval 0 There was no remaining data in this input
180 * vector.
181 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
182 * following are true:
183 * \arg msg_handle is invalid.
184 * \arg msg_handle does not refer to a
185 * \ref PSA_IPC_CALL message.
186 * \arg invec_idx is equal to or greater than
187 * \ref PSA_MAX_IOVEC.
188 * \arg the memory reference for buffer is invalid or
189 * not writable.
190 */
191size_t tfm_spm_partition_psa_read(psa_handle_t msg_handle, uint32_t invec_idx,
192 void *buffer, size_t num_bytes);
193
194/**
195 * \brief Function body of psa_skip.
196 *
197 * \param[in] msg_handle Handle for the client's message.
198 * \param[in] invec_idx Index of input vector to skip from. Must be
199 * less than \ref PSA_MAX_IOVEC.
200 * \param[in] num_bytes Maximum number of bytes to skip in the client
201 * input vector.
202 *
203 * \retval >0 Number of bytes skipped.
204 * \retval 0 There was no remaining data in this input
205 * vector.
206 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
207 * following are true:
208 * \arg msg_handle is invalid.
209 * \arg msg_handle does not refer to a request
210 * message.
211 * \arg invec_idx is equal to or greater than
212 * \ref PSA_MAX_IOVEC.
213 */
214size_t tfm_spm_partition_psa_skip(psa_handle_t msg_handle, uint32_t invec_idx,
215 size_t num_bytes);
216
217/**
218 * \brief Function body of \ref psa_write.
219 *
220 * \param[in] msg_handle Handle for the client's message.
221 * \param[out] outvec_idx Index of output vector in message to write to.
222 * Must be less than \ref PSA_MAX_IOVEC.
223 * \param[in] buffer Buffer with the data to write.
224 * \param[in] num_bytes Number of bytes to write to the client output
225 * vector.
226 *
227 * \retval void Success
228 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
229 * following are true:
230 * \arg msg_handle is invalid.
231 * \arg msg_handle does not refer to a request
232 * message.
233 * \arg outvec_idx is equal to or greater than
234 * \ref PSA_MAX_IOVEC.
235 * \arg The memory reference for buffer is invalid.
236 * \arg The call attempts to write data past the end
237 * of the client output vector.
238 */
239void tfm_spm_partition_psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
240 const void *buffer, size_t num_bytes);
241
242/**
243 * \brief Function body of \ref psa_reply.
244 *
245 * \param[in] msg_handle Handle for the client's message.
246 * \param[in] status Message result value to be reported to the
247 * client.
248 *
Ken Liuf39d8eb2021-10-07 12:55:33 +0800249 * \retval Positive integer Success, the connection handle.
250 * \retval PSA_SUCCESS Success
Mingyang Sunb26b2802021-07-07 11:25:00 +0800251 * \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 */
Ken Liuf39d8eb2021-10-07 12:55:33 +0800257int32_t tfm_spm_partition_psa_reply(psa_handle_t msg_handle,
258 psa_status_t status);
Mingyang Sunb26b2802021-07-07 11:25:00 +0800259
260/**
261 * \brief Function body of \ref psa_norify.
262 *
263 * \param[in] partition_id Secure Partition ID of the target partition.
264 *
265 * \retval void Success.
266 * \retval "PROGRAMMER ERROR" partition_id does not correspond to a Secure
267 * Partition.
268 */
269void tfm_spm_partition_psa_notify(int32_t partition_id);
270
271/**
272 * \brief Function body of \ref psa_clear.
273 *
274 * \retval void Success.
275 * \retval "PROGRAMMER ERROR" The Secure Partition's doorbell signal is not
276 * currently asserted.
277 */
278void tfm_spm_partition_psa_clear(void);
279
280/**
Mingyang Sunb26b2802021-07-07 11:25:00 +0800281 * \brief Function body of \ref psa_panic.
282 *
283 * \retval "Does not return"
284 */
285void tfm_spm_partition_psa_panic(void);
286
Mingyang Suned5fe7b2022-02-10 17:33:21 +0800287/* psa_set_rhandle is only needed by connection-based services */
288#if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1
289
290/**
291 * \brief Function body of \ref psa_set_rhandle.
292 *
293 * \param[in] msg_handle Handle for the client's message.
294 * \param[in] rhandle Reverse handle allocated by the RoT Service.
295 *
296 * \retval void Success, rhandle will be provided with all
297 * subsequent messages delivered on this
298 * connection.
299 * \retval "PROGRAMMER ERROR" msg_handle is invalid.
300 */
301void tfm_spm_partition_psa_set_rhandle(psa_handle_t msg_handle, void *rhandle);
302
303#endif /* CONFIG_TFM_CONNECTION_BASED_SERVICE_API */
304
305#if CONFIG_TFM_FLIH_API == 1 || CONFIG_TFM_SLIH_API == 1
Mingyang Sunb26b2802021-07-07 11:25:00 +0800306/**
307 * \brief Function body of \ref psa_irq_enable.
308 *
309 * \param[in] irq_signal The signal for the interrupt to be enabled.
310 * This must have a single bit set, which must be the
311 * signal value for an interrupt in the calling Secure
312 * Partition.
313 *
314 * \retval void
315 * \retval "PROGRAMMER ERROR" If one or more of the following are true:
316 * \arg \a irq_signal is not an interrupt signal.
317 * \arg \a irq_signal indicates more than one signal.
318 */
Kevin Peng67a89fd2021-11-25 11:22:02 +0800319void tfm_spm_partition_psa_irq_enable(psa_signal_t irq_signal);
Mingyang Sunb26b2802021-07-07 11:25:00 +0800320
321/**
322 * \brief Function body of psa_irq_disable.
323 *
324 * \param[in] irq_signal The signal for the interrupt to be disabled.
325 * This must have a single bit set, which must be the
326 * signal value for an interrupt in the calling Secure
327 * Partition.
328 *
329 * \retval 0 The interrupt was disabled prior to this call.
330 * 1 The interrupt was enabled prior to this call.
331 * \retval "PROGRAMMER ERROR" If one or more of the following are true:
332 * \arg \a irq_signal is not an interrupt signal.
333 * \arg \a irq_signal indicates more than one signal.
334 *
335 * \note The current implementation always return 1. Do not use the return.
336 */
Kevin Peng67a89fd2021-11-25 11:22:02 +0800337psa_irq_status_t tfm_spm_partition_psa_irq_disable(psa_signal_t irq_signal);
Mingyang Sunb26b2802021-07-07 11:25:00 +0800338
Mingyang Suned5fe7b2022-02-10 17:33:21 +0800339/* This API is only used for FLIH. */
340#if CONFIG_TFM_FLIH_API == 1
Mingyang Sunb26b2802021-07-07 11:25:00 +0800341/**
342 * \brief Function body of \ref psa_reset_signal.
343 *
344 * \param[in] irq_signal The interrupt signal to be reset.
345 * This must have a single bit set, corresponding to a
346 * currently asserted signal for an interrupt that is
347 * defined to use FLIH handling.
348 *
349 * \retval void
350 * \retval "Programmer Error" if one or more of the following are true:
351 * \arg \a irq_signal is not a signal for an interrupt
352 * that is specified with FLIH handling in the Secure
353 * Partition manifest.
354 * \arg \a irq_signal indicates more than one signal.
355 * \arg \a irq_signal is not currently asserted.
356 */
357void tfm_spm_partition_psa_reset_signal(psa_signal_t irq_signal);
Mingyang Suned5fe7b2022-02-10 17:33:21 +0800358#endif
Mingyang Sunb26b2802021-07-07 11:25:00 +0800359
Mingyang Suned5fe7b2022-02-10 17:33:21 +0800360/* This API is only used for SLIH. */
361#if CONFIG_TFM_SLIH_API == 1
Xinyu Zhang2bc4d572021-12-27 16:37:46 +0800362/**
Mingyang Suned5fe7b2022-02-10 17:33:21 +0800363 * \brief Function body of \ref psa_eoi.
Xinyu Zhang2bc4d572021-12-27 16:37:46 +0800364 *
Mingyang Suned5fe7b2022-02-10 17:33:21 +0800365 * \param[in] irq_signal The interrupt signal that has been processed.
Xinyu Zhang2bc4d572021-12-27 16:37:46 +0800366 *
Mingyang Suned5fe7b2022-02-10 17:33:21 +0800367 * \retval void Success.
368 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
369 * following are true:
370 * \arg irq_signal is not an interrupt signal.
371 * \arg irq_signal indicates more than one signal.
372 * \arg irq_signal is not currently asserted.
373 * \arg The interrupt is not using SLIH.
Xinyu Zhang2bc4d572021-12-27 16:37:46 +0800374 */
Mingyang Suned5fe7b2022-02-10 17:33:21 +0800375void tfm_spm_partition_psa_eoi(psa_signal_t irq_signal);
376#endif
377#endif /* CONFIG_TFM_FLIH_API == 1 || CONFIG_TFM_SLIH_API == 1 */
Xinyu Zhang2bc4d572021-12-27 16:37:46 +0800378
Shawn Shan038348e2021-09-08 17:11:04 +0800379#if PSA_FRAMEWORK_HAS_MM_IOVEC
380
381/**
382 * \brief Function body of psa_map_invec.
383 */
384const void *tfm_spm_partition_psa_map_invec(psa_handle_t msg_handle,
385 uint32_t invec_idx);
386
387/**
388 * \brief Function body of psa_unmap_invec.
389 */
390void tfm_spm_partition_psa_unmap_invec(psa_handle_t msg_handle,
391 uint32_t invec_idx);
392
393/**
394 * \brief Function body of psa_map_outvet.
395 */
396void *tfm_spm_partition_psa_map_outvec(psa_handle_t msg_handle,
397 uint32_t outvec_idx);
398
399/**
400 * \brief Function body of psa_unmap_outvec.
401 */
402void tfm_spm_partition_psa_unmap_outvec(psa_handle_t msg_handle,
403 uint32_t outvec_idx, size_t len);
404
405#endif /* PSA_FRAMEWORK_HAS_MM_IOVEC */
406
Mingyang Sun133a7922021-07-08 16:01:26 +0800407#endif /* __PSA_API_H__ */