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 | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 26 | /* PSA Client API function body, for privileged use only. */ |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * \brief handler for \ref psa_framework_version. |
| 30 | * |
| 31 | * \return version The version of the PSA Framework implementation |
| 32 | * that is providing the runtime services. |
| 33 | */ |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 34 | uint32_t tfm_spm_client_psa_framework_version(void); |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * \brief handler for \ref psa_version. |
| 38 | * |
| 39 | * \param[in] sid RoT Service identity. |
Summer Qin | 43c185d | 2019-10-10 15:44:42 +0800 | [diff] [blame] | 40 | * \param[in] ns_caller If 'true', call from non-secure client. |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 41 | * Otherwise from secure client. |
| 42 | * |
| 43 | * \retval PSA_VERSION_NONE The RoT Service is not implemented, or the |
| 44 | * caller is not permitted to access the service. |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame] | 45 | * \retval > 0 The version of the implemented RoT Service. |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 46 | */ |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 47 | uint32_t tfm_spm_client_psa_version(uint32_t sid, bool ns_caller); |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * \brief handler for \ref psa_connect. |
| 51 | * |
| 52 | * \param[in] sid RoT Service identity. |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame] | 53 | * \param[in] version The version of the RoT Service. |
Summer Qin | 43c185d | 2019-10-10 15:44:42 +0800 | [diff] [blame] | 54 | * \param[in] ns_caller If 'true', call from non-secure client. |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 55 | * Otherwise from secure client. |
| 56 | * |
| 57 | * \retval PSA_SUCCESS Success. |
| 58 | * \retval PSA_ERROR_CONNECTION_REFUSED The SPM or RoT Service has refused the |
| 59 | * connection. |
| 60 | * \retval PSA_ERROR_CONNECTION_BUSY The SPM or RoT Service cannot make the |
| 61 | * connection at the moment. |
| 62 | * \retval "Does not return" The RoT Service ID and version are not |
| 63 | * supported, or the caller is not permitted to |
| 64 | * access the service. |
| 65 | */ |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 66 | psa_status_t tfm_spm_client_psa_connect(uint32_t sid, uint32_t version, |
| 67 | bool ns_caller); |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * \brief handler for \ref psa_call. |
| 71 | * |
| 72 | * \param[in] handle Service handle to the established connection, |
| 73 | * \ref psa_handle_t |
| 74 | * \param[in] type The request type. |
| 75 | * Must be zero( \ref PSA_IPC_CALL) or positive. |
| 76 | * \param[in] inptr Array of input psa_invec structures. |
| 77 | * \ref psa_invec |
| 78 | * \param[in] in_num Number of input psa_invec structures. |
| 79 | * \ref psa_invec |
| 80 | * \param[in] outptr Array of output psa_outvec structures. |
| 81 | * \ref psa_outvec |
| 82 | * \param[in] out_num Number of outut psa_outvec structures. |
| 83 | * \ref psa_outvec |
Summer Qin | 43c185d | 2019-10-10 15:44:42 +0800 | [diff] [blame] | 84 | * \param[in] ns_caller If 'true', call from non-secure client. |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 85 | * Otherwise from secure client. |
| 86 | * \param[in] privileged Privileged mode or unprivileged mode: |
| 87 | * \ref TFM_PARTITION_UNPRIVILEGED_MODE |
| 88 | * \ref TFM_PARTITION_PRIVILEGED_MODE |
| 89 | * |
| 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 Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 100 | psa_status_t tfm_spm_client_psa_call(psa_handle_t handle, int32_t type, |
| 101 | const psa_invec *inptr, size_t in_num, |
| 102 | psa_outvec *outptr, size_t out_num, |
| 103 | bool ns_caller, uint32_t privileged); |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 104 | |
| 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 |
Summer Qin | 43c185d | 2019-10-10 15:44:42 +0800 | [diff] [blame] | 110 | * \param[in] ns_caller If 'true', call from non-secure client. |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 111 | * Otherwise from secure client. |
| 112 | * |
| 113 | * \retval void Success. |
| 114 | * \retval "Does not return" The call is invalid, one or more of the |
| 115 | * following are true: |
| 116 | * \arg An invalid handle was provided that is not |
| 117 | * the null handle. |
| 118 | * \arg The connection is handling a request. |
| 119 | */ |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 120 | void tfm_spm_client_psa_close(psa_handle_t handle, bool ns_caller); |
David Hu | 733d8f9 | 2019-09-23 15:32:40 +0800 | [diff] [blame] | 121 | |
Mingyang Sun | b26b280 | 2021-07-07 11:25:00 +0800 | [diff] [blame] | 122 | /* PSA Partition API function body, for privileged use only. */ |
| 123 | |
| 124 | /** |
| 125 | * \brief Function body of \ref psa_wait. |
| 126 | * |
| 127 | * \param[in] signal_mask A set of signals to query. Signals that are not |
| 128 | * in this set will be ignored. |
| 129 | * \param[in] timeout Specify either blocking \ref PSA_BLOCK or |
| 130 | * polling \ref PSA_POLL operation. |
| 131 | * |
| 132 | * \retval >0 At least one signal is asserted. |
| 133 | * \retval 0 No signals are asserted. This is only seen when |
| 134 | * a polling timeout is used. |
| 135 | */ |
| 136 | psa_signal_t tfm_spm_partition_psa_wait(psa_signal_t signal_mask, |
| 137 | uint32_t timeout); |
| 138 | |
| 139 | /** |
| 140 | * \brief Function body of \ref psa_get. |
| 141 | * |
| 142 | * \param[in] signal The signal value for an asserted RoT Service. |
| 143 | * \param[out] msg Pointer to \ref psa_msg_t object for receiving |
| 144 | * the message. |
| 145 | * |
| 146 | * \retval PSA_SUCCESS Success, *msg will contain the delivered |
| 147 | * message. |
| 148 | * \retval PSA_ERROR_DOES_NOT_EXIST Message could not be delivered. |
| 149 | * \retval "PROGRAMMER ERROR" The call is invalid because one or more of the |
| 150 | * following are true: |
| 151 | * \arg signal has more than a single bit set. |
| 152 | * \arg signal does not correspond to an RoT Service. |
| 153 | * \arg The RoT Service signal is not currently |
| 154 | * asserted. |
| 155 | * \arg The msg pointer provided is not a valid memory |
| 156 | * reference. |
| 157 | */ |
| 158 | psa_status_t tfm_spm_partition_psa_get(psa_signal_t signal, psa_msg_t *msg); |
| 159 | |
| 160 | /** |
| 161 | * \brief Function body of \ref psa_set_rhandle. |
| 162 | * |
| 163 | * \param[in] msg_handle Handle for the client's message. |
| 164 | * \param[in] rhandle Reverse handle allocated by the RoT Service. |
| 165 | * |
| 166 | * \retval void Success, rhandle will be provided with all |
| 167 | * subsequent messages delivered on this |
| 168 | * connection. |
| 169 | * \retval "PROGRAMMER ERROR" msg_handle is invalid. |
| 170 | */ |
| 171 | void tfm_spm_partition_psa_set_rhandle(psa_handle_t msg_handle, void *rhandle); |
| 172 | |
| 173 | /** |
| 174 | * \brief Function body of \ref psa_read. |
| 175 | * |
| 176 | * \param[in] msg_handle Handle for the client's message. |
| 177 | * \param[in] invec_idx Index of the input vector to read from. Must be |
| 178 | * less than \ref PSA_MAX_IOVEC. |
| 179 | * \param[out] buffer Buffer in the Secure Partition to copy the |
| 180 | * requested data to. |
| 181 | * \param[in] num_bytes Maximum number of bytes to be read from the |
| 182 | * client input vector. |
| 183 | * |
| 184 | * \retval >0 Number of bytes copied. |
| 185 | * \retval 0 There was no remaining data in this input |
| 186 | * vector. |
| 187 | * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the |
| 188 | * following are true: |
| 189 | * \arg msg_handle is invalid. |
| 190 | * \arg msg_handle does not refer to a |
| 191 | * \ref PSA_IPC_CALL message. |
| 192 | * \arg invec_idx is equal to or greater than |
| 193 | * \ref PSA_MAX_IOVEC. |
| 194 | * \arg the memory reference for buffer is invalid or |
| 195 | * not writable. |
| 196 | */ |
| 197 | size_t tfm_spm_partition_psa_read(psa_handle_t msg_handle, uint32_t invec_idx, |
| 198 | void *buffer, size_t num_bytes); |
| 199 | |
| 200 | /** |
| 201 | * \brief Function body of psa_skip. |
| 202 | * |
| 203 | * \param[in] msg_handle Handle for the client's message. |
| 204 | * \param[in] invec_idx Index of input vector to skip from. Must be |
| 205 | * less than \ref PSA_MAX_IOVEC. |
| 206 | * \param[in] num_bytes Maximum number of bytes to skip in the client |
| 207 | * input vector. |
| 208 | * |
| 209 | * \retval >0 Number of bytes skipped. |
| 210 | * \retval 0 There was no remaining data in this input |
| 211 | * vector. |
| 212 | * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the |
| 213 | * following are true: |
| 214 | * \arg msg_handle is invalid. |
| 215 | * \arg msg_handle does not refer to a request |
| 216 | * message. |
| 217 | * \arg invec_idx is equal to or greater than |
| 218 | * \ref PSA_MAX_IOVEC. |
| 219 | */ |
| 220 | size_t tfm_spm_partition_psa_skip(psa_handle_t msg_handle, uint32_t invec_idx, |
| 221 | size_t num_bytes); |
| 222 | |
| 223 | /** |
| 224 | * \brief Function body of \ref psa_write. |
| 225 | * |
| 226 | * \param[in] msg_handle Handle for the client's message. |
| 227 | * \param[out] outvec_idx Index of output vector in message to write to. |
| 228 | * Must be less than \ref PSA_MAX_IOVEC. |
| 229 | * \param[in] buffer Buffer with the data to write. |
| 230 | * \param[in] num_bytes Number of bytes to write to the client output |
| 231 | * vector. |
| 232 | * |
| 233 | * \retval void Success |
| 234 | * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the |
| 235 | * following are true: |
| 236 | * \arg msg_handle is invalid. |
| 237 | * \arg msg_handle does not refer to a request |
| 238 | * message. |
| 239 | * \arg outvec_idx is equal to or greater than |
| 240 | * \ref PSA_MAX_IOVEC. |
| 241 | * \arg The memory reference for buffer is invalid. |
| 242 | * \arg The call attempts to write data past the end |
| 243 | * of the client output vector. |
| 244 | */ |
| 245 | void tfm_spm_partition_psa_write(psa_handle_t msg_handle, uint32_t outvec_idx, |
| 246 | const void *buffer, size_t num_bytes); |
| 247 | |
| 248 | /** |
| 249 | * \brief Function body of \ref psa_reply. |
| 250 | * |
| 251 | * \param[in] msg_handle Handle for the client's message. |
| 252 | * \param[in] status Message result value to be reported to the |
| 253 | * client. |
| 254 | * |
| 255 | * \retval void Success. |
| 256 | * \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 | */ |
| 262 | void tfm_spm_partition_psa_reply(psa_handle_t msg_handle, psa_status_t status); |
| 263 | |
| 264 | /** |
| 265 | * \brief Function body of \ref psa_norify. |
| 266 | * |
| 267 | * \param[in] partition_id Secure Partition ID of the target partition. |
| 268 | * |
| 269 | * \retval void Success. |
| 270 | * \retval "PROGRAMMER ERROR" partition_id does not correspond to a Secure |
| 271 | * Partition. |
| 272 | */ |
| 273 | void tfm_spm_partition_psa_notify(int32_t partition_id); |
| 274 | |
| 275 | /** |
| 276 | * \brief Function body of \ref psa_clear. |
| 277 | * |
| 278 | * \retval void Success. |
| 279 | * \retval "PROGRAMMER ERROR" The Secure Partition's doorbell signal is not |
| 280 | * currently asserted. |
| 281 | */ |
| 282 | void tfm_spm_partition_psa_clear(void); |
| 283 | |
| 284 | /** |
| 285 | * \brief Function body of \ref psa_eoi. |
| 286 | * |
| 287 | * \param[in] irq_signal The interrupt signal that has been processed. |
| 288 | * |
| 289 | * \retval void Success. |
| 290 | * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the |
| 291 | * following are true: |
| 292 | * \arg irq_signal is not an interrupt signal. |
| 293 | * \arg irq_signal indicates more than one signal. |
| 294 | * \arg irq_signal is not currently asserted. |
| 295 | * \arg The interrupt is not using SLIH. |
| 296 | */ |
| 297 | void tfm_spm_partition_psa_eoi(psa_signal_t irq_signal); |
| 298 | |
| 299 | /** |
| 300 | * \brief Function body of \ref psa_panic. |
| 301 | * |
| 302 | * \retval "Does not return" |
| 303 | */ |
| 304 | void tfm_spm_partition_psa_panic(void); |
| 305 | |
| 306 | /** |
| 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 | */ |
| 319 | void tfm_spm_partition_irq_enable(psa_signal_t irq_signal); |
| 320 | |
| 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 | */ |
| 337 | psa_irq_status_t tfm_spm_partition_irq_disable(psa_signal_t irq_signal); |
| 338 | |
| 339 | /** |
| 340 | * \brief Function body of \ref psa_reset_signal. |
| 341 | * |
| 342 | * \param[in] irq_signal The interrupt signal to be reset. |
| 343 | * This must have a single bit set, corresponding to a |
| 344 | * currently asserted signal for an interrupt that is |
| 345 | * defined to use FLIH handling. |
| 346 | * |
| 347 | * \retval void |
| 348 | * \retval "Programmer Error" if one or more of the following are true: |
| 349 | * \arg \a irq_signal is not a signal for an interrupt |
| 350 | * that is specified with FLIH handling in the Secure |
| 351 | * Partition manifest. |
| 352 | * \arg \a irq_signal indicates more than one signal. |
| 353 | * \arg \a irq_signal is not currently asserted. |
| 354 | */ |
| 355 | void tfm_spm_partition_psa_reset_signal(psa_signal_t irq_signal); |
| 356 | |
Mingyang Sun | 133a792 | 2021-07-08 16:01:26 +0800 | [diff] [blame^] | 357 | #endif /* __PSA_API_H__ */ |