Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1 | /* |
J-Alves | 13318e3 | 2021-02-22 17:21:00 +0000 | [diff] [blame] | 2 | * Copyright 2021 The Hafnium Authors. |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 3 | * |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style |
| 5 | * license that can be found in the LICENSE file or at |
| 6 | * https://opensource.org/licenses/BSD-3-Clause. |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include "hf/types.h" |
| 12 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 13 | #define FFA_VERSION_MAJOR 0x1 |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 14 | #define FFA_VERSION_MAJOR_OFFSET 16 |
Daniel Boulby | 6e32c61 | 2021-02-17 15:09:41 +0000 | [diff] [blame] | 15 | #define FFA_VERSION_MAJOR_MASK 0x7FFF |
J-Alves | 3829fc0 | 2021-03-18 12:49:18 +0000 | [diff] [blame] | 16 | #define FFA_VERSION_MINOR 0x1 |
Daniel Boulby | 6e32c61 | 2021-02-17 15:09:41 +0000 | [diff] [blame] | 17 | #define FFA_VERSION_MINOR_OFFSET 0 |
| 18 | #define FFA_VERSION_MINOR_MASK 0xFFFF |
| 19 | |
| 20 | #define MAKE_FFA_VERSION(major, minor) \ |
| 21 | ((((major)&FFA_VERSION_MAJOR_MASK) << FFA_VERSION_MAJOR_OFFSET) | \ |
| 22 | (((minor)&FFA_VERSION_MINOR_MASK) << FFA_VERSION_MINOR_OFFSET)) |
| 23 | #define FFA_VERSION_COMPILED \ |
| 24 | MAKE_FFA_VERSION(FFA_VERSION_MAJOR, FFA_VERSION_MINOR) |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 25 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 26 | /* clang-format off */ |
| 27 | |
| 28 | #define FFA_LOW_32_ID 0x84000060 |
| 29 | #define FFA_HIGH_32_ID 0x8400007F |
| 30 | #define FFA_LOW_64_ID 0xC4000060 |
Fuad Tabba | da72d14 | 2020-07-30 09:17:05 +0100 | [diff] [blame] | 31 | #define FFA_HIGH_64_ID 0xC400007F |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 32 | |
| 33 | /* FF-A function identifiers. */ |
J-Alves | 3829fc0 | 2021-03-18 12:49:18 +0000 | [diff] [blame] | 34 | #define FFA_ERROR_32 0x84000060 |
| 35 | #define FFA_SUCCESS_32 0x84000061 |
| 36 | #define FFA_SUCCESS_64 0xC4000061 |
| 37 | #define FFA_INTERRUPT_32 0x84000062 |
| 38 | #define FFA_VERSION_32 0x84000063 |
| 39 | #define FFA_FEATURES_32 0x84000064 |
| 40 | #define FFA_RX_RELEASE_32 0x84000065 |
| 41 | #define FFA_RXTX_MAP_32 0x84000066 |
| 42 | #define FFA_RXTX_MAP_64 0xC4000066 |
| 43 | #define FFA_RXTX_UNMAP_32 0x84000067 |
| 44 | #define FFA_PARTITION_INFO_GET_32 0x84000068 |
| 45 | #define FFA_ID_GET_32 0x84000069 |
| 46 | #define FFA_MSG_POLL_32 0x8400006A /* Legacy FF-A v1.0 */ |
| 47 | #define FFA_MSG_WAIT_32 0x8400006B |
| 48 | #define FFA_YIELD_32 0x8400006C |
| 49 | #define FFA_RUN_32 0x8400006D |
| 50 | #define FFA_MSG_SEND_32 0x8400006E /* Legacy FF-A v1.0 */ |
| 51 | #define FFA_MSG_SEND_DIRECT_REQ_32 0x8400006F |
| 52 | #define FFA_MSG_SEND_DIRECT_REQ_64 0xC400006F |
| 53 | #define FFA_MSG_SEND_DIRECT_RESP_32 0x84000070 |
| 54 | #define FFA_MSG_SEND_DIRECT_RESP_64 0xC4000070 |
| 55 | #define FFA_MEM_DONATE_32 0x84000071 |
| 56 | #define FFA_MEM_LEND_32 0x84000072 |
| 57 | #define FFA_MEM_SHARE_32 0x84000073 |
| 58 | #define FFA_MEM_RETRIEVE_REQ_32 0x84000074 |
| 59 | #define FFA_MEM_RETRIEVE_RESP_32 0x84000075 |
| 60 | #define FFA_MEM_RELINQUISH_32 0x84000076 |
| 61 | #define FFA_MEM_RECLAIM_32 0x84000077 |
| 62 | #define FFA_MEM_FRAG_RX_32 0x8400007A |
| 63 | #define FFA_MEM_FRAG_TX_32 0x8400007B |
| 64 | #define FFA_NORMAL_WORLD_RESUME 0x8400007C |
| 65 | |
| 66 | /* FF-A v1.1 */ |
| 67 | #define FFA_NOTIFICATION_BITMAP_CREATE_32 0x8400007D |
| 68 | #define FFA_NOTIFICATION_BITMAP_DESTROY_32 0x8400007E |
| 69 | #define FFA_NOTIFICATION_BIND_32 0x8400007F |
| 70 | #define FFA_NOTIFICATION_UNBIND_32 0x84000080 |
| 71 | #define FFA_NOTIFICATION_SET_32 0x84000081 |
| 72 | #define FFA_NOTIFICATION_GET_32 0x84000082 |
| 73 | #define FFA_NOTIFICATION_INFO_GET_64 0xC4000083 |
| 74 | #define FFA_RX_ACQUIRE_32 0x84000084 |
| 75 | #define FFA_SPM_ID_GET_32 0x84000085 |
| 76 | #define FFA_MSG_SEND2_32 0x84000086 |
| 77 | #define FFA_SECONDARY_EP_REGISTER_64 0xC4000087 |
| 78 | #define FFA_MEM_PERM_GET_32 0x84000088 |
| 79 | #define FFA_MEM_PERM_SET_32 0x84000089 |
Raghu Krishnamurthy | ea6d25f | 2021-09-14 15:27:06 -0700 | [diff] [blame] | 80 | #define FFA_MEM_PERM_GET_64 0xC4000088 |
| 81 | #define FFA_MEM_PERM_SET_64 0xC4000089 |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 82 | |
| 83 | /* FF-A error codes. */ |
| 84 | #define FFA_NOT_SUPPORTED INT32_C(-1) |
| 85 | #define FFA_INVALID_PARAMETERS INT32_C(-2) |
| 86 | #define FFA_NO_MEMORY INT32_C(-3) |
| 87 | #define FFA_BUSY INT32_C(-4) |
| 88 | #define FFA_INTERRUPTED INT32_C(-5) |
| 89 | #define FFA_DENIED INT32_C(-6) |
| 90 | #define FFA_RETRY INT32_C(-7) |
| 91 | #define FFA_ABORTED INT32_C(-8) |
J-Alves | c8e8a22 | 2021-06-08 17:33:52 +0100 | [diff] [blame] | 92 | #define FFA_NO_DATA INT32_C(-9) |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 93 | |
| 94 | /* clang-format on */ |
| 95 | |
J-Alves | 6f72ca8 | 2021-11-01 12:34:58 +0000 | [diff] [blame] | 96 | /** |
| 97 | * FF-A Feature ID, to be used with interface FFA_FEATURES. |
| 98 | * As defined in the FF-A v1.1 Beta specification, table 13.10, in section |
| 99 | * 13.2. |
| 100 | */ |
| 101 | |
Olivier Deprez | b76307d | 2022-06-09 17:17:45 +0200 | [diff] [blame] | 102 | #define FFA_FEATURES_FUNC_ID_MASK (UINT32_C(1) << 31) |
J-Alves | 6f72ca8 | 2021-11-01 12:34:58 +0000 | [diff] [blame] | 103 | #define FFA_FEATURES_FEATURE_ID_MASK UINT32_C(0x7F) |
| 104 | |
| 105 | /* Query interrupt ID of Notification Pending Interrupt. */ |
| 106 | #define FFA_FEATURE_NPI 0x1U |
| 107 | |
| 108 | /* Query interrupt ID of Schedule Receiver Interrupt. */ |
| 109 | #define FFA_FEATURE_SRI 0x2U |
| 110 | |
| 111 | /* Query interrupt ID of the Managed Exit Interrupt. */ |
| 112 | #define FFA_FEATURE_MEI 0x3U |
| 113 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 114 | /* FF-A function specific constants. */ |
| 115 | #define FFA_MSG_RECV_BLOCK 0x1 |
| 116 | #define FFA_MSG_RECV_BLOCK_MASK 0x1 |
| 117 | |
| 118 | #define FFA_MSG_SEND_NOTIFY 0x1 |
| 119 | #define FFA_MSG_SEND_NOTIFY_MASK 0x1 |
| 120 | |
| 121 | #define FFA_MEM_RECLAIM_CLEAR 0x1 |
| 122 | |
| 123 | #define FFA_SLEEP_INDEFINITE 0 |
| 124 | |
Raghu Krishnamurthy | ea6d25f | 2021-09-14 15:27:06 -0700 | [diff] [blame] | 125 | #define FFA_MEM_PERM_RO UINT32_C(0x7) |
| 126 | #define FFA_MEM_PERM_RW UINT32_C(0x5) |
| 127 | #define FFA_MEM_PERM_RX UINT32_C(0x3) |
| 128 | |
Daniel Boulby | b46cad1 | 2021-12-13 17:47:21 +0000 | [diff] [blame] | 129 | /* |
| 130 | * Defined in Table 13.31 in the FF-A v1.1 BETA0 specification. |
| 131 | * The Partition count flag is used by FFA_PARTITION_INFO_GET to specify |
| 132 | * if partition info descriptors should be returned or just the count. |
| 133 | */ |
| 134 | #define FFA_PARTITION_COUNT_FLAG 0x1 |
| 135 | #define FFA_PARTITION_COUNT_FLAG_MASK 0x1 |
| 136 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 137 | /** |
| 138 | * For use where the FF-A specification refers explicitly to '4K pages'. Not to |
| 139 | * be confused with PAGE_SIZE, which is the translation granule Hafnium is |
| 140 | * configured to use. |
| 141 | */ |
| 142 | #define FFA_PAGE_SIZE 4096 |
| 143 | |
| 144 | /* The maximum length possible for a single message. */ |
| 145 | #define FFA_MSG_PAYLOAD_MAX HF_MAILBOX_SIZE |
| 146 | |
| 147 | enum ffa_data_access { |
| 148 | FFA_DATA_ACCESS_NOT_SPECIFIED, |
| 149 | FFA_DATA_ACCESS_RO, |
| 150 | FFA_DATA_ACCESS_RW, |
| 151 | FFA_DATA_ACCESS_RESERVED, |
| 152 | }; |
| 153 | |
| 154 | enum ffa_instruction_access { |
| 155 | FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED, |
| 156 | FFA_INSTRUCTION_ACCESS_NX, |
| 157 | FFA_INSTRUCTION_ACCESS_X, |
| 158 | FFA_INSTRUCTION_ACCESS_RESERVED, |
| 159 | }; |
| 160 | |
| 161 | enum ffa_memory_type { |
| 162 | FFA_MEMORY_NOT_SPECIFIED_MEM, |
| 163 | FFA_MEMORY_DEVICE_MEM, |
| 164 | FFA_MEMORY_NORMAL_MEM, |
| 165 | }; |
| 166 | |
| 167 | enum ffa_memory_cacheability { |
| 168 | FFA_MEMORY_CACHE_RESERVED = 0x0, |
| 169 | FFA_MEMORY_CACHE_NON_CACHEABLE = 0x1, |
| 170 | FFA_MEMORY_CACHE_RESERVED_1 = 0x2, |
| 171 | FFA_MEMORY_CACHE_WRITE_BACK = 0x3, |
| 172 | FFA_MEMORY_DEV_NGNRNE = 0x0, |
| 173 | FFA_MEMORY_DEV_NGNRE = 0x1, |
| 174 | FFA_MEMORY_DEV_NGRE = 0x2, |
| 175 | FFA_MEMORY_DEV_GRE = 0x3, |
| 176 | }; |
| 177 | |
| 178 | enum ffa_memory_shareability { |
| 179 | FFA_MEMORY_SHARE_NON_SHAREABLE, |
| 180 | FFA_MEMORY_SHARE_RESERVED, |
| 181 | FFA_MEMORY_OUTER_SHAREABLE, |
| 182 | FFA_MEMORY_INNER_SHAREABLE, |
| 183 | }; |
| 184 | |
| 185 | typedef uint8_t ffa_memory_access_permissions_t; |
| 186 | |
| 187 | /** |
| 188 | * This corresponds to table 44 of the FF-A 1.0 EAC specification, "Memory |
| 189 | * region attributes descriptor". |
| 190 | */ |
| 191 | typedef uint8_t ffa_memory_attributes_t; |
| 192 | |
| 193 | #define FFA_DATA_ACCESS_OFFSET (0x0U) |
| 194 | #define FFA_DATA_ACCESS_MASK ((0x3U) << FFA_DATA_ACCESS_OFFSET) |
| 195 | |
| 196 | #define FFA_INSTRUCTION_ACCESS_OFFSET (0x2U) |
| 197 | #define FFA_INSTRUCTION_ACCESS_MASK ((0x3U) << FFA_INSTRUCTION_ACCESS_OFFSET) |
| 198 | |
| 199 | #define FFA_MEMORY_TYPE_OFFSET (0x4U) |
| 200 | #define FFA_MEMORY_TYPE_MASK ((0x3U) << FFA_MEMORY_TYPE_OFFSET) |
| 201 | |
| 202 | #define FFA_MEMORY_CACHEABILITY_OFFSET (0x2U) |
| 203 | #define FFA_MEMORY_CACHEABILITY_MASK ((0x3U) << FFA_MEMORY_CACHEABILITY_OFFSET) |
| 204 | |
| 205 | #define FFA_MEMORY_SHAREABILITY_OFFSET (0x0U) |
| 206 | #define FFA_MEMORY_SHAREABILITY_MASK ((0x3U) << FFA_MEMORY_SHAREABILITY_OFFSET) |
| 207 | |
| 208 | #define ATTR_FUNCTION_SET(name, container_type, offset, mask) \ |
| 209 | static inline void ffa_set_##name##_attr(container_type *attr, \ |
| 210 | const enum ffa_##name perm) \ |
| 211 | { \ |
| 212 | *attr = (*attr & ~(mask)) | ((perm << offset) & mask); \ |
| 213 | } |
| 214 | |
| 215 | #define ATTR_FUNCTION_GET(name, container_type, offset, mask) \ |
| 216 | static inline enum ffa_##name ffa_get_##name##_attr( \ |
| 217 | container_type attr) \ |
| 218 | { \ |
| 219 | return (enum ffa_##name)((attr & mask) >> offset); \ |
| 220 | } |
| 221 | |
| 222 | ATTR_FUNCTION_SET(data_access, ffa_memory_access_permissions_t, |
| 223 | FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK) |
| 224 | ATTR_FUNCTION_GET(data_access, ffa_memory_access_permissions_t, |
| 225 | FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK) |
| 226 | |
| 227 | ATTR_FUNCTION_SET(instruction_access, ffa_memory_access_permissions_t, |
| 228 | FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK) |
| 229 | ATTR_FUNCTION_GET(instruction_access, ffa_memory_access_permissions_t, |
| 230 | FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK) |
| 231 | |
| 232 | ATTR_FUNCTION_SET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET, |
| 233 | FFA_MEMORY_TYPE_MASK) |
| 234 | ATTR_FUNCTION_GET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET, |
| 235 | FFA_MEMORY_TYPE_MASK) |
| 236 | |
| 237 | ATTR_FUNCTION_SET(memory_cacheability, ffa_memory_attributes_t, |
| 238 | FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK) |
| 239 | ATTR_FUNCTION_GET(memory_cacheability, ffa_memory_attributes_t, |
| 240 | FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK) |
| 241 | |
| 242 | ATTR_FUNCTION_SET(memory_shareability, ffa_memory_attributes_t, |
| 243 | FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK) |
| 244 | ATTR_FUNCTION_GET(memory_shareability, ffa_memory_attributes_t, |
| 245 | FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK) |
| 246 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 247 | /** |
| 248 | * A globally-unique ID assigned by the hypervisor for a region of memory being |
| 249 | * sent between VMs. |
| 250 | */ |
| 251 | typedef uint64_t ffa_memory_handle_t; |
| 252 | |
J-Alves | 917d2f2 | 2020-10-30 18:39:30 +0000 | [diff] [blame] | 253 | #define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \ |
| 254 | ((ffa_memory_handle_t)(UINT64_C(1) << 63)) |
| 255 | #define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR \ |
| 256 | ((ffa_memory_handle_t)(UINT64_C(1) << 63)) |
| 257 | |
| 258 | #define FFA_MEMORY_HANDLE_ALLOCATOR_SPMC (UINT64_C(0) << 63) |
| 259 | #define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0)) |
| 260 | |
| 261 | /** The ID of a VM. These are assigned sequentially starting with an offset. */ |
| 262 | typedef uint16_t ffa_vm_id_t; |
| 263 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 264 | /** |
| 265 | * A count of VMs. This has the same range as the VM IDs but we give it a |
| 266 | * different name to make the different semantics clear. |
| 267 | */ |
| 268 | typedef ffa_vm_id_t ffa_vm_count_t; |
| 269 | |
| 270 | /** The index of a vCPU within a particular VM. */ |
| 271 | typedef uint16_t ffa_vcpu_index_t; |
| 272 | |
| 273 | /** |
| 274 | * A count of vCPUs. This has the same range as the vCPU indices but we give it |
| 275 | * a different name to make the different semantics clear. |
| 276 | */ |
| 277 | typedef ffa_vcpu_index_t ffa_vcpu_count_t; |
| 278 | |
| 279 | /** Parameter and return type of FF-A functions. */ |
| 280 | struct ffa_value { |
| 281 | uint64_t func; |
| 282 | uint64_t arg1; |
| 283 | uint64_t arg2; |
| 284 | uint64_t arg3; |
| 285 | uint64_t arg4; |
| 286 | uint64_t arg5; |
| 287 | uint64_t arg6; |
| 288 | uint64_t arg7; |
| 289 | }; |
| 290 | |
Olivier Deprez | e562e54 | 2020-06-11 17:31:54 +0200 | [diff] [blame] | 291 | static inline uint32_t ffa_func_id(struct ffa_value args) |
| 292 | { |
| 293 | return args.func; |
| 294 | } |
| 295 | |
J-Alves | 13318e3 | 2021-02-22 17:21:00 +0000 | [diff] [blame] | 296 | static inline int32_t ffa_error_code(struct ffa_value val) |
| 297 | { |
| 298 | return (int32_t)val.arg2; |
| 299 | } |
| 300 | |
J-Alves | d6f4e14 | 2021-03-05 13:33:59 +0000 | [diff] [blame] | 301 | static inline ffa_vm_id_t ffa_sender(struct ffa_value args) |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 302 | { |
| 303 | return (args.arg1 >> 16) & 0xffff; |
| 304 | } |
| 305 | |
J-Alves | d6f4e14 | 2021-03-05 13:33:59 +0000 | [diff] [blame] | 306 | static inline ffa_vm_id_t ffa_receiver(struct ffa_value args) |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 307 | { |
| 308 | return args.arg1 & 0xffff; |
| 309 | } |
| 310 | |
| 311 | static inline uint32_t ffa_msg_send_size(struct ffa_value args) |
| 312 | { |
| 313 | return args.arg3; |
| 314 | } |
| 315 | |
| 316 | static inline uint32_t ffa_msg_send_attributes(struct ffa_value args) |
| 317 | { |
| 318 | return args.arg4; |
| 319 | } |
| 320 | |
Olivier Deprez | e562e54 | 2020-06-11 17:31:54 +0200 | [diff] [blame] | 321 | static inline uint32_t ffa_partition_info_get_count(struct ffa_value args) |
| 322 | { |
| 323 | return args.arg2; |
| 324 | } |
| 325 | |
Andrew Walbran | 1bbe940 | 2020-04-30 16:47:13 +0100 | [diff] [blame] | 326 | static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t a1, uint32_t a2) |
| 327 | { |
| 328 | return (uint64_t)a1 | (uint64_t)a2 << 32; |
| 329 | } |
| 330 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 331 | static inline ffa_memory_handle_t ffa_mem_success_handle(struct ffa_value args) |
| 332 | { |
Andrew Walbran | 1bbe940 | 2020-04-30 16:47:13 +0100 | [diff] [blame] | 333 | return ffa_assemble_handle(args.arg2, args.arg3); |
| 334 | } |
| 335 | |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 336 | static inline ffa_memory_handle_t ffa_frag_handle(struct ffa_value args) |
| 337 | { |
| 338 | return ffa_assemble_handle(args.arg1, args.arg2); |
| 339 | } |
| 340 | |
Andrew Walbran | 1bbe940 | 2020-04-30 16:47:13 +0100 | [diff] [blame] | 341 | static inline struct ffa_value ffa_mem_success(ffa_memory_handle_t handle) |
| 342 | { |
| 343 | return (struct ffa_value){.func = FFA_SUCCESS_32, |
| 344 | .arg2 = (uint32_t)handle, |
| 345 | .arg3 = (uint32_t)(handle >> 32)}; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | static inline ffa_vm_id_t ffa_vm_id(struct ffa_value args) |
| 349 | { |
| 350 | return (args.arg1 >> 16) & 0xffff; |
| 351 | } |
| 352 | |
| 353 | static inline ffa_vcpu_index_t ffa_vcpu_index(struct ffa_value args) |
| 354 | { |
| 355 | return args.arg1 & 0xffff; |
| 356 | } |
| 357 | |
| 358 | static inline uint64_t ffa_vm_vcpu(ffa_vm_id_t vm_id, |
| 359 | ffa_vcpu_index_t vcpu_index) |
| 360 | { |
| 361 | return ((uint32_t)vm_id << 16) | vcpu_index; |
| 362 | } |
| 363 | |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 364 | static inline ffa_vm_id_t ffa_frag_sender(struct ffa_value args) |
| 365 | { |
| 366 | return (args.arg4 >> 16) & 0xffff; |
| 367 | } |
| 368 | |
J-Alves | 6f72ca8 | 2021-11-01 12:34:58 +0000 | [diff] [blame] | 369 | static inline uint32_t ffa_feature_intid(struct ffa_value args) |
| 370 | { |
| 371 | return (uint32_t)args.arg2; |
| 372 | } |
| 373 | |
Daniel Boulby | efa381f | 2022-01-18 14:49:40 +0000 | [diff] [blame] | 374 | static inline uint32_t ffa_fwk_msg(struct ffa_value args) |
| 375 | { |
| 376 | return (uint32_t)args.arg2; |
| 377 | } |
| 378 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 379 | /** |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 380 | * Holds the UUID in a struct that is mappable directly to the SMCC calling |
| 381 | * convention, which is used for FF-A calls. |
| 382 | * |
| 383 | * Refer to table 84 of the FF-A 1.0 EAC specification as well as section 5.3 |
| 384 | * of the SMCC Spec 1.2. |
| 385 | */ |
| 386 | struct ffa_uuid { |
| 387 | uint32_t uuid[4]; |
| 388 | }; |
| 389 | |
| 390 | static inline void ffa_uuid_init(uint32_t w0, uint32_t w1, uint32_t w2, |
| 391 | uint32_t w3, struct ffa_uuid *uuid) |
| 392 | { |
| 393 | uuid->uuid[0] = w0; |
| 394 | uuid->uuid[1] = w1; |
| 395 | uuid->uuid[2] = w2; |
| 396 | uuid->uuid[3] = w3; |
| 397 | } |
| 398 | |
| 399 | static inline bool ffa_uuid_equal(const struct ffa_uuid *uuid1, |
| 400 | const struct ffa_uuid *uuid2) |
| 401 | { |
| 402 | return (uuid1->uuid[0] == uuid2->uuid[0]) && |
| 403 | (uuid1->uuid[1] == uuid2->uuid[1]) && |
| 404 | (uuid1->uuid[2] == uuid2->uuid[2]) && |
| 405 | (uuid1->uuid[3] == uuid2->uuid[3]); |
| 406 | } |
| 407 | |
| 408 | static inline bool ffa_uuid_is_null(const struct ffa_uuid *uuid) |
| 409 | { |
| 410 | return (uuid->uuid[0] == 0) && (uuid->uuid[1] == 0) && |
| 411 | (uuid->uuid[2] == 0) && (uuid->uuid[3] == 0); |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Flags to determine the partition properties, as required by |
| 416 | * FFA_PARTITION_INFO_GET. |
| 417 | * |
| 418 | * The values of the flags are specified in table 82 of the FF-A 1.0 EAC |
| 419 | * specification, "Partition information descriptor, partition properties". |
| 420 | */ |
| 421 | typedef uint32_t ffa_partition_properties_t; |
| 422 | |
| 423 | /** Partition property: partition supports receipt of direct requests. */ |
Maksims Svecovs | b596eab | 2021-04-27 00:52:27 +0100 | [diff] [blame] | 424 | #define FFA_PARTITION_DIRECT_REQ_RECV 0x1 |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 425 | |
| 426 | /** Partition property: partition can send direct requests. */ |
Maksims Svecovs | b596eab | 2021-04-27 00:52:27 +0100 | [diff] [blame] | 427 | #define FFA_PARTITION_DIRECT_REQ_SEND 0x2 |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 428 | |
| 429 | /** Partition property: partition can send and receive indirect messages. */ |
| 430 | #define FFA_PARTITION_INDIRECT_MSG 0x4 |
| 431 | |
J-Alves | 09ff9d8 | 2021-11-02 11:55:20 +0000 | [diff] [blame] | 432 | /** Partition property: partition can receive notifications. */ |
| 433 | #define FFA_PARTITION_NOTIFICATION 0x8 |
| 434 | |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 435 | /** |
| 436 | * Holds information returned for each partition by the FFA_PARTITION_INFO_GET |
| 437 | * interface. |
Daniel Boulby | 1ddb3d7 | 2021-12-16 18:16:50 +0000 | [diff] [blame] | 438 | * This corresponds to table 13.34 of the FF-A 1.1 BETA0 EAC specification, |
| 439 | * "Partition information descriptor". |
| 440 | */ |
| 441 | struct ffa_partition_info { |
| 442 | ffa_vm_id_t vm_id; |
| 443 | ffa_vcpu_count_t vcpu_count; |
| 444 | ffa_partition_properties_t properties; |
| 445 | struct ffa_uuid uuid; |
| 446 | }; |
| 447 | |
| 448 | /** |
| 449 | * Create a struct for the "Partition information descriptor" defined for v1.0 |
| 450 | * which can be returned to v1.0 endpoints. |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 451 | * This corresponds to table 82 of the FF-A 1.0 EAC specification, "Partition |
| 452 | * information descriptor". |
| 453 | */ |
Daniel Boulby | 1ddb3d7 | 2021-12-16 18:16:50 +0000 | [diff] [blame] | 454 | |
| 455 | struct ffa_partition_info_v1_0 { |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 456 | ffa_vm_id_t vm_id; |
| 457 | ffa_vcpu_count_t vcpu_count; |
| 458 | ffa_partition_properties_t properties; |
| 459 | }; |
| 460 | |
J-Alves | dd1ad57 | 2022-01-25 17:58:26 +0000 | [diff] [blame] | 461 | /** Length in bytes of the name in boot information descriptor. */ |
| 462 | #define FFA_BOOT_INFO_NAME_LEN 16 |
| 463 | |
J-Alves | 240d84c | 2022-04-22 12:19:34 +0100 | [diff] [blame] | 464 | /** |
| 465 | * The FF-A boot info descriptor, as defined in table 5.8 of section 5.4.1, of |
| 466 | * the FF-A v1.1 EAC0 specification. |
| 467 | */ |
J-Alves | dd1ad57 | 2022-01-25 17:58:26 +0000 | [diff] [blame] | 468 | struct ffa_boot_info_desc { |
| 469 | char name[FFA_BOOT_INFO_NAME_LEN]; |
| 470 | uint8_t type; |
| 471 | uint8_t reserved; |
| 472 | uint16_t flags; |
| 473 | uint32_t size; |
| 474 | uint64_t content; |
| 475 | }; |
| 476 | |
| 477 | /** FF-A boot information type mask. */ |
| 478 | #define FFA_BOOT_INFO_TYPE_SHIFT 7 |
| 479 | #define FFA_BOOT_INFO_TYPE_MASK (0x1U << FFA_BOOT_INFO_TYPE_SHIFT) |
| 480 | #define FFA_BOOT_INFO_TYPE_STD 0U |
| 481 | #define FFA_BOOT_INFO_TYPE_IMPDEF 1U |
| 482 | |
| 483 | /** Standard boot info type IDs. */ |
| 484 | #define FFA_BOOT_INFO_TYPE_ID_MASK 0x7FU |
| 485 | #define FFA_BOOT_INFO_TYPE_ID_FDT 0U |
| 486 | #define FFA_BOOT_INFO_TYPE_ID_HOB 1U |
| 487 | |
| 488 | /** FF-A Boot Info descriptors flags. */ |
| 489 | #define FFA_BOOT_INFO_FLAG_MBZ_MASK 0xFFF0U |
| 490 | |
| 491 | /** Bits [1:0] encode the format of the name field in ffa_boot_info_desc. */ |
| 492 | #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT 0U |
| 493 | #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK \ |
| 494 | (0x3U << FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT) |
| 495 | #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING 0x0U |
| 496 | #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID 0x1U |
| 497 | |
| 498 | /** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */ |
| 499 | #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT 2 |
| 500 | #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK \ |
| 501 | (0x3U << FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT) |
| 502 | #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE 0x1U |
| 503 | #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR 0x0U |
| 504 | |
| 505 | static inline uint16_t ffa_boot_info_content_format( |
| 506 | struct ffa_boot_info_desc *desc) |
| 507 | { |
| 508 | return (desc->flags & FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK) >> |
| 509 | FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT; |
| 510 | } |
| 511 | |
| 512 | static inline uint16_t ffa_boot_info_name_format( |
| 513 | struct ffa_boot_info_desc *desc) |
| 514 | { |
| 515 | return (desc->flags & FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK) >> |
| 516 | FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT; |
| 517 | } |
| 518 | |
| 519 | static inline uint8_t ffa_boot_info_type_id(struct ffa_boot_info_desc *desc) |
| 520 | { |
| 521 | return desc->type & FFA_BOOT_INFO_TYPE_ID_MASK; |
| 522 | } |
| 523 | |
| 524 | static inline uint8_t ffa_boot_info_type(struct ffa_boot_info_desc *desc) |
| 525 | { |
| 526 | return (desc->type & FFA_BOOT_INFO_TYPE_MASK) >> |
| 527 | FFA_BOOT_INFO_TYPE_SHIFT; |
| 528 | } |
| 529 | |
| 530 | /** Length in bytes of the signature in the boot descriptor. */ |
| 531 | #define FFA_BOOT_INFO_HEADER_SIGNATURE_LEN 4 |
| 532 | |
J-Alves | 240d84c | 2022-04-22 12:19:34 +0100 | [diff] [blame] | 533 | /** |
| 534 | * The FF-A boot information header, as defined in table 5.9 of section 5.4.2, |
| 535 | * of the FF-A v1.1 EAC0 specification. |
| 536 | */ |
J-Alves | dd1ad57 | 2022-01-25 17:58:26 +0000 | [diff] [blame] | 537 | struct ffa_boot_info_header { |
| 538 | uint32_t signature; |
| 539 | uint32_t version; |
| 540 | uint32_t info_blob_size; |
| 541 | uint32_t desc_size; |
| 542 | uint32_t desc_count; |
| 543 | uint32_t desc_offset; |
| 544 | uint64_t reserved; |
| 545 | struct ffa_boot_info_desc boot_info[]; |
| 546 | }; |
| 547 | |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 548 | /** |
J-Alves | 980d199 | 2021-03-18 12:49:18 +0000 | [diff] [blame] | 549 | * FF-A v1.1 specification restricts the number of notifications to a maximum |
| 550 | * of 64. Following all possible bitmaps. |
| 551 | */ |
| 552 | #define FFA_NOTIFICATION_MASK(ID) (UINT64_C(1) << ID) |
| 553 | |
| 554 | typedef uint64_t ffa_notifications_bitmap_t; |
| 555 | |
| 556 | #define MAX_FFA_NOTIFICATIONS 64U |
| 557 | |
| 558 | /** |
J-Alves | c003a7a | 2021-03-18 13:06:53 +0000 | [diff] [blame] | 559 | * Flag for notification bind and set, to specify call is about per-vCPU |
| 560 | * notifications. |
| 561 | */ |
Olivier Deprez | b76307d | 2022-06-09 17:17:45 +0200 | [diff] [blame] | 562 | #define FFA_NOTIFICATION_FLAG_PER_VCPU (UINT32_C(1) << 0) |
J-Alves | c003a7a | 2021-03-18 13:06:53 +0000 | [diff] [blame] | 563 | |
| 564 | /** |
J-Alves | 980d199 | 2021-03-18 12:49:18 +0000 | [diff] [blame] | 565 | * Helper function to assemble a 64-bit sized bitmap, from the 32-bit sized lo |
| 566 | * and hi. |
| 567 | * Helpful as FF-A specification defines that the notifications interfaces |
| 568 | * arguments are 32-bit registers. |
| 569 | */ |
| 570 | static inline ffa_notifications_bitmap_t ffa_notifications_bitmap(uint32_t lo, |
| 571 | uint32_t hi) |
| 572 | { |
| 573 | return (ffa_notifications_bitmap_t)hi << 32U | lo; |
| 574 | } |
| 575 | |
J-Alves | 98ff956 | 2021-09-09 14:39:41 +0100 | [diff] [blame] | 576 | static inline ffa_notifications_bitmap_t ffa_notification_get_from_sp( |
| 577 | struct ffa_value val) |
| 578 | { |
| 579 | return ffa_notifications_bitmap((uint32_t)val.arg2, (uint32_t)val.arg3); |
| 580 | } |
| 581 | |
| 582 | static inline ffa_notifications_bitmap_t ffa_notification_get_from_vm( |
| 583 | struct ffa_value val) |
| 584 | { |
| 585 | return ffa_notifications_bitmap((uint32_t)val.arg4, (uint32_t)val.arg5); |
| 586 | } |
| 587 | |
J-Alves | 980d199 | 2021-03-18 12:49:18 +0000 | [diff] [blame] | 588 | /** |
J-Alves | aa79c01 | 2021-07-09 14:29:45 +0100 | [diff] [blame] | 589 | * Flags used in calls to FFA_NOTIFICATION_GET interface. |
| 590 | */ |
Olivier Deprez | b76307d | 2022-06-09 17:17:45 +0200 | [diff] [blame] | 591 | #define FFA_NOTIFICATION_FLAG_BITMAP_SP (UINT32_C(1) << 0) |
| 592 | #define FFA_NOTIFICATION_FLAG_BITMAP_VM (UINT32_C(1) << 1) |
| 593 | #define FFA_NOTIFICATION_FLAG_BITMAP_SPM (UINT32_C(1) << 2) |
| 594 | #define FFA_NOTIFICATION_FLAG_BITMAP_HYP (UINT32_C(1) << 3) |
J-Alves | aa79c01 | 2021-07-09 14:29:45 +0100 | [diff] [blame] | 595 | |
J-Alves | a375507 | 2021-11-26 16:01:08 +0000 | [diff] [blame] | 596 | /* Flag to configure notification as being per vCPU. */ |
Olivier Deprez | b76307d | 2022-06-09 17:17:45 +0200 | [diff] [blame] | 597 | #define FFA_NOTIFICATIONS_FLAG_PER_VCPU (UINT32_C(1) << 0) |
J-Alves | a375507 | 2021-11-26 16:01:08 +0000 | [diff] [blame] | 598 | |
J-Alves | 1339402 | 2021-06-30 13:48:49 +0100 | [diff] [blame] | 599 | /** Flag for FFA_NOTIFICATION_SET to delay Schedule Receiver Interrupt */ |
Olivier Deprez | b76307d | 2022-06-09 17:17:45 +0200 | [diff] [blame] | 600 | #define FFA_NOTIFICATIONS_FLAG_DELAY_SRI (UINT32_C(1) << 1) |
| 601 | |
| 602 | #define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) \ |
| 603 | ((((uint32_t)(id)) & UINT32_C(0xffff)) << 16) |
J-Alves | 1339402 | 2021-06-30 13:48:49 +0100 | [diff] [blame] | 604 | |
J-Alves | be6e303 | 2021-11-30 14:54:12 +0000 | [diff] [blame] | 605 | 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] | 606 | { |
J-Alves | be6e303 | 2021-11-30 14:54:12 +0000 | [diff] [blame] | 607 | return (ffa_vcpu_index_t)(args.arg1 >> 16 & 0xffffU); |
J-Alves | aa79c01 | 2021-07-09 14:29:45 +0100 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | /** |
J-Alves | c8e8a22 | 2021-06-08 17:33:52 +0100 | [diff] [blame] | 611 | * The max number of IDs for return of FFA_NOTIFICATION_INFO_GET. |
| 612 | */ |
| 613 | #define FFA_NOTIFICATIONS_INFO_GET_MAX_IDS 20U |
| 614 | |
| 615 | /** |
| 616 | * Number of registers to use in successfull return of interface |
| 617 | * FFA_NOTIFICATION_INFO_GET. |
| 618 | */ |
| 619 | #define FFA_NOTIFICATIONS_INFO_GET_REGS_RET 5U |
| 620 | |
| 621 | #define FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING 0x1U |
| 622 | |
| 623 | /** |
| 624 | * Helper macros for return parameter encoding as described in section 17.7.1 |
| 625 | * of the FF-A v1.1 Beta0 specification. |
| 626 | */ |
| 627 | #define FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT 0x7U |
| 628 | #define FFA_NOTIFICATIONS_LISTS_COUNT_MASK 0x1fU |
| 629 | #define FFA_NOTIFICATIONS_LIST_SHIFT(l) (2 * (l - 1) + 12) |
| 630 | #define FFA_NOTIFICATIONS_LIST_SIZE_MASK 0x3U |
| 631 | |
| 632 | static inline uint32_t ffa_notification_info_get_lists_count( |
| 633 | struct ffa_value args) |
| 634 | { |
| 635 | return (uint32_t)(args.arg2 >> FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT) & |
| 636 | FFA_NOTIFICATIONS_LISTS_COUNT_MASK; |
| 637 | } |
| 638 | |
| 639 | static inline uint32_t ffa_notification_info_get_list_size( |
| 640 | struct ffa_value args, unsigned int list_idx) |
| 641 | { |
| 642 | return ((uint32_t)args.arg2 >> FFA_NOTIFICATIONS_LIST_SHIFT(list_idx)) & |
| 643 | FFA_NOTIFICATIONS_LIST_SIZE_MASK; |
| 644 | } |
| 645 | |
| 646 | static inline bool ffa_notification_info_get_more_pending(struct ffa_value args) |
| 647 | { |
| 648 | return (args.arg2 & FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING) != 0U; |
| 649 | } |
| 650 | |
| 651 | /** |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 652 | * A set of contiguous pages which is part of a memory region. This corresponds |
| 653 | * to table 40 of the FF-A 1.0 EAC specification, "Constituent memory region |
| 654 | * descriptor". |
| 655 | */ |
| 656 | struct ffa_memory_region_constituent { |
| 657 | /** |
| 658 | * The base IPA of the constituent memory region, aligned to 4 kiB page |
| 659 | * size granularity. |
| 660 | */ |
| 661 | uint64_t address; |
| 662 | /** The number of 4 kiB pages in the constituent memory region. */ |
| 663 | uint32_t page_count; |
| 664 | /** Reserved field, must be 0. */ |
| 665 | uint32_t reserved; |
| 666 | }; |
| 667 | |
| 668 | /** |
| 669 | * A set of pages comprising a memory region. This corresponds to table 39 of |
| 670 | * the FF-A 1.0 EAC specification, "Composite memory region descriptor". |
| 671 | */ |
| 672 | struct ffa_composite_memory_region { |
| 673 | /** |
| 674 | * The total number of 4 kiB pages included in this memory region. This |
| 675 | * must be equal to the sum of page counts specified in each |
| 676 | * `ffa_memory_region_constituent`. |
| 677 | */ |
| 678 | uint32_t page_count; |
| 679 | /** |
| 680 | * The number of constituents (`ffa_memory_region_constituent`) |
| 681 | * included in this memory region range. |
| 682 | */ |
| 683 | uint32_t constituent_count; |
| 684 | /** Reserved field, must be 0. */ |
| 685 | uint64_t reserved_0; |
| 686 | /** An array of `constituent_count` memory region constituents. */ |
| 687 | struct ffa_memory_region_constituent constituents[]; |
| 688 | }; |
| 689 | |
| 690 | /** Flags to indicate properties of receivers during memory region retrieval. */ |
| 691 | typedef uint8_t ffa_memory_receiver_flags_t; |
| 692 | |
| 693 | /** |
| 694 | * This corresponds to table 41 of the FF-A 1.0 EAC specification, "Memory |
| 695 | * access permissions descriptor". |
| 696 | */ |
| 697 | struct ffa_memory_region_attributes { |
| 698 | /** The ID of the VM to which the memory is being given or shared. */ |
| 699 | ffa_vm_id_t receiver; |
| 700 | /** |
| 701 | * The permissions with which the memory region should be mapped in the |
| 702 | * receiver's page table. |
| 703 | */ |
| 704 | ffa_memory_access_permissions_t permissions; |
| 705 | /** |
| 706 | * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP |
| 707 | * for memory regions with multiple borrowers. |
| 708 | */ |
| 709 | ffa_memory_receiver_flags_t flags; |
| 710 | }; |
| 711 | |
| 712 | /** Flags to control the behaviour of a memory sharing transaction. */ |
| 713 | typedef uint32_t ffa_memory_region_flags_t; |
| 714 | |
| 715 | /** |
| 716 | * Clear memory region contents after unmapping it from the sender and before |
| 717 | * mapping it for any receiver. |
| 718 | */ |
| 719 | #define FFA_MEMORY_REGION_FLAG_CLEAR 0x1 |
| 720 | |
| 721 | /** |
| 722 | * Whether the hypervisor may time slice the memory sharing or retrieval |
| 723 | * operation. |
| 724 | */ |
| 725 | #define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2 |
| 726 | |
| 727 | /** |
| 728 | * Whether the hypervisor should clear the memory region after the receiver |
| 729 | * relinquishes it or is aborted. |
| 730 | */ |
| 731 | #define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4 |
| 732 | |
| 733 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3) |
| 734 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3) |
| 735 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3) |
| 736 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3) |
| 737 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3) |
| 738 | |
Federico Recanati | 85090c4 | 2021-12-15 13:17:54 +0100 | [diff] [blame] | 739 | #define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_VALID ((0x1U) << 9) |
| 740 | #define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_MASK ((0xFU) << 5) |
| 741 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 742 | /** |
| 743 | * This corresponds to table 42 of the FF-A 1.0 EAC specification, "Endpoint |
| 744 | * memory access descriptor". |
| 745 | */ |
| 746 | struct ffa_memory_access { |
| 747 | struct ffa_memory_region_attributes receiver_permissions; |
| 748 | /** |
| 749 | * Offset in bytes from the start of the outer `ffa_memory_region` to |
| 750 | * an `ffa_composite_memory_region` struct. |
| 751 | */ |
| 752 | uint32_t composite_memory_region_offset; |
| 753 | uint64_t reserved_0; |
| 754 | }; |
| 755 | |
| 756 | /** |
| 757 | * Information about a set of pages which are being shared. This corresponds to |
| 758 | * table 45 of the FF-A 1.0 EAC specification, "Lend, donate or share memory |
| 759 | * transaction descriptor". Note that it is also used for retrieve requests and |
| 760 | * responses. |
| 761 | */ |
| 762 | struct ffa_memory_region { |
| 763 | /** |
| 764 | * The ID of the VM which originally sent the memory region, i.e. the |
| 765 | * owner. |
| 766 | */ |
| 767 | ffa_vm_id_t sender; |
| 768 | ffa_memory_attributes_t attributes; |
| 769 | /** Reserved field, must be 0. */ |
| 770 | uint8_t reserved_0; |
| 771 | /** Flags to control behaviour of the transaction. */ |
| 772 | ffa_memory_region_flags_t flags; |
| 773 | ffa_memory_handle_t handle; |
| 774 | /** |
| 775 | * An implementation defined value associated with the receiver and the |
| 776 | * memory region. |
| 777 | */ |
| 778 | uint64_t tag; |
| 779 | /** Reserved field, must be 0. */ |
| 780 | uint32_t reserved_1; |
| 781 | /** |
| 782 | * The number of `ffa_memory_access` entries included in this |
| 783 | * transaction. |
| 784 | */ |
| 785 | uint32_t receiver_count; |
| 786 | /** |
Federico Recanati | 3ddf28e | 2021-12-20 09:40:26 +0100 | [diff] [blame] | 787 | * An array of `receiver_count` endpoint memory access descriptors. |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 788 | * Each one specifies a memory region offset, an endpoint and the |
| 789 | * attributes with which this memory region should be mapped in that |
| 790 | * endpoint's page table. |
| 791 | */ |
| 792 | struct ffa_memory_access receivers[]; |
| 793 | }; |
| 794 | |
| 795 | /** |
| 796 | * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table |
| 797 | * 150 of the FF-A 1.0 EAC specification, "Descriptor to relinquish a memory |
| 798 | * region". |
| 799 | */ |
| 800 | struct ffa_mem_relinquish { |
| 801 | ffa_memory_handle_t handle; |
| 802 | ffa_memory_region_flags_t flags; |
| 803 | uint32_t endpoint_count; |
| 804 | ffa_vm_id_t endpoints[]; |
| 805 | }; |
| 806 | |
| 807 | /** |
| 808 | * Gets the `ffa_composite_memory_region` for the given receiver from an |
| 809 | * `ffa_memory_region`, or NULL if it is not valid. |
| 810 | */ |
| 811 | static inline struct ffa_composite_memory_region * |
| 812 | ffa_memory_region_get_composite(struct ffa_memory_region *memory_region, |
| 813 | uint32_t receiver_index) |
| 814 | { |
| 815 | uint32_t offset = memory_region->receivers[receiver_index] |
| 816 | .composite_memory_region_offset; |
| 817 | |
| 818 | if (offset == 0) { |
| 819 | return NULL; |
| 820 | } |
| 821 | |
| 822 | return (struct ffa_composite_memory_region *)((uint8_t *)memory_region + |
| 823 | offset); |
| 824 | } |
| 825 | |
| 826 | static inline uint32_t ffa_mem_relinquish_init( |
| 827 | struct ffa_mem_relinquish *relinquish_request, |
| 828 | ffa_memory_handle_t handle, ffa_memory_region_flags_t flags, |
| 829 | ffa_vm_id_t sender) |
| 830 | { |
| 831 | relinquish_request->handle = handle; |
| 832 | relinquish_request->flags = flags; |
| 833 | relinquish_request->endpoint_count = 1; |
| 834 | relinquish_request->endpoints[0] = sender; |
| 835 | return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_vm_id_t); |
| 836 | } |
| 837 | |
Federico Recanati | 392be39 | 2022-02-08 20:53:03 +0100 | [diff] [blame] | 838 | /** |
| 839 | * Endpoint RX/TX descriptor, as defined by Table 13.27 in FF-A v1.1 EAC0. |
| 840 | * It's used by the Hypervisor to describe the RX/TX buffers mapped by a VM |
| 841 | * to the SPMC, in order to allow indirect messaging. |
| 842 | */ |
| 843 | struct ffa_endpoint_rx_tx_descriptor { |
| 844 | ffa_vm_id_t endpoint_id; |
| 845 | uint16_t reserved; |
| 846 | |
| 847 | /* |
| 848 | * 8-byte aligned offset from the base address of this descriptor to the |
| 849 | * `ffa_composite_memory_region` describing the RX buffer. |
| 850 | */ |
| 851 | uint32_t rx_offset; |
| 852 | |
| 853 | /* |
| 854 | * 8-byte aligned offset from the base address of this descriptor to the |
| 855 | * `ffa_composite_memory_region` describing the TX buffer. |
| 856 | */ |
| 857 | uint32_t tx_offset; |
| 858 | |
| 859 | /* Pad to align on 16-byte boundary. */ |
| 860 | uint32_t pad; |
| 861 | }; |
| 862 | |
| 863 | static inline struct ffa_composite_memory_region * |
| 864 | ffa_enpoint_get_rx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc) |
| 865 | { |
| 866 | return (struct ffa_composite_memory_region *)((uintptr_t)desc + |
| 867 | desc->rx_offset); |
| 868 | } |
| 869 | |
| 870 | static inline struct ffa_composite_memory_region * |
| 871 | ffa_enpoint_get_tx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc) |
| 872 | { |
| 873 | return (struct ffa_composite_memory_region *)((uintptr_t)desc + |
| 874 | desc->tx_offset); |
| 875 | } |
| 876 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 877 | uint32_t ffa_memory_region_init( |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 878 | struct ffa_memory_region *memory_region, size_t memory_region_max_size, |
| 879 | ffa_vm_id_t sender, ffa_vm_id_t receiver, |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 880 | const struct ffa_memory_region_constituent constituents[], |
| 881 | uint32_t constituent_count, uint32_t tag, |
| 882 | ffa_memory_region_flags_t flags, enum ffa_data_access data_access, |
| 883 | enum ffa_instruction_access instruction_access, |
| 884 | enum ffa_memory_type type, enum ffa_memory_cacheability cacheability, |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 885 | enum ffa_memory_shareability shareability, uint32_t *fragment_length, |
| 886 | uint32_t *total_length); |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 887 | uint32_t ffa_memory_retrieve_request_init( |
| 888 | struct ffa_memory_region *memory_region, ffa_memory_handle_t handle, |
| 889 | ffa_vm_id_t sender, ffa_vm_id_t receiver, uint32_t tag, |
| 890 | ffa_memory_region_flags_t flags, enum ffa_data_access data_access, |
| 891 | enum ffa_instruction_access instruction_access, |
| 892 | enum ffa_memory_type type, enum ffa_memory_cacheability cacheability, |
| 893 | enum ffa_memory_shareability shareability); |
| 894 | uint32_t ffa_memory_lender_retrieve_request_init( |
| 895 | struct ffa_memory_region *memory_region, ffa_memory_handle_t handle, |
| 896 | ffa_vm_id_t sender); |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 897 | bool ffa_retrieved_memory_region_init( |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 898 | struct ffa_memory_region *response, size_t response_max_size, |
| 899 | ffa_vm_id_t sender, ffa_memory_attributes_t attributes, |
| 900 | ffa_memory_region_flags_t flags, ffa_memory_handle_t handle, |
| 901 | ffa_vm_id_t receiver, ffa_memory_access_permissions_t permissions, |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 902 | uint32_t page_count, uint32_t total_constituent_count, |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 903 | const struct ffa_memory_region_constituent constituents[], |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 904 | uint32_t fragment_constituent_count, uint32_t *total_length, |
| 905 | uint32_t *fragment_length); |
| 906 | uint32_t ffa_memory_fragment_init( |
| 907 | struct ffa_memory_region_constituent *fragment, |
| 908 | size_t fragment_max_size, |
| 909 | const struct ffa_memory_region_constituent constituents[], |
| 910 | uint32_t constituent_count, uint32_t *fragment_length); |
Federico Recanati | 392be39 | 2022-02-08 20:53:03 +0100 | [diff] [blame] | 911 | void ffa_endpoint_rx_tx_descriptor_init( |
| 912 | struct ffa_endpoint_rx_tx_descriptor *desc, ffa_vm_id_t endpoint_id, |
| 913 | uint64_t rx_address, uint64_t tx_address); |