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