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