blob: c9b947cd64a8389268dfd621a7fcbf7f44bc152f [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
Raghu Krishnamurthy7592bcb2022-12-25 13:09:00 -080086#define FFA_PARTITION_INFO_GET_REGS_64 0xC400008B
Madhukar Pappireddy77d3bcd2023-03-01 17:26:22 -060087#define FFA_EL3_INTR_HANDLE_32 0x8400008C
Maksims Svecovs71b76702022-05-20 15:32:58 +010088
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010089/* FF-A error codes. */
90#define FFA_NOT_SUPPORTED INT32_C(-1)
91#define FFA_INVALID_PARAMETERS INT32_C(-2)
92#define FFA_NO_MEMORY INT32_C(-3)
93#define FFA_BUSY INT32_C(-4)
94#define FFA_INTERRUPTED INT32_C(-5)
95#define FFA_DENIED INT32_C(-6)
96#define FFA_RETRY INT32_C(-7)
97#define FFA_ABORTED INT32_C(-8)
J-Alvesc8e8a222021-06-08 17:33:52 +010098#define FFA_NO_DATA INT32_C(-9)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010099
100/* clang-format on */
101
J-Alves6f72ca82021-11-01 12:34:58 +0000102/**
103 * FF-A Feature ID, to be used with interface FFA_FEATURES.
104 * As defined in the FF-A v1.1 Beta specification, table 13.10, in section
105 * 13.2.
106 */
107
Olivier Deprezb76307d2022-06-09 17:17:45 +0200108#define FFA_FEATURES_FUNC_ID_MASK (UINT32_C(1) << 31)
J-Alves6f72ca82021-11-01 12:34:58 +0000109#define FFA_FEATURES_FEATURE_ID_MASK UINT32_C(0x7F)
110
Karl Meakin34b8ae92023-01-13 13:33:07 +0000111/**
112 * Defined in Table 13.14 in the FF-A v.1.1 REL0 specification.
113 * Bits[31:2] and Bit[0] of input are reserved (must be zero).
114 * Bit[0]: dynamically allocated buffer support.
115 * Bit[1]: NS bit handling.
116 * Bit[2]: support for retrieval by hypervisor.
117 */
118#define FFA_FEATURES_MEM_RETRIEVE_REQ_BUFFER_SUPPORT 0
119#define FFA_FEATURES_MEM_RETRIEVE_REQ_NS_SUPPORT (UINT32_C(1) << 1)
120#define FFA_FEATURES_MEM_RETRIEVE_REQ_HYPERVISOR_SUPPORT (UINT32_C(1) << 2)
121#define FFA_FEATURES_MEM_RETRIEVE_REQ_MBZ_MASK \
122 (~(FFA_FEATURES_MEM_RETRIEVE_REQ_BUFFER_SUPPORT | \
123 FFA_FEATURES_MEM_RETRIEVE_REQ_NS_SUPPORT | \
124 FFA_FEATURES_MEM_RETRIEVE_REQ_HYPERVISOR_SUPPORT))
125
J-Alves6f72ca82021-11-01 12:34:58 +0000126/* Query interrupt ID of Notification Pending Interrupt. */
127#define FFA_FEATURE_NPI 0x1U
128
129/* Query interrupt ID of Schedule Receiver Interrupt. */
130#define FFA_FEATURE_SRI 0x2U
131
132/* Query interrupt ID of the Managed Exit Interrupt. */
133#define FFA_FEATURE_MEI 0x3U
134
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100135/* FF-A function specific constants. */
136#define FFA_MSG_RECV_BLOCK 0x1
137#define FFA_MSG_RECV_BLOCK_MASK 0x1
138
139#define FFA_MSG_SEND_NOTIFY 0x1
140#define FFA_MSG_SEND_NOTIFY_MASK 0x1
141
142#define FFA_MEM_RECLAIM_CLEAR 0x1
143
144#define FFA_SLEEP_INDEFINITE 0
145
Raghu Krishnamurthyea6d25f2021-09-14 15:27:06 -0700146#define FFA_MEM_PERM_RO UINT32_C(0x7)
147#define FFA_MEM_PERM_RW UINT32_C(0x5)
148#define FFA_MEM_PERM_RX UINT32_C(0x3)
149
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000150/*
Olivier Deprez013f4d62022-11-21 15:46:20 +0100151 * Defined in Table 13.34 in the FF-A v1.1 EAC0 specification.
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000152 * The Partition count flag is used by FFA_PARTITION_INFO_GET to specify
153 * if partition info descriptors should be returned or just the count.
154 */
Olivier Deprez013f4d62022-11-21 15:46:20 +0100155#define FFA_PARTITION_COUNT_FLAG UINT32_C(0x1)
156#define FFA_PARTITION_COUNT_FLAG_MASK (UINT32_C(0x1) << 0)
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000157
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100158/**
159 * For use where the FF-A specification refers explicitly to '4K pages'. Not to
160 * be confused with PAGE_SIZE, which is the translation granule Hafnium is
161 * configured to use.
162 */
J-Alves715d6232023-02-16 16:33:28 +0000163#define FFA_PAGE_SIZE ((size_t)4096)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100164
Federico Recanatifc0295e2022-02-08 19:37:39 +0100165/** The ID of a VM. These are assigned sequentially starting with an offset. */
166typedef uint16_t ffa_vm_id_t;
167
168/**
169 * Partition message header as specified by table 6.2 from FF-A v1.1 EAC0
170 * specification.
171 */
172struct ffa_partition_rxtx_header {
173 uint32_t flags; /* MBZ */
174 uint32_t reserved;
175 /* Offset from the beginning of the buffer to the message payload. */
176 uint32_t offset;
177 /* Sender(Bits[31:16]) and Receiver(Bits[15:0]) endpoint IDs. */
178 uint32_t sender_receiver;
179 /* Size of message in buffer. */
180 uint32_t size;
181};
182
183#define FFA_RXTX_HEADER_SIZE sizeof(struct ffa_partition_rxtx_header)
184#define FFA_RXTX_SENDER_SHIFT (0x10U)
J-Alves70079932022-12-07 17:32:20 +0000185#define FFA_RXTX_ALLOCATOR_SHIFT 16
Federico Recanatifc0295e2022-02-08 19:37:39 +0100186
187static inline void ffa_rxtx_header_init(
188 ffa_vm_id_t sender, ffa_vm_id_t receiver, uint32_t size,
189 struct ffa_partition_rxtx_header *header)
190{
191 header->flags = 0;
192 header->reserved = 0;
193 header->offset = FFA_RXTX_HEADER_SIZE;
194 header->sender_receiver =
195 (uint32_t)(receiver | (sender << FFA_RXTX_SENDER_SHIFT));
196 header->size = size;
197}
198
199static inline ffa_vm_id_t ffa_rxtx_header_sender(
200 const struct ffa_partition_rxtx_header *h)
201{
202 return (ffa_vm_id_t)(h->sender_receiver >> FFA_RXTX_SENDER_SHIFT);
203}
204
205static inline ffa_vm_id_t ffa_rxtx_header_receiver(
206 const struct ffa_partition_rxtx_header *h)
207{
208 return (ffa_vm_id_t)(h->sender_receiver);
209}
210
211/* The maximum length possible for a single message. */
212#define FFA_PARTITION_MSG_PAYLOAD_MAX (HF_MAILBOX_SIZE - FFA_RXTX_HEADER_SIZE)
213
214struct ffa_partition_msg {
215 struct ffa_partition_rxtx_header header;
216 char payload[FFA_PARTITION_MSG_PAYLOAD_MAX];
217};
218
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100219/* The maximum length possible for a single message. */
220#define FFA_MSG_PAYLOAD_MAX HF_MAILBOX_SIZE
221
222enum ffa_data_access {
223 FFA_DATA_ACCESS_NOT_SPECIFIED,
224 FFA_DATA_ACCESS_RO,
225 FFA_DATA_ACCESS_RW,
226 FFA_DATA_ACCESS_RESERVED,
227};
228
229enum ffa_instruction_access {
230 FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED,
231 FFA_INSTRUCTION_ACCESS_NX,
232 FFA_INSTRUCTION_ACCESS_X,
233 FFA_INSTRUCTION_ACCESS_RESERVED,
234};
235
236enum ffa_memory_type {
237 FFA_MEMORY_NOT_SPECIFIED_MEM,
238 FFA_MEMORY_DEVICE_MEM,
239 FFA_MEMORY_NORMAL_MEM,
240};
241
242enum ffa_memory_cacheability {
243 FFA_MEMORY_CACHE_RESERVED = 0x0,
244 FFA_MEMORY_CACHE_NON_CACHEABLE = 0x1,
245 FFA_MEMORY_CACHE_RESERVED_1 = 0x2,
246 FFA_MEMORY_CACHE_WRITE_BACK = 0x3,
247 FFA_MEMORY_DEV_NGNRNE = 0x0,
248 FFA_MEMORY_DEV_NGNRE = 0x1,
249 FFA_MEMORY_DEV_NGRE = 0x2,
250 FFA_MEMORY_DEV_GRE = 0x3,
251};
252
253enum ffa_memory_shareability {
254 FFA_MEMORY_SHARE_NON_SHAREABLE,
255 FFA_MEMORY_SHARE_RESERVED,
256 FFA_MEMORY_OUTER_SHAREABLE,
257 FFA_MEMORY_INNER_SHAREABLE,
258};
259
260typedef uint8_t ffa_memory_access_permissions_t;
261
262/**
263 * This corresponds to table 44 of the FF-A 1.0 EAC specification, "Memory
264 * region attributes descriptor".
265 */
266typedef uint8_t ffa_memory_attributes_t;
267
268#define FFA_DATA_ACCESS_OFFSET (0x0U)
269#define FFA_DATA_ACCESS_MASK ((0x3U) << FFA_DATA_ACCESS_OFFSET)
270
271#define FFA_INSTRUCTION_ACCESS_OFFSET (0x2U)
272#define FFA_INSTRUCTION_ACCESS_MASK ((0x3U) << FFA_INSTRUCTION_ACCESS_OFFSET)
273
274#define FFA_MEMORY_TYPE_OFFSET (0x4U)
275#define FFA_MEMORY_TYPE_MASK ((0x3U) << FFA_MEMORY_TYPE_OFFSET)
276
277#define FFA_MEMORY_CACHEABILITY_OFFSET (0x2U)
278#define FFA_MEMORY_CACHEABILITY_MASK ((0x3U) << FFA_MEMORY_CACHEABILITY_OFFSET)
279
280#define FFA_MEMORY_SHAREABILITY_OFFSET (0x0U)
281#define FFA_MEMORY_SHAREABILITY_MASK ((0x3U) << FFA_MEMORY_SHAREABILITY_OFFSET)
282
283#define ATTR_FUNCTION_SET(name, container_type, offset, mask) \
284 static inline void ffa_set_##name##_attr(container_type *attr, \
285 const enum ffa_##name perm) \
286 { \
287 *attr = (*attr & ~(mask)) | ((perm << offset) & mask); \
288 }
289
290#define ATTR_FUNCTION_GET(name, container_type, offset, mask) \
291 static inline enum ffa_##name ffa_get_##name##_attr( \
292 container_type attr) \
293 { \
294 return (enum ffa_##name)((attr & mask) >> offset); \
295 }
296
297ATTR_FUNCTION_SET(data_access, ffa_memory_access_permissions_t,
298 FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK)
299ATTR_FUNCTION_GET(data_access, ffa_memory_access_permissions_t,
300 FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK)
301
302ATTR_FUNCTION_SET(instruction_access, ffa_memory_access_permissions_t,
303 FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK)
304ATTR_FUNCTION_GET(instruction_access, ffa_memory_access_permissions_t,
305 FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK)
306
307ATTR_FUNCTION_SET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET,
308 FFA_MEMORY_TYPE_MASK)
309ATTR_FUNCTION_GET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET,
310 FFA_MEMORY_TYPE_MASK)
311
312ATTR_FUNCTION_SET(memory_cacheability, ffa_memory_attributes_t,
313 FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK)
314ATTR_FUNCTION_GET(memory_cacheability, ffa_memory_attributes_t,
315 FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK)
316
317ATTR_FUNCTION_SET(memory_shareability, ffa_memory_attributes_t,
318 FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK)
319ATTR_FUNCTION_GET(memory_shareability, ffa_memory_attributes_t,
320 FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK)
321
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100322/**
323 * A globally-unique ID assigned by the hypervisor for a region of memory being
324 * sent between VMs.
325 */
326typedef uint64_t ffa_memory_handle_t;
327
J-Alves917d2f22020-10-30 18:39:30 +0000328#define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \
329 ((ffa_memory_handle_t)(UINT64_C(1) << 63))
330#define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR \
331 ((ffa_memory_handle_t)(UINT64_C(1) << 63))
332
333#define FFA_MEMORY_HANDLE_ALLOCATOR_SPMC (UINT64_C(0) << 63)
334#define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0))
335
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100336/**
337 * A count of VMs. This has the same range as the VM IDs but we give it a
338 * different name to make the different semantics clear.
339 */
340typedef ffa_vm_id_t ffa_vm_count_t;
341
342/** The index of a vCPU within a particular VM. */
343typedef uint16_t ffa_vcpu_index_t;
344
345/**
346 * A count of vCPUs. This has the same range as the vCPU indices but we give it
347 * a different name to make the different semantics clear.
348 */
349typedef ffa_vcpu_index_t ffa_vcpu_count_t;
350
351/** Parameter and return type of FF-A functions. */
352struct ffa_value {
353 uint64_t func;
354 uint64_t arg1;
355 uint64_t arg2;
356 uint64_t arg3;
357 uint64_t arg4;
358 uint64_t arg5;
359 uint64_t arg6;
360 uint64_t arg7;
Raghu Krishnamurthy567068e2022-12-26 07:46:38 -0800361
362 struct {
363 uint64_t arg8;
364 uint64_t arg9;
365 uint64_t arg10;
366 uint64_t arg11;
367 uint64_t arg12;
368 uint64_t arg13;
369 uint64_t arg14;
370 uint64_t arg15;
371 uint64_t arg16;
372 uint64_t arg17;
373 bool valid;
374 } extended_val;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100375};
376
Olivier Depreze562e542020-06-11 17:31:54 +0200377static inline uint32_t ffa_func_id(struct ffa_value args)
378{
379 return args.func;
380}
381
J-Alves13318e32021-02-22 17:21:00 +0000382static inline int32_t ffa_error_code(struct ffa_value val)
383{
384 return (int32_t)val.arg2;
385}
386
J-Alvesd6f4e142021-03-05 13:33:59 +0000387static inline ffa_vm_id_t ffa_sender(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100388{
389 return (args.arg1 >> 16) & 0xffff;
390}
391
J-Alvesd6f4e142021-03-05 13:33:59 +0000392static inline ffa_vm_id_t ffa_receiver(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100393{
394 return args.arg1 & 0xffff;
395}
396
397static inline uint32_t ffa_msg_send_size(struct ffa_value args)
398{
399 return args.arg3;
400}
401
Federico Recanati25053ee2022-03-14 15:01:53 +0100402static inline uint32_t ffa_msg_send2_flags(struct ffa_value args)
403{
404 return args.arg2;
405}
406
Olivier Depreze562e542020-06-11 17:31:54 +0200407static inline uint32_t ffa_partition_info_get_count(struct ffa_value args)
408{
409 return args.arg2;
410}
411
Raghu Krishnamurthy2957b922022-12-27 10:29:12 -0800412static inline uint16_t ffa_partition_info_regs_get_last_idx(
413 struct ffa_value args)
414{
415 return args.arg2 & 0xFFFF;
416}
417
418static inline uint16_t ffa_partition_info_regs_get_curr_idx(
419 struct ffa_value args)
420{
421 return (args.arg2 >> 16) & 0xFFFF;
422}
423
424static inline uint16_t ffa_partition_info_regs_get_tag(struct ffa_value args)
425{
426 return (args.arg2 >> 32) & 0xFFFF;
427}
428
429static inline uint16_t ffa_partition_info_regs_get_desc_size(
430 struct ffa_value args)
431{
432 return (args.arg2 >> 48);
433}
434
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100435static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t a1, uint32_t a2)
436{
437 return (uint64_t)a1 | (uint64_t)a2 << 32;
438}
439
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100440static inline ffa_memory_handle_t ffa_mem_success_handle(struct ffa_value args)
441{
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100442 return ffa_assemble_handle(args.arg2, args.arg3);
443}
444
Andrew Walbranca808b12020-05-15 17:22:28 +0100445static inline ffa_memory_handle_t ffa_frag_handle(struct ffa_value args)
446{
447 return ffa_assemble_handle(args.arg1, args.arg2);
448}
449
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100450static inline struct ffa_value ffa_mem_success(ffa_memory_handle_t handle)
451{
452 return (struct ffa_value){.func = FFA_SUCCESS_32,
453 .arg2 = (uint32_t)handle,
454 .arg3 = (uint32_t)(handle >> 32)};
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100455}
456
457static inline ffa_vm_id_t ffa_vm_id(struct ffa_value args)
458{
459 return (args.arg1 >> 16) & 0xffff;
460}
461
462static inline ffa_vcpu_index_t ffa_vcpu_index(struct ffa_value args)
463{
464 return args.arg1 & 0xffff;
465}
466
467static inline uint64_t ffa_vm_vcpu(ffa_vm_id_t vm_id,
468 ffa_vcpu_index_t vcpu_index)
469{
470 return ((uint32_t)vm_id << 16) | vcpu_index;
471}
472
Andrew Walbranca808b12020-05-15 17:22:28 +0100473static inline ffa_vm_id_t ffa_frag_sender(struct ffa_value args)
474{
475 return (args.arg4 >> 16) & 0xffff;
476}
477
J-Alves6f72ca82021-11-01 12:34:58 +0000478static inline uint32_t ffa_feature_intid(struct ffa_value args)
479{
480 return (uint32_t)args.arg2;
481}
482
Daniel Boulbyefa381f2022-01-18 14:49:40 +0000483static inline uint32_t ffa_fwk_msg(struct ffa_value args)
484{
485 return (uint32_t)args.arg2;
486}
487
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100488/**
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100489 * Holds the UUID in a struct that is mappable directly to the SMCC calling
490 * convention, which is used for FF-A calls.
491 *
492 * Refer to table 84 of the FF-A 1.0 EAC specification as well as section 5.3
493 * of the SMCC Spec 1.2.
494 */
495struct ffa_uuid {
496 uint32_t uuid[4];
497};
498
499static inline void ffa_uuid_init(uint32_t w0, uint32_t w1, uint32_t w2,
500 uint32_t w3, struct ffa_uuid *uuid)
501{
502 uuid->uuid[0] = w0;
503 uuid->uuid[1] = w1;
504 uuid->uuid[2] = w2;
505 uuid->uuid[3] = w3;
506}
507
508static inline bool ffa_uuid_equal(const struct ffa_uuid *uuid1,
509 const struct ffa_uuid *uuid2)
510{
511 return (uuid1->uuid[0] == uuid2->uuid[0]) &&
512 (uuid1->uuid[1] == uuid2->uuid[1]) &&
513 (uuid1->uuid[2] == uuid2->uuid[2]) &&
514 (uuid1->uuid[3] == uuid2->uuid[3]);
515}
516
517static inline bool ffa_uuid_is_null(const struct ffa_uuid *uuid)
518{
519 return (uuid->uuid[0] == 0) && (uuid->uuid[1] == 0) &&
520 (uuid->uuid[2] == 0) && (uuid->uuid[3] == 0);
521}
522
523/**
524 * Flags to determine the partition properties, as required by
525 * FFA_PARTITION_INFO_GET.
526 *
Kathleen Capella402fa852022-11-09 16:16:51 -0500527 * 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 +0100528 * specification, "Partition information descriptor, partition properties".
529 */
530typedef uint32_t ffa_partition_properties_t;
531
532/** Partition property: partition supports receipt of direct requests. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500533#define FFA_PARTITION_DIRECT_REQ_RECV (UINT32_C(1) << 0)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100534
535/** Partition property: partition can send direct requests. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500536#define FFA_PARTITION_DIRECT_REQ_SEND (UINT32_C(1) << 1)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100537
538/** Partition property: partition can send and receive indirect messages. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500539#define FFA_PARTITION_INDIRECT_MSG (UINT32_C(1) << 2)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100540
J-Alves09ff9d82021-11-02 11:55:20 +0000541/** Partition property: partition can receive notifications. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500542#define FFA_PARTITION_NOTIFICATION (UINT32_C(1) << 3)
543
544/** Partition property: partition runs in the AArch64 execution state. */
545#define FFA_PARTITION_AARCH64_EXEC (UINT32_C(1) << 8)
J-Alves09ff9d82021-11-02 11:55:20 +0000546
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100547/**
548 * Holds information returned for each partition by the FFA_PARTITION_INFO_GET
549 * interface.
Kathleen Capella402fa852022-11-09 16:16:51 -0500550 * This corresponds to table 13.37 "Partition information descriptor"
551 * in FF-A 1.1 EAC0 specification.
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000552 */
553struct ffa_partition_info {
554 ffa_vm_id_t vm_id;
555 ffa_vcpu_count_t vcpu_count;
556 ffa_partition_properties_t properties;
557 struct ffa_uuid uuid;
558};
559
560/**
Kathleen Capella402fa852022-11-09 16:16:51 -0500561 * Bits[31:3] of partition properties must be zero for FF-A v1.0.
562 * This corresponds to table 8.25 "Partition information descriptor"
563 * in DEN0077A FF-A 1.0 REL specification.
564 */
565#define FFA_PARTITION_v1_0_RES_MASK (~(UINT32_C(0x7)))
566
567/**
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000568 * Create a struct for the "Partition information descriptor" defined for v1.0
569 * which can be returned to v1.0 endpoints.
Kathleen Capella402fa852022-11-09 16:16:51 -0500570 * This corresponds to table 8.25 "Partition information descriptor"
571 * in DEN0077A FF-A 1.0 REL specification.
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100572 */
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000573
574struct ffa_partition_info_v1_0 {
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100575 ffa_vm_id_t vm_id;
576 ffa_vcpu_count_t vcpu_count;
577 ffa_partition_properties_t properties;
578};
579
J-Alvesdd1ad572022-01-25 17:58:26 +0000580/** Length in bytes of the name in boot information descriptor. */
581#define FFA_BOOT_INFO_NAME_LEN 16
582
J-Alves240d84c2022-04-22 12:19:34 +0100583/**
584 * The FF-A boot info descriptor, as defined in table 5.8 of section 5.4.1, of
585 * the FF-A v1.1 EAC0 specification.
586 */
J-Alvesdd1ad572022-01-25 17:58:26 +0000587struct ffa_boot_info_desc {
588 char name[FFA_BOOT_INFO_NAME_LEN];
589 uint8_t type;
590 uint8_t reserved;
591 uint16_t flags;
592 uint32_t size;
593 uint64_t content;
594};
595
596/** FF-A boot information type mask. */
597#define FFA_BOOT_INFO_TYPE_SHIFT 7
598#define FFA_BOOT_INFO_TYPE_MASK (0x1U << FFA_BOOT_INFO_TYPE_SHIFT)
599#define FFA_BOOT_INFO_TYPE_STD 0U
600#define FFA_BOOT_INFO_TYPE_IMPDEF 1U
601
602/** Standard boot info type IDs. */
603#define FFA_BOOT_INFO_TYPE_ID_MASK 0x7FU
604#define FFA_BOOT_INFO_TYPE_ID_FDT 0U
605#define FFA_BOOT_INFO_TYPE_ID_HOB 1U
606
607/** FF-A Boot Info descriptors flags. */
608#define FFA_BOOT_INFO_FLAG_MBZ_MASK 0xFFF0U
609
610/** Bits [1:0] encode the format of the name field in ffa_boot_info_desc. */
611#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT 0U
612#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK \
613 (0x3U << FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT)
614#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING 0x0U
615#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID 0x1U
616
617/** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */
618#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT 2
619#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK \
620 (0x3U << FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT)
621#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE 0x1U
622#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR 0x0U
623
624static inline uint16_t ffa_boot_info_content_format(
625 struct ffa_boot_info_desc *desc)
626{
627 return (desc->flags & FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK) >>
628 FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT;
629}
630
631static inline uint16_t ffa_boot_info_name_format(
632 struct ffa_boot_info_desc *desc)
633{
634 return (desc->flags & FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK) >>
635 FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT;
636}
637
638static inline uint8_t ffa_boot_info_type_id(struct ffa_boot_info_desc *desc)
639{
640 return desc->type & FFA_BOOT_INFO_TYPE_ID_MASK;
641}
642
643static inline uint8_t ffa_boot_info_type(struct ffa_boot_info_desc *desc)
644{
645 return (desc->type & FFA_BOOT_INFO_TYPE_MASK) >>
646 FFA_BOOT_INFO_TYPE_SHIFT;
647}
648
649/** Length in bytes of the signature in the boot descriptor. */
650#define FFA_BOOT_INFO_HEADER_SIGNATURE_LEN 4
651
J-Alves240d84c2022-04-22 12:19:34 +0100652/**
653 * The FF-A boot information header, as defined in table 5.9 of section 5.4.2,
654 * of the FF-A v1.1 EAC0 specification.
655 */
J-Alvesdd1ad572022-01-25 17:58:26 +0000656struct ffa_boot_info_header {
657 uint32_t signature;
658 uint32_t version;
659 uint32_t info_blob_size;
660 uint32_t desc_size;
661 uint32_t desc_count;
662 uint32_t desc_offset;
663 uint64_t reserved;
664 struct ffa_boot_info_desc boot_info[];
665};
666
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100667/**
J-Alves980d1992021-03-18 12:49:18 +0000668 * FF-A v1.1 specification restricts the number of notifications to a maximum
669 * of 64. Following all possible bitmaps.
670 */
671#define FFA_NOTIFICATION_MASK(ID) (UINT64_C(1) << ID)
672
673typedef uint64_t ffa_notifications_bitmap_t;
674
675#define MAX_FFA_NOTIFICATIONS 64U
676
677/**
J-Alvesc003a7a2021-03-18 13:06:53 +0000678 * Flag for notification bind and set, to specify call is about per-vCPU
679 * notifications.
680 */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200681#define FFA_NOTIFICATION_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesc003a7a2021-03-18 13:06:53 +0000682
Federico Recanatie73d2832022-04-20 11:10:52 +0200683#define FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(0)
684#define FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(32)
685
686/**
687 * Helper functions to check for buffer full notification.
688 */
689static inline bool is_ffa_hyp_buffer_full_notification(
690 ffa_notifications_bitmap_t framework)
691{
692 return (framework & FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK) != 0;
693}
694
695static inline bool is_ffa_spm_buffer_full_notification(
696 ffa_notifications_bitmap_t framework)
697{
698 return (framework & FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK) != 0;
699}
700
J-Alvesc003a7a2021-03-18 13:06:53 +0000701/**
J-Alves980d1992021-03-18 12:49:18 +0000702 * Helper function to assemble a 64-bit sized bitmap, from the 32-bit sized lo
703 * and hi.
704 * Helpful as FF-A specification defines that the notifications interfaces
705 * arguments are 32-bit registers.
706 */
707static inline ffa_notifications_bitmap_t ffa_notifications_bitmap(uint32_t lo,
708 uint32_t hi)
709{
710 return (ffa_notifications_bitmap_t)hi << 32U | lo;
711}
712
J-Alves98ff9562021-09-09 14:39:41 +0100713static inline ffa_notifications_bitmap_t ffa_notification_get_from_sp(
714 struct ffa_value val)
715{
716 return ffa_notifications_bitmap((uint32_t)val.arg2, (uint32_t)val.arg3);
717}
718
719static inline ffa_notifications_bitmap_t ffa_notification_get_from_vm(
720 struct ffa_value val)
721{
722 return ffa_notifications_bitmap((uint32_t)val.arg4, (uint32_t)val.arg5);
723}
724
Federico Recanatie73d2832022-04-20 11:10:52 +0200725static inline ffa_notifications_bitmap_t ffa_notification_get_from_framework(
726 struct ffa_value val)
727{
728 return ffa_notifications_bitmap((uint32_t)val.arg6, (uint32_t)val.arg7);
729}
730
J-Alves980d1992021-03-18 12:49:18 +0000731/**
J-Alvesaa79c012021-07-09 14:29:45 +0100732 * Flags used in calls to FFA_NOTIFICATION_GET interface.
733 */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200734#define FFA_NOTIFICATION_FLAG_BITMAP_SP (UINT32_C(1) << 0)
735#define FFA_NOTIFICATION_FLAG_BITMAP_VM (UINT32_C(1) << 1)
736#define FFA_NOTIFICATION_FLAG_BITMAP_SPM (UINT32_C(1) << 2)
737#define FFA_NOTIFICATION_FLAG_BITMAP_HYP (UINT32_C(1) << 3)
J-Alvesaa79c012021-07-09 14:29:45 +0100738
J-Alvesa3755072021-11-26 16:01:08 +0000739/* Flag to configure notification as being per vCPU. */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200740#define FFA_NOTIFICATIONS_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesa3755072021-11-26 16:01:08 +0000741
J-Alves13394022021-06-30 13:48:49 +0100742/** Flag for FFA_NOTIFICATION_SET to delay Schedule Receiver Interrupt */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200743#define FFA_NOTIFICATIONS_FLAG_DELAY_SRI (UINT32_C(1) << 1)
744
745#define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) \
746 ((((uint32_t)(id)) & UINT32_C(0xffff)) << 16)
J-Alves13394022021-06-30 13:48:49 +0100747
J-Alvesbe6e3032021-11-30 14:54:12 +0000748static inline ffa_vcpu_index_t ffa_notifications_get_vcpu(struct ffa_value args)
J-Alvesaa79c012021-07-09 14:29:45 +0100749{
J-Alvesbe6e3032021-11-30 14:54:12 +0000750 return (ffa_vcpu_index_t)(args.arg1 >> 16 & 0xffffU);
J-Alvesaa79c012021-07-09 14:29:45 +0100751}
752
753/**
J-Alvesc8e8a222021-06-08 17:33:52 +0100754 * The max number of IDs for return of FFA_NOTIFICATION_INFO_GET.
755 */
756#define FFA_NOTIFICATIONS_INFO_GET_MAX_IDS 20U
757
758/**
759 * Number of registers to use in successfull return of interface
760 * FFA_NOTIFICATION_INFO_GET.
761 */
762#define FFA_NOTIFICATIONS_INFO_GET_REGS_RET 5U
763
764#define FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING 0x1U
765
766/**
767 * Helper macros for return parameter encoding as described in section 17.7.1
768 * of the FF-A v1.1 Beta0 specification.
769 */
770#define FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT 0x7U
771#define FFA_NOTIFICATIONS_LISTS_COUNT_MASK 0x1fU
772#define FFA_NOTIFICATIONS_LIST_SHIFT(l) (2 * (l - 1) + 12)
773#define FFA_NOTIFICATIONS_LIST_SIZE_MASK 0x3U
774
775static inline uint32_t ffa_notification_info_get_lists_count(
776 struct ffa_value args)
777{
778 return (uint32_t)(args.arg2 >> FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT) &
779 FFA_NOTIFICATIONS_LISTS_COUNT_MASK;
780}
781
782static inline uint32_t ffa_notification_info_get_list_size(
783 struct ffa_value args, unsigned int list_idx)
784{
785 return ((uint32_t)args.arg2 >> FFA_NOTIFICATIONS_LIST_SHIFT(list_idx)) &
786 FFA_NOTIFICATIONS_LIST_SIZE_MASK;
787}
788
789static inline bool ffa_notification_info_get_more_pending(struct ffa_value args)
790{
791 return (args.arg2 & FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING) != 0U;
792}
793
794/**
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100795 * A set of contiguous pages which is part of a memory region. This corresponds
796 * to table 40 of the FF-A 1.0 EAC specification, "Constituent memory region
797 * descriptor".
798 */
799struct ffa_memory_region_constituent {
800 /**
801 * The base IPA of the constituent memory region, aligned to 4 kiB page
802 * size granularity.
803 */
804 uint64_t address;
805 /** The number of 4 kiB pages in the constituent memory region. */
806 uint32_t page_count;
807 /** Reserved field, must be 0. */
808 uint32_t reserved;
809};
810
811/**
812 * A set of pages comprising a memory region. This corresponds to table 39 of
813 * the FF-A 1.0 EAC specification, "Composite memory region descriptor".
814 */
815struct ffa_composite_memory_region {
816 /**
817 * The total number of 4 kiB pages included in this memory region. This
818 * must be equal to the sum of page counts specified in each
819 * `ffa_memory_region_constituent`.
820 */
821 uint32_t page_count;
822 /**
823 * The number of constituents (`ffa_memory_region_constituent`)
824 * included in this memory region range.
825 */
826 uint32_t constituent_count;
827 /** Reserved field, must be 0. */
828 uint64_t reserved_0;
829 /** An array of `constituent_count` memory region constituents. */
830 struct ffa_memory_region_constituent constituents[];
831};
832
833/** Flags to indicate properties of receivers during memory region retrieval. */
834typedef uint8_t ffa_memory_receiver_flags_t;
835
836/**
837 * This corresponds to table 41 of the FF-A 1.0 EAC specification, "Memory
838 * access permissions descriptor".
839 */
840struct ffa_memory_region_attributes {
841 /** The ID of the VM to which the memory is being given or shared. */
842 ffa_vm_id_t receiver;
843 /**
844 * The permissions with which the memory region should be mapped in the
845 * receiver's page table.
846 */
847 ffa_memory_access_permissions_t permissions;
848 /**
849 * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP
850 * for memory regions with multiple borrowers.
851 */
852 ffa_memory_receiver_flags_t flags;
853};
854
855/** Flags to control the behaviour of a memory sharing transaction. */
856typedef uint32_t ffa_memory_region_flags_t;
857
858/**
859 * Clear memory region contents after unmapping it from the sender and before
860 * mapping it for any receiver.
861 */
862#define FFA_MEMORY_REGION_FLAG_CLEAR 0x1
863
864/**
865 * Whether the hypervisor may time slice the memory sharing or retrieval
866 * operation.
867 */
868#define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2
869
870/**
871 * Whether the hypervisor should clear the memory region after the receiver
872 * relinquishes it or is aborted.
873 */
874#define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4
875
876#define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3)
877#define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3)
878#define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3)
879#define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3)
880#define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3)
881
Federico Recanati85090c42021-12-15 13:17:54 +0100882#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_VALID ((0x1U) << 9)
883#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_MASK ((0xFU) << 5)
884
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100885/**
886 * This corresponds to table 42 of the FF-A 1.0 EAC specification, "Endpoint
887 * memory access descriptor".
888 */
889struct ffa_memory_access {
890 struct ffa_memory_region_attributes receiver_permissions;
891 /**
892 * Offset in bytes from the start of the outer `ffa_memory_region` to
893 * an `ffa_composite_memory_region` struct.
894 */
895 uint32_t composite_memory_region_offset;
896 uint64_t reserved_0;
897};
898
J-Alves363f5722022-04-25 17:37:37 +0100899/** The maximum number of recipients a memory region may be sent to. */
J-Alvesba0e6172022-04-25 17:41:40 +0100900#define MAX_MEM_SHARE_RECIPIENTS UINT32_C(2)
J-Alves363f5722022-04-25 17:37:37 +0100901
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100902/**
903 * Information about a set of pages which are being shared. This corresponds to
904 * table 45 of the FF-A 1.0 EAC specification, "Lend, donate or share memory
905 * transaction descriptor". Note that it is also used for retrieve requests and
906 * responses.
907 */
908struct ffa_memory_region {
909 /**
910 * The ID of the VM which originally sent the memory region, i.e. the
911 * owner.
912 */
913 ffa_vm_id_t sender;
914 ffa_memory_attributes_t attributes;
915 /** Reserved field, must be 0. */
916 uint8_t reserved_0;
917 /** Flags to control behaviour of the transaction. */
918 ffa_memory_region_flags_t flags;
919 ffa_memory_handle_t handle;
920 /**
921 * An implementation defined value associated with the receiver and the
922 * memory region.
923 */
924 uint64_t tag;
925 /** Reserved field, must be 0. */
926 uint32_t reserved_1;
927 /**
928 * The number of `ffa_memory_access` entries included in this
929 * transaction.
930 */
931 uint32_t receiver_count;
932 /**
Federico Recanati3ddf28e2021-12-20 09:40:26 +0100933 * An array of `receiver_count` endpoint memory access descriptors.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100934 * Each one specifies a memory region offset, an endpoint and the
935 * attributes with which this memory region should be mapped in that
936 * endpoint's page table.
937 */
938 struct ffa_memory_access receivers[];
939};
940
941/**
942 * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table
943 * 150 of the FF-A 1.0 EAC specification, "Descriptor to relinquish a memory
944 * region".
945 */
946struct ffa_mem_relinquish {
947 ffa_memory_handle_t handle;
948 ffa_memory_region_flags_t flags;
949 uint32_t endpoint_count;
950 ffa_vm_id_t endpoints[];
951};
952
953/**
954 * Gets the `ffa_composite_memory_region` for the given receiver from an
955 * `ffa_memory_region`, or NULL if it is not valid.
956 */
957static inline struct ffa_composite_memory_region *
958ffa_memory_region_get_composite(struct ffa_memory_region *memory_region,
959 uint32_t receiver_index)
960{
961 uint32_t offset = memory_region->receivers[receiver_index]
962 .composite_memory_region_offset;
963
964 if (offset == 0) {
965 return NULL;
966 }
967
968 return (struct ffa_composite_memory_region *)((uint8_t *)memory_region +
969 offset);
970}
971
972static inline uint32_t ffa_mem_relinquish_init(
973 struct ffa_mem_relinquish *relinquish_request,
974 ffa_memory_handle_t handle, ffa_memory_region_flags_t flags,
975 ffa_vm_id_t sender)
976{
977 relinquish_request->handle = handle;
978 relinquish_request->flags = flags;
979 relinquish_request->endpoint_count = 1;
980 relinquish_request->endpoints[0] = sender;
981 return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_vm_id_t);
982}
983
Federico Recanati392be392022-02-08 20:53:03 +0100984/**
985 * Endpoint RX/TX descriptor, as defined by Table 13.27 in FF-A v1.1 EAC0.
986 * It's used by the Hypervisor to describe the RX/TX buffers mapped by a VM
987 * to the SPMC, in order to allow indirect messaging.
988 */
989struct ffa_endpoint_rx_tx_descriptor {
990 ffa_vm_id_t endpoint_id;
991 uint16_t reserved;
992
993 /*
994 * 8-byte aligned offset from the base address of this descriptor to the
995 * `ffa_composite_memory_region` describing the RX buffer.
996 */
997 uint32_t rx_offset;
998
999 /*
1000 * 8-byte aligned offset from the base address of this descriptor to the
1001 * `ffa_composite_memory_region` describing the TX buffer.
1002 */
1003 uint32_t tx_offset;
1004
1005 /* Pad to align on 16-byte boundary. */
1006 uint32_t pad;
1007};
1008
1009static inline struct ffa_composite_memory_region *
1010ffa_enpoint_get_rx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
1011{
1012 return (struct ffa_composite_memory_region *)((uintptr_t)desc +
1013 desc->rx_offset);
1014}
1015
1016static inline struct ffa_composite_memory_region *
1017ffa_enpoint_get_tx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
1018{
1019 return (struct ffa_composite_memory_region *)((uintptr_t)desc +
1020 desc->tx_offset);
1021}
1022
J-Alvesb44bb7d2022-04-25 15:43:46 +01001023void ffa_memory_access_init_permissions(
1024 struct ffa_memory_access *receiver, ffa_vm_id_t receiver_id,
1025 enum ffa_data_access data_access,
1026 enum ffa_instruction_access instruction_access,
1027 ffa_memory_receiver_flags_t flags);
J-Alves45085432022-04-22 16:19:20 +01001028uint32_t ffa_memory_region_init_single_receiver(
Andrew Walbranca808b12020-05-15 17:22:28 +01001029 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
1030 ffa_vm_id_t sender, ffa_vm_id_t receiver,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001031 const struct ffa_memory_region_constituent constituents[],
1032 uint32_t constituent_count, uint32_t tag,
1033 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
1034 enum ffa_instruction_access instruction_access,
1035 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
Andrew Walbranca808b12020-05-15 17:22:28 +01001036 enum ffa_memory_shareability shareability, uint32_t *fragment_length,
1037 uint32_t *total_length);
J-Alvesf4eecf72022-07-20 16:05:34 +01001038uint32_t ffa_memory_region_init(
1039 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
1040 ffa_vm_id_t sender, struct ffa_memory_access receivers[],
1041 uint32_t receiver_count,
1042 const struct ffa_memory_region_constituent constituents[],
1043 uint32_t constituent_count, uint32_t tag,
1044 ffa_memory_region_flags_t flags, enum ffa_memory_type type,
1045 enum ffa_memory_cacheability cacheability,
1046 enum ffa_memory_shareability shareability, uint32_t *fragment_length,
1047 uint32_t *total_length);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001048uint32_t ffa_memory_retrieve_request_init(
1049 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves9b24ed82022-08-04 13:12:45 +01001050 ffa_vm_id_t sender, struct ffa_memory_access receivers[],
1051 uint32_t receiver_count, uint32_t tag, ffa_memory_region_flags_t flags,
1052 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
1053 enum ffa_memory_shareability shareability);
1054uint32_t ffa_memory_retrieve_request_init_single_receiver(
1055 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001056 ffa_vm_id_t sender, ffa_vm_id_t receiver, uint32_t tag,
1057 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
1058 enum ffa_instruction_access instruction_access,
1059 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
1060 enum ffa_memory_shareability shareability);
1061uint32_t ffa_memory_lender_retrieve_request_init(
1062 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
1063 ffa_vm_id_t sender);
Andrew Walbranca808b12020-05-15 17:22:28 +01001064bool ffa_retrieved_memory_region_init(
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001065 struct ffa_memory_region *response, size_t response_max_size,
1066 ffa_vm_id_t sender, ffa_memory_attributes_t attributes,
1067 ffa_memory_region_flags_t flags, ffa_memory_handle_t handle,
1068 ffa_vm_id_t receiver, ffa_memory_access_permissions_t permissions,
Andrew Walbranca808b12020-05-15 17:22:28 +01001069 uint32_t page_count, uint32_t total_constituent_count,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001070 const struct ffa_memory_region_constituent constituents[],
Andrew Walbranca808b12020-05-15 17:22:28 +01001071 uint32_t fragment_constituent_count, uint32_t *total_length,
1072 uint32_t *fragment_length);
1073uint32_t ffa_memory_fragment_init(
1074 struct ffa_memory_region_constituent *fragment,
1075 size_t fragment_max_size,
1076 const struct ffa_memory_region_constituent constituents[],
1077 uint32_t constituent_count, uint32_t *fragment_length);
Federico Recanati392be392022-02-08 20:53:03 +01001078void ffa_endpoint_rx_tx_descriptor_init(
1079 struct ffa_endpoint_rx_tx_descriptor *desc, ffa_vm_id_t endpoint_id,
1080 uint64_t rx_address, uint64_t tx_address);