blob: 8232128c2b6eef0410882f1e5738295eecea9239 [file] [log] [blame]
J-Alves7581c382020-05-07 18:34:20 +01001/*
Daniel Boulby8aa994c2022-01-05 19:44:30 +00002 * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
J-Alves7581c382020-05-07 18:34:20 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef FFA_HELPERS_H
8#define FFA_HELPERS_H
9
J-Alves8f08a052020-05-26 17:14:40 +010010#include <ffa_svc.h>
J-Alves7581c382020-05-07 18:34:20 +010011#include <tftf_lib.h>
12#include <utils_def.h>
13
14/* This error code must be different to the ones used by FFA */
15#define FFA_TFTF_ERROR -42
16
Daniel Boulbye79d2072021-03-03 11:34:53 +000017typedef unsigned short ffa_id_t;
J-Alves5aecd982020-06-11 10:25:33 +010018typedef unsigned short ffa_vm_count_t;
19typedef unsigned short ffa_vcpu_count_t;
J-Alvesf3a393c2020-10-23 16:00:39 +010020typedef uint64_t ffa_memory_handle_t;
21/** Flags to indicate properties of receivers during memory region retrieval. */
22typedef uint8_t ffa_memory_receiver_flags_t;
J-Alves5aecd982020-06-11 10:25:33 +010023
J-Alvesd708c032020-11-19 12:14:21 +000024struct ffa_uuid {
25 const uint32_t uuid[4];
26};
27
J-Alvesda3e6d42022-01-25 10:19:56 +000028/** Length in bytes of the name in boot information descriptor. */
29#define FFA_BOOT_INFO_NAME_LEN 16
30
31/**
32 * The FF-A boot info descriptor, as defined in table 5.8 of section 5.4.1, of
33 * the FF-A v1.1 EAC0 specification.
34 */
35struct ffa_boot_info_desc {
36 char name[FFA_BOOT_INFO_NAME_LEN];
37 uint8_t type;
38 uint8_t reserved;
39 uint16_t flags;
40 uint32_t size;
41 uint64_t content;
42};
43
44/** FF-A boot information type mask. */
45#define FFA_BOOT_INFO_TYPE_SHIFT 7
46#define FFA_BOOT_INFO_TYPE_MASK (0x1U << FFA_BOOT_INFO_TYPE_SHIFT)
47#define FFA_BOOT_INFO_TYPE_STD 0U
48#define FFA_BOOT_INFO_TYPE_IMPDEF 1U
49
50/** Standard boot info type IDs. */
51#define FFA_BOOT_INFO_TYPE_ID_MASK 0x7FU
52#define FFA_BOOT_INFO_TYPE_ID_FDT 0U
53#define FFA_BOOT_INFO_TYPE_ID_HOB 1U
54
55/** FF-A Boot Info descriptors flags. */
56#define FFA_BOOT_INFO_FLAG_MBZ_MASK 0xFFF0U
57
58/** Bits [1:0] encode the format of the name field in ffa_boot_info_desc. */
59#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT 0U
60#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK \
61 (0x3U << FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT)
62#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING 0x0U
63#define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID 0x1U
64
65/** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */
66#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT 2
67#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK \
68 (0x3U << FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT)
69#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE 0x1U
70#define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR 0x0U
71
72static inline uint16_t ffa_boot_info_content_format(
73 struct ffa_boot_info_desc *desc)
74{
75 return (desc->flags & FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK) >>
76 FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT;
77}
78
79static inline uint16_t ffa_boot_info_name_format(
80 struct ffa_boot_info_desc *desc)
81{
82 return (desc->flags & FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK) >>
83 FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT;
84}
85
86static inline uint8_t ffa_boot_info_type_id(struct ffa_boot_info_desc *desc)
87{
88 return desc->type & FFA_BOOT_INFO_TYPE_ID_MASK;
89}
90
91static inline uint8_t ffa_boot_info_type(struct ffa_boot_info_desc *desc)
92{
93 return (desc->type & FFA_BOOT_INFO_TYPE_MASK) >>
94 FFA_BOOT_INFO_TYPE_SHIFT;
95}
96
97/** Length in bytes of the signature in the boot descriptor. */
98#define FFA_BOOT_INFO_HEADER_SIGNATURE_LEN 4
99
100/**
101 * The FF-A boot information header, as defined in table 5.9 of section 5.4.2,
102 * of the FF-A v1.1 EAC0 specification.
103 */
104struct ffa_boot_info_header {
105 uint32_t signature;
106 uint32_t version;
107 uint32_t info_blob_size;
108 uint32_t desc_size;
109 uint32_t desc_count;
110 uint32_t desc_offset;
111 uint64_t reserved;
112 struct ffa_boot_info_desc boot_info[];
113};
114
J-Alves7581c382020-05-07 18:34:20 +0100115#ifndef __ASSEMBLY__
116
J-Alves18c28052021-03-09 09:58:53 +0000117#include <cassert.h>
J-Alves7581c382020-05-07 18:34:20 +0100118#include <stdint.h>
119
J-Alves4439ece2021-11-05 11:52:54 +0000120/**
121 * FF-A Feature ID, to be used with interface FFA_FEATURES.
122 * As defined in the FF-A v1.1 Beta specification, table 13.10, in section
123 * 13.2.
124 */
125
126/** Query interrupt ID of Notification Pending Interrupt. */
127#define FFA_FEATURE_NPI 0x1U
128
129/** Query interrupt ID of Schedule Receiver Interrupt. */
130#define FFA_FEATURE_SRI 0x2U
131
132/** Query interrupt ID of the Managed Exit Interrupt. */
133#define FFA_FEATURE_MEI 0x3U
134
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000135/** Partition property: partition supports receipt of direct requests. */
136#define FFA_PARTITION_DIRECT_REQ_RECV 0x1
137
138/** Partition property: partition can send direct requests. */
139#define FFA_PARTITION_DIRECT_REQ_SEND 0x2
140
141/** Partition property: partition can send and receive indirect messages. */
142#define FFA_PARTITION_INDIRECT_MSG 0x4
143
J-Alves4d05dec2021-11-02 11:52:27 +0000144/** Partition property: partition can receive notifications. */
145#define FFA_PARTITION_NOTIFICATION 0x8
146
Daniel Boulby8aa994c2022-01-05 19:44:30 +0000147/**
148 * Partition info descriptor as defined in Table 13.34 of the v1.1 BETA0
149 * FF-A Specification
150 */
Max Shvetsovc32f4782020-06-23 09:41:15 +0100151struct ffa_partition_info {
152 /** The ID of the VM the information is about */
Daniel Boulbye79d2072021-03-03 11:34:53 +0000153 ffa_id_t id;
Max Shvetsovc32f4782020-06-23 09:41:15 +0100154 /** The number of execution contexts implemented by the partition */
155 uint16_t exec_context;
156 /** The Partition's properties, e.g. supported messaging methods */
157 uint32_t properties;
Daniel Boulby8aa994c2022-01-05 19:44:30 +0000158 /** The uuid of the partition */
159 struct ffa_uuid uuid;
Max Shvetsovc32f4782020-06-23 09:41:15 +0100160};
161
Daniel Boulby2ac55f22022-01-21 12:08:08 +0000162/**
163 * Partition info descriptor as defined in Table 8.25 of the v1.0
164 * FF-A Specification
165 */
166struct ffa_partition_info_v1_0 {
167 /** The ID of the VM the information is about */
168 ffa_id_t id;
169 /** The number of execution contexts implemented by the partition */
170 uint16_t exec_context;
171 /** The Partition's properties, e.g. supported messaging methods */
172 uint32_t properties;
173};
174
J-Alvesf156ae92021-10-08 12:10:05 +0100175static inline uint32_t ffa_func_id(smc_ret_values val)
176{
J-Alves6cb21d92021-01-07 15:18:12 +0000177 return (uint32_t) val.ret0;
178}
179
J-Alvesf156ae92021-10-08 12:10:05 +0100180static inline int32_t ffa_error_code(smc_ret_values val)
181{
J-Alves6cb21d92021-01-07 15:18:12 +0000182 return (int32_t) val.ret2;
183}
184
Daniel Boulby198deda2021-03-03 11:35:25 +0000185static inline ffa_id_t ffa_endpoint_id(smc_ret_values val) {
186 return (ffa_id_t) val.ret2 & 0xffff;
187}
188
Daniel Boulby2ac55f22022-01-21 12:08:08 +0000189static inline uint32_t ffa_partition_info_count(smc_ret_values val)
190{
191 return (uint32_t) val.ret2;
192}
193
J-Alves4439ece2021-11-05 11:52:54 +0000194static inline uint32_t ffa_feature_intid(smc_ret_values val)
195{
196 return (uint32_t)val.ret2;
197}
198
J-Alves18c28052021-03-09 09:58:53 +0000199typedef uint64_t ffa_notification_bitmap_t;
200
201#define FFA_NOTIFICATION(ID) (UINT64_C(1) << ID)
202
203#define MAX_FFA_NOTIFICATIONS UINT32_C(64)
204
205#define FFA_NOTIFICATIONS_FLAG_PER_VCPU UINT32_C(0x1 << 0)
206
J-Alvesb0cb5d02021-07-08 11:19:33 +0100207/** Flag to delay Schedule Receiver Interrupt. */
208#define FFA_NOTIFICATIONS_FLAG_DELAY_SRI UINT32_C(0x1 << 1)
209
J-Alves18c28052021-03-09 09:58:53 +0000210#define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) UINT32_C((id & 0xFFFF) << 16)
211
J-Alvesf156ae92021-10-08 12:10:05 +0100212#define FFA_NOTIFICATIONS_FLAG_BITMAP_SP UINT32_C(0x1 << 0)
213#define FFA_NOTIFICATIONS_FLAG_BITMAP_VM UINT32_C(0x1 << 1)
214#define FFA_NOTIFICATIONS_FLAG_BITMAP_SPM UINT32_C(0x1 << 2)
215#define FFA_NOTIFICATIONS_FLAG_BITMAP_HYP UINT32_C(0x1 << 3)
216
J-Alves269118a2021-09-22 09:46:11 +0100217/**
218 * The following is an SGI ID, that the SPMC configures as non-secure, as
219 * suggested by the FF-A v1.1 specification, in section 9.4.1.
220 */
221#define FFA_SCHEDULE_RECEIVER_INTERRUPT_ID 8
222
J-Alvesf156ae92021-10-08 12:10:05 +0100223#define FFA_NOTIFICATIONS_BITMAP(lo, hi) \
224 (ffa_notification_bitmap_t)(lo) | \
225 (((ffa_notification_bitmap_t)hi << 32) & 0xFFFFFFFF00000000ULL)
226
227#define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) UINT32_C((id & 0xFFFF) << 16)
228
229static inline ffa_notification_bitmap_t ffa_notifications_get_from_sp(smc_ret_values val)
230{
231 return FFA_NOTIFICATIONS_BITMAP(val.ret2, val.ret3);
232}
233
234static inline ffa_notification_bitmap_t ffa_notifications_get_from_vm(smc_ret_values val)
235{
236 return FFA_NOTIFICATIONS_BITMAP(val.ret4, val.ret5);
237}
238
J-Alves5bce2502021-06-14 14:27:45 +0100239/*
240 * FFA_NOTIFICATION_INFO_GET is a SMC64 interface.
241 * The following macros are defined for SMC64 implementation.
242 */
243#define FFA_NOTIFICATIONS_INFO_GET_MAX_IDS 20U
244
245#define FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING UINT64_C(0x1)
246
247#define FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT 0x7U
248#define FFA_NOTIFICATIONS_LISTS_COUNT_MASK 0x1FU
249#define FFA_NOTIFICATIONS_LIST_SHIFT(l) (2 * (l - 1) + 12)
250#define FFA_NOTIFICATIONS_LIST_SIZE_MASK 0x3U
251
252static inline uint32_t ffa_notifications_info_get_lists_count(
253 smc_ret_values ret)
254{
255 return (uint32_t)(ret.ret2 >> FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT)
256 & FFA_NOTIFICATIONS_LISTS_COUNT_MASK;
257}
258
259static inline uint32_t ffa_notifications_info_get_list_size(
260 smc_ret_values ret, uint32_t list)
261{
262 return (uint32_t)(ret.ret2 >> FFA_NOTIFICATIONS_LIST_SHIFT(list)) &
263 FFA_NOTIFICATIONS_LIST_SIZE_MASK;
264}
265
266static inline bool ffa_notifications_info_get_more_pending(smc_ret_values ret)
267{
268 return (ret.ret2 & FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING) != 0U;
269}
270
J-Alvesf3a393c2020-10-23 16:00:39 +0100271enum ffa_data_access {
272 FFA_DATA_ACCESS_NOT_SPECIFIED,
273 FFA_DATA_ACCESS_RO,
274 FFA_DATA_ACCESS_RW,
275 FFA_DATA_ACCESS_RESERVED,
276};
277
278enum ffa_instruction_access {
279 FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED,
280 FFA_INSTRUCTION_ACCESS_NX,
281 FFA_INSTRUCTION_ACCESS_X,
282 FFA_INSTRUCTION_ACCESS_RESERVED,
283};
284
285enum ffa_memory_type {
286 FFA_MEMORY_NOT_SPECIFIED_MEM,
287 FFA_MEMORY_DEVICE_MEM,
288 FFA_MEMORY_NORMAL_MEM,
289};
290
291enum ffa_memory_cacheability {
292 FFA_MEMORY_CACHE_RESERVED = 0x0,
293 FFA_MEMORY_CACHE_NON_CACHEABLE = 0x1,
294 FFA_MEMORY_CACHE_RESERVED_1 = 0x2,
295 FFA_MEMORY_CACHE_WRITE_BACK = 0x3,
296 FFA_MEMORY_DEV_NGNRNE = 0x0,
297 FFA_MEMORY_DEV_NGNRE = 0x1,
298 FFA_MEMORY_DEV_NGRE = 0x2,
299 FFA_MEMORY_DEV_GRE = 0x3,
300};
301
302enum ffa_memory_shareability {
303 FFA_MEMORY_SHARE_NON_SHAREABLE,
304 FFA_MEMORY_SHARE_RESERVED,
305 FFA_MEMORY_OUTER_SHAREABLE,
306 FFA_MEMORY_INNER_SHAREABLE,
307};
308
309typedef uint8_t ffa_memory_access_permissions_t;
310
311/**
312 * This corresponds to table "Memory region attributes descriptor" of the FF-A
313 * 1.0 specification.
314 */
315typedef uint8_t ffa_memory_attributes_t;
316
317#define FFA_DATA_ACCESS_OFFSET (0x0U)
318#define FFA_DATA_ACCESS_MASK ((0x3U) << FFA_DATA_ACCESS_OFFSET)
319
320#define FFA_INSTRUCTION_ACCESS_OFFSET (0x2U)
321#define FFA_INSTRUCTION_ACCESS_MASK ((0x3U) << FFA_INSTRUCTION_ACCESS_OFFSET)
322
323#define FFA_MEMORY_TYPE_OFFSET (0x4U)
324#define FFA_MEMORY_TYPE_MASK ((0x3U) << FFA_MEMORY_TYPE_OFFSET)
325
326#define FFA_MEMORY_CACHEABILITY_OFFSET (0x2U)
327#define FFA_MEMORY_CACHEABILITY_MASK ((0x3U) << FFA_MEMORY_CACHEABILITY_OFFSET)
328
329#define FFA_MEMORY_SHAREABILITY_OFFSET (0x0U)
330#define FFA_MEMORY_SHAREABILITY_MASK ((0x3U) << FFA_MEMORY_SHAREABILITY_OFFSET)
331
332#define ATTR_FUNCTION_SET(name, container_type, offset, mask) \
333 static inline void ffa_set_##name##_attr(container_type *attr, \
334 const enum ffa_##name perm) \
335 { \
336 *attr = (*attr & ~(mask)) | ((perm << offset) & mask); \
337 }
338
339#define ATTR_FUNCTION_GET(name, container_type, offset, mask) \
340 static inline enum ffa_##name ffa_get_##name##_attr( \
341 container_type attr) \
342 { \
343 return (enum ffa_##name)((attr & mask) >> offset); \
344 }
345
346ATTR_FUNCTION_SET(data_access, ffa_memory_access_permissions_t,
347 FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK)
348ATTR_FUNCTION_GET(data_access, ffa_memory_access_permissions_t,
349 FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK)
350
351ATTR_FUNCTION_SET(instruction_access, ffa_memory_access_permissions_t,
352 FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK)
353ATTR_FUNCTION_GET(instruction_access, ffa_memory_access_permissions_t,
354 FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK)
355
356ATTR_FUNCTION_SET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET,
357 FFA_MEMORY_TYPE_MASK)
358ATTR_FUNCTION_GET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET,
359 FFA_MEMORY_TYPE_MASK)
360
361ATTR_FUNCTION_SET(memory_cacheability, ffa_memory_attributes_t,
362 FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK)
363ATTR_FUNCTION_GET(memory_cacheability, ffa_memory_attributes_t,
364 FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK)
365
366ATTR_FUNCTION_SET(memory_shareability, ffa_memory_attributes_t,
367 FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK)
368ATTR_FUNCTION_GET(memory_shareability, ffa_memory_attributes_t,
369 FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK)
370
371#define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \
372 ((ffa_memory_handle_t)(UINT64_C(1) << 63))
373#define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR \
374 ((ffa_memory_handle_t)(UINT64_C(1) << 63))
375#define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0))
376
377/**
378 * A set of contiguous pages which is part of a memory region. This corresponds
379 * to table "Constituent memory region descriptor" of the FFA 1.0 specification.
380 */
381struct ffa_memory_region_constituent {
382 /**
383 * The base IPA of the constituent memory region, aligned to 4 kiB page
384 * size granularity.
385 */
386 void *address;
387 /** The number of 4 kiB pages in the constituent memory region. */
388 uint32_t page_count;
389 /** Reserved field, must be 0. */
390 uint32_t reserved;
391};
392
393/**
394 * A set of pages comprising a memory region. This corresponds to table
395 * "Composite memory region descriptor" of the FFA 1.0 specification.
396 */
397struct ffa_composite_memory_region {
398 /**
399 * The total number of 4 kiB pages included in this memory region. This
400 * must be equal to the sum of page counts specified in each
401 * `ffa_memory_region_constituent`.
402 */
403 uint32_t page_count;
404 /**
405 * The number of constituents (`ffa_memory_region_constituent`)
406 * included in this memory region range.
407 */
408 uint32_t constituent_count;
409 /** Reserved field, must be 0. */
410 uint64_t reserved_0;
411 /** An array of `constituent_count` memory region constituents. */
412 struct ffa_memory_region_constituent constituents[];
413};
414
415/**
416 * This corresponds to table "Memory access permissions descriptor" of the FFA
417 * 1.0 specification.
418 */
419struct ffa_memory_region_attributes {
420 /** The ID of the VM to which the memory is being given or shared. */
Daniel Boulbye79d2072021-03-03 11:34:53 +0000421 ffa_id_t receiver;
J-Alvesf3a393c2020-10-23 16:00:39 +0100422 /**
423 * The permissions with which the memory region should be mapped in the
424 * receiver's page table.
425 */
426 ffa_memory_access_permissions_t permissions;
427 /**
428 * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP
429 * for memory regions with multiple borrowers.
430 */
431 ffa_memory_receiver_flags_t flags;
432};
433
434/** Flags to control the behaviour of a memory sharing transaction. */
435typedef uint32_t ffa_memory_region_flags_t;
436
437/**
438 * Clear memory region contents after unmapping it from the sender and before
439 * mapping it for any receiver.
440 */
441#define FFA_MEMORY_REGION_FLAG_CLEAR 0x1U
442
443/**
444 * Whether the hypervisor may time slice the memory sharing or retrieval
445 * operation.
446 */
447#define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2U
448
449/**
450 * Whether the hypervisor should clear the memory region after the receiver
451 * relinquishes it or is aborted.
452 */
453#define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4U
454
455#define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3)
456#define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3)
457#define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3)
458#define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3)
459#define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3)
460
J-Alves0435cae2020-11-06 10:49:56 +0000461/** The maximum number of recipients a memory region may be sent to. */
462#define MAX_MEM_SHARE_RECIPIENTS 1U
463
J-Alvesf3a393c2020-10-23 16:00:39 +0100464/**
465 * This corresponds to table "Endpoint memory access descriptor" of the FFA 1.0
466 * specification.
467 */
468struct ffa_memory_access {
469 struct ffa_memory_region_attributes receiver_permissions;
470 /**
471 * Offset in bytes from the start of the outer `ffa_memory_region` to
472 * an `ffa_composite_memory_region` struct.
473 */
474 uint32_t composite_memory_region_offset;
475 uint64_t reserved_0;
476};
477
478/**
479 * Information about a set of pages which are being shared. This corresponds to
480 * table "Lend, donate or share memory transaction descriptor" of the FFA
481 * 1.0 specification. Note that it is also used for retrieve requests and
482 * responses.
483 */
484struct ffa_memory_region {
485 /**
486 * The ID of the VM which originally sent the memory region, i.e. the
487 * owner.
488 */
Daniel Boulbye79d2072021-03-03 11:34:53 +0000489 ffa_id_t sender;
J-Alvesf3a393c2020-10-23 16:00:39 +0100490 ffa_memory_attributes_t attributes;
491 /** Reserved field, must be 0. */
492 uint8_t reserved_0;
493 /** Flags to control behaviour of the transaction. */
494 ffa_memory_region_flags_t flags;
495 ffa_memory_handle_t handle;
496 /**
497 * An implementation defined value associated with the receiver and the
498 * memory region.
499 */
500 uint64_t tag;
501 /** Reserved field, must be 0. */
502 uint32_t reserved_1;
503 /**
504 * The number of `ffa_memory_access` entries included in this
505 * transaction.
506 */
507 uint32_t receiver_count;
508 /**
509 * An array of `attribute_count` endpoint memory access descriptors.
510 * Each one specifies a memory region offset, an endpoint and the
511 * attributes with which this memory region should be mapped in that
512 * endpoint's page table.
513 */
514 struct ffa_memory_access receivers[];
515};
516
517/**
518 * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table
519 * "Descriptor to relinquish a memory region" of the FFA 1.0 specification.
520 */
521struct ffa_mem_relinquish {
522 ffa_memory_handle_t handle;
523 ffa_memory_region_flags_t flags;
524 uint32_t endpoint_count;
Daniel Boulbye79d2072021-03-03 11:34:53 +0000525 ffa_id_t endpoints[];
J-Alvesf3a393c2020-10-23 16:00:39 +0100526};
527
528static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t h1, uint32_t h2)
529{
J-Alves18c28052021-03-09 09:58:53 +0000530 return (ffa_notification_bitmap_t)h1 |
531 (ffa_notification_bitmap_t)h2 << 32;
J-Alvesf3a393c2020-10-23 16:00:39 +0100532}
533
534static inline ffa_memory_handle_t ffa_mem_success_handle(smc_ret_values r)
535{
536 return ffa_assemble_handle(r.ret2, r.ret3);
537}
538
539/**
540 * Gets the `ffa_composite_memory_region` for the given receiver from an
541 * `ffa_memory_region`, or NULL if it is not valid.
542 */
543static inline struct ffa_composite_memory_region *
544ffa_memory_region_get_composite(struct ffa_memory_region *memory_region,
545 uint32_t receiver_index)
546{
547 uint32_t offset = memory_region->receivers[receiver_index]
548 .composite_memory_region_offset;
549
550 if (offset == 0) {
551 return NULL;
552 }
553
554 return (struct ffa_composite_memory_region *)((uint8_t *)memory_region +
555 offset);
556}
557
558static inline uint32_t ffa_mem_relinquish_init(
559 struct ffa_mem_relinquish *relinquish_request,
560 ffa_memory_handle_t handle, ffa_memory_region_flags_t flags,
Daniel Boulbye79d2072021-03-03 11:34:53 +0000561 ffa_id_t sender)
J-Alvesf3a393c2020-10-23 16:00:39 +0100562{
563 relinquish_request->handle = handle;
564 relinquish_request->flags = flags;
565 relinquish_request->endpoint_count = 1;
566 relinquish_request->endpoints[0] = sender;
Daniel Boulbye79d2072021-03-03 11:34:53 +0000567 return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_id_t);
J-Alvesf3a393c2020-10-23 16:00:39 +0100568}
569
570uint32_t ffa_memory_retrieve_request_init(
571 struct ffa_memory_region *memory_region, ffa_memory_handle_t handle,
Daniel Boulbye79d2072021-03-03 11:34:53 +0000572 ffa_id_t sender, ffa_id_t receiver, uint32_t tag,
J-Alvesf3a393c2020-10-23 16:00:39 +0100573 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
574 enum ffa_instruction_access instruction_access,
575 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
576 enum ffa_memory_shareability shareability);
577
578uint32_t ffa_memory_region_init(
579 struct ffa_memory_region *memory_region, size_t memory_region_max_size,
Daniel Boulbye79d2072021-03-03 11:34:53 +0000580 ffa_id_t sender, ffa_id_t receiver,
J-Alvesf3a393c2020-10-23 16:00:39 +0100581 const struct ffa_memory_region_constituent constituents[],
582 uint32_t constituent_count, uint32_t tag,
583 ffa_memory_region_flags_t flags, enum ffa_data_access data_access,
584 enum ffa_instruction_access instruction_access,
585 enum ffa_memory_type type, enum ffa_memory_cacheability cacheability,
586 enum ffa_memory_shareability shareability, uint32_t *total_length,
587 uint32_t *fragment_length);
588
Daniel Boulbye79d2072021-03-03 11:34:53 +0000589static inline ffa_id_t ffa_dir_msg_dest(smc_ret_values val) {
590 return (ffa_id_t)val.ret1 & U(0xFFFF);
J-Alves6cb21d92021-01-07 15:18:12 +0000591}
592
Daniel Boulbye79d2072021-03-03 11:34:53 +0000593static inline ffa_id_t ffa_dir_msg_source(smc_ret_values val) {
594 return (ffa_id_t)(val.ret1 >> 16U);
J-Alves6cb21d92021-01-07 15:18:12 +0000595}
596
Daniel Boulbye79d2072021-03-03 11:34:53 +0000597smc_ret_values ffa_msg_send_direct_req64(ffa_id_t source_id,
598 ffa_id_t dest_id, uint64_t arg0,
J-Alvesecd30742021-02-19 18:31:06 +0000599 uint64_t arg1, uint64_t arg2,
600 uint64_t arg3, uint64_t arg4);
J-Alvesd1aae292020-10-08 17:16:58 +0100601
Daniel Boulbye79d2072021-03-03 11:34:53 +0000602smc_ret_values ffa_msg_send_direct_req32(ffa_id_t source_id,
603 ffa_id_t dest_id, uint32_t arg0,
J-Alvesecd30742021-02-19 18:31:06 +0000604 uint32_t arg1, uint32_t arg2,
605 uint32_t arg3, uint32_t arg4);
606
Daniel Boulbye79d2072021-03-03 11:34:53 +0000607smc_ret_values ffa_msg_send_direct_resp64(ffa_id_t source_id,
608 ffa_id_t dest_id, uint64_t arg0,
J-Alvesecd30742021-02-19 18:31:06 +0000609 uint64_t arg1, uint64_t arg2,
610 uint64_t arg3, uint64_t arg4);
611
Daniel Boulbye79d2072021-03-03 11:34:53 +0000612smc_ret_values ffa_msg_send_direct_resp32(ffa_id_t source_id,
613 ffa_id_t dest_id, uint32_t arg0,
J-Alvesecd30742021-02-19 18:31:06 +0000614 uint32_t arg1, uint32_t arg2,
615 uint32_t arg3, uint32_t arg4);
J-Alves035b7d02021-02-11 10:40:35 +0000616
J-Alves7581c382020-05-07 18:34:20 +0100617smc_ret_values ffa_run(uint32_t dest_id, uint32_t vcpu_id);
J-Alves8f08a052020-05-26 17:14:40 +0100618smc_ret_values ffa_version(uint32_t input_version);
J-Alves5aecd982020-06-11 10:25:33 +0100619smc_ret_values ffa_id_get(void);
Daniel Boulby198deda2021-03-03 11:35:25 +0000620smc_ret_values ffa_spm_id_get(void);
J-Alves5aecd982020-06-11 10:25:33 +0100621smc_ret_values ffa_msg_wait(void);
J-Alves5aecd982020-06-11 10:25:33 +0100622smc_ret_values ffa_error(int32_t error_code);
Max Shvetsovc17c1d32020-06-11 15:03:01 +0100623smc_ret_values ffa_features(uint32_t feature);
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000624smc_ret_values ffa_partition_info_get(const struct ffa_uuid uuid);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100625smc_ret_values ffa_rx_release(void);
Ruari Phippsbd0a7e42020-07-17 16:42:21 +0100626smc_ret_values ffa_rxtx_map(uintptr_t send, uintptr_t recv, uint32_t pages);
Daniel Boulbye0602902021-07-07 11:14:39 +0100627smc_ret_values ffa_rxtx_unmap(void);
J-Alves3ea46d12020-09-09 11:13:05 +0100628smc_ret_values ffa_mem_donate(uint32_t descriptor_length,
629 uint32_t fragment_length);
630smc_ret_values ffa_mem_lend(uint32_t descriptor_length,
631 uint32_t fragment_length);
632smc_ret_values ffa_mem_share(uint32_t descriptor_length,
633 uint32_t fragment_length);
634smc_ret_values ffa_mem_retrieve_req(uint32_t descriptor_length,
635 uint32_t fragment_length);
636smc_ret_values ffa_mem_relinquish(void);
637smc_ret_values ffa_mem_reclaim(uint64_t handle, uint32_t flags);
J-Alvesbcb1f972021-03-11 14:03:54 +0000638smc_ret_values ffa_notification_bitmap_create(ffa_id_t vm_id,
639 ffa_vcpu_count_t vcpu_count);
640smc_ret_values ffa_notification_bitmap_destroy(ffa_id_t vm_id);
J-Alves18c28052021-03-09 09:58:53 +0000641smc_ret_values ffa_notification_bind(ffa_id_t sender, ffa_id_t receiver,
642 uint32_t flags,
643 ffa_notification_bitmap_t notifications);
644smc_ret_values ffa_notification_unbind(ffa_id_t sender, ffa_id_t receiver,
645 ffa_notification_bitmap_t notifications);
J-Alvesf156ae92021-10-08 12:10:05 +0100646smc_ret_values ffa_notification_set(ffa_id_t sender, ffa_id_t receiver,
647 uint32_t flags,
648 ffa_notification_bitmap_t bitmap);
649smc_ret_values ffa_notification_get(ffa_id_t receiver, uint32_t vcpu_id,
650 uint32_t flags);
J-Alves5bce2502021-06-14 14:27:45 +0100651smc_ret_values ffa_notification_info_get(void);
J-Alves7581c382020-05-07 18:34:20 +0100652#endif /* __ASSEMBLY__ */
653
654#endif /* FFA_HELPERS_H */