blob: ded5232040fea57db2cb23e05b6ec7ffb7622c87 [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 *
Ken Liuf39d8eb2021-10-07 12:55:33 +0800250 * \retval Positive integer Success, the connection handle.
251 * \retval PSA_SUCCESS Success
Mingyang Sunb26b2802021-07-07 11:25:00 +0800252 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
253 * following are true:
254 * \arg msg_handle is invalid.
255 * \arg An invalid status code is specified for the
256 * type of message.
257 */
Ken Liuf39d8eb2021-10-07 12:55:33 +0800258int32_t tfm_spm_partition_psa_reply(psa_handle_t msg_handle,
259 psa_status_t status);
Mingyang Sunb26b2802021-07-07 11:25:00 +0800260
261/**
262 * \brief Function body of \ref psa_norify.
263 *
264 * \param[in] partition_id Secure Partition ID of the target partition.
265 *
266 * \retval void Success.
267 * \retval "PROGRAMMER ERROR" partition_id does not correspond to a Secure
268 * Partition.
269 */
270void tfm_spm_partition_psa_notify(int32_t partition_id);
271
272/**
273 * \brief Function body of \ref psa_clear.
274 *
275 * \retval void Success.
276 * \retval "PROGRAMMER ERROR" The Secure Partition's doorbell signal is not
277 * currently asserted.
278 */
279void tfm_spm_partition_psa_clear(void);
280
281/**
282 * \brief Function body of \ref psa_eoi.
283 *
284 * \param[in] irq_signal The interrupt signal that has been processed.
285 *
286 * \retval void Success.
287 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
288 * following are true:
289 * \arg irq_signal is not an interrupt signal.
290 * \arg irq_signal indicates more than one signal.
291 * \arg irq_signal is not currently asserted.
292 * \arg The interrupt is not using SLIH.
293 */
294void tfm_spm_partition_psa_eoi(psa_signal_t irq_signal);
295
296/**
297 * \brief Function body of \ref psa_panic.
298 *
299 * \retval "Does not return"
300 */
301void tfm_spm_partition_psa_panic(void);
302
303/**
304 * \brief Function body of \ref psa_irq_enable.
305 *
306 * \param[in] irq_signal The signal for the interrupt to be enabled.
307 * This must have a single bit set, which must be the
308 * signal value for an interrupt in the calling Secure
309 * Partition.
310 *
311 * \retval void
312 * \retval "PROGRAMMER ERROR" If one or more of the following are true:
313 * \arg \a irq_signal is not an interrupt signal.
314 * \arg \a irq_signal indicates more than one signal.
315 */
Kevin Peng67a89fd2021-11-25 11:22:02 +0800316void tfm_spm_partition_psa_irq_enable(psa_signal_t irq_signal);
Mingyang Sunb26b2802021-07-07 11:25:00 +0800317
318/**
319 * \brief Function body of psa_irq_disable.
320 *
321 * \param[in] irq_signal The signal for the interrupt to be disabled.
322 * This must have a single bit set, which must be the
323 * signal value for an interrupt in the calling Secure
324 * Partition.
325 *
326 * \retval 0 The interrupt was disabled prior to this call.
327 * 1 The interrupt was enabled prior to this call.
328 * \retval "PROGRAMMER ERROR" If one or more of the following are true:
329 * \arg \a irq_signal is not an interrupt signal.
330 * \arg \a irq_signal indicates more than one signal.
331 *
332 * \note The current implementation always return 1. Do not use the return.
333 */
Kevin Peng67a89fd2021-11-25 11:22:02 +0800334psa_irq_status_t tfm_spm_partition_psa_irq_disable(psa_signal_t irq_signal);
Mingyang Sunb26b2802021-07-07 11:25:00 +0800335
336/**
337 * \brief Function body of \ref psa_reset_signal.
338 *
339 * \param[in] irq_signal The interrupt signal to be reset.
340 * This must have a single bit set, corresponding to a
341 * currently asserted signal for an interrupt that is
342 * defined to use FLIH handling.
343 *
344 * \retval void
345 * \retval "Programmer Error" if one or more of the following are true:
346 * \arg \a irq_signal is not a signal for an interrupt
347 * that is specified with FLIH handling in the Secure
348 * Partition manifest.
349 * \arg \a irq_signal indicates more than one signal.
350 * \arg \a irq_signal is not currently asserted.
351 */
352void tfm_spm_partition_psa_reset_signal(psa_signal_t irq_signal);
353
Shawn Shan038348e2021-09-08 17:11:04 +0800354#if PSA_FRAMEWORK_HAS_MM_IOVEC
355
356/**
357 * \brief Function body of psa_map_invec.
358 */
359const void *tfm_spm_partition_psa_map_invec(psa_handle_t msg_handle,
360 uint32_t invec_idx);
361
362/**
363 * \brief Function body of psa_unmap_invec.
364 */
365void tfm_spm_partition_psa_unmap_invec(psa_handle_t msg_handle,
366 uint32_t invec_idx);
367
368/**
369 * \brief Function body of psa_map_outvet.
370 */
371void *tfm_spm_partition_psa_map_outvec(psa_handle_t msg_handle,
372 uint32_t outvec_idx);
373
374/**
375 * \brief Function body of psa_unmap_outvec.
376 */
377void tfm_spm_partition_psa_unmap_outvec(psa_handle_t msg_handle,
378 uint32_t outvec_idx, size_t len);
379
380#endif /* PSA_FRAMEWORK_HAS_MM_IOVEC */
381
Mingyang Sun133a7922021-07-08 16:01:26 +0800382#endif /* __PSA_API_H__ */