David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 1 | /* |
Xinyu Zhang | 2bc4d57 | 2021-12-27 16:37:46 +0800 | [diff] [blame^] | 2 | * Copyright (c) 2019-2022, Arm Limited. All rights reserved. |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
Mingyang Sun | 133a792 | 2021-07-08 16:01:26 +0800 | [diff] [blame] | 8 | #ifndef __PSA_API_H__ |
| 9 | #define __PSA_API_H__ |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 10 | |
| 11 | #include <stdint.h> |
Mingyang Sun | 7397b4f | 2020-06-17 15:07:45 +0800 | [diff] [blame] | 12 | #include <stdbool.h> |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 13 | #include "psa/client.h" |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 14 | #include "psa/service.h" |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 15 | |
Xinyu Zhang | b287ef8 | 2021-11-03 18:38:50 +0800 | [diff] [blame] | 16 | /** |
| 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 | */ |
| 27 | void spm_handle_programmer_errors(psa_status_t status); |
Shawn Shan | b222d89 | 2021-01-04 17:41:48 +0800 | [diff] [blame] | 28 | |
Mingyang Sun | eeca465 | 2021-07-15 15:19:16 +0800 | [diff] [blame] | 29 | /** |
| 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 | */ |
| 38 | uint32_t tfm_spm_get_lifecycle_state(void); |
| 39 | |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 40 | /* PSA Client API function body, for privileged use only. */ |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 41 | |
| 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 Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 48 | uint32_t tfm_spm_client_psa_framework_version(void); |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * \brief handler for \ref psa_version. |
| 52 | * |
| 53 | * \param[in] sid RoT Service identity. |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 54 | * |
| 55 | * \retval PSA_VERSION_NONE The RoT Service is not implemented, or the |
| 56 | * caller is not permitted to access the service. |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame] | 57 | * \retval > 0 The version of the implemented RoT Service. |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 58 | */ |
Mingyang Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 59 | uint32_t tfm_spm_client_psa_version(uint32_t sid); |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 60 | |
| 61 | /** |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 62 | * \brief handler for \ref psa_call. |
| 63 | * |
| 64 | * \param[in] handle Service handle to the established connection, |
| 65 | * \ref psa_handle_t |
Mingyang Sun | eeca465 | 2021-07-15 15:19:16 +0800 | [diff] [blame] | 66 | * \param[in] ctrl_param Parameters combined in uint32_t, |
| 67 | * includes request type, in_num and out_num. |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 68 | * \param[in] inptr Array of input psa_invec structures. |
| 69 | * \ref psa_invec |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 70 | * \param[in] outptr Array of output psa_outvec structures. |
| 71 | * \ref psa_outvec |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 72 | * |
| 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 Sun | eeca465 | 2021-07-15 15:19:16 +0800 | [diff] [blame] | 83 | psa_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 Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 87 | |
Xinyu Zhang | 2bc4d57 | 2021-12-27 16:37:46 +0800 | [diff] [blame^] | 88 | /* 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 | */ |
| 106 | psa_status_t tfm_spm_client_psa_connect(uint32_t sid, uint32_t version); |
| 107 | |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 108 | /** |
| 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 Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 113 | * |
Xinyu Zhang | b287ef8 | 2021-11-03 18:38:50 +0800 | [diff] [blame] | 114 | * \retval PSA_SUCCESS Success. |
| 115 | * \retval PSA_ERROR_PROGRAMMER_ERROR The call is invalid, one or more of the |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 116 | * following are true: |
Xinyu Zhang | b287ef8 | 2021-11-03 18:38:50 +0800 | [diff] [blame] | 117 | * \arg Called with a stateless handle. |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 118 | * \arg An invalid handle was provided that is not |
| 119 | * the null handle. |
| 120 | * \arg The connection is handling a request. |
| 121 | */ |
Xinyu Zhang | b287ef8 | 2021-11-03 18:38:50 +0800 | [diff] [blame] | 122 | psa_status_t tfm_spm_client_psa_close(psa_handle_t handle); |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 123 | |
Xinyu Zhang | 2bc4d57 | 2021-12-27 16:37:46 +0800 | [diff] [blame^] | 124 | #endif /* CONFIG_TFM_CONNECTION_BASED_SERVICE_API */ |
| 125 | |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 126 | /* 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 | */ |
| 140 | psa_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 | */ |
| 162 | psa_status_t tfm_spm_partition_psa_get(psa_signal_t signal, psa_msg_t *msg); |
| 163 | |
| 164 | /** |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 165 | * \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 | */ |
| 188 | size_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 | */ |
| 211 | size_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 | */ |
| 236 | void 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 Liu | f39d8eb | 2021-10-07 12:55:33 +0800 | [diff] [blame] | 246 | * \retval Positive integer Success, the connection handle. |
| 247 | * \retval PSA_SUCCESS Success |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 248 | * \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 Liu | f39d8eb | 2021-10-07 12:55:33 +0800 | [diff] [blame] | 254 | int32_t tfm_spm_partition_psa_reply(psa_handle_t msg_handle, |
| 255 | psa_status_t status); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 256 | |
| 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 | */ |
| 266 | void 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 | */ |
| 275 | void 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 | */ |
| 290 | void 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 | */ |
| 297 | void 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 Peng | 67a89fd | 2021-11-25 11:22:02 +0800 | [diff] [blame] | 312 | void tfm_spm_partition_psa_irq_enable(psa_signal_t irq_signal); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 313 | |
| 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 Peng | 67a89fd | 2021-11-25 11:22:02 +0800 | [diff] [blame] | 330 | psa_irq_status_t tfm_spm_partition_psa_irq_disable(psa_signal_t irq_signal); |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 331 | |
| 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 | */ |
| 348 | void tfm_spm_partition_psa_reset_signal(psa_signal_t irq_signal); |
| 349 | |
Xinyu Zhang | 2bc4d57 | 2021-12-27 16:37:46 +0800 | [diff] [blame^] | 350 | /* 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 | */ |
| 364 | void tfm_spm_partition_psa_set_rhandle(psa_handle_t msg_handle, void *rhandle); |
| 365 | |
| 366 | #endif /* CONFIG_TFM_CONNECTION_BASED_SERVICE_API */ |
| 367 | |
Shawn Shan | 038348e | 2021-09-08 17:11:04 +0800 | [diff] [blame] | 368 | #if PSA_FRAMEWORK_HAS_MM_IOVEC |
| 369 | |
| 370 | /** |
| 371 | * \brief Function body of psa_map_invec. |
| 372 | */ |
| 373 | const 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 | */ |
| 379 | void 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 | */ |
| 385 | void *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 | */ |
| 391 | void 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 Sun | 133a792 | 2021-07-08 16:01:26 +0800 | [diff] [blame] | 396 | #endif /* __PSA_API_H__ */ |