blob: 67fd393b953695d6cc29ee7f8fb8ebb1a4380c71 [file] [log] [blame]
J-Alves7581c382020-05-07 18:34:20 +01001/*
Karl Meakin92aa7702023-10-11 18:48:01 +01002 * Copyright (c) 2018-2023, Arm Limited. All rights reserved.
J-Alves7581c382020-05-07 18:34:20 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef FFA_HELPERS_H
8#define FFA_HELPERS_H
9
J-Alves8f08a052020-05-26 17:14:40 +010010#include <ffa_svc.h>
J-Alves7581c382020-05-07 18:34:20 +010011#include <tftf_lib.h>
12#include <utils_def.h>
13
J-Alves779fba62024-04-05 14:14:40 +010014#include <xlat_tables_defs.h>
15
Karl Meakin7308b122024-04-16 14:02:25 +010016/* FFA_VERSION helpers */
17/**
18 * The version number of a Firmware Framework implementation is a 31-bit
19 * unsigned integer, with the upper 15 bits denoting the major revision,
20 * and the lower 16 bits denoting the minor revision.
21 */
22enum ffa_version {
23 FFA_VERSION_1_0 = 0x10000,
24 FFA_VERSION_1_1 = 0x10001,
25 FFA_VERSION_1_2 = 0x10002,
26 FFA_VERSION_COMPILED = FFA_VERSION_1_2,
27};
28
29#define FFA_VERSION_MBZ_BIT (1U << 31U)
30#define FFA_VERSION_MAJOR_SHIFT (16U)
31#define FFA_VERSION_MAJOR_MASK (0x7FFFU)
32#define FFA_VERSION_MINOR_SHIFT (0U)
33#define FFA_VERSION_MINOR_MASK (0xFFFFU)
34
35/** Return true if the version is valid (i.e. bit 31 is 0). */
36static inline bool ffa_version_is_valid(uint32_t version)
37{
38 return (version & FFA_VERSION_MBZ_BIT) == 0;
39}
40
41/** Construct a version from a pair of major and minor components. */
42static inline enum ffa_version make_ffa_version(uint16_t major, uint16_t minor)
43{
44 return (enum ffa_version)((major << FFA_VERSION_MAJOR_SHIFT) |
45 (minor << FFA_VERSION_MINOR_SHIFT));
46}
47
48/** Get the major component of the version. */
49static inline uint16_t ffa_version_get_major(enum ffa_version version)
50{
51 return (version >> FFA_VERSION_MAJOR_SHIFT) & FFA_VERSION_MAJOR_MASK;
52}
53
54/** Get the minor component of the version. */
55static inline uint16_t ffa_version_get_minor(enum ffa_version version)
56{
57 return (version >> FFA_VERSION_MINOR_SHIFT) & FFA_VERSION_MINOR_MASK;
58}
59
60/**
61 * Check major versions are equal and the minor version of the caller is
62 * less than or equal to the minor version of the callee.
63 */
64static inline bool ffa_versions_are_compatible(enum ffa_version caller,
65 enum ffa_version callee)
66{
67 return ffa_version_get_major(caller) == ffa_version_get_major(callee) &&
68 ffa_version_get_minor(caller) <= ffa_version_get_minor(callee);
69}
70
J-Alves7581c382020-05-07 18:34:20 +010071/* This error code must be different to the ones used by FFA */
72#define FFA_TFTF_ERROR -42
73
Daniel Boulbye79d2072021-03-03 11:34:53 +000074typedef unsigned short ffa_id_t;
J-Alves5aecd982020-06-11 10:25:33 +010075typedef unsigned short ffa_vm_count_t;
76typedef unsigned short ffa_vcpu_count_t;
J-Alvesf3a393c2020-10-23 16:00:39 +010077typedef uint64_t ffa_memory_handle_t;
78/** Flags to indicate properties of receivers during memory region retrieval. */
79typedef uint8_t ffa_memory_receiver_flags_t;
J-Alves5aecd982020-06-11 10:25:33 +010080
J-Alvesd708c032020-11-19 12:14:21 +000081struct ffa_uuid {
Raghu Krishnamurthyab5321a2023-04-23 16:14:28 -070082 uint32_t uuid[4];
J-Alvesd708c032020-11-19 12:14:21 +000083};
84
J-Alvesda3e6d42022-01-25 10:19:56 +000085/** Length in bytes of the name in boot information descriptor. */
86#define FFA_BOOT_INFO_NAME_LEN 16
87
88/**
89 * The FF-A boot info descriptor, as defined in table 5.8 of section 5.4.1, of
90 * the FF-A v1.1 EAC0 specification.
91 */
92struct ffa_boot_info_desc {
93 char name[FFA_BOOT_INFO_NAME_LEN];
94 uint8_t type;
95 uint8_t reserved;
96 uint16_t flags;
97 uint32_t size;
98 uint64_t content;
99};
100
101/** FF-A boot information type mask. */
102#define FFA_BOOT_INFO_TYPE_SHIFT 7
103#define FFA_BOOT_INFO_TYPE_MASK (0x1U << FFA_BOOT_INFO_TYPE_SHIFT)
104#define FFA_BOOT_INFO_TYPE_STD 0U
105#define FFA_BOOT_INFO_TYPE_IMPDEF 1U
106
107/** Standard boot info type IDs. */
108#define FFA_BOOT_INFO_TYPE_ID_MASK 0x7FU
109#define FFA_BOOT_INFO_TYPE_ID_FDT 0U
110#define FFA_BOOT_INFO_TYPE_ID_HOB 1U
111
112/** FF-A Boot Info descriptors flags. */
113#define FFA_BOOT_INFO_FLAG_MBZ_MASK 0xFFF0U
114
115/** Bits [1:0] encode the format of the name field in ffa_boot_info_desc. */
116#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT 0U
117#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK \
118 (0x3U << FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT)
119#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING 0x0U
120#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID 0x1U
121
122/** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */
123#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT 2
124#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK \
125 (0x3U << FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT)
126#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE 0x1U
127#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR 0x0U
128
129static inline uint16_t ffa_boot_info_content_format(
130 struct ffa_boot_info_desc *desc)
131{
132 return (desc->flags & FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK) >>
133 FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT;
134}
135
136static inline uint16_t ffa_boot_info_name_format(
137 struct ffa_boot_info_desc *desc)
138{
139 return (desc->flags & FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK) >>
140 FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT;
141}
142
143static inline uint8_t ffa_boot_info_type_id(struct ffa_boot_info_desc *desc)
144{
145 return desc->type & FFA_BOOT_INFO_TYPE_ID_MASK;
146}
147
148static inline uint8_t ffa_boot_info_type(struct ffa_boot_info_desc *desc)
149{
150 return (desc->type & FFA_BOOT_INFO_TYPE_MASK) >>
151 FFA_BOOT_INFO_TYPE_SHIFT;
152}
153
154/** Length in bytes of the signature in the boot descriptor. */
155#define FFA_BOOT_INFO_HEADER_SIGNATURE_LEN 4
156
157/**
158 * The FF-A boot information header, as defined in table 5.9 of section 5.4.2,
159 * of the FF-A v1.1 EAC0 specification.
160 */
161struct ffa_boot_info_header {
162 uint32_t signature;
163 uint32_t version;
164 uint32_t info_blob_size;
165 uint32_t desc_size;
166 uint32_t desc_count;
167 uint32_t desc_offset;
168 uint64_t reserved;
169 struct ffa_boot_info_desc boot_info[];
170};
171
J-Alves7581c382020-05-07 18:34:20 +0100172#ifndef __ASSEMBLY__
173
J-Alves18c28052021-03-09 09:58:53 +0000174#include <cassert.h>
J-Alves7581c382020-05-07 18:34:20 +0100175#include <stdint.h>
176
J-Alves4439ece2021-11-05 11:52:54 +0000177/**
178 * FF-A Feature ID, to be used with interface FFA_FEATURES.
179 * As defined in the FF-A v1.1 Beta specification, table 13.10, in section
180 * 13.2.
181 */
182
183/** Query interrupt ID of Notification Pending Interrupt. */
184#define FFA_FEATURE_NPI 0x1U
185
186/** Query interrupt ID of Schedule Receiver Interrupt. */
187#define FFA_FEATURE_SRI 0x2U
188
189/** Query interrupt ID of the Managed Exit Interrupt. */
190#define FFA_FEATURE_MEI 0x3U
191
Karl Meakinf2bb5d02024-02-13 17:23:17 +0000192/** Minimum and maximum buffer size reported by FFA_FEATURES(FFA_RXTX_MAP) */
193#define FFA_RXTX_MAP_MIN_BUF_4K 0
194#define FFA_RXTX_MAP_MAX_BUF_PAGE_COUNT 1
195
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000196/** Partition property: partition supports receipt of direct requests. */
Kathleen Capella7774d6e2022-11-23 19:06:21 -0500197#define FFA_PARTITION_DIRECT_REQ_RECV (UINT32_C(1) << 0)
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000198
199/** Partition property: partition can send direct requests. */
Kathleen Capella7774d6e2022-11-23 19:06:21 -0500200#define FFA_PARTITION_DIRECT_REQ_SEND (UINT32_C(1) << 1)
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000201
202/** Partition property: partition can send and receive indirect messages. */
Kathleen Capella7774d6e2022-11-23 19:06:21 -0500203#define FFA_PARTITION_INDIRECT_MSG (UINT32_C(1) << 2)
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000204
J-Alves4d05dec2021-11-02 11:52:27 +0000205/** Partition property: partition can receive notifications. */
Kathleen Capella7774d6e2022-11-23 19:06:21 -0500206#define FFA_PARTITION_NOTIFICATION (UINT32_C(1) << 3)
J-Alves4d05dec2021-11-02 11:52:27 +0000207
Kathleen Capella7774d6e2022-11-23 19:06:21 -0500208/** Partition property: partition runs in the AArch64 execution state. */
209#define FFA_PARTITION_AARCH64_EXEC (UINT32_C(1) << 8)
210
211/** Partition info descriptor as defined in FF-A v1.1 EAC0 Table 13.37 */
Max Shvetsovc32f4782020-06-23 09:41:15 +0100212struct ffa_partition_info {
213 /** The ID of the VM the information is about */
Daniel Boulbye79d2072021-03-03 11:34:53 +0000214 ffa_id_t id;
Max Shvetsovc32f4782020-06-23 09:41:15 +0100215 /** The number of execution contexts implemented by the partition */
216 uint16_t exec_context;
217 /** The Partition's properties, e.g. supported messaging methods */
218 uint32_t properties;
Daniel Boulby8aa994c2022-01-05 19:44:30 +0000219 /** The uuid of the partition */
220 struct ffa_uuid uuid;
Max Shvetsovc32f4782020-06-23 09:41:15 +0100221};
222
Daniel Boulby2ac55f22022-01-21 12:08:08 +0000223/**
Kathleen Capella7774d6e2022-11-23 19:06:21 -0500224 * Bits[31:3] of partition properties must be zero for FF-A v1.0.
225 * This corresponds to table 8.25 "Partition information descriptor"
226 * in DEN0077A FF-A 1.0 REL specification.
227 */
228#define FFA_PARTITION_v1_0_RES_MASK (~(UINT32_C(0x7)))
229
230/**
Daniel Boulby2ac55f22022-01-21 12:08:08 +0000231 * Partition info descriptor as defined in Table 8.25 of the v1.0
Kathleen Capella7774d6e2022-11-23 19:06:21 -0500232 * FF-A Specification (DEN0077A).
Daniel Boulby2ac55f22022-01-21 12:08:08 +0000233 */
234struct ffa_partition_info_v1_0 {
235 /** The ID of the VM the information is about */
236 ffa_id_t id;
237 /** The number of execution contexts implemented by the partition */
238 uint16_t exec_context;
239 /** The Partition's properties, e.g. supported messaging methods */
240 uint32_t properties;
241};
242
Daniel Boulbyce386b12022-03-29 18:36:36 +0100243struct ffa_value {
244 u_register_t fid;
245 u_register_t arg1;
246 u_register_t arg2;
247 u_register_t arg3;
248 u_register_t arg4;
249 u_register_t arg5;
250 u_register_t arg6;
251 u_register_t arg7;
Raghu Krishnamurthyab5321a2023-04-23 16:14:28 -0700252 u_register_t arg8;
253 u_register_t arg9;
254 u_register_t arg10;
255 u_register_t arg11;
256 u_register_t arg12;
257 u_register_t arg13;
258 u_register_t arg14;
259 u_register_t arg15;
260 u_register_t arg16;
261 u_register_t arg17;
Daniel Boulbyce386b12022-03-29 18:36:36 +0100262};
263
264/* Function to make an SMC or SVC service call depending on the exception
265 * level of the SP.
266 */
267struct ffa_value ffa_service_call(struct ffa_value *args);
268
269/*
270 * Functions to trigger a service call.
271 *
272 * The arguments to pass through the service call must be stored in the
273 * ffa_value structure. The return values of the service call will be stored
274 * in the same structure (overriding the input arguments).
275 *
276 * Return the first return value. It is equivalent to args.fid but is also
277 * provided as the return value for convenience.
278 */
279u_register_t ffa_svc(struct ffa_value *args);
280u_register_t ffa_smc(struct ffa_value *args);
281
282static inline uint32_t ffa_func_id(struct ffa_value val)
J-Alvesf156ae92021-10-08 12:10:05 +0100283{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100284 return (uint32_t)val.fid;
J-Alves6cb21d92021-01-07 15:18:12 +0000285}
286
Daniel Boulbyce386b12022-03-29 18:36:36 +0100287static inline int32_t ffa_error_code(struct ffa_value val)
J-Alvesf156ae92021-10-08 12:10:05 +0100288{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100289 return (int32_t)val.arg2;
J-Alves6cb21d92021-01-07 15:18:12 +0000290}
291
Daniel Boulbyce386b12022-03-29 18:36:36 +0100292static inline ffa_id_t ffa_endpoint_id(struct ffa_value val) {
293 return (ffa_id_t)val.arg2 & 0xffff;
Daniel Boulby198deda2021-03-03 11:35:25 +0000294}
295
Daniel Boulbyce386b12022-03-29 18:36:36 +0100296static inline uint32_t ffa_partition_info_count(struct ffa_value val)
Daniel Boulby2ac55f22022-01-21 12:08:08 +0000297{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100298 return (uint32_t)val.arg2;
Daniel Boulby2ac55f22022-01-21 12:08:08 +0000299}
300
Daniel Boulby07d751e2022-05-30 17:32:00 +0100301static inline uint32_t ffa_partition_info_desc_size(struct ffa_value val)
302{
303 return (uint32_t)val.arg3;
304}
305
Daniel Boulbyce386b12022-03-29 18:36:36 +0100306static inline uint32_t ffa_feature_intid(struct ffa_value val)
J-Alves4439ece2021-11-05 11:52:54 +0000307{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100308 return (uint32_t)val.arg2;
J-Alves4439ece2021-11-05 11:52:54 +0000309}
310
Raghu Krishnamurthyab5321a2023-04-23 16:14:28 -0700311static inline uint16_t ffa_partition_info_regs_get_last_idx(
312 struct ffa_value args)
313{
314 return args.arg2 & 0xFFFF;
315}
316
317static inline uint16_t ffa_partition_info_regs_get_curr_idx(
318 struct ffa_value args)
319{
320 return (args.arg2 >> 16) & 0xFFFF;
321}
322
323static inline uint16_t ffa_partition_info_regs_get_tag(struct ffa_value args)
324{
325 return (args.arg2 >> 32) & 0xFFFF;
326}
327
328static inline uint16_t ffa_partition_info_regs_get_desc_size(
329 struct ffa_value args)
330{
331 return (args.arg2 >> 48);
332}
333
334static inline uint32_t ffa_partition_info_regs_partition_count(
335 struct ffa_value args)
336{
337 return ffa_partition_info_regs_get_last_idx(args) + 1;
338}
339
340static inline uint32_t ffa_partition_info_regs_entry_count(
341 struct ffa_value args, uint16_t start_idx)
342{
343 return (ffa_partition_info_regs_get_curr_idx(args) - start_idx + 1);
344}
345
346static inline uint16_t ffa_partition_info_regs_entry_size(
347 struct ffa_value args)
348{
349 return (args.arg2 >> 48) & 0xFFFFU;
350}
351
Madhukar Pappireddy611d0952025-01-31 16:07:08 -0600352/**
353 * FF-A Framework message helpers
354 */
355#define FFA_FRAMEWORK_MSG_BIT (1U << 31)
356
357#define FFA_FRAMEWORK_MSG_MASK 0xFFU
358
359#define FFA_FRAMEWORK_MSG_PSCI_REQ 0U
360#define FFA_FRAMEWORK_MSG_PSCI_RESP 2U
361
362static inline uint32_t ffa_framework_msg_flags(struct ffa_value args)
363{
364 return (uint32_t)args.arg2;
365}
366
367static inline bool ffa_is_framework_msg(struct ffa_value args)
368{
369 return (ffa_func_id(args) == FFA_MSG_SEND_DIRECT_REQ_SMC32 ||
370 ffa_func_id(args) == FFA_MSG_SEND_DIRECT_REQ_SMC64) &&
371 ((ffa_framework_msg_flags(args) & FFA_FRAMEWORK_MSG_BIT) != 0);
372}
373
374static inline uint32_t ffa_get_framework_msg(struct ffa_value args)
375{
376 return ffa_framework_msg_flags(args) & FFA_FRAMEWORK_MSG_MASK;
377}
378
J-Alves18c28052021-03-09 09:58:53 +0000379typedef uint64_t ffa_notification_bitmap_t;
380
J-Alves779fba62024-04-05 14:14:40 +0100381/**
382 * Partition message header as specified by table 6.2 from FF-A v1.1 EAC0
383 * specification.
384 */
385struct ffa_partition_rxtx_header {
386 uint32_t flags;
Karl Meakin7c193632025-01-28 11:22:18 +0000387 /* Reserved (SBZ). */
388 uint32_t reserved_1;
J-Alves779fba62024-04-05 14:14:40 +0100389 /* Offset from the beginning of the buffer to the message payload. */
390 uint32_t offset;
391 /* Sender(Bits[31:16]) and Receiver(Bits[15:0]) endpoint IDs. */
392 ffa_id_t receiver;
393 ffa_id_t sender;
394 /* Size of message in buffer. */
395 uint32_t size;
Karl Meakin7c193632025-01-28 11:22:18 +0000396 /* Reserved (SBZ). Added in v1.2 */
397 uint32_t reserved_2;
398 /* UUID identifying the communication protocol. Added in v1.2. */
399 struct ffa_uuid uuid;
J-Alves779fba62024-04-05 14:14:40 +0100400};
401
402#define FFA_RXTX_HEADER_SIZE sizeof(struct ffa_partition_rxtx_header)
403
404static inline void ffa_rxtx_header_init(
405 ffa_id_t sender, ffa_id_t receiver, uint32_t size,
406 struct ffa_partition_rxtx_header *header)
407{
408 header->flags = 0;
Karl Meakin7c193632025-01-28 11:22:18 +0000409 header->reserved_1 = 0;
J-Alves779fba62024-04-05 14:14:40 +0100410 header->offset = FFA_RXTX_HEADER_SIZE;
411 header->sender = sender;
412 header->receiver = receiver;
413 header->size = size;
Karl Meakin7c193632025-01-28 11:22:18 +0000414 header->reserved_2 = 0;
415 header->uuid = (struct ffa_uuid){0};
J-Alves779fba62024-04-05 14:14:40 +0100416}
417
418/* The maximum length possible for a single message. */
419#define FFA_PARTITION_MSG_PAYLOAD_MAX (PAGE_SIZE - FFA_RXTX_HEADER_SIZE)
420
421struct ffa_partition_msg {
422 struct ffa_partition_rxtx_header header;
423 char payload[FFA_PARTITION_MSG_PAYLOAD_MAX];
424};
425
426/* The maximum length possible for a single message. */
427#define FFA_MSG_PAYLOAD_MAX PAGE_SIZE
428
J-Alves18c28052021-03-09 09:58:53 +0000429#define FFA_NOTIFICATION(ID) (UINT64_C(1) << ID)
430
431#define MAX_FFA_NOTIFICATIONS UINT32_C(64)
432
433#define FFA_NOTIFICATIONS_FLAG_PER_VCPU UINT32_C(0x1 << 0)
434
J-Alvesb0cb5d02021-07-08 11:19:33 +0100435/** Flag to delay Schedule Receiver Interrupt. */
436#define FFA_NOTIFICATIONS_FLAG_DELAY_SRI UINT32_C(0x1 << 1)
437
J-Alves18c28052021-03-09 09:58:53 +0000438#define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) UINT32_C((id & 0xFFFF) << 16)
439
J-Alvesf156ae92021-10-08 12:10:05 +0100440#define FFA_NOTIFICATIONS_FLAG_BITMAP_SP UINT32_C(0x1 << 0)
441#define FFA_NOTIFICATIONS_FLAG_BITMAP_VM UINT32_C(0x1 << 1)
442#define FFA_NOTIFICATIONS_FLAG_BITMAP_SPM UINT32_C(0x1 << 2)
443#define FFA_NOTIFICATIONS_FLAG_BITMAP_HYP UINT32_C(0x1 << 3)
444
J-Alvesc6b92d52024-04-05 14:16:00 +0100445#define FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK FFA_NOTIFICATION(0)
446#define FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK FFA_NOTIFICATION(32)
447
J-Alves269118a2021-09-22 09:46:11 +0100448/**
449 * The following is an SGI ID, that the SPMC configures as non-secure, as
450 * suggested by the FF-A v1.1 specification, in section 9.4.1.
451 */
452#define FFA_SCHEDULE_RECEIVER_INTERRUPT_ID 8
453
J-Alvesc6b92d52024-04-05 14:16:00 +0100454/**
455 * Helper function to assemble a 64-bit sized bitmap, from the 32-bit sized lo
456 * and hi.
457 * Helpful as FF-A specification defines that the notifications interfaces
458 * arguments are 32-bit registers.
459 */
460static inline ffa_notification_bitmap_t ffa_notification_bitmap(uint32_t lo,
461 uint32_t hi)
J-Alvesf156ae92021-10-08 12:10:05 +0100462{
J-Alvesc6b92d52024-04-05 14:16:00 +0100463 return (ffa_notification_bitmap_t)hi << 32U | lo;
J-Alvesf156ae92021-10-08 12:10:05 +0100464}
465
J-Alvesc6b92d52024-04-05 14:16:00 +0100466static inline ffa_notification_bitmap_t ffa_notification_get_from_sp(
Daniel Boulbyce386b12022-03-29 18:36:36 +0100467 struct ffa_value val)
J-Alvesf156ae92021-10-08 12:10:05 +0100468{
J-Alvesc6b92d52024-04-05 14:16:00 +0100469 return ffa_notification_bitmap((uint32_t)val.arg2,
470 (uint32_t)val.arg3);
J-Alvesf156ae92021-10-08 12:10:05 +0100471}
472
J-Alvesc6b92d52024-04-05 14:16:00 +0100473static inline ffa_notification_bitmap_t ffa_notification_get_from_vm(
474 struct ffa_value val)
475{
476 return ffa_notification_bitmap((uint32_t)val.arg4,
477 (uint32_t)val.arg5);
478}
479
480static inline ffa_notification_bitmap_t ffa_notification_get_from_framework(
481 struct ffa_value val)
482{
483 return ffa_notification_bitmap((uint32_t)val.arg6,
484 (uint32_t)val.arg7);
485}
486
487 /**
488 * Helper functions to check for buffer full notification.
489 */
490static inline bool is_ffa_hyp_buffer_full_notification(
491 ffa_notification_bitmap_t framework)
492{
493 return (framework & FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK) != 0U;
494}
495
496static inline bool is_ffa_spm_buffer_full_notification(
497 ffa_notification_bitmap_t framework)
498{
499 return (framework & FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK) != 0U;
500}
501
502
J-Alves5bce2502021-06-14 14:27:45 +0100503/*
504 * FFA_NOTIFICATION_INFO_GET is a SMC64 interface.
505 * The following macros are defined for SMC64 implementation.
506 */
507#define FFA_NOTIFICATIONS_INFO_GET_MAX_IDS 20U
508
509#define FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING UINT64_C(0x1)
510
511#define FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT 0x7U
512#define FFA_NOTIFICATIONS_LISTS_COUNT_MASK 0x1FU
513#define FFA_NOTIFICATIONS_LIST_SHIFT(l) (2 * (l - 1) + 12)
514#define FFA_NOTIFICATIONS_LIST_SIZE_MASK 0x3U
515
J-Alvesc6b92d52024-04-05 14:16:00 +0100516static inline uint32_t ffa_notification_info_get_lists_count(
Daniel Boulbyce386b12022-03-29 18:36:36 +0100517 struct ffa_value ret)
J-Alves5bce2502021-06-14 14:27:45 +0100518{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100519 return (uint32_t)(ret.arg2 >> FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT)
J-Alves5bce2502021-06-14 14:27:45 +0100520 & FFA_NOTIFICATIONS_LISTS_COUNT_MASK;
521}
522
J-Alvesc6b92d52024-04-05 14:16:00 +0100523static inline uint32_t ffa_notification_info_get_list_size(
Daniel Boulbyce386b12022-03-29 18:36:36 +0100524 struct ffa_value ret, uint32_t list)
J-Alves5bce2502021-06-14 14:27:45 +0100525{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100526 return (uint32_t)(ret.arg2 >> FFA_NOTIFICATIONS_LIST_SHIFT(list)) &
J-Alves5bce2502021-06-14 14:27:45 +0100527 FFA_NOTIFICATIONS_LIST_SIZE_MASK;
528}
529
J-Alvesc6b92d52024-04-05 14:16:00 +0100530static inline bool ffa_notification_info_get_more_pending(struct ffa_value ret)
J-Alves5bce2502021-06-14 14:27:45 +0100531{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100532 return (ret.arg2 & FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING) != 0U;
J-Alves5bce2502021-06-14 14:27:45 +0100533}
534
J-Alvesf3a393c2020-10-23 16:00:39 +0100535enum ffa_data_access {
536 FFA_DATA_ACCESS_NOT_SPECIFIED,
537 FFA_DATA_ACCESS_RO,
538 FFA_DATA_ACCESS_RW,
539 FFA_DATA_ACCESS_RESERVED,
540};
541
542enum ffa_instruction_access {
543 FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED,
544 FFA_INSTRUCTION_ACCESS_NX,
545 FFA_INSTRUCTION_ACCESS_X,
546 FFA_INSTRUCTION_ACCESS_RESERVED,
547};
548
549enum ffa_memory_type {
550 FFA_MEMORY_NOT_SPECIFIED_MEM,
551 FFA_MEMORY_DEVICE_MEM,
552 FFA_MEMORY_NORMAL_MEM,
553};
554
555enum ffa_memory_cacheability {
556 FFA_MEMORY_CACHE_RESERVED = 0x0,
557 FFA_MEMORY_CACHE_NON_CACHEABLE = 0x1,
558 FFA_MEMORY_CACHE_RESERVED_1 = 0x2,
559 FFA_MEMORY_CACHE_WRITE_BACK = 0x3,
560 FFA_MEMORY_DEV_NGNRNE = 0x0,
561 FFA_MEMORY_DEV_NGNRE = 0x1,
562 FFA_MEMORY_DEV_NGRE = 0x2,
563 FFA_MEMORY_DEV_GRE = 0x3,
564};
565
566enum ffa_memory_shareability {
567 FFA_MEMORY_SHARE_NON_SHAREABLE,
568 FFA_MEMORY_SHARE_RESERVED,
569 FFA_MEMORY_OUTER_SHAREABLE,
570 FFA_MEMORY_INNER_SHAREABLE,
571};
572
Karl Meakin92aa7702023-10-11 18:48:01 +0100573typedef struct {
574 uint8_t data_access : 2;
575 uint8_t instruction_access : 2;
576} ffa_memory_access_permissions_t;
577
578_Static_assert(sizeof(ffa_memory_access_permissions_t) == sizeof(uint8_t),
579 "ffa_memory_access_permissions_t must be 1 byte wide");
J-Alvesf3a393c2020-10-23 16:00:39 +0100580
581/**
J-Alvesd13d7602023-05-05 14:19:03 +0100582 * FF-A v1.1 REL0 Table 10.18 memory region attributes descriptor NS Bit 6.
583 * Per section 10.10.4.1, NS bit is reserved for FFA_MEM_DONATE/LEND/SHARE
584 * and FFA_MEM_RETRIEVE_REQUEST.
585 */
586enum ffa_memory_security {
587 FFA_MEMORY_SECURITY_UNSPECIFIED = 0,
588 FFA_MEMORY_SECURITY_SECURE = 0,
589 FFA_MEMORY_SECURITY_NON_SECURE,
590};
591
592/**
J-Alvesb42d17f2022-07-04 12:42:13 +0100593 * This corresponds to table 10.18 of the FF-A v1.1 EAC0 specification, "Memory
594 * region attributes descriptor".
J-Alvesf3a393c2020-10-23 16:00:39 +0100595 */
Karl Meakin92aa7702023-10-11 18:48:01 +0100596typedef struct {
597 uint16_t shareability : 2;
598 uint16_t cacheability : 2;
599 uint16_t type : 2;
600 uint16_t security : 1;
601} ffa_memory_attributes_t;
J-Alvesf3a393c2020-10-23 16:00:39 +0100602
Karl Meakin92aa7702023-10-11 18:48:01 +0100603_Static_assert(sizeof(ffa_memory_attributes_t) == sizeof(uint16_t),
604 "ffa_memory_attributes_t must be 2 bytes wide");
J-Alvesf3a393c2020-10-23 16:00:39 +0100605
Karl Meakin0d4f5ff2023-10-13 20:03:16 +0100606#define FFA_MEMORY_HANDLE_ALLOCATOR_MASK UINT64_C(1)
607#define FFA_MEMORY_HANDLE_ALLOCATOR_SHIFT 63U
608#define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR UINT64_C(1)
609#define FFA_MEMORY_HANDLE_ALLOCATOR_SPMC UINT64_C(0)
J-Alvesf3a393c2020-10-23 16:00:39 +0100610#define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0))
611
612/**
613 * A set of contiguous pages which is part of a memory region. This corresponds
J-Alvesb42d17f2022-07-04 12:42:13 +0100614 * to table 10.14 of the FF-A v1.1 EAC0 specification, "Constituent memory
615 * region descriptor".
J-Alvesf3a393c2020-10-23 16:00:39 +0100616 */
617struct ffa_memory_region_constituent {
618 /**
619 * The base IPA of the constituent memory region, aligned to 4 kiB page
620 * size granularity.
621 */
622 void *address;
623 /** The number of 4 kiB pages in the constituent memory region. */
624 uint32_t page_count;
625 /** Reserved field, must be 0. */
626 uint32_t reserved;
627};
628
629/**
J-Alvesb42d17f2022-07-04 12:42:13 +0100630 * A set of pages comprising a memory region. This corresponds to table 10.13 of
631 * the FF-A v1.1 EAC0 specification, "Composite memory region descriptor".
J-Alvesf3a393c2020-10-23 16:00:39 +0100632 */
633struct ffa_composite_memory_region {
634 /**
635 * The total number of 4 kiB pages included in this memory region. This
636 * must be equal to the sum of page counts specified in each
637 * `ffa_memory_region_constituent`.
638 */
639 uint32_t page_count;
640 /**
641 * The number of constituents (`ffa_memory_region_constituent`)
642 * included in this memory region range.
643 */
644 uint32_t constituent_count;
645 /** Reserved field, must be 0. */
646 uint64_t reserved_0;
647 /** An array of `constituent_count` memory region constituents. */
648 struct ffa_memory_region_constituent constituents[];
649};
650
651/**
652 * This corresponds to table "Memory access permissions descriptor" of the FFA
653 * 1.0 specification.
654 */
655struct ffa_memory_region_attributes {
656 /** The ID of the VM to which the memory is being given or shared. */
Daniel Boulbye79d2072021-03-03 11:34:53 +0000657 ffa_id_t receiver;
J-Alvesf3a393c2020-10-23 16:00:39 +0100658 /**
659 * The permissions with which the memory region should be mapped in the
660 * receiver's page table.
661 */
662 ffa_memory_access_permissions_t permissions;
663 /**
664 * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP
665 * for memory regions with multiple borrowers.
666 */
667 ffa_memory_receiver_flags_t flags;
668};
669
Karl Meakinbff9b3c2024-01-18 16:08:35 +0000670/**
671 * Endpoint RX/TX descriptor, as defined by Table 13.27 in FF-A v1.1 EAC0.
672 * It's used by the Hypervisor to describe the RX/TX buffers mapped by a VM
673 * to the SPMC, in order to allow indirect messaging.
674 */
675struct ffa_endpoint_rxtx_descriptor {
676 ffa_id_t endpoint_id;
677 uint16_t reserved;
678
679 /*
680 * 8-byte aligned offset from the base address of this descriptor to the
681 * `ffa_composite_memory_region` describing the RX buffer.
682 */
683 uint32_t rx_offset;
684
685 /*
686 * 8-byte aligned offset from the base address of this descriptor to the
687 * `ffa_composite_memory_region` describing the TX buffer.
688 */
689 uint32_t tx_offset;
690
691 /* Pad to align on 16-byte boundary. */
692 uint32_t pad;
693};
694
695_Static_assert(sizeof(struct ffa_endpoint_rxtx_descriptor) == 16,
696 "ffa_endpoint_rx_tx_descriptor must be 16 bytes wide");
697
J-Alvesf3a393c2020-10-23 16:00:39 +0100698/** Flags to control the behaviour of a memory sharing transaction. */
699typedef uint32_t ffa_memory_region_flags_t;
700
701/**
702 * Clear memory region contents after unmapping it from the sender and before
703 * mapping it for any receiver.
704 */
705#define FFA_MEMORY_REGION_FLAG_CLEAR 0x1U
706
707/**
708 * Whether the hypervisor may time slice the memory sharing or retrieval
709 * operation.
710 */
711#define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2U
712
713/**
714 * Whether the hypervisor should clear the memory region after the receiver
715 * relinquishes it or is aborted.
716 */
717#define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4U
718
719#define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3)
720#define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3)
721#define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3)
722#define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3)
723#define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3)
724
J-Alves0435cae2020-11-06 10:49:56 +0000725/** The maximum number of recipients a memory region may be sent to. */
J-Alvesf3253312024-01-18 17:05:26 +0000726#define MAX_MEM_SHARE_RECIPIENTS 2U
J-Alves0435cae2020-11-06 10:49:56 +0000727
Daniel Boulbya24f23a2023-11-15 18:23:40 +0000728struct ffa_memory_access_impdef {
729 uint64_t val[2];
730};
731
J-Alvesf3a393c2020-10-23 16:00:39 +0100732/**
733 * This corresponds to table "Endpoint memory access descriptor" of the FFA 1.0
734 * specification.
735 */
736struct ffa_memory_access {
737 struct ffa_memory_region_attributes receiver_permissions;
738 /**
739 * Offset in bytes from the start of the outer `ffa_memory_region` to
740 * an `ffa_composite_memory_region` struct.
741 */
742 uint32_t composite_memory_region_offset;
Daniel Boulbya24f23a2023-11-15 18:23:40 +0000743 /* Space for implementation defined information */
744 struct ffa_memory_access_impdef impdef;
J-Alvesf3a393c2020-10-23 16:00:39 +0100745 uint64_t reserved_0;
746};
747
748/**
749 * Information about a set of pages which are being shared. This corresponds to
J-Alvesb42d17f2022-07-04 12:42:13 +0100750 * table 10.20 of the FF-A v1.1 EAC0 specification, "Lend, donate or share
751 * memory transaction descriptor". Note that it is also used for retrieve
752 * requests and responses.
J-Alvesf3a393c2020-10-23 16:00:39 +0100753 */
754struct ffa_memory_region {
755 /**
756 * The ID of the VM which originally sent the memory region, i.e. the
757 * owner.
758 */
Daniel Boulbye79d2072021-03-03 11:34:53 +0000759 ffa_id_t sender;
J-Alvesf3a393c2020-10-23 16:00:39 +0100760 ffa_memory_attributes_t attributes;
J-Alvesf3a393c2020-10-23 16:00:39 +0100761 /** Flags to control behaviour of the transaction. */
762 ffa_memory_region_flags_t flags;
763 ffa_memory_handle_t handle;
764 /**
765 * An implementation defined value associated with the receiver and the
766 * memory region.
767 */
768 uint64_t tag;
J-Alvesb42d17f2022-07-04 12:42:13 +0100769 /** Size of the memory access descriptor. */
770 uint32_t memory_access_desc_size;
J-Alvesf3a393c2020-10-23 16:00:39 +0100771 /**
772 * The number of `ffa_memory_access` entries included in this
773 * transaction.
774 */
775 uint32_t receiver_count;
776 /**
J-Alvesb42d17f2022-07-04 12:42:13 +0100777 * Offset of the 'receivers' field, which relates to the memory access
778 * descriptors.
779 */
780 uint32_t receivers_offset;
781 /** Reserved field (12 bytes) must be 0. */
782 uint32_t reserved[3];
783 /**
784 * An array of `receiver_count` endpoint memory access descriptors.
J-Alvesf3a393c2020-10-23 16:00:39 +0100785 * Each one specifies a memory region offset, an endpoint and the
786 * attributes with which this memory region should be mapped in that
787 * endpoint's page table.
788 */
789 struct ffa_memory_access receivers[];
790};
791
792/**
793 * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table
J-Alvesb42d17f2022-07-04 12:42:13 +0100794 * 16.25 of the FF-A v1.1 EAC0 specification, "Descriptor to relinquish a memory
795 * region".
J-Alvesf3a393c2020-10-23 16:00:39 +0100796 */
797struct ffa_mem_relinquish {
798 ffa_memory_handle_t handle;
799 ffa_memory_region_flags_t flags;
800 uint32_t endpoint_count;
Daniel Boulbye79d2072021-03-03 11:34:53 +0000801 ffa_id_t endpoints[];
J-Alvesf3a393c2020-10-23 16:00:39 +0100802};
803
804static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t h1, uint32_t h2)
805{
J-Alves18c28052021-03-09 09:58:53 +0000806 return (ffa_notification_bitmap_t)h1 |
807 (ffa_notification_bitmap_t)h2 << 32;
J-Alvesf3a393c2020-10-23 16:00:39 +0100808}
809
Daniel Boulbyce386b12022-03-29 18:36:36 +0100810static inline ffa_memory_handle_t ffa_mem_success_handle(struct ffa_value r)
J-Alvesf3a393c2020-10-23 16:00:39 +0100811{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100812 return ffa_assemble_handle(r.arg2, r.arg3);
J-Alvesf3a393c2020-10-23 16:00:39 +0100813}
814
Karl Meakin0d4f5ff2023-10-13 20:03:16 +0100815static inline ffa_memory_handle_t ffa_frag_handle(struct ffa_value r)
816{
817 return ffa_assemble_handle(r.arg1, r.arg2);
818}
819
820static inline ffa_id_t ffa_frag_sender(struct ffa_value args)
821{
822 return (args.arg4 >> 16) & 0xffff;
823}
824
J-Alvesf3a393c2020-10-23 16:00:39 +0100825/**
J-Alvesf0b3bd62024-01-18 17:01:37 +0000826 * To maintain forwards compatability we can't make assumptions about the size
827 * of the endpoint memory access descriptor so provide a helper function
828 * to get a receiver from the receiver array using the memory access descriptor
829 * size field from the memory region descriptor struct.
830 * Returns NULL if we cannot return the receiver.
831 */
832static inline struct ffa_memory_access *ffa_memory_region_get_receiver(
833 struct ffa_memory_region *memory_region, uint32_t receiver_index)
834{
835 uint32_t memory_access_desc_size =
836 memory_region->memory_access_desc_size;
837
838 if (receiver_index >= memory_region->receiver_count) {
839 return NULL;
840 }
841
842 /*
843 * Memory access descriptor size cannot be greater than the size of
844 * the memory access descriptor defined by the current FF-A version.
845 */
846 if (memory_access_desc_size > sizeof(struct ffa_memory_access)) {
847 return NULL;
848 }
849
850 /* Check we cannot use receivers offset to cause overflow. */
851 if (memory_region->receivers_offset !=
852 sizeof(struct ffa_memory_region)) {
853 return NULL;
854 }
855
856 return (struct ffa_memory_access *)((uint8_t *)memory_region +
857 memory_region->receivers_offset +
858 (receiver_index *
859 memory_access_desc_size));
860}
861
862/**
J-Alvesf3a393c2020-10-23 16:00:39 +0100863 * Gets the `ffa_composite_memory_region` for the given receiver from an
864 * `ffa_memory_region`, or NULL if it is not valid.
865 */
866static inline struct ffa_composite_memory_region *
867ffa_memory_region_get_composite(struct ffa_memory_region *memory_region,
868 uint32_t receiver_index)
869{
870 uint32_t offset = memory_region->receivers[receiver_index]
871 .composite_memory_region_offset;
872
873 if (offset == 0) {
874 return NULL;
875 }
876
877 return (struct ffa_composite_memory_region *)((uint8_t *)memory_region +
878 offset);
879}
880
881static inline uint32_t ffa_mem_relinquish_init(
882 struct ffa_mem_relinquish *relinquish_request,
883 ffa_memory_handle_t handle, ffa_memory_region_flags_t flags,
Daniel Boulbye79d2072021-03-03 11:34:53 +0000884 ffa_id_t sender)
J-Alvesf3a393c2020-10-23 16:00:39 +0100885{
886 relinquish_request->handle = handle;
887 relinquish_request->flags = flags;
888 relinquish_request->endpoint_count = 1;
889 relinquish_request->endpoints[0] = sender;
Daniel Boulbye79d2072021-03-03 11:34:53 +0000890 return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_id_t);
J-Alvesf3a393c2020-10-23 16:00:39 +0100891}
892
893uint32_t ffa_memory_retrieve_request_init(
894 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
Karl Meakin1331a8c2023-09-14 16:25:15 +0100895 ffa_id_t sender, struct ffa_memory_access receivers[],
896 uint32_t receiver_count, uint32_t tag, ffa_memory_region_flags_t flags,
J-Alvesf3a393c2020-10-23 16:00:39 +0100897 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
898 enum ffa_memory_shareability shareability);
899
Karl Meakin3d879b82023-06-16 10:32:08 +0100900void ffa_hypervisor_retrieve_request_init(struct ffa_memory_region *region,
901 ffa_memory_handle_t handle);
902
J-Alves80354932024-10-15 11:24:27 +0100903static inline uint32_t ffa_mem_retrieve_res_total_size(struct ffa_value ret)
904{
905 return ret.arg1;
906}
907
908static inline uint32_t ffa_mem_retrieve_res_frag_size(struct ffa_value ret)
909{
910 return ret.arg2;
911}
912
913static inline uint32_t ffa_mem_frag_tx_frag_size(struct ffa_value ret)
914{
915 return ret.arg3;
916}
917
J-Alvesf3a393c2020-10-23 16:00:39 +0100918uint32_t ffa_memory_region_init(
919 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
Karl Meakin1331a8c2023-09-14 16:25:15 +0100920 ffa_id_t sender, struct ffa_memory_access receivers[],
921 uint32_t receiver_count,
J-Alvesf3a393c2020-10-23 16:00:39 +0100922 const struct ffa_memory_region_constituent constituents[],
923 uint32_t constituent_count, uint32_t tag,
Karl Meakin1331a8c2023-09-14 16:25:15 +0100924 ffa_memory_region_flags_t flags, enum ffa_memory_type type,
925 enum ffa_memory_cacheability cacheability,
J-Alvesf3a393c2020-10-23 16:00:39 +0100926 enum ffa_memory_shareability shareability, uint32_t *total_length,
927 uint32_t *fragment_length);
928
Karl Meakin0d4f5ff2023-10-13 20:03:16 +0100929uint32_t ffa_memory_fragment_init(
930 struct ffa_memory_region_constituent *fragment,
931 size_t fragment_max_size,
932 const struct ffa_memory_region_constituent constituents[],
933 uint32_t constituent_count, uint32_t *fragment_length);
934
Daniel Boulbyce386b12022-03-29 18:36:36 +0100935static inline ffa_id_t ffa_dir_msg_dest(struct ffa_value val) {
936 return (ffa_id_t)val.arg1 & U(0xFFFF);
J-Alves6cb21d92021-01-07 15:18:12 +0000937}
938
Daniel Boulbyce386b12022-03-29 18:36:36 +0100939static inline ffa_id_t ffa_dir_msg_source(struct ffa_value val) {
940 return (ffa_id_t)(val.arg1 >> 16U);
J-Alves6cb21d92021-01-07 15:18:12 +0000941}
942
Daniel Boulbyce386b12022-03-29 18:36:36 +0100943struct ffa_value ffa_msg_send_direct_req64(ffa_id_t source_id,
944 ffa_id_t dest_id, uint64_t arg0,
945 uint64_t arg1, uint64_t arg2,
946 uint64_t arg3, uint64_t arg4);
J-Alvesd1aae292020-10-08 17:16:58 +0100947
Daniel Boulbyce386b12022-03-29 18:36:36 +0100948struct ffa_value ffa_msg_send_direct_req32(ffa_id_t source_id,
949 ffa_id_t dest_id, uint32_t arg0,
950 uint32_t arg1, uint32_t arg2,
951 uint32_t arg3, uint32_t arg4);
J-Alvesecd30742021-02-19 18:31:06 +0000952
Daniel Boulbyce386b12022-03-29 18:36:36 +0100953struct ffa_value ffa_msg_send_direct_resp64(ffa_id_t source_id,
954 ffa_id_t dest_id, uint64_t arg0,
955 uint64_t arg1, uint64_t arg2,
956 uint64_t arg3, uint64_t arg4);
J-Alvesecd30742021-02-19 18:31:06 +0000957
Daniel Boulbyce386b12022-03-29 18:36:36 +0100958struct ffa_value ffa_msg_send_direct_resp32(ffa_id_t source_id,
959 ffa_id_t dest_id, uint32_t arg0,
960 uint32_t arg1, uint32_t arg2,
961 uint32_t arg3, uint32_t arg4);
J-Alves035b7d02021-02-11 10:40:35 +0000962
Madhukar Pappireddy611d0952025-01-31 16:07:08 -0600963struct ffa_value ffa_framework_msg_send_direct_resp(ffa_id_t source_id,
964 ffa_id_t dest_id, uint32_t msg,
965 uint32_t status_code);
966
Daniel Boulbyce386b12022-03-29 18:36:36 +0100967struct ffa_value ffa_run(uint32_t dest_id, uint32_t vcpu_id);
Madhukar Pappireddy11e57482025-03-28 11:46:16 -0500968struct ffa_value ffa_yield(void);
Daniel Boulbyce386b12022-03-29 18:36:36 +0100969struct ffa_value ffa_version(uint32_t input_version);
970struct ffa_value ffa_id_get(void);
971struct ffa_value ffa_spm_id_get(void);
972struct ffa_value ffa_msg_wait(void);
973struct ffa_value ffa_error(int32_t error_code);
974struct ffa_value ffa_features(uint32_t feature);
Karl Meakin31b81772023-03-14 15:38:17 +0000975struct ffa_value ffa_features_with_input_property(uint32_t feature,
976 uint32_t param);
Daniel Boulbyce386b12022-03-29 18:36:36 +0100977struct ffa_value ffa_partition_info_get(const struct ffa_uuid uuid);
J-Alves067daca2024-04-08 17:31:54 +0100978struct ffa_value ffa_rx_release_with_id(ffa_id_t vm_id);
Daniel Boulbyce386b12022-03-29 18:36:36 +0100979struct ffa_value ffa_rx_release(void);
980struct ffa_value ffa_rxtx_map(uintptr_t send, uintptr_t recv, uint32_t pages);
Karl Meakinbff9b3c2024-01-18 16:08:35 +0000981struct ffa_value ffa_rxtx_unmap_with_id(uint32_t id);
Daniel Boulbyce386b12022-03-29 18:36:36 +0100982struct ffa_value ffa_rxtx_unmap(void);
J-Alvesffdfafb2024-04-09 12:07:11 +0100983struct ffa_value ffa_msg_send2_with_id(uint32_t flags, ffa_id_t sender);
J-Alves779fba62024-04-05 14:14:40 +0100984struct ffa_value ffa_msg_send2(uint32_t flags);
Daniel Boulbyce386b12022-03-29 18:36:36 +0100985struct ffa_value ffa_mem_donate(uint32_t descriptor_length,
986 uint32_t fragment_length);
987struct ffa_value ffa_mem_lend(uint32_t descriptor_length,
J-Alves3ea46d12020-09-09 11:13:05 +0100988 uint32_t fragment_length);
Daniel Boulbyce386b12022-03-29 18:36:36 +0100989struct ffa_value ffa_mem_share(uint32_t descriptor_length,
990 uint32_t fragment_length);
991struct ffa_value ffa_mem_retrieve_req(uint32_t descriptor_length,
992 uint32_t fragment_length);
993struct ffa_value ffa_mem_relinquish(void);
994struct ffa_value ffa_mem_reclaim(uint64_t handle, uint32_t flags);
Karl Meakin0d4f5ff2023-10-13 20:03:16 +0100995struct ffa_value ffa_mem_frag_rx(ffa_memory_handle_t handle,
996 uint32_t fragment_length);
997struct ffa_value ffa_mem_frag_tx(ffa_memory_handle_t handle,
998 uint32_t fragment_length);
Daniel Boulbyce386b12022-03-29 18:36:36 +0100999struct ffa_value ffa_notification_bitmap_create(ffa_id_t vm_id,
1000 ffa_vcpu_count_t vcpu_count);
1001struct ffa_value ffa_notification_bitmap_destroy(ffa_id_t vm_id);
1002struct ffa_value ffa_notification_bind(ffa_id_t sender, ffa_id_t receiver,
1003 uint32_t flags,
J-Alves18c28052021-03-09 09:58:53 +00001004 ffa_notification_bitmap_t notifications);
Daniel Boulbyce386b12022-03-29 18:36:36 +01001005struct ffa_value ffa_notification_unbind(ffa_id_t sender, ffa_id_t receiver,
1006 ffa_notification_bitmap_t notifications);
1007struct ffa_value ffa_notification_set(ffa_id_t sender, ffa_id_t receiver,
1008 uint32_t flags,
1009 ffa_notification_bitmap_t bitmap);
1010struct ffa_value ffa_notification_get(ffa_id_t receiver, uint32_t vcpu_id,
1011 uint32_t flags);
1012struct ffa_value ffa_notification_info_get(void);
Maksims Svecovs0b452232022-05-24 11:30:34 +01001013
1014struct ffa_value ffa_console_log(const char* message, size_t char_count);
Raghu Krishnamurthyab5321a2023-04-23 16:14:28 -07001015struct ffa_value ffa_partition_info_get_regs(const struct ffa_uuid uuid,
1016 const uint16_t start_index,
1017 const uint16_t tag);
Karl Meakin367ff542023-11-01 15:05:37 +00001018
Daniel Boulbya24f23a2023-11-15 18:23:40 +00001019struct ffa_memory_access ffa_memory_access_init(
Karl Meakin367ff542023-11-01 15:05:37 +00001020 ffa_id_t receiver_id, enum ffa_data_access data_access,
1021 enum ffa_instruction_access instruction_access,
Daniel Boulbya24f23a2023-11-15 18:23:40 +00001022 ffa_memory_receiver_flags_t flags,
1023 struct ffa_memory_access_impdef *impdef);
Karl Meakin367ff542023-11-01 15:05:37 +00001024
Karl Meakinbff9b3c2024-01-18 16:08:35 +00001025void ffa_endpoint_rxtx_descriptor_init(
1026 struct ffa_endpoint_rxtx_descriptor *desc, ffa_id_t endpoint_id,
1027 void *rx_address, void *tx_address);
1028
1029struct ffa_value ffa_rxtx_map_forward(
1030 struct ffa_endpoint_rxtx_descriptor *desc, ffa_id_t endpoint_id,
1031 void *rx_address, void *tx_address);
1032
J-Alves7581c382020-05-07 18:34:20 +01001033#endif /* __ASSEMBLY__ */
1034
1035#endif /* FFA_HELPERS_H */