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