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