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