Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Hafnium Authors. |
| 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 |
| 14 | #define FFA_VERSION_MINOR 0x0 |
| 15 | |
| 16 | #define FFA_VERSION_MAJOR_OFFSET 16 |
| 17 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 18 | /* clang-format off */ |
| 19 | |
| 20 | #define FFA_LOW_32_ID 0x84000060 |
| 21 | #define FFA_HIGH_32_ID 0x8400007F |
| 22 | #define FFA_LOW_64_ID 0xC4000060 |
Fuad Tabba | da72d14 | 2020-07-30 09:17:05 +0100 | [diff] [blame] | 23 | #define FFA_HIGH_64_ID 0xC400007F |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 24 | |
| 25 | /* FF-A function identifiers. */ |
| 26 | #define FFA_ERROR_32 0x84000060 |
| 27 | #define FFA_SUCCESS_32 0x84000061 |
| 28 | #define FFA_INTERRUPT_32 0x84000062 |
| 29 | #define FFA_VERSION_32 0x84000063 |
| 30 | #define FFA_FEATURES_32 0x84000064 |
| 31 | #define FFA_RX_RELEASE_32 0x84000065 |
| 32 | #define FFA_RXTX_MAP_32 0x84000066 |
| 33 | #define FFA_RXTX_MAP_64 0xC4000066 |
| 34 | #define FFA_RXTX_UNMAP_32 0x84000067 |
| 35 | #define FFA_PARTITION_INFO_GET_32 0x84000068 |
| 36 | #define FFA_ID_GET_32 0x84000069 |
| 37 | #define FFA_MSG_POLL_32 0x8400006A |
| 38 | #define FFA_MSG_WAIT_32 0x8400006B |
| 39 | #define FFA_YIELD_32 0x8400006C |
| 40 | #define FFA_RUN_32 0x8400006D |
| 41 | #define FFA_MSG_SEND_32 0x8400006E |
| 42 | #define FFA_MSG_SEND_DIRECT_REQ_32 0x8400006F |
| 43 | #define FFA_MSG_SEND_DIRECT_RESP_32 0x84000070 |
| 44 | #define FFA_MEM_DONATE_32 0x84000071 |
| 45 | #define FFA_MEM_LEND_32 0x84000072 |
| 46 | #define FFA_MEM_SHARE_32 0x84000073 |
| 47 | #define FFA_MEM_RETRIEVE_REQ_32 0x84000074 |
| 48 | #define FFA_MEM_RETRIEVE_RESP_32 0x84000075 |
| 49 | #define FFA_MEM_RELINQUISH_32 0x84000076 |
| 50 | #define FFA_MEM_RECLAIM_32 0x84000077 |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 51 | #define FFA_MEM_FRAG_RX_32 0x8400007A |
| 52 | #define FFA_MEM_FRAG_TX_32 0x8400007B |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 53 | |
| 54 | /* FF-A error codes. */ |
| 55 | #define FFA_NOT_SUPPORTED INT32_C(-1) |
| 56 | #define FFA_INVALID_PARAMETERS INT32_C(-2) |
| 57 | #define FFA_NO_MEMORY INT32_C(-3) |
| 58 | #define FFA_BUSY INT32_C(-4) |
| 59 | #define FFA_INTERRUPTED INT32_C(-5) |
| 60 | #define FFA_DENIED INT32_C(-6) |
| 61 | #define FFA_RETRY INT32_C(-7) |
| 62 | #define FFA_ABORTED INT32_C(-8) |
| 63 | |
| 64 | /* clang-format on */ |
| 65 | |
| 66 | /* FF-A function specific constants. */ |
| 67 | #define FFA_MSG_RECV_BLOCK 0x1 |
| 68 | #define FFA_MSG_RECV_BLOCK_MASK 0x1 |
| 69 | |
| 70 | #define FFA_MSG_SEND_NOTIFY 0x1 |
| 71 | #define FFA_MSG_SEND_NOTIFY_MASK 0x1 |
| 72 | |
| 73 | #define FFA_MEM_RECLAIM_CLEAR 0x1 |
| 74 | |
| 75 | #define FFA_SLEEP_INDEFINITE 0 |
| 76 | |
| 77 | /** |
| 78 | * For use where the FF-A specification refers explicitly to '4K pages'. Not to |
| 79 | * be confused with PAGE_SIZE, which is the translation granule Hafnium is |
| 80 | * configured to use. |
| 81 | */ |
| 82 | #define FFA_PAGE_SIZE 4096 |
| 83 | |
| 84 | /* The maximum length possible for a single message. */ |
| 85 | #define FFA_MSG_PAYLOAD_MAX HF_MAILBOX_SIZE |
| 86 | |
| 87 | enum ffa_data_access { |
| 88 | FFA_DATA_ACCESS_NOT_SPECIFIED, |
| 89 | FFA_DATA_ACCESS_RO, |
| 90 | FFA_DATA_ACCESS_RW, |
| 91 | FFA_DATA_ACCESS_RESERVED, |
| 92 | }; |
| 93 | |
| 94 | enum ffa_instruction_access { |
| 95 | FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED, |
| 96 | FFA_INSTRUCTION_ACCESS_NX, |
| 97 | FFA_INSTRUCTION_ACCESS_X, |
| 98 | FFA_INSTRUCTION_ACCESS_RESERVED, |
| 99 | }; |
| 100 | |
| 101 | enum ffa_memory_type { |
| 102 | FFA_MEMORY_NOT_SPECIFIED_MEM, |
| 103 | FFA_MEMORY_DEVICE_MEM, |
| 104 | FFA_MEMORY_NORMAL_MEM, |
| 105 | }; |
| 106 | |
| 107 | enum ffa_memory_cacheability { |
| 108 | FFA_MEMORY_CACHE_RESERVED = 0x0, |
| 109 | FFA_MEMORY_CACHE_NON_CACHEABLE = 0x1, |
| 110 | FFA_MEMORY_CACHE_RESERVED_1 = 0x2, |
| 111 | FFA_MEMORY_CACHE_WRITE_BACK = 0x3, |
| 112 | FFA_MEMORY_DEV_NGNRNE = 0x0, |
| 113 | FFA_MEMORY_DEV_NGNRE = 0x1, |
| 114 | FFA_MEMORY_DEV_NGRE = 0x2, |
| 115 | FFA_MEMORY_DEV_GRE = 0x3, |
| 116 | }; |
| 117 | |
| 118 | enum ffa_memory_shareability { |
| 119 | FFA_MEMORY_SHARE_NON_SHAREABLE, |
| 120 | FFA_MEMORY_SHARE_RESERVED, |
| 121 | FFA_MEMORY_OUTER_SHAREABLE, |
| 122 | FFA_MEMORY_INNER_SHAREABLE, |
| 123 | }; |
| 124 | |
| 125 | typedef uint8_t ffa_memory_access_permissions_t; |
| 126 | |
| 127 | /** |
| 128 | * This corresponds to table 44 of the FF-A 1.0 EAC specification, "Memory |
| 129 | * region attributes descriptor". |
| 130 | */ |
| 131 | typedef uint8_t ffa_memory_attributes_t; |
| 132 | |
| 133 | #define FFA_DATA_ACCESS_OFFSET (0x0U) |
| 134 | #define FFA_DATA_ACCESS_MASK ((0x3U) << FFA_DATA_ACCESS_OFFSET) |
| 135 | |
| 136 | #define FFA_INSTRUCTION_ACCESS_OFFSET (0x2U) |
| 137 | #define FFA_INSTRUCTION_ACCESS_MASK ((0x3U) << FFA_INSTRUCTION_ACCESS_OFFSET) |
| 138 | |
| 139 | #define FFA_MEMORY_TYPE_OFFSET (0x4U) |
| 140 | #define FFA_MEMORY_TYPE_MASK ((0x3U) << FFA_MEMORY_TYPE_OFFSET) |
| 141 | |
| 142 | #define FFA_MEMORY_CACHEABILITY_OFFSET (0x2U) |
| 143 | #define FFA_MEMORY_CACHEABILITY_MASK ((0x3U) << FFA_MEMORY_CACHEABILITY_OFFSET) |
| 144 | |
| 145 | #define FFA_MEMORY_SHAREABILITY_OFFSET (0x0U) |
| 146 | #define FFA_MEMORY_SHAREABILITY_MASK ((0x3U) << FFA_MEMORY_SHAREABILITY_OFFSET) |
| 147 | |
| 148 | #define ATTR_FUNCTION_SET(name, container_type, offset, mask) \ |
| 149 | static inline void ffa_set_##name##_attr(container_type *attr, \ |
| 150 | const enum ffa_##name perm) \ |
| 151 | { \ |
| 152 | *attr = (*attr & ~(mask)) | ((perm << offset) & mask); \ |
| 153 | } |
| 154 | |
| 155 | #define ATTR_FUNCTION_GET(name, container_type, offset, mask) \ |
| 156 | static inline enum ffa_##name ffa_get_##name##_attr( \ |
| 157 | container_type attr) \ |
| 158 | { \ |
| 159 | return (enum ffa_##name)((attr & mask) >> offset); \ |
| 160 | } |
| 161 | |
| 162 | ATTR_FUNCTION_SET(data_access, ffa_memory_access_permissions_t, |
| 163 | FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK) |
| 164 | ATTR_FUNCTION_GET(data_access, ffa_memory_access_permissions_t, |
| 165 | FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK) |
| 166 | |
| 167 | ATTR_FUNCTION_SET(instruction_access, ffa_memory_access_permissions_t, |
| 168 | FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK) |
| 169 | ATTR_FUNCTION_GET(instruction_access, ffa_memory_access_permissions_t, |
| 170 | FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK) |
| 171 | |
| 172 | ATTR_FUNCTION_SET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET, |
| 173 | FFA_MEMORY_TYPE_MASK) |
| 174 | ATTR_FUNCTION_GET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET, |
| 175 | FFA_MEMORY_TYPE_MASK) |
| 176 | |
| 177 | ATTR_FUNCTION_SET(memory_cacheability, ffa_memory_attributes_t, |
| 178 | FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK) |
| 179 | ATTR_FUNCTION_GET(memory_cacheability, ffa_memory_attributes_t, |
| 180 | FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK) |
| 181 | |
| 182 | ATTR_FUNCTION_SET(memory_shareability, ffa_memory_attributes_t, |
| 183 | FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK) |
| 184 | ATTR_FUNCTION_GET(memory_shareability, ffa_memory_attributes_t, |
| 185 | FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK) |
| 186 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 187 | /** |
| 188 | * A globally-unique ID assigned by the hypervisor for a region of memory being |
| 189 | * sent between VMs. |
| 190 | */ |
| 191 | typedef uint64_t ffa_memory_handle_t; |
| 192 | |
J-Alves | 917d2f2 | 2020-10-30 18:39:30 +0000 | [diff] [blame^] | 193 | #define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \ |
| 194 | ((ffa_memory_handle_t)(UINT64_C(1) << 63)) |
| 195 | #define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR \ |
| 196 | ((ffa_memory_handle_t)(UINT64_C(1) << 63)) |
| 197 | |
| 198 | #define FFA_MEMORY_HANDLE_ALLOCATOR_SPMC (UINT64_C(0) << 63) |
| 199 | #define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0)) |
| 200 | |
| 201 | /** The ID of a VM. These are assigned sequentially starting with an offset. */ |
| 202 | typedef uint16_t ffa_vm_id_t; |
| 203 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 204 | /** |
| 205 | * A count of VMs. This has the same range as the VM IDs but we give it a |
| 206 | * different name to make the different semantics clear. |
| 207 | */ |
| 208 | typedef ffa_vm_id_t ffa_vm_count_t; |
| 209 | |
| 210 | /** The index of a vCPU within a particular VM. */ |
| 211 | typedef uint16_t ffa_vcpu_index_t; |
| 212 | |
| 213 | /** |
| 214 | * A count of vCPUs. This has the same range as the vCPU indices but we give it |
| 215 | * a different name to make the different semantics clear. |
| 216 | */ |
| 217 | typedef ffa_vcpu_index_t ffa_vcpu_count_t; |
| 218 | |
| 219 | /** Parameter and return type of FF-A functions. */ |
| 220 | struct ffa_value { |
| 221 | uint64_t func; |
| 222 | uint64_t arg1; |
| 223 | uint64_t arg2; |
| 224 | uint64_t arg3; |
| 225 | uint64_t arg4; |
| 226 | uint64_t arg5; |
| 227 | uint64_t arg6; |
| 228 | uint64_t arg7; |
| 229 | }; |
| 230 | |
| 231 | static inline ffa_vm_id_t ffa_msg_send_sender(struct ffa_value args) |
| 232 | { |
| 233 | return (args.arg1 >> 16) & 0xffff; |
| 234 | } |
| 235 | |
| 236 | static inline ffa_vm_id_t ffa_msg_send_receiver(struct ffa_value args) |
| 237 | { |
| 238 | return args.arg1 & 0xffff; |
| 239 | } |
| 240 | |
| 241 | static inline uint32_t ffa_msg_send_size(struct ffa_value args) |
| 242 | { |
| 243 | return args.arg3; |
| 244 | } |
| 245 | |
| 246 | static inline uint32_t ffa_msg_send_attributes(struct ffa_value args) |
| 247 | { |
| 248 | return args.arg4; |
| 249 | } |
| 250 | |
Andrew Walbran | 1bbe940 | 2020-04-30 16:47:13 +0100 | [diff] [blame] | 251 | static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t a1, uint32_t a2) |
| 252 | { |
| 253 | return (uint64_t)a1 | (uint64_t)a2 << 32; |
| 254 | } |
| 255 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 256 | static inline ffa_memory_handle_t ffa_mem_success_handle(struct ffa_value args) |
| 257 | { |
Andrew Walbran | 1bbe940 | 2020-04-30 16:47:13 +0100 | [diff] [blame] | 258 | return ffa_assemble_handle(args.arg2, args.arg3); |
| 259 | } |
| 260 | |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 261 | static inline ffa_memory_handle_t ffa_frag_handle(struct ffa_value args) |
| 262 | { |
| 263 | return ffa_assemble_handle(args.arg1, args.arg2); |
| 264 | } |
| 265 | |
Andrew Walbran | 1bbe940 | 2020-04-30 16:47:13 +0100 | [diff] [blame] | 266 | static inline struct ffa_value ffa_mem_success(ffa_memory_handle_t handle) |
| 267 | { |
| 268 | return (struct ffa_value){.func = FFA_SUCCESS_32, |
| 269 | .arg2 = (uint32_t)handle, |
| 270 | .arg3 = (uint32_t)(handle >> 32)}; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | static inline ffa_vm_id_t ffa_vm_id(struct ffa_value args) |
| 274 | { |
| 275 | return (args.arg1 >> 16) & 0xffff; |
| 276 | } |
| 277 | |
| 278 | static inline ffa_vcpu_index_t ffa_vcpu_index(struct ffa_value args) |
| 279 | { |
| 280 | return args.arg1 & 0xffff; |
| 281 | } |
| 282 | |
| 283 | static inline uint64_t ffa_vm_vcpu(ffa_vm_id_t vm_id, |
| 284 | ffa_vcpu_index_t vcpu_index) |
| 285 | { |
| 286 | return ((uint32_t)vm_id << 16) | vcpu_index; |
| 287 | } |
| 288 | |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 289 | static inline ffa_vm_id_t ffa_frag_sender(struct ffa_value args) |
| 290 | { |
| 291 | return (args.arg4 >> 16) & 0xffff; |
| 292 | } |
| 293 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 294 | /** |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 295 | * Holds the UUID in a struct that is mappable directly to the SMCC calling |
| 296 | * convention, which is used for FF-A calls. |
| 297 | * |
| 298 | * Refer to table 84 of the FF-A 1.0 EAC specification as well as section 5.3 |
| 299 | * of the SMCC Spec 1.2. |
| 300 | */ |
| 301 | struct ffa_uuid { |
| 302 | uint32_t uuid[4]; |
| 303 | }; |
| 304 | |
| 305 | static inline void ffa_uuid_init(uint32_t w0, uint32_t w1, uint32_t w2, |
| 306 | uint32_t w3, struct ffa_uuid *uuid) |
| 307 | { |
| 308 | uuid->uuid[0] = w0; |
| 309 | uuid->uuid[1] = w1; |
| 310 | uuid->uuid[2] = w2; |
| 311 | uuid->uuid[3] = w3; |
| 312 | } |
| 313 | |
| 314 | static inline bool ffa_uuid_equal(const struct ffa_uuid *uuid1, |
| 315 | const struct ffa_uuid *uuid2) |
| 316 | { |
| 317 | return (uuid1->uuid[0] == uuid2->uuid[0]) && |
| 318 | (uuid1->uuid[1] == uuid2->uuid[1]) && |
| 319 | (uuid1->uuid[2] == uuid2->uuid[2]) && |
| 320 | (uuid1->uuid[3] == uuid2->uuid[3]); |
| 321 | } |
| 322 | |
| 323 | static inline bool ffa_uuid_is_null(const struct ffa_uuid *uuid) |
| 324 | { |
| 325 | return (uuid->uuid[0] == 0) && (uuid->uuid[1] == 0) && |
| 326 | (uuid->uuid[2] == 0) && (uuid->uuid[3] == 0); |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Flags to determine the partition properties, as required by |
| 331 | * FFA_PARTITION_INFO_GET. |
| 332 | * |
| 333 | * The values of the flags are specified in table 82 of the FF-A 1.0 EAC |
| 334 | * specification, "Partition information descriptor, partition properties". |
| 335 | */ |
| 336 | typedef uint32_t ffa_partition_properties_t; |
| 337 | |
| 338 | /** Partition property: partition supports receipt of direct requests. */ |
| 339 | #define FFA_PARTITION_DIRECT_RECV 0x1 |
| 340 | |
| 341 | /** Partition property: partition can send direct requests. */ |
| 342 | #define FFA_PARTITION_DIRECT_SEND 0x2 |
| 343 | |
| 344 | /** Partition property: partition can send and receive indirect messages. */ |
| 345 | #define FFA_PARTITION_INDIRECT_MSG 0x4 |
| 346 | |
| 347 | /** |
| 348 | * Holds information returned for each partition by the FFA_PARTITION_INFO_GET |
| 349 | * interface. |
| 350 | * This corresponds to table 82 of the FF-A 1.0 EAC specification, "Partition |
| 351 | * information descriptor". |
| 352 | */ |
| 353 | struct ffa_partition_info { |
| 354 | ffa_vm_id_t vm_id; |
| 355 | ffa_vcpu_count_t vcpu_count; |
| 356 | ffa_partition_properties_t properties; |
| 357 | }; |
| 358 | |
| 359 | /** |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 360 | * A set of contiguous pages which is part of a memory region. This corresponds |
| 361 | * to table 40 of the FF-A 1.0 EAC specification, "Constituent memory region |
| 362 | * descriptor". |
| 363 | */ |
| 364 | struct ffa_memory_region_constituent { |
| 365 | /** |
| 366 | * The base IPA of the constituent memory region, aligned to 4 kiB page |
| 367 | * size granularity. |
| 368 | */ |
| 369 | uint64_t address; |
| 370 | /** The number of 4 kiB pages in the constituent memory region. */ |
| 371 | uint32_t page_count; |
| 372 | /** Reserved field, must be 0. */ |
| 373 | uint32_t reserved; |
| 374 | }; |
| 375 | |
| 376 | /** |
| 377 | * A set of pages comprising a memory region. This corresponds to table 39 of |
| 378 | * the FF-A 1.0 EAC specification, "Composite memory region descriptor". |
| 379 | */ |
| 380 | struct ffa_composite_memory_region { |
| 381 | /** |
| 382 | * The total number of 4 kiB pages included in this memory region. This |
| 383 | * must be equal to the sum of page counts specified in each |
| 384 | * `ffa_memory_region_constituent`. |
| 385 | */ |
| 386 | uint32_t page_count; |
| 387 | /** |
| 388 | * The number of constituents (`ffa_memory_region_constituent`) |
| 389 | * included in this memory region range. |
| 390 | */ |
| 391 | uint32_t constituent_count; |
| 392 | /** Reserved field, must be 0. */ |
| 393 | uint64_t reserved_0; |
| 394 | /** An array of `constituent_count` memory region constituents. */ |
| 395 | struct ffa_memory_region_constituent constituents[]; |
| 396 | }; |
| 397 | |
| 398 | /** Flags to indicate properties of receivers during memory region retrieval. */ |
| 399 | typedef uint8_t ffa_memory_receiver_flags_t; |
| 400 | |
| 401 | /** |
| 402 | * This corresponds to table 41 of the FF-A 1.0 EAC specification, "Memory |
| 403 | * access permissions descriptor". |
| 404 | */ |
| 405 | struct ffa_memory_region_attributes { |
| 406 | /** The ID of the VM to which the memory is being given or shared. */ |
| 407 | ffa_vm_id_t receiver; |
| 408 | /** |
| 409 | * The permissions with which the memory region should be mapped in the |
| 410 | * receiver's page table. |
| 411 | */ |
| 412 | ffa_memory_access_permissions_t permissions; |
| 413 | /** |
| 414 | * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP |
| 415 | * for memory regions with multiple borrowers. |
| 416 | */ |
| 417 | ffa_memory_receiver_flags_t flags; |
| 418 | }; |
| 419 | |
| 420 | /** Flags to control the behaviour of a memory sharing transaction. */ |
| 421 | typedef uint32_t ffa_memory_region_flags_t; |
| 422 | |
| 423 | /** |
| 424 | * Clear memory region contents after unmapping it from the sender and before |
| 425 | * mapping it for any receiver. |
| 426 | */ |
| 427 | #define FFA_MEMORY_REGION_FLAG_CLEAR 0x1 |
| 428 | |
| 429 | /** |
| 430 | * Whether the hypervisor may time slice the memory sharing or retrieval |
| 431 | * operation. |
| 432 | */ |
| 433 | #define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2 |
| 434 | |
| 435 | /** |
| 436 | * Whether the hypervisor should clear the memory region after the receiver |
| 437 | * relinquishes it or is aborted. |
| 438 | */ |
| 439 | #define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4 |
| 440 | |
| 441 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3) |
| 442 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3) |
| 443 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3) |
| 444 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3) |
| 445 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3) |
| 446 | |
| 447 | /** |
| 448 | * This corresponds to table 42 of the FF-A 1.0 EAC specification, "Endpoint |
| 449 | * memory access descriptor". |
| 450 | */ |
| 451 | struct ffa_memory_access { |
| 452 | struct ffa_memory_region_attributes receiver_permissions; |
| 453 | /** |
| 454 | * Offset in bytes from the start of the outer `ffa_memory_region` to |
| 455 | * an `ffa_composite_memory_region` struct. |
| 456 | */ |
| 457 | uint32_t composite_memory_region_offset; |
| 458 | uint64_t reserved_0; |
| 459 | }; |
| 460 | |
| 461 | /** |
| 462 | * Information about a set of pages which are being shared. This corresponds to |
| 463 | * table 45 of the FF-A 1.0 EAC specification, "Lend, donate or share memory |
| 464 | * transaction descriptor". Note that it is also used for retrieve requests and |
| 465 | * responses. |
| 466 | */ |
| 467 | struct ffa_memory_region { |
| 468 | /** |
| 469 | * The ID of the VM which originally sent the memory region, i.e. the |
| 470 | * owner. |
| 471 | */ |
| 472 | ffa_vm_id_t sender; |
| 473 | ffa_memory_attributes_t attributes; |
| 474 | /** Reserved field, must be 0. */ |
| 475 | uint8_t reserved_0; |
| 476 | /** Flags to control behaviour of the transaction. */ |
| 477 | ffa_memory_region_flags_t flags; |
| 478 | ffa_memory_handle_t handle; |
| 479 | /** |
| 480 | * An implementation defined value associated with the receiver and the |
| 481 | * memory region. |
| 482 | */ |
| 483 | uint64_t tag; |
| 484 | /** Reserved field, must be 0. */ |
| 485 | uint32_t reserved_1; |
| 486 | /** |
| 487 | * The number of `ffa_memory_access` entries included in this |
| 488 | * transaction. |
| 489 | */ |
| 490 | uint32_t receiver_count; |
| 491 | /** |
| 492 | * An array of `attribute_count` endpoint memory access descriptors. |
| 493 | * Each one specifies a memory region offset, an endpoint and the |
| 494 | * attributes with which this memory region should be mapped in that |
| 495 | * endpoint's page table. |
| 496 | */ |
| 497 | struct ffa_memory_access receivers[]; |
| 498 | }; |
| 499 | |
| 500 | /** |
| 501 | * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table |
| 502 | * 150 of the FF-A 1.0 EAC specification, "Descriptor to relinquish a memory |
| 503 | * region". |
| 504 | */ |
| 505 | struct ffa_mem_relinquish { |
| 506 | ffa_memory_handle_t handle; |
| 507 | ffa_memory_region_flags_t flags; |
| 508 | uint32_t endpoint_count; |
| 509 | ffa_vm_id_t endpoints[]; |
| 510 | }; |
| 511 | |
| 512 | /** |
| 513 | * Gets the `ffa_composite_memory_region` for the given receiver from an |
| 514 | * `ffa_memory_region`, or NULL if it is not valid. |
| 515 | */ |
| 516 | static inline struct ffa_composite_memory_region * |
| 517 | ffa_memory_region_get_composite(struct ffa_memory_region *memory_region, |
| 518 | uint32_t receiver_index) |
| 519 | { |
| 520 | uint32_t offset = memory_region->receivers[receiver_index] |
| 521 | .composite_memory_region_offset; |
| 522 | |
| 523 | if (offset == 0) { |
| 524 | return NULL; |
| 525 | } |
| 526 | |
| 527 | return (struct ffa_composite_memory_region *)((uint8_t *)memory_region + |
| 528 | offset); |
| 529 | } |
| 530 | |
| 531 | static inline uint32_t ffa_mem_relinquish_init( |
| 532 | struct ffa_mem_relinquish *relinquish_request, |
| 533 | ffa_memory_handle_t handle, ffa_memory_region_flags_t flags, |
| 534 | ffa_vm_id_t sender) |
| 535 | { |
| 536 | relinquish_request->handle = handle; |
| 537 | relinquish_request->flags = flags; |
| 538 | relinquish_request->endpoint_count = 1; |
| 539 | relinquish_request->endpoints[0] = sender; |
| 540 | return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_vm_id_t); |
| 541 | } |
| 542 | |
| 543 | uint32_t ffa_memory_region_init( |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 544 | struct ffa_memory_region *memory_region, size_t memory_region_max_size, |
| 545 | ffa_vm_id_t sender, ffa_vm_id_t receiver, |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 546 | const struct ffa_memory_region_constituent constituents[], |
| 547 | uint32_t constituent_count, uint32_t tag, |
| 548 | ffa_memory_region_flags_t flags, enum ffa_data_access data_access, |
| 549 | enum ffa_instruction_access instruction_access, |
| 550 | enum ffa_memory_type type, enum ffa_memory_cacheability cacheability, |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 551 | enum ffa_memory_shareability shareability, uint32_t *fragment_length, |
| 552 | uint32_t *total_length); |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 553 | uint32_t ffa_memory_retrieve_request_init( |
| 554 | struct ffa_memory_region *memory_region, ffa_memory_handle_t handle, |
| 555 | ffa_vm_id_t sender, ffa_vm_id_t receiver, uint32_t tag, |
| 556 | ffa_memory_region_flags_t flags, enum ffa_data_access data_access, |
| 557 | enum ffa_instruction_access instruction_access, |
| 558 | enum ffa_memory_type type, enum ffa_memory_cacheability cacheability, |
| 559 | enum ffa_memory_shareability shareability); |
| 560 | uint32_t ffa_memory_lender_retrieve_request_init( |
| 561 | struct ffa_memory_region *memory_region, ffa_memory_handle_t handle, |
| 562 | ffa_vm_id_t sender); |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 563 | bool ffa_retrieved_memory_region_init( |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 564 | struct ffa_memory_region *response, size_t response_max_size, |
| 565 | ffa_vm_id_t sender, ffa_memory_attributes_t attributes, |
| 566 | ffa_memory_region_flags_t flags, ffa_memory_handle_t handle, |
| 567 | ffa_vm_id_t receiver, ffa_memory_access_permissions_t permissions, |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 568 | uint32_t page_count, uint32_t total_constituent_count, |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 569 | const struct ffa_memory_region_constituent constituents[], |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 570 | uint32_t fragment_constituent_count, uint32_t *total_length, |
| 571 | uint32_t *fragment_length); |
| 572 | uint32_t ffa_memory_fragment_init( |
| 573 | struct ffa_memory_region_constituent *fragment, |
| 574 | size_t fragment_max_size, |
| 575 | const struct ffa_memory_region_constituent constituents[], |
| 576 | uint32_t constituent_count, uint32_t *fragment_length); |