David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 1 | /* |
Shawn Shan | b222d89 | 2021-01-04 17:41:48 +0800 | [diff] [blame] | 2 | * Copyright (c) 2019-2021, 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 | |
Shawn Shan | b222d89 | 2021-01-04 17:41:48 +0800 | [diff] [blame] | 16 | #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 Sun | eeca465 | 2021-07-15 15:19:16 +0800 | [diff] [blame^] | 26 | /** |
| 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 | */ |
| 35 | uint32_t tfm_spm_get_lifecycle_state(void); |
| 36 | |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 37 | /* PSA Client API function body, for privileged use only. */ |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 38 | |
| 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 Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 45 | uint32_t tfm_spm_client_psa_framework_version(void); |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * \brief handler for \ref psa_version. |
| 49 | * |
| 50 | * \param[in] sid RoT Service identity. |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 51 | * |
| 52 | * \retval PSA_VERSION_NONE The RoT Service is not implemented, or the |
| 53 | * caller is not permitted to access the service. |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame] | 54 | * \retval > 0 The version of the implemented RoT Service. |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 55 | */ |
Mingyang Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 56 | uint32_t tfm_spm_client_psa_version(uint32_t sid); |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * \brief handler for \ref psa_connect. |
| 60 | * |
| 61 | * \param[in] sid RoT Service identity. |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame] | 62 | * \param[in] version The version of the RoT Service. |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 63 | * |
| 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 Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 73 | psa_status_t tfm_spm_client_psa_connect(uint32_t sid, uint32_t version); |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 74 | |
| 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 Sun | eeca465 | 2021-07-15 15:19:16 +0800 | [diff] [blame^] | 80 | * \param[in] ctrl_param Parameters combined in uint32_t, |
| 81 | * includes request type, in_num and out_num. |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 82 | * \param[in] inptr Array of input psa_invec structures. |
| 83 | * \ref psa_invec |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 84 | * \param[in] outptr Array of output psa_outvec structures. |
| 85 | * \ref psa_outvec |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 86 | * |
| 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 Sun | eeca465 | 2021-07-15 15:19:16 +0800 | [diff] [blame^] | 97 | psa_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 Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 101 | |
| 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 Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 107 | * |
| 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 Sun | 22a3faf | 2021-07-09 15:32:47 +0800 | [diff] [blame] | 115 | void tfm_spm_client_psa_close(psa_handle_t handle); |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 116 | |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 117 | /* 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 | */ |
| 131 | psa_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 | */ |
| 153 | psa_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 | */ |
| 166 | void 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 | */ |
| 192 | size_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 | */ |
| 215 | size_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 | */ |
| 240 | void 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 | * |
| 250 | * \retval void Success. |
| 251 | * \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 | */ |
| 257 | void tfm_spm_partition_psa_reply(psa_handle_t msg_handle, psa_status_t status); |
| 258 | |
| 259 | /** |
| 260 | * \brief Function body of \ref psa_norify. |
| 261 | * |
| 262 | * \param[in] partition_id Secure Partition ID of the target partition. |
| 263 | * |
| 264 | * \retval void Success. |
| 265 | * \retval "PROGRAMMER ERROR" partition_id does not correspond to a Secure |
| 266 | * Partition. |
| 267 | */ |
| 268 | void tfm_spm_partition_psa_notify(int32_t partition_id); |
| 269 | |
| 270 | /** |
| 271 | * \brief Function body of \ref psa_clear. |
| 272 | * |
| 273 | * \retval void Success. |
| 274 | * \retval "PROGRAMMER ERROR" The Secure Partition's doorbell signal is not |
| 275 | * currently asserted. |
| 276 | */ |
| 277 | void tfm_spm_partition_psa_clear(void); |
| 278 | |
| 279 | /** |
| 280 | * \brief Function body of \ref psa_eoi. |
| 281 | * |
| 282 | * \param[in] irq_signal The interrupt signal that has been processed. |
| 283 | * |
| 284 | * \retval void Success. |
| 285 | * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the |
| 286 | * following are true: |
| 287 | * \arg irq_signal is not an interrupt signal. |
| 288 | * \arg irq_signal indicates more than one signal. |
| 289 | * \arg irq_signal is not currently asserted. |
| 290 | * \arg The interrupt is not using SLIH. |
| 291 | */ |
| 292 | void tfm_spm_partition_psa_eoi(psa_signal_t irq_signal); |
| 293 | |
| 294 | /** |
| 295 | * \brief Function body of \ref psa_panic. |
| 296 | * |
| 297 | * \retval "Does not return" |
| 298 | */ |
| 299 | void tfm_spm_partition_psa_panic(void); |
| 300 | |
| 301 | /** |
| 302 | * \brief Function body of \ref psa_irq_enable. |
| 303 | * |
| 304 | * \param[in] irq_signal The signal for the interrupt to be enabled. |
| 305 | * This must have a single bit set, which must be the |
| 306 | * signal value for an interrupt in the calling Secure |
| 307 | * Partition. |
| 308 | * |
| 309 | * \retval void |
| 310 | * \retval "PROGRAMMER ERROR" If one or more of the following are true: |
| 311 | * \arg \a irq_signal is not an interrupt signal. |
| 312 | * \arg \a irq_signal indicates more than one signal. |
| 313 | */ |
| 314 | void tfm_spm_partition_irq_enable(psa_signal_t irq_signal); |
| 315 | |
| 316 | /** |
| 317 | * \brief Function body of psa_irq_disable. |
| 318 | * |
| 319 | * \param[in] irq_signal The signal for the interrupt to be disabled. |
| 320 | * This must have a single bit set, which must be the |
| 321 | * signal value for an interrupt in the calling Secure |
| 322 | * Partition. |
| 323 | * |
| 324 | * \retval 0 The interrupt was disabled prior to this call. |
| 325 | * 1 The interrupt was enabled prior to this call. |
| 326 | * \retval "PROGRAMMER ERROR" If one or more of the following are true: |
| 327 | * \arg \a irq_signal is not an interrupt signal. |
| 328 | * \arg \a irq_signal indicates more than one signal. |
| 329 | * |
| 330 | * \note The current implementation always return 1. Do not use the return. |
| 331 | */ |
| 332 | psa_irq_status_t tfm_spm_partition_irq_disable(psa_signal_t irq_signal); |
| 333 | |
| 334 | /** |
| 335 | * \brief Function body of \ref psa_reset_signal. |
| 336 | * |
| 337 | * \param[in] irq_signal The interrupt signal to be reset. |
| 338 | * This must have a single bit set, corresponding to a |
| 339 | * currently asserted signal for an interrupt that is |
| 340 | * defined to use FLIH handling. |
| 341 | * |
| 342 | * \retval void |
| 343 | * \retval "Programmer Error" if one or more of the following are true: |
| 344 | * \arg \a irq_signal is not a signal for an interrupt |
| 345 | * that is specified with FLIH handling in the Secure |
| 346 | * Partition manifest. |
| 347 | * \arg \a irq_signal indicates more than one signal. |
| 348 | * \arg \a irq_signal is not currently asserted. |
| 349 | */ |
| 350 | void tfm_spm_partition_psa_reset_signal(psa_signal_t irq_signal); |
| 351 | |
Mingyang Sun | 133a792 | 2021-07-08 16:01:26 +0800 | [diff] [blame] | 352 | #endif /* __PSA_API_H__ */ |