blob: 9c4dfbce9339adc73704c6e4cbb7eef2ac0ea519 [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;
Raghu Krishnamurthy567068e2022-12-26 07:46:38 -0800344
345 struct {
346 uint64_t arg8;
347 uint64_t arg9;
348 uint64_t arg10;
349 uint64_t arg11;
350 uint64_t arg12;
351 uint64_t arg13;
352 uint64_t arg14;
353 uint64_t arg15;
354 uint64_t arg16;
355 uint64_t arg17;
356 bool valid;
357 } extended_val;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100358};
359
Olivier Depreze562e542020-06-11 17:31:54 +0200360static inline uint32_t ffa_func_id(struct ffa_value args)
361{
362 return args.func;
363}
364
J-Alves13318e32021-02-22 17:21:00 +0000365static inline int32_t ffa_error_code(struct ffa_value val)
366{
367 return (int32_t)val.arg2;
368}
369
J-Alvesd6f4e142021-03-05 13:33:59 +0000370static inline ffa_vm_id_t ffa_sender(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100371{
372 return (args.arg1 >> 16) & 0xffff;
373}
374
J-Alvesd6f4e142021-03-05 13:33:59 +0000375static inline ffa_vm_id_t ffa_receiver(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100376{
377 return args.arg1 & 0xffff;
378}
379
380static inline uint32_t ffa_msg_send_size(struct ffa_value args)
381{
382 return args.arg3;
383}
384
Federico Recanati25053ee2022-03-14 15:01:53 +0100385static inline uint32_t ffa_msg_send2_flags(struct ffa_value args)
386{
387 return args.arg2;
388}
389
Olivier Depreze562e542020-06-11 17:31:54 +0200390static inline uint32_t ffa_partition_info_get_count(struct ffa_value args)
391{
392 return args.arg2;
393}
394
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100395static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t a1, uint32_t a2)
396{
397 return (uint64_t)a1 | (uint64_t)a2 << 32;
398}
399
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100400static inline ffa_memory_handle_t ffa_mem_success_handle(struct ffa_value args)
401{
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100402 return ffa_assemble_handle(args.arg2, args.arg3);
403}
404
Andrew Walbranca808b12020-05-15 17:22:28 +0100405static inline ffa_memory_handle_t ffa_frag_handle(struct ffa_value args)
406{
407 return ffa_assemble_handle(args.arg1, args.arg2);
408}
409
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100410static inline struct ffa_value ffa_mem_success(ffa_memory_handle_t handle)
411{
412 return (struct ffa_value){.func = FFA_SUCCESS_32,
413 .arg2 = (uint32_t)handle,
414 .arg3 = (uint32_t)(handle >> 32)};
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100415}
416
417static inline ffa_vm_id_t ffa_vm_id(struct ffa_value args)
418{
419 return (args.arg1 >> 16) & 0xffff;
420}
421
422static inline ffa_vcpu_index_t ffa_vcpu_index(struct ffa_value args)
423{
424 return args.arg1 & 0xffff;
425}
426
427static inline uint64_t ffa_vm_vcpu(ffa_vm_id_t vm_id,
428 ffa_vcpu_index_t vcpu_index)
429{
430 return ((uint32_t)vm_id << 16) | vcpu_index;
431}
432
Andrew Walbranca808b12020-05-15 17:22:28 +0100433static inline ffa_vm_id_t ffa_frag_sender(struct ffa_value args)
434{
435 return (args.arg4 >> 16) & 0xffff;
436}
437
J-Alves6f72ca82021-11-01 12:34:58 +0000438static inline uint32_t ffa_feature_intid(struct ffa_value args)
439{
440 return (uint32_t)args.arg2;
441}
442
Daniel Boulbyefa381f2022-01-18 14:49:40 +0000443static inline uint32_t ffa_fwk_msg(struct ffa_value args)
444{
445 return (uint32_t)args.arg2;
446}
447
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100448/**
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100449 * Holds the UUID in a struct that is mappable directly to the SMCC calling
450 * convention, which is used for FF-A calls.
451 *
452 * Refer to table 84 of the FF-A 1.0 EAC specification as well as section 5.3
453 * of the SMCC Spec 1.2.
454 */
455struct ffa_uuid {
456 uint32_t uuid[4];
457};
458
459static inline void ffa_uuid_init(uint32_t w0, uint32_t w1, uint32_t w2,
460 uint32_t w3, struct ffa_uuid *uuid)
461{
462 uuid->uuid[0] = w0;
463 uuid->uuid[1] = w1;
464 uuid->uuid[2] = w2;
465 uuid->uuid[3] = w3;
466}
467
468static inline bool ffa_uuid_equal(const struct ffa_uuid *uuid1,
469 const struct ffa_uuid *uuid2)
470{
471 return (uuid1->uuid[0] == uuid2->uuid[0]) &&
472 (uuid1->uuid[1] == uuid2->uuid[1]) &&
473 (uuid1->uuid[2] == uuid2->uuid[2]) &&
474 (uuid1->uuid[3] == uuid2->uuid[3]);
475}
476
477static inline bool ffa_uuid_is_null(const struct ffa_uuid *uuid)
478{
479 return (uuid->uuid[0] == 0) && (uuid->uuid[1] == 0) &&
480 (uuid->uuid[2] == 0) && (uuid->uuid[3] == 0);
481}
482
483/**
484 * Flags to determine the partition properties, as required by
485 * FFA_PARTITION_INFO_GET.
486 *
Kathleen Capella402fa852022-11-09 16:16:51 -0500487 * 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 +0100488 * specification, "Partition information descriptor, partition properties".
489 */
490typedef uint32_t ffa_partition_properties_t;
491
492/** Partition property: partition supports receipt of direct requests. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500493#define FFA_PARTITION_DIRECT_REQ_RECV (UINT32_C(1) << 0)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100494
495/** Partition property: partition can send direct requests. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500496#define FFA_PARTITION_DIRECT_REQ_SEND (UINT32_C(1) << 1)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100497
498/** Partition property: partition can send and receive indirect messages. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500499#define FFA_PARTITION_INDIRECT_MSG (UINT32_C(1) << 2)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100500
J-Alves09ff9d82021-11-02 11:55:20 +0000501/** Partition property: partition can receive notifications. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500502#define FFA_PARTITION_NOTIFICATION (UINT32_C(1) << 3)
503
504/** Partition property: partition runs in the AArch64 execution state. */
505#define FFA_PARTITION_AARCH64_EXEC (UINT32_C(1) << 8)
J-Alves09ff9d82021-11-02 11:55:20 +0000506
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100507/**
508 * Holds information returned for each partition by the FFA_PARTITION_INFO_GET
509 * interface.
Kathleen Capella402fa852022-11-09 16:16:51 -0500510 * This corresponds to table 13.37 "Partition information descriptor"
511 * in FF-A 1.1 EAC0 specification.
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000512 */
513struct ffa_partition_info {
514 ffa_vm_id_t vm_id;
515 ffa_vcpu_count_t vcpu_count;
516 ffa_partition_properties_t properties;
517 struct ffa_uuid uuid;
518};
519
520/**
Kathleen Capella402fa852022-11-09 16:16:51 -0500521 * Bits[31:3] of partition properties must be zero for FF-A v1.0.
522 * This corresponds to table 8.25 "Partition information descriptor"
523 * in DEN0077A FF-A 1.0 REL specification.
524 */
525#define FFA_PARTITION_v1_0_RES_MASK (~(UINT32_C(0x7)))
526
527/**
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000528 * Create a struct for the "Partition information descriptor" defined for v1.0
529 * which can be returned to v1.0 endpoints.
Kathleen Capella402fa852022-11-09 16:16:51 -0500530 * This corresponds to table 8.25 "Partition information descriptor"
531 * in DEN0077A FF-A 1.0 REL specification.
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100532 */
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000533
534struct ffa_partition_info_v1_0 {
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100535 ffa_vm_id_t vm_id;
536 ffa_vcpu_count_t vcpu_count;
537 ffa_partition_properties_t properties;
538};
539
J-Alvesdd1ad572022-01-25 17:58:26 +0000540/** Length in bytes of the name in boot information descriptor. */
541#define FFA_BOOT_INFO_NAME_LEN 16
542
J-Alves240d84c2022-04-22 12:19:34 +0100543/**
544 * The FF-A boot info descriptor, as defined in table 5.8 of section 5.4.1, of
545 * the FF-A v1.1 EAC0 specification.
546 */
J-Alvesdd1ad572022-01-25 17:58:26 +0000547struct ffa_boot_info_desc {
548 char name[FFA_BOOT_INFO_NAME_LEN];
549 uint8_t type;
550 uint8_t reserved;
551 uint16_t flags;
552 uint32_t size;
553 uint64_t content;
554};
555
556/** FF-A boot information type mask. */
557#define FFA_BOOT_INFO_TYPE_SHIFT 7
558#define FFA_BOOT_INFO_TYPE_MASK (0x1U << FFA_BOOT_INFO_TYPE_SHIFT)
559#define FFA_BOOT_INFO_TYPE_STD 0U
560#define FFA_BOOT_INFO_TYPE_IMPDEF 1U
561
562/** Standard boot info type IDs. */
563#define FFA_BOOT_INFO_TYPE_ID_MASK 0x7FU
564#define FFA_BOOT_INFO_TYPE_ID_FDT 0U
565#define FFA_BOOT_INFO_TYPE_ID_HOB 1U
566
567/** FF-A Boot Info descriptors flags. */
568#define FFA_BOOT_INFO_FLAG_MBZ_MASK 0xFFF0U
569
570/** Bits [1:0] encode the format of the name field in ffa_boot_info_desc. */
571#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT 0U
572#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK \
573 (0x3U << FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT)
574#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING 0x0U
575#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID 0x1U
576
577/** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */
578#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT 2
579#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK \
580 (0x3U << FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT)
581#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE 0x1U
582#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR 0x0U
583
584static inline uint16_t ffa_boot_info_content_format(
585 struct ffa_boot_info_desc *desc)
586{
587 return (desc->flags & FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK) >>
588 FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT;
589}
590
591static inline uint16_t ffa_boot_info_name_format(
592 struct ffa_boot_info_desc *desc)
593{
594 return (desc->flags & FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK) >>
595 FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT;
596}
597
598static inline uint8_t ffa_boot_info_type_id(struct ffa_boot_info_desc *desc)
599{
600 return desc->type & FFA_BOOT_INFO_TYPE_ID_MASK;
601}
602
603static inline uint8_t ffa_boot_info_type(struct ffa_boot_info_desc *desc)
604{
605 return (desc->type & FFA_BOOT_INFO_TYPE_MASK) >>
606 FFA_BOOT_INFO_TYPE_SHIFT;
607}
608
609/** Length in bytes of the signature in the boot descriptor. */
610#define FFA_BOOT_INFO_HEADER_SIGNATURE_LEN 4
611
J-Alves240d84c2022-04-22 12:19:34 +0100612/**
613 * The FF-A boot information header, as defined in table 5.9 of section 5.4.2,
614 * of the FF-A v1.1 EAC0 specification.
615 */
J-Alvesdd1ad572022-01-25 17:58:26 +0000616struct ffa_boot_info_header {
617 uint32_t signature;
618 uint32_t version;
619 uint32_t info_blob_size;
620 uint32_t desc_size;
621 uint32_t desc_count;
622 uint32_t desc_offset;
623 uint64_t reserved;
624 struct ffa_boot_info_desc boot_info[];
625};
626
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100627/**
J-Alves980d1992021-03-18 12:49:18 +0000628 * FF-A v1.1 specification restricts the number of notifications to a maximum
629 * of 64. Following all possible bitmaps.
630 */
631#define FFA_NOTIFICATION_MASK(ID) (UINT64_C(1) << ID)
632
633typedef uint64_t ffa_notifications_bitmap_t;
634
635#define MAX_FFA_NOTIFICATIONS 64U
636
637/**
J-Alvesc003a7a2021-03-18 13:06:53 +0000638 * Flag for notification bind and set, to specify call is about per-vCPU
639 * notifications.
640 */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200641#define FFA_NOTIFICATION_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesc003a7a2021-03-18 13:06:53 +0000642
Federico Recanatie73d2832022-04-20 11:10:52 +0200643#define FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(0)
644#define FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(32)
645
646/**
647 * Helper functions to check for buffer full notification.
648 */
649static inline bool is_ffa_hyp_buffer_full_notification(
650 ffa_notifications_bitmap_t framework)
651{
652 return (framework & FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK) != 0;
653}
654
655static inline bool is_ffa_spm_buffer_full_notification(
656 ffa_notifications_bitmap_t framework)
657{
658 return (framework & FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK) != 0;
659}
660
J-Alvesc003a7a2021-03-18 13:06:53 +0000661/**
J-Alves980d1992021-03-18 12:49:18 +0000662 * Helper function to assemble a 64-bit sized bitmap, from the 32-bit sized lo
663 * and hi.
664 * Helpful as FF-A specification defines that the notifications interfaces
665 * arguments are 32-bit registers.
666 */
667static inline ffa_notifications_bitmap_t ffa_notifications_bitmap(uint32_t lo,
668 uint32_t hi)
669{
670 return (ffa_notifications_bitmap_t)hi << 32U | lo;
671}
672
J-Alves98ff9562021-09-09 14:39:41 +0100673static inline ffa_notifications_bitmap_t ffa_notification_get_from_sp(
674 struct ffa_value val)
675{
676 return ffa_notifications_bitmap((uint32_t)val.arg2, (uint32_t)val.arg3);
677}
678
679static inline ffa_notifications_bitmap_t ffa_notification_get_from_vm(
680 struct ffa_value val)
681{
682 return ffa_notifications_bitmap((uint32_t)val.arg4, (uint32_t)val.arg5);
683}
684
Federico Recanatie73d2832022-04-20 11:10:52 +0200685static inline ffa_notifications_bitmap_t ffa_notification_get_from_framework(
686 struct ffa_value val)
687{
688 return ffa_notifications_bitmap((uint32_t)val.arg6, (uint32_t)val.arg7);
689}
690
J-Alves980d1992021-03-18 12:49:18 +0000691/**
J-Alvesaa79c012021-07-09 14:29:45 +0100692 * Flags used in calls to FFA_NOTIFICATION_GET interface.
693 */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200694#define FFA_NOTIFICATION_FLAG_BITMAP_SP (UINT32_C(1) << 0)
695#define FFA_NOTIFICATION_FLAG_BITMAP_VM (UINT32_C(1) << 1)
696#define FFA_NOTIFICATION_FLAG_BITMAP_SPM (UINT32_C(1) << 2)
697#define FFA_NOTIFICATION_FLAG_BITMAP_HYP (UINT32_C(1) << 3)
J-Alvesaa79c012021-07-09 14:29:45 +0100698
J-Alvesa3755072021-11-26 16:01:08 +0000699/* Flag to configure notification as being per vCPU. */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200700#define FFA_NOTIFICATIONS_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesa3755072021-11-26 16:01:08 +0000701
J-Alves13394022021-06-30 13:48:49 +0100702/** Flag for FFA_NOTIFICATION_SET to delay Schedule Receiver Interrupt */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200703#define FFA_NOTIFICATIONS_FLAG_DELAY_SRI (UINT32_C(1) << 1)
704
705#define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) \
706 ((((uint32_t)(id)) & UINT32_C(0xffff)) << 16)
J-Alves13394022021-06-30 13:48:49 +0100707
J-Alvesbe6e3032021-11-30 14:54:12 +0000708static inline ffa_vcpu_index_t ffa_notifications_get_vcpu(struct ffa_value args)
J-Alvesaa79c012021-07-09 14:29:45 +0100709{
J-Alvesbe6e3032021-11-30 14:54:12 +0000710 return (ffa_vcpu_index_t)(args.arg1 >> 16 & 0xffffU);
J-Alvesaa79c012021-07-09 14:29:45 +0100711}
712
713/**
J-Alvesc8e8a222021-06-08 17:33:52 +0100714 * The max number of IDs for return of FFA_NOTIFICATION_INFO_GET.
715 */
716#define FFA_NOTIFICATIONS_INFO_GET_MAX_IDS 20U
717
718/**
719 * Number of registers to use in successfull return of interface
720 * FFA_NOTIFICATION_INFO_GET.
721 */
722#define FFA_NOTIFICATIONS_INFO_GET_REGS_RET 5U
723
724#define FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING 0x1U
725
726/**
727 * Helper macros for return parameter encoding as described in section 17.7.1
728 * of the FF-A v1.1 Beta0 specification.
729 */
730#define FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT 0x7U
731#define FFA_NOTIFICATIONS_LISTS_COUNT_MASK 0x1fU
732#define FFA_NOTIFICATIONS_LIST_SHIFT(l) (2 * (l - 1) + 12)
733#define FFA_NOTIFICATIONS_LIST_SIZE_MASK 0x3U
734
735static inline uint32_t ffa_notification_info_get_lists_count(
736 struct ffa_value args)
737{
738 return (uint32_t)(args.arg2 >> FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT) &
739 FFA_NOTIFICATIONS_LISTS_COUNT_MASK;
740}
741
742static inline uint32_t ffa_notification_info_get_list_size(
743 struct ffa_value args, unsigned int list_idx)
744{
745 return ((uint32_t)args.arg2 >> FFA_NOTIFICATIONS_LIST_SHIFT(list_idx)) &
746 FFA_NOTIFICATIONS_LIST_SIZE_MASK;
747}
748
749static inline bool ffa_notification_info_get_more_pending(struct ffa_value args)
750{
751 return (args.arg2 & FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING) != 0U;
752}
753
754/**
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100755 * A set of contiguous pages which is part of a memory region. This corresponds
756 * to table 40 of the FF-A 1.0 EAC specification, "Constituent memory region
757 * descriptor".
758 */
759struct ffa_memory_region_constituent {
760 /**
761 * The base IPA of the constituent memory region, aligned to 4 kiB page
762 * size granularity.
763 */
764 uint64_t address;
765 /** The number of 4 kiB pages in the constituent memory region. */
766 uint32_t page_count;
767 /** Reserved field, must be 0. */
768 uint32_t reserved;
769};
770
771/**
772 * A set of pages comprising a memory region. This corresponds to table 39 of
773 * the FF-A 1.0 EAC specification, "Composite memory region descriptor".
774 */
775struct ffa_composite_memory_region {
776 /**
777 * The total number of 4 kiB pages included in this memory region. This
778 * must be equal to the sum of page counts specified in each
779 * `ffa_memory_region_constituent`.
780 */
781 uint32_t page_count;
782 /**
783 * The number of constituents (`ffa_memory_region_constituent`)
784 * included in this memory region range.
785 */
786 uint32_t constituent_count;
787 /** Reserved field, must be 0. */
788 uint64_t reserved_0;
789 /** An array of `constituent_count` memory region constituents. */
790 struct ffa_memory_region_constituent constituents[];
791};
792
793/** Flags to indicate properties of receivers during memory region retrieval. */
794typedef uint8_t ffa_memory_receiver_flags_t;
795
796/**
797 * This corresponds to table 41 of the FF-A 1.0 EAC specification, "Memory
798 * access permissions descriptor".
799 */
800struct ffa_memory_region_attributes {
801 /** The ID of the VM to which the memory is being given or shared. */
802 ffa_vm_id_t receiver;
803 /**
804 * The permissions with which the memory region should be mapped in the
805 * receiver's page table.
806 */
807 ffa_memory_access_permissions_t permissions;
808 /**
809 * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP
810 * for memory regions with multiple borrowers.
811 */
812 ffa_memory_receiver_flags_t flags;
813};
814
815/** Flags to control the behaviour of a memory sharing transaction. */
816typedef uint32_t ffa_memory_region_flags_t;
817
818/**
819 * Clear memory region contents after unmapping it from the sender and before
820 * mapping it for any receiver.
821 */
822#define FFA_MEMORY_REGION_FLAG_CLEAR 0x1
823
824/**
825 * Whether the hypervisor may time slice the memory sharing or retrieval
826 * operation.
827 */
828#define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2
829
830/**
831 * Whether the hypervisor should clear the memory region after the receiver
832 * relinquishes it or is aborted.
833 */
834#define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4
835
836#define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3)
837#define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3)
838#define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3)
839#define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3)
840#define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3)
841
Federico Recanati85090c42021-12-15 13:17:54 +0100842#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_VALID ((0x1U) << 9)
843#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_MASK ((0xFU) << 5)
844
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100845/**
846 * This corresponds to table 42 of the FF-A 1.0 EAC specification, "Endpoint
847 * memory access descriptor".
848 */
849struct ffa_memory_access {
850 struct ffa_memory_region_attributes receiver_permissions;
851 /**
852 * Offset in bytes from the start of the outer `ffa_memory_region` to
853 * an `ffa_composite_memory_region` struct.
854 */
855 uint32_t composite_memory_region_offset;
856 uint64_t reserved_0;
857};
858
J-Alves363f5722022-04-25 17:37:37 +0100859/** The maximum number of recipients a memory region may be sent to. */
J-Alvesba0e6172022-04-25 17:41:40 +0100860#define MAX_MEM_SHARE_RECIPIENTS UINT32_C(2)
J-Alves363f5722022-04-25 17:37:37 +0100861
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100862/**
863 * Information about a set of pages which are being shared. This corresponds to
864 * table 45 of the FF-A 1.0 EAC specification, "Lend, donate or share memory
865 * transaction descriptor". Note that it is also used for retrieve requests and
866 * responses.
867 */
868struct ffa_memory_region {
869 /**
870 * The ID of the VM which originally sent the memory region, i.e. the
871 * owner.
872 */
873 ffa_vm_id_t sender;
874 ffa_memory_attributes_t attributes;
875 /** Reserved field, must be 0. */
876 uint8_t reserved_0;
877 /** Flags to control behaviour of the transaction. */
878 ffa_memory_region_flags_t flags;
879 ffa_memory_handle_t handle;
880 /**
881 * An implementation defined value associated with the receiver and the
882 * memory region.
883 */
884 uint64_t tag;
885 /** Reserved field, must be 0. */
886 uint32_t reserved_1;
887 /**
888 * The number of `ffa_memory_access` entries included in this
889 * transaction.
890 */
891 uint32_t receiver_count;
892 /**
Federico Recanati3ddf28e2021-12-20 09:40:26 +0100893 * An array of `receiver_count` endpoint memory access descriptors.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100894 * Each one specifies a memory region offset, an endpoint and the
895 * attributes with which this memory region should be mapped in that
896 * endpoint's page table.
897 */
898 struct ffa_memory_access receivers[];
899};
900
901/**
902 * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table
903 * 150 of the FF-A 1.0 EAC specification, "Descriptor to relinquish a memory
904 * region".
905 */
906struct ffa_mem_relinquish {
907 ffa_memory_handle_t handle;
908 ffa_memory_region_flags_t flags;
909 uint32_t endpoint_count;
910 ffa_vm_id_t endpoints[];
911};
912
913/**
914 * Gets the `ffa_composite_memory_region` for the given receiver from an
915 * `ffa_memory_region`, or NULL if it is not valid.
916 */
917static inline struct ffa_composite_memory_region *
918ffa_memory_region_get_composite(struct ffa_memory_region *memory_region,
919 uint32_t receiver_index)
920{
921 uint32_t offset = memory_region->receivers[receiver_index]
922 .composite_memory_region_offset;
923
924 if (offset == 0) {
925 return NULL;
926 }
927
928 return (struct ffa_composite_memory_region *)((uint8_t *)memory_region +
929 offset);
930}
931
932static inline uint32_t ffa_mem_relinquish_init(
933 struct ffa_mem_relinquish *relinquish_request,
934 ffa_memory_handle_t handle, ffa_memory_region_flags_t flags,
935 ffa_vm_id_t sender)
936{
937 relinquish_request->handle = handle;
938 relinquish_request->flags = flags;
939 relinquish_request->endpoint_count = 1;
940 relinquish_request->endpoints[0] = sender;
941 return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_vm_id_t);
942}
943
Federico Recanati392be392022-02-08 20:53:03 +0100944/**
945 * Endpoint RX/TX descriptor, as defined by Table 13.27 in FF-A v1.1 EAC0.
946 * It's used by the Hypervisor to describe the RX/TX buffers mapped by a VM
947 * to the SPMC, in order to allow indirect messaging.
948 */
949struct ffa_endpoint_rx_tx_descriptor {
950 ffa_vm_id_t endpoint_id;
951 uint16_t reserved;
952
953 /*
954 * 8-byte aligned offset from the base address of this descriptor to the
955 * `ffa_composite_memory_region` describing the RX buffer.
956 */
957 uint32_t rx_offset;
958
959 /*
960 * 8-byte aligned offset from the base address of this descriptor to the
961 * `ffa_composite_memory_region` describing the TX buffer.
962 */
963 uint32_t tx_offset;
964
965 /* Pad to align on 16-byte boundary. */
966 uint32_t pad;
967};
968
969static inline struct ffa_composite_memory_region *
970ffa_enpoint_get_rx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
971{
972 return (struct ffa_composite_memory_region *)((uintptr_t)desc +
973 desc->rx_offset);
974}
975
976static inline struct ffa_composite_memory_region *
977ffa_enpoint_get_tx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
978{
979 return (struct ffa_composite_memory_region *)((uintptr_t)desc +
980 desc->tx_offset);
981}
982
J-Alvesb44bb7d2022-04-25 15:43:46 +0100983void ffa_memory_access_init_permissions(
984 struct ffa_memory_access *receiver, ffa_vm_id_t receiver_id,
985 enum ffa_data_access data_access,
986 enum ffa_instruction_access instruction_access,
987 ffa_memory_receiver_flags_t flags);
J-Alves45085432022-04-22 16:19:20 +0100988uint32_t ffa_memory_region_init_single_receiver(
Andrew Walbranca808b12020-05-15 17:22:28 +0100989 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
990 ffa_vm_id_t sender, ffa_vm_id_t receiver,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100991 const struct ffa_memory_region_constituent constituents[],
992 uint32_t constituent_count, uint32_t tag,
993 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
994 enum ffa_instruction_access instruction_access,
995 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
Andrew Walbranca808b12020-05-15 17:22:28 +0100996 enum ffa_memory_shareability shareability, uint32_t *fragment_length,
997 uint32_t *total_length);
J-Alvesf4eecf72022-07-20 16:05:34 +0100998uint32_t ffa_memory_region_init(
999 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
1000 ffa_vm_id_t sender, struct ffa_memory_access receivers[],
1001 uint32_t receiver_count,
1002 const struct ffa_memory_region_constituent constituents[],
1003 uint32_t constituent_count, uint32_t tag,
1004 ffa_memory_region_flags_t flags, enum ffa_memory_type type,
1005 enum ffa_memory_cacheability cacheability,
1006 enum ffa_memory_shareability shareability, uint32_t *fragment_length,
1007 uint32_t *total_length);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001008uint32_t ffa_memory_retrieve_request_init(
1009 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves9b24ed82022-08-04 13:12:45 +01001010 ffa_vm_id_t sender, struct ffa_memory_access receivers[],
1011 uint32_t receiver_count, uint32_t tag, ffa_memory_region_flags_t flags,
1012 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
1013 enum ffa_memory_shareability shareability);
1014uint32_t ffa_memory_retrieve_request_init_single_receiver(
1015 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001016 ffa_vm_id_t sender, ffa_vm_id_t receiver, uint32_t tag,
1017 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
1018 enum ffa_instruction_access instruction_access,
1019 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
1020 enum ffa_memory_shareability shareability);
1021uint32_t ffa_memory_lender_retrieve_request_init(
1022 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
1023 ffa_vm_id_t sender);
Andrew Walbranca808b12020-05-15 17:22:28 +01001024bool ffa_retrieved_memory_region_init(
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001025 struct ffa_memory_region *response, size_t response_max_size,
1026 ffa_vm_id_t sender, ffa_memory_attributes_t attributes,
1027 ffa_memory_region_flags_t flags, ffa_memory_handle_t handle,
1028 ffa_vm_id_t receiver, ffa_memory_access_permissions_t permissions,
Andrew Walbranca808b12020-05-15 17:22:28 +01001029 uint32_t page_count, uint32_t total_constituent_count,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001030 const struct ffa_memory_region_constituent constituents[],
Andrew Walbranca808b12020-05-15 17:22:28 +01001031 uint32_t fragment_constituent_count, uint32_t *total_length,
1032 uint32_t *fragment_length);
1033uint32_t ffa_memory_fragment_init(
1034 struct ffa_memory_region_constituent *fragment,
1035 size_t fragment_max_size,
1036 const struct ffa_memory_region_constituent constituents[],
1037 uint32_t constituent_count, uint32_t *fragment_length);
Federico Recanati392be392022-02-08 20:53:03 +01001038void ffa_endpoint_rx_tx_descriptor_init(
1039 struct ffa_endpoint_rx_tx_descriptor *desc, ffa_vm_id_t endpoint_id,
1040 uint64_t rx_address, uint64_t tx_address);