blob: 6045c7c4ea91fae9493339d58ec22768362ad72d [file] [log] [blame]
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001/*
J-Alves13318e32021-02-22 17:21:00 +00002 * Copyright 2021 The Hafnium Authors.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01003 *
Andrew Walbrane959ec12020-06-17 15:01:09 +01004 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/BSD-3-Clause.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01007 */
8
9#pragma once
10
11#include "hf/types.h"
12
Olivier Deprez62d99e32020-01-09 15:58:07 +010013#define FFA_VERSION_MAJOR 0x1
Olivier Deprez62d99e32020-01-09 15:58:07 +010014#define FFA_VERSION_MAJOR_OFFSET 16
Daniel Boulby6e32c612021-02-17 15:09:41 +000015#define FFA_VERSION_MAJOR_MASK 0x7FFF
Kathleen Capellae4fe2962023-09-01 17:08:47 -040016#define FFA_VERSION_MINOR 0x2
Daniel Boulby6e32c612021-02-17 15:09:41 +000017#define FFA_VERSION_MINOR_OFFSET 0
18#define FFA_VERSION_MINOR_MASK 0xFFFF
19
20#define MAKE_FFA_VERSION(major, minor) \
21 ((((major)&FFA_VERSION_MAJOR_MASK) << FFA_VERSION_MAJOR_OFFSET) | \
22 (((minor)&FFA_VERSION_MINOR_MASK) << FFA_VERSION_MINOR_OFFSET))
23#define FFA_VERSION_COMPILED \
24 MAKE_FFA_VERSION(FFA_VERSION_MAJOR, FFA_VERSION_MINOR)
Olivier Deprez62d99e32020-01-09 15:58:07 +010025
Daniel Boulbyc7dc9322023-10-27 15:12:07 +010026/**
27 * Check major versions are equal and the minor version of the caller is
28 * less than or equal to the minor version of the callee.
29 */
30#define FFA_VERSIONS_ARE_COMPATIBLE(v_caller, v_callee) \
31 ((((v_caller >> FFA_VERSION_MAJOR_OFFSET) & FFA_VERSION_MAJOR_MASK) == \
32 ((v_callee >> FFA_VERSION_MAJOR_OFFSET) & \
33 FFA_VERSION_MAJOR_MASK)) && \
34 (((v_caller >> FFA_VERSION_MINOR_OFFSET) & FFA_VERSION_MINOR_MASK) <= \
35 ((v_callee >> FFA_VERSION_MINOR_OFFSET) & FFA_VERSION_MINOR_MASK)))
36
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010037/* clang-format off */
38
39#define FFA_LOW_32_ID 0x84000060
40#define FFA_HIGH_32_ID 0x8400007F
41#define FFA_LOW_64_ID 0xC4000060
Fuad Tabbada72d142020-07-30 09:17:05 +010042#define FFA_HIGH_64_ID 0xC400007F
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010043
Karl Meakinf51a35f2023-08-07 17:53:52 +010044/**
45 * FF-A function identifiers.
46 * Don't forget to update `ffa_func_name` if you add a new one.
47 */
J-Alves3829fc02021-03-18 12:49:18 +000048#define FFA_ERROR_32 0x84000060
49#define FFA_SUCCESS_32 0x84000061
50#define FFA_SUCCESS_64 0xC4000061
51#define FFA_INTERRUPT_32 0x84000062
52#define FFA_VERSION_32 0x84000063
53#define FFA_FEATURES_32 0x84000064
54#define FFA_RX_RELEASE_32 0x84000065
55#define FFA_RXTX_MAP_32 0x84000066
56#define FFA_RXTX_MAP_64 0xC4000066
57#define FFA_RXTX_UNMAP_32 0x84000067
58#define FFA_PARTITION_INFO_GET_32 0x84000068
59#define FFA_ID_GET_32 0x84000069
60#define FFA_MSG_POLL_32 0x8400006A /* Legacy FF-A v1.0 */
61#define FFA_MSG_WAIT_32 0x8400006B
62#define FFA_YIELD_32 0x8400006C
63#define FFA_RUN_32 0x8400006D
64#define FFA_MSG_SEND_32 0x8400006E /* Legacy FF-A v1.0 */
65#define FFA_MSG_SEND_DIRECT_REQ_32 0x8400006F
66#define FFA_MSG_SEND_DIRECT_REQ_64 0xC400006F
67#define FFA_MSG_SEND_DIRECT_RESP_32 0x84000070
68#define FFA_MSG_SEND_DIRECT_RESP_64 0xC4000070
69#define FFA_MEM_DONATE_32 0x84000071
J-Alves95fbb312024-03-20 15:19:16 +000070#define FFA_MEM_DONATE_64 0xC4000071
J-Alves3829fc02021-03-18 12:49:18 +000071#define FFA_MEM_LEND_32 0x84000072
J-Alves95fbb312024-03-20 15:19:16 +000072#define FFA_MEM_LEND_64 0xC4000072
J-Alves3829fc02021-03-18 12:49:18 +000073#define FFA_MEM_SHARE_32 0x84000073
J-Alves95fbb312024-03-20 15:19:16 +000074#define FFA_MEM_SHARE_64 0xC4000073
J-Alves3829fc02021-03-18 12:49:18 +000075#define FFA_MEM_RETRIEVE_REQ_32 0x84000074
J-Alves95fbb312024-03-20 15:19:16 +000076#define FFA_MEM_RETRIEVE_REQ_64 0xC4000074
J-Alves3829fc02021-03-18 12:49:18 +000077#define FFA_MEM_RETRIEVE_RESP_32 0x84000075
78#define FFA_MEM_RELINQUISH_32 0x84000076
79#define FFA_MEM_RECLAIM_32 0x84000077
80#define FFA_MEM_FRAG_RX_32 0x8400007A
81#define FFA_MEM_FRAG_TX_32 0x8400007B
82#define FFA_NORMAL_WORLD_RESUME 0x8400007C
83
84/* FF-A v1.1 */
85#define FFA_NOTIFICATION_BITMAP_CREATE_32 0x8400007D
86#define FFA_NOTIFICATION_BITMAP_DESTROY_32 0x8400007E
87#define FFA_NOTIFICATION_BIND_32 0x8400007F
88#define FFA_NOTIFICATION_UNBIND_32 0x84000080
89#define FFA_NOTIFICATION_SET_32 0x84000081
90#define FFA_NOTIFICATION_GET_32 0x84000082
91#define FFA_NOTIFICATION_INFO_GET_64 0xC4000083
92#define FFA_RX_ACQUIRE_32 0x84000084
93#define FFA_SPM_ID_GET_32 0x84000085
94#define FFA_MSG_SEND2_32 0x84000086
95#define FFA_SECONDARY_EP_REGISTER_64 0xC4000087
96#define FFA_MEM_PERM_GET_32 0x84000088
97#define FFA_MEM_PERM_SET_32 0x84000089
Raghu Krishnamurthyea6d25f2021-09-14 15:27:06 -070098#define FFA_MEM_PERM_GET_64 0xC4000088
99#define FFA_MEM_PERM_SET_64 0xC4000089
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100100
Kathleen Capellae4fe2962023-09-01 17:08:47 -0400101/* FF-A v1.2 */
Maksims Svecovs71b76702022-05-20 15:32:58 +0100102#define FFA_CONSOLE_LOG_32 0x8400008A
103#define FFA_CONSOLE_LOG_64 0xC400008A
Raghu Krishnamurthy7592bcb2022-12-25 13:09:00 -0800104#define FFA_PARTITION_INFO_GET_REGS_64 0xC400008B
Madhukar Pappireddy77d3bcd2023-03-01 17:26:22 -0600105#define FFA_EL3_INTR_HANDLE_32 0x8400008C
Kathleen Capella41fea932023-06-23 17:39:28 -0400106#define FFA_MSG_SEND_DIRECT_REQ2_64 0xC400008D
Kathleen Capella087e5022023-09-07 18:04:15 -0400107#define FFA_MSG_SEND_DIRECT_RESP2_64 0xC400008E
Maksims Svecovs71b76702022-05-20 15:32:58 +0100108
Karl Meakinf51a35f2023-08-07 17:53:52 +0100109/**
110 * FF-A error codes.
111 * Don't forget to update `ffa_error_name` if you add a new one.
112 */
Karl Meakindc759f52024-05-07 16:08:02 +0100113enum ffa_error {
114 FFA_NOT_SUPPORTED = -1,
115 FFA_INVALID_PARAMETERS = -2,
116 FFA_NO_MEMORY = -3,
117 FFA_BUSY = -4,
118 FFA_INTERRUPTED = -5,
119 FFA_DENIED = -6,
120 FFA_RETRY = -7,
121 FFA_ABORTED = -8,
122 FFA_NO_DATA = -9,
123 FFA_NOT_READY = -10,
124};
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100125
126/* clang-format on */
127
Karl Meakinf51a35f2023-08-07 17:53:52 +0100128/* Return the name of the function identifier. */
129static inline const char *ffa_func_name(uint32_t func)
130{
131 switch (func) {
132 case FFA_ERROR_32:
133 return "FFA_ERROR_32";
134 case FFA_SUCCESS_32:
135 return "FFA_SUCCESS_32";
136 case FFA_SUCCESS_64:
137 return "FFA_SUCCESS_64";
138 case FFA_INTERRUPT_32:
139 return "FFA_INTERRUPT_32";
140 case FFA_VERSION_32:
141 return "FFA_VERSION_32";
142 case FFA_FEATURES_32:
143 return "FFA_FEATURES_32";
144 case FFA_RX_RELEASE_32:
145 return "FFA_RX_RELEASE_32";
146 case FFA_RXTX_MAP_32:
147 return "FFA_RXTX_MAP_32";
148 case FFA_RXTX_MAP_64:
149 return "FFA_RXTX_MAP_64";
150 case FFA_RXTX_UNMAP_32:
151 return "FFA_RXTX_UNMAP_32";
152 case FFA_PARTITION_INFO_GET_32:
153 return "FFA_PARTITION_INFO_GET_32";
154 case FFA_ID_GET_32:
155 return "FFA_ID_GET_32";
156 case FFA_MSG_POLL_32:
157 return "FFA_MSG_POLL_32";
158 case FFA_MSG_WAIT_32:
159 return "FFA_MSG_WAIT_32";
160 case FFA_YIELD_32:
161 return "FFA_YIELD_32";
162 case FFA_RUN_32:
163 return "FFA_RUN_32";
164 case FFA_MSG_SEND_32:
165 return "FFA_MSG_SEND_32";
166 case FFA_MSG_SEND_DIRECT_REQ_32:
167 return "FFA_MSG_SEND_DIRECT_REQ_32";
168 case FFA_MSG_SEND_DIRECT_REQ_64:
169 return "FFA_MSG_SEND_DIRECT_REQ_64";
170 case FFA_MSG_SEND_DIRECT_RESP_32:
171 return "FFA_MSG_SEND_DIRECT_RESP_32";
172 case FFA_MSG_SEND_DIRECT_RESP_64:
173 return "FFA_MSG_SEND_DIRECT_RESP_64";
174 case FFA_MEM_DONATE_32:
175 return "FFA_MEM_DONATE_32";
176 case FFA_MEM_LEND_32:
177 return "FFA_MEM_LEND_32";
178 case FFA_MEM_SHARE_32:
179 return "FFA_MEM_SHARE_32";
180 case FFA_MEM_RETRIEVE_REQ_32:
181 return "FFA_MEM_RETRIEVE_REQ_32";
J-Alves95fbb312024-03-20 15:19:16 +0000182 case FFA_MEM_DONATE_64:
183 return "FFA_MEM_DONATE_64";
184 case FFA_MEM_LEND_64:
185 return "FFA_MEM_LEND_64";
186 case FFA_MEM_SHARE_64:
187 return "FFA_MEM_SHARE_64";
188 case FFA_MEM_RETRIEVE_REQ_64:
189 return "FFA_MEM_RETRIEVE_REQ_64";
Karl Meakinf51a35f2023-08-07 17:53:52 +0100190 case FFA_MEM_RETRIEVE_RESP_32:
191 return "FFA_MEM_RETRIEVE_RESP_32";
192 case FFA_MEM_RELINQUISH_32:
193 return "FFA_MEM_RELINQUISH_32";
194 case FFA_MEM_RECLAIM_32:
195 return "FFA_MEM_RECLAIM_32";
196 case FFA_MEM_FRAG_RX_32:
197 return "FFA_MEM_FRAG_RX_32";
198 case FFA_MEM_FRAG_TX_32:
199 return "FFA_MEM_FRAG_TX_32";
200 case FFA_NORMAL_WORLD_RESUME:
201 return "FFA_NORMAL_WORLD_RESUME";
202
203 /* FF-A v1.1 */
204 case FFA_NOTIFICATION_BITMAP_CREATE_32:
205 return "FFA_NOTIFICATION_BITMAP_CREATE_32";
206 case FFA_NOTIFICATION_BITMAP_DESTROY_32:
207 return "FFA_NOTIFICATION_BITMAP_DESTROY_32";
208 case FFA_NOTIFICATION_BIND_32:
209 return "FFA_NOTIFICATION_BIND_32";
210 case FFA_NOTIFICATION_UNBIND_32:
211 return "FFA_NOTIFICATION_UNBIND_32";
212 case FFA_NOTIFICATION_SET_32:
213 return "FFA_NOTIFICATION_SET_32";
214 case FFA_NOTIFICATION_GET_32:
215 return "FFA_NOTIFICATION_GET_32";
216 case FFA_NOTIFICATION_INFO_GET_64:
217 return "FFA_NOTIFICATION_INFO_GET_64";
218 case FFA_RX_ACQUIRE_32:
219 return "FFA_RX_ACQUIRE_32";
220 case FFA_SPM_ID_GET_32:
221 return "FFA_SPM_ID_GET_32";
222 case FFA_MSG_SEND2_32:
223 return "FFA_MSG_SEND2_32";
224 case FFA_SECONDARY_EP_REGISTER_64:
225 return "FFA_SECONDARY_EP_REGISTER_64";
226 case FFA_MEM_PERM_GET_32:
227 return "FFA_MEM_PERM_GET_32";
228 case FFA_MEM_PERM_SET_32:
229 return "FFA_MEM_PERM_SET_32";
230 case FFA_MEM_PERM_GET_64:
231 return "FFA_MEM_PERM_GET_64";
232 case FFA_MEM_PERM_SET_64:
233 return "FFA_MEM_PERM_SET_64";
234
235 /* Implementation-defined ABIs. */
236 case FFA_CONSOLE_LOG_32:
237 return "FFA_CONSOLE_LOG_32";
238 case FFA_CONSOLE_LOG_64:
239 return "FFA_CONSOLE_LOG_64";
240 case FFA_PARTITION_INFO_GET_REGS_64:
241 return "FFA_PARTITION_INFO_GET_REGS_64";
242 case FFA_EL3_INTR_HANDLE_32:
243 return "FFA_EL3_INTR_HANDLE_32";
244
245 default:
246 return "UNKNOWN";
247 }
248}
249
250/* Return the name of the error code. */
Karl Meakindc759f52024-05-07 16:08:02 +0100251static inline const char *ffa_error_name(enum ffa_error error)
Karl Meakinf51a35f2023-08-07 17:53:52 +0100252{
253 switch (error) {
254 case FFA_NOT_SUPPORTED:
255 return "FFA_NOT_SUPPORTED";
256 case FFA_INVALID_PARAMETERS:
257 return "FFA_INVALID_PARAMETERS";
258 case FFA_NO_MEMORY:
259 return "FFA_NO_MEMORY";
260 case FFA_BUSY:
261 return "FFA_BUSY";
262 case FFA_INTERRUPTED:
263 return "FFA_INTERRUPTED";
264 case FFA_DENIED:
265 return "FFA_DENIED";
266 case FFA_RETRY:
267 return "FFA_RETRY";
268 case FFA_ABORTED:
269 return "FFA_ABORTED";
270 case FFA_NO_DATA:
271 return "FFA_NO_DATA";
Karl Meakindc759f52024-05-07 16:08:02 +0100272 case FFA_NOT_READY:
273 return "FFA_NOT_READY";
Karl Meakinf51a35f2023-08-07 17:53:52 +0100274 }
Karl Meakindc759f52024-05-07 16:08:02 +0100275 return "UNKNOWN";
Karl Meakinf51a35f2023-08-07 17:53:52 +0100276}
277
J-Alves6f72ca82021-11-01 12:34:58 +0000278/**
279 * FF-A Feature ID, to be used with interface FFA_FEATURES.
280 * As defined in the FF-A v1.1 Beta specification, table 13.10, in section
281 * 13.2.
282 */
283
Olivier Deprezb76307d2022-06-09 17:17:45 +0200284#define FFA_FEATURES_FUNC_ID_MASK (UINT32_C(1) << 31)
J-Alves6f72ca82021-11-01 12:34:58 +0000285#define FFA_FEATURES_FEATURE_ID_MASK UINT32_C(0x7F)
286
Karl Meakin34b8ae92023-01-13 13:33:07 +0000287/**
288 * Defined in Table 13.14 in the FF-A v.1.1 REL0 specification.
289 * Bits[31:2] and Bit[0] of input are reserved (must be zero).
290 * Bit[0]: dynamically allocated buffer support.
291 * Bit[1]: NS bit handling.
292 * Bit[2]: support for retrieval by hypervisor.
293 */
294#define FFA_FEATURES_MEM_RETRIEVE_REQ_BUFFER_SUPPORT 0
295#define FFA_FEATURES_MEM_RETRIEVE_REQ_NS_SUPPORT (UINT32_C(1) << 1)
296#define FFA_FEATURES_MEM_RETRIEVE_REQ_HYPERVISOR_SUPPORT (UINT32_C(1) << 2)
297#define FFA_FEATURES_MEM_RETRIEVE_REQ_MBZ_MASK \
298 (~(FFA_FEATURES_MEM_RETRIEVE_REQ_BUFFER_SUPPORT | \
299 FFA_FEATURES_MEM_RETRIEVE_REQ_NS_SUPPORT | \
300 FFA_FEATURES_MEM_RETRIEVE_REQ_HYPERVISOR_SUPPORT))
301
J-Alves6f72ca82021-11-01 12:34:58 +0000302/* Query interrupt ID of Notification Pending Interrupt. */
303#define FFA_FEATURE_NPI 0x1U
304
305/* Query interrupt ID of Schedule Receiver Interrupt. */
306#define FFA_FEATURE_SRI 0x2U
307
308/* Query interrupt ID of the Managed Exit Interrupt. */
309#define FFA_FEATURE_MEI 0x3U
310
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100311/* FF-A function specific constants. */
312#define FFA_MSG_RECV_BLOCK 0x1
313#define FFA_MSG_RECV_BLOCK_MASK 0x1
314
315#define FFA_MSG_SEND_NOTIFY 0x1
316#define FFA_MSG_SEND_NOTIFY_MASK 0x1
317
318#define FFA_MEM_RECLAIM_CLEAR 0x1
319
320#define FFA_SLEEP_INDEFINITE 0
321
Raghu Krishnamurthyea6d25f2021-09-14 15:27:06 -0700322#define FFA_MEM_PERM_RO UINT32_C(0x7)
323#define FFA_MEM_PERM_RW UINT32_C(0x5)
324#define FFA_MEM_PERM_RX UINT32_C(0x3)
325
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000326/*
Olivier Deprez013f4d62022-11-21 15:46:20 +0100327 * Defined in Table 13.34 in the FF-A v1.1 EAC0 specification.
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000328 * The Partition count flag is used by FFA_PARTITION_INFO_GET to specify
329 * if partition info descriptors should be returned or just the count.
330 */
Olivier Deprez013f4d62022-11-21 15:46:20 +0100331#define FFA_PARTITION_COUNT_FLAG UINT32_C(0x1)
332#define FFA_PARTITION_COUNT_FLAG_MASK (UINT32_C(0x1) << 0)
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000333
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100334/**
335 * For use where the FF-A specification refers explicitly to '4K pages'. Not to
336 * be confused with PAGE_SIZE, which is the translation granule Hafnium is
337 * configured to use.
338 */
J-Alves715d6232023-02-16 16:33:28 +0000339#define FFA_PAGE_SIZE ((size_t)4096)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100340
Federico Recanatifc0295e2022-02-08 19:37:39 +0100341/** The ID of a VM. These are assigned sequentially starting with an offset. */
J-Alves19e20cf2023-08-02 12:48:55 +0100342typedef uint16_t ffa_id_t;
Federico Recanatifc0295e2022-02-08 19:37:39 +0100343
344/**
J-Alves661e1b72023-08-02 13:39:40 +0100345 * The FF-A v1.2 ALP0, section 6.1 defines that partition IDs are split into two
346 * parts:
347 * - Bit15 -> partition type identifier.
348 * - b'0 -> ID relates to a VM ID.
349 * - b'1 -> ID relates to an SP ID.
350 */
351#define FFA_ID_MASK ((ffa_id_t)0x8000)
352#define FFA_VM_ID_MASK ((ffa_id_t)0x0000)
353
354/**
355 * Helper to check if FF-A ID is a VM ID, managed by the hypervisor.
356 */
357static inline bool ffa_is_vm_id(ffa_id_t id)
358{
359 return (FFA_ID_MASK & id) == FFA_VM_ID_MASK;
360}
361
362/**
Federico Recanatifc0295e2022-02-08 19:37:39 +0100363 * Partition message header as specified by table 6.2 from FF-A v1.1 EAC0
364 * specification.
365 */
366struct ffa_partition_rxtx_header {
367 uint32_t flags; /* MBZ */
368 uint32_t reserved;
369 /* Offset from the beginning of the buffer to the message payload. */
370 uint32_t offset;
371 /* Sender(Bits[31:16]) and Receiver(Bits[15:0]) endpoint IDs. */
372 uint32_t sender_receiver;
373 /* Size of message in buffer. */
374 uint32_t size;
375};
376
377#define FFA_RXTX_HEADER_SIZE sizeof(struct ffa_partition_rxtx_header)
378#define FFA_RXTX_SENDER_SHIFT (0x10U)
J-Alves70079932022-12-07 17:32:20 +0000379#define FFA_RXTX_ALLOCATOR_SHIFT 16
Federico Recanatifc0295e2022-02-08 19:37:39 +0100380
381static inline void ffa_rxtx_header_init(
J-Alves19e20cf2023-08-02 12:48:55 +0100382 ffa_id_t sender, ffa_id_t receiver, uint32_t size,
Federico Recanatifc0295e2022-02-08 19:37:39 +0100383 struct ffa_partition_rxtx_header *header)
384{
385 header->flags = 0;
386 header->reserved = 0;
387 header->offset = FFA_RXTX_HEADER_SIZE;
388 header->sender_receiver =
389 (uint32_t)(receiver | (sender << FFA_RXTX_SENDER_SHIFT));
390 header->size = size;
391}
392
J-Alves19e20cf2023-08-02 12:48:55 +0100393static inline ffa_id_t ffa_rxtx_header_sender(
Federico Recanatifc0295e2022-02-08 19:37:39 +0100394 const struct ffa_partition_rxtx_header *h)
395{
J-Alves19e20cf2023-08-02 12:48:55 +0100396 return (ffa_id_t)(h->sender_receiver >> FFA_RXTX_SENDER_SHIFT);
Federico Recanatifc0295e2022-02-08 19:37:39 +0100397}
398
J-Alves19e20cf2023-08-02 12:48:55 +0100399static inline ffa_id_t ffa_rxtx_header_receiver(
Federico Recanatifc0295e2022-02-08 19:37:39 +0100400 const struct ffa_partition_rxtx_header *h)
401{
J-Alves19e20cf2023-08-02 12:48:55 +0100402 return (ffa_id_t)(h->sender_receiver);
Federico Recanatifc0295e2022-02-08 19:37:39 +0100403}
404
405/* The maximum length possible for a single message. */
406#define FFA_PARTITION_MSG_PAYLOAD_MAX (HF_MAILBOX_SIZE - FFA_RXTX_HEADER_SIZE)
407
408struct ffa_partition_msg {
409 struct ffa_partition_rxtx_header header;
410 char payload[FFA_PARTITION_MSG_PAYLOAD_MAX];
411};
412
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100413/* The maximum length possible for a single message. */
414#define FFA_MSG_PAYLOAD_MAX HF_MAILBOX_SIZE
415
416enum ffa_data_access {
417 FFA_DATA_ACCESS_NOT_SPECIFIED,
418 FFA_DATA_ACCESS_RO,
419 FFA_DATA_ACCESS_RW,
420 FFA_DATA_ACCESS_RESERVED,
421};
422
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100423static inline const char *ffa_data_access_name(enum ffa_data_access data_access)
424{
425 switch (data_access) {
426 case FFA_DATA_ACCESS_NOT_SPECIFIED:
427 return "FFA_DATA_ACCESS_NOT_SPECIFIED";
428 case FFA_DATA_ACCESS_RO:
429 return "FFA_DATA_ACCESS_RO";
430 case FFA_DATA_ACCESS_RW:
431 return "FFA_DATA_ACCESS_RW";
432 case FFA_DATA_ACCESS_RESERVED:
433 return "FFA_DATA_ACCESS_RESERVED";
434 }
435}
436
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100437enum ffa_instruction_access {
438 FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED,
439 FFA_INSTRUCTION_ACCESS_NX,
440 FFA_INSTRUCTION_ACCESS_X,
441 FFA_INSTRUCTION_ACCESS_RESERVED,
442};
443
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100444static inline const char *ffa_instruction_access_name(
445 enum ffa_instruction_access instruction_access)
446{
447 switch (instruction_access) {
448 case FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED:
449 return "FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED";
450 case FFA_INSTRUCTION_ACCESS_NX:
451 return "FFA_INSTRUCTION_ACCESS_NX";
452 case FFA_INSTRUCTION_ACCESS_X:
453 return "FFA_INSTRUCTION_ACCESS_X";
454 case FFA_INSTRUCTION_ACCESS_RESERVED:
455 return "FFA_INSTRUCTION_ACCESS_RESERVED";
456 }
457}
458
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100459enum ffa_memory_type {
460 FFA_MEMORY_NOT_SPECIFIED_MEM,
461 FFA_MEMORY_DEVICE_MEM,
462 FFA_MEMORY_NORMAL_MEM,
463};
464
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100465static inline const char *ffa_memory_type_name(enum ffa_memory_type type)
466{
467 switch (type) {
468 case FFA_MEMORY_NOT_SPECIFIED_MEM:
469 return "FFA_MEMORY_NOT_SPECIFIED_MEM";
470 case FFA_MEMORY_DEVICE_MEM:
471 return "FFA_MEMORY_DEVICE_MEM";
472 case FFA_MEMORY_NORMAL_MEM:
473 return "FFA_MEMORY_NORMAL_MEM";
474 }
475}
476
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100477enum ffa_memory_cacheability {
478 FFA_MEMORY_CACHE_RESERVED = 0x0,
479 FFA_MEMORY_CACHE_NON_CACHEABLE = 0x1,
480 FFA_MEMORY_CACHE_RESERVED_1 = 0x2,
481 FFA_MEMORY_CACHE_WRITE_BACK = 0x3,
482 FFA_MEMORY_DEV_NGNRNE = 0x0,
483 FFA_MEMORY_DEV_NGNRE = 0x1,
484 FFA_MEMORY_DEV_NGRE = 0x2,
485 FFA_MEMORY_DEV_GRE = 0x3,
486};
487
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100488static inline const char *ffa_memory_cacheability_name(
489 enum ffa_memory_cacheability cacheability)
490{
491 switch (cacheability) {
492 case FFA_MEMORY_CACHE_RESERVED:
493 return "FFA_MEMORY_CACHE_RESERVED";
494 case FFA_MEMORY_CACHE_NON_CACHEABLE:
495 return "FFA_MEMORY_CACHE_NON_CACHEABLE";
496 case FFA_MEMORY_CACHE_RESERVED_1:
497 return "FFA_MEMORY_CACHE_RESERVED_1";
498 case FFA_MEMORY_CACHE_WRITE_BACK:
499 return "FFA_MEMORY_CACHE_WRITE_BACK";
500 }
501}
502
Daniel Boulby9764ff62024-01-30 17:47:39 +0000503static inline const char *ffa_device_memory_cacheability_name(
504 enum ffa_memory_cacheability cacheability)
505{
506 switch (cacheability) {
507 case FFA_MEMORY_DEV_NGNRNE:
508 return "FFA_MEMORY_DEV_NGNRNE";
509 case FFA_MEMORY_DEV_NGNRE:
510 return "FFA_MEMORY_DEV_NGNRE";
511 case FFA_MEMORY_DEV_NGRE:
512 return "FFA_MEMORY_DEV_NGRE";
513 case FFA_MEMORY_DEV_GRE:
514 return "FFA_MEMORY_DEV_GRE";
515 }
516}
517
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100518enum ffa_memory_shareability {
519 FFA_MEMORY_SHARE_NON_SHAREABLE,
520 FFA_MEMORY_SHARE_RESERVED,
521 FFA_MEMORY_OUTER_SHAREABLE,
522 FFA_MEMORY_INNER_SHAREABLE,
523};
524
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100525static inline const char *ffa_memory_shareability_name(
526 enum ffa_memory_shareability shareability)
527{
528 switch (shareability) {
529 case FFA_MEMORY_SHARE_NON_SHAREABLE:
530 return "FFA_MEMORY_SHARE_NON_SHAREABLE";
531 case FFA_MEMORY_SHARE_RESERVED:
532 return "FFA_MEMORY_SHARE_RESERVED";
533 case FFA_MEMORY_OUTER_SHAREABLE:
534 return "FFA_MEMORY_OUTER_SHAREABLE";
535 case FFA_MEMORY_INNER_SHAREABLE:
536 return "FFA_MEMORY_INNER_SHAREABLE";
537 }
538}
539
Olivier Deprez4342a3c2022-02-28 09:37:25 +0100540/**
541 * FF-A v1.1 REL0 Table 10.18 memory region attributes descriptor NS Bit 6.
542 * Per section 10.10.4.1, NS bit is reserved for FFA_MEM_DONATE/LEND/SHARE
543 * and FFA_MEM_RETRIEVE_REQUEST.
544 */
545enum ffa_memory_security {
546 FFA_MEMORY_SECURITY_UNSPECIFIED = 0,
547 FFA_MEMORY_SECURITY_SECURE = 0,
548 FFA_MEMORY_SECURITY_NON_SECURE,
549};
550
Karl Meakinf98b2aa2023-10-12 16:09:59 +0100551static inline const char *ffa_memory_security_name(
552 enum ffa_memory_security security)
553{
554 switch (security) {
555 case FFA_MEMORY_SECURITY_UNSPECIFIED:
556 return "FFA_MEMORY_SECURITY_UNSPECIFIED";
557 case FFA_MEMORY_SECURITY_NON_SECURE:
558 return "FFA_MEMORY_SECURITY_NON_SECURE";
559 }
560}
561
Karl Meakin84710f32023-10-12 15:14:49 +0100562typedef struct {
563 uint8_t data_access : 2;
564 uint8_t instruction_access : 2;
565} ffa_memory_access_permissions_t;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100566
567/**
J-Alves0b6653d2022-04-22 13:17:38 +0100568 * This corresponds to table 10.18 of the FF-A v1.1 EAC0 specification, "Memory
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100569 * region attributes descriptor".
570 */
Karl Meakin84710f32023-10-12 15:14:49 +0100571typedef struct {
572 uint8_t shareability : 2;
573 uint8_t cacheability : 2;
574 uint8_t type : 2;
575 uint8_t security : 2;
576 uint8_t : 8;
577} ffa_memory_attributes_t;
J-Alves0b6653d2022-04-22 13:17:38 +0100578
579/* FF-A v1.1 EAC0 states bit [15:7] Must Be Zero. */
580#define FFA_MEMORY_ATTRIBUTES_MBZ_MASK 0xFF80U
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100581
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100582/**
583 * A globally-unique ID assigned by the hypervisor for a region of memory being
584 * sent between VMs.
585 */
586typedef uint64_t ffa_memory_handle_t;
587
J-Alves917d2f22020-10-30 18:39:30 +0000588#define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \
589 ((ffa_memory_handle_t)(UINT64_C(1) << 63))
590#define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR \
591 ((ffa_memory_handle_t)(UINT64_C(1) << 63))
592
593#define FFA_MEMORY_HANDLE_ALLOCATOR_SPMC (UINT64_C(0) << 63)
594#define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0))
595
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100596/**
597 * A count of VMs. This has the same range as the VM IDs but we give it a
598 * different name to make the different semantics clear.
599 */
J-Alves19e20cf2023-08-02 12:48:55 +0100600typedef ffa_id_t ffa_vm_count_t;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100601
602/** The index of a vCPU within a particular VM. */
603typedef uint16_t ffa_vcpu_index_t;
604
605/**
606 * A count of vCPUs. This has the same range as the vCPU indices but we give it
607 * a different name to make the different semantics clear.
608 */
609typedef ffa_vcpu_index_t ffa_vcpu_count_t;
610
611/** Parameter and return type of FF-A functions. */
612struct ffa_value {
613 uint64_t func;
614 uint64_t arg1;
615 uint64_t arg2;
616 uint64_t arg3;
617 uint64_t arg4;
618 uint64_t arg5;
619 uint64_t arg6;
620 uint64_t arg7;
Raghu Krishnamurthy567068e2022-12-26 07:46:38 -0800621
622 struct {
623 uint64_t arg8;
624 uint64_t arg9;
625 uint64_t arg10;
626 uint64_t arg11;
627 uint64_t arg12;
628 uint64_t arg13;
629 uint64_t arg14;
630 uint64_t arg15;
631 uint64_t arg16;
632 uint64_t arg17;
633 bool valid;
634 } extended_val;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100635};
636
Olivier Depreze562e542020-06-11 17:31:54 +0200637static inline uint32_t ffa_func_id(struct ffa_value args)
638{
639 return args.func;
640}
641
Karl Meakindc759f52024-05-07 16:08:02 +0100642static inline enum ffa_error ffa_error_code(struct ffa_value val)
J-Alves13318e32021-02-22 17:21:00 +0000643{
Karl Meakindc759f52024-05-07 16:08:02 +0100644 return (enum ffa_error)val.arg2;
J-Alves13318e32021-02-22 17:21:00 +0000645}
646
J-Alves19e20cf2023-08-02 12:48:55 +0100647static inline ffa_id_t ffa_sender(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100648{
649 return (args.arg1 >> 16) & 0xffff;
650}
651
J-Alves19e20cf2023-08-02 12:48:55 +0100652static inline ffa_id_t ffa_receiver(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100653{
654 return args.arg1 & 0xffff;
655}
656
657static inline uint32_t ffa_msg_send_size(struct ffa_value args)
658{
659 return args.arg3;
660}
661
Federico Recanati25053ee2022-03-14 15:01:53 +0100662static inline uint32_t ffa_msg_send2_flags(struct ffa_value args)
663{
664 return args.arg2;
665}
666
Olivier Depreze562e542020-06-11 17:31:54 +0200667static inline uint32_t ffa_partition_info_get_count(struct ffa_value args)
668{
669 return args.arg2;
670}
671
Raghu Krishnamurthy2957b922022-12-27 10:29:12 -0800672static inline uint16_t ffa_partition_info_regs_get_last_idx(
673 struct ffa_value args)
674{
675 return args.arg2 & 0xFFFF;
676}
677
678static inline uint16_t ffa_partition_info_regs_get_curr_idx(
679 struct ffa_value args)
680{
681 return (args.arg2 >> 16) & 0xFFFF;
682}
683
684static inline uint16_t ffa_partition_info_regs_get_tag(struct ffa_value args)
685{
686 return (args.arg2 >> 32) & 0xFFFF;
687}
688
689static inline uint16_t ffa_partition_info_regs_get_desc_size(
690 struct ffa_value args)
691{
692 return (args.arg2 >> 48);
693}
694
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100695static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t a1, uint32_t a2)
696{
697 return (uint64_t)a1 | (uint64_t)a2 << 32;
698}
699
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100700static inline ffa_memory_handle_t ffa_mem_success_handle(struct ffa_value args)
701{
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100702 return ffa_assemble_handle(args.arg2, args.arg3);
703}
704
Andrew Walbranca808b12020-05-15 17:22:28 +0100705static inline ffa_memory_handle_t ffa_frag_handle(struct ffa_value args)
706{
707 return ffa_assemble_handle(args.arg1, args.arg2);
708}
709
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100710static inline struct ffa_value ffa_mem_success(ffa_memory_handle_t handle)
711{
712 return (struct ffa_value){.func = FFA_SUCCESS_32,
713 .arg2 = (uint32_t)handle,
714 .arg3 = (uint32_t)(handle >> 32)};
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100715}
716
J-Alves19e20cf2023-08-02 12:48:55 +0100717static inline ffa_id_t ffa_vm_id(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100718{
719 return (args.arg1 >> 16) & 0xffff;
720}
721
722static inline ffa_vcpu_index_t ffa_vcpu_index(struct ffa_value args)
723{
724 return args.arg1 & 0xffff;
725}
726
J-Alves19e20cf2023-08-02 12:48:55 +0100727static inline uint64_t ffa_vm_vcpu(ffa_id_t vm_id, ffa_vcpu_index_t vcpu_index)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100728{
729 return ((uint32_t)vm_id << 16) | vcpu_index;
730}
731
J-Alves19e20cf2023-08-02 12:48:55 +0100732static inline ffa_id_t ffa_frag_sender(struct ffa_value args)
Andrew Walbranca808b12020-05-15 17:22:28 +0100733{
734 return (args.arg4 >> 16) & 0xffff;
735}
736
J-Alves6f72ca82021-11-01 12:34:58 +0000737static inline uint32_t ffa_feature_intid(struct ffa_value args)
738{
739 return (uint32_t)args.arg2;
740}
741
Daniel Boulbyefa381f2022-01-18 14:49:40 +0000742static inline uint32_t ffa_fwk_msg(struct ffa_value args)
743{
744 return (uint32_t)args.arg2;
745}
746
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100747/**
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100748 * Holds the UUID in a struct that is mappable directly to the SMCC calling
749 * convention, which is used for FF-A calls.
750 *
751 * Refer to table 84 of the FF-A 1.0 EAC specification as well as section 5.3
752 * of the SMCC Spec 1.2.
753 */
754struct ffa_uuid {
755 uint32_t uuid[4];
756};
757
758static inline void ffa_uuid_init(uint32_t w0, uint32_t w1, uint32_t w2,
759 uint32_t w3, struct ffa_uuid *uuid)
760{
761 uuid->uuid[0] = w0;
762 uuid->uuid[1] = w1;
763 uuid->uuid[2] = w2;
764 uuid->uuid[3] = w3;
765}
766
767static inline bool ffa_uuid_equal(const struct ffa_uuid *uuid1,
768 const struct ffa_uuid *uuid2)
769{
770 return (uuid1->uuid[0] == uuid2->uuid[0]) &&
771 (uuid1->uuid[1] == uuid2->uuid[1]) &&
772 (uuid1->uuid[2] == uuid2->uuid[2]) &&
773 (uuid1->uuid[3] == uuid2->uuid[3]);
774}
775
776static inline bool ffa_uuid_is_null(const struct ffa_uuid *uuid)
777{
778 return (uuid->uuid[0] == 0) && (uuid->uuid[1] == 0) &&
779 (uuid->uuid[2] == 0) && (uuid->uuid[3] == 0);
780}
781
Kathleen Capella41fea932023-06-23 17:39:28 -0400782static inline void ffa_uuid_unpack_from_uint64(uint64_t uuid_lo,
783 uint64_t uuid_hi,
784 struct ffa_uuid *uuid)
785{
786 ffa_uuid_init((uint32_t)(uuid_lo & 0xFFFFFFFFU),
787 (uint32_t)(uuid_lo >> 32),
788 (uint32_t)(uuid_hi & 0xFFFFFFFFU),
789 (uint32_t)(uuid_hi >> 32), uuid);
790}
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100791/**
792 * Flags to determine the partition properties, as required by
793 * FFA_PARTITION_INFO_GET.
794 *
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400795 * 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 +0100796 * specification, "Partition information descriptor, partition properties".
797 */
798typedef uint32_t ffa_partition_properties_t;
799
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400800/**
801 * Partition property: partition supports receipt of direct requests via the
802 * FFA_MSG_SEND_DIRECT_REQ ABI.
803 */
Kathleen Capella402fa852022-11-09 16:16:51 -0500804#define FFA_PARTITION_DIRECT_REQ_RECV (UINT32_C(1) << 0)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100805
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400806/**
807 * Partition property: partition can send direct requests via the
808 * FFA_MSG_SEND_DIRECT_REQ ABI.
809 */
Kathleen Capella402fa852022-11-09 16:16:51 -0500810#define FFA_PARTITION_DIRECT_REQ_SEND (UINT32_C(1) << 1)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100811
812/** Partition property: partition can send and receive indirect messages. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500813#define FFA_PARTITION_INDIRECT_MSG (UINT32_C(1) << 2)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100814
J-Alves09ff9d82021-11-02 11:55:20 +0000815/** Partition property: partition can receive notifications. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500816#define FFA_PARTITION_NOTIFICATION (UINT32_C(1) << 3)
817
818/** Partition property: partition runs in the AArch64 execution state. */
819#define FFA_PARTITION_AARCH64_EXEC (UINT32_C(1) << 8)
J-Alves09ff9d82021-11-02 11:55:20 +0000820
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100821/**
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400822 * Partition property: partition supports receipt of direct requests via the
823 * FFA_MSG_SEND_DIRECT_REQ2 ABI.
824 */
825#define FFA_PARTITION_DIRECT_REQ2_RECV (UINT32_C(1) << 9)
826
827/**
828 * Partition property: partition can send direct requests via the
829 * FFA_MSG_SEND_DIRECT_REQ2 ABI.
830 */
831#define FFA_PARTITION_DIRECT_REQ2_SEND (UINT32_C(1) << 10)
832
833/**
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100834 * Holds information returned for each partition by the FFA_PARTITION_INFO_GET
835 * interface.
Kathleen Capella402fa852022-11-09 16:16:51 -0500836 * This corresponds to table 13.37 "Partition information descriptor"
837 * in FF-A 1.1 EAC0 specification.
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000838 */
839struct ffa_partition_info {
J-Alves19e20cf2023-08-02 12:48:55 +0100840 ffa_id_t vm_id;
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000841 ffa_vcpu_count_t vcpu_count;
842 ffa_partition_properties_t properties;
843 struct ffa_uuid uuid;
844};
845
J-Alvesdd1ad572022-01-25 17:58:26 +0000846/** Length in bytes of the name in boot information descriptor. */
847#define FFA_BOOT_INFO_NAME_LEN 16
848
J-Alves240d84c2022-04-22 12:19:34 +0100849/**
850 * The FF-A boot info descriptor, as defined in table 5.8 of section 5.4.1, of
851 * the FF-A v1.1 EAC0 specification.
852 */
J-Alvesdd1ad572022-01-25 17:58:26 +0000853struct ffa_boot_info_desc {
854 char name[FFA_BOOT_INFO_NAME_LEN];
855 uint8_t type;
856 uint8_t reserved;
857 uint16_t flags;
858 uint32_t size;
859 uint64_t content;
860};
861
862/** FF-A boot information type mask. */
863#define FFA_BOOT_INFO_TYPE_SHIFT 7
864#define FFA_BOOT_INFO_TYPE_MASK (0x1U << FFA_BOOT_INFO_TYPE_SHIFT)
865#define FFA_BOOT_INFO_TYPE_STD 0U
866#define FFA_BOOT_INFO_TYPE_IMPDEF 1U
867
868/** Standard boot info type IDs. */
869#define FFA_BOOT_INFO_TYPE_ID_MASK 0x7FU
870#define FFA_BOOT_INFO_TYPE_ID_FDT 0U
871#define FFA_BOOT_INFO_TYPE_ID_HOB 1U
872
873/** FF-A Boot Info descriptors flags. */
874#define FFA_BOOT_INFO_FLAG_MBZ_MASK 0xFFF0U
875
876/** Bits [1:0] encode the format of the name field in ffa_boot_info_desc. */
877#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT 0U
878#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK \
879 (0x3U << FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT)
880#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING 0x0U
881#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID 0x1U
882
883/** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */
884#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT 2
885#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK \
886 (0x3U << FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT)
887#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE 0x1U
888#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR 0x0U
889
890static inline uint16_t ffa_boot_info_content_format(
891 struct ffa_boot_info_desc *desc)
892{
893 return (desc->flags & FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK) >>
894 FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT;
895}
896
897static inline uint16_t ffa_boot_info_name_format(
898 struct ffa_boot_info_desc *desc)
899{
900 return (desc->flags & FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK) >>
901 FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT;
902}
903
904static inline uint8_t ffa_boot_info_type_id(struct ffa_boot_info_desc *desc)
905{
906 return desc->type & FFA_BOOT_INFO_TYPE_ID_MASK;
907}
908
909static inline uint8_t ffa_boot_info_type(struct ffa_boot_info_desc *desc)
910{
911 return (desc->type & FFA_BOOT_INFO_TYPE_MASK) >>
912 FFA_BOOT_INFO_TYPE_SHIFT;
913}
914
915/** Length in bytes of the signature in the boot descriptor. */
916#define FFA_BOOT_INFO_HEADER_SIGNATURE_LEN 4
917
J-Alves240d84c2022-04-22 12:19:34 +0100918/**
919 * The FF-A boot information header, as defined in table 5.9 of section 5.4.2,
920 * of the FF-A v1.1 EAC0 specification.
921 */
J-Alvesdd1ad572022-01-25 17:58:26 +0000922struct ffa_boot_info_header {
923 uint32_t signature;
924 uint32_t version;
925 uint32_t info_blob_size;
926 uint32_t desc_size;
927 uint32_t desc_count;
928 uint32_t desc_offset;
929 uint64_t reserved;
930 struct ffa_boot_info_desc boot_info[];
931};
932
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100933/**
J-Alves980d1992021-03-18 12:49:18 +0000934 * FF-A v1.1 specification restricts the number of notifications to a maximum
935 * of 64. Following all possible bitmaps.
936 */
937#define FFA_NOTIFICATION_MASK(ID) (UINT64_C(1) << ID)
938
939typedef uint64_t ffa_notifications_bitmap_t;
940
941#define MAX_FFA_NOTIFICATIONS 64U
942
943/**
J-Alvesc003a7a2021-03-18 13:06:53 +0000944 * Flag for notification bind and set, to specify call is about per-vCPU
945 * notifications.
946 */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200947#define FFA_NOTIFICATION_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesc003a7a2021-03-18 13:06:53 +0000948
Federico Recanatie73d2832022-04-20 11:10:52 +0200949#define FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(0)
950#define FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(32)
951
952/**
953 * Helper functions to check for buffer full notification.
954 */
955static inline bool is_ffa_hyp_buffer_full_notification(
956 ffa_notifications_bitmap_t framework)
957{
958 return (framework & FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK) != 0;
959}
960
961static inline bool is_ffa_spm_buffer_full_notification(
962 ffa_notifications_bitmap_t framework)
963{
964 return (framework & FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK) != 0;
965}
966
J-Alvesc003a7a2021-03-18 13:06:53 +0000967/**
J-Alves980d1992021-03-18 12:49:18 +0000968 * Helper function to assemble a 64-bit sized bitmap, from the 32-bit sized lo
969 * and hi.
970 * Helpful as FF-A specification defines that the notifications interfaces
971 * arguments are 32-bit registers.
972 */
973static inline ffa_notifications_bitmap_t ffa_notifications_bitmap(uint32_t lo,
974 uint32_t hi)
975{
976 return (ffa_notifications_bitmap_t)hi << 32U | lo;
977}
978
J-Alves98ff9562021-09-09 14:39:41 +0100979static inline ffa_notifications_bitmap_t ffa_notification_get_from_sp(
980 struct ffa_value val)
981{
982 return ffa_notifications_bitmap((uint32_t)val.arg2, (uint32_t)val.arg3);
983}
984
985static inline ffa_notifications_bitmap_t ffa_notification_get_from_vm(
986 struct ffa_value val)
987{
988 return ffa_notifications_bitmap((uint32_t)val.arg4, (uint32_t)val.arg5);
989}
990
Federico Recanatie73d2832022-04-20 11:10:52 +0200991static inline ffa_notifications_bitmap_t ffa_notification_get_from_framework(
992 struct ffa_value val)
993{
994 return ffa_notifications_bitmap((uint32_t)val.arg6, (uint32_t)val.arg7);
995}
996
J-Alves980d1992021-03-18 12:49:18 +0000997/**
J-Alvesaa79c012021-07-09 14:29:45 +0100998 * Flags used in calls to FFA_NOTIFICATION_GET interface.
999 */
Olivier Deprezb76307d2022-06-09 17:17:45 +02001000#define FFA_NOTIFICATION_FLAG_BITMAP_SP (UINT32_C(1) << 0)
1001#define FFA_NOTIFICATION_FLAG_BITMAP_VM (UINT32_C(1) << 1)
1002#define FFA_NOTIFICATION_FLAG_BITMAP_SPM (UINT32_C(1) << 2)
1003#define FFA_NOTIFICATION_FLAG_BITMAP_HYP (UINT32_C(1) << 3)
J-Alvesaa79c012021-07-09 14:29:45 +01001004
J-Alvesa3755072021-11-26 16:01:08 +00001005/* Flag to configure notification as being per vCPU. */
Olivier Deprezb76307d2022-06-09 17:17:45 +02001006#define FFA_NOTIFICATIONS_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesa3755072021-11-26 16:01:08 +00001007
J-Alves13394022021-06-30 13:48:49 +01001008/** Flag for FFA_NOTIFICATION_SET to delay Schedule Receiver Interrupt */
Olivier Deprezb76307d2022-06-09 17:17:45 +02001009#define FFA_NOTIFICATIONS_FLAG_DELAY_SRI (UINT32_C(1) << 1)
1010
1011#define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) \
1012 ((((uint32_t)(id)) & UINT32_C(0xffff)) << 16)
J-Alves13394022021-06-30 13:48:49 +01001013
J-Alvesbe6e3032021-11-30 14:54:12 +00001014static inline ffa_vcpu_index_t ffa_notifications_get_vcpu(struct ffa_value args)
J-Alvesaa79c012021-07-09 14:29:45 +01001015{
J-Alvesbe6e3032021-11-30 14:54:12 +00001016 return (ffa_vcpu_index_t)(args.arg1 >> 16 & 0xffffU);
J-Alvesaa79c012021-07-09 14:29:45 +01001017}
1018
1019/**
J-Alvesc8e8a222021-06-08 17:33:52 +01001020 * The max number of IDs for return of FFA_NOTIFICATION_INFO_GET.
1021 */
1022#define FFA_NOTIFICATIONS_INFO_GET_MAX_IDS 20U
1023
1024/**
1025 * Number of registers to use in successfull return of interface
1026 * FFA_NOTIFICATION_INFO_GET.
1027 */
1028#define FFA_NOTIFICATIONS_INFO_GET_REGS_RET 5U
1029
1030#define FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING 0x1U
1031
1032/**
1033 * Helper macros for return parameter encoding as described in section 17.7.1
1034 * of the FF-A v1.1 Beta0 specification.
1035 */
1036#define FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT 0x7U
1037#define FFA_NOTIFICATIONS_LISTS_COUNT_MASK 0x1fU
1038#define FFA_NOTIFICATIONS_LIST_SHIFT(l) (2 * (l - 1) + 12)
1039#define FFA_NOTIFICATIONS_LIST_SIZE_MASK 0x3U
1040
1041static inline uint32_t ffa_notification_info_get_lists_count(
1042 struct ffa_value args)
1043{
1044 return (uint32_t)(args.arg2 >> FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT) &
1045 FFA_NOTIFICATIONS_LISTS_COUNT_MASK;
1046}
1047
1048static inline uint32_t ffa_notification_info_get_list_size(
1049 struct ffa_value args, unsigned int list_idx)
1050{
1051 return ((uint32_t)args.arg2 >> FFA_NOTIFICATIONS_LIST_SHIFT(list_idx)) &
1052 FFA_NOTIFICATIONS_LIST_SIZE_MASK;
1053}
1054
1055static inline bool ffa_notification_info_get_more_pending(struct ffa_value args)
1056{
1057 return (args.arg2 & FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING) != 0U;
1058}
1059
1060/**
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001061 * A set of contiguous pages which is part of a memory region. This corresponds
J-Alves0b6653d2022-04-22 13:17:38 +01001062 * to table 10.14 of the FF-A v1.1 EAC0 specification, "Constituent memory
1063 * region descriptor".
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001064 */
1065struct ffa_memory_region_constituent {
1066 /**
1067 * The base IPA of the constituent memory region, aligned to 4 kiB page
1068 * size granularity.
1069 */
1070 uint64_t address;
1071 /** The number of 4 kiB pages in the constituent memory region. */
1072 uint32_t page_count;
1073 /** Reserved field, must be 0. */
1074 uint32_t reserved;
1075};
1076
1077/**
J-Alves0b6653d2022-04-22 13:17:38 +01001078 * A set of pages comprising a memory region. This corresponds to table 10.13 of
1079 * the FF-A v1.1 EAC0 specification, "Composite memory region descriptor".
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001080 */
1081struct ffa_composite_memory_region {
1082 /**
1083 * The total number of 4 kiB pages included in this memory region. This
1084 * must be equal to the sum of page counts specified in each
1085 * `ffa_memory_region_constituent`.
1086 */
1087 uint32_t page_count;
1088 /**
1089 * The number of constituents (`ffa_memory_region_constituent`)
1090 * included in this memory region range.
1091 */
1092 uint32_t constituent_count;
1093 /** Reserved field, must be 0. */
1094 uint64_t reserved_0;
1095 /** An array of `constituent_count` memory region constituents. */
1096 struct ffa_memory_region_constituent constituents[];
1097};
1098
1099/** Flags to indicate properties of receivers during memory region retrieval. */
1100typedef uint8_t ffa_memory_receiver_flags_t;
1101
1102/**
J-Alves0b6653d2022-04-22 13:17:38 +01001103 * This corresponds to table 10.15 of the FF-A v1.1 EAC0 specification, "Memory
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001104 * access permissions descriptor".
1105 */
1106struct ffa_memory_region_attributes {
1107 /** The ID of the VM to which the memory is being given or shared. */
J-Alves19e20cf2023-08-02 12:48:55 +01001108 ffa_id_t receiver;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001109 /**
1110 * The permissions with which the memory region should be mapped in the
1111 * receiver's page table.
1112 */
1113 ffa_memory_access_permissions_t permissions;
1114 /**
1115 * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP
1116 * for memory regions with multiple borrowers.
1117 */
1118 ffa_memory_receiver_flags_t flags;
1119};
1120
1121/** Flags to control the behaviour of a memory sharing transaction. */
1122typedef uint32_t ffa_memory_region_flags_t;
1123
1124/**
1125 * Clear memory region contents after unmapping it from the sender and before
1126 * mapping it for any receiver.
1127 */
1128#define FFA_MEMORY_REGION_FLAG_CLEAR 0x1
1129
1130/**
1131 * Whether the hypervisor may time slice the memory sharing or retrieval
1132 * operation.
1133 */
1134#define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2
1135
1136/**
1137 * Whether the hypervisor should clear the memory region after the receiver
1138 * relinquishes it or is aborted.
1139 */
1140#define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4
1141
J-Alves3456e032023-07-20 12:20:05 +01001142/**
1143 * On retrieve request, bypass the multi-borrower check.
1144 */
1145#define FFA_MEMORY_REGION_FLAG_BYPASS_BORROWERS_CHECK (0x1U << 10)
1146
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001147#define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3)
1148#define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3)
1149#define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3)
1150#define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3)
1151#define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3)
1152
Federico Recanati85090c42021-12-15 13:17:54 +01001153#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_VALID ((0x1U) << 9)
1154#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_MASK ((0xFU) << 5)
1155
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001156/**
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001157 * Struct to store the impdef value seen in Table 11.16 of the
1158 * FF-A v1.2 ALP0 specification "Endpoint memory access descriptor".
1159 */
1160struct ffa_memory_access_impdef {
1161 uint64_t val[2];
1162};
1163
Daniel Boulbye0ca9a02024-03-05 18:40:59 +00001164static inline struct ffa_memory_access_impdef ffa_memory_access_impdef_init(
1165 uint64_t impdef_hi, uint64_t impdef_lo)
1166{
1167 return (struct ffa_memory_access_impdef){{impdef_hi, impdef_lo}};
1168}
1169
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001170/**
J-Alves0b6653d2022-04-22 13:17:38 +01001171 * This corresponds to table 10.16 of the FF-A v1.1 EAC0 specification,
1172 * "Endpoint memory access descriptor".
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001173 */
1174struct ffa_memory_access {
1175 struct ffa_memory_region_attributes receiver_permissions;
1176 /**
1177 * Offset in bytes from the start of the outer `ffa_memory_region` to
1178 * an `ffa_composite_memory_region` struct.
1179 */
1180 uint32_t composite_memory_region_offset;
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001181 struct ffa_memory_access_impdef impdef;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001182 uint64_t reserved_0;
1183};
1184
J-Alves363f5722022-04-25 17:37:37 +01001185/** The maximum number of recipients a memory region may be sent to. */
J-Alvesba0e6172022-04-25 17:41:40 +01001186#define MAX_MEM_SHARE_RECIPIENTS UINT32_C(2)
J-Alves363f5722022-04-25 17:37:37 +01001187
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001188/**
1189 * Information about a set of pages which are being shared. This corresponds to
J-Alves0b6653d2022-04-22 13:17:38 +01001190 * table 10.20 of the FF-A v1.1 EAC0 specification, "Lend, donate or share
1191 * memory transaction descriptor". Note that it is also used for retrieve
1192 * requests and responses.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001193 */
1194struct ffa_memory_region {
1195 /**
1196 * The ID of the VM which originally sent the memory region, i.e. the
1197 * owner.
1198 */
J-Alves19e20cf2023-08-02 12:48:55 +01001199 ffa_id_t sender;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001200 ffa_memory_attributes_t attributes;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001201 /** Flags to control behaviour of the transaction. */
1202 ffa_memory_region_flags_t flags;
1203 ffa_memory_handle_t handle;
1204 /**
1205 * An implementation defined value associated with the receiver and the
1206 * memory region.
1207 */
1208 uint64_t tag;
J-Alves0b6653d2022-04-22 13:17:38 +01001209 /* Size of the memory access descriptor. */
1210 uint32_t memory_access_desc_size;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001211 /**
1212 * The number of `ffa_memory_access` entries included in this
1213 * transaction.
1214 */
1215 uint32_t receiver_count;
1216 /**
J-Alves0b6653d2022-04-22 13:17:38 +01001217 * Offset of the 'receivers' field, which relates to the memory access
1218 * descriptors.
1219 */
1220 uint32_t receivers_offset;
1221 /** Reserved field (12 bytes) must be 0. */
1222 uint32_t reserved[3];
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001223};
1224
1225/**
1226 * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table
J-Alves0b6653d2022-04-22 13:17:38 +01001227 * 16.25 of the FF-A v1.1 EAC0 specification, "Descriptor to relinquish a memory
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001228 * region".
1229 */
1230struct ffa_mem_relinquish {
1231 ffa_memory_handle_t handle;
1232 ffa_memory_region_flags_t flags;
1233 uint32_t endpoint_count;
J-Alves19e20cf2023-08-02 12:48:55 +01001234 ffa_id_t endpoints[];
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001235};
1236
1237/**
Daniel Boulby59ffee92023-11-02 18:26:26 +00001238 * Returns the first FF-A version that matches the memory access descriptor
1239 * size.
Daniel Boulbyde974ca2023-12-12 13:53:31 +00001240 */
1241uint32_t ffa_version_from_memory_access_desc_size(
1242 uint32_t memory_access_desc_size);
1243
1244/**
Daniel Boulbyc7dc9322023-10-27 15:12:07 +01001245 * Returns the first FF-A version that matches the memory access descriptor
1246 * size.
1247 */
1248uint32_t ffa_version_from_memory_access_desc_size(
1249 uint32_t memory_access_desc_size);
1250
1251/**
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001252 * To maintain forwards compatability we can't make assumptions about the size
1253 * of the endpoint memory access descriptor so provide a helper function
1254 * to get a receiver from the receiver array using the memory access descriptor
1255 * size field from the memory region descriptor struct.
1256 * Returns NULL if we cannot return the receiver.
1257 */
1258static inline struct ffa_memory_access *ffa_memory_region_get_receiver(
1259 struct ffa_memory_region *memory_region, uint32_t receiver_index)
1260{
1261 uint32_t memory_access_desc_size =
1262 memory_region->memory_access_desc_size;
1263
1264 if (receiver_index >= memory_region->receiver_count) {
1265 return NULL;
1266 }
1267
1268 /*
1269 * Memory access descriptor size cannot be greater than the size of
1270 * the memory access descriptor defined by the current FF-A version.
1271 */
1272 if (memory_access_desc_size > sizeof(struct ffa_memory_access)) {
1273 return NULL;
1274 }
1275
Daniel Boulby41ef8ba2023-10-13 17:01:22 +01001276 /* Check we cannot use receivers offset to cause overflow. */
1277 if (memory_region->receivers_offset !=
1278 sizeof(struct ffa_memory_region)) {
1279 return NULL;
1280 }
1281
1282 return (struct ffa_memory_access *)((uint8_t *)memory_region +
1283 memory_region->receivers_offset +
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001284 (receiver_index *
1285 memory_access_desc_size));
1286}
1287
1288/**
Daniel Boulby59ffee92023-11-02 18:26:26 +00001289 * Gets the receiver's access permissions from 'struct ffa_memory_region' and
1290 * returns its index in the receiver's array. If receiver's ID doesn't exist
1291 * in the array, return the region's 'receivers_count'.
1292 */
1293static inline uint32_t ffa_memory_region_get_receiver_index(
1294 struct ffa_memory_region *memory_region, ffa_id_t receiver_id)
1295{
1296 uint32_t i;
1297
1298 for (i = 0U; i < memory_region->receiver_count; i++) {
1299 struct ffa_memory_access *receiver =
1300 ffa_memory_region_get_receiver(memory_region, i);
1301 if (receiver->receiver_permissions.receiver == receiver_id) {
1302 break;
1303 }
1304 }
1305
1306 return i;
1307}
1308
1309/**
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001310 * Gets the `ffa_composite_memory_region` for the given receiver from an
1311 * `ffa_memory_region`, or NULL if it is not valid.
1312 */
1313static inline struct ffa_composite_memory_region *
1314ffa_memory_region_get_composite(struct ffa_memory_region *memory_region,
1315 uint32_t receiver_index)
1316{
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001317 struct ffa_memory_access *receiver =
1318 ffa_memory_region_get_receiver(memory_region, receiver_index);
1319 uint32_t offset;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001320
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001321 if (receiver == NULL) {
1322 return NULL;
1323 }
1324
1325 offset = receiver->composite_memory_region_offset;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001326 if (offset == 0) {
1327 return NULL;
1328 }
1329
1330 return (struct ffa_composite_memory_region *)((uint8_t *)memory_region +
1331 offset);
1332}
1333
1334static inline uint32_t ffa_mem_relinquish_init(
1335 struct ffa_mem_relinquish *relinquish_request,
1336 ffa_memory_handle_t handle, ffa_memory_region_flags_t flags,
J-Alves19e20cf2023-08-02 12:48:55 +01001337 ffa_id_t sender)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001338{
1339 relinquish_request->handle = handle;
1340 relinquish_request->flags = flags;
1341 relinquish_request->endpoint_count = 1;
1342 relinquish_request->endpoints[0] = sender;
J-Alves19e20cf2023-08-02 12:48:55 +01001343 return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_id_t);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001344}
1345
J-Alves126ab502022-09-29 11:37:33 +01001346void ffa_copy_memory_region_constituents(
1347 struct ffa_memory_region_constituent *dest,
1348 const struct ffa_memory_region_constituent *src);
1349
Karl Meakin0fd67292024-02-06 17:33:05 +00001350struct ffa_features_rxtx_map_params {
1351 /*
1352 * Bit[0:1]:
1353 * Minimum buffer size and alignment boundary:
1354 * 0b00: 4K
1355 * 0b01: 64K
1356 * 0b10: 16K
1357 * 0b11: Reserved
1358 */
1359 uint8_t min_buf_size : 2;
1360 /*
1361 * Bit[2:15]:
1362 * Reserved (MBZ)
1363 */
1364 uint16_t mbz : 14;
1365 /*
1366 * Bit[16:32]:
1367 * Maximum buffer size in number of pages
1368 * Only present on version 1.2 or later
1369 */
1370 uint16_t max_buf_size : 16;
1371};
1372
1373#define FFA_RXTX_MAP_MIN_BUF_4K 0
1374#define FFA_RXTX_MAP_MAX_BUF_PAGE_COUNT 1
1375
Karl Meakinf7861302024-02-20 14:39:33 +00001376static inline struct ffa_features_rxtx_map_params ffa_features_rxtx_map_params(
1377 struct ffa_value args)
1378{
1379 struct ffa_features_rxtx_map_params params;
1380 uint32_t arg2 = args.arg2;
1381
1382 params = *(struct ffa_features_rxtx_map_params *)(&arg2);
1383
1384 return params;
1385}
1386
Federico Recanati392be392022-02-08 20:53:03 +01001387/**
1388 * Endpoint RX/TX descriptor, as defined by Table 13.27 in FF-A v1.1 EAC0.
1389 * It's used by the Hypervisor to describe the RX/TX buffers mapped by a VM
1390 * to the SPMC, in order to allow indirect messaging.
1391 */
1392struct ffa_endpoint_rx_tx_descriptor {
J-Alves19e20cf2023-08-02 12:48:55 +01001393 ffa_id_t endpoint_id;
Federico Recanati392be392022-02-08 20:53:03 +01001394 uint16_t reserved;
1395
1396 /*
1397 * 8-byte aligned offset from the base address of this descriptor to the
1398 * `ffa_composite_memory_region` describing the RX buffer.
1399 */
1400 uint32_t rx_offset;
1401
1402 /*
1403 * 8-byte aligned offset from the base address of this descriptor to the
1404 * `ffa_composite_memory_region` describing the TX buffer.
1405 */
1406 uint32_t tx_offset;
1407
1408 /* Pad to align on 16-byte boundary. */
1409 uint32_t pad;
1410};
1411
1412static inline struct ffa_composite_memory_region *
Karl Meakinb9705e22024-04-05 13:58:28 +01001413ffa_endpoint_get_rx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
Federico Recanati392be392022-02-08 20:53:03 +01001414{
1415 return (struct ffa_composite_memory_region *)((uintptr_t)desc +
1416 desc->rx_offset);
1417}
1418
1419static inline struct ffa_composite_memory_region *
Karl Meakinb9705e22024-04-05 13:58:28 +01001420ffa_endpoint_get_tx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
Federico Recanati392be392022-02-08 20:53:03 +01001421{
1422 return (struct ffa_composite_memory_region *)((uintptr_t)desc +
1423 desc->tx_offset);
1424}
1425
J-Alves2d8457f2022-10-05 11:06:41 +01001426void ffa_memory_region_init_header(struct ffa_memory_region *memory_region,
J-Alves19e20cf2023-08-02 12:48:55 +01001427 ffa_id_t sender,
J-Alves2d8457f2022-10-05 11:06:41 +01001428 ffa_memory_attributes_t attributes,
1429 ffa_memory_region_flags_t flags,
1430 ffa_memory_handle_t handle, uint32_t tag,
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001431 uint32_t receiver_count,
1432 uint32_t receiver_desc_size);
Daniel Boulby59ffee92023-11-02 18:26:26 +00001433void ffa_memory_access_init(struct ffa_memory_access *receiver,
1434 ffa_id_t receiver_id,
1435 enum ffa_data_access data_access,
1436 enum ffa_instruction_access instruction_access,
1437 ffa_memory_receiver_flags_t flags,
1438 struct ffa_memory_access_impdef *impdef_val);
J-Alves45085432022-04-22 16:19:20 +01001439uint32_t ffa_memory_region_init_single_receiver(
Andrew Walbranca808b12020-05-15 17:22:28 +01001440 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
J-Alves19e20cf2023-08-02 12:48:55 +01001441 ffa_id_t sender, ffa_id_t receiver,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001442 const struct ffa_memory_region_constituent constituents[],
1443 uint32_t constituent_count, uint32_t tag,
1444 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
1445 enum ffa_instruction_access instruction_access,
1446 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
Daniel Boulby59ffee92023-11-02 18:26:26 +00001447 enum ffa_memory_shareability shareability,
1448 struct ffa_memory_access_impdef *impdef_val, uint32_t *fragment_length,
Andrew Walbranca808b12020-05-15 17:22:28 +01001449 uint32_t *total_length);
J-Alvesf4eecf72022-07-20 16:05:34 +01001450uint32_t ffa_memory_region_init(
1451 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
J-Alves19e20cf2023-08-02 12:48:55 +01001452 ffa_id_t sender, struct ffa_memory_access receivers[],
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001453 uint32_t receiver_count, uint32_t receiver_desc_size,
J-Alvesf4eecf72022-07-20 16:05:34 +01001454 const struct ffa_memory_region_constituent constituents[],
1455 uint32_t constituent_count, uint32_t tag,
1456 ffa_memory_region_flags_t flags, enum ffa_memory_type type,
1457 enum ffa_memory_cacheability cacheability,
1458 enum ffa_memory_shareability shareability, uint32_t *fragment_length,
1459 uint32_t *total_length);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001460uint32_t ffa_memory_retrieve_request_init(
1461 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves19e20cf2023-08-02 12:48:55 +01001462 ffa_id_t sender, struct ffa_memory_access receivers[],
Daniel Boulbyd5ae44b2023-12-12 12:18:11 +00001463 uint32_t receiver_count, uint32_t receiver_desc_size, uint32_t tag,
1464 ffa_memory_region_flags_t flags, enum ffa_memory_type type,
1465 enum ffa_memory_cacheability cacheability,
J-Alves9b24ed82022-08-04 13:12:45 +01001466 enum ffa_memory_shareability shareability);
1467uint32_t ffa_memory_retrieve_request_init_single_receiver(
1468 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves19e20cf2023-08-02 12:48:55 +01001469 ffa_id_t sender, ffa_id_t receiver, uint32_t tag,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001470 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
1471 enum ffa_instruction_access instruction_access,
1472 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
Daniel Boulby59ffee92023-11-02 18:26:26 +00001473 enum ffa_memory_shareability shareability,
1474 struct ffa_memory_access_impdef *impdef_val);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001475uint32_t ffa_memory_lender_retrieve_request_init(
1476 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves19e20cf2023-08-02 12:48:55 +01001477 ffa_id_t sender);
Andrew Walbranca808b12020-05-15 17:22:28 +01001478uint32_t ffa_memory_fragment_init(
1479 struct ffa_memory_region_constituent *fragment,
1480 size_t fragment_max_size,
1481 const struct ffa_memory_region_constituent constituents[],
1482 uint32_t constituent_count, uint32_t *fragment_length);
Federico Recanati392be392022-02-08 20:53:03 +01001483void ffa_endpoint_rx_tx_descriptor_init(
J-Alves19e20cf2023-08-02 12:48:55 +01001484 struct ffa_endpoint_rx_tx_descriptor *desc, ffa_id_t endpoint_id,
Federico Recanati392be392022-02-08 20:53:03 +01001485 uint64_t rx_address, uint64_t tx_address);