blob: 747117820cfab9845293b8f0181816223945a26a [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. */
358#define FFA_PARTITION_DIRECT_RECV 0x1
359
360/** Partition property: partition can send direct requests. */
361#define FFA_PARTITION_DIRECT_SEND 0x2
362
363/** Partition property: partition can send and receive indirect messages. */
364#define FFA_PARTITION_INDIRECT_MSG 0x4
365
366/**
367 * Holds information returned for each partition by the FFA_PARTITION_INFO_GET
368 * interface.
369 * This corresponds to table 82 of the FF-A 1.0 EAC specification, "Partition
370 * information descriptor".
371 */
372struct ffa_partition_info {
373 ffa_vm_id_t vm_id;
374 ffa_vcpu_count_t vcpu_count;
375 ffa_partition_properties_t properties;
376};
377
378/**
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100379 * A set of contiguous pages which is part of a memory region. This corresponds
380 * to table 40 of the FF-A 1.0 EAC specification, "Constituent memory region
381 * descriptor".
382 */
383struct ffa_memory_region_constituent {
384 /**
385 * The base IPA of the constituent memory region, aligned to 4 kiB page
386 * size granularity.
387 */
388 uint64_t address;
389 /** The number of 4 kiB pages in the constituent memory region. */
390 uint32_t page_count;
391 /** Reserved field, must be 0. */
392 uint32_t reserved;
393};
394
395/**
396 * A set of pages comprising a memory region. This corresponds to table 39 of
397 * the FF-A 1.0 EAC specification, "Composite memory region descriptor".
398 */
399struct ffa_composite_memory_region {
400 /**
401 * The total number of 4 kiB pages included in this memory region. This
402 * must be equal to the sum of page counts specified in each
403 * `ffa_memory_region_constituent`.
404 */
405 uint32_t page_count;
406 /**
407 * The number of constituents (`ffa_memory_region_constituent`)
408 * included in this memory region range.
409 */
410 uint32_t constituent_count;
411 /** Reserved field, must be 0. */
412 uint64_t reserved_0;
413 /** An array of `constituent_count` memory region constituents. */
414 struct ffa_memory_region_constituent constituents[];
415};
416
417/** Flags to indicate properties of receivers during memory region retrieval. */
418typedef uint8_t ffa_memory_receiver_flags_t;
419
420/**
421 * This corresponds to table 41 of the FF-A 1.0 EAC specification, "Memory
422 * access permissions descriptor".
423 */
424struct ffa_memory_region_attributes {
425 /** The ID of the VM to which the memory is being given or shared. */
426 ffa_vm_id_t receiver;
427 /**
428 * The permissions with which the memory region should be mapped in the
429 * receiver's page table.
430 */
431 ffa_memory_access_permissions_t permissions;
432 /**
433 * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP
434 * for memory regions with multiple borrowers.
435 */
436 ffa_memory_receiver_flags_t flags;
437};
438
439/** Flags to control the behaviour of a memory sharing transaction. */
440typedef uint32_t ffa_memory_region_flags_t;
441
442/**
443 * Clear memory region contents after unmapping it from the sender and before
444 * mapping it for any receiver.
445 */
446#define FFA_MEMORY_REGION_FLAG_CLEAR 0x1
447
448/**
449 * Whether the hypervisor may time slice the memory sharing or retrieval
450 * operation.
451 */
452#define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2
453
454/**
455 * Whether the hypervisor should clear the memory region after the receiver
456 * relinquishes it or is aborted.
457 */
458#define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4
459
460#define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3)
461#define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3)
462#define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3)
463#define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3)
464#define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3)
465
466/**
467 * This corresponds to table 42 of the FF-A 1.0 EAC specification, "Endpoint
468 * memory access descriptor".
469 */
470struct ffa_memory_access {
471 struct ffa_memory_region_attributes receiver_permissions;
472 /**
473 * Offset in bytes from the start of the outer `ffa_memory_region` to
474 * an `ffa_composite_memory_region` struct.
475 */
476 uint32_t composite_memory_region_offset;
477 uint64_t reserved_0;
478};
479
480/**
481 * Information about a set of pages which are being shared. This corresponds to
482 * table 45 of the FF-A 1.0 EAC specification, "Lend, donate or share memory
483 * transaction descriptor". Note that it is also used for retrieve requests and
484 * responses.
485 */
486struct ffa_memory_region {
487 /**
488 * The ID of the VM which originally sent the memory region, i.e. the
489 * owner.
490 */
491 ffa_vm_id_t sender;
492 ffa_memory_attributes_t attributes;
493 /** Reserved field, must be 0. */
494 uint8_t reserved_0;
495 /** Flags to control behaviour of the transaction. */
496 ffa_memory_region_flags_t flags;
497 ffa_memory_handle_t handle;
498 /**
499 * An implementation defined value associated with the receiver and the
500 * memory region.
501 */
502 uint64_t tag;
503 /** Reserved field, must be 0. */
504 uint32_t reserved_1;
505 /**
506 * The number of `ffa_memory_access` entries included in this
507 * transaction.
508 */
509 uint32_t receiver_count;
510 /**
511 * An array of `attribute_count` endpoint memory access descriptors.
512 * Each one specifies a memory region offset, an endpoint and the
513 * attributes with which this memory region should be mapped in that
514 * endpoint's page table.
515 */
516 struct ffa_memory_access receivers[];
517};
518
519/**
520 * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table
521 * 150 of the FF-A 1.0 EAC specification, "Descriptor to relinquish a memory
522 * region".
523 */
524struct ffa_mem_relinquish {
525 ffa_memory_handle_t handle;
526 ffa_memory_region_flags_t flags;
527 uint32_t endpoint_count;
528 ffa_vm_id_t endpoints[];
529};
530
531/**
532 * Gets the `ffa_composite_memory_region` for the given receiver from an
533 * `ffa_memory_region`, or NULL if it is not valid.
534 */
535static inline struct ffa_composite_memory_region *
536ffa_memory_region_get_composite(struct ffa_memory_region *memory_region,
537 uint32_t receiver_index)
538{
539 uint32_t offset = memory_region->receivers[receiver_index]
540 .composite_memory_region_offset;
541
542 if (offset == 0) {
543 return NULL;
544 }
545
546 return (struct ffa_composite_memory_region *)((uint8_t *)memory_region +
547 offset);
548}
549
550static inline uint32_t ffa_mem_relinquish_init(
551 struct ffa_mem_relinquish *relinquish_request,
552 ffa_memory_handle_t handle, ffa_memory_region_flags_t flags,
553 ffa_vm_id_t sender)
554{
555 relinquish_request->handle = handle;
556 relinquish_request->flags = flags;
557 relinquish_request->endpoint_count = 1;
558 relinquish_request->endpoints[0] = sender;
559 return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_vm_id_t);
560}
561
562uint32_t ffa_memory_region_init(
Andrew Walbranca808b12020-05-15 17:22:28 +0100563 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
564 ffa_vm_id_t sender, ffa_vm_id_t receiver,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100565 const struct ffa_memory_region_constituent constituents[],
566 uint32_t constituent_count, uint32_t tag,
567 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
568 enum ffa_instruction_access instruction_access,
569 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
Andrew Walbranca808b12020-05-15 17:22:28 +0100570 enum ffa_memory_shareability shareability, uint32_t *fragment_length,
571 uint32_t *total_length);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100572uint32_t ffa_memory_retrieve_request_init(
573 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
574 ffa_vm_id_t sender, ffa_vm_id_t receiver, uint32_t tag,
575 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
576 enum ffa_instruction_access instruction_access,
577 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
578 enum ffa_memory_shareability shareability);
579uint32_t ffa_memory_lender_retrieve_request_init(
580 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
581 ffa_vm_id_t sender);
Andrew Walbranca808b12020-05-15 17:22:28 +0100582bool ffa_retrieved_memory_region_init(
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100583 struct ffa_memory_region *response, size_t response_max_size,
584 ffa_vm_id_t sender, ffa_memory_attributes_t attributes,
585 ffa_memory_region_flags_t flags, ffa_memory_handle_t handle,
586 ffa_vm_id_t receiver, ffa_memory_access_permissions_t permissions,
Andrew Walbranca808b12020-05-15 17:22:28 +0100587 uint32_t page_count, uint32_t total_constituent_count,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100588 const struct ffa_memory_region_constituent constituents[],
Andrew Walbranca808b12020-05-15 17:22:28 +0100589 uint32_t fragment_constituent_count, uint32_t *total_length,
590 uint32_t *fragment_length);
591uint32_t ffa_memory_fragment_init(
592 struct ffa_memory_region_constituent *fragment,
593 size_t fragment_max_size,
594 const struct ffa_memory_region_constituent constituents[],
595 uint32_t constituent_count, uint32_t *fragment_length);