blob: 5fef6c7c4f2996d2ec3147bf1d64fce2fc44a5d6 [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
J-Alves3829fc02021-03-18 12:49:18 +000016#define FFA_VERSION_MINOR 0x1
Daniel Boulby6e32c612021-02-17 15:09:41 +000017#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. */
J-Alves3829fc02021-03-18 12:49:18 +000034#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 Krishnamurthyea6d25f2021-09-14 15:27:06 -070080#define FFA_MEM_PERM_GET_64 0xC4000088
81#define FFA_MEM_PERM_SET_64 0xC4000089
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010082
Maksims Svecovs71b76702022-05-20 15:32:58 +010083/* Implementation-defined ABIs. */
84#define FFA_CONSOLE_LOG_32 0x8400008A
85#define FFA_CONSOLE_LOG_64 0xC400008A
86
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010087/* FF-A error codes. */
88#define FFA_NOT_SUPPORTED INT32_C(-1)
89#define FFA_INVALID_PARAMETERS INT32_C(-2)
90#define FFA_NO_MEMORY INT32_C(-3)
91#define FFA_BUSY INT32_C(-4)
92#define FFA_INTERRUPTED INT32_C(-5)
93#define FFA_DENIED INT32_C(-6)
94#define FFA_RETRY INT32_C(-7)
95#define FFA_ABORTED INT32_C(-8)
J-Alvesc8e8a222021-06-08 17:33:52 +010096#define FFA_NO_DATA INT32_C(-9)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010097
98/* clang-format on */
99
J-Alves6f72ca82021-11-01 12:34:58 +0000100/**
101 * FF-A Feature ID, to be used with interface FFA_FEATURES.
102 * As defined in the FF-A v1.1 Beta specification, table 13.10, in section
103 * 13.2.
104 */
105
Olivier Deprezb76307d2022-06-09 17:17:45 +0200106#define FFA_FEATURES_FUNC_ID_MASK (UINT32_C(1) << 31)
J-Alves6f72ca82021-11-01 12:34:58 +0000107#define FFA_FEATURES_FEATURE_ID_MASK UINT32_C(0x7F)
108
109/* Query interrupt ID of Notification Pending Interrupt. */
110#define FFA_FEATURE_NPI 0x1U
111
112/* Query interrupt ID of Schedule Receiver Interrupt. */
113#define FFA_FEATURE_SRI 0x2U
114
115/* Query interrupt ID of the Managed Exit Interrupt. */
116#define FFA_FEATURE_MEI 0x3U
117
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100118/* FF-A function specific constants. */
119#define FFA_MSG_RECV_BLOCK 0x1
120#define FFA_MSG_RECV_BLOCK_MASK 0x1
121
122#define FFA_MSG_SEND_NOTIFY 0x1
123#define FFA_MSG_SEND_NOTIFY_MASK 0x1
124
125#define FFA_MEM_RECLAIM_CLEAR 0x1
126
127#define FFA_SLEEP_INDEFINITE 0
128
Raghu Krishnamurthyea6d25f2021-09-14 15:27:06 -0700129#define FFA_MEM_PERM_RO UINT32_C(0x7)
130#define FFA_MEM_PERM_RW UINT32_C(0x5)
131#define FFA_MEM_PERM_RX UINT32_C(0x3)
132
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000133/*
Olivier Deprez013f4d62022-11-21 15:46:20 +0100134 * Defined in Table 13.34 in the FF-A v1.1 EAC0 specification.
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000135 * The Partition count flag is used by FFA_PARTITION_INFO_GET to specify
136 * if partition info descriptors should be returned or just the count.
137 */
Olivier Deprez013f4d62022-11-21 15:46:20 +0100138#define FFA_PARTITION_COUNT_FLAG UINT32_C(0x1)
139#define FFA_PARTITION_COUNT_FLAG_MASK (UINT32_C(0x1) << 0)
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000140
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100141/**
142 * For use where the FF-A specification refers explicitly to '4K pages'. Not to
143 * be confused with PAGE_SIZE, which is the translation granule Hafnium is
144 * configured to use.
145 */
146#define FFA_PAGE_SIZE 4096
147
Federico Recanatifc0295e2022-02-08 19:37:39 +0100148/** The ID of a VM. These are assigned sequentially starting with an offset. */
149typedef uint16_t ffa_vm_id_t;
150
151/**
152 * Partition message header as specified by table 6.2 from FF-A v1.1 EAC0
153 * specification.
154 */
155struct ffa_partition_rxtx_header {
156 uint32_t flags; /* MBZ */
157 uint32_t reserved;
158 /* Offset from the beginning of the buffer to the message payload. */
159 uint32_t offset;
160 /* Sender(Bits[31:16]) and Receiver(Bits[15:0]) endpoint IDs. */
161 uint32_t sender_receiver;
162 /* Size of message in buffer. */
163 uint32_t size;
164};
165
166#define FFA_RXTX_HEADER_SIZE sizeof(struct ffa_partition_rxtx_header)
167#define FFA_RXTX_SENDER_SHIFT (0x10U)
J-Alves70079932022-12-07 17:32:20 +0000168#define FFA_RXTX_ALLOCATOR_SHIFT 16
Federico Recanatifc0295e2022-02-08 19:37:39 +0100169
170static inline void ffa_rxtx_header_init(
171 ffa_vm_id_t sender, ffa_vm_id_t receiver, uint32_t size,
172 struct ffa_partition_rxtx_header *header)
173{
174 header->flags = 0;
175 header->reserved = 0;
176 header->offset = FFA_RXTX_HEADER_SIZE;
177 header->sender_receiver =
178 (uint32_t)(receiver | (sender << FFA_RXTX_SENDER_SHIFT));
179 header->size = size;
180}
181
182static inline ffa_vm_id_t ffa_rxtx_header_sender(
183 const struct ffa_partition_rxtx_header *h)
184{
185 return (ffa_vm_id_t)(h->sender_receiver >> FFA_RXTX_SENDER_SHIFT);
186}
187
188static inline ffa_vm_id_t ffa_rxtx_header_receiver(
189 const struct ffa_partition_rxtx_header *h)
190{
191 return (ffa_vm_id_t)(h->sender_receiver);
192}
193
194/* The maximum length possible for a single message. */
195#define FFA_PARTITION_MSG_PAYLOAD_MAX (HF_MAILBOX_SIZE - FFA_RXTX_HEADER_SIZE)
196
197struct ffa_partition_msg {
198 struct ffa_partition_rxtx_header header;
199 char payload[FFA_PARTITION_MSG_PAYLOAD_MAX];
200};
201
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100202/* The maximum length possible for a single message. */
203#define FFA_MSG_PAYLOAD_MAX HF_MAILBOX_SIZE
204
205enum ffa_data_access {
206 FFA_DATA_ACCESS_NOT_SPECIFIED,
207 FFA_DATA_ACCESS_RO,
208 FFA_DATA_ACCESS_RW,
209 FFA_DATA_ACCESS_RESERVED,
210};
211
212enum ffa_instruction_access {
213 FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED,
214 FFA_INSTRUCTION_ACCESS_NX,
215 FFA_INSTRUCTION_ACCESS_X,
216 FFA_INSTRUCTION_ACCESS_RESERVED,
217};
218
219enum ffa_memory_type {
220 FFA_MEMORY_NOT_SPECIFIED_MEM,
221 FFA_MEMORY_DEVICE_MEM,
222 FFA_MEMORY_NORMAL_MEM,
223};
224
225enum ffa_memory_cacheability {
226 FFA_MEMORY_CACHE_RESERVED = 0x0,
227 FFA_MEMORY_CACHE_NON_CACHEABLE = 0x1,
228 FFA_MEMORY_CACHE_RESERVED_1 = 0x2,
229 FFA_MEMORY_CACHE_WRITE_BACK = 0x3,
230 FFA_MEMORY_DEV_NGNRNE = 0x0,
231 FFA_MEMORY_DEV_NGNRE = 0x1,
232 FFA_MEMORY_DEV_NGRE = 0x2,
233 FFA_MEMORY_DEV_GRE = 0x3,
234};
235
236enum ffa_memory_shareability {
237 FFA_MEMORY_SHARE_NON_SHAREABLE,
238 FFA_MEMORY_SHARE_RESERVED,
239 FFA_MEMORY_OUTER_SHAREABLE,
240 FFA_MEMORY_INNER_SHAREABLE,
241};
242
243typedef uint8_t ffa_memory_access_permissions_t;
244
245/**
246 * This corresponds to table 44 of the FF-A 1.0 EAC specification, "Memory
247 * region attributes descriptor".
248 */
249typedef uint8_t ffa_memory_attributes_t;
250
251#define FFA_DATA_ACCESS_OFFSET (0x0U)
252#define FFA_DATA_ACCESS_MASK ((0x3U) << FFA_DATA_ACCESS_OFFSET)
253
254#define FFA_INSTRUCTION_ACCESS_OFFSET (0x2U)
255#define FFA_INSTRUCTION_ACCESS_MASK ((0x3U) << FFA_INSTRUCTION_ACCESS_OFFSET)
256
257#define FFA_MEMORY_TYPE_OFFSET (0x4U)
258#define FFA_MEMORY_TYPE_MASK ((0x3U) << FFA_MEMORY_TYPE_OFFSET)
259
260#define FFA_MEMORY_CACHEABILITY_OFFSET (0x2U)
261#define FFA_MEMORY_CACHEABILITY_MASK ((0x3U) << FFA_MEMORY_CACHEABILITY_OFFSET)
262
263#define FFA_MEMORY_SHAREABILITY_OFFSET (0x0U)
264#define FFA_MEMORY_SHAREABILITY_MASK ((0x3U) << FFA_MEMORY_SHAREABILITY_OFFSET)
265
266#define ATTR_FUNCTION_SET(name, container_type, offset, mask) \
267 static inline void ffa_set_##name##_attr(container_type *attr, \
268 const enum ffa_##name perm) \
269 { \
270 *attr = (*attr & ~(mask)) | ((perm << offset) & mask); \
271 }
272
273#define ATTR_FUNCTION_GET(name, container_type, offset, mask) \
274 static inline enum ffa_##name ffa_get_##name##_attr( \
275 container_type attr) \
276 { \
277 return (enum ffa_##name)((attr & mask) >> offset); \
278 }
279
280ATTR_FUNCTION_SET(data_access, ffa_memory_access_permissions_t,
281 FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK)
282ATTR_FUNCTION_GET(data_access, ffa_memory_access_permissions_t,
283 FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK)
284
285ATTR_FUNCTION_SET(instruction_access, ffa_memory_access_permissions_t,
286 FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK)
287ATTR_FUNCTION_GET(instruction_access, ffa_memory_access_permissions_t,
288 FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK)
289
290ATTR_FUNCTION_SET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET,
291 FFA_MEMORY_TYPE_MASK)
292ATTR_FUNCTION_GET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET,
293 FFA_MEMORY_TYPE_MASK)
294
295ATTR_FUNCTION_SET(memory_cacheability, ffa_memory_attributes_t,
296 FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK)
297ATTR_FUNCTION_GET(memory_cacheability, ffa_memory_attributes_t,
298 FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK)
299
300ATTR_FUNCTION_SET(memory_shareability, ffa_memory_attributes_t,
301 FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK)
302ATTR_FUNCTION_GET(memory_shareability, ffa_memory_attributes_t,
303 FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK)
304
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100305/**
306 * A globally-unique ID assigned by the hypervisor for a region of memory being
307 * sent between VMs.
308 */
309typedef uint64_t ffa_memory_handle_t;
310
J-Alves917d2f22020-10-30 18:39:30 +0000311#define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \
312 ((ffa_memory_handle_t)(UINT64_C(1) << 63))
313#define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR \
314 ((ffa_memory_handle_t)(UINT64_C(1) << 63))
315
316#define FFA_MEMORY_HANDLE_ALLOCATOR_SPMC (UINT64_C(0) << 63)
317#define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0))
318
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100319/**
320 * A count of VMs. This has the same range as the VM IDs but we give it a
321 * different name to make the different semantics clear.
322 */
323typedef ffa_vm_id_t ffa_vm_count_t;
324
325/** The index of a vCPU within a particular VM. */
326typedef uint16_t ffa_vcpu_index_t;
327
328/**
329 * A count of vCPUs. This has the same range as the vCPU indices but we give it
330 * a different name to make the different semantics clear.
331 */
332typedef ffa_vcpu_index_t ffa_vcpu_count_t;
333
334/** Parameter and return type of FF-A functions. */
335struct ffa_value {
336 uint64_t func;
337 uint64_t arg1;
338 uint64_t arg2;
339 uint64_t arg3;
340 uint64_t arg4;
341 uint64_t arg5;
342 uint64_t arg6;
343 uint64_t arg7;
344};
345
Olivier Depreze562e542020-06-11 17:31:54 +0200346static inline uint32_t ffa_func_id(struct ffa_value args)
347{
348 return args.func;
349}
350
J-Alves13318e32021-02-22 17:21:00 +0000351static inline int32_t ffa_error_code(struct ffa_value val)
352{
353 return (int32_t)val.arg2;
354}
355
J-Alvesd6f4e142021-03-05 13:33:59 +0000356static inline ffa_vm_id_t ffa_sender(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100357{
358 return (args.arg1 >> 16) & 0xffff;
359}
360
J-Alvesd6f4e142021-03-05 13:33:59 +0000361static inline ffa_vm_id_t ffa_receiver(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100362{
363 return args.arg1 & 0xffff;
364}
365
366static inline uint32_t ffa_msg_send_size(struct ffa_value args)
367{
368 return args.arg3;
369}
370
Federico Recanati25053ee2022-03-14 15:01:53 +0100371static inline uint32_t ffa_msg_send2_flags(struct ffa_value args)
372{
373 return args.arg2;
374}
375
Olivier Depreze562e542020-06-11 17:31:54 +0200376static inline uint32_t ffa_partition_info_get_count(struct ffa_value args)
377{
378 return args.arg2;
379}
380
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100381static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t a1, uint32_t a2)
382{
383 return (uint64_t)a1 | (uint64_t)a2 << 32;
384}
385
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100386static inline ffa_memory_handle_t ffa_mem_success_handle(struct ffa_value args)
387{
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100388 return ffa_assemble_handle(args.arg2, args.arg3);
389}
390
Andrew Walbranca808b12020-05-15 17:22:28 +0100391static inline ffa_memory_handle_t ffa_frag_handle(struct ffa_value args)
392{
393 return ffa_assemble_handle(args.arg1, args.arg2);
394}
395
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100396static inline struct ffa_value ffa_mem_success(ffa_memory_handle_t handle)
397{
398 return (struct ffa_value){.func = FFA_SUCCESS_32,
399 .arg2 = (uint32_t)handle,
400 .arg3 = (uint32_t)(handle >> 32)};
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100401}
402
403static inline ffa_vm_id_t ffa_vm_id(struct ffa_value args)
404{
405 return (args.arg1 >> 16) & 0xffff;
406}
407
408static inline ffa_vcpu_index_t ffa_vcpu_index(struct ffa_value args)
409{
410 return args.arg1 & 0xffff;
411}
412
413static inline uint64_t ffa_vm_vcpu(ffa_vm_id_t vm_id,
414 ffa_vcpu_index_t vcpu_index)
415{
416 return ((uint32_t)vm_id << 16) | vcpu_index;
417}
418
Andrew Walbranca808b12020-05-15 17:22:28 +0100419static inline ffa_vm_id_t ffa_frag_sender(struct ffa_value args)
420{
421 return (args.arg4 >> 16) & 0xffff;
422}
423
J-Alves6f72ca82021-11-01 12:34:58 +0000424static inline uint32_t ffa_feature_intid(struct ffa_value args)
425{
426 return (uint32_t)args.arg2;
427}
428
Daniel Boulbyefa381f2022-01-18 14:49:40 +0000429static inline uint32_t ffa_fwk_msg(struct ffa_value args)
430{
431 return (uint32_t)args.arg2;
432}
433
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100434/**
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100435 * Holds the UUID in a struct that is mappable directly to the SMCC calling
436 * convention, which is used for FF-A calls.
437 *
438 * Refer to table 84 of the FF-A 1.0 EAC specification as well as section 5.3
439 * of the SMCC Spec 1.2.
440 */
441struct ffa_uuid {
442 uint32_t uuid[4];
443};
444
445static inline void ffa_uuid_init(uint32_t w0, uint32_t w1, uint32_t w2,
446 uint32_t w3, struct ffa_uuid *uuid)
447{
448 uuid->uuid[0] = w0;
449 uuid->uuid[1] = w1;
450 uuid->uuid[2] = w2;
451 uuid->uuid[3] = w3;
452}
453
454static inline bool ffa_uuid_equal(const struct ffa_uuid *uuid1,
455 const struct ffa_uuid *uuid2)
456{
457 return (uuid1->uuid[0] == uuid2->uuid[0]) &&
458 (uuid1->uuid[1] == uuid2->uuid[1]) &&
459 (uuid1->uuid[2] == uuid2->uuid[2]) &&
460 (uuid1->uuid[3] == uuid2->uuid[3]);
461}
462
463static inline bool ffa_uuid_is_null(const struct ffa_uuid *uuid)
464{
465 return (uuid->uuid[0] == 0) && (uuid->uuid[1] == 0) &&
466 (uuid->uuid[2] == 0) && (uuid->uuid[3] == 0);
467}
468
469/**
470 * Flags to determine the partition properties, as required by
471 * FFA_PARTITION_INFO_GET.
472 *
Kathleen Capella402fa852022-11-09 16:16:51 -0500473 * The values of the flags are specified in table 8.25 of DEN0077A FF-A 1.0 REL
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100474 * specification, "Partition information descriptor, partition properties".
475 */
476typedef uint32_t ffa_partition_properties_t;
477
478/** Partition property: partition supports receipt of direct requests. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500479#define FFA_PARTITION_DIRECT_REQ_RECV (UINT32_C(1) << 0)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100480
481/** Partition property: partition can send direct requests. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500482#define FFA_PARTITION_DIRECT_REQ_SEND (UINT32_C(1) << 1)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100483
484/** Partition property: partition can send and receive indirect messages. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500485#define FFA_PARTITION_INDIRECT_MSG (UINT32_C(1) << 2)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100486
J-Alves09ff9d82021-11-02 11:55:20 +0000487/** Partition property: partition can receive notifications. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500488#define FFA_PARTITION_NOTIFICATION (UINT32_C(1) << 3)
489
490/** Partition property: partition runs in the AArch64 execution state. */
491#define FFA_PARTITION_AARCH64_EXEC (UINT32_C(1) << 8)
J-Alves09ff9d82021-11-02 11:55:20 +0000492
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100493/**
494 * Holds information returned for each partition by the FFA_PARTITION_INFO_GET
495 * interface.
Kathleen Capella402fa852022-11-09 16:16:51 -0500496 * This corresponds to table 13.37 "Partition information descriptor"
497 * in FF-A 1.1 EAC0 specification.
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000498 */
499struct ffa_partition_info {
500 ffa_vm_id_t vm_id;
501 ffa_vcpu_count_t vcpu_count;
502 ffa_partition_properties_t properties;
503 struct ffa_uuid uuid;
504};
505
506/**
Kathleen Capella402fa852022-11-09 16:16:51 -0500507 * Bits[31:3] of partition properties must be zero for FF-A v1.0.
508 * This corresponds to table 8.25 "Partition information descriptor"
509 * in DEN0077A FF-A 1.0 REL specification.
510 */
511#define FFA_PARTITION_v1_0_RES_MASK (~(UINT32_C(0x7)))
512
513/**
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000514 * Create a struct for the "Partition information descriptor" defined for v1.0
515 * which can be returned to v1.0 endpoints.
Kathleen Capella402fa852022-11-09 16:16:51 -0500516 * This corresponds to table 8.25 "Partition information descriptor"
517 * in DEN0077A FF-A 1.0 REL specification.
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100518 */
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000519
520struct ffa_partition_info_v1_0 {
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100521 ffa_vm_id_t vm_id;
522 ffa_vcpu_count_t vcpu_count;
523 ffa_partition_properties_t properties;
524};
525
J-Alvesdd1ad572022-01-25 17:58:26 +0000526/** Length in bytes of the name in boot information descriptor. */
527#define FFA_BOOT_INFO_NAME_LEN 16
528
J-Alves240d84c2022-04-22 12:19:34 +0100529/**
530 * The FF-A boot info descriptor, as defined in table 5.8 of section 5.4.1, of
531 * the FF-A v1.1 EAC0 specification.
532 */
J-Alvesdd1ad572022-01-25 17:58:26 +0000533struct ffa_boot_info_desc {
534 char name[FFA_BOOT_INFO_NAME_LEN];
535 uint8_t type;
536 uint8_t reserved;
537 uint16_t flags;
538 uint32_t size;
539 uint64_t content;
540};
541
542/** FF-A boot information type mask. */
543#define FFA_BOOT_INFO_TYPE_SHIFT 7
544#define FFA_BOOT_INFO_TYPE_MASK (0x1U << FFA_BOOT_INFO_TYPE_SHIFT)
545#define FFA_BOOT_INFO_TYPE_STD 0U
546#define FFA_BOOT_INFO_TYPE_IMPDEF 1U
547
548/** Standard boot info type IDs. */
549#define FFA_BOOT_INFO_TYPE_ID_MASK 0x7FU
550#define FFA_BOOT_INFO_TYPE_ID_FDT 0U
551#define FFA_BOOT_INFO_TYPE_ID_HOB 1U
552
553/** FF-A Boot Info descriptors flags. */
554#define FFA_BOOT_INFO_FLAG_MBZ_MASK 0xFFF0U
555
556/** Bits [1:0] encode the format of the name field in ffa_boot_info_desc. */
557#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT 0U
558#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK \
559 (0x3U << FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT)
560#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING 0x0U
561#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID 0x1U
562
563/** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */
564#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT 2
565#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK \
566 (0x3U << FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT)
567#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE 0x1U
568#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR 0x0U
569
570static inline uint16_t ffa_boot_info_content_format(
571 struct ffa_boot_info_desc *desc)
572{
573 return (desc->flags & FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK) >>
574 FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT;
575}
576
577static inline uint16_t ffa_boot_info_name_format(
578 struct ffa_boot_info_desc *desc)
579{
580 return (desc->flags & FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK) >>
581 FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT;
582}
583
584static inline uint8_t ffa_boot_info_type_id(struct ffa_boot_info_desc *desc)
585{
586 return desc->type & FFA_BOOT_INFO_TYPE_ID_MASK;
587}
588
589static inline uint8_t ffa_boot_info_type(struct ffa_boot_info_desc *desc)
590{
591 return (desc->type & FFA_BOOT_INFO_TYPE_MASK) >>
592 FFA_BOOT_INFO_TYPE_SHIFT;
593}
594
595/** Length in bytes of the signature in the boot descriptor. */
596#define FFA_BOOT_INFO_HEADER_SIGNATURE_LEN 4
597
J-Alves240d84c2022-04-22 12:19:34 +0100598/**
599 * The FF-A boot information header, as defined in table 5.9 of section 5.4.2,
600 * of the FF-A v1.1 EAC0 specification.
601 */
J-Alvesdd1ad572022-01-25 17:58:26 +0000602struct ffa_boot_info_header {
603 uint32_t signature;
604 uint32_t version;
605 uint32_t info_blob_size;
606 uint32_t desc_size;
607 uint32_t desc_count;
608 uint32_t desc_offset;
609 uint64_t reserved;
610 struct ffa_boot_info_desc boot_info[];
611};
612
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100613/**
J-Alves980d1992021-03-18 12:49:18 +0000614 * FF-A v1.1 specification restricts the number of notifications to a maximum
615 * of 64. Following all possible bitmaps.
616 */
617#define FFA_NOTIFICATION_MASK(ID) (UINT64_C(1) << ID)
618
619typedef uint64_t ffa_notifications_bitmap_t;
620
621#define MAX_FFA_NOTIFICATIONS 64U
622
623/**
J-Alvesc003a7a2021-03-18 13:06:53 +0000624 * Flag for notification bind and set, to specify call is about per-vCPU
625 * notifications.
626 */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200627#define FFA_NOTIFICATION_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesc003a7a2021-03-18 13:06:53 +0000628
Federico Recanatie73d2832022-04-20 11:10:52 +0200629#define FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(0)
630#define FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(32)
631
632/**
633 * Helper functions to check for buffer full notification.
634 */
635static inline bool is_ffa_hyp_buffer_full_notification(
636 ffa_notifications_bitmap_t framework)
637{
638 return (framework & FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK) != 0;
639}
640
641static inline bool is_ffa_spm_buffer_full_notification(
642 ffa_notifications_bitmap_t framework)
643{
644 return (framework & FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK) != 0;
645}
646
J-Alvesc003a7a2021-03-18 13:06:53 +0000647/**
J-Alves980d1992021-03-18 12:49:18 +0000648 * Helper function to assemble a 64-bit sized bitmap, from the 32-bit sized lo
649 * and hi.
650 * Helpful as FF-A specification defines that the notifications interfaces
651 * arguments are 32-bit registers.
652 */
653static inline ffa_notifications_bitmap_t ffa_notifications_bitmap(uint32_t lo,
654 uint32_t hi)
655{
656 return (ffa_notifications_bitmap_t)hi << 32U | lo;
657}
658
J-Alves98ff9562021-09-09 14:39:41 +0100659static inline ffa_notifications_bitmap_t ffa_notification_get_from_sp(
660 struct ffa_value val)
661{
662 return ffa_notifications_bitmap((uint32_t)val.arg2, (uint32_t)val.arg3);
663}
664
665static inline ffa_notifications_bitmap_t ffa_notification_get_from_vm(
666 struct ffa_value val)
667{
668 return ffa_notifications_bitmap((uint32_t)val.arg4, (uint32_t)val.arg5);
669}
670
Federico Recanatie73d2832022-04-20 11:10:52 +0200671static inline ffa_notifications_bitmap_t ffa_notification_get_from_framework(
672 struct ffa_value val)
673{
674 return ffa_notifications_bitmap((uint32_t)val.arg6, (uint32_t)val.arg7);
675}
676
J-Alves980d1992021-03-18 12:49:18 +0000677/**
J-Alvesaa79c012021-07-09 14:29:45 +0100678 * Flags used in calls to FFA_NOTIFICATION_GET interface.
679 */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200680#define FFA_NOTIFICATION_FLAG_BITMAP_SP (UINT32_C(1) << 0)
681#define FFA_NOTIFICATION_FLAG_BITMAP_VM (UINT32_C(1) << 1)
682#define FFA_NOTIFICATION_FLAG_BITMAP_SPM (UINT32_C(1) << 2)
683#define FFA_NOTIFICATION_FLAG_BITMAP_HYP (UINT32_C(1) << 3)
J-Alvesaa79c012021-07-09 14:29:45 +0100684
J-Alvesa3755072021-11-26 16:01:08 +0000685/* Flag to configure notification as being per vCPU. */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200686#define FFA_NOTIFICATIONS_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesa3755072021-11-26 16:01:08 +0000687
J-Alves13394022021-06-30 13:48:49 +0100688/** Flag for FFA_NOTIFICATION_SET to delay Schedule Receiver Interrupt */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200689#define FFA_NOTIFICATIONS_FLAG_DELAY_SRI (UINT32_C(1) << 1)
690
691#define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) \
692 ((((uint32_t)(id)) & UINT32_C(0xffff)) << 16)
J-Alves13394022021-06-30 13:48:49 +0100693
J-Alvesbe6e3032021-11-30 14:54:12 +0000694static inline ffa_vcpu_index_t ffa_notifications_get_vcpu(struct ffa_value args)
J-Alvesaa79c012021-07-09 14:29:45 +0100695{
J-Alvesbe6e3032021-11-30 14:54:12 +0000696 return (ffa_vcpu_index_t)(args.arg1 >> 16 & 0xffffU);
J-Alvesaa79c012021-07-09 14:29:45 +0100697}
698
699/**
J-Alvesc8e8a222021-06-08 17:33:52 +0100700 * The max number of IDs for return of FFA_NOTIFICATION_INFO_GET.
701 */
702#define FFA_NOTIFICATIONS_INFO_GET_MAX_IDS 20U
703
704/**
705 * Number of registers to use in successfull return of interface
706 * FFA_NOTIFICATION_INFO_GET.
707 */
708#define FFA_NOTIFICATIONS_INFO_GET_REGS_RET 5U
709
710#define FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING 0x1U
711
712/**
713 * Helper macros for return parameter encoding as described in section 17.7.1
714 * of the FF-A v1.1 Beta0 specification.
715 */
716#define FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT 0x7U
717#define FFA_NOTIFICATIONS_LISTS_COUNT_MASK 0x1fU
718#define FFA_NOTIFICATIONS_LIST_SHIFT(l) (2 * (l - 1) + 12)
719#define FFA_NOTIFICATIONS_LIST_SIZE_MASK 0x3U
720
721static inline uint32_t ffa_notification_info_get_lists_count(
722 struct ffa_value args)
723{
724 return (uint32_t)(args.arg2 >> FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT) &
725 FFA_NOTIFICATIONS_LISTS_COUNT_MASK;
726}
727
728static inline uint32_t ffa_notification_info_get_list_size(
729 struct ffa_value args, unsigned int list_idx)
730{
731 return ((uint32_t)args.arg2 >> FFA_NOTIFICATIONS_LIST_SHIFT(list_idx)) &
732 FFA_NOTIFICATIONS_LIST_SIZE_MASK;
733}
734
735static inline bool ffa_notification_info_get_more_pending(struct ffa_value args)
736{
737 return (args.arg2 & FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING) != 0U;
738}
739
740/**
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100741 * A set of contiguous pages which is part of a memory region. This corresponds
742 * to table 40 of the FF-A 1.0 EAC specification, "Constituent memory region
743 * descriptor".
744 */
745struct ffa_memory_region_constituent {
746 /**
747 * The base IPA of the constituent memory region, aligned to 4 kiB page
748 * size granularity.
749 */
750 uint64_t address;
751 /** The number of 4 kiB pages in the constituent memory region. */
752 uint32_t page_count;
753 /** Reserved field, must be 0. */
754 uint32_t reserved;
755};
756
757/**
758 * A set of pages comprising a memory region. This corresponds to table 39 of
759 * the FF-A 1.0 EAC specification, "Composite memory region descriptor".
760 */
761struct ffa_composite_memory_region {
762 /**
763 * The total number of 4 kiB pages included in this memory region. This
764 * must be equal to the sum of page counts specified in each
765 * `ffa_memory_region_constituent`.
766 */
767 uint32_t page_count;
768 /**
769 * The number of constituents (`ffa_memory_region_constituent`)
770 * included in this memory region range.
771 */
772 uint32_t constituent_count;
773 /** Reserved field, must be 0. */
774 uint64_t reserved_0;
775 /** An array of `constituent_count` memory region constituents. */
776 struct ffa_memory_region_constituent constituents[];
777};
778
779/** Flags to indicate properties of receivers during memory region retrieval. */
780typedef uint8_t ffa_memory_receiver_flags_t;
781
782/**
783 * This corresponds to table 41 of the FF-A 1.0 EAC specification, "Memory
784 * access permissions descriptor".
785 */
786struct ffa_memory_region_attributes {
787 /** The ID of the VM to which the memory is being given or shared. */
788 ffa_vm_id_t receiver;
789 /**
790 * The permissions with which the memory region should be mapped in the
791 * receiver's page table.
792 */
793 ffa_memory_access_permissions_t permissions;
794 /**
795 * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP
796 * for memory regions with multiple borrowers.
797 */
798 ffa_memory_receiver_flags_t flags;
799};
800
801/** Flags to control the behaviour of a memory sharing transaction. */
802typedef uint32_t ffa_memory_region_flags_t;
803
804/**
805 * Clear memory region contents after unmapping it from the sender and before
806 * mapping it for any receiver.
807 */
808#define FFA_MEMORY_REGION_FLAG_CLEAR 0x1
809
810/**
811 * Whether the hypervisor may time slice the memory sharing or retrieval
812 * operation.
813 */
814#define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2
815
816/**
817 * Whether the hypervisor should clear the memory region after the receiver
818 * relinquishes it or is aborted.
819 */
820#define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4
821
822#define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3)
823#define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3)
824#define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3)
825#define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3)
826#define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3)
827
Federico Recanati85090c42021-12-15 13:17:54 +0100828#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_VALID ((0x1U) << 9)
829#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_MASK ((0xFU) << 5)
830
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100831/**
832 * This corresponds to table 42 of the FF-A 1.0 EAC specification, "Endpoint
833 * memory access descriptor".
834 */
835struct ffa_memory_access {
836 struct ffa_memory_region_attributes receiver_permissions;
837 /**
838 * Offset in bytes from the start of the outer `ffa_memory_region` to
839 * an `ffa_composite_memory_region` struct.
840 */
841 uint32_t composite_memory_region_offset;
842 uint64_t reserved_0;
843};
844
J-Alves363f5722022-04-25 17:37:37 +0100845/** The maximum number of recipients a memory region may be sent to. */
J-Alvesba0e6172022-04-25 17:41:40 +0100846#define MAX_MEM_SHARE_RECIPIENTS UINT32_C(2)
J-Alves363f5722022-04-25 17:37:37 +0100847
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100848/**
849 * Information about a set of pages which are being shared. This corresponds to
850 * table 45 of the FF-A 1.0 EAC specification, "Lend, donate or share memory
851 * transaction descriptor". Note that it is also used for retrieve requests and
852 * responses.
853 */
854struct ffa_memory_region {
855 /**
856 * The ID of the VM which originally sent the memory region, i.e. the
857 * owner.
858 */
859 ffa_vm_id_t sender;
860 ffa_memory_attributes_t attributes;
861 /** Reserved field, must be 0. */
862 uint8_t reserved_0;
863 /** Flags to control behaviour of the transaction. */
864 ffa_memory_region_flags_t flags;
865 ffa_memory_handle_t handle;
866 /**
867 * An implementation defined value associated with the receiver and the
868 * memory region.
869 */
870 uint64_t tag;
871 /** Reserved field, must be 0. */
872 uint32_t reserved_1;
873 /**
874 * The number of `ffa_memory_access` entries included in this
875 * transaction.
876 */
877 uint32_t receiver_count;
878 /**
Federico Recanati3ddf28e2021-12-20 09:40:26 +0100879 * An array of `receiver_count` endpoint memory access descriptors.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100880 * Each one specifies a memory region offset, an endpoint and the
881 * attributes with which this memory region should be mapped in that
882 * endpoint's page table.
883 */
884 struct ffa_memory_access receivers[];
885};
886
887/**
888 * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table
889 * 150 of the FF-A 1.0 EAC specification, "Descriptor to relinquish a memory
890 * region".
891 */
892struct ffa_mem_relinquish {
893 ffa_memory_handle_t handle;
894 ffa_memory_region_flags_t flags;
895 uint32_t endpoint_count;
896 ffa_vm_id_t endpoints[];
897};
898
899/**
900 * Gets the `ffa_composite_memory_region` for the given receiver from an
901 * `ffa_memory_region`, or NULL if it is not valid.
902 */
903static inline struct ffa_composite_memory_region *
904ffa_memory_region_get_composite(struct ffa_memory_region *memory_region,
905 uint32_t receiver_index)
906{
907 uint32_t offset = memory_region->receivers[receiver_index]
908 .composite_memory_region_offset;
909
910 if (offset == 0) {
911 return NULL;
912 }
913
914 return (struct ffa_composite_memory_region *)((uint8_t *)memory_region +
915 offset);
916}
917
918static inline uint32_t ffa_mem_relinquish_init(
919 struct ffa_mem_relinquish *relinquish_request,
920 ffa_memory_handle_t handle, ffa_memory_region_flags_t flags,
921 ffa_vm_id_t sender)
922{
923 relinquish_request->handle = handle;
924 relinquish_request->flags = flags;
925 relinquish_request->endpoint_count = 1;
926 relinquish_request->endpoints[0] = sender;
927 return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_vm_id_t);
928}
929
Federico Recanati392be392022-02-08 20:53:03 +0100930/**
931 * Endpoint RX/TX descriptor, as defined by Table 13.27 in FF-A v1.1 EAC0.
932 * It's used by the Hypervisor to describe the RX/TX buffers mapped by a VM
933 * to the SPMC, in order to allow indirect messaging.
934 */
935struct ffa_endpoint_rx_tx_descriptor {
936 ffa_vm_id_t endpoint_id;
937 uint16_t reserved;
938
939 /*
940 * 8-byte aligned offset from the base address of this descriptor to the
941 * `ffa_composite_memory_region` describing the RX buffer.
942 */
943 uint32_t rx_offset;
944
945 /*
946 * 8-byte aligned offset from the base address of this descriptor to the
947 * `ffa_composite_memory_region` describing the TX buffer.
948 */
949 uint32_t tx_offset;
950
951 /* Pad to align on 16-byte boundary. */
952 uint32_t pad;
953};
954
955static inline struct ffa_composite_memory_region *
956ffa_enpoint_get_rx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
957{
958 return (struct ffa_composite_memory_region *)((uintptr_t)desc +
959 desc->rx_offset);
960}
961
962static inline struct ffa_composite_memory_region *
963ffa_enpoint_get_tx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
964{
965 return (struct ffa_composite_memory_region *)((uintptr_t)desc +
966 desc->tx_offset);
967}
968
J-Alvesb44bb7d2022-04-25 15:43:46 +0100969void ffa_memory_access_init_permissions(
970 struct ffa_memory_access *receiver, ffa_vm_id_t receiver_id,
971 enum ffa_data_access data_access,
972 enum ffa_instruction_access instruction_access,
973 ffa_memory_receiver_flags_t flags);
J-Alves45085432022-04-22 16:19:20 +0100974uint32_t ffa_memory_region_init_single_receiver(
Andrew Walbranca808b12020-05-15 17:22:28 +0100975 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
976 ffa_vm_id_t sender, ffa_vm_id_t receiver,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100977 const struct ffa_memory_region_constituent constituents[],
978 uint32_t constituent_count, uint32_t tag,
979 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
980 enum ffa_instruction_access instruction_access,
981 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
Andrew Walbranca808b12020-05-15 17:22:28 +0100982 enum ffa_memory_shareability shareability, uint32_t *fragment_length,
983 uint32_t *total_length);
J-Alvesf4eecf72022-07-20 16:05:34 +0100984uint32_t ffa_memory_region_init(
985 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
986 ffa_vm_id_t sender, struct ffa_memory_access receivers[],
987 uint32_t receiver_count,
988 const struct ffa_memory_region_constituent constituents[],
989 uint32_t constituent_count, uint32_t tag,
990 ffa_memory_region_flags_t flags, enum ffa_memory_type type,
991 enum ffa_memory_cacheability cacheability,
992 enum ffa_memory_shareability shareability, uint32_t *fragment_length,
993 uint32_t *total_length);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100994uint32_t ffa_memory_retrieve_request_init(
995 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves9b24ed82022-08-04 13:12:45 +0100996 ffa_vm_id_t sender, struct ffa_memory_access receivers[],
997 uint32_t receiver_count, uint32_t tag, ffa_memory_region_flags_t flags,
998 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
999 enum ffa_memory_shareability shareability);
1000uint32_t ffa_memory_retrieve_request_init_single_receiver(
1001 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001002 ffa_vm_id_t sender, ffa_vm_id_t receiver, uint32_t tag,
1003 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
1004 enum ffa_instruction_access instruction_access,
1005 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
1006 enum ffa_memory_shareability shareability);
1007uint32_t ffa_memory_lender_retrieve_request_init(
1008 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
1009 ffa_vm_id_t sender);
Andrew Walbranca808b12020-05-15 17:22:28 +01001010bool ffa_retrieved_memory_region_init(
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001011 struct ffa_memory_region *response, size_t response_max_size,
1012 ffa_vm_id_t sender, ffa_memory_attributes_t attributes,
1013 ffa_memory_region_flags_t flags, ffa_memory_handle_t handle,
1014 ffa_vm_id_t receiver, ffa_memory_access_permissions_t permissions,
Andrew Walbranca808b12020-05-15 17:22:28 +01001015 uint32_t page_count, uint32_t total_constituent_count,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001016 const struct ffa_memory_region_constituent constituents[],
Andrew Walbranca808b12020-05-15 17:22:28 +01001017 uint32_t fragment_constituent_count, uint32_t *total_length,
1018 uint32_t *fragment_length);
1019uint32_t ffa_memory_fragment_init(
1020 struct ffa_memory_region_constituent *fragment,
1021 size_t fragment_max_size,
1022 const struct ffa_memory_region_constituent constituents[],
1023 uint32_t constituent_count, uint32_t *fragment_length);
Federico Recanati392be392022-02-08 20:53:03 +01001024void ffa_endpoint_rx_tx_descriptor_init(
1025 struct ffa_endpoint_rx_tx_descriptor *desc, ffa_vm_id_t endpoint_id,
1026 uint64_t rx_address, uint64_t tx_address);