blob: 1258c765b4187bbe8e04d5a83fa0c922964d32d5 [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
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/**
62 * \brief handler for \ref psa_connect.
63 *
64 * \param[in] sid RoT Service identity.
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +053065 * \param[in] version The version of the RoT Service.
David Hu733d8f92019-09-23 15:32:40 +080066 *
67 * \retval PSA_SUCCESS Success.
68 * \retval PSA_ERROR_CONNECTION_REFUSED The SPM or RoT Service has refused the
69 * connection.
70 * \retval PSA_ERROR_CONNECTION_BUSY The SPM or RoT Service cannot make the
71 * connection at the moment.
72 * \retval "Does not return" The RoT Service ID and version are not
73 * supported, or the caller is not permitted to
74 * access the service.
75 */
Mingyang Sun22a3faf2021-07-09 15:32:47 +080076psa_status_t tfm_spm_client_psa_connect(uint32_t sid, uint32_t version);
David Hu733d8f92019-09-23 15:32:40 +080077
78/**
79 * \brief handler for \ref psa_call.
80 *
81 * \param[in] handle Service handle to the established connection,
82 * \ref psa_handle_t
Mingyang Suneeca4652021-07-15 15:19:16 +080083 * \param[in] ctrl_param Parameters combined in uint32_t,
84 * includes request type, in_num and out_num.
David Hu733d8f92019-09-23 15:32:40 +080085 * \param[in] inptr Array of input psa_invec structures.
86 * \ref psa_invec
David Hu733d8f92019-09-23 15:32:40 +080087 * \param[in] outptr Array of output psa_outvec structures.
88 * \ref psa_outvec
David Hu733d8f92019-09-23 15:32:40 +080089 *
90 * \retval PSA_SUCCESS Success.
91 * \retval "Does not return" The call is invalid, one or more of the
92 * following are true:
93 * \arg An invalid handle was passed.
94 * \arg The connection is already handling a request.
95 * \arg An invalid memory reference was provided.
96 * \arg in_num + out_num > PSA_MAX_IOVEC.
97 * \arg The message is unrecognized by the RoT
98 * Service or incorrectly formatted.
99 */
Mingyang Suneeca4652021-07-15 15:19:16 +0800100psa_status_t tfm_spm_client_psa_call(psa_handle_t handle,
101 uint32_t ctrl_param,
102 const psa_invec *inptr,
103 psa_outvec *outptr);
David Hu733d8f92019-09-23 15:32:40 +0800104
105/**
106 * \brief handler for \ref psa_close.
107 *
108 * \param[in] handle Service handle to the connection to be closed,
109 * \ref psa_handle_t
David Hu733d8f92019-09-23 15:32:40 +0800110 *
Xinyu Zhangb287ef82021-11-03 18:38:50 +0800111 * \retval PSA_SUCCESS Success.
112 * \retval PSA_ERROR_PROGRAMMER_ERROR The call is invalid, one or more of the
David Hu733d8f92019-09-23 15:32:40 +0800113 * following are true:
Xinyu Zhangb287ef82021-11-03 18:38:50 +0800114 * \arg Called with a stateless handle.
David Hu733d8f92019-09-23 15:32:40 +0800115 * \arg An invalid handle was provided that is not
116 * the null handle.
117 * \arg The connection is handling a request.
118 */
Xinyu Zhangb287ef82021-11-03 18:38:50 +0800119psa_status_t tfm_spm_client_psa_close(psa_handle_t handle);
David Hu733d8f92019-09-23 15:32:40 +0800120
Mingyang Sunb26b2802021-07-07 11:25:00 +0800121/* PSA Partition API function body, for privileged use only. */
122
123/**
124 * \brief Function body of \ref psa_wait.
125 *
126 * \param[in] signal_mask A set of signals to query. Signals that are not
127 * in this set will be ignored.
128 * \param[in] timeout Specify either blocking \ref PSA_BLOCK or
129 * polling \ref PSA_POLL operation.
130 *
131 * \retval >0 At least one signal is asserted.
132 * \retval 0 No signals are asserted. This is only seen when
133 * a polling timeout is used.
134 */
135psa_signal_t tfm_spm_partition_psa_wait(psa_signal_t signal_mask,
136 uint32_t timeout);
137
138/**
139 * \brief Function body of \ref psa_get.
140 *
141 * \param[in] signal The signal value for an asserted RoT Service.
142 * \param[out] msg Pointer to \ref psa_msg_t object for receiving
143 * the message.
144 *
145 * \retval PSA_SUCCESS Success, *msg will contain the delivered
146 * message.
147 * \retval PSA_ERROR_DOES_NOT_EXIST Message could not be delivered.
148 * \retval "PROGRAMMER ERROR" The call is invalid because one or more of the
149 * following are true:
150 * \arg signal has more than a single bit set.
151 * \arg signal does not correspond to an RoT Service.
152 * \arg The RoT Service signal is not currently
153 * asserted.
154 * \arg The msg pointer provided is not a valid memory
155 * reference.
156 */
157psa_status_t tfm_spm_partition_psa_get(psa_signal_t signal, psa_msg_t *msg);
158
159/**
160 * \brief Function body of \ref psa_set_rhandle.
161 *
162 * \param[in] msg_handle Handle for the client's message.
163 * \param[in] rhandle Reverse handle allocated by the RoT Service.
164 *
165 * \retval void Success, rhandle will be provided with all
166 * subsequent messages delivered on this
167 * connection.
168 * \retval "PROGRAMMER ERROR" msg_handle is invalid.
169 */
170void tfm_spm_partition_psa_set_rhandle(psa_handle_t msg_handle, void *rhandle);
171
172/**
173 * \brief Function body of \ref psa_read.
174 *
175 * \param[in] msg_handle Handle for the client's message.
176 * \param[in] invec_idx Index of the input vector to read from. Must be
177 * less than \ref PSA_MAX_IOVEC.
178 * \param[out] buffer Buffer in the Secure Partition to copy the
179 * requested data to.
180 * \param[in] num_bytes Maximum number of bytes to be read from the
181 * client input vector.
182 *
183 * \retval >0 Number of bytes copied.
184 * \retval 0 There was no remaining data in this input
185 * vector.
186 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
187 * following are true:
188 * \arg msg_handle is invalid.
189 * \arg msg_handle does not refer to a
190 * \ref PSA_IPC_CALL message.
191 * \arg invec_idx is equal to or greater than
192 * \ref PSA_MAX_IOVEC.
193 * \arg the memory reference for buffer is invalid or
194 * not writable.
195 */
196size_t tfm_spm_partition_psa_read(psa_handle_t msg_handle, uint32_t invec_idx,
197 void *buffer, size_t num_bytes);
198
199/**
200 * \brief Function body of psa_skip.
201 *
202 * \param[in] msg_handle Handle for the client's message.
203 * \param[in] invec_idx Index of input vector to skip from. Must be
204 * less than \ref PSA_MAX_IOVEC.
205 * \param[in] num_bytes Maximum number of bytes to skip in the client
206 * input vector.
207 *
208 * \retval >0 Number of bytes skipped.
209 * \retval 0 There was no remaining data in this input
210 * vector.
211 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
212 * following are true:
213 * \arg msg_handle is invalid.
214 * \arg msg_handle does not refer to a request
215 * message.
216 * \arg invec_idx is equal to or greater than
217 * \ref PSA_MAX_IOVEC.
218 */
219size_t tfm_spm_partition_psa_skip(psa_handle_t msg_handle, uint32_t invec_idx,
220 size_t num_bytes);
221
222/**
223 * \brief Function body of \ref psa_write.
224 *
225 * \param[in] msg_handle Handle for the client's message.
226 * \param[out] outvec_idx Index of output vector in message to write to.
227 * Must be less than \ref PSA_MAX_IOVEC.
228 * \param[in] buffer Buffer with the data to write.
229 * \param[in] num_bytes Number of bytes to write to the client output
230 * vector.
231 *
232 * \retval void Success
233 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
234 * following are true:
235 * \arg msg_handle is invalid.
236 * \arg msg_handle does not refer to a request
237 * message.
238 * \arg outvec_idx is equal to or greater than
239 * \ref PSA_MAX_IOVEC.
240 * \arg The memory reference for buffer is invalid.
241 * \arg The call attempts to write data past the end
242 * of the client output vector.
243 */
244void tfm_spm_partition_psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
245 const void *buffer, size_t num_bytes);
246
247/**
248 * \brief Function body of \ref psa_reply.
249 *
250 * \param[in] msg_handle Handle for the client's message.
251 * \param[in] status Message result value to be reported to the
252 * client.
253 *
Ken Liuf39d8eb2021-10-07 12:55:33 +0800254 * \retval Positive integer Success, the connection handle.
255 * \retval PSA_SUCCESS Success
Mingyang Sunb26b2802021-07-07 11:25:00 +0800256 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
257 * following are true:
258 * \arg msg_handle is invalid.
259 * \arg An invalid status code is specified for the
260 * type of message.
261 */
Ken Liuf39d8eb2021-10-07 12:55:33 +0800262int32_t tfm_spm_partition_psa_reply(psa_handle_t msg_handle,
263 psa_status_t status);
Mingyang Sunb26b2802021-07-07 11:25:00 +0800264
265/**
266 * \brief Function body of \ref psa_norify.
267 *
268 * \param[in] partition_id Secure Partition ID of the target partition.
269 *
270 * \retval void Success.
271 * \retval "PROGRAMMER ERROR" partition_id does not correspond to a Secure
272 * Partition.
273 */
274void tfm_spm_partition_psa_notify(int32_t partition_id);
275
276/**
277 * \brief Function body of \ref psa_clear.
278 *
279 * \retval void Success.
280 * \retval "PROGRAMMER ERROR" The Secure Partition's doorbell signal is not
281 * currently asserted.
282 */
283void tfm_spm_partition_psa_clear(void);
284
285/**
286 * \brief Function body of \ref psa_eoi.
287 *
288 * \param[in] irq_signal The interrupt signal that has been processed.
289 *
290 * \retval void Success.
291 * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the
292 * following are true:
293 * \arg irq_signal is not an interrupt signal.
294 * \arg irq_signal indicates more than one signal.
295 * \arg irq_signal is not currently asserted.
296 * \arg The interrupt is not using SLIH.
297 */
298void tfm_spm_partition_psa_eoi(psa_signal_t irq_signal);
299
300/**
301 * \brief Function body of \ref psa_panic.
302 *
303 * \retval "Does not return"
304 */
305void tfm_spm_partition_psa_panic(void);
306
307/**
308 * \brief Function body of \ref psa_irq_enable.
309 *
310 * \param[in] irq_signal The signal for the interrupt to be enabled.
311 * This must have a single bit set, which must be the
312 * signal value for an interrupt in the calling Secure
313 * Partition.
314 *
315 * \retval void
316 * \retval "PROGRAMMER ERROR" If one or more of the following are true:
317 * \arg \a irq_signal is not an interrupt signal.
318 * \arg \a irq_signal indicates more than one signal.
319 */
Kevin Peng67a89fd2021-11-25 11:22:02 +0800320void tfm_spm_partition_psa_irq_enable(psa_signal_t irq_signal);
Mingyang Sunb26b2802021-07-07 11:25:00 +0800321
322/**
323 * \brief Function body of psa_irq_disable.
324 *
325 * \param[in] irq_signal The signal for the interrupt to be disabled.
326 * This must have a single bit set, which must be the
327 * signal value for an interrupt in the calling Secure
328 * Partition.
329 *
330 * \retval 0 The interrupt was disabled prior to this call.
331 * 1 The interrupt was enabled prior to this call.
332 * \retval "PROGRAMMER ERROR" If one or more of the following are true:
333 * \arg \a irq_signal is not an interrupt signal.
334 * \arg \a irq_signal indicates more than one signal.
335 *
336 * \note The current implementation always return 1. Do not use the return.
337 */
Kevin Peng67a89fd2021-11-25 11:22:02 +0800338psa_irq_status_t tfm_spm_partition_psa_irq_disable(psa_signal_t irq_signal);
Mingyang Sunb26b2802021-07-07 11:25:00 +0800339
340/**
341 * \brief Function body of \ref psa_reset_signal.
342 *
343 * \param[in] irq_signal The interrupt signal to be reset.
344 * This must have a single bit set, corresponding to a
345 * currently asserted signal for an interrupt that is
346 * defined to use FLIH handling.
347 *
348 * \retval void
349 * \retval "Programmer Error" if one or more of the following are true:
350 * \arg \a irq_signal is not a signal for an interrupt
351 * that is specified with FLIH handling in the Secure
352 * Partition manifest.
353 * \arg \a irq_signal indicates more than one signal.
354 * \arg \a irq_signal is not currently asserted.
355 */
356void tfm_spm_partition_psa_reset_signal(psa_signal_t irq_signal);
357
Shawn Shan038348e2021-09-08 17:11:04 +0800358#if PSA_FRAMEWORK_HAS_MM_IOVEC
359
360/**
361 * \brief Function body of psa_map_invec.
362 */
363const void *tfm_spm_partition_psa_map_invec(psa_handle_t msg_handle,
364 uint32_t invec_idx);
365
366/**
367 * \brief Function body of psa_unmap_invec.
368 */
369void tfm_spm_partition_psa_unmap_invec(psa_handle_t msg_handle,
370 uint32_t invec_idx);
371
372/**
373 * \brief Function body of psa_map_outvet.
374 */
375void *tfm_spm_partition_psa_map_outvec(psa_handle_t msg_handle,
376 uint32_t outvec_idx);
377
378/**
379 * \brief Function body of psa_unmap_outvec.
380 */
381void tfm_spm_partition_psa_unmap_outvec(psa_handle_t msg_handle,
382 uint32_t outvec_idx, size_t len);
383
384#endif /* PSA_FRAMEWORK_HAS_MM_IOVEC */
385
Mingyang Sun133a7922021-07-08 16:01:26 +0800386#endif /* __PSA_API_H__ */