blob: 8dddd9592a76818c2bb77d8e5891b8b86454f5f5 [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 */
Karl Meakindc759f52024-05-07 16:08:02 +0100109enum ffa_error {
110 FFA_NOT_SUPPORTED = -1,
111 FFA_INVALID_PARAMETERS = -2,
112 FFA_NO_MEMORY = -3,
113 FFA_BUSY = -4,
114 FFA_INTERRUPTED = -5,
115 FFA_DENIED = -6,
116 FFA_RETRY = -7,
117 FFA_ABORTED = -8,
118 FFA_NO_DATA = -9,
119 FFA_NOT_READY = -10,
120};
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100121
122/* clang-format on */
123
Karl Meakinf51a35f2023-08-07 17:53:52 +0100124/* Return the name of the function identifier. */
125static inline const char *ffa_func_name(uint32_t func)
126{
127 switch (func) {
128 case FFA_ERROR_32:
129 return "FFA_ERROR_32";
130 case FFA_SUCCESS_32:
131 return "FFA_SUCCESS_32";
132 case FFA_SUCCESS_64:
133 return "FFA_SUCCESS_64";
134 case FFA_INTERRUPT_32:
135 return "FFA_INTERRUPT_32";
136 case FFA_VERSION_32:
137 return "FFA_VERSION_32";
138 case FFA_FEATURES_32:
139 return "FFA_FEATURES_32";
140 case FFA_RX_RELEASE_32:
141 return "FFA_RX_RELEASE_32";
142 case FFA_RXTX_MAP_32:
143 return "FFA_RXTX_MAP_32";
144 case FFA_RXTX_MAP_64:
145 return "FFA_RXTX_MAP_64";
146 case FFA_RXTX_UNMAP_32:
147 return "FFA_RXTX_UNMAP_32";
148 case FFA_PARTITION_INFO_GET_32:
149 return "FFA_PARTITION_INFO_GET_32";
150 case FFA_ID_GET_32:
151 return "FFA_ID_GET_32";
152 case FFA_MSG_POLL_32:
153 return "FFA_MSG_POLL_32";
154 case FFA_MSG_WAIT_32:
155 return "FFA_MSG_WAIT_32";
156 case FFA_YIELD_32:
157 return "FFA_YIELD_32";
158 case FFA_RUN_32:
159 return "FFA_RUN_32";
160 case FFA_MSG_SEND_32:
161 return "FFA_MSG_SEND_32";
162 case FFA_MSG_SEND_DIRECT_REQ_32:
163 return "FFA_MSG_SEND_DIRECT_REQ_32";
164 case FFA_MSG_SEND_DIRECT_REQ_64:
165 return "FFA_MSG_SEND_DIRECT_REQ_64";
166 case FFA_MSG_SEND_DIRECT_RESP_32:
167 return "FFA_MSG_SEND_DIRECT_RESP_32";
168 case FFA_MSG_SEND_DIRECT_RESP_64:
169 return "FFA_MSG_SEND_DIRECT_RESP_64";
170 case FFA_MEM_DONATE_32:
171 return "FFA_MEM_DONATE_32";
172 case FFA_MEM_LEND_32:
173 return "FFA_MEM_LEND_32";
174 case FFA_MEM_SHARE_32:
175 return "FFA_MEM_SHARE_32";
176 case FFA_MEM_RETRIEVE_REQ_32:
177 return "FFA_MEM_RETRIEVE_REQ_32";
178 case FFA_MEM_RETRIEVE_RESP_32:
179 return "FFA_MEM_RETRIEVE_RESP_32";
180 case FFA_MEM_RELINQUISH_32:
181 return "FFA_MEM_RELINQUISH_32";
182 case FFA_MEM_RECLAIM_32:
183 return "FFA_MEM_RECLAIM_32";
184 case FFA_MEM_FRAG_RX_32:
185 return "FFA_MEM_FRAG_RX_32";
186 case FFA_MEM_FRAG_TX_32:
187 return "FFA_MEM_FRAG_TX_32";
188 case FFA_NORMAL_WORLD_RESUME:
189 return "FFA_NORMAL_WORLD_RESUME";
190
191 /* FF-A v1.1 */
192 case FFA_NOTIFICATION_BITMAP_CREATE_32:
193 return "FFA_NOTIFICATION_BITMAP_CREATE_32";
194 case FFA_NOTIFICATION_BITMAP_DESTROY_32:
195 return "FFA_NOTIFICATION_BITMAP_DESTROY_32";
196 case FFA_NOTIFICATION_BIND_32:
197 return "FFA_NOTIFICATION_BIND_32";
198 case FFA_NOTIFICATION_UNBIND_32:
199 return "FFA_NOTIFICATION_UNBIND_32";
200 case FFA_NOTIFICATION_SET_32:
201 return "FFA_NOTIFICATION_SET_32";
202 case FFA_NOTIFICATION_GET_32:
203 return "FFA_NOTIFICATION_GET_32";
204 case FFA_NOTIFICATION_INFO_GET_64:
205 return "FFA_NOTIFICATION_INFO_GET_64";
206 case FFA_RX_ACQUIRE_32:
207 return "FFA_RX_ACQUIRE_32";
208 case FFA_SPM_ID_GET_32:
209 return "FFA_SPM_ID_GET_32";
210 case FFA_MSG_SEND2_32:
211 return "FFA_MSG_SEND2_32";
212 case FFA_SECONDARY_EP_REGISTER_64:
213 return "FFA_SECONDARY_EP_REGISTER_64";
214 case FFA_MEM_PERM_GET_32:
215 return "FFA_MEM_PERM_GET_32";
216 case FFA_MEM_PERM_SET_32:
217 return "FFA_MEM_PERM_SET_32";
218 case FFA_MEM_PERM_GET_64:
219 return "FFA_MEM_PERM_GET_64";
220 case FFA_MEM_PERM_SET_64:
221 return "FFA_MEM_PERM_SET_64";
222
223 /* Implementation-defined ABIs. */
224 case FFA_CONSOLE_LOG_32:
225 return "FFA_CONSOLE_LOG_32";
226 case FFA_CONSOLE_LOG_64:
227 return "FFA_CONSOLE_LOG_64";
228 case FFA_PARTITION_INFO_GET_REGS_64:
229 return "FFA_PARTITION_INFO_GET_REGS_64";
230 case FFA_EL3_INTR_HANDLE_32:
231 return "FFA_EL3_INTR_HANDLE_32";
232
233 default:
234 return "UNKNOWN";
235 }
236}
237
238/* Return the name of the error code. */
Karl Meakindc759f52024-05-07 16:08:02 +0100239static inline const char *ffa_error_name(enum ffa_error error)
Karl Meakinf51a35f2023-08-07 17:53:52 +0100240{
241 switch (error) {
242 case FFA_NOT_SUPPORTED:
243 return "FFA_NOT_SUPPORTED";
244 case FFA_INVALID_PARAMETERS:
245 return "FFA_INVALID_PARAMETERS";
246 case FFA_NO_MEMORY:
247 return "FFA_NO_MEMORY";
248 case FFA_BUSY:
249 return "FFA_BUSY";
250 case FFA_INTERRUPTED:
251 return "FFA_INTERRUPTED";
252 case FFA_DENIED:
253 return "FFA_DENIED";
254 case FFA_RETRY:
255 return "FFA_RETRY";
256 case FFA_ABORTED:
257 return "FFA_ABORTED";
258 case FFA_NO_DATA:
259 return "FFA_NO_DATA";
Karl Meakindc759f52024-05-07 16:08:02 +0100260 case FFA_NOT_READY:
261 return "FFA_NOT_READY";
Karl Meakinf51a35f2023-08-07 17:53:52 +0100262 }
Karl Meakindc759f52024-05-07 16:08:02 +0100263 return "UNKNOWN";
Karl Meakinf51a35f2023-08-07 17:53:52 +0100264}
265
J-Alves6f72ca82021-11-01 12:34:58 +0000266/**
267 * FF-A Feature ID, to be used with interface FFA_FEATURES.
268 * As defined in the FF-A v1.1 Beta specification, table 13.10, in section
269 * 13.2.
270 */
271
Olivier Deprezb76307d2022-06-09 17:17:45 +0200272#define FFA_FEATURES_FUNC_ID_MASK (UINT32_C(1) << 31)
J-Alves6f72ca82021-11-01 12:34:58 +0000273#define FFA_FEATURES_FEATURE_ID_MASK UINT32_C(0x7F)
274
Karl Meakin34b8ae92023-01-13 13:33:07 +0000275/**
276 * Defined in Table 13.14 in the FF-A v.1.1 REL0 specification.
277 * Bits[31:2] and Bit[0] of input are reserved (must be zero).
278 * Bit[0]: dynamically allocated buffer support.
279 * Bit[1]: NS bit handling.
280 * Bit[2]: support for retrieval by hypervisor.
281 */
282#define FFA_FEATURES_MEM_RETRIEVE_REQ_BUFFER_SUPPORT 0
283#define FFA_FEATURES_MEM_RETRIEVE_REQ_NS_SUPPORT (UINT32_C(1) << 1)
284#define FFA_FEATURES_MEM_RETRIEVE_REQ_HYPERVISOR_SUPPORT (UINT32_C(1) << 2)
285#define FFA_FEATURES_MEM_RETRIEVE_REQ_MBZ_MASK \
286 (~(FFA_FEATURES_MEM_RETRIEVE_REQ_BUFFER_SUPPORT | \
287 FFA_FEATURES_MEM_RETRIEVE_REQ_NS_SUPPORT | \
288 FFA_FEATURES_MEM_RETRIEVE_REQ_HYPERVISOR_SUPPORT))
289
J-Alves6f72ca82021-11-01 12:34:58 +0000290/* Query interrupt ID of Notification Pending Interrupt. */
291#define FFA_FEATURE_NPI 0x1U
292
293/* Query interrupt ID of Schedule Receiver Interrupt. */
294#define FFA_FEATURE_SRI 0x2U
295
296/* Query interrupt ID of the Managed Exit Interrupt. */
297#define FFA_FEATURE_MEI 0x3U
298
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100299/* FF-A function specific constants. */
300#define FFA_MSG_RECV_BLOCK 0x1
301#define FFA_MSG_RECV_BLOCK_MASK 0x1
302
303#define FFA_MSG_SEND_NOTIFY 0x1
304#define FFA_MSG_SEND_NOTIFY_MASK 0x1
305
306#define FFA_MEM_RECLAIM_CLEAR 0x1
307
308#define FFA_SLEEP_INDEFINITE 0
309
Raghu Krishnamurthyea6d25f2021-09-14 15:27:06 -0700310#define FFA_MEM_PERM_RO UINT32_C(0x7)
311#define FFA_MEM_PERM_RW UINT32_C(0x5)
312#define FFA_MEM_PERM_RX UINT32_C(0x3)
313
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000314/*
Olivier Deprez013f4d62022-11-21 15:46:20 +0100315 * Defined in Table 13.34 in the FF-A v1.1 EAC0 specification.
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000316 * The Partition count flag is used by FFA_PARTITION_INFO_GET to specify
317 * if partition info descriptors should be returned or just the count.
318 */
Olivier Deprez013f4d62022-11-21 15:46:20 +0100319#define FFA_PARTITION_COUNT_FLAG UINT32_C(0x1)
320#define FFA_PARTITION_COUNT_FLAG_MASK (UINT32_C(0x1) << 0)
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000321
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100322/**
323 * For use where the FF-A specification refers explicitly to '4K pages'. Not to
324 * be confused with PAGE_SIZE, which is the translation granule Hafnium is
325 * configured to use.
326 */
J-Alves715d6232023-02-16 16:33:28 +0000327#define FFA_PAGE_SIZE ((size_t)4096)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100328
Federico Recanatifc0295e2022-02-08 19:37:39 +0100329/** The ID of a VM. These are assigned sequentially starting with an offset. */
J-Alves19e20cf2023-08-02 12:48:55 +0100330typedef uint16_t ffa_id_t;
Federico Recanatifc0295e2022-02-08 19:37:39 +0100331
332/**
J-Alves661e1b72023-08-02 13:39:40 +0100333 * The FF-A v1.2 ALP0, section 6.1 defines that partition IDs are split into two
334 * parts:
335 * - Bit15 -> partition type identifier.
336 * - b'0 -> ID relates to a VM ID.
337 * - b'1 -> ID relates to an SP ID.
338 */
339#define FFA_ID_MASK ((ffa_id_t)0x8000)
340#define FFA_VM_ID_MASK ((ffa_id_t)0x0000)
341
342/**
343 * Helper to check if FF-A ID is a VM ID, managed by the hypervisor.
344 */
345static inline bool ffa_is_vm_id(ffa_id_t id)
346{
347 return (FFA_ID_MASK & id) == FFA_VM_ID_MASK;
348}
349
350/**
Federico Recanatifc0295e2022-02-08 19:37:39 +0100351 * Partition message header as specified by table 6.2 from FF-A v1.1 EAC0
352 * specification.
353 */
354struct ffa_partition_rxtx_header {
355 uint32_t flags; /* MBZ */
356 uint32_t reserved;
357 /* Offset from the beginning of the buffer to the message payload. */
358 uint32_t offset;
359 /* Sender(Bits[31:16]) and Receiver(Bits[15:0]) endpoint IDs. */
360 uint32_t sender_receiver;
361 /* Size of message in buffer. */
362 uint32_t size;
363};
364
365#define FFA_RXTX_HEADER_SIZE sizeof(struct ffa_partition_rxtx_header)
366#define FFA_RXTX_SENDER_SHIFT (0x10U)
J-Alves70079932022-12-07 17:32:20 +0000367#define FFA_RXTX_ALLOCATOR_SHIFT 16
Federico Recanatifc0295e2022-02-08 19:37:39 +0100368
369static inline void ffa_rxtx_header_init(
J-Alves19e20cf2023-08-02 12:48:55 +0100370 ffa_id_t sender, ffa_id_t receiver, uint32_t size,
Federico Recanatifc0295e2022-02-08 19:37:39 +0100371 struct ffa_partition_rxtx_header *header)
372{
373 header->flags = 0;
374 header->reserved = 0;
375 header->offset = FFA_RXTX_HEADER_SIZE;
376 header->sender_receiver =
377 (uint32_t)(receiver | (sender << FFA_RXTX_SENDER_SHIFT));
378 header->size = size;
379}
380
J-Alves19e20cf2023-08-02 12:48:55 +0100381static inline ffa_id_t ffa_rxtx_header_sender(
Federico Recanatifc0295e2022-02-08 19:37:39 +0100382 const struct ffa_partition_rxtx_header *h)
383{
J-Alves19e20cf2023-08-02 12:48:55 +0100384 return (ffa_id_t)(h->sender_receiver >> FFA_RXTX_SENDER_SHIFT);
Federico Recanatifc0295e2022-02-08 19:37:39 +0100385}
386
J-Alves19e20cf2023-08-02 12:48:55 +0100387static inline ffa_id_t ffa_rxtx_header_receiver(
Federico Recanatifc0295e2022-02-08 19:37:39 +0100388 const struct ffa_partition_rxtx_header *h)
389{
J-Alves19e20cf2023-08-02 12:48:55 +0100390 return (ffa_id_t)(h->sender_receiver);
Federico Recanatifc0295e2022-02-08 19:37:39 +0100391}
392
393/* The maximum length possible for a single message. */
394#define FFA_PARTITION_MSG_PAYLOAD_MAX (HF_MAILBOX_SIZE - FFA_RXTX_HEADER_SIZE)
395
396struct ffa_partition_msg {
397 struct ffa_partition_rxtx_header header;
398 char payload[FFA_PARTITION_MSG_PAYLOAD_MAX];
399};
400
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100401/* The maximum length possible for a single message. */
402#define FFA_MSG_PAYLOAD_MAX HF_MAILBOX_SIZE
403
404enum ffa_data_access {
405 FFA_DATA_ACCESS_NOT_SPECIFIED,
406 FFA_DATA_ACCESS_RO,
407 FFA_DATA_ACCESS_RW,
408 FFA_DATA_ACCESS_RESERVED,
409};
410
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100411static inline const char *ffa_data_access_name(enum ffa_data_access data_access)
412{
413 switch (data_access) {
414 case FFA_DATA_ACCESS_NOT_SPECIFIED:
415 return "FFA_DATA_ACCESS_NOT_SPECIFIED";
416 case FFA_DATA_ACCESS_RO:
417 return "FFA_DATA_ACCESS_RO";
418 case FFA_DATA_ACCESS_RW:
419 return "FFA_DATA_ACCESS_RW";
420 case FFA_DATA_ACCESS_RESERVED:
421 return "FFA_DATA_ACCESS_RESERVED";
422 }
423}
424
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100425enum ffa_instruction_access {
426 FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED,
427 FFA_INSTRUCTION_ACCESS_NX,
428 FFA_INSTRUCTION_ACCESS_X,
429 FFA_INSTRUCTION_ACCESS_RESERVED,
430};
431
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100432static inline const char *ffa_instruction_access_name(
433 enum ffa_instruction_access instruction_access)
434{
435 switch (instruction_access) {
436 case FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED:
437 return "FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED";
438 case FFA_INSTRUCTION_ACCESS_NX:
439 return "FFA_INSTRUCTION_ACCESS_NX";
440 case FFA_INSTRUCTION_ACCESS_X:
441 return "FFA_INSTRUCTION_ACCESS_X";
442 case FFA_INSTRUCTION_ACCESS_RESERVED:
443 return "FFA_INSTRUCTION_ACCESS_RESERVED";
444 }
445}
446
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100447enum ffa_memory_type {
448 FFA_MEMORY_NOT_SPECIFIED_MEM,
449 FFA_MEMORY_DEVICE_MEM,
450 FFA_MEMORY_NORMAL_MEM,
451};
452
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100453static inline const char *ffa_memory_type_name(enum ffa_memory_type type)
454{
455 switch (type) {
456 case FFA_MEMORY_NOT_SPECIFIED_MEM:
457 return "FFA_MEMORY_NOT_SPECIFIED_MEM";
458 case FFA_MEMORY_DEVICE_MEM:
459 return "FFA_MEMORY_DEVICE_MEM";
460 case FFA_MEMORY_NORMAL_MEM:
461 return "FFA_MEMORY_NORMAL_MEM";
462 }
463}
464
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100465enum ffa_memory_cacheability {
466 FFA_MEMORY_CACHE_RESERVED = 0x0,
467 FFA_MEMORY_CACHE_NON_CACHEABLE = 0x1,
468 FFA_MEMORY_CACHE_RESERVED_1 = 0x2,
469 FFA_MEMORY_CACHE_WRITE_BACK = 0x3,
470 FFA_MEMORY_DEV_NGNRNE = 0x0,
471 FFA_MEMORY_DEV_NGNRE = 0x1,
472 FFA_MEMORY_DEV_NGRE = 0x2,
473 FFA_MEMORY_DEV_GRE = 0x3,
474};
475
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100476static inline const char *ffa_memory_cacheability_name(
477 enum ffa_memory_cacheability cacheability)
478{
479 switch (cacheability) {
480 case FFA_MEMORY_CACHE_RESERVED:
481 return "FFA_MEMORY_CACHE_RESERVED";
482 case FFA_MEMORY_CACHE_NON_CACHEABLE:
483 return "FFA_MEMORY_CACHE_NON_CACHEABLE";
484 case FFA_MEMORY_CACHE_RESERVED_1:
485 return "FFA_MEMORY_CACHE_RESERVED_1";
486 case FFA_MEMORY_CACHE_WRITE_BACK:
487 return "FFA_MEMORY_CACHE_WRITE_BACK";
488 }
489}
490
Daniel Boulby9764ff62024-01-30 17:47:39 +0000491static inline const char *ffa_device_memory_cacheability_name(
492 enum ffa_memory_cacheability cacheability)
493{
494 switch (cacheability) {
495 case FFA_MEMORY_DEV_NGNRNE:
496 return "FFA_MEMORY_DEV_NGNRNE";
497 case FFA_MEMORY_DEV_NGNRE:
498 return "FFA_MEMORY_DEV_NGNRE";
499 case FFA_MEMORY_DEV_NGRE:
500 return "FFA_MEMORY_DEV_NGRE";
501 case FFA_MEMORY_DEV_GRE:
502 return "FFA_MEMORY_DEV_GRE";
503 }
504}
505
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100506enum ffa_memory_shareability {
507 FFA_MEMORY_SHARE_NON_SHAREABLE,
508 FFA_MEMORY_SHARE_RESERVED,
509 FFA_MEMORY_OUTER_SHAREABLE,
510 FFA_MEMORY_INNER_SHAREABLE,
511};
512
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100513static inline const char *ffa_memory_shareability_name(
514 enum ffa_memory_shareability shareability)
515{
516 switch (shareability) {
517 case FFA_MEMORY_SHARE_NON_SHAREABLE:
518 return "FFA_MEMORY_SHARE_NON_SHAREABLE";
519 case FFA_MEMORY_SHARE_RESERVED:
520 return "FFA_MEMORY_SHARE_RESERVED";
521 case FFA_MEMORY_OUTER_SHAREABLE:
522 return "FFA_MEMORY_OUTER_SHAREABLE";
523 case FFA_MEMORY_INNER_SHAREABLE:
524 return "FFA_MEMORY_INNER_SHAREABLE";
525 }
526}
527
Olivier Deprez4342a3c2022-02-28 09:37:25 +0100528/**
529 * FF-A v1.1 REL0 Table 10.18 memory region attributes descriptor NS Bit 6.
530 * Per section 10.10.4.1, NS bit is reserved for FFA_MEM_DONATE/LEND/SHARE
531 * and FFA_MEM_RETRIEVE_REQUEST.
532 */
533enum ffa_memory_security {
534 FFA_MEMORY_SECURITY_UNSPECIFIED = 0,
535 FFA_MEMORY_SECURITY_SECURE = 0,
536 FFA_MEMORY_SECURITY_NON_SECURE,
537};
538
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100539static inline const char *ffa_memory_security_name(
540 enum ffa_memory_security security)
541{
542 switch (security) {
543 case FFA_MEMORY_SECURITY_UNSPECIFIED:
544 return "FFA_MEMORY_SECURITY_UNSPECIFIED";
545 case FFA_MEMORY_SECURITY_NON_SECURE:
546 return "FFA_MEMORY_SECURITY_NON_SECURE";
547 }
548}
549
Karl Meakin84710f32023-10-12 15:14:49 +0100550typedef struct {
551 uint8_t data_access : 2;
552 uint8_t instruction_access : 2;
553} ffa_memory_access_permissions_t;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100554
555/**
J-Alves0b6653d2022-04-22 13:17:38 +0100556 * This corresponds to table 10.18 of the FF-A v1.1 EAC0 specification, "Memory
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100557 * region attributes descriptor".
558 */
Karl Meakin84710f32023-10-12 15:14:49 +0100559typedef struct {
560 uint8_t shareability : 2;
561 uint8_t cacheability : 2;
562 uint8_t type : 2;
563 uint8_t security : 2;
564 uint8_t : 8;
565} ffa_memory_attributes_t;
J-Alves0b6653d2022-04-22 13:17:38 +0100566
567/* FF-A v1.1 EAC0 states bit [15:7] Must Be Zero. */
568#define FFA_MEMORY_ATTRIBUTES_MBZ_MASK 0xFF80U
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100569
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100570/**
571 * A globally-unique ID assigned by the hypervisor for a region of memory being
572 * sent between VMs.
573 */
574typedef uint64_t ffa_memory_handle_t;
575
J-Alves917d2f22020-10-30 18:39:30 +0000576#define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \
577 ((ffa_memory_handle_t)(UINT64_C(1) << 63))
578#define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR \
579 ((ffa_memory_handle_t)(UINT64_C(1) << 63))
580
581#define FFA_MEMORY_HANDLE_ALLOCATOR_SPMC (UINT64_C(0) << 63)
582#define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0))
583
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100584/**
585 * A count of VMs. This has the same range as the VM IDs but we give it a
586 * different name to make the different semantics clear.
587 */
J-Alves19e20cf2023-08-02 12:48:55 +0100588typedef ffa_id_t ffa_vm_count_t;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100589
590/** The index of a vCPU within a particular VM. */
591typedef uint16_t ffa_vcpu_index_t;
592
593/**
594 * A count of vCPUs. This has the same range as the vCPU indices but we give it
595 * a different name to make the different semantics clear.
596 */
597typedef ffa_vcpu_index_t ffa_vcpu_count_t;
598
599/** Parameter and return type of FF-A functions. */
600struct ffa_value {
601 uint64_t func;
602 uint64_t arg1;
603 uint64_t arg2;
604 uint64_t arg3;
605 uint64_t arg4;
606 uint64_t arg5;
607 uint64_t arg6;
608 uint64_t arg7;
Raghu Krishnamurthy567068e2022-12-26 07:46:38 -0800609
610 struct {
611 uint64_t arg8;
612 uint64_t arg9;
613 uint64_t arg10;
614 uint64_t arg11;
615 uint64_t arg12;
616 uint64_t arg13;
617 uint64_t arg14;
618 uint64_t arg15;
619 uint64_t arg16;
620 uint64_t arg17;
621 bool valid;
622 } extended_val;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100623};
624
Olivier Depreze562e542020-06-11 17:31:54 +0200625static inline uint32_t ffa_func_id(struct ffa_value args)
626{
627 return args.func;
628}
629
Karl Meakindc759f52024-05-07 16:08:02 +0100630static inline enum ffa_error ffa_error_code(struct ffa_value val)
J-Alves13318e32021-02-22 17:21:00 +0000631{
Karl Meakindc759f52024-05-07 16:08:02 +0100632 return (enum ffa_error)val.arg2;
J-Alves13318e32021-02-22 17:21:00 +0000633}
634
J-Alves19e20cf2023-08-02 12:48:55 +0100635static inline ffa_id_t ffa_sender(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100636{
637 return (args.arg1 >> 16) & 0xffff;
638}
639
J-Alves19e20cf2023-08-02 12:48:55 +0100640static inline ffa_id_t ffa_receiver(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100641{
642 return args.arg1 & 0xffff;
643}
644
645static inline uint32_t ffa_msg_send_size(struct ffa_value args)
646{
647 return args.arg3;
648}
649
Federico Recanati25053ee2022-03-14 15:01:53 +0100650static inline uint32_t ffa_msg_send2_flags(struct ffa_value args)
651{
652 return args.arg2;
653}
654
Olivier Depreze562e542020-06-11 17:31:54 +0200655static inline uint32_t ffa_partition_info_get_count(struct ffa_value args)
656{
657 return args.arg2;
658}
659
Raghu Krishnamurthy2957b922022-12-27 10:29:12 -0800660static inline uint16_t ffa_partition_info_regs_get_last_idx(
661 struct ffa_value args)
662{
663 return args.arg2 & 0xFFFF;
664}
665
666static inline uint16_t ffa_partition_info_regs_get_curr_idx(
667 struct ffa_value args)
668{
669 return (args.arg2 >> 16) & 0xFFFF;
670}
671
672static inline uint16_t ffa_partition_info_regs_get_tag(struct ffa_value args)
673{
674 return (args.arg2 >> 32) & 0xFFFF;
675}
676
677static inline uint16_t ffa_partition_info_regs_get_desc_size(
678 struct ffa_value args)
679{
680 return (args.arg2 >> 48);
681}
682
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100683static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t a1, uint32_t a2)
684{
685 return (uint64_t)a1 | (uint64_t)a2 << 32;
686}
687
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100688static inline ffa_memory_handle_t ffa_mem_success_handle(struct ffa_value args)
689{
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100690 return ffa_assemble_handle(args.arg2, args.arg3);
691}
692
Andrew Walbranca808b12020-05-15 17:22:28 +0100693static inline ffa_memory_handle_t ffa_frag_handle(struct ffa_value args)
694{
695 return ffa_assemble_handle(args.arg1, args.arg2);
696}
697
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100698static inline struct ffa_value ffa_mem_success(ffa_memory_handle_t handle)
699{
700 return (struct ffa_value){.func = FFA_SUCCESS_32,
701 .arg2 = (uint32_t)handle,
702 .arg3 = (uint32_t)(handle >> 32)};
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100703}
704
J-Alves19e20cf2023-08-02 12:48:55 +0100705static inline ffa_id_t ffa_vm_id(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100706{
707 return (args.arg1 >> 16) & 0xffff;
708}
709
710static inline ffa_vcpu_index_t ffa_vcpu_index(struct ffa_value args)
711{
712 return args.arg1 & 0xffff;
713}
714
J-Alves19e20cf2023-08-02 12:48:55 +0100715static inline uint64_t ffa_vm_vcpu(ffa_id_t vm_id, ffa_vcpu_index_t vcpu_index)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100716{
717 return ((uint32_t)vm_id << 16) | vcpu_index;
718}
719
J-Alves19e20cf2023-08-02 12:48:55 +0100720static inline ffa_id_t ffa_frag_sender(struct ffa_value args)
Andrew Walbranca808b12020-05-15 17:22:28 +0100721{
722 return (args.arg4 >> 16) & 0xffff;
723}
724
J-Alves6f72ca82021-11-01 12:34:58 +0000725static inline uint32_t ffa_feature_intid(struct ffa_value args)
726{
727 return (uint32_t)args.arg2;
728}
729
Daniel Boulbyefa381f2022-01-18 14:49:40 +0000730static inline uint32_t ffa_fwk_msg(struct ffa_value args)
731{
732 return (uint32_t)args.arg2;
733}
734
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100735/**
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100736 * Holds the UUID in a struct that is mappable directly to the SMCC calling
737 * convention, which is used for FF-A calls.
738 *
739 * Refer to table 84 of the FF-A 1.0 EAC specification as well as section 5.3
740 * of the SMCC Spec 1.2.
741 */
742struct ffa_uuid {
743 uint32_t uuid[4];
744};
745
746static inline void ffa_uuid_init(uint32_t w0, uint32_t w1, uint32_t w2,
747 uint32_t w3, struct ffa_uuid *uuid)
748{
749 uuid->uuid[0] = w0;
750 uuid->uuid[1] = w1;
751 uuid->uuid[2] = w2;
752 uuid->uuid[3] = w3;
753}
754
755static inline bool ffa_uuid_equal(const struct ffa_uuid *uuid1,
756 const struct ffa_uuid *uuid2)
757{
758 return (uuid1->uuid[0] == uuid2->uuid[0]) &&
759 (uuid1->uuid[1] == uuid2->uuid[1]) &&
760 (uuid1->uuid[2] == uuid2->uuid[2]) &&
761 (uuid1->uuid[3] == uuid2->uuid[3]);
762}
763
764static inline bool ffa_uuid_is_null(const struct ffa_uuid *uuid)
765{
766 return (uuid->uuid[0] == 0) && (uuid->uuid[1] == 0) &&
767 (uuid->uuid[2] == 0) && (uuid->uuid[3] == 0);
768}
769
Kathleen Capella41fea932023-06-23 17:39:28 -0400770static inline void ffa_uuid_unpack_from_uint64(uint64_t uuid_lo,
771 uint64_t uuid_hi,
772 struct ffa_uuid *uuid)
773{
774 ffa_uuid_init((uint32_t)(uuid_lo & 0xFFFFFFFFU),
775 (uint32_t)(uuid_lo >> 32),
776 (uint32_t)(uuid_hi & 0xFFFFFFFFU),
777 (uint32_t)(uuid_hi >> 32), uuid);
778}
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100779/**
780 * Flags to determine the partition properties, as required by
781 * FFA_PARTITION_INFO_GET.
782 *
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400783 * 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 +0100784 * specification, "Partition information descriptor, partition properties".
785 */
786typedef uint32_t ffa_partition_properties_t;
787
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400788/**
789 * Partition property: partition supports receipt of direct requests via the
790 * FFA_MSG_SEND_DIRECT_REQ ABI.
791 */
Kathleen Capella402fa852022-11-09 16:16:51 -0500792#define FFA_PARTITION_DIRECT_REQ_RECV (UINT32_C(1) << 0)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100793
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400794/**
795 * Partition property: partition can send direct requests via the
796 * FFA_MSG_SEND_DIRECT_REQ ABI.
797 */
Kathleen Capella402fa852022-11-09 16:16:51 -0500798#define FFA_PARTITION_DIRECT_REQ_SEND (UINT32_C(1) << 1)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100799
800/** Partition property: partition can send and receive indirect messages. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500801#define FFA_PARTITION_INDIRECT_MSG (UINT32_C(1) << 2)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100802
J-Alves09ff9d82021-11-02 11:55:20 +0000803/** Partition property: partition can receive notifications. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500804#define FFA_PARTITION_NOTIFICATION (UINT32_C(1) << 3)
805
806/** Partition property: partition runs in the AArch64 execution state. */
807#define FFA_PARTITION_AARCH64_EXEC (UINT32_C(1) << 8)
J-Alves09ff9d82021-11-02 11:55:20 +0000808
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100809/**
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400810 * Partition property: partition supports receipt of direct requests via the
811 * FFA_MSG_SEND_DIRECT_REQ2 ABI.
812 */
813#define FFA_PARTITION_DIRECT_REQ2_RECV (UINT32_C(1) << 9)
814
815/**
816 * Partition property: partition can send direct requests via the
817 * FFA_MSG_SEND_DIRECT_REQ2 ABI.
818 */
819#define FFA_PARTITION_DIRECT_REQ2_SEND (UINT32_C(1) << 10)
820
821/**
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100822 * Holds information returned for each partition by the FFA_PARTITION_INFO_GET
823 * interface.
Kathleen Capella402fa852022-11-09 16:16:51 -0500824 * This corresponds to table 13.37 "Partition information descriptor"
825 * in FF-A 1.1 EAC0 specification.
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000826 */
827struct ffa_partition_info {
J-Alves19e20cf2023-08-02 12:48:55 +0100828 ffa_id_t vm_id;
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000829 ffa_vcpu_count_t vcpu_count;
830 ffa_partition_properties_t properties;
831 struct ffa_uuid uuid;
832};
833
J-Alvesdd1ad572022-01-25 17:58:26 +0000834/** Length in bytes of the name in boot information descriptor. */
835#define FFA_BOOT_INFO_NAME_LEN 16
836
J-Alves240d84c2022-04-22 12:19:34 +0100837/**
838 * The FF-A boot info descriptor, as defined in table 5.8 of section 5.4.1, of
839 * the FF-A v1.1 EAC0 specification.
840 */
J-Alvesdd1ad572022-01-25 17:58:26 +0000841struct ffa_boot_info_desc {
842 char name[FFA_BOOT_INFO_NAME_LEN];
843 uint8_t type;
844 uint8_t reserved;
845 uint16_t flags;
846 uint32_t size;
847 uint64_t content;
848};
849
850/** FF-A boot information type mask. */
851#define FFA_BOOT_INFO_TYPE_SHIFT 7
852#define FFA_BOOT_INFO_TYPE_MASK (0x1U << FFA_BOOT_INFO_TYPE_SHIFT)
853#define FFA_BOOT_INFO_TYPE_STD 0U
854#define FFA_BOOT_INFO_TYPE_IMPDEF 1U
855
856/** Standard boot info type IDs. */
857#define FFA_BOOT_INFO_TYPE_ID_MASK 0x7FU
858#define FFA_BOOT_INFO_TYPE_ID_FDT 0U
859#define FFA_BOOT_INFO_TYPE_ID_HOB 1U
860
861/** FF-A Boot Info descriptors flags. */
862#define FFA_BOOT_INFO_FLAG_MBZ_MASK 0xFFF0U
863
864/** Bits [1:0] encode the format of the name field in ffa_boot_info_desc. */
865#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT 0U
866#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK \
867 (0x3U << FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT)
868#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING 0x0U
869#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID 0x1U
870
871/** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */
872#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT 2
873#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK \
874 (0x3U << FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT)
875#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE 0x1U
876#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR 0x0U
877
878static inline uint16_t ffa_boot_info_content_format(
879 struct ffa_boot_info_desc *desc)
880{
881 return (desc->flags & FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK) >>
882 FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT;
883}
884
885static inline uint16_t ffa_boot_info_name_format(
886 struct ffa_boot_info_desc *desc)
887{
888 return (desc->flags & FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK) >>
889 FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT;
890}
891
892static inline uint8_t ffa_boot_info_type_id(struct ffa_boot_info_desc *desc)
893{
894 return desc->type & FFA_BOOT_INFO_TYPE_ID_MASK;
895}
896
897static inline uint8_t ffa_boot_info_type(struct ffa_boot_info_desc *desc)
898{
899 return (desc->type & FFA_BOOT_INFO_TYPE_MASK) >>
900 FFA_BOOT_INFO_TYPE_SHIFT;
901}
902
903/** Length in bytes of the signature in the boot descriptor. */
904#define FFA_BOOT_INFO_HEADER_SIGNATURE_LEN 4
905
J-Alves240d84c2022-04-22 12:19:34 +0100906/**
907 * The FF-A boot information header, as defined in table 5.9 of section 5.4.2,
908 * of the FF-A v1.1 EAC0 specification.
909 */
J-Alvesdd1ad572022-01-25 17:58:26 +0000910struct ffa_boot_info_header {
911 uint32_t signature;
912 uint32_t version;
913 uint32_t info_blob_size;
914 uint32_t desc_size;
915 uint32_t desc_count;
916 uint32_t desc_offset;
917 uint64_t reserved;
918 struct ffa_boot_info_desc boot_info[];
919};
920
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100921/**
J-Alves980d1992021-03-18 12:49:18 +0000922 * FF-A v1.1 specification restricts the number of notifications to a maximum
923 * of 64. Following all possible bitmaps.
924 */
925#define FFA_NOTIFICATION_MASK(ID) (UINT64_C(1) << ID)
926
927typedef uint64_t ffa_notifications_bitmap_t;
928
929#define MAX_FFA_NOTIFICATIONS 64U
930
931/**
J-Alvesc003a7a2021-03-18 13:06:53 +0000932 * Flag for notification bind and set, to specify call is about per-vCPU
933 * notifications.
934 */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200935#define FFA_NOTIFICATION_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesc003a7a2021-03-18 13:06:53 +0000936
Federico Recanatie73d2832022-04-20 11:10:52 +0200937#define FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(0)
938#define FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(32)
939
940/**
941 * Helper functions to check for buffer full notification.
942 */
943static inline bool is_ffa_hyp_buffer_full_notification(
944 ffa_notifications_bitmap_t framework)
945{
946 return (framework & FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK) != 0;
947}
948
949static inline bool is_ffa_spm_buffer_full_notification(
950 ffa_notifications_bitmap_t framework)
951{
952 return (framework & FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK) != 0;
953}
954
J-Alvesc003a7a2021-03-18 13:06:53 +0000955/**
J-Alves980d1992021-03-18 12:49:18 +0000956 * Helper function to assemble a 64-bit sized bitmap, from the 32-bit sized lo
957 * and hi.
958 * Helpful as FF-A specification defines that the notifications interfaces
959 * arguments are 32-bit registers.
960 */
961static inline ffa_notifications_bitmap_t ffa_notifications_bitmap(uint32_t lo,
962 uint32_t hi)
963{
964 return (ffa_notifications_bitmap_t)hi << 32U | lo;
965}
966
J-Alves98ff9562021-09-09 14:39:41 +0100967static inline ffa_notifications_bitmap_t ffa_notification_get_from_sp(
968 struct ffa_value val)
969{
970 return ffa_notifications_bitmap((uint32_t)val.arg2, (uint32_t)val.arg3);
971}
972
973static inline ffa_notifications_bitmap_t ffa_notification_get_from_vm(
974 struct ffa_value val)
975{
976 return ffa_notifications_bitmap((uint32_t)val.arg4, (uint32_t)val.arg5);
977}
978
Federico Recanatie73d2832022-04-20 11:10:52 +0200979static inline ffa_notifications_bitmap_t ffa_notification_get_from_framework(
980 struct ffa_value val)
981{
982 return ffa_notifications_bitmap((uint32_t)val.arg6, (uint32_t)val.arg7);
983}
984
J-Alves980d1992021-03-18 12:49:18 +0000985/**
J-Alvesaa79c012021-07-09 14:29:45 +0100986 * Flags used in calls to FFA_NOTIFICATION_GET interface.
987 */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200988#define FFA_NOTIFICATION_FLAG_BITMAP_SP (UINT32_C(1) << 0)
989#define FFA_NOTIFICATION_FLAG_BITMAP_VM (UINT32_C(1) << 1)
990#define FFA_NOTIFICATION_FLAG_BITMAP_SPM (UINT32_C(1) << 2)
991#define FFA_NOTIFICATION_FLAG_BITMAP_HYP (UINT32_C(1) << 3)
J-Alvesaa79c012021-07-09 14:29:45 +0100992
J-Alvesa3755072021-11-26 16:01:08 +0000993/* Flag to configure notification as being per vCPU. */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200994#define FFA_NOTIFICATIONS_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesa3755072021-11-26 16:01:08 +0000995
J-Alves13394022021-06-30 13:48:49 +0100996/** Flag for FFA_NOTIFICATION_SET to delay Schedule Receiver Interrupt */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200997#define FFA_NOTIFICATIONS_FLAG_DELAY_SRI (UINT32_C(1) << 1)
998
999#define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) \
1000 ((((uint32_t)(id)) & UINT32_C(0xffff)) << 16)
J-Alves13394022021-06-30 13:48:49 +01001001
J-Alvesbe6e3032021-11-30 14:54:12 +00001002static inline ffa_vcpu_index_t ffa_notifications_get_vcpu(struct ffa_value args)
J-Alvesaa79c012021-07-09 14:29:45 +01001003{
J-Alvesbe6e3032021-11-30 14:54:12 +00001004 return (ffa_vcpu_index_t)(args.arg1 >> 16 & 0xffffU);
J-Alvesaa79c012021-07-09 14:29:45 +01001005}
1006
1007/**
J-Alvesc8e8a222021-06-08 17:33:52 +01001008 * The max number of IDs for return of FFA_NOTIFICATION_INFO_GET.
1009 */
1010#define FFA_NOTIFICATIONS_INFO_GET_MAX_IDS 20U
1011
1012/**
1013 * Number of registers to use in successfull return of interface
1014 * FFA_NOTIFICATION_INFO_GET.
1015 */
1016#define FFA_NOTIFICATIONS_INFO_GET_REGS_RET 5U
1017
1018#define FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING 0x1U
1019
1020/**
1021 * Helper macros for return parameter encoding as described in section 17.7.1
1022 * of the FF-A v1.1 Beta0 specification.
1023 */
1024#define FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT 0x7U
1025#define FFA_NOTIFICATIONS_LISTS_COUNT_MASK 0x1fU
1026#define FFA_NOTIFICATIONS_LIST_SHIFT(l) (2 * (l - 1) + 12)
1027#define FFA_NOTIFICATIONS_LIST_SIZE_MASK 0x3U
1028
1029static inline uint32_t ffa_notification_info_get_lists_count(
1030 struct ffa_value args)
1031{
1032 return (uint32_t)(args.arg2 >> FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT) &
1033 FFA_NOTIFICATIONS_LISTS_COUNT_MASK;
1034}
1035
1036static inline uint32_t ffa_notification_info_get_list_size(
1037 struct ffa_value args, unsigned int list_idx)
1038{
1039 return ((uint32_t)args.arg2 >> FFA_NOTIFICATIONS_LIST_SHIFT(list_idx)) &
1040 FFA_NOTIFICATIONS_LIST_SIZE_MASK;
1041}
1042
1043static inline bool ffa_notification_info_get_more_pending(struct ffa_value args)
1044{
1045 return (args.arg2 & FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING) != 0U;
1046}
1047
1048/**
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001049 * A set of contiguous pages which is part of a memory region. This corresponds
J-Alves0b6653d2022-04-22 13:17:38 +01001050 * to table 10.14 of the FF-A v1.1 EAC0 specification, "Constituent memory
1051 * region descriptor".
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001052 */
1053struct ffa_memory_region_constituent {
1054 /**
1055 * The base IPA of the constituent memory region, aligned to 4 kiB page
1056 * size granularity.
1057 */
1058 uint64_t address;
1059 /** The number of 4 kiB pages in the constituent memory region. */
1060 uint32_t page_count;
1061 /** Reserved field, must be 0. */
1062 uint32_t reserved;
1063};
1064
1065/**
J-Alves0b6653d2022-04-22 13:17:38 +01001066 * A set of pages comprising a memory region. This corresponds to table 10.13 of
1067 * the FF-A v1.1 EAC0 specification, "Composite memory region descriptor".
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001068 */
1069struct ffa_composite_memory_region {
1070 /**
1071 * The total number of 4 kiB pages included in this memory region. This
1072 * must be equal to the sum of page counts specified in each
1073 * `ffa_memory_region_constituent`.
1074 */
1075 uint32_t page_count;
1076 /**
1077 * The number of constituents (`ffa_memory_region_constituent`)
1078 * included in this memory region range.
1079 */
1080 uint32_t constituent_count;
1081 /** Reserved field, must be 0. */
1082 uint64_t reserved_0;
1083 /** An array of `constituent_count` memory region constituents. */
1084 struct ffa_memory_region_constituent constituents[];
1085};
1086
1087/** Flags to indicate properties of receivers during memory region retrieval. */
1088typedef uint8_t ffa_memory_receiver_flags_t;
1089
1090/**
J-Alves0b6653d2022-04-22 13:17:38 +01001091 * This corresponds to table 10.15 of the FF-A v1.1 EAC0 specification, "Memory
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001092 * access permissions descriptor".
1093 */
1094struct ffa_memory_region_attributes {
1095 /** The ID of the VM to which the memory is being given or shared. */
J-Alves19e20cf2023-08-02 12:48:55 +01001096 ffa_id_t receiver;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001097 /**
1098 * The permissions with which the memory region should be mapped in the
1099 * receiver's page table.
1100 */
1101 ffa_memory_access_permissions_t permissions;
1102 /**
1103 * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP
1104 * for memory regions with multiple borrowers.
1105 */
1106 ffa_memory_receiver_flags_t flags;
1107};
1108
1109/** Flags to control the behaviour of a memory sharing transaction. */
1110typedef uint32_t ffa_memory_region_flags_t;
1111
1112/**
1113 * Clear memory region contents after unmapping it from the sender and before
1114 * mapping it for any receiver.
1115 */
1116#define FFA_MEMORY_REGION_FLAG_CLEAR 0x1
1117
1118/**
1119 * Whether the hypervisor may time slice the memory sharing or retrieval
1120 * operation.
1121 */
1122#define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2
1123
1124/**
1125 * Whether the hypervisor should clear the memory region after the receiver
1126 * relinquishes it or is aborted.
1127 */
1128#define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4
1129
J-Alves3456e032023-07-20 12:20:05 +01001130/**
1131 * On retrieve request, bypass the multi-borrower check.
1132 */
1133#define FFA_MEMORY_REGION_FLAG_BYPASS_BORROWERS_CHECK (0x1U << 10)
1134
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001135#define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3)
1136#define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3)
1137#define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3)
1138#define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3)
1139#define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3)
1140
Federico Recanati85090c42021-12-15 13:17:54 +01001141#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_VALID ((0x1U) << 9)
1142#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_MASK ((0xFU) << 5)
1143
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001144/**
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001145 * Struct to store the impdef value seen in Table 11.16 of the
1146 * FF-A v1.2 ALP0 specification "Endpoint memory access descriptor".
1147 */
1148struct ffa_memory_access_impdef {
1149 uint64_t val[2];
1150};
1151
Daniel Boulbye0ca9a02024-03-05 18:40:59 +00001152static inline struct ffa_memory_access_impdef ffa_memory_access_impdef_init(
1153 uint64_t impdef_hi, uint64_t impdef_lo)
1154{
1155 return (struct ffa_memory_access_impdef){{impdef_hi, impdef_lo}};
1156}
1157
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001158/**
J-Alves0b6653d2022-04-22 13:17:38 +01001159 * This corresponds to table 10.16 of the FF-A v1.1 EAC0 specification,
1160 * "Endpoint memory access descriptor".
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001161 */
1162struct ffa_memory_access {
1163 struct ffa_memory_region_attributes receiver_permissions;
1164 /**
1165 * Offset in bytes from the start of the outer `ffa_memory_region` to
1166 * an `ffa_composite_memory_region` struct.
1167 */
1168 uint32_t composite_memory_region_offset;
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001169 struct ffa_memory_access_impdef impdef;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001170 uint64_t reserved_0;
1171};
1172
J-Alves363f5722022-04-25 17:37:37 +01001173/** The maximum number of recipients a memory region may be sent to. */
J-Alvesba0e6172022-04-25 17:41:40 +01001174#define MAX_MEM_SHARE_RECIPIENTS UINT32_C(2)
J-Alves363f5722022-04-25 17:37:37 +01001175
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001176/**
1177 * Information about a set of pages which are being shared. This corresponds to
J-Alves0b6653d2022-04-22 13:17:38 +01001178 * table 10.20 of the FF-A v1.1 EAC0 specification, "Lend, donate or share
1179 * memory transaction descriptor". Note that it is also used for retrieve
1180 * requests and responses.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001181 */
1182struct ffa_memory_region {
1183 /**
1184 * The ID of the VM which originally sent the memory region, i.e. the
1185 * owner.
1186 */
J-Alves19e20cf2023-08-02 12:48:55 +01001187 ffa_id_t sender;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001188 ffa_memory_attributes_t attributes;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001189 /** Flags to control behaviour of the transaction. */
1190 ffa_memory_region_flags_t flags;
1191 ffa_memory_handle_t handle;
1192 /**
1193 * An implementation defined value associated with the receiver and the
1194 * memory region.
1195 */
1196 uint64_t tag;
J-Alves0b6653d2022-04-22 13:17:38 +01001197 /* Size of the memory access descriptor. */
1198 uint32_t memory_access_desc_size;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001199 /**
1200 * The number of `ffa_memory_access` entries included in this
1201 * transaction.
1202 */
1203 uint32_t receiver_count;
1204 /**
J-Alves0b6653d2022-04-22 13:17:38 +01001205 * Offset of the 'receivers' field, which relates to the memory access
1206 * descriptors.
1207 */
1208 uint32_t receivers_offset;
1209 /** Reserved field (12 bytes) must be 0. */
1210 uint32_t reserved[3];
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001211};
1212
1213/**
1214 * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table
J-Alves0b6653d2022-04-22 13:17:38 +01001215 * 16.25 of the FF-A v1.1 EAC0 specification, "Descriptor to relinquish a memory
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001216 * region".
1217 */
1218struct ffa_mem_relinquish {
1219 ffa_memory_handle_t handle;
1220 ffa_memory_region_flags_t flags;
1221 uint32_t endpoint_count;
J-Alves19e20cf2023-08-02 12:48:55 +01001222 ffa_id_t endpoints[];
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001223};
1224
1225/**
Daniel Boulby59ffee92023-11-02 18:26:26 +00001226 * Returns the first FF-A version that matches the memory access descriptor
1227 * size.
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001228 */
1229uint32_t ffa_version_from_memory_access_desc_size(
1230 uint32_t memory_access_desc_size);
1231
1232/**
Daniel Boulbyc7dc9322023-10-27 15:12:07 +01001233 * Returns the first FF-A version that matches the memory access descriptor
1234 * size.
1235 */
1236uint32_t ffa_version_from_memory_access_desc_size(
1237 uint32_t memory_access_desc_size);
1238
1239/**
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001240 * To maintain forwards compatability we can't make assumptions about the size
1241 * of the endpoint memory access descriptor so provide a helper function
1242 * to get a receiver from the receiver array using the memory access descriptor
1243 * size field from the memory region descriptor struct.
1244 * Returns NULL if we cannot return the receiver.
1245 */
1246static inline struct ffa_memory_access *ffa_memory_region_get_receiver(
1247 struct ffa_memory_region *memory_region, uint32_t receiver_index)
1248{
1249 uint32_t memory_access_desc_size =
1250 memory_region->memory_access_desc_size;
1251
1252 if (receiver_index >= memory_region->receiver_count) {
1253 return NULL;
1254 }
1255
1256 /*
1257 * Memory access descriptor size cannot be greater than the size of
1258 * the memory access descriptor defined by the current FF-A version.
1259 */
1260 if (memory_access_desc_size > sizeof(struct ffa_memory_access)) {
1261 return NULL;
1262 }
1263
Daniel Boulby41ef8ba2023-10-13 17:01:22 +01001264 /* Check we cannot use receivers offset to cause overflow. */
1265 if (memory_region->receivers_offset !=
1266 sizeof(struct ffa_memory_region)) {
1267 return NULL;
1268 }
1269
1270 return (struct ffa_memory_access *)((uint8_t *)memory_region +
1271 memory_region->receivers_offset +
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001272 (receiver_index *
1273 memory_access_desc_size));
1274}
1275
1276/**
Daniel Boulby59ffee92023-11-02 18:26:26 +00001277 * Gets the receiver's access permissions from 'struct ffa_memory_region' and
1278 * returns its index in the receiver's array. If receiver's ID doesn't exist
1279 * in the array, return the region's 'receivers_count'.
1280 */
1281static inline uint32_t ffa_memory_region_get_receiver_index(
1282 struct ffa_memory_region *memory_region, ffa_id_t receiver_id)
1283{
1284 uint32_t i;
1285
1286 for (i = 0U; i < memory_region->receiver_count; i++) {
1287 struct ffa_memory_access *receiver =
1288 ffa_memory_region_get_receiver(memory_region, i);
1289 if (receiver->receiver_permissions.receiver == receiver_id) {
1290 break;
1291 }
1292 }
1293
1294 return i;
1295}
1296
1297/**
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001298 * Gets the `ffa_composite_memory_region` for the given receiver from an
1299 * `ffa_memory_region`, or NULL if it is not valid.
1300 */
1301static inline struct ffa_composite_memory_region *
1302ffa_memory_region_get_composite(struct ffa_memory_region *memory_region,
1303 uint32_t receiver_index)
1304{
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001305 struct ffa_memory_access *receiver =
1306 ffa_memory_region_get_receiver(memory_region, receiver_index);
1307 uint32_t offset;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001308
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001309 if (receiver == NULL) {
1310 return NULL;
1311 }
1312
1313 offset = receiver->composite_memory_region_offset;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001314 if (offset == 0) {
1315 return NULL;
1316 }
1317
1318 return (struct ffa_composite_memory_region *)((uint8_t *)memory_region +
1319 offset);
1320}
1321
1322static inline uint32_t ffa_mem_relinquish_init(
1323 struct ffa_mem_relinquish *relinquish_request,
1324 ffa_memory_handle_t handle, ffa_memory_region_flags_t flags,
J-Alves19e20cf2023-08-02 12:48:55 +01001325 ffa_id_t sender)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001326{
1327 relinquish_request->handle = handle;
1328 relinquish_request->flags = flags;
1329 relinquish_request->endpoint_count = 1;
1330 relinquish_request->endpoints[0] = sender;
J-Alves19e20cf2023-08-02 12:48:55 +01001331 return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_id_t);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001332}
1333
J-Alves126ab502022-09-29 11:37:33 +01001334void ffa_copy_memory_region_constituents(
1335 struct ffa_memory_region_constituent *dest,
1336 const struct ffa_memory_region_constituent *src);
1337
Karl Meakin0fd67292024-02-06 17:33:05 +00001338struct ffa_features_rxtx_map_params {
1339 /*
1340 * Bit[0:1]:
1341 * Minimum buffer size and alignment boundary:
1342 * 0b00: 4K
1343 * 0b01: 64K
1344 * 0b10: 16K
1345 * 0b11: Reserved
1346 */
1347 uint8_t min_buf_size : 2;
1348 /*
1349 * Bit[2:15]:
1350 * Reserved (MBZ)
1351 */
1352 uint16_t mbz : 14;
1353 /*
1354 * Bit[16:32]:
1355 * Maximum buffer size in number of pages
1356 * Only present on version 1.2 or later
1357 */
1358 uint16_t max_buf_size : 16;
1359};
1360
1361#define FFA_RXTX_MAP_MIN_BUF_4K 0
1362#define FFA_RXTX_MAP_MAX_BUF_PAGE_COUNT 1
1363
Karl Meakinf7861302024-02-20 14:39:33 +00001364static inline struct ffa_features_rxtx_map_params ffa_features_rxtx_map_params(
1365 struct ffa_value args)
1366{
1367 struct ffa_features_rxtx_map_params params;
1368 uint32_t arg2 = args.arg2;
1369
1370 params = *(struct ffa_features_rxtx_map_params *)(&arg2);
1371
1372 return params;
1373}
1374
Federico Recanati392be392022-02-08 20:53:03 +01001375/**
1376 * Endpoint RX/TX descriptor, as defined by Table 13.27 in FF-A v1.1 EAC0.
1377 * It's used by the Hypervisor to describe the RX/TX buffers mapped by a VM
1378 * to the SPMC, in order to allow indirect messaging.
1379 */
1380struct ffa_endpoint_rx_tx_descriptor {
J-Alves19e20cf2023-08-02 12:48:55 +01001381 ffa_id_t endpoint_id;
Federico Recanati392be392022-02-08 20:53:03 +01001382 uint16_t reserved;
1383
1384 /*
1385 * 8-byte aligned offset from the base address of this descriptor to the
1386 * `ffa_composite_memory_region` describing the RX buffer.
1387 */
1388 uint32_t rx_offset;
1389
1390 /*
1391 * 8-byte aligned offset from the base address of this descriptor to the
1392 * `ffa_composite_memory_region` describing the TX buffer.
1393 */
1394 uint32_t tx_offset;
1395
1396 /* Pad to align on 16-byte boundary. */
1397 uint32_t pad;
1398};
1399
1400static inline struct ffa_composite_memory_region *
Karl Meakinb9705e22024-04-05 13:58:28 +01001401ffa_endpoint_get_rx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
Federico Recanati392be392022-02-08 20:53:03 +01001402{
1403 return (struct ffa_composite_memory_region *)((uintptr_t)desc +
1404 desc->rx_offset);
1405}
1406
1407static inline struct ffa_composite_memory_region *
Karl Meakinb9705e22024-04-05 13:58:28 +01001408ffa_endpoint_get_tx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
Federico Recanati392be392022-02-08 20:53:03 +01001409{
1410 return (struct ffa_composite_memory_region *)((uintptr_t)desc +
1411 desc->tx_offset);
1412}
1413
J-Alves2d8457f2022-10-05 11:06:41 +01001414void ffa_memory_region_init_header(struct ffa_memory_region *memory_region,
J-Alves19e20cf2023-08-02 12:48:55 +01001415 ffa_id_t sender,
J-Alves2d8457f2022-10-05 11:06:41 +01001416 ffa_memory_attributes_t attributes,
1417 ffa_memory_region_flags_t flags,
1418 ffa_memory_handle_t handle, uint32_t tag,
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001419 uint32_t receiver_count,
1420 uint32_t receiver_desc_size);
Daniel Boulby59ffee92023-11-02 18:26:26 +00001421void ffa_memory_access_init(struct ffa_memory_access *receiver,
1422 ffa_id_t receiver_id,
1423 enum ffa_data_access data_access,
1424 enum ffa_instruction_access instruction_access,
1425 ffa_memory_receiver_flags_t flags,
1426 struct ffa_memory_access_impdef *impdef_val);
J-Alves45085432022-04-22 16:19:20 +01001427uint32_t ffa_memory_region_init_single_receiver(
Andrew Walbranca808b12020-05-15 17:22:28 +01001428 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
J-Alves19e20cf2023-08-02 12:48:55 +01001429 ffa_id_t sender, ffa_id_t receiver,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001430 const struct ffa_memory_region_constituent constituents[],
1431 uint32_t constituent_count, uint32_t tag,
1432 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
1433 enum ffa_instruction_access instruction_access,
1434 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
Daniel Boulby59ffee92023-11-02 18:26:26 +00001435 enum ffa_memory_shareability shareability,
1436 struct ffa_memory_access_impdef *impdef_val, uint32_t *fragment_length,
Andrew Walbranca808b12020-05-15 17:22:28 +01001437 uint32_t *total_length);
J-Alvesf4eecf72022-07-20 16:05:34 +01001438uint32_t ffa_memory_region_init(
1439 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
J-Alves19e20cf2023-08-02 12:48:55 +01001440 ffa_id_t sender, struct ffa_memory_access receivers[],
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001441 uint32_t receiver_count, uint32_t receiver_desc_size,
J-Alvesf4eecf72022-07-20 16:05:34 +01001442 const struct ffa_memory_region_constituent constituents[],
1443 uint32_t constituent_count, uint32_t tag,
1444 ffa_memory_region_flags_t flags, enum ffa_memory_type type,
1445 enum ffa_memory_cacheability cacheability,
1446 enum ffa_memory_shareability shareability, uint32_t *fragment_length,
1447 uint32_t *total_length);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001448uint32_t ffa_memory_retrieve_request_init(
1449 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves19e20cf2023-08-02 12:48:55 +01001450 ffa_id_t sender, struct ffa_memory_access receivers[],
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001451 uint32_t receiver_count, uint32_t receiver_desc_size, uint32_t tag,
1452 ffa_memory_region_flags_t flags, enum ffa_memory_type type,
1453 enum ffa_memory_cacheability cacheability,
J-Alves9b24ed82022-08-04 13:12:45 +01001454 enum ffa_memory_shareability shareability);
1455uint32_t ffa_memory_retrieve_request_init_single_receiver(
1456 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves19e20cf2023-08-02 12:48:55 +01001457 ffa_id_t sender, ffa_id_t receiver, uint32_t tag,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001458 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
1459 enum ffa_instruction_access instruction_access,
1460 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
Daniel Boulby59ffee92023-11-02 18:26:26 +00001461 enum ffa_memory_shareability shareability,
1462 struct ffa_memory_access_impdef *impdef_val);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001463uint32_t ffa_memory_lender_retrieve_request_init(
1464 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves19e20cf2023-08-02 12:48:55 +01001465 ffa_id_t sender);
Andrew Walbranca808b12020-05-15 17:22:28 +01001466uint32_t ffa_memory_fragment_init(
1467 struct ffa_memory_region_constituent *fragment,
1468 size_t fragment_max_size,
1469 const struct ffa_memory_region_constituent constituents[],
1470 uint32_t constituent_count, uint32_t *fragment_length);
Federico Recanati392be392022-02-08 20:53:03 +01001471void ffa_endpoint_rx_tx_descriptor_init(
J-Alves19e20cf2023-08-02 12:48:55 +01001472 struct ffa_endpoint_rx_tx_descriptor *desc, ffa_id_t endpoint_id,
Federico Recanati392be392022-02-08 20:53:03 +01001473 uint64_t rx_address, uint64_t tx_address);