blob: 240de5e7b6e987d71ef32624aa095d9bdf2db3dc [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
Karl Meakin0e617d92024-04-05 12:55:22 +010013/**
14 * The version number of a Firmware Framework implementation is a 31-bit
15 * unsigned integer, with the upper 15 bits denoting the major revision,
16 * and the lower 16 bits denoting the minor revision.
17 *
18 * See FF-A specification v1.2 ALP1, section 13.2.1.
19 */
Karl Meakin0dba87e2025-03-24 17:36:04 +000020enum ffa_version : uint32_t {
Karl Meakin0e617d92024-04-05 12:55:22 +010021 FFA_VERSION_1_0 = 0x10000,
22 FFA_VERSION_1_1 = 0x10001,
23 FFA_VERSION_1_2 = 0x10002,
Karl Meakin59352b32025-02-25 12:19:45 +000024/*
25 * Use the value of `FFA_VERSION` passed by the build system, otherwise default
26 * to latest FF-A version.
27 */
28#ifdef FFA_VERSION
29 FFA_VERSION_COMPILED = FFA_VERSION,
30#else
Karl Meakin0e617d92024-04-05 12:55:22 +010031 FFA_VERSION_COMPILED = FFA_VERSION_1_2,
Karl Meakin59352b32025-02-25 12:19:45 +000032#endif
Karl Meakin0e617d92024-04-05 12:55:22 +010033};
Daniel Boulby6e32c612021-02-17 15:09:41 +000034
Karl Meakin59352b32025-02-25 12:19:45 +000035static_assert((FFA_VERSION_1_0 <= FFA_VERSION_COMPILED) &&
36 (FFA_VERSION_1_2 >= FFA_VERSION_COMPILED),
37 "FFA_VERSION_COMPILED must be between v1.0 and v1.2");
38
Karl Meakin0e617d92024-04-05 12:55:22 +010039#define FFA_VERSION_MBZ_BIT (1U << 31U)
40#define FFA_VERSION_MAJOR_SHIFT (16U)
41#define FFA_VERSION_MAJOR_MASK (0x7FFFU)
42#define FFA_VERSION_MINOR_SHIFT (0U)
43#define FFA_VERSION_MINOR_MASK (0xFFFFU)
44
45/** Return true if the version is valid (i.e. bit 31 is 0). */
46static inline bool ffa_version_is_valid(uint32_t version)
47{
48 return (version & FFA_VERSION_MBZ_BIT) == 0;
49}
50
51/** Construct a version from a pair of major and minor components. */
52static inline enum ffa_version make_ffa_version(uint16_t major, uint16_t minor)
53{
54 return (enum ffa_version)((major << FFA_VERSION_MAJOR_SHIFT) |
55 (minor << FFA_VERSION_MINOR_SHIFT));
56}
57
58/** Get the major component of the version. */
59static inline uint16_t ffa_version_get_major(enum ffa_version version)
60{
61 return (version >> FFA_VERSION_MAJOR_SHIFT) & FFA_VERSION_MAJOR_MASK;
62}
63
64/** Get the minor component of the version. */
65static inline uint16_t ffa_version_get_minor(enum ffa_version version)
66{
67 return (version >> FFA_VERSION_MINOR_SHIFT) & FFA_VERSION_MINOR_MASK;
68}
Olivier Deprez62d99e32020-01-09 15:58:07 +010069
Daniel Boulbyc7dc9322023-10-27 15:12:07 +010070/**
71 * Check major versions are equal and the minor version of the caller is
72 * less than or equal to the minor version of the callee.
73 */
Karl Meakin0e617d92024-04-05 12:55:22 +010074static inline bool ffa_versions_are_compatible(enum ffa_version caller,
75 enum ffa_version callee)
76{
77 return ffa_version_get_major(caller) == ffa_version_get_major(callee) &&
78 ffa_version_get_minor(caller) <= ffa_version_get_minor(callee);
79}
Daniel Boulbyc7dc9322023-10-27 15:12:07 +010080
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010081/* clang-format off */
82
83#define FFA_LOW_32_ID 0x84000060
84#define FFA_HIGH_32_ID 0x8400007F
85#define FFA_LOW_64_ID 0xC4000060
Fuad Tabbada72d142020-07-30 09:17:05 +010086#define FFA_HIGH_64_ID 0xC400007F
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010087
Karl Meakinf51a35f2023-08-07 17:53:52 +010088/**
89 * FF-A function identifiers.
90 * Don't forget to update `ffa_func_name` if you add a new one.
91 */
Karl Meakinadf6daf2025-03-19 15:29:31 +000092enum ffa_function : uint32_t {
93 FFA_ERROR_32 = 0x84000060,
94 FFA_SUCCESS_32 = 0x84000061,
95 FFA_SUCCESS_64 = 0xC4000061,
96 FFA_INTERRUPT_32 = 0x84000062,
97 FFA_VERSION_32 = 0x84000063,
98 FFA_FEATURES_32 = 0x84000064,
99 FFA_RX_RELEASE_32 = 0x84000065,
100 FFA_RXTX_MAP_32 = 0x84000066,
101 FFA_RXTX_MAP_64 = 0xC4000066,
102 FFA_RXTX_UNMAP_32 = 0x84000067,
103 FFA_PARTITION_INFO_GET_32 = 0x84000068,
104 FFA_ID_GET_32 = 0x84000069,
105 FFA_MSG_POLL_32 = 0x8400006A, /* Legacy FF-A v1.0 */
106 FFA_MSG_WAIT_32 = 0x8400006B,
107 FFA_YIELD_32 = 0x8400006C,
108 FFA_RUN_32 = 0x8400006D,
109 FFA_MSG_SEND_32 = 0x8400006E, /* Legacy FF-A v1.0 */
110 FFA_MSG_SEND_DIRECT_REQ_32 = 0x8400006F,
111 FFA_MSG_SEND_DIRECT_REQ_64 = 0xC400006F,
112 FFA_MSG_SEND_DIRECT_RESP_32 = 0x84000070,
113 FFA_MSG_SEND_DIRECT_RESP_64 = 0xC4000070,
114 FFA_MEM_DONATE_32 = 0x84000071,
115 FFA_MEM_DONATE_64 = 0xC4000071,
116 FFA_MEM_LEND_32 = 0x84000072,
117 FFA_MEM_LEND_64 = 0xC4000072,
118 FFA_MEM_SHARE_32 = 0x84000073,
119 FFA_MEM_SHARE_64 = 0xC4000073,
120 FFA_MEM_RETRIEVE_REQ_32 = 0x84000074,
121 FFA_MEM_RETRIEVE_REQ_64 = 0xC4000074,
122 FFA_MEM_RETRIEVE_RESP_32 = 0x84000075,
123 FFA_MEM_RELINQUISH_32 = 0x84000076,
124 FFA_MEM_RECLAIM_32 = 0x84000077,
125 FFA_MEM_FRAG_RX_32 = 0x8400007A,
126 FFA_MEM_FRAG_TX_32 = 0x8400007B,
127 FFA_NORMAL_WORLD_RESUME = 0x8400007C,
J-Alves3829fc02021-03-18 12:49:18 +0000128
Karl Meakinadf6daf2025-03-19 15:29:31 +0000129 /* FF-A v1.1 */
130 FFA_NOTIFICATION_BITMAP_CREATE_32 = 0x8400007D,
131 FFA_NOTIFICATION_BITMAP_DESTROY_32 = 0x8400007E,
132 FFA_NOTIFICATION_BIND_32 = 0x8400007F,
133 FFA_NOTIFICATION_UNBIND_32 = 0x84000080,
134 FFA_NOTIFICATION_SET_32 = 0x84000081,
135 FFA_NOTIFICATION_GET_32 = 0x84000082,
136 FFA_NOTIFICATION_INFO_GET_64 = 0xC4000083,
137 FFA_RX_ACQUIRE_32 = 0x84000084,
138 FFA_SPM_ID_GET_32 = 0x84000085,
139 FFA_MSG_SEND2_32 = 0x84000086,
140 FFA_SECONDARY_EP_REGISTER_64 = 0xC4000087,
141 FFA_MEM_PERM_GET_32 = 0x84000088,
142 FFA_MEM_PERM_SET_32 = 0x84000089,
143 FFA_MEM_PERM_GET_64 = 0xC4000088,
144 FFA_MEM_PERM_SET_64 = 0xC4000089,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100145
Karl Meakinadf6daf2025-03-19 15:29:31 +0000146 /* FF-A v1.2 */
147 FFA_CONSOLE_LOG_32 = 0x8400008A,
148 FFA_CONSOLE_LOG_64 = 0xC400008A,
149 FFA_PARTITION_INFO_GET_REGS_64 = 0xC400008B,
150 FFA_EL3_INTR_HANDLE_32 = 0x8400008C,
151 FFA_MSG_SEND_DIRECT_REQ2_64 = 0xC400008D,
152 FFA_MSG_SEND_DIRECT_RESP2_64 = 0xC400008E,
153};
Maksims Svecovs71b76702022-05-20 15:32:58 +0100154
Karl Meakinf51a35f2023-08-07 17:53:52 +0100155/**
156 * FF-A error codes.
157 * Don't forget to update `ffa_error_name` if you add a new one.
Karl Meakin0dba87e2025-03-24 17:36:04 +0000158 *
159 * NOTE: Error codes have negative values, but we set the underlying type of the
160 * enum to `uint32_t` because it is more convenient to treat them as unsigned
161 * values: the SMCC calling convention specifies that signed 32 bit values must
162 * be zero-extended when passed in 64-bit registers (ie the upper 32 bits must
163 * be zero).
Karl Meakinf51a35f2023-08-07 17:53:52 +0100164 */
Karl Meakin0dba87e2025-03-24 17:36:04 +0000165enum ffa_error : uint32_t {
166 FFA_NOT_SUPPORTED = UINT32_C(-1),
167 FFA_INVALID_PARAMETERS = UINT32_C(-2),
168 FFA_NO_MEMORY = UINT32_C(-3),
169 FFA_BUSY = UINT32_C(-4),
170 FFA_INTERRUPTED = UINT32_C(-5),
171 FFA_DENIED = UINT32_C(-6),
172 FFA_RETRY = UINT32_C(-7),
173 FFA_ABORTED = UINT32_C(-8),
174 FFA_NO_DATA = UINT32_C(-9),
175 FFA_NOT_READY = UINT32_C(-10),
Karl Meakindc759f52024-05-07 16:08:02 +0100176};
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100177
178/* clang-format on */
179
Karl Meakinf51a35f2023-08-07 17:53:52 +0100180/* Return the name of the function identifier. */
Karl Meakinadf6daf2025-03-19 15:29:31 +0000181static inline const char *ffa_func_name(enum ffa_function func)
Karl Meakinf51a35f2023-08-07 17:53:52 +0100182{
183 switch (func) {
184 case FFA_ERROR_32:
185 return "FFA_ERROR_32";
186 case FFA_SUCCESS_32:
187 return "FFA_SUCCESS_32";
188 case FFA_SUCCESS_64:
189 return "FFA_SUCCESS_64";
190 case FFA_INTERRUPT_32:
191 return "FFA_INTERRUPT_32";
192 case FFA_VERSION_32:
193 return "FFA_VERSION_32";
194 case FFA_FEATURES_32:
195 return "FFA_FEATURES_32";
196 case FFA_RX_RELEASE_32:
197 return "FFA_RX_RELEASE_32";
198 case FFA_RXTX_MAP_32:
199 return "FFA_RXTX_MAP_32";
200 case FFA_RXTX_MAP_64:
201 return "FFA_RXTX_MAP_64";
202 case FFA_RXTX_UNMAP_32:
203 return "FFA_RXTX_UNMAP_32";
204 case FFA_PARTITION_INFO_GET_32:
205 return "FFA_PARTITION_INFO_GET_32";
206 case FFA_ID_GET_32:
207 return "FFA_ID_GET_32";
208 case FFA_MSG_POLL_32:
209 return "FFA_MSG_POLL_32";
210 case FFA_MSG_WAIT_32:
211 return "FFA_MSG_WAIT_32";
212 case FFA_YIELD_32:
213 return "FFA_YIELD_32";
214 case FFA_RUN_32:
215 return "FFA_RUN_32";
216 case FFA_MSG_SEND_32:
217 return "FFA_MSG_SEND_32";
218 case FFA_MSG_SEND_DIRECT_REQ_32:
219 return "FFA_MSG_SEND_DIRECT_REQ_32";
220 case FFA_MSG_SEND_DIRECT_REQ_64:
221 return "FFA_MSG_SEND_DIRECT_REQ_64";
222 case FFA_MSG_SEND_DIRECT_RESP_32:
223 return "FFA_MSG_SEND_DIRECT_RESP_32";
224 case FFA_MSG_SEND_DIRECT_RESP_64:
225 return "FFA_MSG_SEND_DIRECT_RESP_64";
226 case FFA_MEM_DONATE_32:
227 return "FFA_MEM_DONATE_32";
228 case FFA_MEM_LEND_32:
229 return "FFA_MEM_LEND_32";
230 case FFA_MEM_SHARE_32:
231 return "FFA_MEM_SHARE_32";
232 case FFA_MEM_RETRIEVE_REQ_32:
233 return "FFA_MEM_RETRIEVE_REQ_32";
J-Alves95fbb312024-03-20 15:19:16 +0000234 case FFA_MEM_DONATE_64:
235 return "FFA_MEM_DONATE_64";
236 case FFA_MEM_LEND_64:
237 return "FFA_MEM_LEND_64";
238 case FFA_MEM_SHARE_64:
239 return "FFA_MEM_SHARE_64";
240 case FFA_MEM_RETRIEVE_REQ_64:
241 return "FFA_MEM_RETRIEVE_REQ_64";
Karl Meakinf51a35f2023-08-07 17:53:52 +0100242 case FFA_MEM_RETRIEVE_RESP_32:
243 return "FFA_MEM_RETRIEVE_RESP_32";
244 case FFA_MEM_RELINQUISH_32:
245 return "FFA_MEM_RELINQUISH_32";
246 case FFA_MEM_RECLAIM_32:
247 return "FFA_MEM_RECLAIM_32";
248 case FFA_MEM_FRAG_RX_32:
249 return "FFA_MEM_FRAG_RX_32";
250 case FFA_MEM_FRAG_TX_32:
251 return "FFA_MEM_FRAG_TX_32";
252 case FFA_NORMAL_WORLD_RESUME:
253 return "FFA_NORMAL_WORLD_RESUME";
254
255 /* FF-A v1.1 */
256 case FFA_NOTIFICATION_BITMAP_CREATE_32:
257 return "FFA_NOTIFICATION_BITMAP_CREATE_32";
258 case FFA_NOTIFICATION_BITMAP_DESTROY_32:
259 return "FFA_NOTIFICATION_BITMAP_DESTROY_32";
260 case FFA_NOTIFICATION_BIND_32:
261 return "FFA_NOTIFICATION_BIND_32";
262 case FFA_NOTIFICATION_UNBIND_32:
263 return "FFA_NOTIFICATION_UNBIND_32";
264 case FFA_NOTIFICATION_SET_32:
265 return "FFA_NOTIFICATION_SET_32";
266 case FFA_NOTIFICATION_GET_32:
267 return "FFA_NOTIFICATION_GET_32";
268 case FFA_NOTIFICATION_INFO_GET_64:
269 return "FFA_NOTIFICATION_INFO_GET_64";
270 case FFA_RX_ACQUIRE_32:
271 return "FFA_RX_ACQUIRE_32";
272 case FFA_SPM_ID_GET_32:
273 return "FFA_SPM_ID_GET_32";
274 case FFA_MSG_SEND2_32:
275 return "FFA_MSG_SEND2_32";
276 case FFA_SECONDARY_EP_REGISTER_64:
277 return "FFA_SECONDARY_EP_REGISTER_64";
278 case FFA_MEM_PERM_GET_32:
279 return "FFA_MEM_PERM_GET_32";
280 case FFA_MEM_PERM_SET_32:
281 return "FFA_MEM_PERM_SET_32";
282 case FFA_MEM_PERM_GET_64:
283 return "FFA_MEM_PERM_GET_64";
284 case FFA_MEM_PERM_SET_64:
285 return "FFA_MEM_PERM_SET_64";
286
287 /* Implementation-defined ABIs. */
288 case FFA_CONSOLE_LOG_32:
289 return "FFA_CONSOLE_LOG_32";
290 case FFA_CONSOLE_LOG_64:
291 return "FFA_CONSOLE_LOG_64";
292 case FFA_PARTITION_INFO_GET_REGS_64:
293 return "FFA_PARTITION_INFO_GET_REGS_64";
294 case FFA_EL3_INTR_HANDLE_32:
295 return "FFA_EL3_INTR_HANDLE_32";
Karl Meakinadf6daf2025-03-19 15:29:31 +0000296 case FFA_MSG_SEND_DIRECT_REQ2_64:
297 return "FFA_MSG_SEND_DIRECT_REQ2_64";
298 case FFA_MSG_SEND_DIRECT_RESP2_64:
299 return "FFA_MSG_SEND_DIRECT_REQ2_64 ";
Karl Meakinf51a35f2023-08-07 17:53:52 +0100300 }
Karl Meakinadf6daf2025-03-19 15:29:31 +0000301 return "UNKNOWN";
Karl Meakinf51a35f2023-08-07 17:53:52 +0100302}
303
304/* Return the name of the error code. */
Karl Meakindc759f52024-05-07 16:08:02 +0100305static inline const char *ffa_error_name(enum ffa_error error)
Karl Meakinf51a35f2023-08-07 17:53:52 +0100306{
307 switch (error) {
308 case FFA_NOT_SUPPORTED:
309 return "FFA_NOT_SUPPORTED";
310 case FFA_INVALID_PARAMETERS:
311 return "FFA_INVALID_PARAMETERS";
312 case FFA_NO_MEMORY:
313 return "FFA_NO_MEMORY";
314 case FFA_BUSY:
315 return "FFA_BUSY";
316 case FFA_INTERRUPTED:
317 return "FFA_INTERRUPTED";
318 case FFA_DENIED:
319 return "FFA_DENIED";
320 case FFA_RETRY:
321 return "FFA_RETRY";
322 case FFA_ABORTED:
323 return "FFA_ABORTED";
324 case FFA_NO_DATA:
325 return "FFA_NO_DATA";
Karl Meakindc759f52024-05-07 16:08:02 +0100326 case FFA_NOT_READY:
327 return "FFA_NOT_READY";
Karl Meakinf51a35f2023-08-07 17:53:52 +0100328 }
Karl Meakindc759f52024-05-07 16:08:02 +0100329 return "UNKNOWN";
Karl Meakinf51a35f2023-08-07 17:53:52 +0100330}
331
J-Alves6f72ca82021-11-01 12:34:58 +0000332/**
Karl Meakin49ec1e42024-05-10 13:08:24 +0100333 * Defined in Table 3.1 in the FF-A v.1.2 memory management supplement.
334 * Input properties:
335 * - Bits[31:2] and Bit[0] are reserved (SBZ).
336 * Output properties:
337 * - Bit[0]: dynamically allocated buffer support.
338 * - Bit[1]: NS bit handling.
339 * - Bit[2]: support for retrieval by hypervisor.
340 * - Bits[31:3] are reserved (MBZ).
J-Alves6f72ca82021-11-01 12:34:58 +0000341 */
Karl Meakin49ec1e42024-05-10 13:08:24 +0100342#define FFA_FEATURES_MEM_RETRIEVE_REQ_BUFFER_SUPPORT (0U << 0U)
343#define FFA_FEATURES_MEM_RETRIEVE_REQ_NS_SUPPORT (1U << 1U)
344#define FFA_FEATURES_MEM_RETRIEVE_REQ_HYPERVISOR_SUPPORT (1U << 2U)
J-Alves6f72ca82021-11-01 12:34:58 +0000345
Karl Meakin49ec1e42024-05-10 13:08:24 +0100346#define FFA_FEATURES_MEM_RETRIEVE_REQ_MBZ_HI_BIT (31U)
347#define FFA_FEATURES_MEM_RETRIEVE_REQ_MBZ_LO_BIT (2U)
348#define FFA_FEATURES_MEM_RETRIEVE_REQ_MBZ_BIT (0U)
J-Alves6f72ca82021-11-01 12:34:58 +0000349
Karl Meakin0dba87e2025-03-24 17:36:04 +0000350enum ffa_feature_id : uint32_t {
Karl Meakin49ec1e42024-05-10 13:08:24 +0100351 /* Query interrupt ID of Notification Pending Interrupt. */
352 FFA_FEATURE_NPI = 1,
Karl Meakin34b8ae92023-01-13 13:33:07 +0000353
Karl Meakin49ec1e42024-05-10 13:08:24 +0100354 /* Query interrupt ID of Schedule Receiver Interrupt. */
355 FFA_FEATURE_SRI = 2,
J-Alves6f72ca82021-11-01 12:34:58 +0000356
Karl Meakin49ec1e42024-05-10 13:08:24 +0100357 /* Query interrupt ID of the Managed Exit Interrupt. */
358 FFA_FEATURE_MEI = 3,
359};
J-Alves6f72ca82021-11-01 12:34:58 +0000360
Karl Meakin49ec1e42024-05-10 13:08:24 +0100361/** Constants for bitmasks used in FFA_FEATURES. */
362#define FFA_FEATURES_FEATURE_BIT (31U)
363#define FFA_FEATURES_FEATURE_MBZ_HI_BIT (30U)
364#define FFA_FEATURES_FEATURE_MBZ_LO_BIT (8U)
365
366#define FFA_FEATURES_NS_SUPPORT_BIT (1U)
J-Alves6f72ca82021-11-01 12:34:58 +0000367
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100368/* FF-A function specific constants. */
369#define FFA_MSG_RECV_BLOCK 0x1
370#define FFA_MSG_RECV_BLOCK_MASK 0x1
371
372#define FFA_MSG_SEND_NOTIFY 0x1
373#define FFA_MSG_SEND_NOTIFY_MASK 0x1
374
375#define FFA_MEM_RECLAIM_CLEAR 0x1
376
377#define FFA_SLEEP_INDEFINITE 0
378
Karl Meakin80220052025-02-20 14:43:34 +0000379/*
380 * The type of memory permissions used by `FFA_MEM_PERM_GET` and
381 * `FFA_MEM_PERM_SET`.
382 */
Karl Meakin0dba87e2025-03-24 17:36:04 +0000383enum ffa_mem_perm : uint32_t {
Karl Meakin80220052025-02-20 14:43:34 +0000384 FFA_MEM_PERM_RO = 0x7,
385 FFA_MEM_PERM_RW = 0x5,
386 FFA_MEM_PERM_RX = 0x3,
387};
Raghu Krishnamurthyea6d25f2021-09-14 15:27:06 -0700388
Kathleen Capella7253bd52024-08-14 17:36:09 -0400389#define FFA_MSG_WAIT_FLAG_RETAIN_RX UINT32_C(0x1)
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000390/*
Olivier Deprez013f4d62022-11-21 15:46:20 +0100391 * Defined in Table 13.34 in the FF-A v1.1 EAC0 specification.
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000392 * The Partition count flag is used by FFA_PARTITION_INFO_GET to specify
393 * if partition info descriptors should be returned or just the count.
394 */
Olivier Deprez013f4d62022-11-21 15:46:20 +0100395#define FFA_PARTITION_COUNT_FLAG UINT32_C(0x1)
396#define FFA_PARTITION_COUNT_FLAG_MASK (UINT32_C(0x1) << 0)
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000397
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100398/**
399 * For use where the FF-A specification refers explicitly to '4K pages'. Not to
400 * be confused with PAGE_SIZE, which is the translation granule Hafnium is
401 * configured to use.
402 */
J-Alves715d6232023-02-16 16:33:28 +0000403#define FFA_PAGE_SIZE ((size_t)4096)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100404
Federico Recanatifc0295e2022-02-08 19:37:39 +0100405/** The ID of a VM. These are assigned sequentially starting with an offset. */
J-Alves19e20cf2023-08-02 12:48:55 +0100406typedef uint16_t ffa_id_t;
Federico Recanatifc0295e2022-02-08 19:37:39 +0100407
408/**
J-Alves661e1b72023-08-02 13:39:40 +0100409 * The FF-A v1.2 ALP0, section 6.1 defines that partition IDs are split into two
410 * parts:
411 * - Bit15 -> partition type identifier.
412 * - b'0 -> ID relates to a VM ID.
413 * - b'1 -> ID relates to an SP ID.
414 */
415#define FFA_ID_MASK ((ffa_id_t)0x8000)
416#define FFA_VM_ID_MASK ((ffa_id_t)0x0000)
417
418/**
419 * Helper to check if FF-A ID is a VM ID, managed by the hypervisor.
420 */
421static inline bool ffa_is_vm_id(ffa_id_t id)
422{
423 return (FFA_ID_MASK & id) == FFA_VM_ID_MASK;
424}
425
426/**
Karl Meakinc88c8e92024-11-29 16:13:55 +0000427 * Holds the UUID in a struct that is mappable directly to the SMCC calling
428 * convention, which is used for FF-A calls.
429 *
430 * Refer to table 84 of the FF-A 1.0 EAC specification as well as section 5.3
431 * of the SMCC Spec 1.2.
432 */
433struct ffa_uuid {
434 uint32_t uuid[4];
435};
436
437static inline void ffa_uuid_init(uint32_t w0, uint32_t w1, uint32_t w2,
438 uint32_t w3, struct ffa_uuid *uuid)
439{
440 uuid->uuid[0] = w0;
441 uuid->uuid[1] = w1;
442 uuid->uuid[2] = w2;
443 uuid->uuid[3] = w3;
444}
445
446static inline bool ffa_uuid_equal(const struct ffa_uuid *uuid1,
447 const struct ffa_uuid *uuid2)
448{
449 return (uuid1->uuid[0] == uuid2->uuid[0]) &&
450 (uuid1->uuid[1] == uuid2->uuid[1]) &&
451 (uuid1->uuid[2] == uuid2->uuid[2]) &&
452 (uuid1->uuid[3] == uuid2->uuid[3]);
453}
454
455static inline bool ffa_uuid_is_null(const struct ffa_uuid *uuid)
456{
457 struct ffa_uuid null = {0};
458
459 return ffa_uuid_equal(uuid, &null);
460}
461
462static inline void ffa_uuid_from_u64x2(uint64_t uuid_lo, uint64_t uuid_hi,
463 struct ffa_uuid *uuid)
464{
465 ffa_uuid_init((uint32_t)(uuid_lo & 0xFFFFFFFFU),
466 (uint32_t)(uuid_lo >> 32),
467 (uint32_t)(uuid_hi & 0xFFFFFFFFU),
468 (uint32_t)(uuid_hi >> 32), uuid);
469}
470
471/**
472 * Split `uuid` into two u64s.
473 * This function writes to pointer parameters because C does not allow returning
474 * arrays from functions.
475 */
476static inline void ffa_uuid_to_u64x2(uint64_t *lo, uint64_t *hi,
477 const struct ffa_uuid *uuid)
478{
479 *lo = (uint64_t)uuid->uuid[1] << 32 | uuid->uuid[0];
480 *hi = (uint64_t)uuid->uuid[3] << 32 | uuid->uuid[2];
481}
482
483/**
484 * Partition message header as specified by table 7.1 from FF-A v1.3 ALP0
Federico Recanatifc0295e2022-02-08 19:37:39 +0100485 * specification.
486 */
487struct ffa_partition_rxtx_header {
Karl Meakinbf580c22024-12-12 14:31:06 +0000488 /* Reserved (SBZ). */
489 uint32_t flags;
490 /* Reserved (SBZ). */
491 uint32_t reserved_1;
Federico Recanatifc0295e2022-02-08 19:37:39 +0100492 /* Offset from the beginning of the buffer to the message payload. */
493 uint32_t offset;
Karl Meakin9ca05512024-11-29 17:02:32 +0000494 /* Receiver endpoint ID. */
495 ffa_id_t receiver;
496 /* Sender endpoint ID. */
497 ffa_id_t sender;
Federico Recanatifc0295e2022-02-08 19:37:39 +0100498 /* Size of message in buffer. */
499 uint32_t size;
Karl Meakinbf580c22024-12-12 14:31:06 +0000500 /* Reserved (SBZ). Added in v1.2. */
501 uint32_t reserved_2;
502 /* UUID identifying the communication protocol. Added in v1.2. */
503 struct ffa_uuid uuid;
Federico Recanatifc0295e2022-02-08 19:37:39 +0100504};
505
Karl Meakinbf580c22024-12-12 14:31:06 +0000506#define FFA_RXTX_HEADER_SIZE_V1_1 \
507 offsetof(struct ffa_partition_rxtx_header, reserved_2)
Federico Recanatifc0295e2022-02-08 19:37:39 +0100508#define FFA_RXTX_HEADER_SIZE sizeof(struct ffa_partition_rxtx_header)
J-Alves70079932022-12-07 17:32:20 +0000509#define FFA_RXTX_ALLOCATOR_SHIFT 16
Federico Recanatifc0295e2022-02-08 19:37:39 +0100510
Karl Meakin895007c2025-01-13 15:48:07 +0000511/**
Karl Meakinbf580c22024-12-12 14:31:06 +0000512 * Initialize a partition message header, with the default values for `flags`,
513 * `offset` and `uuid` and the v1.1 payload offset.
514 */
515static inline void ffa_rxtx_header_init_v1_1(
516 struct ffa_partition_rxtx_header *header, ffa_id_t sender,
517 ffa_id_t receiver, uint32_t payload_size)
518{
519 header->flags = 0;
520 header->reserved_1 = 0;
521 header->offset = FFA_RXTX_HEADER_SIZE_V1_1;
522 header->sender = sender;
523 header->receiver = receiver;
524 header->size = payload_size;
525 header->reserved_2 = 0;
526 header->uuid = (struct ffa_uuid){0};
527}
528
529/**
530 * Initialize a partition message header, with the default values for `flags`,
531 * `offset` and `uuid`.
Karl Meakin895007c2025-01-13 15:48:07 +0000532 */
Federico Recanatifc0295e2022-02-08 19:37:39 +0100533static inline void ffa_rxtx_header_init(
Karl Meakin895007c2025-01-13 15:48:07 +0000534 struct ffa_partition_rxtx_header *header, ffa_id_t sender,
535 ffa_id_t receiver, uint32_t payload_size)
Federico Recanatifc0295e2022-02-08 19:37:39 +0100536{
537 header->flags = 0;
Karl Meakinbf580c22024-12-12 14:31:06 +0000538 header->reserved_1 = 0;
Federico Recanatifc0295e2022-02-08 19:37:39 +0100539 header->offset = FFA_RXTX_HEADER_SIZE;
Karl Meakin9ca05512024-11-29 17:02:32 +0000540 header->sender = sender;
541 header->receiver = receiver;
Karl Meakin895007c2025-01-13 15:48:07 +0000542 header->size = payload_size;
Karl Meakinbf580c22024-12-12 14:31:06 +0000543 header->reserved_2 = 0;
544 header->uuid = (struct ffa_uuid){0};
545}
546
547/**
548 * Initialize a partition message header, with the default values for `flags`
549 * and `offset`.
550 */
551static inline void ffa_rxtx_header_init_with_uuid(
552 struct ffa_partition_rxtx_header *header, ffa_id_t sender,
553 ffa_id_t receiver, uint32_t size, struct ffa_uuid uuid)
554{
555 header->flags = 0;
556 header->reserved_1 = 0;
557 header->offset = FFA_RXTX_HEADER_SIZE;
558 header->sender = sender;
559 header->receiver = receiver;
560 header->size = size;
561 header->reserved_2 = 0;
562 header->uuid = uuid;
Federico Recanatifc0295e2022-02-08 19:37:39 +0100563}
564
Federico Recanatifc0295e2022-02-08 19:37:39 +0100565/* The maximum length possible for a single message. */
Karl Meakinbf580c22024-12-12 14:31:06 +0000566#define FFA_PARTITION_MSG_PAYLOAD_MAX_V1_1 \
567 (HF_MAILBOX_SIZE - FFA_RXTX_HEADER_SIZE_V1_1)
Federico Recanatifc0295e2022-02-08 19:37:39 +0100568#define FFA_PARTITION_MSG_PAYLOAD_MAX (HF_MAILBOX_SIZE - FFA_RXTX_HEADER_SIZE)
569
570struct ffa_partition_msg {
571 struct ffa_partition_rxtx_header header;
Karl Meakinbf580c22024-12-12 14:31:06 +0000572 /**
573 * Prefer using `ffa_partition_msg_payload` to accessing this field
574 * directly, because the offset does not necessarily correspond to the
575 * offset of this field.
576 */
Federico Recanatifc0295e2022-02-08 19:37:39 +0100577 char payload[FFA_PARTITION_MSG_PAYLOAD_MAX];
578};
579
Karl Meakinbf580c22024-12-12 14:31:06 +0000580static_assert(sizeof(struct ffa_partition_msg) == HF_MAILBOX_SIZE,
581 "FF-A message size must match mailbox size");
582
Karl Meakin891eb882025-01-17 19:11:20 +0000583/**
584 * Get the partition message's payload, according to the header's `offset`
585 * field.
586 */
587static inline void *ffa_partition_msg_payload(struct ffa_partition_msg *msg)
588{
589 return (char *)msg + msg->header.offset;
590}
591
592static inline const void *ffa_partition_msg_payload_const(
593 const struct ffa_partition_msg *msg)
594{
595 return (const char *)msg + msg->header.offset;
596}
597
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100598/* The maximum length possible for a single message. */
599#define FFA_MSG_PAYLOAD_MAX HF_MAILBOX_SIZE
600
Karl Meakin0dba87e2025-03-24 17:36:04 +0000601enum ffa_data_access : uint8_t {
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100602 FFA_DATA_ACCESS_NOT_SPECIFIED,
603 FFA_DATA_ACCESS_RO,
604 FFA_DATA_ACCESS_RW,
605 FFA_DATA_ACCESS_RESERVED,
606};
607
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100608static inline const char *ffa_data_access_name(enum ffa_data_access data_access)
609{
610 switch (data_access) {
611 case FFA_DATA_ACCESS_NOT_SPECIFIED:
612 return "FFA_DATA_ACCESS_NOT_SPECIFIED";
613 case FFA_DATA_ACCESS_RO:
614 return "FFA_DATA_ACCESS_RO";
615 case FFA_DATA_ACCESS_RW:
616 return "FFA_DATA_ACCESS_RW";
617 case FFA_DATA_ACCESS_RESERVED:
618 return "FFA_DATA_ACCESS_RESERVED";
619 }
620}
621
Karl Meakin0dba87e2025-03-24 17:36:04 +0000622enum ffa_instruction_access : uint8_t {
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100623 FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED,
624 FFA_INSTRUCTION_ACCESS_NX,
625 FFA_INSTRUCTION_ACCESS_X,
626 FFA_INSTRUCTION_ACCESS_RESERVED,
627};
628
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100629static inline const char *ffa_instruction_access_name(
630 enum ffa_instruction_access instruction_access)
631{
632 switch (instruction_access) {
633 case FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED:
634 return "FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED";
635 case FFA_INSTRUCTION_ACCESS_NX:
636 return "FFA_INSTRUCTION_ACCESS_NX";
637 case FFA_INSTRUCTION_ACCESS_X:
638 return "FFA_INSTRUCTION_ACCESS_X";
639 case FFA_INSTRUCTION_ACCESS_RESERVED:
640 return "FFA_INSTRUCTION_ACCESS_RESERVED";
641 }
642}
643
Karl Meakin0dba87e2025-03-24 17:36:04 +0000644enum ffa_memory_type : uint8_t {
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100645 FFA_MEMORY_NOT_SPECIFIED_MEM,
646 FFA_MEMORY_DEVICE_MEM,
647 FFA_MEMORY_NORMAL_MEM,
648};
649
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100650static inline const char *ffa_memory_type_name(enum ffa_memory_type type)
651{
652 switch (type) {
653 case FFA_MEMORY_NOT_SPECIFIED_MEM:
654 return "FFA_MEMORY_NOT_SPECIFIED_MEM";
655 case FFA_MEMORY_DEVICE_MEM:
656 return "FFA_MEMORY_DEVICE_MEM";
657 case FFA_MEMORY_NORMAL_MEM:
658 return "FFA_MEMORY_NORMAL_MEM";
659 }
660}
661
Karl Meakin0dba87e2025-03-24 17:36:04 +0000662enum ffa_memory_cacheability : uint8_t {
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100663 FFA_MEMORY_CACHE_RESERVED = 0x0,
664 FFA_MEMORY_CACHE_NON_CACHEABLE = 0x1,
665 FFA_MEMORY_CACHE_RESERVED_1 = 0x2,
666 FFA_MEMORY_CACHE_WRITE_BACK = 0x3,
667 FFA_MEMORY_DEV_NGNRNE = 0x0,
668 FFA_MEMORY_DEV_NGNRE = 0x1,
669 FFA_MEMORY_DEV_NGRE = 0x2,
670 FFA_MEMORY_DEV_GRE = 0x3,
671};
672
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100673static inline const char *ffa_memory_cacheability_name(
674 enum ffa_memory_cacheability cacheability)
675{
676 switch (cacheability) {
677 case FFA_MEMORY_CACHE_RESERVED:
678 return "FFA_MEMORY_CACHE_RESERVED";
679 case FFA_MEMORY_CACHE_NON_CACHEABLE:
680 return "FFA_MEMORY_CACHE_NON_CACHEABLE";
681 case FFA_MEMORY_CACHE_RESERVED_1:
682 return "FFA_MEMORY_CACHE_RESERVED_1";
683 case FFA_MEMORY_CACHE_WRITE_BACK:
684 return "FFA_MEMORY_CACHE_WRITE_BACK";
685 }
686}
687
Daniel Boulby9764ff62024-01-30 17:47:39 +0000688static inline const char *ffa_device_memory_cacheability_name(
689 enum ffa_memory_cacheability cacheability)
690{
691 switch (cacheability) {
692 case FFA_MEMORY_DEV_NGNRNE:
693 return "FFA_MEMORY_DEV_NGNRNE";
694 case FFA_MEMORY_DEV_NGNRE:
695 return "FFA_MEMORY_DEV_NGNRE";
696 case FFA_MEMORY_DEV_NGRE:
697 return "FFA_MEMORY_DEV_NGRE";
698 case FFA_MEMORY_DEV_GRE:
699 return "FFA_MEMORY_DEV_GRE";
700 }
701}
702
Karl Meakin0dba87e2025-03-24 17:36:04 +0000703enum ffa_memory_shareability : uint8_t {
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100704 FFA_MEMORY_SHARE_NON_SHAREABLE,
705 FFA_MEMORY_SHARE_RESERVED,
706 FFA_MEMORY_OUTER_SHAREABLE,
707 FFA_MEMORY_INNER_SHAREABLE,
708};
709
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100710static inline const char *ffa_memory_shareability_name(
711 enum ffa_memory_shareability shareability)
712{
713 switch (shareability) {
714 case FFA_MEMORY_SHARE_NON_SHAREABLE:
715 return "FFA_MEMORY_SHARE_NON_SHAREABLE";
716 case FFA_MEMORY_SHARE_RESERVED:
717 return "FFA_MEMORY_SHARE_RESERVED";
718 case FFA_MEMORY_OUTER_SHAREABLE:
719 return "FFA_MEMORY_OUTER_SHAREABLE";
720 case FFA_MEMORY_INNER_SHAREABLE:
721 return "FFA_MEMORY_INNER_SHAREABLE";
722 }
723}
724
Olivier Deprez4342a3c2022-02-28 09:37:25 +0100725/**
726 * FF-A v1.1 REL0 Table 10.18 memory region attributes descriptor NS Bit 6.
727 * Per section 10.10.4.1, NS bit is reserved for FFA_MEM_DONATE/LEND/SHARE
728 * and FFA_MEM_RETRIEVE_REQUEST.
729 */
Karl Meakin0dba87e2025-03-24 17:36:04 +0000730enum ffa_memory_security : uint8_t {
Olivier Deprez4342a3c2022-02-28 09:37:25 +0100731 FFA_MEMORY_SECURITY_UNSPECIFIED = 0,
732 FFA_MEMORY_SECURITY_SECURE = 0,
733 FFA_MEMORY_SECURITY_NON_SECURE,
734};
735
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100736static inline const char *ffa_memory_security_name(
737 enum ffa_memory_security security)
738{
739 switch (security) {
740 case FFA_MEMORY_SECURITY_UNSPECIFIED:
741 return "FFA_MEMORY_SECURITY_UNSPECIFIED";
742 case FFA_MEMORY_SECURITY_NON_SECURE:
743 return "FFA_MEMORY_SECURITY_NON_SECURE";
744 }
745}
746
Karl Meakin84710f32023-10-12 15:14:49 +0100747typedef struct {
Karl Meakin0dba87e2025-03-24 17:36:04 +0000748 enum ffa_data_access data_access : 2;
749 enum ffa_instruction_access instruction_access : 2;
Karl Meakin84710f32023-10-12 15:14:49 +0100750} ffa_memory_access_permissions_t;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100751
Karl Meakin0dba87e2025-03-24 17:36:04 +0000752static_assert(sizeof(ffa_memory_access_permissions_t) == sizeof(uint8_t),
753 "ffa_memory_access_permissions_t must be 8 bits wide");
754
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100755/**
J-Alves0b6653d2022-04-22 13:17:38 +0100756 * This corresponds to table 10.18 of the FF-A v1.1 EAC0 specification, "Memory
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100757 * region attributes descriptor".
758 */
Karl Meakin84710f32023-10-12 15:14:49 +0100759typedef struct {
Karl Meakin0dba87e2025-03-24 17:36:04 +0000760 enum ffa_memory_shareability shareability : 2;
761 enum ffa_memory_cacheability cacheability : 2;
762 enum ffa_memory_type type : 2;
763 enum ffa_memory_security security : 2;
Karl Meakin84710f32023-10-12 15:14:49 +0100764 uint8_t : 8;
765} ffa_memory_attributes_t;
J-Alves0b6653d2022-04-22 13:17:38 +0100766
Karl Meakin0dba87e2025-03-24 17:36:04 +0000767static_assert(sizeof(ffa_memory_attributes_t) == sizeof(uint16_t),
768 "ffa_memory_attributes_t must be 16 bits wide");
769
J-Alves0b6653d2022-04-22 13:17:38 +0100770/* FF-A v1.1 EAC0 states bit [15:7] Must Be Zero. */
771#define FFA_MEMORY_ATTRIBUTES_MBZ_MASK 0xFF80U
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100772
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100773/**
774 * A globally-unique ID assigned by the hypervisor for a region of memory being
775 * sent between VMs.
776 */
777typedef uint64_t ffa_memory_handle_t;
778
Karl Meakin1a760e72024-07-25 18:58:37 +0100779enum ffa_memory_handle_allocator {
780 FFA_MEMORY_HANDLE_ALLOCATOR_SPMC = 0,
781 FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR = 1,
782};
J-Alves917d2f22020-10-30 18:39:30 +0000783
Karl Meakin1a760e72024-07-25 18:58:37 +0100784#define FFA_MEMORY_HANDLE_ALLOCATOR_BIT UINT64_C(63)
785#define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \
786 (UINT64_C(1) << FFA_MEMORY_HANDLE_ALLOCATOR_BIT)
J-Alves917d2f22020-10-30 18:39:30 +0000787#define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0))
788
Karl Meakin1a760e72024-07-25 18:58:37 +0100789static inline ffa_memory_handle_t ffa_memory_handle_make(
790 uint64_t index, enum ffa_memory_handle_allocator allocator)
791{
792 return index | ((uint64_t)allocator << FFA_MEMORY_HANDLE_ALLOCATOR_BIT);
793}
794
795static inline uint64_t ffa_memory_handle_index(ffa_memory_handle_t handle)
796{
797 return handle & ~FFA_MEMORY_HANDLE_ALLOCATOR_MASK;
798}
799
800static inline enum ffa_memory_handle_allocator ffa_memory_handle_allocator(
801 ffa_memory_handle_t handle)
802{
803 return ((handle & FFA_MEMORY_HANDLE_ALLOCATOR_MASK) != 0)
804 ? FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR
805 : FFA_MEMORY_HANDLE_ALLOCATOR_SPMC;
806}
807
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100808/**
809 * A count of VMs. This has the same range as the VM IDs but we give it a
810 * different name to make the different semantics clear.
811 */
J-Alves19e20cf2023-08-02 12:48:55 +0100812typedef ffa_id_t ffa_vm_count_t;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100813
814/** The index of a vCPU within a particular VM. */
815typedef uint16_t ffa_vcpu_index_t;
816
817/**
818 * A count of vCPUs. This has the same range as the vCPU indices but we give it
819 * a different name to make the different semantics clear.
820 */
821typedef ffa_vcpu_index_t ffa_vcpu_count_t;
822
823/** Parameter and return type of FF-A functions. */
824struct ffa_value {
825 uint64_t func;
826 uint64_t arg1;
827 uint64_t arg2;
828 uint64_t arg3;
829 uint64_t arg4;
830 uint64_t arg5;
831 uint64_t arg6;
832 uint64_t arg7;
Raghu Krishnamurthy567068e2022-12-26 07:46:38 -0800833
834 struct {
835 uint64_t arg8;
836 uint64_t arg9;
837 uint64_t arg10;
838 uint64_t arg11;
839 uint64_t arg12;
840 uint64_t arg13;
841 uint64_t arg14;
842 uint64_t arg15;
843 uint64_t arg16;
844 uint64_t arg17;
845 bool valid;
846 } extended_val;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100847};
848
Olivier Depreze562e542020-06-11 17:31:54 +0200849static inline uint32_t ffa_func_id(struct ffa_value args)
850{
851 return args.func;
852}
853
Karl Meakindc759f52024-05-07 16:08:02 +0100854static inline enum ffa_error ffa_error_code(struct ffa_value val)
J-Alves13318e32021-02-22 17:21:00 +0000855{
Karl Meakin66a38bd2024-05-28 16:00:56 +0100856 /* NOLINTNEXTLINE(EnumCastOutOfRange) */
Karl Meakindc759f52024-05-07 16:08:02 +0100857 return (enum ffa_error)val.arg2;
J-Alves13318e32021-02-22 17:21:00 +0000858}
859
J-Alves19e20cf2023-08-02 12:48:55 +0100860static inline ffa_id_t ffa_sender(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100861{
862 return (args.arg1 >> 16) & 0xffff;
863}
864
J-Alves19e20cf2023-08-02 12:48:55 +0100865static inline ffa_id_t ffa_receiver(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100866{
867 return args.arg1 & 0xffff;
868}
869
870static inline uint32_t ffa_msg_send_size(struct ffa_value args)
871{
872 return args.arg3;
873}
874
Federico Recanati25053ee2022-03-14 15:01:53 +0100875static inline uint32_t ffa_msg_send2_flags(struct ffa_value args)
876{
877 return args.arg2;
878}
879
Olivier Depreze562e542020-06-11 17:31:54 +0200880static inline uint32_t ffa_partition_info_get_count(struct ffa_value args)
881{
882 return args.arg2;
883}
884
Raghu Krishnamurthy2957b922022-12-27 10:29:12 -0800885static inline uint16_t ffa_partition_info_regs_get_last_idx(
886 struct ffa_value args)
887{
888 return args.arg2 & 0xFFFF;
889}
890
891static inline uint16_t ffa_partition_info_regs_get_curr_idx(
892 struct ffa_value args)
893{
894 return (args.arg2 >> 16) & 0xFFFF;
895}
896
897static inline uint16_t ffa_partition_info_regs_get_tag(struct ffa_value args)
898{
899 return (args.arg2 >> 32) & 0xFFFF;
900}
901
902static inline uint16_t ffa_partition_info_regs_get_desc_size(
903 struct ffa_value args)
904{
905 return (args.arg2 >> 48);
906}
907
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100908static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t a1, uint32_t a2)
909{
910 return (uint64_t)a1 | (uint64_t)a2 << 32;
911}
912
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100913static inline ffa_memory_handle_t ffa_mem_success_handle(struct ffa_value args)
914{
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100915 return ffa_assemble_handle(args.arg2, args.arg3);
916}
917
Andrew Walbranca808b12020-05-15 17:22:28 +0100918static inline ffa_memory_handle_t ffa_frag_handle(struct ffa_value args)
919{
920 return ffa_assemble_handle(args.arg1, args.arg2);
921}
922
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100923static inline struct ffa_value ffa_mem_success(ffa_memory_handle_t handle)
924{
925 return (struct ffa_value){.func = FFA_SUCCESS_32,
926 .arg2 = (uint32_t)handle,
927 .arg3 = (uint32_t)(handle >> 32)};
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100928}
929
J-Alves19e20cf2023-08-02 12:48:55 +0100930static inline ffa_id_t ffa_vm_id(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100931{
932 return (args.arg1 >> 16) & 0xffff;
933}
934
935static inline ffa_vcpu_index_t ffa_vcpu_index(struct ffa_value args)
936{
937 return args.arg1 & 0xffff;
938}
939
J-Alves19e20cf2023-08-02 12:48:55 +0100940static inline uint64_t ffa_vm_vcpu(ffa_id_t vm_id, ffa_vcpu_index_t vcpu_index)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100941{
942 return ((uint32_t)vm_id << 16) | vcpu_index;
943}
944
J-Alves19e20cf2023-08-02 12:48:55 +0100945static inline ffa_id_t ffa_frag_sender(struct ffa_value args)
Andrew Walbranca808b12020-05-15 17:22:28 +0100946{
947 return (args.arg4 >> 16) & 0xffff;
948}
949
J-Alves6f72ca82021-11-01 12:34:58 +0000950static inline uint32_t ffa_feature_intid(struct ffa_value args)
951{
952 return (uint32_t)args.arg2;
953}
954
Karl Meakind0356f82024-09-04 13:34:31 +0100955#define FFA_FRAMEWORK_MSG_BIT (UINT64_C(1) << 31)
956#define FFA_FRAMEWORK_MSG_FUNC_MASK UINT64_C(0xFF)
957
958/**
Madhukar Pappireddy8afab732025-02-10 09:39:36 -0600959 * Identifies FF-A framework messages. See sections 18.2 and 18.3 of v1.2 FF-A
Karl Meakind0356f82024-09-04 13:34:31 +0100960 * specification.
961 */
Karl Meakin0dba87e2025-03-24 17:36:04 +0000962enum ffa_framework_msg_func : uint32_t {
Madhukar Pappireddy8afab732025-02-10 09:39:36 -0600963 /* Power management framework messages. */
964 FFA_FRAMEWORK_MSG_PSCI_REQ = 0,
965 FFA_FRAMEWORK_MSG_PSCI_RESP = 2,
966
967 /* The VM availability messages. */
Karl Meakind0356f82024-09-04 13:34:31 +0100968 FFA_FRAMEWORK_MSG_VM_CREATION_REQ = 4,
969 FFA_FRAMEWORK_MSG_VM_CREATION_RESP = 5,
Karl Meakind0356f82024-09-04 13:34:31 +0100970 FFA_FRAMEWORK_MSG_VM_DESTRUCTION_REQ = 6,
971 FFA_FRAMEWORK_MSG_VM_DESTRUCTION_RESP = 7,
Madhukar Pappireddy8afab732025-02-10 09:39:36 -0600972
973 SPMD_FRAMEWORK_MSG_FFA_VERSION_REQ = 8,
974 SPMD_FRAMEWORK_MSG_FFA_VERSION_RESP = 9,
975
976 FFA_FRAMEWORK_MSG_INVALID = 0xFF,
Karl Meakind0356f82024-09-04 13:34:31 +0100977};
978
Karl Meakin06e8b732024-09-20 18:26:49 +0100979#define FFA_VM_AVAILABILITY_MESSAGE_SBZ_LO 16
980#define FFA_VM_AVAILABILITY_MESSAGE_SBZ_HI 31
981
Karl Meakind0356f82024-09-04 13:34:31 +0100982/** Get the `flags` field of a framework message */
983static inline uint32_t ffa_framework_msg_flags(struct ffa_value args)
Daniel Boulbyefa381f2022-01-18 14:49:40 +0000984{
985 return (uint32_t)args.arg2;
986}
987
Karl Meakind0356f82024-09-04 13:34:31 +0100988/** Is `args` a framework message? */
989static inline bool ffa_is_framework_msg(struct ffa_value args)
990{
Karl Meakin06e8b732024-09-20 18:26:49 +0100991 return (args.func != FFA_MSG_SEND_DIRECT_REQ2_64) &&
992 (args.func != FFA_MSG_SEND_DIRECT_RESP2_64) &&
993 ((ffa_framework_msg_flags(args) & FFA_FRAMEWORK_MSG_BIT) != 0);
Karl Meakind0356f82024-09-04 13:34:31 +0100994}
995
Karl Meakina1a02352024-09-20 18:27:18 +0100996/**
997 * Get the ID of the VM that has been created/destroyed from VM availability
998 * message
999 */
1000static inline ffa_id_t ffa_vm_availability_message_vm_id(struct ffa_value args)
1001{
1002 return args.arg5 & 0xFFFF;
1003}
1004
Karl Meakind0356f82024-09-04 13:34:31 +01001005/** Get the function ID from a framework message */
Madhukar Pappireddy984e99a2025-02-10 09:55:27 -06001006static inline uint32_t ffa_framework_msg_get_func(struct ffa_value args)
Karl Meakind0356f82024-09-04 13:34:31 +01001007{
1008 return ffa_framework_msg_flags(args) & FFA_FRAMEWORK_MSG_FUNC_MASK;
1009}
1010
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001011/**
Fuad Tabbae4efcc32020-07-16 15:37:27 +01001012 * Flags to determine the partition properties, as required by
1013 * FFA_PARTITION_INFO_GET.
1014 *
Kathleen Capellaf71dee42023-08-08 16:24:14 -04001015 * 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 +01001016 * specification, "Partition information descriptor, partition properties".
1017 */
1018typedef uint32_t ffa_partition_properties_t;
1019
Kathleen Capellaf71dee42023-08-08 16:24:14 -04001020/**
1021 * Partition property: partition supports receipt of direct requests via the
1022 * FFA_MSG_SEND_DIRECT_REQ ABI.
1023 */
Kathleen Capella402fa852022-11-09 16:16:51 -05001024#define FFA_PARTITION_DIRECT_REQ_RECV (UINT32_C(1) << 0)
Fuad Tabbae4efcc32020-07-16 15:37:27 +01001025
Kathleen Capellaf71dee42023-08-08 16:24:14 -04001026/**
1027 * Partition property: partition can send direct requests via the
1028 * FFA_MSG_SEND_DIRECT_REQ ABI.
1029 */
Kathleen Capella402fa852022-11-09 16:16:51 -05001030#define FFA_PARTITION_DIRECT_REQ_SEND (UINT32_C(1) << 1)
Fuad Tabbae4efcc32020-07-16 15:37:27 +01001031
1032/** Partition property: partition can send and receive indirect messages. */
Kathleen Capella402fa852022-11-09 16:16:51 -05001033#define FFA_PARTITION_INDIRECT_MSG (UINT32_C(1) << 2)
Fuad Tabbae4efcc32020-07-16 15:37:27 +01001034
J-Alves09ff9d82021-11-02 11:55:20 +00001035/** Partition property: partition can receive notifications. */
Kathleen Capella402fa852022-11-09 16:16:51 -05001036#define FFA_PARTITION_NOTIFICATION (UINT32_C(1) << 3)
1037
Karl Meakina603e082024-08-02 17:57:27 +01001038/**
1039 * Partition property: partition must be informed about each VM that is created
1040 * by the Hypervisor.
1041 */
1042#define FFA_PARTITION_VM_CREATED (UINT32_C(1) << 6)
1043
1044/**
1045 * Partition property: partition must be informed about each VM that is
1046 * destroyed by the Hypervisor.
1047 */
1048#define FFA_PARTITION_VM_DESTROYED (UINT32_C(1) << 7)
1049
Kathleen Capella402fa852022-11-09 16:16:51 -05001050/** Partition property: partition runs in the AArch64 execution state. */
1051#define FFA_PARTITION_AARCH64_EXEC (UINT32_C(1) << 8)
J-Alves09ff9d82021-11-02 11:55:20 +00001052
Fuad Tabbae4efcc32020-07-16 15:37:27 +01001053/**
Kathleen Capellaf71dee42023-08-08 16:24:14 -04001054 * Partition property: partition supports receipt of direct requests via the
1055 * FFA_MSG_SEND_DIRECT_REQ2 ABI.
1056 */
1057#define FFA_PARTITION_DIRECT_REQ2_RECV (UINT32_C(1) << 9)
1058
1059/**
1060 * Partition property: partition can send direct requests via the
1061 * FFA_MSG_SEND_DIRECT_REQ2 ABI.
1062 */
1063#define FFA_PARTITION_DIRECT_REQ2_SEND (UINT32_C(1) << 10)
1064
1065/**
Fuad Tabbae4efcc32020-07-16 15:37:27 +01001066 * Holds information returned for each partition by the FFA_PARTITION_INFO_GET
1067 * interface.
Kathleen Capella402fa852022-11-09 16:16:51 -05001068 * This corresponds to table 13.37 "Partition information descriptor"
1069 * in FF-A 1.1 EAC0 specification.
Daniel Boulby1ddb3d72021-12-16 18:16:50 +00001070 */
1071struct ffa_partition_info {
J-Alves19e20cf2023-08-02 12:48:55 +01001072 ffa_id_t vm_id;
Daniel Boulby1ddb3d72021-12-16 18:16:50 +00001073 ffa_vcpu_count_t vcpu_count;
1074 ffa_partition_properties_t properties;
1075 struct ffa_uuid uuid;
1076};
1077
J-Alvesdd1ad572022-01-25 17:58:26 +00001078/** Length in bytes of the name in boot information descriptor. */
1079#define FFA_BOOT_INFO_NAME_LEN 16
1080
J-Alves240d84c2022-04-22 12:19:34 +01001081/**
1082 * The FF-A boot info descriptor, as defined in table 5.8 of section 5.4.1, of
1083 * the FF-A v1.1 EAC0 specification.
1084 */
J-Alvesdd1ad572022-01-25 17:58:26 +00001085struct ffa_boot_info_desc {
1086 char name[FFA_BOOT_INFO_NAME_LEN];
1087 uint8_t type;
1088 uint8_t reserved;
1089 uint16_t flags;
1090 uint32_t size;
1091 uint64_t content;
1092};
1093
1094/** FF-A boot information type mask. */
1095#define FFA_BOOT_INFO_TYPE_SHIFT 7
1096#define FFA_BOOT_INFO_TYPE_MASK (0x1U << FFA_BOOT_INFO_TYPE_SHIFT)
1097#define FFA_BOOT_INFO_TYPE_STD 0U
1098#define FFA_BOOT_INFO_TYPE_IMPDEF 1U
1099
1100/** Standard boot info type IDs. */
1101#define FFA_BOOT_INFO_TYPE_ID_MASK 0x7FU
1102#define FFA_BOOT_INFO_TYPE_ID_FDT 0U
1103#define FFA_BOOT_INFO_TYPE_ID_HOB 1U
1104
1105/** FF-A Boot Info descriptors flags. */
1106#define FFA_BOOT_INFO_FLAG_MBZ_MASK 0xFFF0U
1107
1108/** Bits [1:0] encode the format of the name field in ffa_boot_info_desc. */
1109#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT 0U
1110#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK \
1111 (0x3U << FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT)
1112#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING 0x0U
1113#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID 0x1U
1114
1115/** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */
1116#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT 2
1117#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK \
1118 (0x3U << FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT)
1119#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE 0x1U
1120#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR 0x0U
1121
1122static inline uint16_t ffa_boot_info_content_format(
1123 struct ffa_boot_info_desc *desc)
1124{
1125 return (desc->flags & FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK) >>
1126 FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT;
1127}
1128
1129static inline uint16_t ffa_boot_info_name_format(
1130 struct ffa_boot_info_desc *desc)
1131{
1132 return (desc->flags & FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK) >>
1133 FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT;
1134}
1135
1136static inline uint8_t ffa_boot_info_type_id(struct ffa_boot_info_desc *desc)
1137{
1138 return desc->type & FFA_BOOT_INFO_TYPE_ID_MASK;
1139}
1140
1141static inline uint8_t ffa_boot_info_type(struct ffa_boot_info_desc *desc)
1142{
1143 return (desc->type & FFA_BOOT_INFO_TYPE_MASK) >>
1144 FFA_BOOT_INFO_TYPE_SHIFT;
1145}
1146
1147/** Length in bytes of the signature in the boot descriptor. */
1148#define FFA_BOOT_INFO_HEADER_SIGNATURE_LEN 4
1149
J-Alves240d84c2022-04-22 12:19:34 +01001150/**
1151 * The FF-A boot information header, as defined in table 5.9 of section 5.4.2,
1152 * of the FF-A v1.1 EAC0 specification.
1153 */
J-Alvesdd1ad572022-01-25 17:58:26 +00001154struct ffa_boot_info_header {
1155 uint32_t signature;
1156 uint32_t version;
1157 uint32_t info_blob_size;
1158 uint32_t desc_size;
1159 uint32_t desc_count;
1160 uint32_t desc_offset;
1161 uint64_t reserved;
1162 struct ffa_boot_info_desc boot_info[];
1163};
1164
Fuad Tabbae4efcc32020-07-16 15:37:27 +01001165/**
J-Alves980d1992021-03-18 12:49:18 +00001166 * FF-A v1.1 specification restricts the number of notifications to a maximum
1167 * of 64. Following all possible bitmaps.
1168 */
Karl Meakin2ad6b662024-07-29 20:45:40 +01001169#define FFA_NOTIFICATION_MASK(ID) (UINT64_C(1) << (ID))
J-Alves980d1992021-03-18 12:49:18 +00001170
1171typedef uint64_t ffa_notifications_bitmap_t;
1172
1173#define MAX_FFA_NOTIFICATIONS 64U
1174
1175/**
J-Alvesc003a7a2021-03-18 13:06:53 +00001176 * Flag for notification bind and set, to specify call is about per-vCPU
1177 * notifications.
1178 */
Olivier Deprezb76307d2022-06-09 17:17:45 +02001179#define FFA_NOTIFICATION_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesc003a7a2021-03-18 13:06:53 +00001180
Federico Recanatie73d2832022-04-20 11:10:52 +02001181#define FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(0)
1182#define FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(32)
1183
1184/**
1185 * Helper functions to check for buffer full notification.
1186 */
1187static inline bool is_ffa_hyp_buffer_full_notification(
1188 ffa_notifications_bitmap_t framework)
1189{
1190 return (framework & FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK) != 0;
1191}
1192
1193static inline bool is_ffa_spm_buffer_full_notification(
1194 ffa_notifications_bitmap_t framework)
1195{
1196 return (framework & FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK) != 0;
1197}
1198
J-Alvesc003a7a2021-03-18 13:06:53 +00001199/**
J-Alves980d1992021-03-18 12:49:18 +00001200 * Helper function to assemble a 64-bit sized bitmap, from the 32-bit sized lo
1201 * and hi.
1202 * Helpful as FF-A specification defines that the notifications interfaces
1203 * arguments are 32-bit registers.
1204 */
1205static inline ffa_notifications_bitmap_t ffa_notifications_bitmap(uint32_t lo,
1206 uint32_t hi)
1207{
1208 return (ffa_notifications_bitmap_t)hi << 32U | lo;
1209}
1210
J-Alves98ff9562021-09-09 14:39:41 +01001211static inline ffa_notifications_bitmap_t ffa_notification_get_from_sp(
1212 struct ffa_value val)
1213{
1214 return ffa_notifications_bitmap((uint32_t)val.arg2, (uint32_t)val.arg3);
1215}
1216
1217static inline ffa_notifications_bitmap_t ffa_notification_get_from_vm(
1218 struct ffa_value val)
1219{
1220 return ffa_notifications_bitmap((uint32_t)val.arg4, (uint32_t)val.arg5);
1221}
1222
Federico Recanatie73d2832022-04-20 11:10:52 +02001223static inline ffa_notifications_bitmap_t ffa_notification_get_from_framework(
1224 struct ffa_value val)
1225{
1226 return ffa_notifications_bitmap((uint32_t)val.arg6, (uint32_t)val.arg7);
1227}
1228
Karl Meakinf9c73ce2024-07-30 17:37:13 +01001229typedef uint32_t ffa_notification_flags_t;
1230
1231/** Flags used in calls to FFA_NOTIFICATION_BIND interface. */
1232#define FFA_NOTIFICATIONS_FLAG_PER_VCPU (UINT32_C(1) << 0)
1233
1234/** Flags used in calls to FFA_NOTIFICATION_GET interface. */
Olivier Deprezb76307d2022-06-09 17:17:45 +02001235#define FFA_NOTIFICATION_FLAG_BITMAP_SP (UINT32_C(1) << 0)
1236#define FFA_NOTIFICATION_FLAG_BITMAP_VM (UINT32_C(1) << 1)
1237#define FFA_NOTIFICATION_FLAG_BITMAP_SPM (UINT32_C(1) << 2)
1238#define FFA_NOTIFICATION_FLAG_BITMAP_HYP (UINT32_C(1) << 3)
J-Alvesaa79c012021-07-09 14:29:45 +01001239
Karl Meakinf9c73ce2024-07-30 17:37:13 +01001240/** Flags used in calls to FFA_NOTIFICATION_SET interface. */
Olivier Deprezb76307d2022-06-09 17:17:45 +02001241#define FFA_NOTIFICATIONS_FLAG_PER_VCPU (UINT32_C(1) << 0)
Olivier Deprezb76307d2022-06-09 17:17:45 +02001242#define FFA_NOTIFICATIONS_FLAG_DELAY_SRI (UINT32_C(1) << 1)
Olivier Deprezb76307d2022-06-09 17:17:45 +02001243#define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) \
1244 ((((uint32_t)(id)) & UINT32_C(0xffff)) << 16)
Karl Meakinf9c73ce2024-07-30 17:37:13 +01001245#define FFA_NOTIFICATIONS_FLAGS_GET_VCPU_ID(flags) \
1246 ((ffa_vcpu_index_t)((flags) >> 16))
J-Alves13394022021-06-30 13:48:49 +01001247
J-Alvesbe6e3032021-11-30 14:54:12 +00001248static inline ffa_vcpu_index_t ffa_notifications_get_vcpu(struct ffa_value args)
J-Alvesaa79c012021-07-09 14:29:45 +01001249{
Karl Meakinf9c73ce2024-07-30 17:37:13 +01001250 return FFA_NOTIFICATIONS_FLAGS_GET_VCPU_ID(args.arg1);
J-Alvesaa79c012021-07-09 14:29:45 +01001251}
1252
1253/**
J-Alvesc8e8a222021-06-08 17:33:52 +01001254 * The max number of IDs for return of FFA_NOTIFICATION_INFO_GET.
1255 */
1256#define FFA_NOTIFICATIONS_INFO_GET_MAX_IDS 20U
1257
1258/**
1259 * Number of registers to use in successfull return of interface
1260 * FFA_NOTIFICATION_INFO_GET.
1261 */
1262#define FFA_NOTIFICATIONS_INFO_GET_REGS_RET 5U
1263
1264#define FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING 0x1U
1265
1266/**
1267 * Helper macros for return parameter encoding as described in section 17.7.1
1268 * of the FF-A v1.1 Beta0 specification.
1269 */
1270#define FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT 0x7U
1271#define FFA_NOTIFICATIONS_LISTS_COUNT_MASK 0x1fU
Karl Meakin2ad6b662024-07-29 20:45:40 +01001272#define FFA_NOTIFICATIONS_LIST_SHIFT(l) (2 * ((l) - 1) + 12)
J-Alvesc8e8a222021-06-08 17:33:52 +01001273#define FFA_NOTIFICATIONS_LIST_SIZE_MASK 0x3U
Daniel Boulby1308a632024-09-11 15:19:16 +01001274#define FFA_NOTIFICATIONS_LIST_MAX_SIZE 0x4U
Daniel Boulbyedfdf282025-01-02 18:51:19 +00001275#define FFA_NOTIFICATIONS_LIST_MAX_VCPU_IDS \
1276 (FFA_NOTIFICATIONS_LIST_MAX_SIZE - 1)
J-Alvesc8e8a222021-06-08 17:33:52 +01001277
1278static inline uint32_t ffa_notification_info_get_lists_count(
1279 struct ffa_value args)
1280{
1281 return (uint32_t)(args.arg2 >> FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT) &
1282 FFA_NOTIFICATIONS_LISTS_COUNT_MASK;
1283}
1284
1285static inline uint32_t ffa_notification_info_get_list_size(
1286 struct ffa_value args, unsigned int list_idx)
1287{
1288 return ((uint32_t)args.arg2 >> FFA_NOTIFICATIONS_LIST_SHIFT(list_idx)) &
1289 FFA_NOTIFICATIONS_LIST_SIZE_MASK;
1290}
1291
1292static inline bool ffa_notification_info_get_more_pending(struct ffa_value args)
1293{
1294 return (args.arg2 & FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING) != 0U;
1295}
1296
Daniel Boulby1308a632024-09-11 15:19:16 +01001297void ffa_notification_info_get_and_check(
1298 const uint32_t expected_lists_count,
1299 const uint32_t *const expected_lists_sizes,
1300 const uint16_t *const expected_ids);
1301
J-Alvesc8e8a222021-06-08 17:33:52 +01001302/**
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001303 * A set of contiguous pages which is part of a memory region. This corresponds
J-Alves0b6653d2022-04-22 13:17:38 +01001304 * to table 10.14 of the FF-A v1.1 EAC0 specification, "Constituent memory
1305 * region descriptor".
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001306 */
1307struct ffa_memory_region_constituent {
1308 /**
1309 * The base IPA of the constituent memory region, aligned to 4 kiB page
1310 * size granularity.
1311 */
1312 uint64_t address;
1313 /** The number of 4 kiB pages in the constituent memory region. */
1314 uint32_t page_count;
1315 /** Reserved field, must be 0. */
1316 uint32_t reserved;
1317};
1318
1319/**
J-Alves0b6653d2022-04-22 13:17:38 +01001320 * A set of pages comprising a memory region. This corresponds to table 10.13 of
1321 * the FF-A v1.1 EAC0 specification, "Composite memory region descriptor".
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001322 */
1323struct ffa_composite_memory_region {
1324 /**
1325 * The total number of 4 kiB pages included in this memory region. This
1326 * must be equal to the sum of page counts specified in each
1327 * `ffa_memory_region_constituent`.
1328 */
1329 uint32_t page_count;
1330 /**
1331 * The number of constituents (`ffa_memory_region_constituent`)
1332 * included in this memory region range.
1333 */
1334 uint32_t constituent_count;
1335 /** Reserved field, must be 0. */
1336 uint64_t reserved_0;
1337 /** An array of `constituent_count` memory region constituents. */
1338 struct ffa_memory_region_constituent constituents[];
1339};
1340
1341/** Flags to indicate properties of receivers during memory region retrieval. */
1342typedef uint8_t ffa_memory_receiver_flags_t;
1343
1344/**
J-Alves0b6653d2022-04-22 13:17:38 +01001345 * This corresponds to table 10.15 of the FF-A v1.1 EAC0 specification, "Memory
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001346 * access permissions descriptor".
1347 */
1348struct ffa_memory_region_attributes {
1349 /** The ID of the VM to which the memory is being given or shared. */
J-Alves19e20cf2023-08-02 12:48:55 +01001350 ffa_id_t receiver;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001351 /**
1352 * The permissions with which the memory region should be mapped in the
1353 * receiver's page table.
1354 */
1355 ffa_memory_access_permissions_t permissions;
1356 /**
1357 * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP
1358 * for memory regions with multiple borrowers.
1359 */
1360 ffa_memory_receiver_flags_t flags;
1361};
1362
1363/** Flags to control the behaviour of a memory sharing transaction. */
1364typedef uint32_t ffa_memory_region_flags_t;
1365
1366/**
1367 * Clear memory region contents after unmapping it from the sender and before
1368 * mapping it for any receiver.
1369 */
1370#define FFA_MEMORY_REGION_FLAG_CLEAR 0x1
1371
1372/**
1373 * Whether the hypervisor may time slice the memory sharing or retrieval
1374 * operation.
1375 */
1376#define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2
1377
1378/**
1379 * Whether the hypervisor should clear the memory region after the receiver
1380 * relinquishes it or is aborted.
1381 */
1382#define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4
1383
J-Alves3456e032023-07-20 12:20:05 +01001384/**
1385 * On retrieve request, bypass the multi-borrower check.
1386 */
1387#define FFA_MEMORY_REGION_FLAG_BYPASS_BORROWERS_CHECK (0x1U << 10)
1388
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001389#define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3)
1390#define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3)
1391#define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3)
1392#define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3)
1393#define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3)
1394
Federico Recanati85090c42021-12-15 13:17:54 +01001395#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_VALID ((0x1U) << 9)
1396#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_MASK ((0xFU) << 5)
1397
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001398/**
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001399 * Struct to store the impdef value seen in Table 11.16 of the
1400 * FF-A v1.2 ALP0 specification "Endpoint memory access descriptor".
1401 */
1402struct ffa_memory_access_impdef {
1403 uint64_t val[2];
1404};
1405
Daniel Boulbye0ca9a02024-03-05 18:40:59 +00001406static inline struct ffa_memory_access_impdef ffa_memory_access_impdef_init(
1407 uint64_t impdef_hi, uint64_t impdef_lo)
1408{
1409 return (struct ffa_memory_access_impdef){{impdef_hi, impdef_lo}};
1410}
1411
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001412/**
J-Alves0b6653d2022-04-22 13:17:38 +01001413 * This corresponds to table 10.16 of the FF-A v1.1 EAC0 specification,
1414 * "Endpoint memory access descriptor".
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001415 */
1416struct ffa_memory_access {
1417 struct ffa_memory_region_attributes receiver_permissions;
1418 /**
1419 * Offset in bytes from the start of the outer `ffa_memory_region` to
1420 * an `ffa_composite_memory_region` struct.
1421 */
1422 uint32_t composite_memory_region_offset;
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001423 struct ffa_memory_access_impdef impdef;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001424 uint64_t reserved_0;
1425};
1426
J-Alves363f5722022-04-25 17:37:37 +01001427/** The maximum number of recipients a memory region may be sent to. */
J-Alvesba0e6172022-04-25 17:41:40 +01001428#define MAX_MEM_SHARE_RECIPIENTS UINT32_C(2)
J-Alves363f5722022-04-25 17:37:37 +01001429
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001430/**
1431 * Information about a set of pages which are being shared. This corresponds to
J-Alves0b6653d2022-04-22 13:17:38 +01001432 * table 10.20 of the FF-A v1.1 EAC0 specification, "Lend, donate or share
1433 * memory transaction descriptor". Note that it is also used for retrieve
1434 * requests and responses.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001435 */
1436struct ffa_memory_region {
1437 /**
1438 * The ID of the VM which originally sent the memory region, i.e. the
1439 * owner.
1440 */
J-Alves19e20cf2023-08-02 12:48:55 +01001441 ffa_id_t sender;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001442 ffa_memory_attributes_t attributes;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001443 /** Flags to control behaviour of the transaction. */
1444 ffa_memory_region_flags_t flags;
1445 ffa_memory_handle_t handle;
1446 /**
1447 * An implementation defined value associated with the receiver and the
1448 * memory region.
1449 */
1450 uint64_t tag;
J-Alves0b6653d2022-04-22 13:17:38 +01001451 /* Size of the memory access descriptor. */
1452 uint32_t memory_access_desc_size;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001453 /**
1454 * The number of `ffa_memory_access` entries included in this
1455 * transaction.
1456 */
1457 uint32_t receiver_count;
1458 /**
J-Alves0b6653d2022-04-22 13:17:38 +01001459 * Offset of the 'receivers' field, which relates to the memory access
1460 * descriptors.
1461 */
1462 uint32_t receivers_offset;
1463 /** Reserved field (12 bytes) must be 0. */
1464 uint32_t reserved[3];
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001465};
1466
1467/**
1468 * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table
J-Alves0b6653d2022-04-22 13:17:38 +01001469 * 16.25 of the FF-A v1.1 EAC0 specification, "Descriptor to relinquish a memory
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001470 * region".
1471 */
1472struct ffa_mem_relinquish {
1473 ffa_memory_handle_t handle;
1474 ffa_memory_region_flags_t flags;
1475 uint32_t endpoint_count;
J-Alves19e20cf2023-08-02 12:48:55 +01001476 ffa_id_t endpoints[];
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001477};
1478
1479/**
Daniel Boulby59ffee92023-11-02 18:26:26 +00001480 * Returns the first FF-A version that matches the memory access descriptor
1481 * size.
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001482 */
Karl Meakin0e617d92024-04-05 12:55:22 +01001483enum ffa_version ffa_version_from_memory_access_desc_size(
Daniel Boulbyc7dc9322023-10-27 15:12:07 +01001484 uint32_t memory_access_desc_size);
1485
1486/**
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001487 * To maintain forwards compatability we can't make assumptions about the size
1488 * of the endpoint memory access descriptor so provide a helper function
1489 * to get a receiver from the receiver array using the memory access descriptor
1490 * size field from the memory region descriptor struct.
1491 * Returns NULL if we cannot return the receiver.
1492 */
1493static inline struct ffa_memory_access *ffa_memory_region_get_receiver(
1494 struct ffa_memory_region *memory_region, uint32_t receiver_index)
1495{
1496 uint32_t memory_access_desc_size =
1497 memory_region->memory_access_desc_size;
1498
1499 if (receiver_index >= memory_region->receiver_count) {
1500 return NULL;
1501 }
1502
1503 /*
1504 * Memory access descriptor size cannot be greater than the size of
1505 * the memory access descriptor defined by the current FF-A version.
1506 */
1507 if (memory_access_desc_size > sizeof(struct ffa_memory_access)) {
1508 return NULL;
1509 }
1510
Daniel Boulby41ef8ba2023-10-13 17:01:22 +01001511 /* Check we cannot use receivers offset to cause overflow. */
1512 if (memory_region->receivers_offset !=
1513 sizeof(struct ffa_memory_region)) {
1514 return NULL;
1515 }
1516
Karl Meakin2ad6b662024-07-29 20:45:40 +01001517 return (struct ffa_memory_access
1518 *)((uint8_t *)memory_region +
1519 (size_t)memory_region->receivers_offset +
1520 (size_t)(receiver_index * memory_access_desc_size));
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001521}
1522
1523/**
Daniel Boulby59ffee92023-11-02 18:26:26 +00001524 * Gets the receiver's access permissions from 'struct ffa_memory_region' and
1525 * returns its index in the receiver's array. If receiver's ID doesn't exist
1526 * in the array, return the region's 'receivers_count'.
1527 */
1528static inline uint32_t ffa_memory_region_get_receiver_index(
1529 struct ffa_memory_region *memory_region, ffa_id_t receiver_id)
1530{
1531 uint32_t i;
1532
1533 for (i = 0U; i < memory_region->receiver_count; i++) {
1534 struct ffa_memory_access *receiver =
1535 ffa_memory_region_get_receiver(memory_region, i);
1536 if (receiver->receiver_permissions.receiver == receiver_id) {
1537 break;
1538 }
1539 }
1540
1541 return i;
1542}
1543
1544/**
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001545 * Gets the `ffa_composite_memory_region` for the given receiver from an
1546 * `ffa_memory_region`, or NULL if it is not valid.
1547 */
1548static inline struct ffa_composite_memory_region *
1549ffa_memory_region_get_composite(struct ffa_memory_region *memory_region,
1550 uint32_t receiver_index)
1551{
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001552 struct ffa_memory_access *receiver =
1553 ffa_memory_region_get_receiver(memory_region, receiver_index);
1554 uint32_t offset;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001555
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001556 if (receiver == NULL) {
1557 return NULL;
1558 }
1559
1560 offset = receiver->composite_memory_region_offset;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001561 if (offset == 0) {
1562 return NULL;
1563 }
1564
1565 return (struct ffa_composite_memory_region *)((uint8_t *)memory_region +
1566 offset);
1567}
1568
1569static inline uint32_t ffa_mem_relinquish_init(
1570 struct ffa_mem_relinquish *relinquish_request,
1571 ffa_memory_handle_t handle, ffa_memory_region_flags_t flags,
J-Alves19e20cf2023-08-02 12:48:55 +01001572 ffa_id_t sender)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001573{
1574 relinquish_request->handle = handle;
1575 relinquish_request->flags = flags;
1576 relinquish_request->endpoint_count = 1;
1577 relinquish_request->endpoints[0] = sender;
J-Alves19e20cf2023-08-02 12:48:55 +01001578 return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_id_t);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001579}
1580
J-Alves126ab502022-09-29 11:37:33 +01001581void ffa_copy_memory_region_constituents(
1582 struct ffa_memory_region_constituent *dest,
1583 const struct ffa_memory_region_constituent *src);
1584
Karl Meakin0fd67292024-02-06 17:33:05 +00001585struct ffa_features_rxtx_map_params {
1586 /*
1587 * Bit[0:1]:
1588 * Minimum buffer size and alignment boundary:
1589 * 0b00: 4K
1590 * 0b01: 64K
1591 * 0b10: 16K
1592 * 0b11: Reserved
1593 */
1594 uint8_t min_buf_size : 2;
1595 /*
1596 * Bit[2:15]:
1597 * Reserved (MBZ)
1598 */
1599 uint16_t mbz : 14;
1600 /*
1601 * Bit[16:32]:
1602 * Maximum buffer size in number of pages
1603 * Only present on version 1.2 or later
1604 */
1605 uint16_t max_buf_size : 16;
1606};
1607
Karl Meakin49ec1e42024-05-10 13:08:24 +01001608enum ffa_features_rxtx_map_buf_size {
1609 FFA_RXTX_MAP_MIN_BUF_4K = 0,
1610 FFA_RXTX_MAP_MAX_BUF_PAGE_COUNT = 1,
1611};
Karl Meakin0fd67292024-02-06 17:33:05 +00001612
Karl Meakinf7861302024-02-20 14:39:33 +00001613static inline struct ffa_features_rxtx_map_params ffa_features_rxtx_map_params(
1614 struct ffa_value args)
1615{
1616 struct ffa_features_rxtx_map_params params;
1617 uint32_t arg2 = args.arg2;
1618
1619 params = *(struct ffa_features_rxtx_map_params *)(&arg2);
1620
1621 return params;
1622}
1623
Federico Recanati392be392022-02-08 20:53:03 +01001624/**
1625 * Endpoint RX/TX descriptor, as defined by Table 13.27 in FF-A v1.1 EAC0.
1626 * It's used by the Hypervisor to describe the RX/TX buffers mapped by a VM
1627 * to the SPMC, in order to allow indirect messaging.
1628 */
1629struct ffa_endpoint_rx_tx_descriptor {
J-Alves19e20cf2023-08-02 12:48:55 +01001630 ffa_id_t endpoint_id;
Federico Recanati392be392022-02-08 20:53:03 +01001631 uint16_t reserved;
1632
1633 /*
1634 * 8-byte aligned offset from the base address of this descriptor to the
1635 * `ffa_composite_memory_region` describing the RX buffer.
1636 */
1637 uint32_t rx_offset;
1638
1639 /*
1640 * 8-byte aligned offset from the base address of this descriptor to the
1641 * `ffa_composite_memory_region` describing the TX buffer.
1642 */
1643 uint32_t tx_offset;
1644
1645 /* Pad to align on 16-byte boundary. */
1646 uint32_t pad;
1647};
1648
1649static inline struct ffa_composite_memory_region *
Karl Meakinb9705e22024-04-05 13:58:28 +01001650ffa_endpoint_get_rx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
Federico Recanati392be392022-02-08 20:53:03 +01001651{
Karl Meakin2ad6b662024-07-29 20:45:40 +01001652 return (struct ffa_composite_memory_region *)((char *)desc +
Federico Recanati392be392022-02-08 20:53:03 +01001653 desc->rx_offset);
1654}
1655
1656static inline struct ffa_composite_memory_region *
Karl Meakinb9705e22024-04-05 13:58:28 +01001657ffa_endpoint_get_tx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
Federico Recanati392be392022-02-08 20:53:03 +01001658{
Karl Meakin2ad6b662024-07-29 20:45:40 +01001659 return (struct ffa_composite_memory_region *)((char *)desc +
Federico Recanati392be392022-02-08 20:53:03 +01001660 desc->tx_offset);
1661}
1662
J-Alves2d8457f2022-10-05 11:06:41 +01001663void ffa_memory_region_init_header(struct ffa_memory_region *memory_region,
J-Alves19e20cf2023-08-02 12:48:55 +01001664 ffa_id_t sender,
J-Alves2d8457f2022-10-05 11:06:41 +01001665 ffa_memory_attributes_t attributes,
1666 ffa_memory_region_flags_t flags,
1667 ffa_memory_handle_t handle, uint32_t tag,
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001668 uint32_t receiver_count,
1669 uint32_t receiver_desc_size);
Daniel Boulby59ffee92023-11-02 18:26:26 +00001670void ffa_memory_access_init(struct ffa_memory_access *receiver,
1671 ffa_id_t receiver_id,
1672 enum ffa_data_access data_access,
1673 enum ffa_instruction_access instruction_access,
1674 ffa_memory_receiver_flags_t flags,
1675 struct ffa_memory_access_impdef *impdef_val);
J-Alves45085432022-04-22 16:19:20 +01001676uint32_t ffa_memory_region_init_single_receiver(
Andrew Walbranca808b12020-05-15 17:22:28 +01001677 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
J-Alves19e20cf2023-08-02 12:48:55 +01001678 ffa_id_t sender, ffa_id_t receiver,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001679 const struct ffa_memory_region_constituent constituents[],
1680 uint32_t constituent_count, uint32_t tag,
1681 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
1682 enum ffa_instruction_access instruction_access,
1683 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
Daniel Boulby59ffee92023-11-02 18:26:26 +00001684 enum ffa_memory_shareability shareability,
1685 struct ffa_memory_access_impdef *impdef_val, uint32_t *fragment_length,
Andrew Walbranca808b12020-05-15 17:22:28 +01001686 uint32_t *total_length);
J-Alvesf4eecf72022-07-20 16:05:34 +01001687uint32_t ffa_memory_region_init(
1688 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
J-Alves19e20cf2023-08-02 12:48:55 +01001689 ffa_id_t sender, struct ffa_memory_access receivers[],
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001690 uint32_t receiver_count, uint32_t receiver_desc_size,
J-Alvesf4eecf72022-07-20 16:05:34 +01001691 const struct ffa_memory_region_constituent constituents[],
1692 uint32_t constituent_count, uint32_t tag,
1693 ffa_memory_region_flags_t flags, enum ffa_memory_type type,
1694 enum ffa_memory_cacheability cacheability,
1695 enum ffa_memory_shareability shareability, uint32_t *fragment_length,
1696 uint32_t *total_length);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001697uint32_t ffa_memory_retrieve_request_init(
1698 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves19e20cf2023-08-02 12:48:55 +01001699 ffa_id_t sender, struct ffa_memory_access receivers[],
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001700 uint32_t receiver_count, uint32_t receiver_desc_size, uint32_t tag,
1701 ffa_memory_region_flags_t flags, enum ffa_memory_type type,
1702 enum ffa_memory_cacheability cacheability,
J-Alves9b24ed82022-08-04 13:12:45 +01001703 enum ffa_memory_shareability shareability);
1704uint32_t ffa_memory_retrieve_request_init_single_receiver(
1705 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves19e20cf2023-08-02 12:48:55 +01001706 ffa_id_t sender, ffa_id_t receiver, uint32_t tag,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001707 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
1708 enum ffa_instruction_access instruction_access,
1709 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
Daniel Boulby59ffee92023-11-02 18:26:26 +00001710 enum ffa_memory_shareability shareability,
1711 struct ffa_memory_access_impdef *impdef_val);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001712uint32_t ffa_memory_lender_retrieve_request_init(
1713 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves19e20cf2023-08-02 12:48:55 +01001714 ffa_id_t sender);
Andrew Walbranca808b12020-05-15 17:22:28 +01001715uint32_t ffa_memory_fragment_init(
1716 struct ffa_memory_region_constituent *fragment,
1717 size_t fragment_max_size,
1718 const struct ffa_memory_region_constituent constituents[],
1719 uint32_t constituent_count, uint32_t *fragment_length);
Federico Recanati392be392022-02-08 20:53:03 +01001720void ffa_endpoint_rx_tx_descriptor_init(
J-Alves19e20cf2023-08-02 12:48:55 +01001721 struct ffa_endpoint_rx_tx_descriptor *desc, ffa_id_t endpoint_id,
Federico Recanati392be392022-02-08 20:53:03 +01001722 uint64_t rx_address, uint64_t tx_address);