blob: 6494b52db2e6b9449339c7e67b910db705516c6f [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
Kathleen Capella087e5022023-09-07 18:04:15 -0400103#define FFA_MSG_SEND_DIRECT_RESP2_64 0xC400008E
Maksims Svecovs71b76702022-05-20 15:32:58 +0100104
Karl Meakinf51a35f2023-08-07 17:53:52 +0100105/**
106 * FF-A error codes.
107 * Don't forget to update `ffa_error_name` if you add a new one.
108 */
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100109#define FFA_NOT_SUPPORTED INT32_C(-1)
110#define FFA_INVALID_PARAMETERS INT32_C(-2)
111#define FFA_NO_MEMORY INT32_C(-3)
112#define FFA_BUSY INT32_C(-4)
113#define FFA_INTERRUPTED INT32_C(-5)
114#define FFA_DENIED INT32_C(-6)
115#define FFA_RETRY INT32_C(-7)
116#define FFA_ABORTED INT32_C(-8)
J-Alvesc8e8a222021-06-08 17:33:52 +0100117#define FFA_NO_DATA INT32_C(-9)
Kathleen Capellae4fe2962023-09-01 17:08:47 -0400118#define FFA_NOT_READY INT32_C(-10)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100119
120/* clang-format on */
121
Karl Meakinf51a35f2023-08-07 17:53:52 +0100122/* Return the name of the function identifier. */
123static inline const char *ffa_func_name(uint32_t func)
124{
125 switch (func) {
126 case FFA_ERROR_32:
127 return "FFA_ERROR_32";
128 case FFA_SUCCESS_32:
129 return "FFA_SUCCESS_32";
130 case FFA_SUCCESS_64:
131 return "FFA_SUCCESS_64";
132 case FFA_INTERRUPT_32:
133 return "FFA_INTERRUPT_32";
134 case FFA_VERSION_32:
135 return "FFA_VERSION_32";
136 case FFA_FEATURES_32:
137 return "FFA_FEATURES_32";
138 case FFA_RX_RELEASE_32:
139 return "FFA_RX_RELEASE_32";
140 case FFA_RXTX_MAP_32:
141 return "FFA_RXTX_MAP_32";
142 case FFA_RXTX_MAP_64:
143 return "FFA_RXTX_MAP_64";
144 case FFA_RXTX_UNMAP_32:
145 return "FFA_RXTX_UNMAP_32";
146 case FFA_PARTITION_INFO_GET_32:
147 return "FFA_PARTITION_INFO_GET_32";
148 case FFA_ID_GET_32:
149 return "FFA_ID_GET_32";
150 case FFA_MSG_POLL_32:
151 return "FFA_MSG_POLL_32";
152 case FFA_MSG_WAIT_32:
153 return "FFA_MSG_WAIT_32";
154 case FFA_YIELD_32:
155 return "FFA_YIELD_32";
156 case FFA_RUN_32:
157 return "FFA_RUN_32";
158 case FFA_MSG_SEND_32:
159 return "FFA_MSG_SEND_32";
160 case FFA_MSG_SEND_DIRECT_REQ_32:
161 return "FFA_MSG_SEND_DIRECT_REQ_32";
162 case FFA_MSG_SEND_DIRECT_REQ_64:
163 return "FFA_MSG_SEND_DIRECT_REQ_64";
164 case FFA_MSG_SEND_DIRECT_RESP_32:
165 return "FFA_MSG_SEND_DIRECT_RESP_32";
166 case FFA_MSG_SEND_DIRECT_RESP_64:
167 return "FFA_MSG_SEND_DIRECT_RESP_64";
168 case FFA_MEM_DONATE_32:
169 return "FFA_MEM_DONATE_32";
170 case FFA_MEM_LEND_32:
171 return "FFA_MEM_LEND_32";
172 case FFA_MEM_SHARE_32:
173 return "FFA_MEM_SHARE_32";
174 case FFA_MEM_RETRIEVE_REQ_32:
175 return "FFA_MEM_RETRIEVE_REQ_32";
176 case FFA_MEM_RETRIEVE_RESP_32:
177 return "FFA_MEM_RETRIEVE_RESP_32";
178 case FFA_MEM_RELINQUISH_32:
179 return "FFA_MEM_RELINQUISH_32";
180 case FFA_MEM_RECLAIM_32:
181 return "FFA_MEM_RECLAIM_32";
182 case FFA_MEM_FRAG_RX_32:
183 return "FFA_MEM_FRAG_RX_32";
184 case FFA_MEM_FRAG_TX_32:
185 return "FFA_MEM_FRAG_TX_32";
186 case FFA_NORMAL_WORLD_RESUME:
187 return "FFA_NORMAL_WORLD_RESUME";
188
189 /* FF-A v1.1 */
190 case FFA_NOTIFICATION_BITMAP_CREATE_32:
191 return "FFA_NOTIFICATION_BITMAP_CREATE_32";
192 case FFA_NOTIFICATION_BITMAP_DESTROY_32:
193 return "FFA_NOTIFICATION_BITMAP_DESTROY_32";
194 case FFA_NOTIFICATION_BIND_32:
195 return "FFA_NOTIFICATION_BIND_32";
196 case FFA_NOTIFICATION_UNBIND_32:
197 return "FFA_NOTIFICATION_UNBIND_32";
198 case FFA_NOTIFICATION_SET_32:
199 return "FFA_NOTIFICATION_SET_32";
200 case FFA_NOTIFICATION_GET_32:
201 return "FFA_NOTIFICATION_GET_32";
202 case FFA_NOTIFICATION_INFO_GET_64:
203 return "FFA_NOTIFICATION_INFO_GET_64";
204 case FFA_RX_ACQUIRE_32:
205 return "FFA_RX_ACQUIRE_32";
206 case FFA_SPM_ID_GET_32:
207 return "FFA_SPM_ID_GET_32";
208 case FFA_MSG_SEND2_32:
209 return "FFA_MSG_SEND2_32";
210 case FFA_SECONDARY_EP_REGISTER_64:
211 return "FFA_SECONDARY_EP_REGISTER_64";
212 case FFA_MEM_PERM_GET_32:
213 return "FFA_MEM_PERM_GET_32";
214 case FFA_MEM_PERM_SET_32:
215 return "FFA_MEM_PERM_SET_32";
216 case FFA_MEM_PERM_GET_64:
217 return "FFA_MEM_PERM_GET_64";
218 case FFA_MEM_PERM_SET_64:
219 return "FFA_MEM_PERM_SET_64";
220
221 /* Implementation-defined ABIs. */
222 case FFA_CONSOLE_LOG_32:
223 return "FFA_CONSOLE_LOG_32";
224 case FFA_CONSOLE_LOG_64:
225 return "FFA_CONSOLE_LOG_64";
226 case FFA_PARTITION_INFO_GET_REGS_64:
227 return "FFA_PARTITION_INFO_GET_REGS_64";
228 case FFA_EL3_INTR_HANDLE_32:
229 return "FFA_EL3_INTR_HANDLE_32";
230
231 default:
232 return "UNKNOWN";
233 }
234}
235
236/* Return the name of the error code. */
237static inline const char *ffa_error_name(int32_t error)
238{
239 switch (error) {
240 case FFA_NOT_SUPPORTED:
241 return "FFA_NOT_SUPPORTED";
242 case FFA_INVALID_PARAMETERS:
243 return "FFA_INVALID_PARAMETERS";
244 case FFA_NO_MEMORY:
245 return "FFA_NO_MEMORY";
246 case FFA_BUSY:
247 return "FFA_BUSY";
248 case FFA_INTERRUPTED:
249 return "FFA_INTERRUPTED";
250 case FFA_DENIED:
251 return "FFA_DENIED";
252 case FFA_RETRY:
253 return "FFA_RETRY";
254 case FFA_ABORTED:
255 return "FFA_ABORTED";
256 case FFA_NO_DATA:
257 return "FFA_NO_DATA";
258 default:
259 return "UNKNOWN";
260 }
261}
262
J-Alves6f72ca82021-11-01 12:34:58 +0000263/**
264 * FF-A Feature ID, to be used with interface FFA_FEATURES.
265 * As defined in the FF-A v1.1 Beta specification, table 13.10, in section
266 * 13.2.
267 */
268
Olivier Deprezb76307d2022-06-09 17:17:45 +0200269#define FFA_FEATURES_FUNC_ID_MASK (UINT32_C(1) << 31)
J-Alves6f72ca82021-11-01 12:34:58 +0000270#define FFA_FEATURES_FEATURE_ID_MASK UINT32_C(0x7F)
271
Karl Meakin34b8ae92023-01-13 13:33:07 +0000272/**
273 * Defined in Table 13.14 in the FF-A v.1.1 REL0 specification.
274 * Bits[31:2] and Bit[0] of input are reserved (must be zero).
275 * Bit[0]: dynamically allocated buffer support.
276 * Bit[1]: NS bit handling.
277 * Bit[2]: support for retrieval by hypervisor.
278 */
279#define FFA_FEATURES_MEM_RETRIEVE_REQ_BUFFER_SUPPORT 0
280#define FFA_FEATURES_MEM_RETRIEVE_REQ_NS_SUPPORT (UINT32_C(1) << 1)
281#define FFA_FEATURES_MEM_RETRIEVE_REQ_HYPERVISOR_SUPPORT (UINT32_C(1) << 2)
282#define FFA_FEATURES_MEM_RETRIEVE_REQ_MBZ_MASK \
283 (~(FFA_FEATURES_MEM_RETRIEVE_REQ_BUFFER_SUPPORT | \
284 FFA_FEATURES_MEM_RETRIEVE_REQ_NS_SUPPORT | \
285 FFA_FEATURES_MEM_RETRIEVE_REQ_HYPERVISOR_SUPPORT))
286
J-Alves6f72ca82021-11-01 12:34:58 +0000287/* Query interrupt ID of Notification Pending Interrupt. */
288#define FFA_FEATURE_NPI 0x1U
289
290/* Query interrupt ID of Schedule Receiver Interrupt. */
291#define FFA_FEATURE_SRI 0x2U
292
293/* Query interrupt ID of the Managed Exit Interrupt. */
294#define FFA_FEATURE_MEI 0x3U
295
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100296/* FF-A function specific constants. */
297#define FFA_MSG_RECV_BLOCK 0x1
298#define FFA_MSG_RECV_BLOCK_MASK 0x1
299
300#define FFA_MSG_SEND_NOTIFY 0x1
301#define FFA_MSG_SEND_NOTIFY_MASK 0x1
302
303#define FFA_MEM_RECLAIM_CLEAR 0x1
304
305#define FFA_SLEEP_INDEFINITE 0
306
Raghu Krishnamurthyea6d25f2021-09-14 15:27:06 -0700307#define FFA_MEM_PERM_RO UINT32_C(0x7)
308#define FFA_MEM_PERM_RW UINT32_C(0x5)
309#define FFA_MEM_PERM_RX UINT32_C(0x3)
310
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000311/*
Olivier Deprez013f4d62022-11-21 15:46:20 +0100312 * Defined in Table 13.34 in the FF-A v1.1 EAC0 specification.
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000313 * The Partition count flag is used by FFA_PARTITION_INFO_GET to specify
314 * if partition info descriptors should be returned or just the count.
315 */
Olivier Deprez013f4d62022-11-21 15:46:20 +0100316#define FFA_PARTITION_COUNT_FLAG UINT32_C(0x1)
317#define FFA_PARTITION_COUNT_FLAG_MASK (UINT32_C(0x1) << 0)
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000318
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100319/**
320 * For use where the FF-A specification refers explicitly to '4K pages'. Not to
321 * be confused with PAGE_SIZE, which is the translation granule Hafnium is
322 * configured to use.
323 */
J-Alves715d6232023-02-16 16:33:28 +0000324#define FFA_PAGE_SIZE ((size_t)4096)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100325
Federico Recanatifc0295e2022-02-08 19:37:39 +0100326/** The ID of a VM. These are assigned sequentially starting with an offset. */
J-Alves19e20cf2023-08-02 12:48:55 +0100327typedef uint16_t ffa_id_t;
Federico Recanatifc0295e2022-02-08 19:37:39 +0100328
329/**
J-Alves661e1b72023-08-02 13:39:40 +0100330 * The FF-A v1.2 ALP0, section 6.1 defines that partition IDs are split into two
331 * parts:
332 * - Bit15 -> partition type identifier.
333 * - b'0 -> ID relates to a VM ID.
334 * - b'1 -> ID relates to an SP ID.
335 */
336#define FFA_ID_MASK ((ffa_id_t)0x8000)
337#define FFA_VM_ID_MASK ((ffa_id_t)0x0000)
338
339/**
340 * Helper to check if FF-A ID is a VM ID, managed by the hypervisor.
341 */
342static inline bool ffa_is_vm_id(ffa_id_t id)
343{
344 return (FFA_ID_MASK & id) == FFA_VM_ID_MASK;
345}
346
347/**
Federico Recanatifc0295e2022-02-08 19:37:39 +0100348 * Partition message header as specified by table 6.2 from FF-A v1.1 EAC0
349 * specification.
350 */
351struct ffa_partition_rxtx_header {
352 uint32_t flags; /* MBZ */
353 uint32_t reserved;
354 /* Offset from the beginning of the buffer to the message payload. */
355 uint32_t offset;
356 /* Sender(Bits[31:16]) and Receiver(Bits[15:0]) endpoint IDs. */
357 uint32_t sender_receiver;
358 /* Size of message in buffer. */
359 uint32_t size;
360};
361
362#define FFA_RXTX_HEADER_SIZE sizeof(struct ffa_partition_rxtx_header)
363#define FFA_RXTX_SENDER_SHIFT (0x10U)
J-Alves70079932022-12-07 17:32:20 +0000364#define FFA_RXTX_ALLOCATOR_SHIFT 16
Federico Recanatifc0295e2022-02-08 19:37:39 +0100365
366static inline void ffa_rxtx_header_init(
J-Alves19e20cf2023-08-02 12:48:55 +0100367 ffa_id_t sender, ffa_id_t receiver, uint32_t size,
Federico Recanatifc0295e2022-02-08 19:37:39 +0100368 struct ffa_partition_rxtx_header *header)
369{
370 header->flags = 0;
371 header->reserved = 0;
372 header->offset = FFA_RXTX_HEADER_SIZE;
373 header->sender_receiver =
374 (uint32_t)(receiver | (sender << FFA_RXTX_SENDER_SHIFT));
375 header->size = size;
376}
377
J-Alves19e20cf2023-08-02 12:48:55 +0100378static inline ffa_id_t ffa_rxtx_header_sender(
Federico Recanatifc0295e2022-02-08 19:37:39 +0100379 const struct ffa_partition_rxtx_header *h)
380{
J-Alves19e20cf2023-08-02 12:48:55 +0100381 return (ffa_id_t)(h->sender_receiver >> FFA_RXTX_SENDER_SHIFT);
Federico Recanatifc0295e2022-02-08 19:37:39 +0100382}
383
J-Alves19e20cf2023-08-02 12:48:55 +0100384static inline ffa_id_t ffa_rxtx_header_receiver(
Federico Recanatifc0295e2022-02-08 19:37:39 +0100385 const struct ffa_partition_rxtx_header *h)
386{
J-Alves19e20cf2023-08-02 12:48:55 +0100387 return (ffa_id_t)(h->sender_receiver);
Federico Recanatifc0295e2022-02-08 19:37:39 +0100388}
389
390/* The maximum length possible for a single message. */
391#define FFA_PARTITION_MSG_PAYLOAD_MAX (HF_MAILBOX_SIZE - FFA_RXTX_HEADER_SIZE)
392
393struct ffa_partition_msg {
394 struct ffa_partition_rxtx_header header;
395 char payload[FFA_PARTITION_MSG_PAYLOAD_MAX];
396};
397
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100398/* The maximum length possible for a single message. */
399#define FFA_MSG_PAYLOAD_MAX HF_MAILBOX_SIZE
400
401enum ffa_data_access {
402 FFA_DATA_ACCESS_NOT_SPECIFIED,
403 FFA_DATA_ACCESS_RO,
404 FFA_DATA_ACCESS_RW,
405 FFA_DATA_ACCESS_RESERVED,
406};
407
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100408static inline const char *ffa_data_access_name(enum ffa_data_access data_access)
409{
410 switch (data_access) {
411 case FFA_DATA_ACCESS_NOT_SPECIFIED:
412 return "FFA_DATA_ACCESS_NOT_SPECIFIED";
413 case FFA_DATA_ACCESS_RO:
414 return "FFA_DATA_ACCESS_RO";
415 case FFA_DATA_ACCESS_RW:
416 return "FFA_DATA_ACCESS_RW";
417 case FFA_DATA_ACCESS_RESERVED:
418 return "FFA_DATA_ACCESS_RESERVED";
419 }
420}
421
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100422enum ffa_instruction_access {
423 FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED,
424 FFA_INSTRUCTION_ACCESS_NX,
425 FFA_INSTRUCTION_ACCESS_X,
426 FFA_INSTRUCTION_ACCESS_RESERVED,
427};
428
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100429static inline const char *ffa_instruction_access_name(
430 enum ffa_instruction_access instruction_access)
431{
432 switch (instruction_access) {
433 case FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED:
434 return "FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED";
435 case FFA_INSTRUCTION_ACCESS_NX:
436 return "FFA_INSTRUCTION_ACCESS_NX";
437 case FFA_INSTRUCTION_ACCESS_X:
438 return "FFA_INSTRUCTION_ACCESS_X";
439 case FFA_INSTRUCTION_ACCESS_RESERVED:
440 return "FFA_INSTRUCTION_ACCESS_RESERVED";
441 }
442}
443
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100444enum ffa_memory_type {
445 FFA_MEMORY_NOT_SPECIFIED_MEM,
446 FFA_MEMORY_DEVICE_MEM,
447 FFA_MEMORY_NORMAL_MEM,
448};
449
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100450static inline const char *ffa_memory_type_name(enum ffa_memory_type type)
451{
452 switch (type) {
453 case FFA_MEMORY_NOT_SPECIFIED_MEM:
454 return "FFA_MEMORY_NOT_SPECIFIED_MEM";
455 case FFA_MEMORY_DEVICE_MEM:
456 return "FFA_MEMORY_DEVICE_MEM";
457 case FFA_MEMORY_NORMAL_MEM:
458 return "FFA_MEMORY_NORMAL_MEM";
459 }
460}
461
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100462enum ffa_memory_cacheability {
463 FFA_MEMORY_CACHE_RESERVED = 0x0,
464 FFA_MEMORY_CACHE_NON_CACHEABLE = 0x1,
465 FFA_MEMORY_CACHE_RESERVED_1 = 0x2,
466 FFA_MEMORY_CACHE_WRITE_BACK = 0x3,
467 FFA_MEMORY_DEV_NGNRNE = 0x0,
468 FFA_MEMORY_DEV_NGNRE = 0x1,
469 FFA_MEMORY_DEV_NGRE = 0x2,
470 FFA_MEMORY_DEV_GRE = 0x3,
471};
472
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100473static inline const char *ffa_memory_cacheability_name(
474 enum ffa_memory_cacheability cacheability)
475{
476 switch (cacheability) {
477 case FFA_MEMORY_CACHE_RESERVED:
478 return "FFA_MEMORY_CACHE_RESERVED";
479 case FFA_MEMORY_CACHE_NON_CACHEABLE:
480 return "FFA_MEMORY_CACHE_NON_CACHEABLE";
481 case FFA_MEMORY_CACHE_RESERVED_1:
482 return "FFA_MEMORY_CACHE_RESERVED_1";
483 case FFA_MEMORY_CACHE_WRITE_BACK:
484 return "FFA_MEMORY_CACHE_WRITE_BACK";
485 }
486}
487
Daniel Boulby9764ff62024-01-30 17:47:39 +0000488static inline const char *ffa_device_memory_cacheability_name(
489 enum ffa_memory_cacheability cacheability)
490{
491 switch (cacheability) {
492 case FFA_MEMORY_DEV_NGNRNE:
493 return "FFA_MEMORY_DEV_NGNRNE";
494 case FFA_MEMORY_DEV_NGNRE:
495 return "FFA_MEMORY_DEV_NGNRE";
496 case FFA_MEMORY_DEV_NGRE:
497 return "FFA_MEMORY_DEV_NGRE";
498 case FFA_MEMORY_DEV_GRE:
499 return "FFA_MEMORY_DEV_GRE";
500 }
501}
502
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100503enum ffa_memory_shareability {
504 FFA_MEMORY_SHARE_NON_SHAREABLE,
505 FFA_MEMORY_SHARE_RESERVED,
506 FFA_MEMORY_OUTER_SHAREABLE,
507 FFA_MEMORY_INNER_SHAREABLE,
508};
509
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100510static inline const char *ffa_memory_shareability_name(
511 enum ffa_memory_shareability shareability)
512{
513 switch (shareability) {
514 case FFA_MEMORY_SHARE_NON_SHAREABLE:
515 return "FFA_MEMORY_SHARE_NON_SHAREABLE";
516 case FFA_MEMORY_SHARE_RESERVED:
517 return "FFA_MEMORY_SHARE_RESERVED";
518 case FFA_MEMORY_OUTER_SHAREABLE:
519 return "FFA_MEMORY_OUTER_SHAREABLE";
520 case FFA_MEMORY_INNER_SHAREABLE:
521 return "FFA_MEMORY_INNER_SHAREABLE";
522 }
523}
524
Olivier Deprez4342a3c2022-02-28 09:37:25 +0100525/**
526 * FF-A v1.1 REL0 Table 10.18 memory region attributes descriptor NS Bit 6.
527 * Per section 10.10.4.1, NS bit is reserved for FFA_MEM_DONATE/LEND/SHARE
528 * and FFA_MEM_RETRIEVE_REQUEST.
529 */
530enum ffa_memory_security {
531 FFA_MEMORY_SECURITY_UNSPECIFIED = 0,
532 FFA_MEMORY_SECURITY_SECURE = 0,
533 FFA_MEMORY_SECURITY_NON_SECURE,
534};
535
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100536static inline const char *ffa_memory_security_name(
537 enum ffa_memory_security security)
538{
539 switch (security) {
540 case FFA_MEMORY_SECURITY_UNSPECIFIED:
541 return "FFA_MEMORY_SECURITY_UNSPECIFIED";
542 case FFA_MEMORY_SECURITY_NON_SECURE:
543 return "FFA_MEMORY_SECURITY_NON_SECURE";
544 }
545}
546
Karl Meakin84710f32023-10-12 15:14:49 +0100547typedef struct {
548 uint8_t data_access : 2;
549 uint8_t instruction_access : 2;
550} ffa_memory_access_permissions_t;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100551
552/**
J-Alves0b6653d2022-04-22 13:17:38 +0100553 * This corresponds to table 10.18 of the FF-A v1.1 EAC0 specification, "Memory
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100554 * region attributes descriptor".
555 */
Karl Meakin84710f32023-10-12 15:14:49 +0100556typedef struct {
557 uint8_t shareability : 2;
558 uint8_t cacheability : 2;
559 uint8_t type : 2;
560 uint8_t security : 2;
561 uint8_t : 8;
562} ffa_memory_attributes_t;
J-Alves0b6653d2022-04-22 13:17:38 +0100563
564/* FF-A v1.1 EAC0 states bit [15:7] Must Be Zero. */
565#define FFA_MEMORY_ATTRIBUTES_MBZ_MASK 0xFF80U
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100566
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100567/**
568 * A globally-unique ID assigned by the hypervisor for a region of memory being
569 * sent between VMs.
570 */
571typedef uint64_t ffa_memory_handle_t;
572
J-Alves917d2f22020-10-30 18:39:30 +0000573#define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \
574 ((ffa_memory_handle_t)(UINT64_C(1) << 63))
575#define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR \
576 ((ffa_memory_handle_t)(UINT64_C(1) << 63))
577
578#define FFA_MEMORY_HANDLE_ALLOCATOR_SPMC (UINT64_C(0) << 63)
579#define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0))
580
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100581/**
582 * A count of VMs. This has the same range as the VM IDs but we give it a
583 * different name to make the different semantics clear.
584 */
J-Alves19e20cf2023-08-02 12:48:55 +0100585typedef ffa_id_t ffa_vm_count_t;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100586
587/** The index of a vCPU within a particular VM. */
588typedef uint16_t ffa_vcpu_index_t;
589
590/**
591 * A count of vCPUs. This has the same range as the vCPU indices but we give it
592 * a different name to make the different semantics clear.
593 */
594typedef ffa_vcpu_index_t ffa_vcpu_count_t;
595
596/** Parameter and return type of FF-A functions. */
597struct ffa_value {
598 uint64_t func;
599 uint64_t arg1;
600 uint64_t arg2;
601 uint64_t arg3;
602 uint64_t arg4;
603 uint64_t arg5;
604 uint64_t arg6;
605 uint64_t arg7;
Raghu Krishnamurthy567068e2022-12-26 07:46:38 -0800606
607 struct {
608 uint64_t arg8;
609 uint64_t arg9;
610 uint64_t arg10;
611 uint64_t arg11;
612 uint64_t arg12;
613 uint64_t arg13;
614 uint64_t arg14;
615 uint64_t arg15;
616 uint64_t arg16;
617 uint64_t arg17;
618 bool valid;
619 } extended_val;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100620};
621
Olivier Depreze562e542020-06-11 17:31:54 +0200622static inline uint32_t ffa_func_id(struct ffa_value args)
623{
624 return args.func;
625}
626
J-Alves13318e32021-02-22 17:21:00 +0000627static inline int32_t ffa_error_code(struct ffa_value val)
628{
629 return (int32_t)val.arg2;
630}
631
J-Alves19e20cf2023-08-02 12:48:55 +0100632static inline ffa_id_t ffa_sender(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100633{
634 return (args.arg1 >> 16) & 0xffff;
635}
636
J-Alves19e20cf2023-08-02 12:48:55 +0100637static inline ffa_id_t ffa_receiver(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100638{
639 return args.arg1 & 0xffff;
640}
641
642static inline uint32_t ffa_msg_send_size(struct ffa_value args)
643{
644 return args.arg3;
645}
646
Federico Recanati25053ee2022-03-14 15:01:53 +0100647static inline uint32_t ffa_msg_send2_flags(struct ffa_value args)
648{
649 return args.arg2;
650}
651
Olivier Depreze562e542020-06-11 17:31:54 +0200652static inline uint32_t ffa_partition_info_get_count(struct ffa_value args)
653{
654 return args.arg2;
655}
656
Raghu Krishnamurthy2957b922022-12-27 10:29:12 -0800657static inline uint16_t ffa_partition_info_regs_get_last_idx(
658 struct ffa_value args)
659{
660 return args.arg2 & 0xFFFF;
661}
662
663static inline uint16_t ffa_partition_info_regs_get_curr_idx(
664 struct ffa_value args)
665{
666 return (args.arg2 >> 16) & 0xFFFF;
667}
668
669static inline uint16_t ffa_partition_info_regs_get_tag(struct ffa_value args)
670{
671 return (args.arg2 >> 32) & 0xFFFF;
672}
673
674static inline uint16_t ffa_partition_info_regs_get_desc_size(
675 struct ffa_value args)
676{
677 return (args.arg2 >> 48);
678}
679
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100680static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t a1, uint32_t a2)
681{
682 return (uint64_t)a1 | (uint64_t)a2 << 32;
683}
684
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100685static inline ffa_memory_handle_t ffa_mem_success_handle(struct ffa_value args)
686{
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100687 return ffa_assemble_handle(args.arg2, args.arg3);
688}
689
Andrew Walbranca808b12020-05-15 17:22:28 +0100690static inline ffa_memory_handle_t ffa_frag_handle(struct ffa_value args)
691{
692 return ffa_assemble_handle(args.arg1, args.arg2);
693}
694
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100695static inline struct ffa_value ffa_mem_success(ffa_memory_handle_t handle)
696{
697 return (struct ffa_value){.func = FFA_SUCCESS_32,
698 .arg2 = (uint32_t)handle,
699 .arg3 = (uint32_t)(handle >> 32)};
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100700}
701
J-Alves19e20cf2023-08-02 12:48:55 +0100702static inline ffa_id_t ffa_vm_id(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100703{
704 return (args.arg1 >> 16) & 0xffff;
705}
706
707static inline ffa_vcpu_index_t ffa_vcpu_index(struct ffa_value args)
708{
709 return args.arg1 & 0xffff;
710}
711
J-Alves19e20cf2023-08-02 12:48:55 +0100712static inline uint64_t ffa_vm_vcpu(ffa_id_t vm_id, ffa_vcpu_index_t vcpu_index)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100713{
714 return ((uint32_t)vm_id << 16) | vcpu_index;
715}
716
J-Alves19e20cf2023-08-02 12:48:55 +0100717static inline ffa_id_t ffa_frag_sender(struct ffa_value args)
Andrew Walbranca808b12020-05-15 17:22:28 +0100718{
719 return (args.arg4 >> 16) & 0xffff;
720}
721
J-Alves6f72ca82021-11-01 12:34:58 +0000722static inline uint32_t ffa_feature_intid(struct ffa_value args)
723{
724 return (uint32_t)args.arg2;
725}
726
Daniel Boulbyefa381f2022-01-18 14:49:40 +0000727static inline uint32_t ffa_fwk_msg(struct ffa_value args)
728{
729 return (uint32_t)args.arg2;
730}
731
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100732/**
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100733 * Holds the UUID in a struct that is mappable directly to the SMCC calling
734 * convention, which is used for FF-A calls.
735 *
736 * Refer to table 84 of the FF-A 1.0 EAC specification as well as section 5.3
737 * of the SMCC Spec 1.2.
738 */
739struct ffa_uuid {
740 uint32_t uuid[4];
741};
742
743static inline void ffa_uuid_init(uint32_t w0, uint32_t w1, uint32_t w2,
744 uint32_t w3, struct ffa_uuid *uuid)
745{
746 uuid->uuid[0] = w0;
747 uuid->uuid[1] = w1;
748 uuid->uuid[2] = w2;
749 uuid->uuid[3] = w3;
750}
751
752static inline bool ffa_uuid_equal(const struct ffa_uuid *uuid1,
753 const struct ffa_uuid *uuid2)
754{
755 return (uuid1->uuid[0] == uuid2->uuid[0]) &&
756 (uuid1->uuid[1] == uuid2->uuid[1]) &&
757 (uuid1->uuid[2] == uuid2->uuid[2]) &&
758 (uuid1->uuid[3] == uuid2->uuid[3]);
759}
760
761static inline bool ffa_uuid_is_null(const struct ffa_uuid *uuid)
762{
763 return (uuid->uuid[0] == 0) && (uuid->uuid[1] == 0) &&
764 (uuid->uuid[2] == 0) && (uuid->uuid[3] == 0);
765}
766
Kathleen Capella41fea932023-06-23 17:39:28 -0400767static inline void ffa_uuid_unpack_from_uint64(uint64_t uuid_lo,
768 uint64_t uuid_hi,
769 struct ffa_uuid *uuid)
770{
771 ffa_uuid_init((uint32_t)(uuid_lo & 0xFFFFFFFFU),
772 (uint32_t)(uuid_lo >> 32),
773 (uint32_t)(uuid_hi & 0xFFFFFFFFU),
774 (uint32_t)(uuid_hi >> 32), uuid);
775}
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100776/**
777 * Flags to determine the partition properties, as required by
778 * FFA_PARTITION_INFO_GET.
779 *
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400780 * 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 +0100781 * specification, "Partition information descriptor, partition properties".
782 */
783typedef uint32_t ffa_partition_properties_t;
784
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400785/**
786 * Partition property: partition supports receipt of direct requests via the
787 * FFA_MSG_SEND_DIRECT_REQ ABI.
788 */
Kathleen Capella402fa852022-11-09 16:16:51 -0500789#define FFA_PARTITION_DIRECT_REQ_RECV (UINT32_C(1) << 0)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100790
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400791/**
792 * Partition property: partition can send direct requests via the
793 * FFA_MSG_SEND_DIRECT_REQ ABI.
794 */
Kathleen Capella402fa852022-11-09 16:16:51 -0500795#define FFA_PARTITION_DIRECT_REQ_SEND (UINT32_C(1) << 1)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100796
797/** Partition property: partition can send and receive indirect messages. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500798#define FFA_PARTITION_INDIRECT_MSG (UINT32_C(1) << 2)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100799
J-Alves09ff9d82021-11-02 11:55:20 +0000800/** Partition property: partition can receive notifications. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500801#define FFA_PARTITION_NOTIFICATION (UINT32_C(1) << 3)
802
803/** Partition property: partition runs in the AArch64 execution state. */
804#define FFA_PARTITION_AARCH64_EXEC (UINT32_C(1) << 8)
J-Alves09ff9d82021-11-02 11:55:20 +0000805
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100806/**
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400807 * Partition property: partition supports receipt of direct requests via the
808 * FFA_MSG_SEND_DIRECT_REQ2 ABI.
809 */
810#define FFA_PARTITION_DIRECT_REQ2_RECV (UINT32_C(1) << 9)
811
812/**
813 * Partition property: partition can send direct requests via the
814 * FFA_MSG_SEND_DIRECT_REQ2 ABI.
815 */
816#define FFA_PARTITION_DIRECT_REQ2_SEND (UINT32_C(1) << 10)
817
818/**
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100819 * Holds information returned for each partition by the FFA_PARTITION_INFO_GET
820 * interface.
Kathleen Capella402fa852022-11-09 16:16:51 -0500821 * This corresponds to table 13.37 "Partition information descriptor"
822 * in FF-A 1.1 EAC0 specification.
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000823 */
824struct ffa_partition_info {
J-Alves19e20cf2023-08-02 12:48:55 +0100825 ffa_id_t vm_id;
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000826 ffa_vcpu_count_t vcpu_count;
827 ffa_partition_properties_t properties;
828 struct ffa_uuid uuid;
829};
830
J-Alvesdd1ad572022-01-25 17:58:26 +0000831/** Length in bytes of the name in boot information descriptor. */
832#define FFA_BOOT_INFO_NAME_LEN 16
833
J-Alves240d84c2022-04-22 12:19:34 +0100834/**
835 * The FF-A boot info descriptor, as defined in table 5.8 of section 5.4.1, of
836 * the FF-A v1.1 EAC0 specification.
837 */
J-Alvesdd1ad572022-01-25 17:58:26 +0000838struct ffa_boot_info_desc {
839 char name[FFA_BOOT_INFO_NAME_LEN];
840 uint8_t type;
841 uint8_t reserved;
842 uint16_t flags;
843 uint32_t size;
844 uint64_t content;
845};
846
847/** FF-A boot information type mask. */
848#define FFA_BOOT_INFO_TYPE_SHIFT 7
849#define FFA_BOOT_INFO_TYPE_MASK (0x1U << FFA_BOOT_INFO_TYPE_SHIFT)
850#define FFA_BOOT_INFO_TYPE_STD 0U
851#define FFA_BOOT_INFO_TYPE_IMPDEF 1U
852
853/** Standard boot info type IDs. */
854#define FFA_BOOT_INFO_TYPE_ID_MASK 0x7FU
855#define FFA_BOOT_INFO_TYPE_ID_FDT 0U
856#define FFA_BOOT_INFO_TYPE_ID_HOB 1U
857
858/** FF-A Boot Info descriptors flags. */
859#define FFA_BOOT_INFO_FLAG_MBZ_MASK 0xFFF0U
860
861/** Bits [1:0] encode the format of the name field in ffa_boot_info_desc. */
862#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT 0U
863#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK \
864 (0x3U << FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT)
865#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING 0x0U
866#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID 0x1U
867
868/** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */
869#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT 2
870#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK \
871 (0x3U << FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT)
872#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE 0x1U
873#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR 0x0U
874
875static inline uint16_t ffa_boot_info_content_format(
876 struct ffa_boot_info_desc *desc)
877{
878 return (desc->flags & FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK) >>
879 FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT;
880}
881
882static inline uint16_t ffa_boot_info_name_format(
883 struct ffa_boot_info_desc *desc)
884{
885 return (desc->flags & FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK) >>
886 FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT;
887}
888
889static inline uint8_t ffa_boot_info_type_id(struct ffa_boot_info_desc *desc)
890{
891 return desc->type & FFA_BOOT_INFO_TYPE_ID_MASK;
892}
893
894static inline uint8_t ffa_boot_info_type(struct ffa_boot_info_desc *desc)
895{
896 return (desc->type & FFA_BOOT_INFO_TYPE_MASK) >>
897 FFA_BOOT_INFO_TYPE_SHIFT;
898}
899
900/** Length in bytes of the signature in the boot descriptor. */
901#define FFA_BOOT_INFO_HEADER_SIGNATURE_LEN 4
902
J-Alves240d84c2022-04-22 12:19:34 +0100903/**
904 * The FF-A boot information header, as defined in table 5.9 of section 5.4.2,
905 * of the FF-A v1.1 EAC0 specification.
906 */
J-Alvesdd1ad572022-01-25 17:58:26 +0000907struct ffa_boot_info_header {
908 uint32_t signature;
909 uint32_t version;
910 uint32_t info_blob_size;
911 uint32_t desc_size;
912 uint32_t desc_count;
913 uint32_t desc_offset;
914 uint64_t reserved;
915 struct ffa_boot_info_desc boot_info[];
916};
917
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100918/**
J-Alves980d1992021-03-18 12:49:18 +0000919 * FF-A v1.1 specification restricts the number of notifications to a maximum
920 * of 64. Following all possible bitmaps.
921 */
922#define FFA_NOTIFICATION_MASK(ID) (UINT64_C(1) << ID)
923
924typedef uint64_t ffa_notifications_bitmap_t;
925
926#define MAX_FFA_NOTIFICATIONS 64U
927
928/**
J-Alvesc003a7a2021-03-18 13:06:53 +0000929 * Flag for notification bind and set, to specify call is about per-vCPU
930 * notifications.
931 */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200932#define FFA_NOTIFICATION_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesc003a7a2021-03-18 13:06:53 +0000933
Federico Recanatie73d2832022-04-20 11:10:52 +0200934#define FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(0)
935#define FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(32)
936
937/**
938 * Helper functions to check for buffer full notification.
939 */
940static inline bool is_ffa_hyp_buffer_full_notification(
941 ffa_notifications_bitmap_t framework)
942{
943 return (framework & FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK) != 0;
944}
945
946static inline bool is_ffa_spm_buffer_full_notification(
947 ffa_notifications_bitmap_t framework)
948{
949 return (framework & FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK) != 0;
950}
951
J-Alvesc003a7a2021-03-18 13:06:53 +0000952/**
J-Alves980d1992021-03-18 12:49:18 +0000953 * Helper function to assemble a 64-bit sized bitmap, from the 32-bit sized lo
954 * and hi.
955 * Helpful as FF-A specification defines that the notifications interfaces
956 * arguments are 32-bit registers.
957 */
958static inline ffa_notifications_bitmap_t ffa_notifications_bitmap(uint32_t lo,
959 uint32_t hi)
960{
961 return (ffa_notifications_bitmap_t)hi << 32U | lo;
962}
963
J-Alves98ff9562021-09-09 14:39:41 +0100964static inline ffa_notifications_bitmap_t ffa_notification_get_from_sp(
965 struct ffa_value val)
966{
967 return ffa_notifications_bitmap((uint32_t)val.arg2, (uint32_t)val.arg3);
968}
969
970static inline ffa_notifications_bitmap_t ffa_notification_get_from_vm(
971 struct ffa_value val)
972{
973 return ffa_notifications_bitmap((uint32_t)val.arg4, (uint32_t)val.arg5);
974}
975
Federico Recanatie73d2832022-04-20 11:10:52 +0200976static inline ffa_notifications_bitmap_t ffa_notification_get_from_framework(
977 struct ffa_value val)
978{
979 return ffa_notifications_bitmap((uint32_t)val.arg6, (uint32_t)val.arg7);
980}
981
J-Alves980d1992021-03-18 12:49:18 +0000982/**
J-Alvesaa79c012021-07-09 14:29:45 +0100983 * Flags used in calls to FFA_NOTIFICATION_GET interface.
984 */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200985#define FFA_NOTIFICATION_FLAG_BITMAP_SP (UINT32_C(1) << 0)
986#define FFA_NOTIFICATION_FLAG_BITMAP_VM (UINT32_C(1) << 1)
987#define FFA_NOTIFICATION_FLAG_BITMAP_SPM (UINT32_C(1) << 2)
988#define FFA_NOTIFICATION_FLAG_BITMAP_HYP (UINT32_C(1) << 3)
J-Alvesaa79c012021-07-09 14:29:45 +0100989
J-Alvesa3755072021-11-26 16:01:08 +0000990/* Flag to configure notification as being per vCPU. */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200991#define FFA_NOTIFICATIONS_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesa3755072021-11-26 16:01:08 +0000992
J-Alves13394022021-06-30 13:48:49 +0100993/** Flag for FFA_NOTIFICATION_SET to delay Schedule Receiver Interrupt */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200994#define FFA_NOTIFICATIONS_FLAG_DELAY_SRI (UINT32_C(1) << 1)
995
996#define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) \
997 ((((uint32_t)(id)) & UINT32_C(0xffff)) << 16)
J-Alves13394022021-06-30 13:48:49 +0100998
J-Alvesbe6e3032021-11-30 14:54:12 +0000999static inline ffa_vcpu_index_t ffa_notifications_get_vcpu(struct ffa_value args)
J-Alvesaa79c012021-07-09 14:29:45 +01001000{
J-Alvesbe6e3032021-11-30 14:54:12 +00001001 return (ffa_vcpu_index_t)(args.arg1 >> 16 & 0xffffU);
J-Alvesaa79c012021-07-09 14:29:45 +01001002}
1003
1004/**
J-Alvesc8e8a222021-06-08 17:33:52 +01001005 * The max number of IDs for return of FFA_NOTIFICATION_INFO_GET.
1006 */
1007#define FFA_NOTIFICATIONS_INFO_GET_MAX_IDS 20U
1008
1009/**
1010 * Number of registers to use in successfull return of interface
1011 * FFA_NOTIFICATION_INFO_GET.
1012 */
1013#define FFA_NOTIFICATIONS_INFO_GET_REGS_RET 5U
1014
1015#define FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING 0x1U
1016
1017/**
1018 * Helper macros for return parameter encoding as described in section 17.7.1
1019 * of the FF-A v1.1 Beta0 specification.
1020 */
1021#define FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT 0x7U
1022#define FFA_NOTIFICATIONS_LISTS_COUNT_MASK 0x1fU
1023#define FFA_NOTIFICATIONS_LIST_SHIFT(l) (2 * (l - 1) + 12)
1024#define FFA_NOTIFICATIONS_LIST_SIZE_MASK 0x3U
1025
1026static inline uint32_t ffa_notification_info_get_lists_count(
1027 struct ffa_value args)
1028{
1029 return (uint32_t)(args.arg2 >> FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT) &
1030 FFA_NOTIFICATIONS_LISTS_COUNT_MASK;
1031}
1032
1033static inline uint32_t ffa_notification_info_get_list_size(
1034 struct ffa_value args, unsigned int list_idx)
1035{
1036 return ((uint32_t)args.arg2 >> FFA_NOTIFICATIONS_LIST_SHIFT(list_idx)) &
1037 FFA_NOTIFICATIONS_LIST_SIZE_MASK;
1038}
1039
1040static inline bool ffa_notification_info_get_more_pending(struct ffa_value args)
1041{
1042 return (args.arg2 & FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING) != 0U;
1043}
1044
1045/**
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001046 * A set of contiguous pages which is part of a memory region. This corresponds
J-Alves0b6653d2022-04-22 13:17:38 +01001047 * to table 10.14 of the FF-A v1.1 EAC0 specification, "Constituent memory
1048 * region descriptor".
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001049 */
1050struct ffa_memory_region_constituent {
1051 /**
1052 * The base IPA of the constituent memory region, aligned to 4 kiB page
1053 * size granularity.
1054 */
1055 uint64_t address;
1056 /** The number of 4 kiB pages in the constituent memory region. */
1057 uint32_t page_count;
1058 /** Reserved field, must be 0. */
1059 uint32_t reserved;
1060};
1061
1062/**
J-Alves0b6653d2022-04-22 13:17:38 +01001063 * A set of pages comprising a memory region. This corresponds to table 10.13 of
1064 * the FF-A v1.1 EAC0 specification, "Composite memory region descriptor".
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001065 */
1066struct ffa_composite_memory_region {
1067 /**
1068 * The total number of 4 kiB pages included in this memory region. This
1069 * must be equal to the sum of page counts specified in each
1070 * `ffa_memory_region_constituent`.
1071 */
1072 uint32_t page_count;
1073 /**
1074 * The number of constituents (`ffa_memory_region_constituent`)
1075 * included in this memory region range.
1076 */
1077 uint32_t constituent_count;
1078 /** Reserved field, must be 0. */
1079 uint64_t reserved_0;
1080 /** An array of `constituent_count` memory region constituents. */
1081 struct ffa_memory_region_constituent constituents[];
1082};
1083
1084/** Flags to indicate properties of receivers during memory region retrieval. */
1085typedef uint8_t ffa_memory_receiver_flags_t;
1086
1087/**
J-Alves0b6653d2022-04-22 13:17:38 +01001088 * This corresponds to table 10.15 of the FF-A v1.1 EAC0 specification, "Memory
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001089 * access permissions descriptor".
1090 */
1091struct ffa_memory_region_attributes {
1092 /** The ID of the VM to which the memory is being given or shared. */
J-Alves19e20cf2023-08-02 12:48:55 +01001093 ffa_id_t receiver;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001094 /**
1095 * The permissions with which the memory region should be mapped in the
1096 * receiver's page table.
1097 */
1098 ffa_memory_access_permissions_t permissions;
1099 /**
1100 * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP
1101 * for memory regions with multiple borrowers.
1102 */
1103 ffa_memory_receiver_flags_t flags;
1104};
1105
1106/** Flags to control the behaviour of a memory sharing transaction. */
1107typedef uint32_t ffa_memory_region_flags_t;
1108
1109/**
1110 * Clear memory region contents after unmapping it from the sender and before
1111 * mapping it for any receiver.
1112 */
1113#define FFA_MEMORY_REGION_FLAG_CLEAR 0x1
1114
1115/**
1116 * Whether the hypervisor may time slice the memory sharing or retrieval
1117 * operation.
1118 */
1119#define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2
1120
1121/**
1122 * Whether the hypervisor should clear the memory region after the receiver
1123 * relinquishes it or is aborted.
1124 */
1125#define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4
1126
J-Alves3456e032023-07-20 12:20:05 +01001127/**
1128 * On retrieve request, bypass the multi-borrower check.
1129 */
1130#define FFA_MEMORY_REGION_FLAG_BYPASS_BORROWERS_CHECK (0x1U << 10)
1131
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001132#define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3)
1133#define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3)
1134#define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3)
1135#define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3)
1136#define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3)
1137
Federico Recanati85090c42021-12-15 13:17:54 +01001138#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_VALID ((0x1U) << 9)
1139#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_MASK ((0xFU) << 5)
1140
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001141/**
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001142 * Struct to store the impdef value seen in Table 11.16 of the
1143 * FF-A v1.2 ALP0 specification "Endpoint memory access descriptor".
1144 */
1145struct ffa_memory_access_impdef {
1146 uint64_t val[2];
1147};
1148
Daniel Boulbye0ca9a02024-03-05 18:40:59 +00001149static inline struct ffa_memory_access_impdef ffa_memory_access_impdef_init(
1150 uint64_t impdef_hi, uint64_t impdef_lo)
1151{
1152 return (struct ffa_memory_access_impdef){{impdef_hi, impdef_lo}};
1153}
1154
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001155/**
J-Alves0b6653d2022-04-22 13:17:38 +01001156 * This corresponds to table 10.16 of the FF-A v1.1 EAC0 specification,
1157 * "Endpoint memory access descriptor".
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001158 */
1159struct ffa_memory_access {
1160 struct ffa_memory_region_attributes receiver_permissions;
1161 /**
1162 * Offset in bytes from the start of the outer `ffa_memory_region` to
1163 * an `ffa_composite_memory_region` struct.
1164 */
1165 uint32_t composite_memory_region_offset;
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001166 struct ffa_memory_access_impdef impdef;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001167 uint64_t reserved_0;
1168};
1169
J-Alves363f5722022-04-25 17:37:37 +01001170/** The maximum number of recipients a memory region may be sent to. */
J-Alvesba0e6172022-04-25 17:41:40 +01001171#define MAX_MEM_SHARE_RECIPIENTS UINT32_C(2)
J-Alves363f5722022-04-25 17:37:37 +01001172
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001173/**
1174 * Information about a set of pages which are being shared. This corresponds to
J-Alves0b6653d2022-04-22 13:17:38 +01001175 * table 10.20 of the FF-A v1.1 EAC0 specification, "Lend, donate or share
1176 * memory transaction descriptor". Note that it is also used for retrieve
1177 * requests and responses.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001178 */
1179struct ffa_memory_region {
1180 /**
1181 * The ID of the VM which originally sent the memory region, i.e. the
1182 * owner.
1183 */
J-Alves19e20cf2023-08-02 12:48:55 +01001184 ffa_id_t sender;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001185 ffa_memory_attributes_t attributes;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001186 /** Flags to control behaviour of the transaction. */
1187 ffa_memory_region_flags_t flags;
1188 ffa_memory_handle_t handle;
1189 /**
1190 * An implementation defined value associated with the receiver and the
1191 * memory region.
1192 */
1193 uint64_t tag;
J-Alves0b6653d2022-04-22 13:17:38 +01001194 /* Size of the memory access descriptor. */
1195 uint32_t memory_access_desc_size;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001196 /**
1197 * The number of `ffa_memory_access` entries included in this
1198 * transaction.
1199 */
1200 uint32_t receiver_count;
1201 /**
J-Alves0b6653d2022-04-22 13:17:38 +01001202 * Offset of the 'receivers' field, which relates to the memory access
1203 * descriptors.
1204 */
1205 uint32_t receivers_offset;
1206 /** Reserved field (12 bytes) must be 0. */
1207 uint32_t reserved[3];
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001208};
1209
1210/**
1211 * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table
J-Alves0b6653d2022-04-22 13:17:38 +01001212 * 16.25 of the FF-A v1.1 EAC0 specification, "Descriptor to relinquish a memory
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001213 * region".
1214 */
1215struct ffa_mem_relinquish {
1216 ffa_memory_handle_t handle;
1217 ffa_memory_region_flags_t flags;
1218 uint32_t endpoint_count;
J-Alves19e20cf2023-08-02 12:48:55 +01001219 ffa_id_t endpoints[];
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001220};
1221
1222/**
Daniel Boulby59ffee92023-11-02 18:26:26 +00001223 * Returns the first FF-A version that matches the memory access descriptor
1224 * size.
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001225 */
1226uint32_t ffa_version_from_memory_access_desc_size(
1227 uint32_t memory_access_desc_size);
1228
1229/**
Daniel Boulbyc7dc9322023-10-27 15:12:07 +01001230 * Returns the first FF-A version that matches the memory access descriptor
1231 * size.
1232 */
1233uint32_t ffa_version_from_memory_access_desc_size(
1234 uint32_t memory_access_desc_size);
1235
1236/**
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001237 * To maintain forwards compatability we can't make assumptions about the size
1238 * of the endpoint memory access descriptor so provide a helper function
1239 * to get a receiver from the receiver array using the memory access descriptor
1240 * size field from the memory region descriptor struct.
1241 * Returns NULL if we cannot return the receiver.
1242 */
1243static inline struct ffa_memory_access *ffa_memory_region_get_receiver(
1244 struct ffa_memory_region *memory_region, uint32_t receiver_index)
1245{
1246 uint32_t memory_access_desc_size =
1247 memory_region->memory_access_desc_size;
1248
1249 if (receiver_index >= memory_region->receiver_count) {
1250 return NULL;
1251 }
1252
1253 /*
1254 * Memory access descriptor size cannot be greater than the size of
1255 * the memory access descriptor defined by the current FF-A version.
1256 */
1257 if (memory_access_desc_size > sizeof(struct ffa_memory_access)) {
1258 return NULL;
1259 }
1260
Daniel Boulby41ef8ba2023-10-13 17:01:22 +01001261 /* Check we cannot use receivers offset to cause overflow. */
1262 if (memory_region->receivers_offset !=
1263 sizeof(struct ffa_memory_region)) {
1264 return NULL;
1265 }
1266
1267 return (struct ffa_memory_access *)((uint8_t *)memory_region +
1268 memory_region->receivers_offset +
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001269 (receiver_index *
1270 memory_access_desc_size));
1271}
1272
1273/**
Daniel Boulby59ffee92023-11-02 18:26:26 +00001274 * Gets the receiver's access permissions from 'struct ffa_memory_region' and
1275 * returns its index in the receiver's array. If receiver's ID doesn't exist
1276 * in the array, return the region's 'receivers_count'.
1277 */
1278static inline uint32_t ffa_memory_region_get_receiver_index(
1279 struct ffa_memory_region *memory_region, ffa_id_t receiver_id)
1280{
1281 uint32_t i;
1282
1283 for (i = 0U; i < memory_region->receiver_count; i++) {
1284 struct ffa_memory_access *receiver =
1285 ffa_memory_region_get_receiver(memory_region, i);
1286 if (receiver->receiver_permissions.receiver == receiver_id) {
1287 break;
1288 }
1289 }
1290
1291 return i;
1292}
1293
1294/**
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001295 * Gets the `ffa_composite_memory_region` for the given receiver from an
1296 * `ffa_memory_region`, or NULL if it is not valid.
1297 */
1298static inline struct ffa_composite_memory_region *
1299ffa_memory_region_get_composite(struct ffa_memory_region *memory_region,
1300 uint32_t receiver_index)
1301{
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001302 struct ffa_memory_access *receiver =
1303 ffa_memory_region_get_receiver(memory_region, receiver_index);
1304 uint32_t offset;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001305
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001306 if (receiver == NULL) {
1307 return NULL;
1308 }
1309
1310 offset = receiver->composite_memory_region_offset;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001311 if (offset == 0) {
1312 return NULL;
1313 }
1314
1315 return (struct ffa_composite_memory_region *)((uint8_t *)memory_region +
1316 offset);
1317}
1318
1319static inline uint32_t ffa_mem_relinquish_init(
1320 struct ffa_mem_relinquish *relinquish_request,
1321 ffa_memory_handle_t handle, ffa_memory_region_flags_t flags,
J-Alves19e20cf2023-08-02 12:48:55 +01001322 ffa_id_t sender)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001323{
1324 relinquish_request->handle = handle;
1325 relinquish_request->flags = flags;
1326 relinquish_request->endpoint_count = 1;
1327 relinquish_request->endpoints[0] = sender;
J-Alves19e20cf2023-08-02 12:48:55 +01001328 return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_id_t);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001329}
1330
J-Alves126ab502022-09-29 11:37:33 +01001331void ffa_copy_memory_region_constituents(
1332 struct ffa_memory_region_constituent *dest,
1333 const struct ffa_memory_region_constituent *src);
1334
Karl Meakin0fd67292024-02-06 17:33:05 +00001335struct ffa_features_rxtx_map_params {
1336 /*
1337 * Bit[0:1]:
1338 * Minimum buffer size and alignment boundary:
1339 * 0b00: 4K
1340 * 0b01: 64K
1341 * 0b10: 16K
1342 * 0b11: Reserved
1343 */
1344 uint8_t min_buf_size : 2;
1345 /*
1346 * Bit[2:15]:
1347 * Reserved (MBZ)
1348 */
1349 uint16_t mbz : 14;
1350 /*
1351 * Bit[16:32]:
1352 * Maximum buffer size in number of pages
1353 * Only present on version 1.2 or later
1354 */
1355 uint16_t max_buf_size : 16;
1356};
1357
1358#define FFA_RXTX_MAP_MIN_BUF_4K 0
1359#define FFA_RXTX_MAP_MAX_BUF_PAGE_COUNT 1
1360
Karl Meakinf7861302024-02-20 14:39:33 +00001361static inline struct ffa_features_rxtx_map_params ffa_features_rxtx_map_params(
1362 struct ffa_value args)
1363{
1364 struct ffa_features_rxtx_map_params params;
1365 uint32_t arg2 = args.arg2;
1366
1367 params = *(struct ffa_features_rxtx_map_params *)(&arg2);
1368
1369 return params;
1370}
1371
Federico Recanati392be392022-02-08 20:53:03 +01001372/**
1373 * Endpoint RX/TX descriptor, as defined by Table 13.27 in FF-A v1.1 EAC0.
1374 * It's used by the Hypervisor to describe the RX/TX buffers mapped by a VM
1375 * to the SPMC, in order to allow indirect messaging.
1376 */
1377struct ffa_endpoint_rx_tx_descriptor {
J-Alves19e20cf2023-08-02 12:48:55 +01001378 ffa_id_t endpoint_id;
Federico Recanati392be392022-02-08 20:53:03 +01001379 uint16_t reserved;
1380
1381 /*
1382 * 8-byte aligned offset from the base address of this descriptor to the
1383 * `ffa_composite_memory_region` describing the RX buffer.
1384 */
1385 uint32_t rx_offset;
1386
1387 /*
1388 * 8-byte aligned offset from the base address of this descriptor to the
1389 * `ffa_composite_memory_region` describing the TX buffer.
1390 */
1391 uint32_t tx_offset;
1392
1393 /* Pad to align on 16-byte boundary. */
1394 uint32_t pad;
1395};
1396
1397static inline struct ffa_composite_memory_region *
Karl Meakinb9705e22024-04-05 13:58:28 +01001398ffa_endpoint_get_rx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
Federico Recanati392be392022-02-08 20:53:03 +01001399{
1400 return (struct ffa_composite_memory_region *)((uintptr_t)desc +
1401 desc->rx_offset);
1402}
1403
1404static inline struct ffa_composite_memory_region *
Karl Meakinb9705e22024-04-05 13:58:28 +01001405ffa_endpoint_get_tx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
Federico Recanati392be392022-02-08 20:53:03 +01001406{
1407 return (struct ffa_composite_memory_region *)((uintptr_t)desc +
1408 desc->tx_offset);
1409}
1410
J-Alves2d8457f2022-10-05 11:06:41 +01001411void ffa_memory_region_init_header(struct ffa_memory_region *memory_region,
J-Alves19e20cf2023-08-02 12:48:55 +01001412 ffa_id_t sender,
J-Alves2d8457f2022-10-05 11:06:41 +01001413 ffa_memory_attributes_t attributes,
1414 ffa_memory_region_flags_t flags,
1415 ffa_memory_handle_t handle, uint32_t tag,
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001416 uint32_t receiver_count,
1417 uint32_t receiver_desc_size);
Daniel Boulby59ffee92023-11-02 18:26:26 +00001418void ffa_memory_access_init(struct ffa_memory_access *receiver,
1419 ffa_id_t receiver_id,
1420 enum ffa_data_access data_access,
1421 enum ffa_instruction_access instruction_access,
1422 ffa_memory_receiver_flags_t flags,
1423 struct ffa_memory_access_impdef *impdef_val);
J-Alves45085432022-04-22 16:19:20 +01001424uint32_t ffa_memory_region_init_single_receiver(
Andrew Walbranca808b12020-05-15 17:22:28 +01001425 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
J-Alves19e20cf2023-08-02 12:48:55 +01001426 ffa_id_t sender, ffa_id_t receiver,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001427 const struct ffa_memory_region_constituent constituents[],
1428 uint32_t constituent_count, uint32_t tag,
1429 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
1430 enum ffa_instruction_access instruction_access,
1431 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
Daniel Boulby59ffee92023-11-02 18:26:26 +00001432 enum ffa_memory_shareability shareability,
1433 struct ffa_memory_access_impdef *impdef_val, uint32_t *fragment_length,
Andrew Walbranca808b12020-05-15 17:22:28 +01001434 uint32_t *total_length);
J-Alvesf4eecf72022-07-20 16:05:34 +01001435uint32_t ffa_memory_region_init(
1436 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
J-Alves19e20cf2023-08-02 12:48:55 +01001437 ffa_id_t sender, struct ffa_memory_access receivers[],
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001438 uint32_t receiver_count, uint32_t receiver_desc_size,
J-Alvesf4eecf72022-07-20 16:05:34 +01001439 const struct ffa_memory_region_constituent constituents[],
1440 uint32_t constituent_count, uint32_t tag,
1441 ffa_memory_region_flags_t flags, enum ffa_memory_type type,
1442 enum ffa_memory_cacheability cacheability,
1443 enum ffa_memory_shareability shareability, uint32_t *fragment_length,
1444 uint32_t *total_length);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001445uint32_t ffa_memory_retrieve_request_init(
1446 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves19e20cf2023-08-02 12:48:55 +01001447 ffa_id_t sender, struct ffa_memory_access receivers[],
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001448 uint32_t receiver_count, uint32_t receiver_desc_size, uint32_t tag,
1449 ffa_memory_region_flags_t flags, enum ffa_memory_type type,
1450 enum ffa_memory_cacheability cacheability,
J-Alves9b24ed82022-08-04 13:12:45 +01001451 enum ffa_memory_shareability shareability);
1452uint32_t ffa_memory_retrieve_request_init_single_receiver(
1453 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves19e20cf2023-08-02 12:48:55 +01001454 ffa_id_t sender, ffa_id_t receiver, uint32_t tag,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001455 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
1456 enum ffa_instruction_access instruction_access,
1457 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
Daniel Boulby59ffee92023-11-02 18:26:26 +00001458 enum ffa_memory_shareability shareability,
1459 struct ffa_memory_access_impdef *impdef_val);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001460uint32_t ffa_memory_lender_retrieve_request_init(
1461 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves19e20cf2023-08-02 12:48:55 +01001462 ffa_id_t sender);
Andrew Walbranca808b12020-05-15 17:22:28 +01001463uint32_t ffa_memory_fragment_init(
1464 struct ffa_memory_region_constituent *fragment,
1465 size_t fragment_max_size,
1466 const struct ffa_memory_region_constituent constituents[],
1467 uint32_t constituent_count, uint32_t *fragment_length);
Federico Recanati392be392022-02-08 20:53:03 +01001468void ffa_endpoint_rx_tx_descriptor_init(
J-Alves19e20cf2023-08-02 12:48:55 +01001469 struct ffa_endpoint_rx_tx_descriptor *desc, ffa_id_t endpoint_id,
Federico Recanati392be392022-02-08 20:53:03 +01001470 uint64_t rx_address, uint64_t tx_address);