blob: 2cb0b7cd4d0d52a21694601ce9a3dada5d945b67 [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
Kathleen Capellae4fe2962023-09-01 17:08:47 -040016#define FFA_VERSION_MINOR 0x2
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
Daniel Boulbyc7dc9322023-10-27 15:12:07 +010026/**
27 * Check major versions are equal and the minor version of the caller is
28 * less than or equal to the minor version of the callee.
29 */
30#define FFA_VERSIONS_ARE_COMPATIBLE(v_caller, v_callee) \
31 ((((v_caller >> FFA_VERSION_MAJOR_OFFSET) & FFA_VERSION_MAJOR_MASK) == \
32 ((v_callee >> FFA_VERSION_MAJOR_OFFSET) & \
33 FFA_VERSION_MAJOR_MASK)) && \
34 (((v_caller >> FFA_VERSION_MINOR_OFFSET) & FFA_VERSION_MINOR_MASK) <= \
35 ((v_callee >> FFA_VERSION_MINOR_OFFSET) & FFA_VERSION_MINOR_MASK)))
36
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010037/* clang-format off */
38
39#define FFA_LOW_32_ID 0x84000060
40#define FFA_HIGH_32_ID 0x8400007F
41#define FFA_LOW_64_ID 0xC4000060
Fuad Tabbada72d142020-07-30 09:17:05 +010042#define FFA_HIGH_64_ID 0xC400007F
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010043
Karl Meakinf51a35f2023-08-07 17:53:52 +010044/**
45 * FF-A function identifiers.
46 * Don't forget to update `ffa_func_name` if you add a new one.
47 */
J-Alves3829fc02021-03-18 12:49:18 +000048#define FFA_ERROR_32 0x84000060
49#define FFA_SUCCESS_32 0x84000061
50#define FFA_SUCCESS_64 0xC4000061
51#define FFA_INTERRUPT_32 0x84000062
52#define FFA_VERSION_32 0x84000063
53#define FFA_FEATURES_32 0x84000064
54#define FFA_RX_RELEASE_32 0x84000065
55#define FFA_RXTX_MAP_32 0x84000066
56#define FFA_RXTX_MAP_64 0xC4000066
57#define FFA_RXTX_UNMAP_32 0x84000067
58#define FFA_PARTITION_INFO_GET_32 0x84000068
59#define FFA_ID_GET_32 0x84000069
60#define FFA_MSG_POLL_32 0x8400006A /* Legacy FF-A v1.0 */
61#define FFA_MSG_WAIT_32 0x8400006B
62#define FFA_YIELD_32 0x8400006C
63#define FFA_RUN_32 0x8400006D
64#define FFA_MSG_SEND_32 0x8400006E /* Legacy FF-A v1.0 */
65#define FFA_MSG_SEND_DIRECT_REQ_32 0x8400006F
66#define FFA_MSG_SEND_DIRECT_REQ_64 0xC400006F
67#define FFA_MSG_SEND_DIRECT_RESP_32 0x84000070
68#define FFA_MSG_SEND_DIRECT_RESP_64 0xC4000070
69#define FFA_MEM_DONATE_32 0x84000071
70#define FFA_MEM_LEND_32 0x84000072
71#define FFA_MEM_SHARE_32 0x84000073
72#define FFA_MEM_RETRIEVE_REQ_32 0x84000074
73#define FFA_MEM_RETRIEVE_RESP_32 0x84000075
74#define FFA_MEM_RELINQUISH_32 0x84000076
75#define FFA_MEM_RECLAIM_32 0x84000077
76#define FFA_MEM_FRAG_RX_32 0x8400007A
77#define FFA_MEM_FRAG_TX_32 0x8400007B
78#define FFA_NORMAL_WORLD_RESUME 0x8400007C
79
80/* FF-A v1.1 */
81#define FFA_NOTIFICATION_BITMAP_CREATE_32 0x8400007D
82#define FFA_NOTIFICATION_BITMAP_DESTROY_32 0x8400007E
83#define FFA_NOTIFICATION_BIND_32 0x8400007F
84#define FFA_NOTIFICATION_UNBIND_32 0x84000080
85#define FFA_NOTIFICATION_SET_32 0x84000081
86#define FFA_NOTIFICATION_GET_32 0x84000082
87#define FFA_NOTIFICATION_INFO_GET_64 0xC4000083
88#define FFA_RX_ACQUIRE_32 0x84000084
89#define FFA_SPM_ID_GET_32 0x84000085
90#define FFA_MSG_SEND2_32 0x84000086
91#define FFA_SECONDARY_EP_REGISTER_64 0xC4000087
92#define FFA_MEM_PERM_GET_32 0x84000088
93#define FFA_MEM_PERM_SET_32 0x84000089
Raghu Krishnamurthyea6d25f2021-09-14 15:27:06 -070094#define FFA_MEM_PERM_GET_64 0xC4000088
95#define FFA_MEM_PERM_SET_64 0xC4000089
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010096
Kathleen Capellae4fe2962023-09-01 17:08:47 -040097/* FF-A v1.2 */
Maksims Svecovs71b76702022-05-20 15:32:58 +010098#define FFA_CONSOLE_LOG_32 0x8400008A
99#define FFA_CONSOLE_LOG_64 0xC400008A
Raghu Krishnamurthy7592bcb2022-12-25 13:09:00 -0800100#define FFA_PARTITION_INFO_GET_REGS_64 0xC400008B
Madhukar Pappireddy77d3bcd2023-03-01 17:26:22 -0600101#define FFA_EL3_INTR_HANDLE_32 0x8400008C
Kathleen Capella41fea932023-06-23 17:39:28 -0400102#define FFA_MSG_SEND_DIRECT_REQ2_64 0xC400008D
Maksims Svecovs71b76702022-05-20 15:32:58 +0100103
Karl Meakinf51a35f2023-08-07 17:53:52 +0100104/**
105 * FF-A error codes.
106 * Don't forget to update `ffa_error_name` if you add a new one.
107 */
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100108#define FFA_NOT_SUPPORTED INT32_C(-1)
109#define FFA_INVALID_PARAMETERS INT32_C(-2)
110#define FFA_NO_MEMORY INT32_C(-3)
111#define FFA_BUSY INT32_C(-4)
112#define FFA_INTERRUPTED INT32_C(-5)
113#define FFA_DENIED INT32_C(-6)
114#define FFA_RETRY INT32_C(-7)
115#define FFA_ABORTED INT32_C(-8)
J-Alvesc8e8a222021-06-08 17:33:52 +0100116#define FFA_NO_DATA INT32_C(-9)
Kathleen Capellae4fe2962023-09-01 17:08:47 -0400117#define FFA_NOT_READY INT32_C(-10)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100118
119/* clang-format on */
120
Karl Meakinf51a35f2023-08-07 17:53:52 +0100121/* Return the name of the function identifier. */
122static inline const char *ffa_func_name(uint32_t func)
123{
124 switch (func) {
125 case FFA_ERROR_32:
126 return "FFA_ERROR_32";
127 case FFA_SUCCESS_32:
128 return "FFA_SUCCESS_32";
129 case FFA_SUCCESS_64:
130 return "FFA_SUCCESS_64";
131 case FFA_INTERRUPT_32:
132 return "FFA_INTERRUPT_32";
133 case FFA_VERSION_32:
134 return "FFA_VERSION_32";
135 case FFA_FEATURES_32:
136 return "FFA_FEATURES_32";
137 case FFA_RX_RELEASE_32:
138 return "FFA_RX_RELEASE_32";
139 case FFA_RXTX_MAP_32:
140 return "FFA_RXTX_MAP_32";
141 case FFA_RXTX_MAP_64:
142 return "FFA_RXTX_MAP_64";
143 case FFA_RXTX_UNMAP_32:
144 return "FFA_RXTX_UNMAP_32";
145 case FFA_PARTITION_INFO_GET_32:
146 return "FFA_PARTITION_INFO_GET_32";
147 case FFA_ID_GET_32:
148 return "FFA_ID_GET_32";
149 case FFA_MSG_POLL_32:
150 return "FFA_MSG_POLL_32";
151 case FFA_MSG_WAIT_32:
152 return "FFA_MSG_WAIT_32";
153 case FFA_YIELD_32:
154 return "FFA_YIELD_32";
155 case FFA_RUN_32:
156 return "FFA_RUN_32";
157 case FFA_MSG_SEND_32:
158 return "FFA_MSG_SEND_32";
159 case FFA_MSG_SEND_DIRECT_REQ_32:
160 return "FFA_MSG_SEND_DIRECT_REQ_32";
161 case FFA_MSG_SEND_DIRECT_REQ_64:
162 return "FFA_MSG_SEND_DIRECT_REQ_64";
163 case FFA_MSG_SEND_DIRECT_RESP_32:
164 return "FFA_MSG_SEND_DIRECT_RESP_32";
165 case FFA_MSG_SEND_DIRECT_RESP_64:
166 return "FFA_MSG_SEND_DIRECT_RESP_64";
167 case FFA_MEM_DONATE_32:
168 return "FFA_MEM_DONATE_32";
169 case FFA_MEM_LEND_32:
170 return "FFA_MEM_LEND_32";
171 case FFA_MEM_SHARE_32:
172 return "FFA_MEM_SHARE_32";
173 case FFA_MEM_RETRIEVE_REQ_32:
174 return "FFA_MEM_RETRIEVE_REQ_32";
175 case FFA_MEM_RETRIEVE_RESP_32:
176 return "FFA_MEM_RETRIEVE_RESP_32";
177 case FFA_MEM_RELINQUISH_32:
178 return "FFA_MEM_RELINQUISH_32";
179 case FFA_MEM_RECLAIM_32:
180 return "FFA_MEM_RECLAIM_32";
181 case FFA_MEM_FRAG_RX_32:
182 return "FFA_MEM_FRAG_RX_32";
183 case FFA_MEM_FRAG_TX_32:
184 return "FFA_MEM_FRAG_TX_32";
185 case FFA_NORMAL_WORLD_RESUME:
186 return "FFA_NORMAL_WORLD_RESUME";
187
188 /* FF-A v1.1 */
189 case FFA_NOTIFICATION_BITMAP_CREATE_32:
190 return "FFA_NOTIFICATION_BITMAP_CREATE_32";
191 case FFA_NOTIFICATION_BITMAP_DESTROY_32:
192 return "FFA_NOTIFICATION_BITMAP_DESTROY_32";
193 case FFA_NOTIFICATION_BIND_32:
194 return "FFA_NOTIFICATION_BIND_32";
195 case FFA_NOTIFICATION_UNBIND_32:
196 return "FFA_NOTIFICATION_UNBIND_32";
197 case FFA_NOTIFICATION_SET_32:
198 return "FFA_NOTIFICATION_SET_32";
199 case FFA_NOTIFICATION_GET_32:
200 return "FFA_NOTIFICATION_GET_32";
201 case FFA_NOTIFICATION_INFO_GET_64:
202 return "FFA_NOTIFICATION_INFO_GET_64";
203 case FFA_RX_ACQUIRE_32:
204 return "FFA_RX_ACQUIRE_32";
205 case FFA_SPM_ID_GET_32:
206 return "FFA_SPM_ID_GET_32";
207 case FFA_MSG_SEND2_32:
208 return "FFA_MSG_SEND2_32";
209 case FFA_SECONDARY_EP_REGISTER_64:
210 return "FFA_SECONDARY_EP_REGISTER_64";
211 case FFA_MEM_PERM_GET_32:
212 return "FFA_MEM_PERM_GET_32";
213 case FFA_MEM_PERM_SET_32:
214 return "FFA_MEM_PERM_SET_32";
215 case FFA_MEM_PERM_GET_64:
216 return "FFA_MEM_PERM_GET_64";
217 case FFA_MEM_PERM_SET_64:
218 return "FFA_MEM_PERM_SET_64";
219
220 /* Implementation-defined ABIs. */
221 case FFA_CONSOLE_LOG_32:
222 return "FFA_CONSOLE_LOG_32";
223 case FFA_CONSOLE_LOG_64:
224 return "FFA_CONSOLE_LOG_64";
225 case FFA_PARTITION_INFO_GET_REGS_64:
226 return "FFA_PARTITION_INFO_GET_REGS_64";
227 case FFA_EL3_INTR_HANDLE_32:
228 return "FFA_EL3_INTR_HANDLE_32";
229
230 default:
231 return "UNKNOWN";
232 }
233}
234
235/* Return the name of the error code. */
236static inline const char *ffa_error_name(int32_t error)
237{
238 switch (error) {
239 case FFA_NOT_SUPPORTED:
240 return "FFA_NOT_SUPPORTED";
241 case FFA_INVALID_PARAMETERS:
242 return "FFA_INVALID_PARAMETERS";
243 case FFA_NO_MEMORY:
244 return "FFA_NO_MEMORY";
245 case FFA_BUSY:
246 return "FFA_BUSY";
247 case FFA_INTERRUPTED:
248 return "FFA_INTERRUPTED";
249 case FFA_DENIED:
250 return "FFA_DENIED";
251 case FFA_RETRY:
252 return "FFA_RETRY";
253 case FFA_ABORTED:
254 return "FFA_ABORTED";
255 case FFA_NO_DATA:
256 return "FFA_NO_DATA";
257 default:
258 return "UNKNOWN";
259 }
260}
261
J-Alves6f72ca82021-11-01 12:34:58 +0000262/**
263 * FF-A Feature ID, to be used with interface FFA_FEATURES.
264 * As defined in the FF-A v1.1 Beta specification, table 13.10, in section
265 * 13.2.
266 */
267
Olivier Deprezb76307d2022-06-09 17:17:45 +0200268#define FFA_FEATURES_FUNC_ID_MASK (UINT32_C(1) << 31)
J-Alves6f72ca82021-11-01 12:34:58 +0000269#define FFA_FEATURES_FEATURE_ID_MASK UINT32_C(0x7F)
270
Karl Meakin34b8ae92023-01-13 13:33:07 +0000271/**
272 * Defined in Table 13.14 in the FF-A v.1.1 REL0 specification.
273 * Bits[31:2] and Bit[0] of input are reserved (must be zero).
274 * Bit[0]: dynamically allocated buffer support.
275 * Bit[1]: NS bit handling.
276 * Bit[2]: support for retrieval by hypervisor.
277 */
278#define FFA_FEATURES_MEM_RETRIEVE_REQ_BUFFER_SUPPORT 0
279#define FFA_FEATURES_MEM_RETRIEVE_REQ_NS_SUPPORT (UINT32_C(1) << 1)
280#define FFA_FEATURES_MEM_RETRIEVE_REQ_HYPERVISOR_SUPPORT (UINT32_C(1) << 2)
281#define FFA_FEATURES_MEM_RETRIEVE_REQ_MBZ_MASK \
282 (~(FFA_FEATURES_MEM_RETRIEVE_REQ_BUFFER_SUPPORT | \
283 FFA_FEATURES_MEM_RETRIEVE_REQ_NS_SUPPORT | \
284 FFA_FEATURES_MEM_RETRIEVE_REQ_HYPERVISOR_SUPPORT))
285
J-Alves6f72ca82021-11-01 12:34:58 +0000286/* Query interrupt ID of Notification Pending Interrupt. */
287#define FFA_FEATURE_NPI 0x1U
288
289/* Query interrupt ID of Schedule Receiver Interrupt. */
290#define FFA_FEATURE_SRI 0x2U
291
292/* Query interrupt ID of the Managed Exit Interrupt. */
293#define FFA_FEATURE_MEI 0x3U
294
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100295/* FF-A function specific constants. */
296#define FFA_MSG_RECV_BLOCK 0x1
297#define FFA_MSG_RECV_BLOCK_MASK 0x1
298
299#define FFA_MSG_SEND_NOTIFY 0x1
300#define FFA_MSG_SEND_NOTIFY_MASK 0x1
301
302#define FFA_MEM_RECLAIM_CLEAR 0x1
303
304#define FFA_SLEEP_INDEFINITE 0
305
Raghu Krishnamurthyea6d25f2021-09-14 15:27:06 -0700306#define FFA_MEM_PERM_RO UINT32_C(0x7)
307#define FFA_MEM_PERM_RW UINT32_C(0x5)
308#define FFA_MEM_PERM_RX UINT32_C(0x3)
309
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000310/*
Olivier Deprez013f4d62022-11-21 15:46:20 +0100311 * Defined in Table 13.34 in the FF-A v1.1 EAC0 specification.
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000312 * The Partition count flag is used by FFA_PARTITION_INFO_GET to specify
313 * if partition info descriptors should be returned or just the count.
314 */
Olivier Deprez013f4d62022-11-21 15:46:20 +0100315#define FFA_PARTITION_COUNT_FLAG UINT32_C(0x1)
316#define FFA_PARTITION_COUNT_FLAG_MASK (UINT32_C(0x1) << 0)
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000317
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100318/**
319 * For use where the FF-A specification refers explicitly to '4K pages'. Not to
320 * be confused with PAGE_SIZE, which is the translation granule Hafnium is
321 * configured to use.
322 */
J-Alves715d6232023-02-16 16:33:28 +0000323#define FFA_PAGE_SIZE ((size_t)4096)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100324
Federico Recanatifc0295e2022-02-08 19:37:39 +0100325/** The ID of a VM. These are assigned sequentially starting with an offset. */
J-Alves19e20cf2023-08-02 12:48:55 +0100326typedef uint16_t ffa_id_t;
Federico Recanatifc0295e2022-02-08 19:37:39 +0100327
328/**
J-Alves661e1b72023-08-02 13:39:40 +0100329 * The FF-A v1.2 ALP0, section 6.1 defines that partition IDs are split into two
330 * parts:
331 * - Bit15 -> partition type identifier.
332 * - b'0 -> ID relates to a VM ID.
333 * - b'1 -> ID relates to an SP ID.
334 */
335#define FFA_ID_MASK ((ffa_id_t)0x8000)
336#define FFA_VM_ID_MASK ((ffa_id_t)0x0000)
337
338/**
339 * Helper to check if FF-A ID is a VM ID, managed by the hypervisor.
340 */
341static inline bool ffa_is_vm_id(ffa_id_t id)
342{
343 return (FFA_ID_MASK & id) == FFA_VM_ID_MASK;
344}
345
346/**
Federico Recanatifc0295e2022-02-08 19:37:39 +0100347 * Partition message header as specified by table 6.2 from FF-A v1.1 EAC0
348 * specification.
349 */
350struct ffa_partition_rxtx_header {
351 uint32_t flags; /* MBZ */
352 uint32_t reserved;
353 /* Offset from the beginning of the buffer to the message payload. */
354 uint32_t offset;
355 /* Sender(Bits[31:16]) and Receiver(Bits[15:0]) endpoint IDs. */
356 uint32_t sender_receiver;
357 /* Size of message in buffer. */
358 uint32_t size;
359};
360
361#define FFA_RXTX_HEADER_SIZE sizeof(struct ffa_partition_rxtx_header)
362#define FFA_RXTX_SENDER_SHIFT (0x10U)
J-Alves70079932022-12-07 17:32:20 +0000363#define FFA_RXTX_ALLOCATOR_SHIFT 16
Federico Recanatifc0295e2022-02-08 19:37:39 +0100364
365static inline void ffa_rxtx_header_init(
J-Alves19e20cf2023-08-02 12:48:55 +0100366 ffa_id_t sender, ffa_id_t receiver, uint32_t size,
Federico Recanatifc0295e2022-02-08 19:37:39 +0100367 struct ffa_partition_rxtx_header *header)
368{
369 header->flags = 0;
370 header->reserved = 0;
371 header->offset = FFA_RXTX_HEADER_SIZE;
372 header->sender_receiver =
373 (uint32_t)(receiver | (sender << FFA_RXTX_SENDER_SHIFT));
374 header->size = size;
375}
376
J-Alves19e20cf2023-08-02 12:48:55 +0100377static inline ffa_id_t ffa_rxtx_header_sender(
Federico Recanatifc0295e2022-02-08 19:37:39 +0100378 const struct ffa_partition_rxtx_header *h)
379{
J-Alves19e20cf2023-08-02 12:48:55 +0100380 return (ffa_id_t)(h->sender_receiver >> FFA_RXTX_SENDER_SHIFT);
Federico Recanatifc0295e2022-02-08 19:37:39 +0100381}
382
J-Alves19e20cf2023-08-02 12:48:55 +0100383static inline ffa_id_t ffa_rxtx_header_receiver(
Federico Recanatifc0295e2022-02-08 19:37:39 +0100384 const struct ffa_partition_rxtx_header *h)
385{
J-Alves19e20cf2023-08-02 12:48:55 +0100386 return (ffa_id_t)(h->sender_receiver);
Federico Recanatifc0295e2022-02-08 19:37:39 +0100387}
388
389/* The maximum length possible for a single message. */
390#define FFA_PARTITION_MSG_PAYLOAD_MAX (HF_MAILBOX_SIZE - FFA_RXTX_HEADER_SIZE)
391
392struct ffa_partition_msg {
393 struct ffa_partition_rxtx_header header;
394 char payload[FFA_PARTITION_MSG_PAYLOAD_MAX];
395};
396
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100397/* The maximum length possible for a single message. */
398#define FFA_MSG_PAYLOAD_MAX HF_MAILBOX_SIZE
399
400enum ffa_data_access {
401 FFA_DATA_ACCESS_NOT_SPECIFIED,
402 FFA_DATA_ACCESS_RO,
403 FFA_DATA_ACCESS_RW,
404 FFA_DATA_ACCESS_RESERVED,
405};
406
407enum ffa_instruction_access {
408 FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED,
409 FFA_INSTRUCTION_ACCESS_NX,
410 FFA_INSTRUCTION_ACCESS_X,
411 FFA_INSTRUCTION_ACCESS_RESERVED,
412};
413
414enum ffa_memory_type {
415 FFA_MEMORY_NOT_SPECIFIED_MEM,
416 FFA_MEMORY_DEVICE_MEM,
417 FFA_MEMORY_NORMAL_MEM,
418};
419
420enum ffa_memory_cacheability {
421 FFA_MEMORY_CACHE_RESERVED = 0x0,
422 FFA_MEMORY_CACHE_NON_CACHEABLE = 0x1,
423 FFA_MEMORY_CACHE_RESERVED_1 = 0x2,
424 FFA_MEMORY_CACHE_WRITE_BACK = 0x3,
425 FFA_MEMORY_DEV_NGNRNE = 0x0,
426 FFA_MEMORY_DEV_NGNRE = 0x1,
427 FFA_MEMORY_DEV_NGRE = 0x2,
428 FFA_MEMORY_DEV_GRE = 0x3,
429};
430
431enum ffa_memory_shareability {
432 FFA_MEMORY_SHARE_NON_SHAREABLE,
433 FFA_MEMORY_SHARE_RESERVED,
434 FFA_MEMORY_OUTER_SHAREABLE,
435 FFA_MEMORY_INNER_SHAREABLE,
436};
437
Olivier Deprez4342a3c2022-02-28 09:37:25 +0100438/**
439 * FF-A v1.1 REL0 Table 10.18 memory region attributes descriptor NS Bit 6.
440 * Per section 10.10.4.1, NS bit is reserved for FFA_MEM_DONATE/LEND/SHARE
441 * and FFA_MEM_RETRIEVE_REQUEST.
442 */
443enum ffa_memory_security {
444 FFA_MEMORY_SECURITY_UNSPECIFIED = 0,
445 FFA_MEMORY_SECURITY_SECURE = 0,
446 FFA_MEMORY_SECURITY_NON_SECURE,
447};
448
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100449typedef uint8_t ffa_memory_access_permissions_t;
450
451/**
J-Alves0b6653d2022-04-22 13:17:38 +0100452 * This corresponds to table 10.18 of the FF-A v1.1 EAC0 specification, "Memory
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100453 * region attributes descriptor".
454 */
J-Alves0b6653d2022-04-22 13:17:38 +0100455typedef uint16_t ffa_memory_attributes_t;
456
457/* FF-A v1.1 EAC0 states bit [15:7] Must Be Zero. */
458#define FFA_MEMORY_ATTRIBUTES_MBZ_MASK 0xFF80U
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100459
460#define FFA_DATA_ACCESS_OFFSET (0x0U)
461#define FFA_DATA_ACCESS_MASK ((0x3U) << FFA_DATA_ACCESS_OFFSET)
462
463#define FFA_INSTRUCTION_ACCESS_OFFSET (0x2U)
464#define FFA_INSTRUCTION_ACCESS_MASK ((0x3U) << FFA_INSTRUCTION_ACCESS_OFFSET)
465
466#define FFA_MEMORY_TYPE_OFFSET (0x4U)
467#define FFA_MEMORY_TYPE_MASK ((0x3U) << FFA_MEMORY_TYPE_OFFSET)
468
Olivier Deprez4342a3c2022-02-28 09:37:25 +0100469#define FFA_MEMORY_SECURITY_OFFSET (0x6U)
470#define FFA_MEMORY_SECURITY_MASK ((0x1U) << FFA_MEMORY_SECURITY_OFFSET)
471
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100472#define FFA_MEMORY_CACHEABILITY_OFFSET (0x2U)
473#define FFA_MEMORY_CACHEABILITY_MASK ((0x3U) << FFA_MEMORY_CACHEABILITY_OFFSET)
474
475#define FFA_MEMORY_SHAREABILITY_OFFSET (0x0U)
476#define FFA_MEMORY_SHAREABILITY_MASK ((0x3U) << FFA_MEMORY_SHAREABILITY_OFFSET)
477
478#define ATTR_FUNCTION_SET(name, container_type, offset, mask) \
479 static inline void ffa_set_##name##_attr(container_type *attr, \
480 const enum ffa_##name perm) \
481 { \
482 *attr = (*attr & ~(mask)) | ((perm << offset) & mask); \
483 }
484
485#define ATTR_FUNCTION_GET(name, container_type, offset, mask) \
486 static inline enum ffa_##name ffa_get_##name##_attr( \
487 container_type attr) \
488 { \
489 return (enum ffa_##name)((attr & mask) >> offset); \
490 }
491
492ATTR_FUNCTION_SET(data_access, ffa_memory_access_permissions_t,
493 FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK)
494ATTR_FUNCTION_GET(data_access, ffa_memory_access_permissions_t,
495 FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK)
496
497ATTR_FUNCTION_SET(instruction_access, ffa_memory_access_permissions_t,
498 FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK)
499ATTR_FUNCTION_GET(instruction_access, ffa_memory_access_permissions_t,
500 FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK)
501
502ATTR_FUNCTION_SET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET,
503 FFA_MEMORY_TYPE_MASK)
504ATTR_FUNCTION_GET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET,
505 FFA_MEMORY_TYPE_MASK)
506
507ATTR_FUNCTION_SET(memory_cacheability, ffa_memory_attributes_t,
508 FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK)
509ATTR_FUNCTION_GET(memory_cacheability, ffa_memory_attributes_t,
510 FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK)
511
512ATTR_FUNCTION_SET(memory_shareability, ffa_memory_attributes_t,
513 FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK)
514ATTR_FUNCTION_GET(memory_shareability, ffa_memory_attributes_t,
515 FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK)
516
Olivier Deprez4342a3c2022-02-28 09:37:25 +0100517ATTR_FUNCTION_SET(memory_security, ffa_memory_attributes_t,
518 FFA_MEMORY_SECURITY_OFFSET, FFA_MEMORY_SECURITY_MASK)
519ATTR_FUNCTION_GET(memory_security, ffa_memory_attributes_t,
520 FFA_MEMORY_SECURITY_OFFSET, FFA_MEMORY_SECURITY_MASK)
521
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100522/**
523 * A globally-unique ID assigned by the hypervisor for a region of memory being
524 * sent between VMs.
525 */
526typedef uint64_t ffa_memory_handle_t;
527
J-Alves917d2f22020-10-30 18:39:30 +0000528#define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \
529 ((ffa_memory_handle_t)(UINT64_C(1) << 63))
530#define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR \
531 ((ffa_memory_handle_t)(UINT64_C(1) << 63))
532
533#define FFA_MEMORY_HANDLE_ALLOCATOR_SPMC (UINT64_C(0) << 63)
534#define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0))
535
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100536/**
537 * A count of VMs. This has the same range as the VM IDs but we give it a
538 * different name to make the different semantics clear.
539 */
J-Alves19e20cf2023-08-02 12:48:55 +0100540typedef ffa_id_t ffa_vm_count_t;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100541
542/** The index of a vCPU within a particular VM. */
543typedef uint16_t ffa_vcpu_index_t;
544
545/**
546 * A count of vCPUs. This has the same range as the vCPU indices but we give it
547 * a different name to make the different semantics clear.
548 */
549typedef ffa_vcpu_index_t ffa_vcpu_count_t;
550
551/** Parameter and return type of FF-A functions. */
552struct ffa_value {
553 uint64_t func;
554 uint64_t arg1;
555 uint64_t arg2;
556 uint64_t arg3;
557 uint64_t arg4;
558 uint64_t arg5;
559 uint64_t arg6;
560 uint64_t arg7;
Raghu Krishnamurthy567068e2022-12-26 07:46:38 -0800561
562 struct {
563 uint64_t arg8;
564 uint64_t arg9;
565 uint64_t arg10;
566 uint64_t arg11;
567 uint64_t arg12;
568 uint64_t arg13;
569 uint64_t arg14;
570 uint64_t arg15;
571 uint64_t arg16;
572 uint64_t arg17;
573 bool valid;
574 } extended_val;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100575};
576
Olivier Depreze562e542020-06-11 17:31:54 +0200577static inline uint32_t ffa_func_id(struct ffa_value args)
578{
579 return args.func;
580}
581
J-Alves13318e32021-02-22 17:21:00 +0000582static inline int32_t ffa_error_code(struct ffa_value val)
583{
584 return (int32_t)val.arg2;
585}
586
J-Alves19e20cf2023-08-02 12:48:55 +0100587static inline ffa_id_t ffa_sender(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100588{
589 return (args.arg1 >> 16) & 0xffff;
590}
591
J-Alves19e20cf2023-08-02 12:48:55 +0100592static inline ffa_id_t ffa_receiver(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100593{
594 return args.arg1 & 0xffff;
595}
596
597static inline uint32_t ffa_msg_send_size(struct ffa_value args)
598{
599 return args.arg3;
600}
601
Federico Recanati25053ee2022-03-14 15:01:53 +0100602static inline uint32_t ffa_msg_send2_flags(struct ffa_value args)
603{
604 return args.arg2;
605}
606
Olivier Depreze562e542020-06-11 17:31:54 +0200607static inline uint32_t ffa_partition_info_get_count(struct ffa_value args)
608{
609 return args.arg2;
610}
611
Raghu Krishnamurthy2957b922022-12-27 10:29:12 -0800612static inline uint16_t ffa_partition_info_regs_get_last_idx(
613 struct ffa_value args)
614{
615 return args.arg2 & 0xFFFF;
616}
617
618static inline uint16_t ffa_partition_info_regs_get_curr_idx(
619 struct ffa_value args)
620{
621 return (args.arg2 >> 16) & 0xFFFF;
622}
623
624static inline uint16_t ffa_partition_info_regs_get_tag(struct ffa_value args)
625{
626 return (args.arg2 >> 32) & 0xFFFF;
627}
628
629static inline uint16_t ffa_partition_info_regs_get_desc_size(
630 struct ffa_value args)
631{
632 return (args.arg2 >> 48);
633}
634
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100635static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t a1, uint32_t a2)
636{
637 return (uint64_t)a1 | (uint64_t)a2 << 32;
638}
639
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100640static inline ffa_memory_handle_t ffa_mem_success_handle(struct ffa_value args)
641{
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100642 return ffa_assemble_handle(args.arg2, args.arg3);
643}
644
Andrew Walbranca808b12020-05-15 17:22:28 +0100645static inline ffa_memory_handle_t ffa_frag_handle(struct ffa_value args)
646{
647 return ffa_assemble_handle(args.arg1, args.arg2);
648}
649
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100650static inline struct ffa_value ffa_mem_success(ffa_memory_handle_t handle)
651{
652 return (struct ffa_value){.func = FFA_SUCCESS_32,
653 .arg2 = (uint32_t)handle,
654 .arg3 = (uint32_t)(handle >> 32)};
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100655}
656
J-Alves19e20cf2023-08-02 12:48:55 +0100657static inline ffa_id_t ffa_vm_id(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100658{
659 return (args.arg1 >> 16) & 0xffff;
660}
661
662static inline ffa_vcpu_index_t ffa_vcpu_index(struct ffa_value args)
663{
664 return args.arg1 & 0xffff;
665}
666
J-Alves19e20cf2023-08-02 12:48:55 +0100667static inline uint64_t ffa_vm_vcpu(ffa_id_t vm_id, ffa_vcpu_index_t vcpu_index)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100668{
669 return ((uint32_t)vm_id << 16) | vcpu_index;
670}
671
J-Alves19e20cf2023-08-02 12:48:55 +0100672static inline ffa_id_t ffa_frag_sender(struct ffa_value args)
Andrew Walbranca808b12020-05-15 17:22:28 +0100673{
674 return (args.arg4 >> 16) & 0xffff;
675}
676
J-Alves6f72ca82021-11-01 12:34:58 +0000677static inline uint32_t ffa_feature_intid(struct ffa_value args)
678{
679 return (uint32_t)args.arg2;
680}
681
Daniel Boulbyefa381f2022-01-18 14:49:40 +0000682static inline uint32_t ffa_fwk_msg(struct ffa_value args)
683{
684 return (uint32_t)args.arg2;
685}
686
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100687/**
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100688 * Holds the UUID in a struct that is mappable directly to the SMCC calling
689 * convention, which is used for FF-A calls.
690 *
691 * Refer to table 84 of the FF-A 1.0 EAC specification as well as section 5.3
692 * of the SMCC Spec 1.2.
693 */
694struct ffa_uuid {
695 uint32_t uuid[4];
696};
697
698static inline void ffa_uuid_init(uint32_t w0, uint32_t w1, uint32_t w2,
699 uint32_t w3, struct ffa_uuid *uuid)
700{
701 uuid->uuid[0] = w0;
702 uuid->uuid[1] = w1;
703 uuid->uuid[2] = w2;
704 uuid->uuid[3] = w3;
705}
706
707static inline bool ffa_uuid_equal(const struct ffa_uuid *uuid1,
708 const struct ffa_uuid *uuid2)
709{
710 return (uuid1->uuid[0] == uuid2->uuid[0]) &&
711 (uuid1->uuid[1] == uuid2->uuid[1]) &&
712 (uuid1->uuid[2] == uuid2->uuid[2]) &&
713 (uuid1->uuid[3] == uuid2->uuid[3]);
714}
715
716static inline bool ffa_uuid_is_null(const struct ffa_uuid *uuid)
717{
718 return (uuid->uuid[0] == 0) && (uuid->uuid[1] == 0) &&
719 (uuid->uuid[2] == 0) && (uuid->uuid[3] == 0);
720}
721
Kathleen Capella41fea932023-06-23 17:39:28 -0400722static inline void ffa_uuid_unpack_from_uint64(uint64_t uuid_lo,
723 uint64_t uuid_hi,
724 struct ffa_uuid *uuid)
725{
726 ffa_uuid_init((uint32_t)(uuid_lo & 0xFFFFFFFFU),
727 (uint32_t)(uuid_lo >> 32),
728 (uint32_t)(uuid_hi & 0xFFFFFFFFU),
729 (uint32_t)(uuid_hi >> 32), uuid);
730}
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100731/**
732 * Flags to determine the partition properties, as required by
733 * FFA_PARTITION_INFO_GET.
734 *
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400735 * The values of the flags are specified in table 6.2 of DEN0077A FF-A 1.2 ALP0
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100736 * specification, "Partition information descriptor, partition properties".
737 */
738typedef uint32_t ffa_partition_properties_t;
739
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400740/**
741 * Partition property: partition supports receipt of direct requests via the
742 * FFA_MSG_SEND_DIRECT_REQ ABI.
743 */
Kathleen Capella402fa852022-11-09 16:16:51 -0500744#define FFA_PARTITION_DIRECT_REQ_RECV (UINT32_C(1) << 0)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100745
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400746/**
747 * Partition property: partition can send direct requests via the
748 * FFA_MSG_SEND_DIRECT_REQ ABI.
749 */
Kathleen Capella402fa852022-11-09 16:16:51 -0500750#define FFA_PARTITION_DIRECT_REQ_SEND (UINT32_C(1) << 1)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100751
752/** Partition property: partition can send and receive indirect messages. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500753#define FFA_PARTITION_INDIRECT_MSG (UINT32_C(1) << 2)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100754
J-Alves09ff9d82021-11-02 11:55:20 +0000755/** Partition property: partition can receive notifications. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500756#define FFA_PARTITION_NOTIFICATION (UINT32_C(1) << 3)
757
758/** Partition property: partition runs in the AArch64 execution state. */
759#define FFA_PARTITION_AARCH64_EXEC (UINT32_C(1) << 8)
J-Alves09ff9d82021-11-02 11:55:20 +0000760
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100761/**
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400762 * Partition property: partition supports receipt of direct requests via the
763 * FFA_MSG_SEND_DIRECT_REQ2 ABI.
764 */
765#define FFA_PARTITION_DIRECT_REQ2_RECV (UINT32_C(1) << 9)
766
767/**
768 * Partition property: partition can send direct requests via the
769 * FFA_MSG_SEND_DIRECT_REQ2 ABI.
770 */
771#define FFA_PARTITION_DIRECT_REQ2_SEND (UINT32_C(1) << 10)
772
773/**
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100774 * Holds information returned for each partition by the FFA_PARTITION_INFO_GET
775 * interface.
Kathleen Capella402fa852022-11-09 16:16:51 -0500776 * This corresponds to table 13.37 "Partition information descriptor"
777 * in FF-A 1.1 EAC0 specification.
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000778 */
779struct ffa_partition_info {
J-Alves19e20cf2023-08-02 12:48:55 +0100780 ffa_id_t vm_id;
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000781 ffa_vcpu_count_t vcpu_count;
782 ffa_partition_properties_t properties;
783 struct ffa_uuid uuid;
784};
785
J-Alvesdd1ad572022-01-25 17:58:26 +0000786/** Length in bytes of the name in boot information descriptor. */
787#define FFA_BOOT_INFO_NAME_LEN 16
788
J-Alves240d84c2022-04-22 12:19:34 +0100789/**
790 * The FF-A boot info descriptor, as defined in table 5.8 of section 5.4.1, of
791 * the FF-A v1.1 EAC0 specification.
792 */
J-Alvesdd1ad572022-01-25 17:58:26 +0000793struct ffa_boot_info_desc {
794 char name[FFA_BOOT_INFO_NAME_LEN];
795 uint8_t type;
796 uint8_t reserved;
797 uint16_t flags;
798 uint32_t size;
799 uint64_t content;
800};
801
802/** FF-A boot information type mask. */
803#define FFA_BOOT_INFO_TYPE_SHIFT 7
804#define FFA_BOOT_INFO_TYPE_MASK (0x1U << FFA_BOOT_INFO_TYPE_SHIFT)
805#define FFA_BOOT_INFO_TYPE_STD 0U
806#define FFA_BOOT_INFO_TYPE_IMPDEF 1U
807
808/** Standard boot info type IDs. */
809#define FFA_BOOT_INFO_TYPE_ID_MASK 0x7FU
810#define FFA_BOOT_INFO_TYPE_ID_FDT 0U
811#define FFA_BOOT_INFO_TYPE_ID_HOB 1U
812
813/** FF-A Boot Info descriptors flags. */
814#define FFA_BOOT_INFO_FLAG_MBZ_MASK 0xFFF0U
815
816/** Bits [1:0] encode the format of the name field in ffa_boot_info_desc. */
817#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT 0U
818#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK \
819 (0x3U << FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT)
820#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING 0x0U
821#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID 0x1U
822
823/** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */
824#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT 2
825#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK \
826 (0x3U << FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT)
827#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE 0x1U
828#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR 0x0U
829
830static inline uint16_t ffa_boot_info_content_format(
831 struct ffa_boot_info_desc *desc)
832{
833 return (desc->flags & FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK) >>
834 FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT;
835}
836
837static inline uint16_t ffa_boot_info_name_format(
838 struct ffa_boot_info_desc *desc)
839{
840 return (desc->flags & FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK) >>
841 FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT;
842}
843
844static inline uint8_t ffa_boot_info_type_id(struct ffa_boot_info_desc *desc)
845{
846 return desc->type & FFA_BOOT_INFO_TYPE_ID_MASK;
847}
848
849static inline uint8_t ffa_boot_info_type(struct ffa_boot_info_desc *desc)
850{
851 return (desc->type & FFA_BOOT_INFO_TYPE_MASK) >>
852 FFA_BOOT_INFO_TYPE_SHIFT;
853}
854
855/** Length in bytes of the signature in the boot descriptor. */
856#define FFA_BOOT_INFO_HEADER_SIGNATURE_LEN 4
857
J-Alves240d84c2022-04-22 12:19:34 +0100858/**
859 * The FF-A boot information header, as defined in table 5.9 of section 5.4.2,
860 * of the FF-A v1.1 EAC0 specification.
861 */
J-Alvesdd1ad572022-01-25 17:58:26 +0000862struct ffa_boot_info_header {
863 uint32_t signature;
864 uint32_t version;
865 uint32_t info_blob_size;
866 uint32_t desc_size;
867 uint32_t desc_count;
868 uint32_t desc_offset;
869 uint64_t reserved;
870 struct ffa_boot_info_desc boot_info[];
871};
872
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100873/**
J-Alves980d1992021-03-18 12:49:18 +0000874 * FF-A v1.1 specification restricts the number of notifications to a maximum
875 * of 64. Following all possible bitmaps.
876 */
877#define FFA_NOTIFICATION_MASK(ID) (UINT64_C(1) << ID)
878
879typedef uint64_t ffa_notifications_bitmap_t;
880
881#define MAX_FFA_NOTIFICATIONS 64U
882
883/**
J-Alvesc003a7a2021-03-18 13:06:53 +0000884 * Flag for notification bind and set, to specify call is about per-vCPU
885 * notifications.
886 */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200887#define FFA_NOTIFICATION_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesc003a7a2021-03-18 13:06:53 +0000888
Federico Recanatie73d2832022-04-20 11:10:52 +0200889#define FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(0)
890#define FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(32)
891
892/**
893 * Helper functions to check for buffer full notification.
894 */
895static inline bool is_ffa_hyp_buffer_full_notification(
896 ffa_notifications_bitmap_t framework)
897{
898 return (framework & FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK) != 0;
899}
900
901static inline bool is_ffa_spm_buffer_full_notification(
902 ffa_notifications_bitmap_t framework)
903{
904 return (framework & FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK) != 0;
905}
906
J-Alvesc003a7a2021-03-18 13:06:53 +0000907/**
J-Alves980d1992021-03-18 12:49:18 +0000908 * Helper function to assemble a 64-bit sized bitmap, from the 32-bit sized lo
909 * and hi.
910 * Helpful as FF-A specification defines that the notifications interfaces
911 * arguments are 32-bit registers.
912 */
913static inline ffa_notifications_bitmap_t ffa_notifications_bitmap(uint32_t lo,
914 uint32_t hi)
915{
916 return (ffa_notifications_bitmap_t)hi << 32U | lo;
917}
918
J-Alves98ff9562021-09-09 14:39:41 +0100919static inline ffa_notifications_bitmap_t ffa_notification_get_from_sp(
920 struct ffa_value val)
921{
922 return ffa_notifications_bitmap((uint32_t)val.arg2, (uint32_t)val.arg3);
923}
924
925static inline ffa_notifications_bitmap_t ffa_notification_get_from_vm(
926 struct ffa_value val)
927{
928 return ffa_notifications_bitmap((uint32_t)val.arg4, (uint32_t)val.arg5);
929}
930
Federico Recanatie73d2832022-04-20 11:10:52 +0200931static inline ffa_notifications_bitmap_t ffa_notification_get_from_framework(
932 struct ffa_value val)
933{
934 return ffa_notifications_bitmap((uint32_t)val.arg6, (uint32_t)val.arg7);
935}
936
J-Alves980d1992021-03-18 12:49:18 +0000937/**
J-Alvesaa79c012021-07-09 14:29:45 +0100938 * Flags used in calls to FFA_NOTIFICATION_GET interface.
939 */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200940#define FFA_NOTIFICATION_FLAG_BITMAP_SP (UINT32_C(1) << 0)
941#define FFA_NOTIFICATION_FLAG_BITMAP_VM (UINT32_C(1) << 1)
942#define FFA_NOTIFICATION_FLAG_BITMAP_SPM (UINT32_C(1) << 2)
943#define FFA_NOTIFICATION_FLAG_BITMAP_HYP (UINT32_C(1) << 3)
J-Alvesaa79c012021-07-09 14:29:45 +0100944
J-Alvesa3755072021-11-26 16:01:08 +0000945/* Flag to configure notification as being per vCPU. */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200946#define FFA_NOTIFICATIONS_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesa3755072021-11-26 16:01:08 +0000947
J-Alves13394022021-06-30 13:48:49 +0100948/** Flag for FFA_NOTIFICATION_SET to delay Schedule Receiver Interrupt */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200949#define FFA_NOTIFICATIONS_FLAG_DELAY_SRI (UINT32_C(1) << 1)
950
951#define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) \
952 ((((uint32_t)(id)) & UINT32_C(0xffff)) << 16)
J-Alves13394022021-06-30 13:48:49 +0100953
J-Alvesbe6e3032021-11-30 14:54:12 +0000954static inline ffa_vcpu_index_t ffa_notifications_get_vcpu(struct ffa_value args)
J-Alvesaa79c012021-07-09 14:29:45 +0100955{
J-Alvesbe6e3032021-11-30 14:54:12 +0000956 return (ffa_vcpu_index_t)(args.arg1 >> 16 & 0xffffU);
J-Alvesaa79c012021-07-09 14:29:45 +0100957}
958
959/**
J-Alvesc8e8a222021-06-08 17:33:52 +0100960 * The max number of IDs for return of FFA_NOTIFICATION_INFO_GET.
961 */
962#define FFA_NOTIFICATIONS_INFO_GET_MAX_IDS 20U
963
964/**
965 * Number of registers to use in successfull return of interface
966 * FFA_NOTIFICATION_INFO_GET.
967 */
968#define FFA_NOTIFICATIONS_INFO_GET_REGS_RET 5U
969
970#define FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING 0x1U
971
972/**
973 * Helper macros for return parameter encoding as described in section 17.7.1
974 * of the FF-A v1.1 Beta0 specification.
975 */
976#define FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT 0x7U
977#define FFA_NOTIFICATIONS_LISTS_COUNT_MASK 0x1fU
978#define FFA_NOTIFICATIONS_LIST_SHIFT(l) (2 * (l - 1) + 12)
979#define FFA_NOTIFICATIONS_LIST_SIZE_MASK 0x3U
980
981static inline uint32_t ffa_notification_info_get_lists_count(
982 struct ffa_value args)
983{
984 return (uint32_t)(args.arg2 >> FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT) &
985 FFA_NOTIFICATIONS_LISTS_COUNT_MASK;
986}
987
988static inline uint32_t ffa_notification_info_get_list_size(
989 struct ffa_value args, unsigned int list_idx)
990{
991 return ((uint32_t)args.arg2 >> FFA_NOTIFICATIONS_LIST_SHIFT(list_idx)) &
992 FFA_NOTIFICATIONS_LIST_SIZE_MASK;
993}
994
995static inline bool ffa_notification_info_get_more_pending(struct ffa_value args)
996{
997 return (args.arg2 & FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING) != 0U;
998}
999
1000/**
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001001 * A set of contiguous pages which is part of a memory region. This corresponds
J-Alves0b6653d2022-04-22 13:17:38 +01001002 * to table 10.14 of the FF-A v1.1 EAC0 specification, "Constituent memory
1003 * region descriptor".
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001004 */
1005struct ffa_memory_region_constituent {
1006 /**
1007 * The base IPA of the constituent memory region, aligned to 4 kiB page
1008 * size granularity.
1009 */
1010 uint64_t address;
1011 /** The number of 4 kiB pages in the constituent memory region. */
1012 uint32_t page_count;
1013 /** Reserved field, must be 0. */
1014 uint32_t reserved;
1015};
1016
1017/**
J-Alves0b6653d2022-04-22 13:17:38 +01001018 * A set of pages comprising a memory region. This corresponds to table 10.13 of
1019 * the FF-A v1.1 EAC0 specification, "Composite memory region descriptor".
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001020 */
1021struct ffa_composite_memory_region {
1022 /**
1023 * The total number of 4 kiB pages included in this memory region. This
1024 * must be equal to the sum of page counts specified in each
1025 * `ffa_memory_region_constituent`.
1026 */
1027 uint32_t page_count;
1028 /**
1029 * The number of constituents (`ffa_memory_region_constituent`)
1030 * included in this memory region range.
1031 */
1032 uint32_t constituent_count;
1033 /** Reserved field, must be 0. */
1034 uint64_t reserved_0;
1035 /** An array of `constituent_count` memory region constituents. */
1036 struct ffa_memory_region_constituent constituents[];
1037};
1038
1039/** Flags to indicate properties of receivers during memory region retrieval. */
1040typedef uint8_t ffa_memory_receiver_flags_t;
1041
1042/**
J-Alves0b6653d2022-04-22 13:17:38 +01001043 * This corresponds to table 10.15 of the FF-A v1.1 EAC0 specification, "Memory
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001044 * access permissions descriptor".
1045 */
1046struct ffa_memory_region_attributes {
1047 /** The ID of the VM to which the memory is being given or shared. */
J-Alves19e20cf2023-08-02 12:48:55 +01001048 ffa_id_t receiver;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001049 /**
1050 * The permissions with which the memory region should be mapped in the
1051 * receiver's page table.
1052 */
1053 ffa_memory_access_permissions_t permissions;
1054 /**
1055 * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP
1056 * for memory regions with multiple borrowers.
1057 */
1058 ffa_memory_receiver_flags_t flags;
1059};
1060
1061/** Flags to control the behaviour of a memory sharing transaction. */
1062typedef uint32_t ffa_memory_region_flags_t;
1063
1064/**
1065 * Clear memory region contents after unmapping it from the sender and before
1066 * mapping it for any receiver.
1067 */
1068#define FFA_MEMORY_REGION_FLAG_CLEAR 0x1
1069
1070/**
1071 * Whether the hypervisor may time slice the memory sharing or retrieval
1072 * operation.
1073 */
1074#define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2
1075
1076/**
1077 * Whether the hypervisor should clear the memory region after the receiver
1078 * relinquishes it or is aborted.
1079 */
1080#define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4
1081
J-Alves3456e032023-07-20 12:20:05 +01001082/**
1083 * On retrieve request, bypass the multi-borrower check.
1084 */
1085#define FFA_MEMORY_REGION_FLAG_BYPASS_BORROWERS_CHECK (0x1U << 10)
1086
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001087#define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3)
1088#define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3)
1089#define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3)
1090#define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3)
1091#define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3)
1092
Federico Recanati85090c42021-12-15 13:17:54 +01001093#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_VALID ((0x1U) << 9)
1094#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_MASK ((0xFU) << 5)
1095
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001096/**
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001097 * Struct to store the impdef value seen in Table 11.16 of the
1098 * FF-A v1.2 ALP0 specification "Endpoint memory access descriptor".
1099 */
1100struct ffa_memory_access_impdef {
1101 uint64_t val[2];
1102};
1103
1104/**
J-Alves0b6653d2022-04-22 13:17:38 +01001105 * This corresponds to table 10.16 of the FF-A v1.1 EAC0 specification,
1106 * "Endpoint memory access descriptor".
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001107 */
1108struct ffa_memory_access {
1109 struct ffa_memory_region_attributes receiver_permissions;
1110 /**
1111 * Offset in bytes from the start of the outer `ffa_memory_region` to
1112 * an `ffa_composite_memory_region` struct.
1113 */
1114 uint32_t composite_memory_region_offset;
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001115 struct ffa_memory_access_impdef impdef;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001116 uint64_t reserved_0;
1117};
1118
J-Alves363f5722022-04-25 17:37:37 +01001119/** The maximum number of recipients a memory region may be sent to. */
J-Alvesba0e6172022-04-25 17:41:40 +01001120#define MAX_MEM_SHARE_RECIPIENTS UINT32_C(2)
J-Alves363f5722022-04-25 17:37:37 +01001121
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001122/**
1123 * Information about a set of pages which are being shared. This corresponds to
J-Alves0b6653d2022-04-22 13:17:38 +01001124 * table 10.20 of the FF-A v1.1 EAC0 specification, "Lend, donate or share
1125 * memory transaction descriptor". Note that it is also used for retrieve
1126 * requests and responses.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001127 */
1128struct ffa_memory_region {
1129 /**
1130 * The ID of the VM which originally sent the memory region, i.e. the
1131 * owner.
1132 */
J-Alves19e20cf2023-08-02 12:48:55 +01001133 ffa_id_t sender;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001134 ffa_memory_attributes_t attributes;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001135 /** Flags to control behaviour of the transaction. */
1136 ffa_memory_region_flags_t flags;
1137 ffa_memory_handle_t handle;
1138 /**
1139 * An implementation defined value associated with the receiver and the
1140 * memory region.
1141 */
1142 uint64_t tag;
J-Alves0b6653d2022-04-22 13:17:38 +01001143 /* Size of the memory access descriptor. */
1144 uint32_t memory_access_desc_size;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001145 /**
1146 * The number of `ffa_memory_access` entries included in this
1147 * transaction.
1148 */
1149 uint32_t receiver_count;
1150 /**
J-Alves0b6653d2022-04-22 13:17:38 +01001151 * Offset of the 'receivers' field, which relates to the memory access
1152 * descriptors.
1153 */
1154 uint32_t receivers_offset;
1155 /** Reserved field (12 bytes) must be 0. */
1156 uint32_t reserved[3];
1157 /**
Federico Recanati3ddf28e2021-12-20 09:40:26 +01001158 * An array of `receiver_count` endpoint memory access descriptors.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001159 * Each one specifies a memory region offset, an endpoint and the
1160 * attributes with which this memory region should be mapped in that
1161 * endpoint's page table.
1162 */
1163 struct ffa_memory_access receivers[];
1164};
1165
1166/**
1167 * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table
J-Alves0b6653d2022-04-22 13:17:38 +01001168 * 16.25 of the FF-A v1.1 EAC0 specification, "Descriptor to relinquish a memory
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001169 * region".
1170 */
1171struct ffa_mem_relinquish {
1172 ffa_memory_handle_t handle;
1173 ffa_memory_region_flags_t flags;
1174 uint32_t endpoint_count;
J-Alves19e20cf2023-08-02 12:48:55 +01001175 ffa_id_t endpoints[];
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001176};
1177
1178/**
Daniel Boulby59ffee92023-11-02 18:26:26 +00001179 * Returns the first FF-A version that matches the memory access descriptor
1180 * size.
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001181 */
1182uint32_t ffa_version_from_memory_access_desc_size(
1183 uint32_t memory_access_desc_size);
1184
1185/**
Daniel Boulbyc7dc9322023-10-27 15:12:07 +01001186 * Returns the first FF-A version that matches the memory access descriptor
1187 * size.
1188 */
1189uint32_t ffa_version_from_memory_access_desc_size(
1190 uint32_t memory_access_desc_size);
1191
1192/**
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001193 * To maintain forwards compatability we can't make assumptions about the size
1194 * of the endpoint memory access descriptor so provide a helper function
1195 * to get a receiver from the receiver array using the memory access descriptor
1196 * size field from the memory region descriptor struct.
1197 * Returns NULL if we cannot return the receiver.
1198 */
1199static inline struct ffa_memory_access *ffa_memory_region_get_receiver(
1200 struct ffa_memory_region *memory_region, uint32_t receiver_index)
1201{
1202 uint32_t memory_access_desc_size =
1203 memory_region->memory_access_desc_size;
1204
1205 if (receiver_index >= memory_region->receiver_count) {
1206 return NULL;
1207 }
1208
1209 /*
1210 * Memory access descriptor size cannot be greater than the size of
1211 * the memory access descriptor defined by the current FF-A version.
1212 */
1213 if (memory_access_desc_size > sizeof(struct ffa_memory_access)) {
1214 return NULL;
1215 }
1216
1217 return (struct ffa_memory_access *)((uint8_t *)
1218 memory_region->receivers +
1219 (receiver_index *
1220 memory_access_desc_size));
1221}
1222
1223/**
Daniel Boulby59ffee92023-11-02 18:26:26 +00001224 * Gets the receiver's access permissions from 'struct ffa_memory_region' and
1225 * returns its index in the receiver's array. If receiver's ID doesn't exist
1226 * in the array, return the region's 'receivers_count'.
1227 */
1228static inline uint32_t ffa_memory_region_get_receiver_index(
1229 struct ffa_memory_region *memory_region, ffa_id_t receiver_id)
1230{
1231 uint32_t i;
1232
1233 for (i = 0U; i < memory_region->receiver_count; i++) {
1234 struct ffa_memory_access *receiver =
1235 ffa_memory_region_get_receiver(memory_region, i);
1236 if (receiver->receiver_permissions.receiver == receiver_id) {
1237 break;
1238 }
1239 }
1240
1241 return i;
1242}
1243
1244/**
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001245 * Gets the `ffa_composite_memory_region` for the given receiver from an
1246 * `ffa_memory_region`, or NULL if it is not valid.
1247 */
1248static inline struct ffa_composite_memory_region *
1249ffa_memory_region_get_composite(struct ffa_memory_region *memory_region,
1250 uint32_t receiver_index)
1251{
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001252 struct ffa_memory_access *receiver =
1253 ffa_memory_region_get_receiver(memory_region, receiver_index);
1254 uint32_t offset;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001255
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001256 if (receiver == NULL) {
1257 return NULL;
1258 }
1259
1260 offset = receiver->composite_memory_region_offset;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001261 if (offset == 0) {
1262 return NULL;
1263 }
1264
1265 return (struct ffa_composite_memory_region *)((uint8_t *)memory_region +
1266 offset);
1267}
1268
1269static inline uint32_t ffa_mem_relinquish_init(
1270 struct ffa_mem_relinquish *relinquish_request,
1271 ffa_memory_handle_t handle, ffa_memory_region_flags_t flags,
J-Alves19e20cf2023-08-02 12:48:55 +01001272 ffa_id_t sender)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001273{
1274 relinquish_request->handle = handle;
1275 relinquish_request->flags = flags;
1276 relinquish_request->endpoint_count = 1;
1277 relinquish_request->endpoints[0] = sender;
J-Alves19e20cf2023-08-02 12:48:55 +01001278 return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_id_t);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001279}
1280
J-Alves126ab502022-09-29 11:37:33 +01001281void ffa_copy_memory_region_constituents(
1282 struct ffa_memory_region_constituent *dest,
1283 const struct ffa_memory_region_constituent *src);
1284
Federico Recanati392be392022-02-08 20:53:03 +01001285/**
1286 * Endpoint RX/TX descriptor, as defined by Table 13.27 in FF-A v1.1 EAC0.
1287 * It's used by the Hypervisor to describe the RX/TX buffers mapped by a VM
1288 * to the SPMC, in order to allow indirect messaging.
1289 */
1290struct ffa_endpoint_rx_tx_descriptor {
J-Alves19e20cf2023-08-02 12:48:55 +01001291 ffa_id_t endpoint_id;
Federico Recanati392be392022-02-08 20:53:03 +01001292 uint16_t reserved;
1293
1294 /*
1295 * 8-byte aligned offset from the base address of this descriptor to the
1296 * `ffa_composite_memory_region` describing the RX buffer.
1297 */
1298 uint32_t rx_offset;
1299
1300 /*
1301 * 8-byte aligned offset from the base address of this descriptor to the
1302 * `ffa_composite_memory_region` describing the TX buffer.
1303 */
1304 uint32_t tx_offset;
1305
1306 /* Pad to align on 16-byte boundary. */
1307 uint32_t pad;
1308};
1309
1310static inline struct ffa_composite_memory_region *
1311ffa_enpoint_get_rx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
1312{
1313 return (struct ffa_composite_memory_region *)((uintptr_t)desc +
1314 desc->rx_offset);
1315}
1316
1317static inline struct ffa_composite_memory_region *
1318ffa_enpoint_get_tx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
1319{
1320 return (struct ffa_composite_memory_region *)((uintptr_t)desc +
1321 desc->tx_offset);
1322}
1323
J-Alves2d8457f2022-10-05 11:06:41 +01001324void ffa_memory_region_init_header(struct ffa_memory_region *memory_region,
J-Alves19e20cf2023-08-02 12:48:55 +01001325 ffa_id_t sender,
J-Alves2d8457f2022-10-05 11:06:41 +01001326 ffa_memory_attributes_t attributes,
1327 ffa_memory_region_flags_t flags,
1328 ffa_memory_handle_t handle, uint32_t tag,
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001329 uint32_t receiver_count,
1330 uint32_t receiver_desc_size);
Daniel Boulby59ffee92023-11-02 18:26:26 +00001331void ffa_memory_access_init(struct ffa_memory_access *receiver,
1332 ffa_id_t receiver_id,
1333 enum ffa_data_access data_access,
1334 enum ffa_instruction_access instruction_access,
1335 ffa_memory_receiver_flags_t flags,
1336 struct ffa_memory_access_impdef *impdef_val);
J-Alves45085432022-04-22 16:19:20 +01001337uint32_t ffa_memory_region_init_single_receiver(
Andrew Walbranca808b12020-05-15 17:22:28 +01001338 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
J-Alves19e20cf2023-08-02 12:48:55 +01001339 ffa_id_t sender, ffa_id_t receiver,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001340 const struct ffa_memory_region_constituent constituents[],
1341 uint32_t constituent_count, uint32_t tag,
1342 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
1343 enum ffa_instruction_access instruction_access,
1344 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
Daniel Boulby59ffee92023-11-02 18:26:26 +00001345 enum ffa_memory_shareability shareability,
1346 struct ffa_memory_access_impdef *impdef_val, uint32_t *fragment_length,
Andrew Walbranca808b12020-05-15 17:22:28 +01001347 uint32_t *total_length);
J-Alvesf4eecf72022-07-20 16:05:34 +01001348uint32_t ffa_memory_region_init(
1349 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
J-Alves19e20cf2023-08-02 12:48:55 +01001350 ffa_id_t sender, struct ffa_memory_access receivers[],
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001351 uint32_t receiver_count, uint32_t receiver_desc_size,
J-Alvesf4eecf72022-07-20 16:05:34 +01001352 const struct ffa_memory_region_constituent constituents[],
1353 uint32_t constituent_count, uint32_t tag,
1354 ffa_memory_region_flags_t flags, enum ffa_memory_type type,
1355 enum ffa_memory_cacheability cacheability,
1356 enum ffa_memory_shareability shareability, uint32_t *fragment_length,
1357 uint32_t *total_length);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001358uint32_t ffa_memory_retrieve_request_init(
1359 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves19e20cf2023-08-02 12:48:55 +01001360 ffa_id_t sender, struct ffa_memory_access receivers[],
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001361 uint32_t receiver_count, uint32_t receiver_desc_size, uint32_t tag,
1362 ffa_memory_region_flags_t flags, enum ffa_memory_type type,
1363 enum ffa_memory_cacheability cacheability,
J-Alves9b24ed82022-08-04 13:12:45 +01001364 enum ffa_memory_shareability shareability);
1365uint32_t ffa_memory_retrieve_request_init_single_receiver(
1366 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves19e20cf2023-08-02 12:48:55 +01001367 ffa_id_t sender, ffa_id_t receiver, uint32_t tag,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001368 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
1369 enum ffa_instruction_access instruction_access,
1370 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
Daniel Boulby59ffee92023-11-02 18:26:26 +00001371 enum ffa_memory_shareability shareability,
1372 struct ffa_memory_access_impdef *impdef_val);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001373uint32_t ffa_memory_lender_retrieve_request_init(
1374 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves19e20cf2023-08-02 12:48:55 +01001375 ffa_id_t sender);
Andrew Walbranca808b12020-05-15 17:22:28 +01001376uint32_t ffa_memory_fragment_init(
1377 struct ffa_memory_region_constituent *fragment,
1378 size_t fragment_max_size,
1379 const struct ffa_memory_region_constituent constituents[],
1380 uint32_t constituent_count, uint32_t *fragment_length);
Federico Recanati392be392022-02-08 20:53:03 +01001381void ffa_endpoint_rx_tx_descriptor_init(
J-Alves19e20cf2023-08-02 12:48:55 +01001382 struct ffa_endpoint_rx_tx_descriptor *desc, ffa_id_t endpoint_id,
Federico Recanati392be392022-02-08 20:53:03 +01001383 uint64_t rx_address, uint64_t tx_address);