Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef __PSA_SERVICE_H__ |
| 9 | #define __PSA_SERVICE_H__ |
| 10 | |
| 11 | #ifdef __cplusplus |
| 12 | extern "C" { |
| 13 | #endif |
| 14 | |
| 15 | #include <inttypes.h> |
| 16 | |
| 17 | /* PSA wait timeouts */ |
| 18 | #define PSA_POLL (0x00000000u) |
| 19 | #define PSA_BLOCK (0x80000000u) |
| 20 | |
| 21 | /* doorbell signal */ |
| 22 | #define PSA_DOORBELL (0x00000008u) |
| 23 | |
| 24 | /* PSA message types */ |
| 25 | #define PSA_IPC_CONNECT (1) |
| 26 | #define PSA_IPC_CALL (2) |
| 27 | #define PSA_IPC_DISCONNECT (3) |
| 28 | |
| 29 | /* PSA response types */ |
| 30 | #define PSA_CONNECTION_ACCEPTED (0) |
| 31 | |
| 32 | /* maximum number of input and output vectors */ |
| 33 | #define PSA_MAX_IOVEC (4) |
| 34 | |
| 35 | typedef uint32_t psa_signal_t; |
| 36 | |
| 37 | /** |
| 38 | * Describes a message received by a RoT Service after calling \ref psa_get(). |
| 39 | */ |
| 40 | typedef struct psa_msg_t { |
| 41 | uint32_t type; |
| 42 | psa_handle_t handle; |
| 43 | void *rhandle; |
| 44 | size_t in_size[PSA_MAX_IOVEC]; |
| 45 | size_t out_size[PSA_MAX_IOVEC]; |
| 46 | } psa_msg_t; |
| 47 | |
| 48 | /* ******** ******** PSA Secure Function API ******** ******** */ |
| 49 | |
| 50 | /** |
| 51 | * \brief Returns the set of signals that have been asserted for a Sercure |
| 52 | * Partition. |
| 53 | * |
| 54 | * \param[in] timeout Specify either blocking or polling operation |
| 55 | * |
| 56 | * \retval >0 At least one signal is asserted |
| 57 | * \retval 0 No signals are asserted. This is only seen if the |
| 58 | * caller used a polling timeout |
| 59 | */ |
| 60 | uint32_t psa_wait_any(uint32_t timeout); |
| 61 | |
| 62 | /** |
| 63 | * \brief Returns the Secure Partition interrupt signals that have been |
| 64 | * asserted from the subset of signals indicated in the bitmask provided. |
| 65 | * |
| 66 | * \param[in] signal_mask A set of interrupt and doorbell signals to query. |
| 67 | * Signals that are not in this set will be ignored |
| 68 | * \param[in] timeout Specify either blocking or polling operation |
| 69 | * |
| 70 | * \retval >0 At least one signal is asserted |
| 71 | * \retval 0 No signals are asserted. This case is only seen if |
| 72 | * caller used a polling timeout |
| 73 | * \retval "Does not return" The call is invalid, one or more of the following |
| 74 | * are true: |
| 75 | * \arg signal_mask does not include any interrupt or |
| 76 | * doorbell signals |
| 77 | * \arg signal_mask includes one or more RoT Service |
| 78 | * signals |
| 79 | */ |
| 80 | uint32_t psa_wait_interrupt(psa_signal_t signal_mask, uint32_t timeout); |
| 81 | |
| 82 | /** |
| 83 | * \brief Get the message which corresponds to a given RoT Service signal |
| 84 | * and remove the message from the RoT Service queue. |
| 85 | * |
| 86 | * \param[in] signal The signal value for an asserted RoT Service |
| 87 | * \param[out] msg Pointer to \ref psa_msg_t object for receiving |
| 88 | * the message |
| 89 | * |
| 90 | * \retval void Success |
| 91 | * \retval "Does not return" The call is invalid because one or more of the |
| 92 | * following are true: |
| 93 | * \arg signal has more than a single bit set |
| 94 | * \arg signal does not correspond to a RoT Service |
| 95 | * \arg The RoT Service signal is not currently asserted |
| 96 | * \arg The msg pointer provided is not a valid memory |
| 97 | * reference |
| 98 | */ |
| 99 | void psa_get(psa_signal_t signal, psa_msg_t *msg); |
| 100 | |
| 101 | /** |
| 102 | * \brief Get the Partition ID of the sender of a message. |
| 103 | * |
| 104 | * \param[in] msg_handle Message handle for an incoming message |
| 105 | * |
| 106 | * \retval >0 ID of a Secure Partition |
| 107 | * \retval <0 ID of an NSPE client |
| 108 | * \retval "Does not return" msg_handle is invalid |
| 109 | * |
| 110 | * \note Bit[31] is set if the caller is from the NSPE. |
| 111 | */ |
| 112 | int32_t psa_identity(psa_handle_t msg_handle); |
| 113 | |
| 114 | /** |
| 115 | * \brief Associates some caller-provided private data with a specified client |
| 116 | * connection. |
| 117 | * |
| 118 | * \param[in] msg_handle Handle for the client's message |
| 119 | * \param[in] rhandle Reverse handle allocated by the RoT Service |
| 120 | * |
| 121 | * \retval void Success, rhandle will be provided with all |
| 122 | * subsequent messages delivered on this connection |
| 123 | * \retval "Does not return" msg_handle is invalid |
| 124 | */ |
| 125 | void psa_set_rhandle(psa_handle_t msg_handle, void *rhandle); |
| 126 | |
| 127 | /** |
| 128 | * \brief Read a message parameter or part of a message parameter from the |
| 129 | * client input vector. |
| 130 | * |
| 131 | * \param[in] msg_handle Handle for the client's message |
| 132 | * \param[in] invec_idx Index of the input vector to read from. Must be |
| 133 | * less than \ref PSA_MAX_IOVEC |
| 134 | * \param[out] buffer Buffer in the Secure Partition to copy the |
| 135 | * requested data to |
| 136 | * \param[in] num_bytes Maximum number of bytes to be read from the client |
| 137 | * input vector |
| 138 | * |
| 139 | * \retval >0 Number of bytes copied |
| 140 | * \retval 0 There was no remaining data in this input vector |
| 141 | * \retval "Does not return" The call is invalid, one or more of the following |
| 142 | * are true: |
| 143 | * \arg msg_handle is invalid |
| 144 | * \arg msg_handle does not refer to a \ref PSA_IPC_CALL |
| 145 | * message |
| 146 | * \arg invec_idx is equal to or greater than |
| 147 | * PSA_MAX_IOVEC |
| 148 | * \arg the memory reference for buffer is invalid or |
| 149 | * not writable |
| 150 | */ |
| 151 | size_t psa_read(psa_handle_t msg_handle, uint32_t invec_idx, |
| 152 | void *buffer, size_t num_bytes); |
| 153 | |
| 154 | /** |
| 155 | * \brief Skip a given number of bytes for an input vector. |
| 156 | * |
| 157 | * \param[in] msg_handle Handle for the client's message |
| 158 | * \param[in] invec_idx Index of input vector in message to skip from. |
| 159 | * Must be less than \ref PSA_MAX_IOVEC |
| 160 | * \param[in] num_bytes Maximum number of bytes to skip in the client input |
| 161 | * vector |
| 162 | * |
| 163 | * \retval >0 Number of bytes skipped |
| 164 | * \retval 0 There was no remaining data in this input vector |
| 165 | * \retval "Does not return" The call is invalid, one or more of the following |
| 166 | * are true: |
| 167 | * \arg msg_handle is invalid |
| 168 | * \arg msg_handle does not refer to a \ref PSA_IPC_CALL |
| 169 | * message |
| 170 | * \arg invec_idx is equal to or greater than |
| 171 | * PSA_MAX_IOVEC |
| 172 | */ |
| 173 | size_t psa_skip(psa_handle_t msg_handle, uint32_t invec_idx, size_t num_bytes); |
| 174 | |
| 175 | /** |
| 176 | * \brief Write a message response to the client output vector. |
| 177 | * |
| 178 | * \param[in] msg_handle Handle for the client's message |
| 179 | * \param[out] outvec_idx Index of output vector in message to write to. |
| 180 | * Must be less than \ref PSA_MAX_IOVEC |
| 181 | * \param[in] buffer Buffer with the data to write |
| 182 | * \param[in] num_bytes Number of bytes to write to the client output |
| 183 | * vector |
| 184 | * |
| 185 | * \retval void Success |
| 186 | * \retval "Does not return" The call is invalid, one or more of the following |
| 187 | * are true: |
| 188 | * \arg msg_handle is invalid |
| 189 | * \arg msg_handle does not refer to a \ref PSA_IPC_CALL |
| 190 | * message |
| 191 | * \arg outvec_idx is equal to or greater than |
| 192 | * \ref PSA_MAX_IOVEC |
| 193 | * \arg the memory reference for buffer is invalid |
| 194 | * \arg the call attempts to write data past the end of |
| 195 | * the client output vector |
| 196 | */ |
| 197 | void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx, |
| 198 | const void *buffer, size_t num_bytes); |
| 199 | |
| 200 | /** |
| 201 | * \brief Completes handling of a specific message and unblocks the client. |
| 202 | * |
| 203 | * \param[in] msg_handle Handle for the client's message or the null handle |
| 204 | * \param[in] retval Return value to be reported to the client |
| 205 | * |
| 206 | * \retval void Success |
| 207 | * \retval "Does not return" The call is invalid, one or more of the following |
| 208 | * are true: |
| 209 | * \arg msg_handle is invalid and is not the null handle |
| 210 | * \arg An invalid return code is specified for the type |
| 211 | * of message |
| 212 | */ |
| 213 | void psa_end(psa_handle_t msg_handle, psa_error_t retval); |
| 214 | |
| 215 | /** |
| 216 | * \brief Sends a PSA_DOORBELL signal to a specific Secure Partition. |
| 217 | * |
| 218 | * \param[in] partition_id Secure Partition ID of the target partition |
| 219 | * |
| 220 | * \retval void Success |
| 221 | * \retval "Does not return" partition_id does not correspond to a Secure |
| 222 | * Partition |
| 223 | */ |
| 224 | void psa_notify(int32_t partition_id); |
| 225 | |
| 226 | /** |
| 227 | * \brief Clears the PSA_DOORBELL signal. |
| 228 | * |
| 229 | * \param[in] void |
| 230 | * |
| 231 | * \retval void Success |
| 232 | * \retval "Does not return" The Secure Partition's doorbell signal is not |
| 233 | * currently asserted |
| 234 | */ |
| 235 | void psa_clear(void); |
| 236 | |
| 237 | /** |
| 238 | * \brief Informs the SPM that an interrupt has been handled (end of interrupt). |
| 239 | * |
| 240 | * \param[in] irq_signal The interrupt signal that has been processed |
| 241 | * |
| 242 | * \retval void Success |
| 243 | * \retval "Does not return" The call is invalid, one or more of the following |
| 244 | * are true: |
| 245 | * \arg irq_signal is not an interrupt signal |
| 246 | * \arg irq_signal indicates more than one signal |
| 247 | * \arg irq_signal is not currently asserted |
| 248 | */ |
| 249 | void psa_eoi(uint32_t irq_signal); |
| 250 | |
| 251 | #ifdef __cplusplus |
| 252 | } |
| 253 | #endif |
| 254 | |
| 255 | #endif /* __PSA_SERVICE_H__ */ |