Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1 | /* |
J-Alves | 13318e3 | 2021-02-22 17:21:00 +0000 | [diff] [blame] | 2 | * Copyright 2021 The Hafnium Authors. |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 3 | * |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style |
| 5 | * license that can be found in the LICENSE file or at |
| 6 | * https://opensource.org/licenses/BSD-3-Clause. |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include "hf/types.h" |
| 12 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 13 | #define FFA_VERSION_MAJOR 0x1 |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 14 | #define FFA_VERSION_MAJOR_OFFSET 16 |
Daniel Boulby | 6e32c61 | 2021-02-17 15:09:41 +0000 | [diff] [blame] | 15 | #define FFA_VERSION_MAJOR_MASK 0x7FFF |
Kathleen Capella | e4fe296 | 2023-09-01 17:08:47 -0400 | [diff] [blame] | 16 | #define FFA_VERSION_MINOR 0x2 |
Daniel Boulby | 6e32c61 | 2021-02-17 15:09:41 +0000 | [diff] [blame] | 17 | #define FFA_VERSION_MINOR_OFFSET 0 |
| 18 | #define FFA_VERSION_MINOR_MASK 0xFFFF |
| 19 | |
| 20 | #define MAKE_FFA_VERSION(major, minor) \ |
| 21 | ((((major)&FFA_VERSION_MAJOR_MASK) << FFA_VERSION_MAJOR_OFFSET) | \ |
| 22 | (((minor)&FFA_VERSION_MINOR_MASK) << FFA_VERSION_MINOR_OFFSET)) |
| 23 | #define FFA_VERSION_COMPILED \ |
| 24 | MAKE_FFA_VERSION(FFA_VERSION_MAJOR, FFA_VERSION_MINOR) |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 25 | |
Daniel Boulby | c7dc932 | 2023-10-27 15:12:07 +0100 | [diff] [blame] | 26 | /** |
| 27 | * Check major versions are equal and the minor version of the caller is |
| 28 | * less than or equal to the minor version of the callee. |
| 29 | */ |
| 30 | #define FFA_VERSIONS_ARE_COMPATIBLE(v_caller, v_callee) \ |
| 31 | ((((v_caller >> FFA_VERSION_MAJOR_OFFSET) & FFA_VERSION_MAJOR_MASK) == \ |
| 32 | ((v_callee >> FFA_VERSION_MAJOR_OFFSET) & \ |
| 33 | FFA_VERSION_MAJOR_MASK)) && \ |
| 34 | (((v_caller >> FFA_VERSION_MINOR_OFFSET) & FFA_VERSION_MINOR_MASK) <= \ |
| 35 | ((v_callee >> FFA_VERSION_MINOR_OFFSET) & FFA_VERSION_MINOR_MASK))) |
| 36 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 37 | /* clang-format off */ |
| 38 | |
| 39 | #define FFA_LOW_32_ID 0x84000060 |
| 40 | #define FFA_HIGH_32_ID 0x8400007F |
| 41 | #define FFA_LOW_64_ID 0xC4000060 |
Fuad Tabba | da72d14 | 2020-07-30 09:17:05 +0100 | [diff] [blame] | 42 | #define FFA_HIGH_64_ID 0xC400007F |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 43 | |
Karl Meakin | f51a35f | 2023-08-07 17:53:52 +0100 | [diff] [blame] | 44 | /** |
| 45 | * FF-A function identifiers. |
| 46 | * Don't forget to update `ffa_func_name` if you add a new one. |
| 47 | */ |
J-Alves | 3829fc0 | 2021-03-18 12:49:18 +0000 | [diff] [blame] | 48 | #define FFA_ERROR_32 0x84000060 |
| 49 | #define FFA_SUCCESS_32 0x84000061 |
| 50 | #define FFA_SUCCESS_64 0xC4000061 |
| 51 | #define FFA_INTERRUPT_32 0x84000062 |
| 52 | #define FFA_VERSION_32 0x84000063 |
| 53 | #define FFA_FEATURES_32 0x84000064 |
| 54 | #define FFA_RX_RELEASE_32 0x84000065 |
| 55 | #define FFA_RXTX_MAP_32 0x84000066 |
| 56 | #define FFA_RXTX_MAP_64 0xC4000066 |
| 57 | #define FFA_RXTX_UNMAP_32 0x84000067 |
| 58 | #define FFA_PARTITION_INFO_GET_32 0x84000068 |
| 59 | #define FFA_ID_GET_32 0x84000069 |
| 60 | #define FFA_MSG_POLL_32 0x8400006A /* Legacy FF-A v1.0 */ |
| 61 | #define FFA_MSG_WAIT_32 0x8400006B |
| 62 | #define FFA_YIELD_32 0x8400006C |
| 63 | #define FFA_RUN_32 0x8400006D |
| 64 | #define FFA_MSG_SEND_32 0x8400006E /* Legacy FF-A v1.0 */ |
| 65 | #define FFA_MSG_SEND_DIRECT_REQ_32 0x8400006F |
| 66 | #define FFA_MSG_SEND_DIRECT_REQ_64 0xC400006F |
| 67 | #define FFA_MSG_SEND_DIRECT_RESP_32 0x84000070 |
| 68 | #define FFA_MSG_SEND_DIRECT_RESP_64 0xC4000070 |
| 69 | #define FFA_MEM_DONATE_32 0x84000071 |
J-Alves | 95fbb31 | 2024-03-20 15:19:16 +0000 | [diff] [blame^] | 70 | #define FFA_MEM_DONATE_64 0xC4000071 |
J-Alves | 3829fc0 | 2021-03-18 12:49:18 +0000 | [diff] [blame] | 71 | #define FFA_MEM_LEND_32 0x84000072 |
J-Alves | 95fbb31 | 2024-03-20 15:19:16 +0000 | [diff] [blame^] | 72 | #define FFA_MEM_LEND_64 0xC4000072 |
J-Alves | 3829fc0 | 2021-03-18 12:49:18 +0000 | [diff] [blame] | 73 | #define FFA_MEM_SHARE_32 0x84000073 |
J-Alves | 95fbb31 | 2024-03-20 15:19:16 +0000 | [diff] [blame^] | 74 | #define FFA_MEM_SHARE_64 0xC4000073 |
J-Alves | 3829fc0 | 2021-03-18 12:49:18 +0000 | [diff] [blame] | 75 | #define FFA_MEM_RETRIEVE_REQ_32 0x84000074 |
J-Alves | 95fbb31 | 2024-03-20 15:19:16 +0000 | [diff] [blame^] | 76 | #define FFA_MEM_RETRIEVE_REQ_64 0xC4000074 |
J-Alves | 3829fc0 | 2021-03-18 12:49:18 +0000 | [diff] [blame] | 77 | #define FFA_MEM_RETRIEVE_RESP_32 0x84000075 |
| 78 | #define FFA_MEM_RELINQUISH_32 0x84000076 |
| 79 | #define FFA_MEM_RECLAIM_32 0x84000077 |
| 80 | #define FFA_MEM_FRAG_RX_32 0x8400007A |
| 81 | #define FFA_MEM_FRAG_TX_32 0x8400007B |
| 82 | #define FFA_NORMAL_WORLD_RESUME 0x8400007C |
| 83 | |
| 84 | /* FF-A v1.1 */ |
| 85 | #define FFA_NOTIFICATION_BITMAP_CREATE_32 0x8400007D |
| 86 | #define FFA_NOTIFICATION_BITMAP_DESTROY_32 0x8400007E |
| 87 | #define FFA_NOTIFICATION_BIND_32 0x8400007F |
| 88 | #define FFA_NOTIFICATION_UNBIND_32 0x84000080 |
| 89 | #define FFA_NOTIFICATION_SET_32 0x84000081 |
| 90 | #define FFA_NOTIFICATION_GET_32 0x84000082 |
| 91 | #define FFA_NOTIFICATION_INFO_GET_64 0xC4000083 |
| 92 | #define FFA_RX_ACQUIRE_32 0x84000084 |
| 93 | #define FFA_SPM_ID_GET_32 0x84000085 |
| 94 | #define FFA_MSG_SEND2_32 0x84000086 |
| 95 | #define FFA_SECONDARY_EP_REGISTER_64 0xC4000087 |
| 96 | #define FFA_MEM_PERM_GET_32 0x84000088 |
| 97 | #define FFA_MEM_PERM_SET_32 0x84000089 |
Raghu Krishnamurthy | ea6d25f | 2021-09-14 15:27:06 -0700 | [diff] [blame] | 98 | #define FFA_MEM_PERM_GET_64 0xC4000088 |
| 99 | #define FFA_MEM_PERM_SET_64 0xC4000089 |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 100 | |
Kathleen Capella | e4fe296 | 2023-09-01 17:08:47 -0400 | [diff] [blame] | 101 | /* FF-A v1.2 */ |
Maksims Svecovs | 71b7670 | 2022-05-20 15:32:58 +0100 | [diff] [blame] | 102 | #define FFA_CONSOLE_LOG_32 0x8400008A |
| 103 | #define FFA_CONSOLE_LOG_64 0xC400008A |
Raghu Krishnamurthy | 7592bcb | 2022-12-25 13:09:00 -0800 | [diff] [blame] | 104 | #define FFA_PARTITION_INFO_GET_REGS_64 0xC400008B |
Madhukar Pappireddy | 77d3bcd | 2023-03-01 17:26:22 -0600 | [diff] [blame] | 105 | #define FFA_EL3_INTR_HANDLE_32 0x8400008C |
Kathleen Capella | 41fea93 | 2023-06-23 17:39:28 -0400 | [diff] [blame] | 106 | #define FFA_MSG_SEND_DIRECT_REQ2_64 0xC400008D |
Kathleen Capella | 087e502 | 2023-09-07 18:04:15 -0400 | [diff] [blame] | 107 | #define FFA_MSG_SEND_DIRECT_RESP2_64 0xC400008E |
Maksims Svecovs | 71b7670 | 2022-05-20 15:32:58 +0100 | [diff] [blame] | 108 | |
Karl Meakin | f51a35f | 2023-08-07 17:53:52 +0100 | [diff] [blame] | 109 | /** |
| 110 | * FF-A error codes. |
| 111 | * Don't forget to update `ffa_error_name` if you add a new one. |
| 112 | */ |
Karl Meakin | dc759f5 | 2024-05-07 16:08:02 +0100 | [diff] [blame] | 113 | enum ffa_error { |
| 114 | FFA_NOT_SUPPORTED = -1, |
| 115 | FFA_INVALID_PARAMETERS = -2, |
| 116 | FFA_NO_MEMORY = -3, |
| 117 | FFA_BUSY = -4, |
| 118 | FFA_INTERRUPTED = -5, |
| 119 | FFA_DENIED = -6, |
| 120 | FFA_RETRY = -7, |
| 121 | FFA_ABORTED = -8, |
| 122 | FFA_NO_DATA = -9, |
| 123 | FFA_NOT_READY = -10, |
| 124 | }; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 125 | |
| 126 | /* clang-format on */ |
| 127 | |
Karl Meakin | f51a35f | 2023-08-07 17:53:52 +0100 | [diff] [blame] | 128 | /* Return the name of the function identifier. */ |
| 129 | static inline const char *ffa_func_name(uint32_t func) |
| 130 | { |
| 131 | switch (func) { |
| 132 | case FFA_ERROR_32: |
| 133 | return "FFA_ERROR_32"; |
| 134 | case FFA_SUCCESS_32: |
| 135 | return "FFA_SUCCESS_32"; |
| 136 | case FFA_SUCCESS_64: |
| 137 | return "FFA_SUCCESS_64"; |
| 138 | case FFA_INTERRUPT_32: |
| 139 | return "FFA_INTERRUPT_32"; |
| 140 | case FFA_VERSION_32: |
| 141 | return "FFA_VERSION_32"; |
| 142 | case FFA_FEATURES_32: |
| 143 | return "FFA_FEATURES_32"; |
| 144 | case FFA_RX_RELEASE_32: |
| 145 | return "FFA_RX_RELEASE_32"; |
| 146 | case FFA_RXTX_MAP_32: |
| 147 | return "FFA_RXTX_MAP_32"; |
| 148 | case FFA_RXTX_MAP_64: |
| 149 | return "FFA_RXTX_MAP_64"; |
| 150 | case FFA_RXTX_UNMAP_32: |
| 151 | return "FFA_RXTX_UNMAP_32"; |
| 152 | case FFA_PARTITION_INFO_GET_32: |
| 153 | return "FFA_PARTITION_INFO_GET_32"; |
| 154 | case FFA_ID_GET_32: |
| 155 | return "FFA_ID_GET_32"; |
| 156 | case FFA_MSG_POLL_32: |
| 157 | return "FFA_MSG_POLL_32"; |
| 158 | case FFA_MSG_WAIT_32: |
| 159 | return "FFA_MSG_WAIT_32"; |
| 160 | case FFA_YIELD_32: |
| 161 | return "FFA_YIELD_32"; |
| 162 | case FFA_RUN_32: |
| 163 | return "FFA_RUN_32"; |
| 164 | case FFA_MSG_SEND_32: |
| 165 | return "FFA_MSG_SEND_32"; |
| 166 | case FFA_MSG_SEND_DIRECT_REQ_32: |
| 167 | return "FFA_MSG_SEND_DIRECT_REQ_32"; |
| 168 | case FFA_MSG_SEND_DIRECT_REQ_64: |
| 169 | return "FFA_MSG_SEND_DIRECT_REQ_64"; |
| 170 | case FFA_MSG_SEND_DIRECT_RESP_32: |
| 171 | return "FFA_MSG_SEND_DIRECT_RESP_32"; |
| 172 | case FFA_MSG_SEND_DIRECT_RESP_64: |
| 173 | return "FFA_MSG_SEND_DIRECT_RESP_64"; |
| 174 | case FFA_MEM_DONATE_32: |
| 175 | return "FFA_MEM_DONATE_32"; |
| 176 | case FFA_MEM_LEND_32: |
| 177 | return "FFA_MEM_LEND_32"; |
| 178 | case FFA_MEM_SHARE_32: |
| 179 | return "FFA_MEM_SHARE_32"; |
| 180 | case FFA_MEM_RETRIEVE_REQ_32: |
| 181 | return "FFA_MEM_RETRIEVE_REQ_32"; |
J-Alves | 95fbb31 | 2024-03-20 15:19:16 +0000 | [diff] [blame^] | 182 | case FFA_MEM_DONATE_64: |
| 183 | return "FFA_MEM_DONATE_64"; |
| 184 | case FFA_MEM_LEND_64: |
| 185 | return "FFA_MEM_LEND_64"; |
| 186 | case FFA_MEM_SHARE_64: |
| 187 | return "FFA_MEM_SHARE_64"; |
| 188 | case FFA_MEM_RETRIEVE_REQ_64: |
| 189 | return "FFA_MEM_RETRIEVE_REQ_64"; |
Karl Meakin | f51a35f | 2023-08-07 17:53:52 +0100 | [diff] [blame] | 190 | case FFA_MEM_RETRIEVE_RESP_32: |
| 191 | return "FFA_MEM_RETRIEVE_RESP_32"; |
| 192 | case FFA_MEM_RELINQUISH_32: |
| 193 | return "FFA_MEM_RELINQUISH_32"; |
| 194 | case FFA_MEM_RECLAIM_32: |
| 195 | return "FFA_MEM_RECLAIM_32"; |
| 196 | case FFA_MEM_FRAG_RX_32: |
| 197 | return "FFA_MEM_FRAG_RX_32"; |
| 198 | case FFA_MEM_FRAG_TX_32: |
| 199 | return "FFA_MEM_FRAG_TX_32"; |
| 200 | case FFA_NORMAL_WORLD_RESUME: |
| 201 | return "FFA_NORMAL_WORLD_RESUME"; |
| 202 | |
| 203 | /* FF-A v1.1 */ |
| 204 | case FFA_NOTIFICATION_BITMAP_CREATE_32: |
| 205 | return "FFA_NOTIFICATION_BITMAP_CREATE_32"; |
| 206 | case FFA_NOTIFICATION_BITMAP_DESTROY_32: |
| 207 | return "FFA_NOTIFICATION_BITMAP_DESTROY_32"; |
| 208 | case FFA_NOTIFICATION_BIND_32: |
| 209 | return "FFA_NOTIFICATION_BIND_32"; |
| 210 | case FFA_NOTIFICATION_UNBIND_32: |
| 211 | return "FFA_NOTIFICATION_UNBIND_32"; |
| 212 | case FFA_NOTIFICATION_SET_32: |
| 213 | return "FFA_NOTIFICATION_SET_32"; |
| 214 | case FFA_NOTIFICATION_GET_32: |
| 215 | return "FFA_NOTIFICATION_GET_32"; |
| 216 | case FFA_NOTIFICATION_INFO_GET_64: |
| 217 | return "FFA_NOTIFICATION_INFO_GET_64"; |
| 218 | case FFA_RX_ACQUIRE_32: |
| 219 | return "FFA_RX_ACQUIRE_32"; |
| 220 | case FFA_SPM_ID_GET_32: |
| 221 | return "FFA_SPM_ID_GET_32"; |
| 222 | case FFA_MSG_SEND2_32: |
| 223 | return "FFA_MSG_SEND2_32"; |
| 224 | case FFA_SECONDARY_EP_REGISTER_64: |
| 225 | return "FFA_SECONDARY_EP_REGISTER_64"; |
| 226 | case FFA_MEM_PERM_GET_32: |
| 227 | return "FFA_MEM_PERM_GET_32"; |
| 228 | case FFA_MEM_PERM_SET_32: |
| 229 | return "FFA_MEM_PERM_SET_32"; |
| 230 | case FFA_MEM_PERM_GET_64: |
| 231 | return "FFA_MEM_PERM_GET_64"; |
| 232 | case FFA_MEM_PERM_SET_64: |
| 233 | return "FFA_MEM_PERM_SET_64"; |
| 234 | |
| 235 | /* Implementation-defined ABIs. */ |
| 236 | case FFA_CONSOLE_LOG_32: |
| 237 | return "FFA_CONSOLE_LOG_32"; |
| 238 | case FFA_CONSOLE_LOG_64: |
| 239 | return "FFA_CONSOLE_LOG_64"; |
| 240 | case FFA_PARTITION_INFO_GET_REGS_64: |
| 241 | return "FFA_PARTITION_INFO_GET_REGS_64"; |
| 242 | case FFA_EL3_INTR_HANDLE_32: |
| 243 | return "FFA_EL3_INTR_HANDLE_32"; |
| 244 | |
| 245 | default: |
| 246 | return "UNKNOWN"; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | /* Return the name of the error code. */ |
Karl Meakin | dc759f5 | 2024-05-07 16:08:02 +0100 | [diff] [blame] | 251 | static inline const char *ffa_error_name(enum ffa_error error) |
Karl Meakin | f51a35f | 2023-08-07 17:53:52 +0100 | [diff] [blame] | 252 | { |
| 253 | switch (error) { |
| 254 | case FFA_NOT_SUPPORTED: |
| 255 | return "FFA_NOT_SUPPORTED"; |
| 256 | case FFA_INVALID_PARAMETERS: |
| 257 | return "FFA_INVALID_PARAMETERS"; |
| 258 | case FFA_NO_MEMORY: |
| 259 | return "FFA_NO_MEMORY"; |
| 260 | case FFA_BUSY: |
| 261 | return "FFA_BUSY"; |
| 262 | case FFA_INTERRUPTED: |
| 263 | return "FFA_INTERRUPTED"; |
| 264 | case FFA_DENIED: |
| 265 | return "FFA_DENIED"; |
| 266 | case FFA_RETRY: |
| 267 | return "FFA_RETRY"; |
| 268 | case FFA_ABORTED: |
| 269 | return "FFA_ABORTED"; |
| 270 | case FFA_NO_DATA: |
| 271 | return "FFA_NO_DATA"; |
Karl Meakin | dc759f5 | 2024-05-07 16:08:02 +0100 | [diff] [blame] | 272 | case FFA_NOT_READY: |
| 273 | return "FFA_NOT_READY"; |
Karl Meakin | f51a35f | 2023-08-07 17:53:52 +0100 | [diff] [blame] | 274 | } |
Karl Meakin | dc759f5 | 2024-05-07 16:08:02 +0100 | [diff] [blame] | 275 | return "UNKNOWN"; |
Karl Meakin | f51a35f | 2023-08-07 17:53:52 +0100 | [diff] [blame] | 276 | } |
| 277 | |
J-Alves | 6f72ca8 | 2021-11-01 12:34:58 +0000 | [diff] [blame] | 278 | /** |
| 279 | * FF-A Feature ID, to be used with interface FFA_FEATURES. |
| 280 | * As defined in the FF-A v1.1 Beta specification, table 13.10, in section |
| 281 | * 13.2. |
| 282 | */ |
| 283 | |
Olivier Deprez | b76307d | 2022-06-09 17:17:45 +0200 | [diff] [blame] | 284 | #define FFA_FEATURES_FUNC_ID_MASK (UINT32_C(1) << 31) |
J-Alves | 6f72ca8 | 2021-11-01 12:34:58 +0000 | [diff] [blame] | 285 | #define FFA_FEATURES_FEATURE_ID_MASK UINT32_C(0x7F) |
| 286 | |
Karl Meakin | 34b8ae9 | 2023-01-13 13:33:07 +0000 | [diff] [blame] | 287 | /** |
| 288 | * Defined in Table 13.14 in the FF-A v.1.1 REL0 specification. |
| 289 | * Bits[31:2] and Bit[0] of input are reserved (must be zero). |
| 290 | * Bit[0]: dynamically allocated buffer support. |
| 291 | * Bit[1]: NS bit handling. |
| 292 | * Bit[2]: support for retrieval by hypervisor. |
| 293 | */ |
| 294 | #define FFA_FEATURES_MEM_RETRIEVE_REQ_BUFFER_SUPPORT 0 |
| 295 | #define FFA_FEATURES_MEM_RETRIEVE_REQ_NS_SUPPORT (UINT32_C(1) << 1) |
| 296 | #define FFA_FEATURES_MEM_RETRIEVE_REQ_HYPERVISOR_SUPPORT (UINT32_C(1) << 2) |
| 297 | #define FFA_FEATURES_MEM_RETRIEVE_REQ_MBZ_MASK \ |
| 298 | (~(FFA_FEATURES_MEM_RETRIEVE_REQ_BUFFER_SUPPORT | \ |
| 299 | FFA_FEATURES_MEM_RETRIEVE_REQ_NS_SUPPORT | \ |
| 300 | FFA_FEATURES_MEM_RETRIEVE_REQ_HYPERVISOR_SUPPORT)) |
| 301 | |
J-Alves | 6f72ca8 | 2021-11-01 12:34:58 +0000 | [diff] [blame] | 302 | /* Query interrupt ID of Notification Pending Interrupt. */ |
| 303 | #define FFA_FEATURE_NPI 0x1U |
| 304 | |
| 305 | /* Query interrupt ID of Schedule Receiver Interrupt. */ |
| 306 | #define FFA_FEATURE_SRI 0x2U |
| 307 | |
| 308 | /* Query interrupt ID of the Managed Exit Interrupt. */ |
| 309 | #define FFA_FEATURE_MEI 0x3U |
| 310 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 311 | /* FF-A function specific constants. */ |
| 312 | #define FFA_MSG_RECV_BLOCK 0x1 |
| 313 | #define FFA_MSG_RECV_BLOCK_MASK 0x1 |
| 314 | |
| 315 | #define FFA_MSG_SEND_NOTIFY 0x1 |
| 316 | #define FFA_MSG_SEND_NOTIFY_MASK 0x1 |
| 317 | |
| 318 | #define FFA_MEM_RECLAIM_CLEAR 0x1 |
| 319 | |
| 320 | #define FFA_SLEEP_INDEFINITE 0 |
| 321 | |
Raghu Krishnamurthy | ea6d25f | 2021-09-14 15:27:06 -0700 | [diff] [blame] | 322 | #define FFA_MEM_PERM_RO UINT32_C(0x7) |
| 323 | #define FFA_MEM_PERM_RW UINT32_C(0x5) |
| 324 | #define FFA_MEM_PERM_RX UINT32_C(0x3) |
| 325 | |
Daniel Boulby | b46cad1 | 2021-12-13 17:47:21 +0000 | [diff] [blame] | 326 | /* |
Olivier Deprez | 013f4d6 | 2022-11-21 15:46:20 +0100 | [diff] [blame] | 327 | * Defined in Table 13.34 in the FF-A v1.1 EAC0 specification. |
Daniel Boulby | b46cad1 | 2021-12-13 17:47:21 +0000 | [diff] [blame] | 328 | * The Partition count flag is used by FFA_PARTITION_INFO_GET to specify |
| 329 | * if partition info descriptors should be returned or just the count. |
| 330 | */ |
Olivier Deprez | 013f4d6 | 2022-11-21 15:46:20 +0100 | [diff] [blame] | 331 | #define FFA_PARTITION_COUNT_FLAG UINT32_C(0x1) |
| 332 | #define FFA_PARTITION_COUNT_FLAG_MASK (UINT32_C(0x1) << 0) |
Daniel Boulby | b46cad1 | 2021-12-13 17:47:21 +0000 | [diff] [blame] | 333 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 334 | /** |
| 335 | * For use where the FF-A specification refers explicitly to '4K pages'. Not to |
| 336 | * be confused with PAGE_SIZE, which is the translation granule Hafnium is |
| 337 | * configured to use. |
| 338 | */ |
J-Alves | 715d623 | 2023-02-16 16:33:28 +0000 | [diff] [blame] | 339 | #define FFA_PAGE_SIZE ((size_t)4096) |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 340 | |
Federico Recanati | fc0295e | 2022-02-08 19:37:39 +0100 | [diff] [blame] | 341 | /** The ID of a VM. These are assigned sequentially starting with an offset. */ |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 342 | typedef uint16_t ffa_id_t; |
Federico Recanati | fc0295e | 2022-02-08 19:37:39 +0100 | [diff] [blame] | 343 | |
| 344 | /** |
J-Alves | 661e1b7 | 2023-08-02 13:39:40 +0100 | [diff] [blame] | 345 | * The FF-A v1.2 ALP0, section 6.1 defines that partition IDs are split into two |
| 346 | * parts: |
| 347 | * - Bit15 -> partition type identifier. |
| 348 | * - b'0 -> ID relates to a VM ID. |
| 349 | * - b'1 -> ID relates to an SP ID. |
| 350 | */ |
| 351 | #define FFA_ID_MASK ((ffa_id_t)0x8000) |
| 352 | #define FFA_VM_ID_MASK ((ffa_id_t)0x0000) |
| 353 | |
| 354 | /** |
| 355 | * Helper to check if FF-A ID is a VM ID, managed by the hypervisor. |
| 356 | */ |
| 357 | static inline bool ffa_is_vm_id(ffa_id_t id) |
| 358 | { |
| 359 | return (FFA_ID_MASK & id) == FFA_VM_ID_MASK; |
| 360 | } |
| 361 | |
| 362 | /** |
Federico Recanati | fc0295e | 2022-02-08 19:37:39 +0100 | [diff] [blame] | 363 | * Partition message header as specified by table 6.2 from FF-A v1.1 EAC0 |
| 364 | * specification. |
| 365 | */ |
| 366 | struct ffa_partition_rxtx_header { |
| 367 | uint32_t flags; /* MBZ */ |
| 368 | uint32_t reserved; |
| 369 | /* Offset from the beginning of the buffer to the message payload. */ |
| 370 | uint32_t offset; |
| 371 | /* Sender(Bits[31:16]) and Receiver(Bits[15:0]) endpoint IDs. */ |
| 372 | uint32_t sender_receiver; |
| 373 | /* Size of message in buffer. */ |
| 374 | uint32_t size; |
| 375 | }; |
| 376 | |
| 377 | #define FFA_RXTX_HEADER_SIZE sizeof(struct ffa_partition_rxtx_header) |
| 378 | #define FFA_RXTX_SENDER_SHIFT (0x10U) |
J-Alves | 7007993 | 2022-12-07 17:32:20 +0000 | [diff] [blame] | 379 | #define FFA_RXTX_ALLOCATOR_SHIFT 16 |
Federico Recanati | fc0295e | 2022-02-08 19:37:39 +0100 | [diff] [blame] | 380 | |
| 381 | static inline void ffa_rxtx_header_init( |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 382 | ffa_id_t sender, ffa_id_t receiver, uint32_t size, |
Federico Recanati | fc0295e | 2022-02-08 19:37:39 +0100 | [diff] [blame] | 383 | struct ffa_partition_rxtx_header *header) |
| 384 | { |
| 385 | header->flags = 0; |
| 386 | header->reserved = 0; |
| 387 | header->offset = FFA_RXTX_HEADER_SIZE; |
| 388 | header->sender_receiver = |
| 389 | (uint32_t)(receiver | (sender << FFA_RXTX_SENDER_SHIFT)); |
| 390 | header->size = size; |
| 391 | } |
| 392 | |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 393 | static inline ffa_id_t ffa_rxtx_header_sender( |
Federico Recanati | fc0295e | 2022-02-08 19:37:39 +0100 | [diff] [blame] | 394 | const struct ffa_partition_rxtx_header *h) |
| 395 | { |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 396 | return (ffa_id_t)(h->sender_receiver >> FFA_RXTX_SENDER_SHIFT); |
Federico Recanati | fc0295e | 2022-02-08 19:37:39 +0100 | [diff] [blame] | 397 | } |
| 398 | |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 399 | static inline ffa_id_t ffa_rxtx_header_receiver( |
Federico Recanati | fc0295e | 2022-02-08 19:37:39 +0100 | [diff] [blame] | 400 | const struct ffa_partition_rxtx_header *h) |
| 401 | { |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 402 | return (ffa_id_t)(h->sender_receiver); |
Federico Recanati | fc0295e | 2022-02-08 19:37:39 +0100 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | /* The maximum length possible for a single message. */ |
| 406 | #define FFA_PARTITION_MSG_PAYLOAD_MAX (HF_MAILBOX_SIZE - FFA_RXTX_HEADER_SIZE) |
| 407 | |
| 408 | struct ffa_partition_msg { |
| 409 | struct ffa_partition_rxtx_header header; |
| 410 | char payload[FFA_PARTITION_MSG_PAYLOAD_MAX]; |
| 411 | }; |
| 412 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 413 | /* The maximum length possible for a single message. */ |
| 414 | #define FFA_MSG_PAYLOAD_MAX HF_MAILBOX_SIZE |
| 415 | |
| 416 | enum ffa_data_access { |
| 417 | FFA_DATA_ACCESS_NOT_SPECIFIED, |
| 418 | FFA_DATA_ACCESS_RO, |
| 419 | FFA_DATA_ACCESS_RW, |
| 420 | FFA_DATA_ACCESS_RESERVED, |
| 421 | }; |
| 422 | |
Karl Meakin | f98b2aa | 2023-10-12 16:09:59 +0100 | [diff] [blame] | 423 | static inline const char *ffa_data_access_name(enum ffa_data_access data_access) |
| 424 | { |
| 425 | switch (data_access) { |
| 426 | case FFA_DATA_ACCESS_NOT_SPECIFIED: |
| 427 | return "FFA_DATA_ACCESS_NOT_SPECIFIED"; |
| 428 | case FFA_DATA_ACCESS_RO: |
| 429 | return "FFA_DATA_ACCESS_RO"; |
| 430 | case FFA_DATA_ACCESS_RW: |
| 431 | return "FFA_DATA_ACCESS_RW"; |
| 432 | case FFA_DATA_ACCESS_RESERVED: |
| 433 | return "FFA_DATA_ACCESS_RESERVED"; |
| 434 | } |
| 435 | } |
| 436 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 437 | enum ffa_instruction_access { |
| 438 | FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED, |
| 439 | FFA_INSTRUCTION_ACCESS_NX, |
| 440 | FFA_INSTRUCTION_ACCESS_X, |
| 441 | FFA_INSTRUCTION_ACCESS_RESERVED, |
| 442 | }; |
| 443 | |
Karl Meakin | f98b2aa | 2023-10-12 16:09:59 +0100 | [diff] [blame] | 444 | static inline const char *ffa_instruction_access_name( |
| 445 | enum ffa_instruction_access instruction_access) |
| 446 | { |
| 447 | switch (instruction_access) { |
| 448 | case FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED: |
| 449 | return "FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED"; |
| 450 | case FFA_INSTRUCTION_ACCESS_NX: |
| 451 | return "FFA_INSTRUCTION_ACCESS_NX"; |
| 452 | case FFA_INSTRUCTION_ACCESS_X: |
| 453 | return "FFA_INSTRUCTION_ACCESS_X"; |
| 454 | case FFA_INSTRUCTION_ACCESS_RESERVED: |
| 455 | return "FFA_INSTRUCTION_ACCESS_RESERVED"; |
| 456 | } |
| 457 | } |
| 458 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 459 | enum ffa_memory_type { |
| 460 | FFA_MEMORY_NOT_SPECIFIED_MEM, |
| 461 | FFA_MEMORY_DEVICE_MEM, |
| 462 | FFA_MEMORY_NORMAL_MEM, |
| 463 | }; |
| 464 | |
Karl Meakin | f98b2aa | 2023-10-12 16:09:59 +0100 | [diff] [blame] | 465 | static inline const char *ffa_memory_type_name(enum ffa_memory_type type) |
| 466 | { |
| 467 | switch (type) { |
| 468 | case FFA_MEMORY_NOT_SPECIFIED_MEM: |
| 469 | return "FFA_MEMORY_NOT_SPECIFIED_MEM"; |
| 470 | case FFA_MEMORY_DEVICE_MEM: |
| 471 | return "FFA_MEMORY_DEVICE_MEM"; |
| 472 | case FFA_MEMORY_NORMAL_MEM: |
| 473 | return "FFA_MEMORY_NORMAL_MEM"; |
| 474 | } |
| 475 | } |
| 476 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 477 | enum ffa_memory_cacheability { |
| 478 | FFA_MEMORY_CACHE_RESERVED = 0x0, |
| 479 | FFA_MEMORY_CACHE_NON_CACHEABLE = 0x1, |
| 480 | FFA_MEMORY_CACHE_RESERVED_1 = 0x2, |
| 481 | FFA_MEMORY_CACHE_WRITE_BACK = 0x3, |
| 482 | FFA_MEMORY_DEV_NGNRNE = 0x0, |
| 483 | FFA_MEMORY_DEV_NGNRE = 0x1, |
| 484 | FFA_MEMORY_DEV_NGRE = 0x2, |
| 485 | FFA_MEMORY_DEV_GRE = 0x3, |
| 486 | }; |
| 487 | |
Karl Meakin | f98b2aa | 2023-10-12 16:09:59 +0100 | [diff] [blame] | 488 | static inline const char *ffa_memory_cacheability_name( |
| 489 | enum ffa_memory_cacheability cacheability) |
| 490 | { |
| 491 | switch (cacheability) { |
| 492 | case FFA_MEMORY_CACHE_RESERVED: |
| 493 | return "FFA_MEMORY_CACHE_RESERVED"; |
| 494 | case FFA_MEMORY_CACHE_NON_CACHEABLE: |
| 495 | return "FFA_MEMORY_CACHE_NON_CACHEABLE"; |
| 496 | case FFA_MEMORY_CACHE_RESERVED_1: |
| 497 | return "FFA_MEMORY_CACHE_RESERVED_1"; |
| 498 | case FFA_MEMORY_CACHE_WRITE_BACK: |
| 499 | return "FFA_MEMORY_CACHE_WRITE_BACK"; |
| 500 | } |
| 501 | } |
| 502 | |
Daniel Boulby | 9764ff6 | 2024-01-30 17:47:39 +0000 | [diff] [blame] | 503 | static inline const char *ffa_device_memory_cacheability_name( |
| 504 | enum ffa_memory_cacheability cacheability) |
| 505 | { |
| 506 | switch (cacheability) { |
| 507 | case FFA_MEMORY_DEV_NGNRNE: |
| 508 | return "FFA_MEMORY_DEV_NGNRNE"; |
| 509 | case FFA_MEMORY_DEV_NGNRE: |
| 510 | return "FFA_MEMORY_DEV_NGNRE"; |
| 511 | case FFA_MEMORY_DEV_NGRE: |
| 512 | return "FFA_MEMORY_DEV_NGRE"; |
| 513 | case FFA_MEMORY_DEV_GRE: |
| 514 | return "FFA_MEMORY_DEV_GRE"; |
| 515 | } |
| 516 | } |
| 517 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 518 | enum ffa_memory_shareability { |
| 519 | FFA_MEMORY_SHARE_NON_SHAREABLE, |
| 520 | FFA_MEMORY_SHARE_RESERVED, |
| 521 | FFA_MEMORY_OUTER_SHAREABLE, |
| 522 | FFA_MEMORY_INNER_SHAREABLE, |
| 523 | }; |
| 524 | |
Karl Meakin | f98b2aa | 2023-10-12 16:09:59 +0100 | [diff] [blame] | 525 | static inline const char *ffa_memory_shareability_name( |
| 526 | enum ffa_memory_shareability shareability) |
| 527 | { |
| 528 | switch (shareability) { |
| 529 | case FFA_MEMORY_SHARE_NON_SHAREABLE: |
| 530 | return "FFA_MEMORY_SHARE_NON_SHAREABLE"; |
| 531 | case FFA_MEMORY_SHARE_RESERVED: |
| 532 | return "FFA_MEMORY_SHARE_RESERVED"; |
| 533 | case FFA_MEMORY_OUTER_SHAREABLE: |
| 534 | return "FFA_MEMORY_OUTER_SHAREABLE"; |
| 535 | case FFA_MEMORY_INNER_SHAREABLE: |
| 536 | return "FFA_MEMORY_INNER_SHAREABLE"; |
| 537 | } |
| 538 | } |
| 539 | |
Olivier Deprez | 4342a3c | 2022-02-28 09:37:25 +0100 | [diff] [blame] | 540 | /** |
| 541 | * FF-A v1.1 REL0 Table 10.18 memory region attributes descriptor NS Bit 6. |
| 542 | * Per section 10.10.4.1, NS bit is reserved for FFA_MEM_DONATE/LEND/SHARE |
| 543 | * and FFA_MEM_RETRIEVE_REQUEST. |
| 544 | */ |
| 545 | enum ffa_memory_security { |
| 546 | FFA_MEMORY_SECURITY_UNSPECIFIED = 0, |
| 547 | FFA_MEMORY_SECURITY_SECURE = 0, |
| 548 | FFA_MEMORY_SECURITY_NON_SECURE, |
| 549 | }; |
| 550 | |
Karl Meakin | f98b2aa | 2023-10-12 16:09:59 +0100 | [diff] [blame] | 551 | static inline const char *ffa_memory_security_name( |
| 552 | enum ffa_memory_security security) |
| 553 | { |
| 554 | switch (security) { |
| 555 | case FFA_MEMORY_SECURITY_UNSPECIFIED: |
| 556 | return "FFA_MEMORY_SECURITY_UNSPECIFIED"; |
| 557 | case FFA_MEMORY_SECURITY_NON_SECURE: |
| 558 | return "FFA_MEMORY_SECURITY_NON_SECURE"; |
| 559 | } |
| 560 | } |
| 561 | |
Karl Meakin | 84710f3 | 2023-10-12 15:14:49 +0100 | [diff] [blame] | 562 | typedef struct { |
| 563 | uint8_t data_access : 2; |
| 564 | uint8_t instruction_access : 2; |
| 565 | } ffa_memory_access_permissions_t; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 566 | |
| 567 | /** |
J-Alves | 0b6653d | 2022-04-22 13:17:38 +0100 | [diff] [blame] | 568 | * This corresponds to table 10.18 of the FF-A v1.1 EAC0 specification, "Memory |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 569 | * region attributes descriptor". |
| 570 | */ |
Karl Meakin | 84710f3 | 2023-10-12 15:14:49 +0100 | [diff] [blame] | 571 | typedef struct { |
| 572 | uint8_t shareability : 2; |
| 573 | uint8_t cacheability : 2; |
| 574 | uint8_t type : 2; |
| 575 | uint8_t security : 2; |
| 576 | uint8_t : 8; |
| 577 | } ffa_memory_attributes_t; |
J-Alves | 0b6653d | 2022-04-22 13:17:38 +0100 | [diff] [blame] | 578 | |
| 579 | /* FF-A v1.1 EAC0 states bit [15:7] Must Be Zero. */ |
| 580 | #define FFA_MEMORY_ATTRIBUTES_MBZ_MASK 0xFF80U |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 581 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 582 | /** |
| 583 | * A globally-unique ID assigned by the hypervisor for a region of memory being |
| 584 | * sent between VMs. |
| 585 | */ |
| 586 | typedef uint64_t ffa_memory_handle_t; |
| 587 | |
J-Alves | 917d2f2 | 2020-10-30 18:39:30 +0000 | [diff] [blame] | 588 | #define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \ |
| 589 | ((ffa_memory_handle_t)(UINT64_C(1) << 63)) |
| 590 | #define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR \ |
| 591 | ((ffa_memory_handle_t)(UINT64_C(1) << 63)) |
| 592 | |
| 593 | #define FFA_MEMORY_HANDLE_ALLOCATOR_SPMC (UINT64_C(0) << 63) |
| 594 | #define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0)) |
| 595 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 596 | /** |
| 597 | * A count of VMs. This has the same range as the VM IDs but we give it a |
| 598 | * different name to make the different semantics clear. |
| 599 | */ |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 600 | typedef ffa_id_t ffa_vm_count_t; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 601 | |
| 602 | /** The index of a vCPU within a particular VM. */ |
| 603 | typedef uint16_t ffa_vcpu_index_t; |
| 604 | |
| 605 | /** |
| 606 | * A count of vCPUs. This has the same range as the vCPU indices but we give it |
| 607 | * a different name to make the different semantics clear. |
| 608 | */ |
| 609 | typedef ffa_vcpu_index_t ffa_vcpu_count_t; |
| 610 | |
| 611 | /** Parameter and return type of FF-A functions. */ |
| 612 | struct ffa_value { |
| 613 | uint64_t func; |
| 614 | uint64_t arg1; |
| 615 | uint64_t arg2; |
| 616 | uint64_t arg3; |
| 617 | uint64_t arg4; |
| 618 | uint64_t arg5; |
| 619 | uint64_t arg6; |
| 620 | uint64_t arg7; |
Raghu Krishnamurthy | 567068e | 2022-12-26 07:46:38 -0800 | [diff] [blame] | 621 | |
| 622 | struct { |
| 623 | uint64_t arg8; |
| 624 | uint64_t arg9; |
| 625 | uint64_t arg10; |
| 626 | uint64_t arg11; |
| 627 | uint64_t arg12; |
| 628 | uint64_t arg13; |
| 629 | uint64_t arg14; |
| 630 | uint64_t arg15; |
| 631 | uint64_t arg16; |
| 632 | uint64_t arg17; |
| 633 | bool valid; |
| 634 | } extended_val; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 635 | }; |
| 636 | |
Olivier Deprez | e562e54 | 2020-06-11 17:31:54 +0200 | [diff] [blame] | 637 | static inline uint32_t ffa_func_id(struct ffa_value args) |
| 638 | { |
| 639 | return args.func; |
| 640 | } |
| 641 | |
Karl Meakin | dc759f5 | 2024-05-07 16:08:02 +0100 | [diff] [blame] | 642 | static inline enum ffa_error ffa_error_code(struct ffa_value val) |
J-Alves | 13318e3 | 2021-02-22 17:21:00 +0000 | [diff] [blame] | 643 | { |
Karl Meakin | dc759f5 | 2024-05-07 16:08:02 +0100 | [diff] [blame] | 644 | return (enum ffa_error)val.arg2; |
J-Alves | 13318e3 | 2021-02-22 17:21:00 +0000 | [diff] [blame] | 645 | } |
| 646 | |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 647 | static inline ffa_id_t ffa_sender(struct ffa_value args) |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 648 | { |
| 649 | return (args.arg1 >> 16) & 0xffff; |
| 650 | } |
| 651 | |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 652 | static inline ffa_id_t ffa_receiver(struct ffa_value args) |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 653 | { |
| 654 | return args.arg1 & 0xffff; |
| 655 | } |
| 656 | |
| 657 | static inline uint32_t ffa_msg_send_size(struct ffa_value args) |
| 658 | { |
| 659 | return args.arg3; |
| 660 | } |
| 661 | |
Federico Recanati | 25053ee | 2022-03-14 15:01:53 +0100 | [diff] [blame] | 662 | static inline uint32_t ffa_msg_send2_flags(struct ffa_value args) |
| 663 | { |
| 664 | return args.arg2; |
| 665 | } |
| 666 | |
Olivier Deprez | e562e54 | 2020-06-11 17:31:54 +0200 | [diff] [blame] | 667 | static inline uint32_t ffa_partition_info_get_count(struct ffa_value args) |
| 668 | { |
| 669 | return args.arg2; |
| 670 | } |
| 671 | |
Raghu Krishnamurthy | 2957b92 | 2022-12-27 10:29:12 -0800 | [diff] [blame] | 672 | static inline uint16_t ffa_partition_info_regs_get_last_idx( |
| 673 | struct ffa_value args) |
| 674 | { |
| 675 | return args.arg2 & 0xFFFF; |
| 676 | } |
| 677 | |
| 678 | static inline uint16_t ffa_partition_info_regs_get_curr_idx( |
| 679 | struct ffa_value args) |
| 680 | { |
| 681 | return (args.arg2 >> 16) & 0xFFFF; |
| 682 | } |
| 683 | |
| 684 | static inline uint16_t ffa_partition_info_regs_get_tag(struct ffa_value args) |
| 685 | { |
| 686 | return (args.arg2 >> 32) & 0xFFFF; |
| 687 | } |
| 688 | |
| 689 | static inline uint16_t ffa_partition_info_regs_get_desc_size( |
| 690 | struct ffa_value args) |
| 691 | { |
| 692 | return (args.arg2 >> 48); |
| 693 | } |
| 694 | |
Andrew Walbran | 1bbe940 | 2020-04-30 16:47:13 +0100 | [diff] [blame] | 695 | static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t a1, uint32_t a2) |
| 696 | { |
| 697 | return (uint64_t)a1 | (uint64_t)a2 << 32; |
| 698 | } |
| 699 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 700 | static inline ffa_memory_handle_t ffa_mem_success_handle(struct ffa_value args) |
| 701 | { |
Andrew Walbran | 1bbe940 | 2020-04-30 16:47:13 +0100 | [diff] [blame] | 702 | return ffa_assemble_handle(args.arg2, args.arg3); |
| 703 | } |
| 704 | |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 705 | static inline ffa_memory_handle_t ffa_frag_handle(struct ffa_value args) |
| 706 | { |
| 707 | return ffa_assemble_handle(args.arg1, args.arg2); |
| 708 | } |
| 709 | |
Andrew Walbran | 1bbe940 | 2020-04-30 16:47:13 +0100 | [diff] [blame] | 710 | static inline struct ffa_value ffa_mem_success(ffa_memory_handle_t handle) |
| 711 | { |
| 712 | return (struct ffa_value){.func = FFA_SUCCESS_32, |
| 713 | .arg2 = (uint32_t)handle, |
| 714 | .arg3 = (uint32_t)(handle >> 32)}; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 715 | } |
| 716 | |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 717 | static inline ffa_id_t ffa_vm_id(struct ffa_value args) |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 718 | { |
| 719 | return (args.arg1 >> 16) & 0xffff; |
| 720 | } |
| 721 | |
| 722 | static inline ffa_vcpu_index_t ffa_vcpu_index(struct ffa_value args) |
| 723 | { |
| 724 | return args.arg1 & 0xffff; |
| 725 | } |
| 726 | |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 727 | static inline uint64_t ffa_vm_vcpu(ffa_id_t vm_id, ffa_vcpu_index_t vcpu_index) |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 728 | { |
| 729 | return ((uint32_t)vm_id << 16) | vcpu_index; |
| 730 | } |
| 731 | |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 732 | static inline ffa_id_t ffa_frag_sender(struct ffa_value args) |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 733 | { |
| 734 | return (args.arg4 >> 16) & 0xffff; |
| 735 | } |
| 736 | |
J-Alves | 6f72ca8 | 2021-11-01 12:34:58 +0000 | [diff] [blame] | 737 | static inline uint32_t ffa_feature_intid(struct ffa_value args) |
| 738 | { |
| 739 | return (uint32_t)args.arg2; |
| 740 | } |
| 741 | |
Daniel Boulby | efa381f | 2022-01-18 14:49:40 +0000 | [diff] [blame] | 742 | static inline uint32_t ffa_fwk_msg(struct ffa_value args) |
| 743 | { |
| 744 | return (uint32_t)args.arg2; |
| 745 | } |
| 746 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 747 | /** |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 748 | * Holds the UUID in a struct that is mappable directly to the SMCC calling |
| 749 | * convention, which is used for FF-A calls. |
| 750 | * |
| 751 | * Refer to table 84 of the FF-A 1.0 EAC specification as well as section 5.3 |
| 752 | * of the SMCC Spec 1.2. |
| 753 | */ |
| 754 | struct ffa_uuid { |
| 755 | uint32_t uuid[4]; |
| 756 | }; |
| 757 | |
| 758 | static inline void ffa_uuid_init(uint32_t w0, uint32_t w1, uint32_t w2, |
| 759 | uint32_t w3, struct ffa_uuid *uuid) |
| 760 | { |
| 761 | uuid->uuid[0] = w0; |
| 762 | uuid->uuid[1] = w1; |
| 763 | uuid->uuid[2] = w2; |
| 764 | uuid->uuid[3] = w3; |
| 765 | } |
| 766 | |
| 767 | static inline bool ffa_uuid_equal(const struct ffa_uuid *uuid1, |
| 768 | const struct ffa_uuid *uuid2) |
| 769 | { |
| 770 | return (uuid1->uuid[0] == uuid2->uuid[0]) && |
| 771 | (uuid1->uuid[1] == uuid2->uuid[1]) && |
| 772 | (uuid1->uuid[2] == uuid2->uuid[2]) && |
| 773 | (uuid1->uuid[3] == uuid2->uuid[3]); |
| 774 | } |
| 775 | |
| 776 | static inline bool ffa_uuid_is_null(const struct ffa_uuid *uuid) |
| 777 | { |
| 778 | return (uuid->uuid[0] == 0) && (uuid->uuid[1] == 0) && |
| 779 | (uuid->uuid[2] == 0) && (uuid->uuid[3] == 0); |
| 780 | } |
| 781 | |
Kathleen Capella | 41fea93 | 2023-06-23 17:39:28 -0400 | [diff] [blame] | 782 | static inline void ffa_uuid_unpack_from_uint64(uint64_t uuid_lo, |
| 783 | uint64_t uuid_hi, |
| 784 | struct ffa_uuid *uuid) |
| 785 | { |
| 786 | ffa_uuid_init((uint32_t)(uuid_lo & 0xFFFFFFFFU), |
| 787 | (uint32_t)(uuid_lo >> 32), |
| 788 | (uint32_t)(uuid_hi & 0xFFFFFFFFU), |
| 789 | (uint32_t)(uuid_hi >> 32), uuid); |
| 790 | } |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 791 | /** |
| 792 | * Flags to determine the partition properties, as required by |
| 793 | * FFA_PARTITION_INFO_GET. |
| 794 | * |
Kathleen Capella | f71dee4 | 2023-08-08 16:24:14 -0400 | [diff] [blame] | 795 | * The values of the flags are specified in table 6.2 of DEN0077A FF-A 1.2 ALP0 |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 796 | * specification, "Partition information descriptor, partition properties". |
| 797 | */ |
| 798 | typedef uint32_t ffa_partition_properties_t; |
| 799 | |
Kathleen Capella | f71dee4 | 2023-08-08 16:24:14 -0400 | [diff] [blame] | 800 | /** |
| 801 | * Partition property: partition supports receipt of direct requests via the |
| 802 | * FFA_MSG_SEND_DIRECT_REQ ABI. |
| 803 | */ |
Kathleen Capella | 402fa85 | 2022-11-09 16:16:51 -0500 | [diff] [blame] | 804 | #define FFA_PARTITION_DIRECT_REQ_RECV (UINT32_C(1) << 0) |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 805 | |
Kathleen Capella | f71dee4 | 2023-08-08 16:24:14 -0400 | [diff] [blame] | 806 | /** |
| 807 | * Partition property: partition can send direct requests via the |
| 808 | * FFA_MSG_SEND_DIRECT_REQ ABI. |
| 809 | */ |
Kathleen Capella | 402fa85 | 2022-11-09 16:16:51 -0500 | [diff] [blame] | 810 | #define FFA_PARTITION_DIRECT_REQ_SEND (UINT32_C(1) << 1) |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 811 | |
| 812 | /** Partition property: partition can send and receive indirect messages. */ |
Kathleen Capella | 402fa85 | 2022-11-09 16:16:51 -0500 | [diff] [blame] | 813 | #define FFA_PARTITION_INDIRECT_MSG (UINT32_C(1) << 2) |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 814 | |
J-Alves | 09ff9d8 | 2021-11-02 11:55:20 +0000 | [diff] [blame] | 815 | /** Partition property: partition can receive notifications. */ |
Kathleen Capella | 402fa85 | 2022-11-09 16:16:51 -0500 | [diff] [blame] | 816 | #define FFA_PARTITION_NOTIFICATION (UINT32_C(1) << 3) |
| 817 | |
| 818 | /** Partition property: partition runs in the AArch64 execution state. */ |
| 819 | #define FFA_PARTITION_AARCH64_EXEC (UINT32_C(1) << 8) |
J-Alves | 09ff9d8 | 2021-11-02 11:55:20 +0000 | [diff] [blame] | 820 | |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 821 | /** |
Kathleen Capella | f71dee4 | 2023-08-08 16:24:14 -0400 | [diff] [blame] | 822 | * Partition property: partition supports receipt of direct requests via the |
| 823 | * FFA_MSG_SEND_DIRECT_REQ2 ABI. |
| 824 | */ |
| 825 | #define FFA_PARTITION_DIRECT_REQ2_RECV (UINT32_C(1) << 9) |
| 826 | |
| 827 | /** |
| 828 | * Partition property: partition can send direct requests via the |
| 829 | * FFA_MSG_SEND_DIRECT_REQ2 ABI. |
| 830 | */ |
| 831 | #define FFA_PARTITION_DIRECT_REQ2_SEND (UINT32_C(1) << 10) |
| 832 | |
| 833 | /** |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 834 | * Holds information returned for each partition by the FFA_PARTITION_INFO_GET |
| 835 | * interface. |
Kathleen Capella | 402fa85 | 2022-11-09 16:16:51 -0500 | [diff] [blame] | 836 | * This corresponds to table 13.37 "Partition information descriptor" |
| 837 | * in FF-A 1.1 EAC0 specification. |
Daniel Boulby | 1ddb3d7 | 2021-12-16 18:16:50 +0000 | [diff] [blame] | 838 | */ |
| 839 | struct ffa_partition_info { |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 840 | ffa_id_t vm_id; |
Daniel Boulby | 1ddb3d7 | 2021-12-16 18:16:50 +0000 | [diff] [blame] | 841 | ffa_vcpu_count_t vcpu_count; |
| 842 | ffa_partition_properties_t properties; |
| 843 | struct ffa_uuid uuid; |
| 844 | }; |
| 845 | |
J-Alves | dd1ad57 | 2022-01-25 17:58:26 +0000 | [diff] [blame] | 846 | /** Length in bytes of the name in boot information descriptor. */ |
| 847 | #define FFA_BOOT_INFO_NAME_LEN 16 |
| 848 | |
J-Alves | 240d84c | 2022-04-22 12:19:34 +0100 | [diff] [blame] | 849 | /** |
| 850 | * The FF-A boot info descriptor, as defined in table 5.8 of section 5.4.1, of |
| 851 | * the FF-A v1.1 EAC0 specification. |
| 852 | */ |
J-Alves | dd1ad57 | 2022-01-25 17:58:26 +0000 | [diff] [blame] | 853 | struct ffa_boot_info_desc { |
| 854 | char name[FFA_BOOT_INFO_NAME_LEN]; |
| 855 | uint8_t type; |
| 856 | uint8_t reserved; |
| 857 | uint16_t flags; |
| 858 | uint32_t size; |
| 859 | uint64_t content; |
| 860 | }; |
| 861 | |
| 862 | /** FF-A boot information type mask. */ |
| 863 | #define FFA_BOOT_INFO_TYPE_SHIFT 7 |
| 864 | #define FFA_BOOT_INFO_TYPE_MASK (0x1U << FFA_BOOT_INFO_TYPE_SHIFT) |
| 865 | #define FFA_BOOT_INFO_TYPE_STD 0U |
| 866 | #define FFA_BOOT_INFO_TYPE_IMPDEF 1U |
| 867 | |
| 868 | /** Standard boot info type IDs. */ |
| 869 | #define FFA_BOOT_INFO_TYPE_ID_MASK 0x7FU |
| 870 | #define FFA_BOOT_INFO_TYPE_ID_FDT 0U |
| 871 | #define FFA_BOOT_INFO_TYPE_ID_HOB 1U |
| 872 | |
| 873 | /** FF-A Boot Info descriptors flags. */ |
| 874 | #define FFA_BOOT_INFO_FLAG_MBZ_MASK 0xFFF0U |
| 875 | |
| 876 | /** Bits [1:0] encode the format of the name field in ffa_boot_info_desc. */ |
| 877 | #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT 0U |
| 878 | #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK \ |
| 879 | (0x3U << FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT) |
| 880 | #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING 0x0U |
| 881 | #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID 0x1U |
| 882 | |
| 883 | /** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */ |
| 884 | #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT 2 |
| 885 | #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK \ |
| 886 | (0x3U << FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT) |
| 887 | #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE 0x1U |
| 888 | #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR 0x0U |
| 889 | |
| 890 | static inline uint16_t ffa_boot_info_content_format( |
| 891 | struct ffa_boot_info_desc *desc) |
| 892 | { |
| 893 | return (desc->flags & FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK) >> |
| 894 | FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT; |
| 895 | } |
| 896 | |
| 897 | static inline uint16_t ffa_boot_info_name_format( |
| 898 | struct ffa_boot_info_desc *desc) |
| 899 | { |
| 900 | return (desc->flags & FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK) >> |
| 901 | FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT; |
| 902 | } |
| 903 | |
| 904 | static inline uint8_t ffa_boot_info_type_id(struct ffa_boot_info_desc *desc) |
| 905 | { |
| 906 | return desc->type & FFA_BOOT_INFO_TYPE_ID_MASK; |
| 907 | } |
| 908 | |
| 909 | static inline uint8_t ffa_boot_info_type(struct ffa_boot_info_desc *desc) |
| 910 | { |
| 911 | return (desc->type & FFA_BOOT_INFO_TYPE_MASK) >> |
| 912 | FFA_BOOT_INFO_TYPE_SHIFT; |
| 913 | } |
| 914 | |
| 915 | /** Length in bytes of the signature in the boot descriptor. */ |
| 916 | #define FFA_BOOT_INFO_HEADER_SIGNATURE_LEN 4 |
| 917 | |
J-Alves | 240d84c | 2022-04-22 12:19:34 +0100 | [diff] [blame] | 918 | /** |
| 919 | * The FF-A boot information header, as defined in table 5.9 of section 5.4.2, |
| 920 | * of the FF-A v1.1 EAC0 specification. |
| 921 | */ |
J-Alves | dd1ad57 | 2022-01-25 17:58:26 +0000 | [diff] [blame] | 922 | struct ffa_boot_info_header { |
| 923 | uint32_t signature; |
| 924 | uint32_t version; |
| 925 | uint32_t info_blob_size; |
| 926 | uint32_t desc_size; |
| 927 | uint32_t desc_count; |
| 928 | uint32_t desc_offset; |
| 929 | uint64_t reserved; |
| 930 | struct ffa_boot_info_desc boot_info[]; |
| 931 | }; |
| 932 | |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 933 | /** |
J-Alves | 980d199 | 2021-03-18 12:49:18 +0000 | [diff] [blame] | 934 | * FF-A v1.1 specification restricts the number of notifications to a maximum |
| 935 | * of 64. Following all possible bitmaps. |
| 936 | */ |
| 937 | #define FFA_NOTIFICATION_MASK(ID) (UINT64_C(1) << ID) |
| 938 | |
| 939 | typedef uint64_t ffa_notifications_bitmap_t; |
| 940 | |
| 941 | #define MAX_FFA_NOTIFICATIONS 64U |
| 942 | |
| 943 | /** |
J-Alves | c003a7a | 2021-03-18 13:06:53 +0000 | [diff] [blame] | 944 | * Flag for notification bind and set, to specify call is about per-vCPU |
| 945 | * notifications. |
| 946 | */ |
Olivier Deprez | b76307d | 2022-06-09 17:17:45 +0200 | [diff] [blame] | 947 | #define FFA_NOTIFICATION_FLAG_PER_VCPU (UINT32_C(1) << 0) |
J-Alves | c003a7a | 2021-03-18 13:06:53 +0000 | [diff] [blame] | 948 | |
Federico Recanati | e73d283 | 2022-04-20 11:10:52 +0200 | [diff] [blame] | 949 | #define FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(0) |
| 950 | #define FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(32) |
| 951 | |
| 952 | /** |
| 953 | * Helper functions to check for buffer full notification. |
| 954 | */ |
| 955 | static inline bool is_ffa_hyp_buffer_full_notification( |
| 956 | ffa_notifications_bitmap_t framework) |
| 957 | { |
| 958 | return (framework & FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK) != 0; |
| 959 | } |
| 960 | |
| 961 | static inline bool is_ffa_spm_buffer_full_notification( |
| 962 | ffa_notifications_bitmap_t framework) |
| 963 | { |
| 964 | return (framework & FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK) != 0; |
| 965 | } |
| 966 | |
J-Alves | c003a7a | 2021-03-18 13:06:53 +0000 | [diff] [blame] | 967 | /** |
J-Alves | 980d199 | 2021-03-18 12:49:18 +0000 | [diff] [blame] | 968 | * Helper function to assemble a 64-bit sized bitmap, from the 32-bit sized lo |
| 969 | * and hi. |
| 970 | * Helpful as FF-A specification defines that the notifications interfaces |
| 971 | * arguments are 32-bit registers. |
| 972 | */ |
| 973 | static inline ffa_notifications_bitmap_t ffa_notifications_bitmap(uint32_t lo, |
| 974 | uint32_t hi) |
| 975 | { |
| 976 | return (ffa_notifications_bitmap_t)hi << 32U | lo; |
| 977 | } |
| 978 | |
J-Alves | 98ff956 | 2021-09-09 14:39:41 +0100 | [diff] [blame] | 979 | static inline ffa_notifications_bitmap_t ffa_notification_get_from_sp( |
| 980 | struct ffa_value val) |
| 981 | { |
| 982 | return ffa_notifications_bitmap((uint32_t)val.arg2, (uint32_t)val.arg3); |
| 983 | } |
| 984 | |
| 985 | static inline ffa_notifications_bitmap_t ffa_notification_get_from_vm( |
| 986 | struct ffa_value val) |
| 987 | { |
| 988 | return ffa_notifications_bitmap((uint32_t)val.arg4, (uint32_t)val.arg5); |
| 989 | } |
| 990 | |
Federico Recanati | e73d283 | 2022-04-20 11:10:52 +0200 | [diff] [blame] | 991 | static inline ffa_notifications_bitmap_t ffa_notification_get_from_framework( |
| 992 | struct ffa_value val) |
| 993 | { |
| 994 | return ffa_notifications_bitmap((uint32_t)val.arg6, (uint32_t)val.arg7); |
| 995 | } |
| 996 | |
J-Alves | 980d199 | 2021-03-18 12:49:18 +0000 | [diff] [blame] | 997 | /** |
J-Alves | aa79c01 | 2021-07-09 14:29:45 +0100 | [diff] [blame] | 998 | * Flags used in calls to FFA_NOTIFICATION_GET interface. |
| 999 | */ |
Olivier Deprez | b76307d | 2022-06-09 17:17:45 +0200 | [diff] [blame] | 1000 | #define FFA_NOTIFICATION_FLAG_BITMAP_SP (UINT32_C(1) << 0) |
| 1001 | #define FFA_NOTIFICATION_FLAG_BITMAP_VM (UINT32_C(1) << 1) |
| 1002 | #define FFA_NOTIFICATION_FLAG_BITMAP_SPM (UINT32_C(1) << 2) |
| 1003 | #define FFA_NOTIFICATION_FLAG_BITMAP_HYP (UINT32_C(1) << 3) |
J-Alves | aa79c01 | 2021-07-09 14:29:45 +0100 | [diff] [blame] | 1004 | |
J-Alves | a375507 | 2021-11-26 16:01:08 +0000 | [diff] [blame] | 1005 | /* Flag to configure notification as being per vCPU. */ |
Olivier Deprez | b76307d | 2022-06-09 17:17:45 +0200 | [diff] [blame] | 1006 | #define FFA_NOTIFICATIONS_FLAG_PER_VCPU (UINT32_C(1) << 0) |
J-Alves | a375507 | 2021-11-26 16:01:08 +0000 | [diff] [blame] | 1007 | |
J-Alves | 1339402 | 2021-06-30 13:48:49 +0100 | [diff] [blame] | 1008 | /** Flag for FFA_NOTIFICATION_SET to delay Schedule Receiver Interrupt */ |
Olivier Deprez | b76307d | 2022-06-09 17:17:45 +0200 | [diff] [blame] | 1009 | #define FFA_NOTIFICATIONS_FLAG_DELAY_SRI (UINT32_C(1) << 1) |
| 1010 | |
| 1011 | #define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) \ |
| 1012 | ((((uint32_t)(id)) & UINT32_C(0xffff)) << 16) |
J-Alves | 1339402 | 2021-06-30 13:48:49 +0100 | [diff] [blame] | 1013 | |
J-Alves | be6e303 | 2021-11-30 14:54:12 +0000 | [diff] [blame] | 1014 | static inline ffa_vcpu_index_t ffa_notifications_get_vcpu(struct ffa_value args) |
J-Alves | aa79c01 | 2021-07-09 14:29:45 +0100 | [diff] [blame] | 1015 | { |
J-Alves | be6e303 | 2021-11-30 14:54:12 +0000 | [diff] [blame] | 1016 | return (ffa_vcpu_index_t)(args.arg1 >> 16 & 0xffffU); |
J-Alves | aa79c01 | 2021-07-09 14:29:45 +0100 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | /** |
J-Alves | c8e8a22 | 2021-06-08 17:33:52 +0100 | [diff] [blame] | 1020 | * The max number of IDs for return of FFA_NOTIFICATION_INFO_GET. |
| 1021 | */ |
| 1022 | #define FFA_NOTIFICATIONS_INFO_GET_MAX_IDS 20U |
| 1023 | |
| 1024 | /** |
| 1025 | * Number of registers to use in successfull return of interface |
| 1026 | * FFA_NOTIFICATION_INFO_GET. |
| 1027 | */ |
| 1028 | #define FFA_NOTIFICATIONS_INFO_GET_REGS_RET 5U |
| 1029 | |
| 1030 | #define FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING 0x1U |
| 1031 | |
| 1032 | /** |
| 1033 | * Helper macros for return parameter encoding as described in section 17.7.1 |
| 1034 | * of the FF-A v1.1 Beta0 specification. |
| 1035 | */ |
| 1036 | #define FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT 0x7U |
| 1037 | #define FFA_NOTIFICATIONS_LISTS_COUNT_MASK 0x1fU |
| 1038 | #define FFA_NOTIFICATIONS_LIST_SHIFT(l) (2 * (l - 1) + 12) |
| 1039 | #define FFA_NOTIFICATIONS_LIST_SIZE_MASK 0x3U |
| 1040 | |
| 1041 | static inline uint32_t ffa_notification_info_get_lists_count( |
| 1042 | struct ffa_value args) |
| 1043 | { |
| 1044 | return (uint32_t)(args.arg2 >> FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT) & |
| 1045 | FFA_NOTIFICATIONS_LISTS_COUNT_MASK; |
| 1046 | } |
| 1047 | |
| 1048 | static inline uint32_t ffa_notification_info_get_list_size( |
| 1049 | struct ffa_value args, unsigned int list_idx) |
| 1050 | { |
| 1051 | return ((uint32_t)args.arg2 >> FFA_NOTIFICATIONS_LIST_SHIFT(list_idx)) & |
| 1052 | FFA_NOTIFICATIONS_LIST_SIZE_MASK; |
| 1053 | } |
| 1054 | |
| 1055 | static inline bool ffa_notification_info_get_more_pending(struct ffa_value args) |
| 1056 | { |
| 1057 | return (args.arg2 & FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING) != 0U; |
| 1058 | } |
| 1059 | |
| 1060 | /** |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1061 | * A set of contiguous pages which is part of a memory region. This corresponds |
J-Alves | 0b6653d | 2022-04-22 13:17:38 +0100 | [diff] [blame] | 1062 | * to table 10.14 of the FF-A v1.1 EAC0 specification, "Constituent memory |
| 1063 | * region descriptor". |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1064 | */ |
| 1065 | struct ffa_memory_region_constituent { |
| 1066 | /** |
| 1067 | * The base IPA of the constituent memory region, aligned to 4 kiB page |
| 1068 | * size granularity. |
| 1069 | */ |
| 1070 | uint64_t address; |
| 1071 | /** The number of 4 kiB pages in the constituent memory region. */ |
| 1072 | uint32_t page_count; |
| 1073 | /** Reserved field, must be 0. */ |
| 1074 | uint32_t reserved; |
| 1075 | }; |
| 1076 | |
| 1077 | /** |
J-Alves | 0b6653d | 2022-04-22 13:17:38 +0100 | [diff] [blame] | 1078 | * A set of pages comprising a memory region. This corresponds to table 10.13 of |
| 1079 | * the FF-A v1.1 EAC0 specification, "Composite memory region descriptor". |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1080 | */ |
| 1081 | struct ffa_composite_memory_region { |
| 1082 | /** |
| 1083 | * The total number of 4 kiB pages included in this memory region. This |
| 1084 | * must be equal to the sum of page counts specified in each |
| 1085 | * `ffa_memory_region_constituent`. |
| 1086 | */ |
| 1087 | uint32_t page_count; |
| 1088 | /** |
| 1089 | * The number of constituents (`ffa_memory_region_constituent`) |
| 1090 | * included in this memory region range. |
| 1091 | */ |
| 1092 | uint32_t constituent_count; |
| 1093 | /** Reserved field, must be 0. */ |
| 1094 | uint64_t reserved_0; |
| 1095 | /** An array of `constituent_count` memory region constituents. */ |
| 1096 | struct ffa_memory_region_constituent constituents[]; |
| 1097 | }; |
| 1098 | |
| 1099 | /** Flags to indicate properties of receivers during memory region retrieval. */ |
| 1100 | typedef uint8_t ffa_memory_receiver_flags_t; |
| 1101 | |
| 1102 | /** |
J-Alves | 0b6653d | 2022-04-22 13:17:38 +0100 | [diff] [blame] | 1103 | * This corresponds to table 10.15 of the FF-A v1.1 EAC0 specification, "Memory |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1104 | * access permissions descriptor". |
| 1105 | */ |
| 1106 | struct ffa_memory_region_attributes { |
| 1107 | /** The ID of the VM to which the memory is being given or shared. */ |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 1108 | ffa_id_t receiver; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1109 | /** |
| 1110 | * The permissions with which the memory region should be mapped in the |
| 1111 | * receiver's page table. |
| 1112 | */ |
| 1113 | ffa_memory_access_permissions_t permissions; |
| 1114 | /** |
| 1115 | * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP |
| 1116 | * for memory regions with multiple borrowers. |
| 1117 | */ |
| 1118 | ffa_memory_receiver_flags_t flags; |
| 1119 | }; |
| 1120 | |
| 1121 | /** Flags to control the behaviour of a memory sharing transaction. */ |
| 1122 | typedef uint32_t ffa_memory_region_flags_t; |
| 1123 | |
| 1124 | /** |
| 1125 | * Clear memory region contents after unmapping it from the sender and before |
| 1126 | * mapping it for any receiver. |
| 1127 | */ |
| 1128 | #define FFA_MEMORY_REGION_FLAG_CLEAR 0x1 |
| 1129 | |
| 1130 | /** |
| 1131 | * Whether the hypervisor may time slice the memory sharing or retrieval |
| 1132 | * operation. |
| 1133 | */ |
| 1134 | #define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2 |
| 1135 | |
| 1136 | /** |
| 1137 | * Whether the hypervisor should clear the memory region after the receiver |
| 1138 | * relinquishes it or is aborted. |
| 1139 | */ |
| 1140 | #define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4 |
| 1141 | |
J-Alves | 3456e03 | 2023-07-20 12:20:05 +0100 | [diff] [blame] | 1142 | /** |
| 1143 | * On retrieve request, bypass the multi-borrower check. |
| 1144 | */ |
| 1145 | #define FFA_MEMORY_REGION_FLAG_BYPASS_BORROWERS_CHECK (0x1U << 10) |
| 1146 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1147 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3) |
| 1148 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3) |
| 1149 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3) |
| 1150 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3) |
| 1151 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3) |
| 1152 | |
Federico Recanati | 85090c4 | 2021-12-15 13:17:54 +0100 | [diff] [blame] | 1153 | #define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_VALID ((0x1U) << 9) |
| 1154 | #define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_MASK ((0xFU) << 5) |
| 1155 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1156 | /** |
Daniel Boulby | de974ca | 2023-12-12 13:53:31 +0000 | [diff] [blame] | 1157 | * Struct to store the impdef value seen in Table 11.16 of the |
| 1158 | * FF-A v1.2 ALP0 specification "Endpoint memory access descriptor". |
| 1159 | */ |
| 1160 | struct ffa_memory_access_impdef { |
| 1161 | uint64_t val[2]; |
| 1162 | }; |
| 1163 | |
Daniel Boulby | e0ca9a0 | 2024-03-05 18:40:59 +0000 | [diff] [blame] | 1164 | static inline struct ffa_memory_access_impdef ffa_memory_access_impdef_init( |
| 1165 | uint64_t impdef_hi, uint64_t impdef_lo) |
| 1166 | { |
| 1167 | return (struct ffa_memory_access_impdef){{impdef_hi, impdef_lo}}; |
| 1168 | } |
| 1169 | |
Daniel Boulby | de974ca | 2023-12-12 13:53:31 +0000 | [diff] [blame] | 1170 | /** |
J-Alves | 0b6653d | 2022-04-22 13:17:38 +0100 | [diff] [blame] | 1171 | * This corresponds to table 10.16 of the FF-A v1.1 EAC0 specification, |
| 1172 | * "Endpoint memory access descriptor". |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1173 | */ |
| 1174 | struct ffa_memory_access { |
| 1175 | struct ffa_memory_region_attributes receiver_permissions; |
| 1176 | /** |
| 1177 | * Offset in bytes from the start of the outer `ffa_memory_region` to |
| 1178 | * an `ffa_composite_memory_region` struct. |
| 1179 | */ |
| 1180 | uint32_t composite_memory_region_offset; |
Daniel Boulby | de974ca | 2023-12-12 13:53:31 +0000 | [diff] [blame] | 1181 | struct ffa_memory_access_impdef impdef; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1182 | uint64_t reserved_0; |
| 1183 | }; |
| 1184 | |
J-Alves | 363f572 | 2022-04-25 17:37:37 +0100 | [diff] [blame] | 1185 | /** The maximum number of recipients a memory region may be sent to. */ |
J-Alves | ba0e617 | 2022-04-25 17:41:40 +0100 | [diff] [blame] | 1186 | #define MAX_MEM_SHARE_RECIPIENTS UINT32_C(2) |
J-Alves | 363f572 | 2022-04-25 17:37:37 +0100 | [diff] [blame] | 1187 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1188 | /** |
| 1189 | * Information about a set of pages which are being shared. This corresponds to |
J-Alves | 0b6653d | 2022-04-22 13:17:38 +0100 | [diff] [blame] | 1190 | * table 10.20 of the FF-A v1.1 EAC0 specification, "Lend, donate or share |
| 1191 | * memory transaction descriptor". Note that it is also used for retrieve |
| 1192 | * requests and responses. |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1193 | */ |
| 1194 | struct ffa_memory_region { |
| 1195 | /** |
| 1196 | * The ID of the VM which originally sent the memory region, i.e. the |
| 1197 | * owner. |
| 1198 | */ |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 1199 | ffa_id_t sender; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1200 | ffa_memory_attributes_t attributes; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1201 | /** Flags to control behaviour of the transaction. */ |
| 1202 | ffa_memory_region_flags_t flags; |
| 1203 | ffa_memory_handle_t handle; |
| 1204 | /** |
| 1205 | * An implementation defined value associated with the receiver and the |
| 1206 | * memory region. |
| 1207 | */ |
| 1208 | uint64_t tag; |
J-Alves | 0b6653d | 2022-04-22 13:17:38 +0100 | [diff] [blame] | 1209 | /* Size of the memory access descriptor. */ |
| 1210 | uint32_t memory_access_desc_size; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1211 | /** |
| 1212 | * The number of `ffa_memory_access` entries included in this |
| 1213 | * transaction. |
| 1214 | */ |
| 1215 | uint32_t receiver_count; |
| 1216 | /** |
J-Alves | 0b6653d | 2022-04-22 13:17:38 +0100 | [diff] [blame] | 1217 | * Offset of the 'receivers' field, which relates to the memory access |
| 1218 | * descriptors. |
| 1219 | */ |
| 1220 | uint32_t receivers_offset; |
| 1221 | /** Reserved field (12 bytes) must be 0. */ |
| 1222 | uint32_t reserved[3]; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1223 | }; |
| 1224 | |
| 1225 | /** |
| 1226 | * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table |
J-Alves | 0b6653d | 2022-04-22 13:17:38 +0100 | [diff] [blame] | 1227 | * 16.25 of the FF-A v1.1 EAC0 specification, "Descriptor to relinquish a memory |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1228 | * region". |
| 1229 | */ |
| 1230 | struct ffa_mem_relinquish { |
| 1231 | ffa_memory_handle_t handle; |
| 1232 | ffa_memory_region_flags_t flags; |
| 1233 | uint32_t endpoint_count; |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 1234 | ffa_id_t endpoints[]; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1235 | }; |
| 1236 | |
| 1237 | /** |
Daniel Boulby | 59ffee9 | 2023-11-02 18:26:26 +0000 | [diff] [blame] | 1238 | * Returns the first FF-A version that matches the memory access descriptor |
| 1239 | * size. |
Daniel Boulby | de974ca | 2023-12-12 13:53:31 +0000 | [diff] [blame] | 1240 | */ |
| 1241 | uint32_t ffa_version_from_memory_access_desc_size( |
| 1242 | uint32_t memory_access_desc_size); |
| 1243 | |
| 1244 | /** |
Daniel Boulby | c7dc932 | 2023-10-27 15:12:07 +0100 | [diff] [blame] | 1245 | * Returns the first FF-A version that matches the memory access descriptor |
| 1246 | * size. |
| 1247 | */ |
| 1248 | uint32_t ffa_version_from_memory_access_desc_size( |
| 1249 | uint32_t memory_access_desc_size); |
| 1250 | |
| 1251 | /** |
Daniel Boulby | d5ae44b | 2023-12-12 12:18:11 +0000 | [diff] [blame] | 1252 | * To maintain forwards compatability we can't make assumptions about the size |
| 1253 | * of the endpoint memory access descriptor so provide a helper function |
| 1254 | * to get a receiver from the receiver array using the memory access descriptor |
| 1255 | * size field from the memory region descriptor struct. |
| 1256 | * Returns NULL if we cannot return the receiver. |
| 1257 | */ |
| 1258 | static inline struct ffa_memory_access *ffa_memory_region_get_receiver( |
| 1259 | struct ffa_memory_region *memory_region, uint32_t receiver_index) |
| 1260 | { |
| 1261 | uint32_t memory_access_desc_size = |
| 1262 | memory_region->memory_access_desc_size; |
| 1263 | |
| 1264 | if (receiver_index >= memory_region->receiver_count) { |
| 1265 | return NULL; |
| 1266 | } |
| 1267 | |
| 1268 | /* |
| 1269 | * Memory access descriptor size cannot be greater than the size of |
| 1270 | * the memory access descriptor defined by the current FF-A version. |
| 1271 | */ |
| 1272 | if (memory_access_desc_size > sizeof(struct ffa_memory_access)) { |
| 1273 | return NULL; |
| 1274 | } |
| 1275 | |
Daniel Boulby | 41ef8ba | 2023-10-13 17:01:22 +0100 | [diff] [blame] | 1276 | /* Check we cannot use receivers offset to cause overflow. */ |
| 1277 | if (memory_region->receivers_offset != |
| 1278 | sizeof(struct ffa_memory_region)) { |
| 1279 | return NULL; |
| 1280 | } |
| 1281 | |
| 1282 | return (struct ffa_memory_access *)((uint8_t *)memory_region + |
| 1283 | memory_region->receivers_offset + |
Daniel Boulby | d5ae44b | 2023-12-12 12:18:11 +0000 | [diff] [blame] | 1284 | (receiver_index * |
| 1285 | memory_access_desc_size)); |
| 1286 | } |
| 1287 | |
| 1288 | /** |
Daniel Boulby | 59ffee9 | 2023-11-02 18:26:26 +0000 | [diff] [blame] | 1289 | * Gets the receiver's access permissions from 'struct ffa_memory_region' and |
| 1290 | * returns its index in the receiver's array. If receiver's ID doesn't exist |
| 1291 | * in the array, return the region's 'receivers_count'. |
| 1292 | */ |
| 1293 | static inline uint32_t ffa_memory_region_get_receiver_index( |
| 1294 | struct ffa_memory_region *memory_region, ffa_id_t receiver_id) |
| 1295 | { |
| 1296 | uint32_t i; |
| 1297 | |
| 1298 | for (i = 0U; i < memory_region->receiver_count; i++) { |
| 1299 | struct ffa_memory_access *receiver = |
| 1300 | ffa_memory_region_get_receiver(memory_region, i); |
| 1301 | if (receiver->receiver_permissions.receiver == receiver_id) { |
| 1302 | break; |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | return i; |
| 1307 | } |
| 1308 | |
| 1309 | /** |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1310 | * Gets the `ffa_composite_memory_region` for the given receiver from an |
| 1311 | * `ffa_memory_region`, or NULL if it is not valid. |
| 1312 | */ |
| 1313 | static inline struct ffa_composite_memory_region * |
| 1314 | ffa_memory_region_get_composite(struct ffa_memory_region *memory_region, |
| 1315 | uint32_t receiver_index) |
| 1316 | { |
Daniel Boulby | d5ae44b | 2023-12-12 12:18:11 +0000 | [diff] [blame] | 1317 | struct ffa_memory_access *receiver = |
| 1318 | ffa_memory_region_get_receiver(memory_region, receiver_index); |
| 1319 | uint32_t offset; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1320 | |
Daniel Boulby | d5ae44b | 2023-12-12 12:18:11 +0000 | [diff] [blame] | 1321 | if (receiver == NULL) { |
| 1322 | return NULL; |
| 1323 | } |
| 1324 | |
| 1325 | offset = receiver->composite_memory_region_offset; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1326 | if (offset == 0) { |
| 1327 | return NULL; |
| 1328 | } |
| 1329 | |
| 1330 | return (struct ffa_composite_memory_region *)((uint8_t *)memory_region + |
| 1331 | offset); |
| 1332 | } |
| 1333 | |
| 1334 | static inline uint32_t ffa_mem_relinquish_init( |
| 1335 | struct ffa_mem_relinquish *relinquish_request, |
| 1336 | ffa_memory_handle_t handle, ffa_memory_region_flags_t flags, |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 1337 | ffa_id_t sender) |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1338 | { |
| 1339 | relinquish_request->handle = handle; |
| 1340 | relinquish_request->flags = flags; |
| 1341 | relinquish_request->endpoint_count = 1; |
| 1342 | relinquish_request->endpoints[0] = sender; |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 1343 | return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_id_t); |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1344 | } |
| 1345 | |
J-Alves | 126ab50 | 2022-09-29 11:37:33 +0100 | [diff] [blame] | 1346 | void ffa_copy_memory_region_constituents( |
| 1347 | struct ffa_memory_region_constituent *dest, |
| 1348 | const struct ffa_memory_region_constituent *src); |
| 1349 | |
Karl Meakin | 0fd6729 | 2024-02-06 17:33:05 +0000 | [diff] [blame] | 1350 | struct ffa_features_rxtx_map_params { |
| 1351 | /* |
| 1352 | * Bit[0:1]: |
| 1353 | * Minimum buffer size and alignment boundary: |
| 1354 | * 0b00: 4K |
| 1355 | * 0b01: 64K |
| 1356 | * 0b10: 16K |
| 1357 | * 0b11: Reserved |
| 1358 | */ |
| 1359 | uint8_t min_buf_size : 2; |
| 1360 | /* |
| 1361 | * Bit[2:15]: |
| 1362 | * Reserved (MBZ) |
| 1363 | */ |
| 1364 | uint16_t mbz : 14; |
| 1365 | /* |
| 1366 | * Bit[16:32]: |
| 1367 | * Maximum buffer size in number of pages |
| 1368 | * Only present on version 1.2 or later |
| 1369 | */ |
| 1370 | uint16_t max_buf_size : 16; |
| 1371 | }; |
| 1372 | |
| 1373 | #define FFA_RXTX_MAP_MIN_BUF_4K 0 |
| 1374 | #define FFA_RXTX_MAP_MAX_BUF_PAGE_COUNT 1 |
| 1375 | |
Karl Meakin | f786130 | 2024-02-20 14:39:33 +0000 | [diff] [blame] | 1376 | static inline struct ffa_features_rxtx_map_params ffa_features_rxtx_map_params( |
| 1377 | struct ffa_value args) |
| 1378 | { |
| 1379 | struct ffa_features_rxtx_map_params params; |
| 1380 | uint32_t arg2 = args.arg2; |
| 1381 | |
| 1382 | params = *(struct ffa_features_rxtx_map_params *)(&arg2); |
| 1383 | |
| 1384 | return params; |
| 1385 | } |
| 1386 | |
Federico Recanati | 392be39 | 2022-02-08 20:53:03 +0100 | [diff] [blame] | 1387 | /** |
| 1388 | * Endpoint RX/TX descriptor, as defined by Table 13.27 in FF-A v1.1 EAC0. |
| 1389 | * It's used by the Hypervisor to describe the RX/TX buffers mapped by a VM |
| 1390 | * to the SPMC, in order to allow indirect messaging. |
| 1391 | */ |
| 1392 | struct ffa_endpoint_rx_tx_descriptor { |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 1393 | ffa_id_t endpoint_id; |
Federico Recanati | 392be39 | 2022-02-08 20:53:03 +0100 | [diff] [blame] | 1394 | uint16_t reserved; |
| 1395 | |
| 1396 | /* |
| 1397 | * 8-byte aligned offset from the base address of this descriptor to the |
| 1398 | * `ffa_composite_memory_region` describing the RX buffer. |
| 1399 | */ |
| 1400 | uint32_t rx_offset; |
| 1401 | |
| 1402 | /* |
| 1403 | * 8-byte aligned offset from the base address of this descriptor to the |
| 1404 | * `ffa_composite_memory_region` describing the TX buffer. |
| 1405 | */ |
| 1406 | uint32_t tx_offset; |
| 1407 | |
| 1408 | /* Pad to align on 16-byte boundary. */ |
| 1409 | uint32_t pad; |
| 1410 | }; |
| 1411 | |
| 1412 | static inline struct ffa_composite_memory_region * |
Karl Meakin | b9705e2 | 2024-04-05 13:58:28 +0100 | [diff] [blame] | 1413 | ffa_endpoint_get_rx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc) |
Federico Recanati | 392be39 | 2022-02-08 20:53:03 +0100 | [diff] [blame] | 1414 | { |
| 1415 | return (struct ffa_composite_memory_region *)((uintptr_t)desc + |
| 1416 | desc->rx_offset); |
| 1417 | } |
| 1418 | |
| 1419 | static inline struct ffa_composite_memory_region * |
Karl Meakin | b9705e2 | 2024-04-05 13:58:28 +0100 | [diff] [blame] | 1420 | ffa_endpoint_get_tx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc) |
Federico Recanati | 392be39 | 2022-02-08 20:53:03 +0100 | [diff] [blame] | 1421 | { |
| 1422 | return (struct ffa_composite_memory_region *)((uintptr_t)desc + |
| 1423 | desc->tx_offset); |
| 1424 | } |
| 1425 | |
J-Alves | 2d8457f | 2022-10-05 11:06:41 +0100 | [diff] [blame] | 1426 | void ffa_memory_region_init_header(struct ffa_memory_region *memory_region, |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 1427 | ffa_id_t sender, |
J-Alves | 2d8457f | 2022-10-05 11:06:41 +0100 | [diff] [blame] | 1428 | ffa_memory_attributes_t attributes, |
| 1429 | ffa_memory_region_flags_t flags, |
| 1430 | ffa_memory_handle_t handle, uint32_t tag, |
Daniel Boulby | d5ae44b | 2023-12-12 12:18:11 +0000 | [diff] [blame] | 1431 | uint32_t receiver_count, |
| 1432 | uint32_t receiver_desc_size); |
Daniel Boulby | 59ffee9 | 2023-11-02 18:26:26 +0000 | [diff] [blame] | 1433 | void ffa_memory_access_init(struct ffa_memory_access *receiver, |
| 1434 | ffa_id_t receiver_id, |
| 1435 | enum ffa_data_access data_access, |
| 1436 | enum ffa_instruction_access instruction_access, |
| 1437 | ffa_memory_receiver_flags_t flags, |
| 1438 | struct ffa_memory_access_impdef *impdef_val); |
J-Alves | 4508543 | 2022-04-22 16:19:20 +0100 | [diff] [blame] | 1439 | uint32_t ffa_memory_region_init_single_receiver( |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 1440 | struct ffa_memory_region *memory_region, size_t memory_region_max_size, |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 1441 | ffa_id_t sender, ffa_id_t receiver, |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1442 | const struct ffa_memory_region_constituent constituents[], |
| 1443 | uint32_t constituent_count, uint32_t tag, |
| 1444 | ffa_memory_region_flags_t flags, enum ffa_data_access data_access, |
| 1445 | enum ffa_instruction_access instruction_access, |
| 1446 | enum ffa_memory_type type, enum ffa_memory_cacheability cacheability, |
Daniel Boulby | 59ffee9 | 2023-11-02 18:26:26 +0000 | [diff] [blame] | 1447 | enum ffa_memory_shareability shareability, |
| 1448 | struct ffa_memory_access_impdef *impdef_val, uint32_t *fragment_length, |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 1449 | uint32_t *total_length); |
J-Alves | f4eecf7 | 2022-07-20 16:05:34 +0100 | [diff] [blame] | 1450 | uint32_t ffa_memory_region_init( |
| 1451 | struct ffa_memory_region *memory_region, size_t memory_region_max_size, |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 1452 | ffa_id_t sender, struct ffa_memory_access receivers[], |
Daniel Boulby | d5ae44b | 2023-12-12 12:18:11 +0000 | [diff] [blame] | 1453 | uint32_t receiver_count, uint32_t receiver_desc_size, |
J-Alves | f4eecf7 | 2022-07-20 16:05:34 +0100 | [diff] [blame] | 1454 | const struct ffa_memory_region_constituent constituents[], |
| 1455 | uint32_t constituent_count, uint32_t tag, |
| 1456 | ffa_memory_region_flags_t flags, enum ffa_memory_type type, |
| 1457 | enum ffa_memory_cacheability cacheability, |
| 1458 | enum ffa_memory_shareability shareability, uint32_t *fragment_length, |
| 1459 | uint32_t *total_length); |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1460 | uint32_t ffa_memory_retrieve_request_init( |
| 1461 | struct ffa_memory_region *memory_region, ffa_memory_handle_t handle, |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 1462 | ffa_id_t sender, struct ffa_memory_access receivers[], |
Daniel Boulby | d5ae44b | 2023-12-12 12:18:11 +0000 | [diff] [blame] | 1463 | uint32_t receiver_count, uint32_t receiver_desc_size, uint32_t tag, |
| 1464 | ffa_memory_region_flags_t flags, enum ffa_memory_type type, |
| 1465 | enum ffa_memory_cacheability cacheability, |
J-Alves | 9b24ed8 | 2022-08-04 13:12:45 +0100 | [diff] [blame] | 1466 | enum ffa_memory_shareability shareability); |
| 1467 | uint32_t ffa_memory_retrieve_request_init_single_receiver( |
| 1468 | struct ffa_memory_region *memory_region, ffa_memory_handle_t handle, |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 1469 | ffa_id_t sender, ffa_id_t receiver, uint32_t tag, |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1470 | ffa_memory_region_flags_t flags, enum ffa_data_access data_access, |
| 1471 | enum ffa_instruction_access instruction_access, |
| 1472 | enum ffa_memory_type type, enum ffa_memory_cacheability cacheability, |
Daniel Boulby | 59ffee9 | 2023-11-02 18:26:26 +0000 | [diff] [blame] | 1473 | enum ffa_memory_shareability shareability, |
| 1474 | struct ffa_memory_access_impdef *impdef_val); |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1475 | uint32_t ffa_memory_lender_retrieve_request_init( |
| 1476 | struct ffa_memory_region *memory_region, ffa_memory_handle_t handle, |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 1477 | ffa_id_t sender); |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 1478 | uint32_t ffa_memory_fragment_init( |
| 1479 | struct ffa_memory_region_constituent *fragment, |
| 1480 | size_t fragment_max_size, |
| 1481 | const struct ffa_memory_region_constituent constituents[], |
| 1482 | uint32_t constituent_count, uint32_t *fragment_length); |
Federico Recanati | 392be39 | 2022-02-08 20:53:03 +0100 | [diff] [blame] | 1483 | void ffa_endpoint_rx_tx_descriptor_init( |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 1484 | struct ffa_endpoint_rx_tx_descriptor *desc, ffa_id_t endpoint_id, |
Federico Recanati | 392be39 | 2022-02-08 20:53:03 +0100 | [diff] [blame] | 1485 | uint64_t rx_address, uint64_t tx_address); |