blob: 0bf05ae36e47cf4e35429993ada6df917208d8db [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
J-Alves3829fc02021-03-18 12:49:18 +000016#define FFA_VERSION_MINOR 0x1
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
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010026/* clang-format off */
27
28#define FFA_LOW_32_ID 0x84000060
29#define FFA_HIGH_32_ID 0x8400007F
30#define FFA_LOW_64_ID 0xC4000060
Fuad Tabbada72d142020-07-30 09:17:05 +010031#define FFA_HIGH_64_ID 0xC400007F
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010032
33/* FF-A function identifiers. */
J-Alves3829fc02021-03-18 12:49:18 +000034#define FFA_ERROR_32 0x84000060
35#define FFA_SUCCESS_32 0x84000061
36#define FFA_SUCCESS_64 0xC4000061
37#define FFA_INTERRUPT_32 0x84000062
38#define FFA_VERSION_32 0x84000063
39#define FFA_FEATURES_32 0x84000064
40#define FFA_RX_RELEASE_32 0x84000065
41#define FFA_RXTX_MAP_32 0x84000066
42#define FFA_RXTX_MAP_64 0xC4000066
43#define FFA_RXTX_UNMAP_32 0x84000067
44#define FFA_PARTITION_INFO_GET_32 0x84000068
45#define FFA_ID_GET_32 0x84000069
46#define FFA_MSG_POLL_32 0x8400006A /* Legacy FF-A v1.0 */
47#define FFA_MSG_WAIT_32 0x8400006B
48#define FFA_YIELD_32 0x8400006C
49#define FFA_RUN_32 0x8400006D
50#define FFA_MSG_SEND_32 0x8400006E /* Legacy FF-A v1.0 */
51#define FFA_MSG_SEND_DIRECT_REQ_32 0x8400006F
52#define FFA_MSG_SEND_DIRECT_REQ_64 0xC400006F
53#define FFA_MSG_SEND_DIRECT_RESP_32 0x84000070
54#define FFA_MSG_SEND_DIRECT_RESP_64 0xC4000070
55#define FFA_MEM_DONATE_32 0x84000071
56#define FFA_MEM_LEND_32 0x84000072
57#define FFA_MEM_SHARE_32 0x84000073
58#define FFA_MEM_RETRIEVE_REQ_32 0x84000074
59#define FFA_MEM_RETRIEVE_RESP_32 0x84000075
60#define FFA_MEM_RELINQUISH_32 0x84000076
61#define FFA_MEM_RECLAIM_32 0x84000077
62#define FFA_MEM_FRAG_RX_32 0x8400007A
63#define FFA_MEM_FRAG_TX_32 0x8400007B
64#define FFA_NORMAL_WORLD_RESUME 0x8400007C
65
66/* FF-A v1.1 */
67#define FFA_NOTIFICATION_BITMAP_CREATE_32 0x8400007D
68#define FFA_NOTIFICATION_BITMAP_DESTROY_32 0x8400007E
69#define FFA_NOTIFICATION_BIND_32 0x8400007F
70#define FFA_NOTIFICATION_UNBIND_32 0x84000080
71#define FFA_NOTIFICATION_SET_32 0x84000081
72#define FFA_NOTIFICATION_GET_32 0x84000082
73#define FFA_NOTIFICATION_INFO_GET_64 0xC4000083
74#define FFA_RX_ACQUIRE_32 0x84000084
75#define FFA_SPM_ID_GET_32 0x84000085
76#define FFA_MSG_SEND2_32 0x84000086
77#define FFA_SECONDARY_EP_REGISTER_64 0xC4000087
78#define FFA_MEM_PERM_GET_32 0x84000088
79#define FFA_MEM_PERM_SET_32 0x84000089
Raghu Krishnamurthyea6d25f2021-09-14 15:27:06 -070080#define FFA_MEM_PERM_GET_64 0xC4000088
81#define FFA_MEM_PERM_SET_64 0xC4000089
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010082
Maksims Svecovs71b76702022-05-20 15:32:58 +010083/* Implementation-defined ABIs. */
84#define FFA_CONSOLE_LOG_32 0x8400008A
85#define FFA_CONSOLE_LOG_64 0xC400008A
Raghu Krishnamurthy7592bcb2022-12-25 13:09:00 -080086#define FFA_PARTITION_INFO_GET_REGS_64 0xC400008B
Maksims Svecovs71b76702022-05-20 15:32:58 +010087
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010088/* FF-A error codes. */
89#define FFA_NOT_SUPPORTED INT32_C(-1)
90#define FFA_INVALID_PARAMETERS INT32_C(-2)
91#define FFA_NO_MEMORY INT32_C(-3)
92#define FFA_BUSY INT32_C(-4)
93#define FFA_INTERRUPTED INT32_C(-5)
94#define FFA_DENIED INT32_C(-6)
95#define FFA_RETRY INT32_C(-7)
96#define FFA_ABORTED INT32_C(-8)
J-Alvesc8e8a222021-06-08 17:33:52 +010097#define FFA_NO_DATA INT32_C(-9)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010098
99/* clang-format on */
100
J-Alves6f72ca82021-11-01 12:34:58 +0000101/**
102 * FF-A Feature ID, to be used with interface FFA_FEATURES.
103 * As defined in the FF-A v1.1 Beta specification, table 13.10, in section
104 * 13.2.
105 */
106
Olivier Deprezb76307d2022-06-09 17:17:45 +0200107#define FFA_FEATURES_FUNC_ID_MASK (UINT32_C(1) << 31)
J-Alves6f72ca82021-11-01 12:34:58 +0000108#define FFA_FEATURES_FEATURE_ID_MASK UINT32_C(0x7F)
109
110/* Query interrupt ID of Notification Pending Interrupt. */
111#define FFA_FEATURE_NPI 0x1U
112
113/* Query interrupt ID of Schedule Receiver Interrupt. */
114#define FFA_FEATURE_SRI 0x2U
115
116/* Query interrupt ID of the Managed Exit Interrupt. */
117#define FFA_FEATURE_MEI 0x3U
118
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100119/* FF-A function specific constants. */
120#define FFA_MSG_RECV_BLOCK 0x1
121#define FFA_MSG_RECV_BLOCK_MASK 0x1
122
123#define FFA_MSG_SEND_NOTIFY 0x1
124#define FFA_MSG_SEND_NOTIFY_MASK 0x1
125
126#define FFA_MEM_RECLAIM_CLEAR 0x1
127
128#define FFA_SLEEP_INDEFINITE 0
129
Raghu Krishnamurthyea6d25f2021-09-14 15:27:06 -0700130#define FFA_MEM_PERM_RO UINT32_C(0x7)
131#define FFA_MEM_PERM_RW UINT32_C(0x5)
132#define FFA_MEM_PERM_RX UINT32_C(0x3)
133
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000134/*
Olivier Deprez013f4d62022-11-21 15:46:20 +0100135 * Defined in Table 13.34 in the FF-A v1.1 EAC0 specification.
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000136 * The Partition count flag is used by FFA_PARTITION_INFO_GET to specify
137 * if partition info descriptors should be returned or just the count.
138 */
Olivier Deprez013f4d62022-11-21 15:46:20 +0100139#define FFA_PARTITION_COUNT_FLAG UINT32_C(0x1)
140#define FFA_PARTITION_COUNT_FLAG_MASK (UINT32_C(0x1) << 0)
Daniel Boulbyb46cad12021-12-13 17:47:21 +0000141
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100142/**
143 * For use where the FF-A specification refers explicitly to '4K pages'. Not to
144 * be confused with PAGE_SIZE, which is the translation granule Hafnium is
145 * configured to use.
146 */
147#define FFA_PAGE_SIZE 4096
148
Federico Recanatifc0295e2022-02-08 19:37:39 +0100149/** The ID of a VM. These are assigned sequentially starting with an offset. */
150typedef uint16_t ffa_vm_id_t;
151
152/**
153 * Partition message header as specified by table 6.2 from FF-A v1.1 EAC0
154 * specification.
155 */
156struct ffa_partition_rxtx_header {
157 uint32_t flags; /* MBZ */
158 uint32_t reserved;
159 /* Offset from the beginning of the buffer to the message payload. */
160 uint32_t offset;
161 /* Sender(Bits[31:16]) and Receiver(Bits[15:0]) endpoint IDs. */
162 uint32_t sender_receiver;
163 /* Size of message in buffer. */
164 uint32_t size;
165};
166
167#define FFA_RXTX_HEADER_SIZE sizeof(struct ffa_partition_rxtx_header)
168#define FFA_RXTX_SENDER_SHIFT (0x10U)
J-Alves70079932022-12-07 17:32:20 +0000169#define FFA_RXTX_ALLOCATOR_SHIFT 16
Federico Recanatifc0295e2022-02-08 19:37:39 +0100170
171static inline void ffa_rxtx_header_init(
172 ffa_vm_id_t sender, ffa_vm_id_t receiver, uint32_t size,
173 struct ffa_partition_rxtx_header *header)
174{
175 header->flags = 0;
176 header->reserved = 0;
177 header->offset = FFA_RXTX_HEADER_SIZE;
178 header->sender_receiver =
179 (uint32_t)(receiver | (sender << FFA_RXTX_SENDER_SHIFT));
180 header->size = size;
181}
182
183static inline ffa_vm_id_t ffa_rxtx_header_sender(
184 const struct ffa_partition_rxtx_header *h)
185{
186 return (ffa_vm_id_t)(h->sender_receiver >> FFA_RXTX_SENDER_SHIFT);
187}
188
189static inline ffa_vm_id_t ffa_rxtx_header_receiver(
190 const struct ffa_partition_rxtx_header *h)
191{
192 return (ffa_vm_id_t)(h->sender_receiver);
193}
194
195/* The maximum length possible for a single message. */
196#define FFA_PARTITION_MSG_PAYLOAD_MAX (HF_MAILBOX_SIZE - FFA_RXTX_HEADER_SIZE)
197
198struct ffa_partition_msg {
199 struct ffa_partition_rxtx_header header;
200 char payload[FFA_PARTITION_MSG_PAYLOAD_MAX];
201};
202
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100203/* The maximum length possible for a single message. */
204#define FFA_MSG_PAYLOAD_MAX HF_MAILBOX_SIZE
205
206enum ffa_data_access {
207 FFA_DATA_ACCESS_NOT_SPECIFIED,
208 FFA_DATA_ACCESS_RO,
209 FFA_DATA_ACCESS_RW,
210 FFA_DATA_ACCESS_RESERVED,
211};
212
213enum ffa_instruction_access {
214 FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED,
215 FFA_INSTRUCTION_ACCESS_NX,
216 FFA_INSTRUCTION_ACCESS_X,
217 FFA_INSTRUCTION_ACCESS_RESERVED,
218};
219
220enum ffa_memory_type {
221 FFA_MEMORY_NOT_SPECIFIED_MEM,
222 FFA_MEMORY_DEVICE_MEM,
223 FFA_MEMORY_NORMAL_MEM,
224};
225
226enum ffa_memory_cacheability {
227 FFA_MEMORY_CACHE_RESERVED = 0x0,
228 FFA_MEMORY_CACHE_NON_CACHEABLE = 0x1,
229 FFA_MEMORY_CACHE_RESERVED_1 = 0x2,
230 FFA_MEMORY_CACHE_WRITE_BACK = 0x3,
231 FFA_MEMORY_DEV_NGNRNE = 0x0,
232 FFA_MEMORY_DEV_NGNRE = 0x1,
233 FFA_MEMORY_DEV_NGRE = 0x2,
234 FFA_MEMORY_DEV_GRE = 0x3,
235};
236
237enum ffa_memory_shareability {
238 FFA_MEMORY_SHARE_NON_SHAREABLE,
239 FFA_MEMORY_SHARE_RESERVED,
240 FFA_MEMORY_OUTER_SHAREABLE,
241 FFA_MEMORY_INNER_SHAREABLE,
242};
243
244typedef uint8_t ffa_memory_access_permissions_t;
245
246/**
247 * This corresponds to table 44 of the FF-A 1.0 EAC specification, "Memory
248 * region attributes descriptor".
249 */
250typedef uint8_t ffa_memory_attributes_t;
251
252#define FFA_DATA_ACCESS_OFFSET (0x0U)
253#define FFA_DATA_ACCESS_MASK ((0x3U) << FFA_DATA_ACCESS_OFFSET)
254
255#define FFA_INSTRUCTION_ACCESS_OFFSET (0x2U)
256#define FFA_INSTRUCTION_ACCESS_MASK ((0x3U) << FFA_INSTRUCTION_ACCESS_OFFSET)
257
258#define FFA_MEMORY_TYPE_OFFSET (0x4U)
259#define FFA_MEMORY_TYPE_MASK ((0x3U) << FFA_MEMORY_TYPE_OFFSET)
260
261#define FFA_MEMORY_CACHEABILITY_OFFSET (0x2U)
262#define FFA_MEMORY_CACHEABILITY_MASK ((0x3U) << FFA_MEMORY_CACHEABILITY_OFFSET)
263
264#define FFA_MEMORY_SHAREABILITY_OFFSET (0x0U)
265#define FFA_MEMORY_SHAREABILITY_MASK ((0x3U) << FFA_MEMORY_SHAREABILITY_OFFSET)
266
267#define ATTR_FUNCTION_SET(name, container_type, offset, mask) \
268 static inline void ffa_set_##name##_attr(container_type *attr, \
269 const enum ffa_##name perm) \
270 { \
271 *attr = (*attr & ~(mask)) | ((perm << offset) & mask); \
272 }
273
274#define ATTR_FUNCTION_GET(name, container_type, offset, mask) \
275 static inline enum ffa_##name ffa_get_##name##_attr( \
276 container_type attr) \
277 { \
278 return (enum ffa_##name)((attr & mask) >> offset); \
279 }
280
281ATTR_FUNCTION_SET(data_access, ffa_memory_access_permissions_t,
282 FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK)
283ATTR_FUNCTION_GET(data_access, ffa_memory_access_permissions_t,
284 FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK)
285
286ATTR_FUNCTION_SET(instruction_access, ffa_memory_access_permissions_t,
287 FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK)
288ATTR_FUNCTION_GET(instruction_access, ffa_memory_access_permissions_t,
289 FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK)
290
291ATTR_FUNCTION_SET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET,
292 FFA_MEMORY_TYPE_MASK)
293ATTR_FUNCTION_GET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET,
294 FFA_MEMORY_TYPE_MASK)
295
296ATTR_FUNCTION_SET(memory_cacheability, ffa_memory_attributes_t,
297 FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK)
298ATTR_FUNCTION_GET(memory_cacheability, ffa_memory_attributes_t,
299 FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK)
300
301ATTR_FUNCTION_SET(memory_shareability, ffa_memory_attributes_t,
302 FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK)
303ATTR_FUNCTION_GET(memory_shareability, ffa_memory_attributes_t,
304 FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK)
305
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100306/**
307 * A globally-unique ID assigned by the hypervisor for a region of memory being
308 * sent between VMs.
309 */
310typedef uint64_t ffa_memory_handle_t;
311
J-Alves917d2f22020-10-30 18:39:30 +0000312#define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \
313 ((ffa_memory_handle_t)(UINT64_C(1) << 63))
314#define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR \
315 ((ffa_memory_handle_t)(UINT64_C(1) << 63))
316
317#define FFA_MEMORY_HANDLE_ALLOCATOR_SPMC (UINT64_C(0) << 63)
318#define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0))
319
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100320/**
321 * A count of VMs. This has the same range as the VM IDs but we give it a
322 * different name to make the different semantics clear.
323 */
324typedef ffa_vm_id_t ffa_vm_count_t;
325
326/** The index of a vCPU within a particular VM. */
327typedef uint16_t ffa_vcpu_index_t;
328
329/**
330 * A count of vCPUs. This has the same range as the vCPU indices but we give it
331 * a different name to make the different semantics clear.
332 */
333typedef ffa_vcpu_index_t ffa_vcpu_count_t;
334
335/** Parameter and return type of FF-A functions. */
336struct ffa_value {
337 uint64_t func;
338 uint64_t arg1;
339 uint64_t arg2;
340 uint64_t arg3;
341 uint64_t arg4;
342 uint64_t arg5;
343 uint64_t arg6;
344 uint64_t arg7;
Raghu Krishnamurthy567068e2022-12-26 07:46:38 -0800345
346 struct {
347 uint64_t arg8;
348 uint64_t arg9;
349 uint64_t arg10;
350 uint64_t arg11;
351 uint64_t arg12;
352 uint64_t arg13;
353 uint64_t arg14;
354 uint64_t arg15;
355 uint64_t arg16;
356 uint64_t arg17;
357 bool valid;
358 } extended_val;
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100359};
360
Olivier Depreze562e542020-06-11 17:31:54 +0200361static inline uint32_t ffa_func_id(struct ffa_value args)
362{
363 return args.func;
364}
365
J-Alves13318e32021-02-22 17:21:00 +0000366static inline int32_t ffa_error_code(struct ffa_value val)
367{
368 return (int32_t)val.arg2;
369}
370
J-Alvesd6f4e142021-03-05 13:33:59 +0000371static inline ffa_vm_id_t ffa_sender(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100372{
373 return (args.arg1 >> 16) & 0xffff;
374}
375
J-Alvesd6f4e142021-03-05 13:33:59 +0000376static inline ffa_vm_id_t ffa_receiver(struct ffa_value args)
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100377{
378 return args.arg1 & 0xffff;
379}
380
381static inline uint32_t ffa_msg_send_size(struct ffa_value args)
382{
383 return args.arg3;
384}
385
Federico Recanati25053ee2022-03-14 15:01:53 +0100386static inline uint32_t ffa_msg_send2_flags(struct ffa_value args)
387{
388 return args.arg2;
389}
390
Olivier Depreze562e542020-06-11 17:31:54 +0200391static inline uint32_t ffa_partition_info_get_count(struct ffa_value args)
392{
393 return args.arg2;
394}
395
Raghu Krishnamurthy2957b922022-12-27 10:29:12 -0800396static inline uint16_t ffa_partition_info_regs_get_last_idx(
397 struct ffa_value args)
398{
399 return args.arg2 & 0xFFFF;
400}
401
402static inline uint16_t ffa_partition_info_regs_get_curr_idx(
403 struct ffa_value args)
404{
405 return (args.arg2 >> 16) & 0xFFFF;
406}
407
408static inline uint16_t ffa_partition_info_regs_get_tag(struct ffa_value args)
409{
410 return (args.arg2 >> 32) & 0xFFFF;
411}
412
413static inline uint16_t ffa_partition_info_regs_get_desc_size(
414 struct ffa_value args)
415{
416 return (args.arg2 >> 48);
417}
418
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100419static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t a1, uint32_t a2)
420{
421 return (uint64_t)a1 | (uint64_t)a2 << 32;
422}
423
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100424static inline ffa_memory_handle_t ffa_mem_success_handle(struct ffa_value args)
425{
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100426 return ffa_assemble_handle(args.arg2, args.arg3);
427}
428
Andrew Walbranca808b12020-05-15 17:22:28 +0100429static inline ffa_memory_handle_t ffa_frag_handle(struct ffa_value args)
430{
431 return ffa_assemble_handle(args.arg1, args.arg2);
432}
433
Andrew Walbran1bbe9402020-04-30 16:47:13 +0100434static inline struct ffa_value ffa_mem_success(ffa_memory_handle_t handle)
435{
436 return (struct ffa_value){.func = FFA_SUCCESS_32,
437 .arg2 = (uint32_t)handle,
438 .arg3 = (uint32_t)(handle >> 32)};
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100439}
440
441static inline ffa_vm_id_t ffa_vm_id(struct ffa_value args)
442{
443 return (args.arg1 >> 16) & 0xffff;
444}
445
446static inline ffa_vcpu_index_t ffa_vcpu_index(struct ffa_value args)
447{
448 return args.arg1 & 0xffff;
449}
450
451static inline uint64_t ffa_vm_vcpu(ffa_vm_id_t vm_id,
452 ffa_vcpu_index_t vcpu_index)
453{
454 return ((uint32_t)vm_id << 16) | vcpu_index;
455}
456
Andrew Walbranca808b12020-05-15 17:22:28 +0100457static inline ffa_vm_id_t ffa_frag_sender(struct ffa_value args)
458{
459 return (args.arg4 >> 16) & 0xffff;
460}
461
J-Alves6f72ca82021-11-01 12:34:58 +0000462static inline uint32_t ffa_feature_intid(struct ffa_value args)
463{
464 return (uint32_t)args.arg2;
465}
466
Daniel Boulbyefa381f2022-01-18 14:49:40 +0000467static inline uint32_t ffa_fwk_msg(struct ffa_value args)
468{
469 return (uint32_t)args.arg2;
470}
471
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100472/**
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100473 * Holds the UUID in a struct that is mappable directly to the SMCC calling
474 * convention, which is used for FF-A calls.
475 *
476 * Refer to table 84 of the FF-A 1.0 EAC specification as well as section 5.3
477 * of the SMCC Spec 1.2.
478 */
479struct ffa_uuid {
480 uint32_t uuid[4];
481};
482
483static inline void ffa_uuid_init(uint32_t w0, uint32_t w1, uint32_t w2,
484 uint32_t w3, struct ffa_uuid *uuid)
485{
486 uuid->uuid[0] = w0;
487 uuid->uuid[1] = w1;
488 uuid->uuid[2] = w2;
489 uuid->uuid[3] = w3;
490}
491
492static inline bool ffa_uuid_equal(const struct ffa_uuid *uuid1,
493 const struct ffa_uuid *uuid2)
494{
495 return (uuid1->uuid[0] == uuid2->uuid[0]) &&
496 (uuid1->uuid[1] == uuid2->uuid[1]) &&
497 (uuid1->uuid[2] == uuid2->uuid[2]) &&
498 (uuid1->uuid[3] == uuid2->uuid[3]);
499}
500
501static inline bool ffa_uuid_is_null(const struct ffa_uuid *uuid)
502{
503 return (uuid->uuid[0] == 0) && (uuid->uuid[1] == 0) &&
504 (uuid->uuid[2] == 0) && (uuid->uuid[3] == 0);
505}
506
507/**
508 * Flags to determine the partition properties, as required by
509 * FFA_PARTITION_INFO_GET.
510 *
Kathleen Capella402fa852022-11-09 16:16:51 -0500511 * The values of the flags are specified in table 8.25 of DEN0077A FF-A 1.0 REL
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100512 * specification, "Partition information descriptor, partition properties".
513 */
514typedef uint32_t ffa_partition_properties_t;
515
516/** Partition property: partition supports receipt of direct requests. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500517#define FFA_PARTITION_DIRECT_REQ_RECV (UINT32_C(1) << 0)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100518
519/** Partition property: partition can send direct requests. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500520#define FFA_PARTITION_DIRECT_REQ_SEND (UINT32_C(1) << 1)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100521
522/** Partition property: partition can send and receive indirect messages. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500523#define FFA_PARTITION_INDIRECT_MSG (UINT32_C(1) << 2)
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100524
J-Alves09ff9d82021-11-02 11:55:20 +0000525/** Partition property: partition can receive notifications. */
Kathleen Capella402fa852022-11-09 16:16:51 -0500526#define FFA_PARTITION_NOTIFICATION (UINT32_C(1) << 3)
527
528/** Partition property: partition runs in the AArch64 execution state. */
529#define FFA_PARTITION_AARCH64_EXEC (UINT32_C(1) << 8)
J-Alves09ff9d82021-11-02 11:55:20 +0000530
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100531/**
532 * Holds information returned for each partition by the FFA_PARTITION_INFO_GET
533 * interface.
Kathleen Capella402fa852022-11-09 16:16:51 -0500534 * This corresponds to table 13.37 "Partition information descriptor"
535 * in FF-A 1.1 EAC0 specification.
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000536 */
537struct ffa_partition_info {
538 ffa_vm_id_t vm_id;
539 ffa_vcpu_count_t vcpu_count;
540 ffa_partition_properties_t properties;
541 struct ffa_uuid uuid;
542};
543
544/**
Kathleen Capella402fa852022-11-09 16:16:51 -0500545 * Bits[31:3] of partition properties must be zero for FF-A v1.0.
546 * This corresponds to table 8.25 "Partition information descriptor"
547 * in DEN0077A FF-A 1.0 REL specification.
548 */
549#define FFA_PARTITION_v1_0_RES_MASK (~(UINT32_C(0x7)))
550
551/**
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000552 * Create a struct for the "Partition information descriptor" defined for v1.0
553 * which can be returned to v1.0 endpoints.
Kathleen Capella402fa852022-11-09 16:16:51 -0500554 * This corresponds to table 8.25 "Partition information descriptor"
555 * in DEN0077A FF-A 1.0 REL specification.
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100556 */
Daniel Boulby1ddb3d72021-12-16 18:16:50 +0000557
558struct ffa_partition_info_v1_0 {
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100559 ffa_vm_id_t vm_id;
560 ffa_vcpu_count_t vcpu_count;
561 ffa_partition_properties_t properties;
562};
563
J-Alvesdd1ad572022-01-25 17:58:26 +0000564/** Length in bytes of the name in boot information descriptor. */
565#define FFA_BOOT_INFO_NAME_LEN 16
566
J-Alves240d84c2022-04-22 12:19:34 +0100567/**
568 * The FF-A boot info descriptor, as defined in table 5.8 of section 5.4.1, of
569 * the FF-A v1.1 EAC0 specification.
570 */
J-Alvesdd1ad572022-01-25 17:58:26 +0000571struct ffa_boot_info_desc {
572 char name[FFA_BOOT_INFO_NAME_LEN];
573 uint8_t type;
574 uint8_t reserved;
575 uint16_t flags;
576 uint32_t size;
577 uint64_t content;
578};
579
580/** FF-A boot information type mask. */
581#define FFA_BOOT_INFO_TYPE_SHIFT 7
582#define FFA_BOOT_INFO_TYPE_MASK (0x1U << FFA_BOOT_INFO_TYPE_SHIFT)
583#define FFA_BOOT_INFO_TYPE_STD 0U
584#define FFA_BOOT_INFO_TYPE_IMPDEF 1U
585
586/** Standard boot info type IDs. */
587#define FFA_BOOT_INFO_TYPE_ID_MASK 0x7FU
588#define FFA_BOOT_INFO_TYPE_ID_FDT 0U
589#define FFA_BOOT_INFO_TYPE_ID_HOB 1U
590
591/** FF-A Boot Info descriptors flags. */
592#define FFA_BOOT_INFO_FLAG_MBZ_MASK 0xFFF0U
593
594/** Bits [1:0] encode the format of the name field in ffa_boot_info_desc. */
595#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT 0U
596#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK \
597 (0x3U << FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT)
598#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING 0x0U
599#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID 0x1U
600
601/** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */
602#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT 2
603#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK \
604 (0x3U << FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT)
605#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE 0x1U
606#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR 0x0U
607
608static inline uint16_t ffa_boot_info_content_format(
609 struct ffa_boot_info_desc *desc)
610{
611 return (desc->flags & FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK) >>
612 FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT;
613}
614
615static inline uint16_t ffa_boot_info_name_format(
616 struct ffa_boot_info_desc *desc)
617{
618 return (desc->flags & FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK) >>
619 FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT;
620}
621
622static inline uint8_t ffa_boot_info_type_id(struct ffa_boot_info_desc *desc)
623{
624 return desc->type & FFA_BOOT_INFO_TYPE_ID_MASK;
625}
626
627static inline uint8_t ffa_boot_info_type(struct ffa_boot_info_desc *desc)
628{
629 return (desc->type & FFA_BOOT_INFO_TYPE_MASK) >>
630 FFA_BOOT_INFO_TYPE_SHIFT;
631}
632
633/** Length in bytes of the signature in the boot descriptor. */
634#define FFA_BOOT_INFO_HEADER_SIGNATURE_LEN 4
635
J-Alves240d84c2022-04-22 12:19:34 +0100636/**
637 * The FF-A boot information header, as defined in table 5.9 of section 5.4.2,
638 * of the FF-A v1.1 EAC0 specification.
639 */
J-Alvesdd1ad572022-01-25 17:58:26 +0000640struct ffa_boot_info_header {
641 uint32_t signature;
642 uint32_t version;
643 uint32_t info_blob_size;
644 uint32_t desc_size;
645 uint32_t desc_count;
646 uint32_t desc_offset;
647 uint64_t reserved;
648 struct ffa_boot_info_desc boot_info[];
649};
650
Fuad Tabbae4efcc32020-07-16 15:37:27 +0100651/**
J-Alves980d1992021-03-18 12:49:18 +0000652 * FF-A v1.1 specification restricts the number of notifications to a maximum
653 * of 64. Following all possible bitmaps.
654 */
655#define FFA_NOTIFICATION_MASK(ID) (UINT64_C(1) << ID)
656
657typedef uint64_t ffa_notifications_bitmap_t;
658
659#define MAX_FFA_NOTIFICATIONS 64U
660
661/**
J-Alvesc003a7a2021-03-18 13:06:53 +0000662 * Flag for notification bind and set, to specify call is about per-vCPU
663 * notifications.
664 */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200665#define FFA_NOTIFICATION_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesc003a7a2021-03-18 13:06:53 +0000666
Federico Recanatie73d2832022-04-20 11:10:52 +0200667#define FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(0)
668#define FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK FFA_NOTIFICATION_MASK(32)
669
670/**
671 * Helper functions to check for buffer full notification.
672 */
673static inline bool is_ffa_hyp_buffer_full_notification(
674 ffa_notifications_bitmap_t framework)
675{
676 return (framework & FFA_NOTIFICATION_HYP_BUFFER_FULL_MASK) != 0;
677}
678
679static inline bool is_ffa_spm_buffer_full_notification(
680 ffa_notifications_bitmap_t framework)
681{
682 return (framework & FFA_NOTIFICATION_SPM_BUFFER_FULL_MASK) != 0;
683}
684
J-Alvesc003a7a2021-03-18 13:06:53 +0000685/**
J-Alves980d1992021-03-18 12:49:18 +0000686 * Helper function to assemble a 64-bit sized bitmap, from the 32-bit sized lo
687 * and hi.
688 * Helpful as FF-A specification defines that the notifications interfaces
689 * arguments are 32-bit registers.
690 */
691static inline ffa_notifications_bitmap_t ffa_notifications_bitmap(uint32_t lo,
692 uint32_t hi)
693{
694 return (ffa_notifications_bitmap_t)hi << 32U | lo;
695}
696
J-Alves98ff9562021-09-09 14:39:41 +0100697static inline ffa_notifications_bitmap_t ffa_notification_get_from_sp(
698 struct ffa_value val)
699{
700 return ffa_notifications_bitmap((uint32_t)val.arg2, (uint32_t)val.arg3);
701}
702
703static inline ffa_notifications_bitmap_t ffa_notification_get_from_vm(
704 struct ffa_value val)
705{
706 return ffa_notifications_bitmap((uint32_t)val.arg4, (uint32_t)val.arg5);
707}
708
Federico Recanatie73d2832022-04-20 11:10:52 +0200709static inline ffa_notifications_bitmap_t ffa_notification_get_from_framework(
710 struct ffa_value val)
711{
712 return ffa_notifications_bitmap((uint32_t)val.arg6, (uint32_t)val.arg7);
713}
714
J-Alves980d1992021-03-18 12:49:18 +0000715/**
J-Alvesaa79c012021-07-09 14:29:45 +0100716 * Flags used in calls to FFA_NOTIFICATION_GET interface.
717 */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200718#define FFA_NOTIFICATION_FLAG_BITMAP_SP (UINT32_C(1) << 0)
719#define FFA_NOTIFICATION_FLAG_BITMAP_VM (UINT32_C(1) << 1)
720#define FFA_NOTIFICATION_FLAG_BITMAP_SPM (UINT32_C(1) << 2)
721#define FFA_NOTIFICATION_FLAG_BITMAP_HYP (UINT32_C(1) << 3)
J-Alvesaa79c012021-07-09 14:29:45 +0100722
J-Alvesa3755072021-11-26 16:01:08 +0000723/* Flag to configure notification as being per vCPU. */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200724#define FFA_NOTIFICATIONS_FLAG_PER_VCPU (UINT32_C(1) << 0)
J-Alvesa3755072021-11-26 16:01:08 +0000725
J-Alves13394022021-06-30 13:48:49 +0100726/** Flag for FFA_NOTIFICATION_SET to delay Schedule Receiver Interrupt */
Olivier Deprezb76307d2022-06-09 17:17:45 +0200727#define FFA_NOTIFICATIONS_FLAG_DELAY_SRI (UINT32_C(1) << 1)
728
729#define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) \
730 ((((uint32_t)(id)) & UINT32_C(0xffff)) << 16)
J-Alves13394022021-06-30 13:48:49 +0100731
J-Alvesbe6e3032021-11-30 14:54:12 +0000732static inline ffa_vcpu_index_t ffa_notifications_get_vcpu(struct ffa_value args)
J-Alvesaa79c012021-07-09 14:29:45 +0100733{
J-Alvesbe6e3032021-11-30 14:54:12 +0000734 return (ffa_vcpu_index_t)(args.arg1 >> 16 & 0xffffU);
J-Alvesaa79c012021-07-09 14:29:45 +0100735}
736
737/**
J-Alvesc8e8a222021-06-08 17:33:52 +0100738 * The max number of IDs for return of FFA_NOTIFICATION_INFO_GET.
739 */
740#define FFA_NOTIFICATIONS_INFO_GET_MAX_IDS 20U
741
742/**
743 * Number of registers to use in successfull return of interface
744 * FFA_NOTIFICATION_INFO_GET.
745 */
746#define FFA_NOTIFICATIONS_INFO_GET_REGS_RET 5U
747
748#define FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING 0x1U
749
750/**
751 * Helper macros for return parameter encoding as described in section 17.7.1
752 * of the FF-A v1.1 Beta0 specification.
753 */
754#define FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT 0x7U
755#define FFA_NOTIFICATIONS_LISTS_COUNT_MASK 0x1fU
756#define FFA_NOTIFICATIONS_LIST_SHIFT(l) (2 * (l - 1) + 12)
757#define FFA_NOTIFICATIONS_LIST_SIZE_MASK 0x3U
758
759static inline uint32_t ffa_notification_info_get_lists_count(
760 struct ffa_value args)
761{
762 return (uint32_t)(args.arg2 >> FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT) &
763 FFA_NOTIFICATIONS_LISTS_COUNT_MASK;
764}
765
766static inline uint32_t ffa_notification_info_get_list_size(
767 struct ffa_value args, unsigned int list_idx)
768{
769 return ((uint32_t)args.arg2 >> FFA_NOTIFICATIONS_LIST_SHIFT(list_idx)) &
770 FFA_NOTIFICATIONS_LIST_SIZE_MASK;
771}
772
773static inline bool ffa_notification_info_get_more_pending(struct ffa_value args)
774{
775 return (args.arg2 & FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING) != 0U;
776}
777
778/**
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100779 * A set of contiguous pages which is part of a memory region. This corresponds
780 * to table 40 of the FF-A 1.0 EAC specification, "Constituent memory region
781 * descriptor".
782 */
783struct ffa_memory_region_constituent {
784 /**
785 * The base IPA of the constituent memory region, aligned to 4 kiB page
786 * size granularity.
787 */
788 uint64_t address;
789 /** The number of 4 kiB pages in the constituent memory region. */
790 uint32_t page_count;
791 /** Reserved field, must be 0. */
792 uint32_t reserved;
793};
794
795/**
796 * A set of pages comprising a memory region. This corresponds to table 39 of
797 * the FF-A 1.0 EAC specification, "Composite memory region descriptor".
798 */
799struct ffa_composite_memory_region {
800 /**
801 * The total number of 4 kiB pages included in this memory region. This
802 * must be equal to the sum of page counts specified in each
803 * `ffa_memory_region_constituent`.
804 */
805 uint32_t page_count;
806 /**
807 * The number of constituents (`ffa_memory_region_constituent`)
808 * included in this memory region range.
809 */
810 uint32_t constituent_count;
811 /** Reserved field, must be 0. */
812 uint64_t reserved_0;
813 /** An array of `constituent_count` memory region constituents. */
814 struct ffa_memory_region_constituent constituents[];
815};
816
817/** Flags to indicate properties of receivers during memory region retrieval. */
818typedef uint8_t ffa_memory_receiver_flags_t;
819
820/**
821 * This corresponds to table 41 of the FF-A 1.0 EAC specification, "Memory
822 * access permissions descriptor".
823 */
824struct ffa_memory_region_attributes {
825 /** The ID of the VM to which the memory is being given or shared. */
826 ffa_vm_id_t receiver;
827 /**
828 * The permissions with which the memory region should be mapped in the
829 * receiver's page table.
830 */
831 ffa_memory_access_permissions_t permissions;
832 /**
833 * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP
834 * for memory regions with multiple borrowers.
835 */
836 ffa_memory_receiver_flags_t flags;
837};
838
839/** Flags to control the behaviour of a memory sharing transaction. */
840typedef uint32_t ffa_memory_region_flags_t;
841
842/**
843 * Clear memory region contents after unmapping it from the sender and before
844 * mapping it for any receiver.
845 */
846#define FFA_MEMORY_REGION_FLAG_CLEAR 0x1
847
848/**
849 * Whether the hypervisor may time slice the memory sharing or retrieval
850 * operation.
851 */
852#define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2
853
854/**
855 * Whether the hypervisor should clear the memory region after the receiver
856 * relinquishes it or is aborted.
857 */
858#define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4
859
860#define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3)
861#define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3)
862#define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3)
863#define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3)
864#define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3)
865
Federico Recanati85090c42021-12-15 13:17:54 +0100866#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_VALID ((0x1U) << 9)
867#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_MASK ((0xFU) << 5)
868
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100869/**
870 * This corresponds to table 42 of the FF-A 1.0 EAC specification, "Endpoint
871 * memory access descriptor".
872 */
873struct ffa_memory_access {
874 struct ffa_memory_region_attributes receiver_permissions;
875 /**
876 * Offset in bytes from the start of the outer `ffa_memory_region` to
877 * an `ffa_composite_memory_region` struct.
878 */
879 uint32_t composite_memory_region_offset;
880 uint64_t reserved_0;
881};
882
J-Alves363f5722022-04-25 17:37:37 +0100883/** The maximum number of recipients a memory region may be sent to. */
J-Alvesba0e6172022-04-25 17:41:40 +0100884#define MAX_MEM_SHARE_RECIPIENTS UINT32_C(2)
J-Alves363f5722022-04-25 17:37:37 +0100885
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100886/**
887 * Information about a set of pages which are being shared. This corresponds to
888 * table 45 of the FF-A 1.0 EAC specification, "Lend, donate or share memory
889 * transaction descriptor". Note that it is also used for retrieve requests and
890 * responses.
891 */
892struct ffa_memory_region {
893 /**
894 * The ID of the VM which originally sent the memory region, i.e. the
895 * owner.
896 */
897 ffa_vm_id_t sender;
898 ffa_memory_attributes_t attributes;
899 /** Reserved field, must be 0. */
900 uint8_t reserved_0;
901 /** Flags to control behaviour of the transaction. */
902 ffa_memory_region_flags_t flags;
903 ffa_memory_handle_t handle;
904 /**
905 * An implementation defined value associated with the receiver and the
906 * memory region.
907 */
908 uint64_t tag;
909 /** Reserved field, must be 0. */
910 uint32_t reserved_1;
911 /**
912 * The number of `ffa_memory_access` entries included in this
913 * transaction.
914 */
915 uint32_t receiver_count;
916 /**
Federico Recanati3ddf28e2021-12-20 09:40:26 +0100917 * An array of `receiver_count` endpoint memory access descriptors.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100918 * Each one specifies a memory region offset, an endpoint and the
919 * attributes with which this memory region should be mapped in that
920 * endpoint's page table.
921 */
922 struct ffa_memory_access receivers[];
923};
924
925/**
926 * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table
927 * 150 of the FF-A 1.0 EAC specification, "Descriptor to relinquish a memory
928 * region".
929 */
930struct ffa_mem_relinquish {
931 ffa_memory_handle_t handle;
932 ffa_memory_region_flags_t flags;
933 uint32_t endpoint_count;
934 ffa_vm_id_t endpoints[];
935};
936
937/**
938 * Gets the `ffa_composite_memory_region` for the given receiver from an
939 * `ffa_memory_region`, or NULL if it is not valid.
940 */
941static inline struct ffa_composite_memory_region *
942ffa_memory_region_get_composite(struct ffa_memory_region *memory_region,
943 uint32_t receiver_index)
944{
945 uint32_t offset = memory_region->receivers[receiver_index]
946 .composite_memory_region_offset;
947
948 if (offset == 0) {
949 return NULL;
950 }
951
952 return (struct ffa_composite_memory_region *)((uint8_t *)memory_region +
953 offset);
954}
955
956static inline uint32_t ffa_mem_relinquish_init(
957 struct ffa_mem_relinquish *relinquish_request,
958 ffa_memory_handle_t handle, ffa_memory_region_flags_t flags,
959 ffa_vm_id_t sender)
960{
961 relinquish_request->handle = handle;
962 relinquish_request->flags = flags;
963 relinquish_request->endpoint_count = 1;
964 relinquish_request->endpoints[0] = sender;
965 return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_vm_id_t);
966}
967
Federico Recanati392be392022-02-08 20:53:03 +0100968/**
969 * Endpoint RX/TX descriptor, as defined by Table 13.27 in FF-A v1.1 EAC0.
970 * It's used by the Hypervisor to describe the RX/TX buffers mapped by a VM
971 * to the SPMC, in order to allow indirect messaging.
972 */
973struct ffa_endpoint_rx_tx_descriptor {
974 ffa_vm_id_t endpoint_id;
975 uint16_t reserved;
976
977 /*
978 * 8-byte aligned offset from the base address of this descriptor to the
979 * `ffa_composite_memory_region` describing the RX buffer.
980 */
981 uint32_t rx_offset;
982
983 /*
984 * 8-byte aligned offset from the base address of this descriptor to the
985 * `ffa_composite_memory_region` describing the TX buffer.
986 */
987 uint32_t tx_offset;
988
989 /* Pad to align on 16-byte boundary. */
990 uint32_t pad;
991};
992
993static inline struct ffa_composite_memory_region *
994ffa_enpoint_get_rx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
995{
996 return (struct ffa_composite_memory_region *)((uintptr_t)desc +
997 desc->rx_offset);
998}
999
1000static inline struct ffa_composite_memory_region *
1001ffa_enpoint_get_tx_memory_region(struct ffa_endpoint_rx_tx_descriptor *desc)
1002{
1003 return (struct ffa_composite_memory_region *)((uintptr_t)desc +
1004 desc->tx_offset);
1005}
1006
J-Alvesb44bb7d2022-04-25 15:43:46 +01001007void ffa_memory_access_init_permissions(
1008 struct ffa_memory_access *receiver, ffa_vm_id_t receiver_id,
1009 enum ffa_data_access data_access,
1010 enum ffa_instruction_access instruction_access,
1011 ffa_memory_receiver_flags_t flags);
J-Alves45085432022-04-22 16:19:20 +01001012uint32_t ffa_memory_region_init_single_receiver(
Andrew Walbranca808b12020-05-15 17:22:28 +01001013 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
1014 ffa_vm_id_t sender, ffa_vm_id_t receiver,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001015 const struct ffa_memory_region_constituent constituents[],
1016 uint32_t constituent_count, uint32_t tag,
1017 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
1018 enum ffa_instruction_access instruction_access,
1019 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
Andrew Walbranca808b12020-05-15 17:22:28 +01001020 enum ffa_memory_shareability shareability, uint32_t *fragment_length,
1021 uint32_t *total_length);
J-Alvesf4eecf72022-07-20 16:05:34 +01001022uint32_t ffa_memory_region_init(
1023 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
1024 ffa_vm_id_t sender, struct ffa_memory_access receivers[],
1025 uint32_t receiver_count,
1026 const struct ffa_memory_region_constituent constituents[],
1027 uint32_t constituent_count, uint32_t tag,
1028 ffa_memory_region_flags_t flags, enum ffa_memory_type type,
1029 enum ffa_memory_cacheability cacheability,
1030 enum ffa_memory_shareability shareability, uint32_t *fragment_length,
1031 uint32_t *total_length);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001032uint32_t ffa_memory_retrieve_request_init(
1033 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
J-Alves9b24ed82022-08-04 13:12:45 +01001034 ffa_vm_id_t sender, struct ffa_memory_access receivers[],
1035 uint32_t receiver_count, uint32_t tag, ffa_memory_region_flags_t flags,
1036 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
1037 enum ffa_memory_shareability shareability);
1038uint32_t ffa_memory_retrieve_request_init_single_receiver(
1039 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001040 ffa_vm_id_t sender, ffa_vm_id_t receiver, uint32_t tag,
1041 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
1042 enum ffa_instruction_access instruction_access,
1043 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
1044 enum ffa_memory_shareability shareability);
1045uint32_t ffa_memory_lender_retrieve_request_init(
1046 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
1047 ffa_vm_id_t sender);
Andrew Walbranca808b12020-05-15 17:22:28 +01001048bool ffa_retrieved_memory_region_init(
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001049 struct ffa_memory_region *response, size_t response_max_size,
1050 ffa_vm_id_t sender, ffa_memory_attributes_t attributes,
1051 ffa_memory_region_flags_t flags, ffa_memory_handle_t handle,
1052 ffa_vm_id_t receiver, ffa_memory_access_permissions_t permissions,
Andrew Walbranca808b12020-05-15 17:22:28 +01001053 uint32_t page_count, uint32_t total_constituent_count,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +01001054 const struct ffa_memory_region_constituent constituents[],
Andrew Walbranca808b12020-05-15 17:22:28 +01001055 uint32_t fragment_constituent_count, uint32_t *total_length,
1056 uint32_t *fragment_length);
1057uint32_t ffa_memory_fragment_init(
1058 struct ffa_memory_region_constituent *fragment,
1059 size_t fragment_max_size,
1060 const struct ffa_memory_region_constituent constituents[],
1061 uint32_t constituent_count, uint32_t *fragment_length);
Federico Recanati392be392022-02-08 20:53:03 +01001062void ffa_endpoint_rx_tx_descriptor_init(
1063 struct ffa_endpoint_rx_tx_descriptor *desc, ffa_vm_id_t endpoint_id,
1064 uint64_t rx_address, uint64_t tx_address);