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