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