J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 1 | /* |
Karl Meakin | 92aa770 | 2023-10-11 18:48:01 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2023, Arm Limited. All rights reserved. |
J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef FFA_HELPERS_H |
| 8 | #define FFA_HELPERS_H |
| 9 | |
J-Alves | 8f08a05 | 2020-05-26 17:14:40 +0100 | [diff] [blame] | 10 | #include <ffa_svc.h> |
J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 11 | #include <tftf_lib.h> |
| 12 | #include <utils_def.h> |
| 13 | |
J-Alves | 779fba6 | 2024-04-05 14:14:40 +0100 | [diff] [blame^] | 14 | #include <xlat_tables_defs.h> |
| 15 | |
J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 16 | /* This error code must be different to the ones used by FFA */ |
| 17 | #define FFA_TFTF_ERROR -42 |
| 18 | |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 19 | typedef unsigned short ffa_id_t; |
J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 20 | typedef unsigned short ffa_vm_count_t; |
| 21 | typedef unsigned short ffa_vcpu_count_t; |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 22 | typedef uint64_t ffa_memory_handle_t; |
| 23 | /** Flags to indicate properties of receivers during memory region retrieval. */ |
| 24 | typedef uint8_t ffa_memory_receiver_flags_t; |
J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 25 | |
J-Alves | d708c03 | 2020-11-19 12:14:21 +0000 | [diff] [blame] | 26 | struct ffa_uuid { |
Raghu Krishnamurthy | ab5321a | 2023-04-23 16:14:28 -0700 | [diff] [blame] | 27 | uint32_t uuid[4]; |
J-Alves | d708c03 | 2020-11-19 12:14:21 +0000 | [diff] [blame] | 28 | }; |
| 29 | |
J-Alves | da3e6d4 | 2022-01-25 10:19:56 +0000 | [diff] [blame] | 30 | /** Length in bytes of the name in boot information descriptor. */ |
| 31 | #define FFA_BOOT_INFO_NAME_LEN 16 |
| 32 | |
| 33 | /** |
| 34 | * The FF-A boot info descriptor, as defined in table 5.8 of section 5.4.1, of |
| 35 | * the FF-A v1.1 EAC0 specification. |
| 36 | */ |
| 37 | struct ffa_boot_info_desc { |
| 38 | char name[FFA_BOOT_INFO_NAME_LEN]; |
| 39 | uint8_t type; |
| 40 | uint8_t reserved; |
| 41 | uint16_t flags; |
| 42 | uint32_t size; |
| 43 | uint64_t content; |
| 44 | }; |
| 45 | |
| 46 | /** FF-A boot information type mask. */ |
| 47 | #define FFA_BOOT_INFO_TYPE_SHIFT 7 |
| 48 | #define FFA_BOOT_INFO_TYPE_MASK (0x1U << FFA_BOOT_INFO_TYPE_SHIFT) |
| 49 | #define FFA_BOOT_INFO_TYPE_STD 0U |
| 50 | #define FFA_BOOT_INFO_TYPE_IMPDEF 1U |
| 51 | |
| 52 | /** Standard boot info type IDs. */ |
| 53 | #define FFA_BOOT_INFO_TYPE_ID_MASK 0x7FU |
| 54 | #define FFA_BOOT_INFO_TYPE_ID_FDT 0U |
| 55 | #define FFA_BOOT_INFO_TYPE_ID_HOB 1U |
| 56 | |
| 57 | /** FF-A Boot Info descriptors flags. */ |
| 58 | #define FFA_BOOT_INFO_FLAG_MBZ_MASK 0xFFF0U |
| 59 | |
| 60 | /** Bits [1:0] encode the format of the name field in ffa_boot_info_desc. */ |
| 61 | #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT 0U |
| 62 | #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK \ |
| 63 | (0x3U << FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT) |
| 64 | #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING 0x0U |
| 65 | #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID 0x1U |
| 66 | |
| 67 | /** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */ |
| 68 | #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT 2 |
| 69 | #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK \ |
| 70 | (0x3U << FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT) |
| 71 | #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE 0x1U |
| 72 | #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR 0x0U |
| 73 | |
| 74 | static inline uint16_t ffa_boot_info_content_format( |
| 75 | struct ffa_boot_info_desc *desc) |
| 76 | { |
| 77 | return (desc->flags & FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK) >> |
| 78 | FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT; |
| 79 | } |
| 80 | |
| 81 | static inline uint16_t ffa_boot_info_name_format( |
| 82 | struct ffa_boot_info_desc *desc) |
| 83 | { |
| 84 | return (desc->flags & FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK) >> |
| 85 | FFA_BOOT_INFO_FLAG_NAME_FORMAT_SHIFT; |
| 86 | } |
| 87 | |
| 88 | static inline uint8_t ffa_boot_info_type_id(struct ffa_boot_info_desc *desc) |
| 89 | { |
| 90 | return desc->type & FFA_BOOT_INFO_TYPE_ID_MASK; |
| 91 | } |
| 92 | |
| 93 | static inline uint8_t ffa_boot_info_type(struct ffa_boot_info_desc *desc) |
| 94 | { |
| 95 | return (desc->type & FFA_BOOT_INFO_TYPE_MASK) >> |
| 96 | FFA_BOOT_INFO_TYPE_SHIFT; |
| 97 | } |
| 98 | |
| 99 | /** Length in bytes of the signature in the boot descriptor. */ |
| 100 | #define FFA_BOOT_INFO_HEADER_SIGNATURE_LEN 4 |
| 101 | |
| 102 | /** |
| 103 | * The FF-A boot information header, as defined in table 5.9 of section 5.4.2, |
| 104 | * of the FF-A v1.1 EAC0 specification. |
| 105 | */ |
| 106 | struct ffa_boot_info_header { |
| 107 | uint32_t signature; |
| 108 | uint32_t version; |
| 109 | uint32_t info_blob_size; |
| 110 | uint32_t desc_size; |
| 111 | uint32_t desc_count; |
| 112 | uint32_t desc_offset; |
| 113 | uint64_t reserved; |
| 114 | struct ffa_boot_info_desc boot_info[]; |
| 115 | }; |
| 116 | |
J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 117 | #ifndef __ASSEMBLY__ |
| 118 | |
J-Alves | 18c2805 | 2021-03-09 09:58:53 +0000 | [diff] [blame] | 119 | #include <cassert.h> |
J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 120 | #include <stdint.h> |
| 121 | |
J-Alves | 4439ece | 2021-11-05 11:52:54 +0000 | [diff] [blame] | 122 | /** |
| 123 | * FF-A Feature ID, to be used with interface FFA_FEATURES. |
| 124 | * As defined in the FF-A v1.1 Beta specification, table 13.10, in section |
| 125 | * 13.2. |
| 126 | */ |
| 127 | |
| 128 | /** Query interrupt ID of Notification Pending Interrupt. */ |
| 129 | #define FFA_FEATURE_NPI 0x1U |
| 130 | |
| 131 | /** Query interrupt ID of Schedule Receiver Interrupt. */ |
| 132 | #define FFA_FEATURE_SRI 0x2U |
| 133 | |
| 134 | /** Query interrupt ID of the Managed Exit Interrupt. */ |
| 135 | #define FFA_FEATURE_MEI 0x3U |
| 136 | |
Karl Meakin | f2bb5d0 | 2024-02-13 17:23:17 +0000 | [diff] [blame] | 137 | /** Minimum and maximum buffer size reported by FFA_FEATURES(FFA_RXTX_MAP) */ |
| 138 | #define FFA_RXTX_MAP_MIN_BUF_4K 0 |
| 139 | #define FFA_RXTX_MAP_MAX_BUF_PAGE_COUNT 1 |
| 140 | |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 141 | /** Partition property: partition supports receipt of direct requests. */ |
Kathleen Capella | 7774d6e | 2022-11-23 19:06:21 -0500 | [diff] [blame] | 142 | #define FFA_PARTITION_DIRECT_REQ_RECV (UINT32_C(1) << 0) |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 143 | |
| 144 | /** Partition property: partition can send direct requests. */ |
Kathleen Capella | 7774d6e | 2022-11-23 19:06:21 -0500 | [diff] [blame] | 145 | #define FFA_PARTITION_DIRECT_REQ_SEND (UINT32_C(1) << 1) |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 146 | |
| 147 | /** Partition property: partition can send and receive indirect messages. */ |
Kathleen Capella | 7774d6e | 2022-11-23 19:06:21 -0500 | [diff] [blame] | 148 | #define FFA_PARTITION_INDIRECT_MSG (UINT32_C(1) << 2) |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 149 | |
J-Alves | 4d05dec | 2021-11-02 11:52:27 +0000 | [diff] [blame] | 150 | /** Partition property: partition can receive notifications. */ |
Kathleen Capella | 7774d6e | 2022-11-23 19:06:21 -0500 | [diff] [blame] | 151 | #define FFA_PARTITION_NOTIFICATION (UINT32_C(1) << 3) |
J-Alves | 4d05dec | 2021-11-02 11:52:27 +0000 | [diff] [blame] | 152 | |
Kathleen Capella | 7774d6e | 2022-11-23 19:06:21 -0500 | [diff] [blame] | 153 | /** Partition property: partition runs in the AArch64 execution state. */ |
| 154 | #define FFA_PARTITION_AARCH64_EXEC (UINT32_C(1) << 8) |
| 155 | |
| 156 | /** Partition info descriptor as defined in FF-A v1.1 EAC0 Table 13.37 */ |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 157 | struct ffa_partition_info { |
| 158 | /** The ID of the VM the information is about */ |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 159 | ffa_id_t id; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 160 | /** The number of execution contexts implemented by the partition */ |
| 161 | uint16_t exec_context; |
| 162 | /** The Partition's properties, e.g. supported messaging methods */ |
| 163 | uint32_t properties; |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 164 | /** The uuid of the partition */ |
| 165 | struct ffa_uuid uuid; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 166 | }; |
| 167 | |
Daniel Boulby | 2ac55f2 | 2022-01-21 12:08:08 +0000 | [diff] [blame] | 168 | /** |
Kathleen Capella | 7774d6e | 2022-11-23 19:06:21 -0500 | [diff] [blame] | 169 | * Bits[31:3] of partition properties must be zero for FF-A v1.0. |
| 170 | * This corresponds to table 8.25 "Partition information descriptor" |
| 171 | * in DEN0077A FF-A 1.0 REL specification. |
| 172 | */ |
| 173 | #define FFA_PARTITION_v1_0_RES_MASK (~(UINT32_C(0x7))) |
| 174 | |
| 175 | /** |
Daniel Boulby | 2ac55f2 | 2022-01-21 12:08:08 +0000 | [diff] [blame] | 176 | * Partition info descriptor as defined in Table 8.25 of the v1.0 |
Kathleen Capella | 7774d6e | 2022-11-23 19:06:21 -0500 | [diff] [blame] | 177 | * FF-A Specification (DEN0077A). |
Daniel Boulby | 2ac55f2 | 2022-01-21 12:08:08 +0000 | [diff] [blame] | 178 | */ |
| 179 | struct ffa_partition_info_v1_0 { |
| 180 | /** The ID of the VM the information is about */ |
| 181 | ffa_id_t id; |
| 182 | /** The number of execution contexts implemented by the partition */ |
| 183 | uint16_t exec_context; |
| 184 | /** The Partition's properties, e.g. supported messaging methods */ |
| 185 | uint32_t properties; |
| 186 | }; |
| 187 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 188 | struct ffa_value { |
| 189 | u_register_t fid; |
| 190 | u_register_t arg1; |
| 191 | u_register_t arg2; |
| 192 | u_register_t arg3; |
| 193 | u_register_t arg4; |
| 194 | u_register_t arg5; |
| 195 | u_register_t arg6; |
| 196 | u_register_t arg7; |
Raghu Krishnamurthy | ab5321a | 2023-04-23 16:14:28 -0700 | [diff] [blame] | 197 | u_register_t arg8; |
| 198 | u_register_t arg9; |
| 199 | u_register_t arg10; |
| 200 | u_register_t arg11; |
| 201 | u_register_t arg12; |
| 202 | u_register_t arg13; |
| 203 | u_register_t arg14; |
| 204 | u_register_t arg15; |
| 205 | u_register_t arg16; |
| 206 | u_register_t arg17; |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 207 | }; |
| 208 | |
| 209 | /* Function to make an SMC or SVC service call depending on the exception |
| 210 | * level of the SP. |
| 211 | */ |
| 212 | struct ffa_value ffa_service_call(struct ffa_value *args); |
| 213 | |
| 214 | /* |
| 215 | * Functions to trigger a service call. |
| 216 | * |
| 217 | * The arguments to pass through the service call must be stored in the |
| 218 | * ffa_value structure. The return values of the service call will be stored |
| 219 | * in the same structure (overriding the input arguments). |
| 220 | * |
| 221 | * Return the first return value. It is equivalent to args.fid but is also |
| 222 | * provided as the return value for convenience. |
| 223 | */ |
| 224 | u_register_t ffa_svc(struct ffa_value *args); |
| 225 | u_register_t ffa_smc(struct ffa_value *args); |
| 226 | |
| 227 | static inline uint32_t ffa_func_id(struct ffa_value val) |
J-Alves | f156ae9 | 2021-10-08 12:10:05 +0100 | [diff] [blame] | 228 | { |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 229 | return (uint32_t)val.fid; |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 232 | static inline int32_t ffa_error_code(struct ffa_value val) |
J-Alves | f156ae9 | 2021-10-08 12:10:05 +0100 | [diff] [blame] | 233 | { |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 234 | return (int32_t)val.arg2; |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 237 | static inline ffa_id_t ffa_endpoint_id(struct ffa_value val) { |
| 238 | return (ffa_id_t)val.arg2 & 0xffff; |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 241 | static inline uint32_t ffa_partition_info_count(struct ffa_value val) |
Daniel Boulby | 2ac55f2 | 2022-01-21 12:08:08 +0000 | [diff] [blame] | 242 | { |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 243 | return (uint32_t)val.arg2; |
Daniel Boulby | 2ac55f2 | 2022-01-21 12:08:08 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Daniel Boulby | 07d751e | 2022-05-30 17:32:00 +0100 | [diff] [blame] | 246 | static inline uint32_t ffa_partition_info_desc_size(struct ffa_value val) |
| 247 | { |
| 248 | return (uint32_t)val.arg3; |
| 249 | } |
| 250 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 251 | static inline uint32_t ffa_feature_intid(struct ffa_value val) |
J-Alves | 4439ece | 2021-11-05 11:52:54 +0000 | [diff] [blame] | 252 | { |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 253 | return (uint32_t)val.arg2; |
J-Alves | 4439ece | 2021-11-05 11:52:54 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Raghu Krishnamurthy | ab5321a | 2023-04-23 16:14:28 -0700 | [diff] [blame] | 256 | static inline uint16_t ffa_partition_info_regs_get_last_idx( |
| 257 | struct ffa_value args) |
| 258 | { |
| 259 | return args.arg2 & 0xFFFF; |
| 260 | } |
| 261 | |
| 262 | static inline uint16_t ffa_partition_info_regs_get_curr_idx( |
| 263 | struct ffa_value args) |
| 264 | { |
| 265 | return (args.arg2 >> 16) & 0xFFFF; |
| 266 | } |
| 267 | |
| 268 | static inline uint16_t ffa_partition_info_regs_get_tag(struct ffa_value args) |
| 269 | { |
| 270 | return (args.arg2 >> 32) & 0xFFFF; |
| 271 | } |
| 272 | |
| 273 | static inline uint16_t ffa_partition_info_regs_get_desc_size( |
| 274 | struct ffa_value args) |
| 275 | { |
| 276 | return (args.arg2 >> 48); |
| 277 | } |
| 278 | |
| 279 | static inline uint32_t ffa_partition_info_regs_partition_count( |
| 280 | struct ffa_value args) |
| 281 | { |
| 282 | return ffa_partition_info_regs_get_last_idx(args) + 1; |
| 283 | } |
| 284 | |
| 285 | static inline uint32_t ffa_partition_info_regs_entry_count( |
| 286 | struct ffa_value args, uint16_t start_idx) |
| 287 | { |
| 288 | return (ffa_partition_info_regs_get_curr_idx(args) - start_idx + 1); |
| 289 | } |
| 290 | |
| 291 | static inline uint16_t ffa_partition_info_regs_entry_size( |
| 292 | struct ffa_value args) |
| 293 | { |
| 294 | return (args.arg2 >> 48) & 0xFFFFU; |
| 295 | } |
| 296 | |
J-Alves | 18c2805 | 2021-03-09 09:58:53 +0000 | [diff] [blame] | 297 | typedef uint64_t ffa_notification_bitmap_t; |
| 298 | |
J-Alves | 779fba6 | 2024-04-05 14:14:40 +0100 | [diff] [blame^] | 299 | /** |
| 300 | * Partition message header as specified by table 6.2 from FF-A v1.1 EAC0 |
| 301 | * specification. |
| 302 | */ |
| 303 | struct ffa_partition_rxtx_header { |
| 304 | uint32_t flags; |
| 305 | /* MBZ */ |
| 306 | uint32_t reserved; |
| 307 | /* Offset from the beginning of the buffer to the message payload. */ |
| 308 | uint32_t offset; |
| 309 | /* Sender(Bits[31:16]) and Receiver(Bits[15:0]) endpoint IDs. */ |
| 310 | ffa_id_t receiver; |
| 311 | ffa_id_t sender; |
| 312 | /* Size of message in buffer. */ |
| 313 | uint32_t size; |
| 314 | }; |
| 315 | |
| 316 | #define FFA_RXTX_HEADER_SIZE sizeof(struct ffa_partition_rxtx_header) |
| 317 | |
| 318 | static inline void ffa_rxtx_header_init( |
| 319 | ffa_id_t sender, ffa_id_t receiver, uint32_t size, |
| 320 | struct ffa_partition_rxtx_header *header) |
| 321 | { |
| 322 | header->flags = 0; |
| 323 | header->reserved = 0; |
| 324 | header->offset = FFA_RXTX_HEADER_SIZE; |
| 325 | header->sender = sender; |
| 326 | header->receiver = receiver; |
| 327 | header->size = size; |
| 328 | } |
| 329 | |
| 330 | /* The maximum length possible for a single message. */ |
| 331 | #define FFA_PARTITION_MSG_PAYLOAD_MAX (PAGE_SIZE - FFA_RXTX_HEADER_SIZE) |
| 332 | |
| 333 | struct ffa_partition_msg { |
| 334 | struct ffa_partition_rxtx_header header; |
| 335 | char payload[FFA_PARTITION_MSG_PAYLOAD_MAX]; |
| 336 | }; |
| 337 | |
| 338 | /* The maximum length possible for a single message. */ |
| 339 | #define FFA_MSG_PAYLOAD_MAX PAGE_SIZE |
| 340 | |
J-Alves | 18c2805 | 2021-03-09 09:58:53 +0000 | [diff] [blame] | 341 | #define FFA_NOTIFICATION(ID) (UINT64_C(1) << ID) |
| 342 | |
| 343 | #define MAX_FFA_NOTIFICATIONS UINT32_C(64) |
| 344 | |
| 345 | #define FFA_NOTIFICATIONS_FLAG_PER_VCPU UINT32_C(0x1 << 0) |
| 346 | |
J-Alves | b0cb5d0 | 2021-07-08 11:19:33 +0100 | [diff] [blame] | 347 | /** Flag to delay Schedule Receiver Interrupt. */ |
| 348 | #define FFA_NOTIFICATIONS_FLAG_DELAY_SRI UINT32_C(0x1 << 1) |
| 349 | |
J-Alves | 18c2805 | 2021-03-09 09:58:53 +0000 | [diff] [blame] | 350 | #define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) UINT32_C((id & 0xFFFF) << 16) |
| 351 | |
J-Alves | f156ae9 | 2021-10-08 12:10:05 +0100 | [diff] [blame] | 352 | #define FFA_NOTIFICATIONS_FLAG_BITMAP_SP UINT32_C(0x1 << 0) |
| 353 | #define FFA_NOTIFICATIONS_FLAG_BITMAP_VM UINT32_C(0x1 << 1) |
| 354 | #define FFA_NOTIFICATIONS_FLAG_BITMAP_SPM UINT32_C(0x1 << 2) |
| 355 | #define FFA_NOTIFICATIONS_FLAG_BITMAP_HYP UINT32_C(0x1 << 3) |
| 356 | |
J-Alves | 269118a | 2021-09-22 09:46:11 +0100 | [diff] [blame] | 357 | /** |
| 358 | * The following is an SGI ID, that the SPMC configures as non-secure, as |
| 359 | * suggested by the FF-A v1.1 specification, in section 9.4.1. |
| 360 | */ |
| 361 | #define FFA_SCHEDULE_RECEIVER_INTERRUPT_ID 8 |
| 362 | |
J-Alves | f156ae9 | 2021-10-08 12:10:05 +0100 | [diff] [blame] | 363 | #define FFA_NOTIFICATIONS_BITMAP(lo, hi) \ |
| 364 | (ffa_notification_bitmap_t)(lo) | \ |
| 365 | (((ffa_notification_bitmap_t)hi << 32) & 0xFFFFFFFF00000000ULL) |
| 366 | |
| 367 | #define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) UINT32_C((id & 0xFFFF) << 16) |
| 368 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 369 | static inline ffa_notification_bitmap_t ffa_notifications_get_from_sp( |
| 370 | struct ffa_value val) |
J-Alves | f156ae9 | 2021-10-08 12:10:05 +0100 | [diff] [blame] | 371 | { |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 372 | return FFA_NOTIFICATIONS_BITMAP(val.arg2, val.arg3); |
J-Alves | f156ae9 | 2021-10-08 12:10:05 +0100 | [diff] [blame] | 373 | } |
| 374 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 375 | static inline ffa_notification_bitmap_t ffa_notifications_get_from_vm( |
| 376 | struct ffa_value val) |
J-Alves | f156ae9 | 2021-10-08 12:10:05 +0100 | [diff] [blame] | 377 | { |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 378 | return FFA_NOTIFICATIONS_BITMAP(val.arg4, val.arg5); |
J-Alves | f156ae9 | 2021-10-08 12:10:05 +0100 | [diff] [blame] | 379 | } |
| 380 | |
J-Alves | 5bce250 | 2021-06-14 14:27:45 +0100 | [diff] [blame] | 381 | /* |
| 382 | * FFA_NOTIFICATION_INFO_GET is a SMC64 interface. |
| 383 | * The following macros are defined for SMC64 implementation. |
| 384 | */ |
| 385 | #define FFA_NOTIFICATIONS_INFO_GET_MAX_IDS 20U |
| 386 | |
| 387 | #define FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING UINT64_C(0x1) |
| 388 | |
| 389 | #define FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT 0x7U |
| 390 | #define FFA_NOTIFICATIONS_LISTS_COUNT_MASK 0x1FU |
| 391 | #define FFA_NOTIFICATIONS_LIST_SHIFT(l) (2 * (l - 1) + 12) |
| 392 | #define FFA_NOTIFICATIONS_LIST_SIZE_MASK 0x3U |
| 393 | |
| 394 | static inline uint32_t ffa_notifications_info_get_lists_count( |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 395 | struct ffa_value ret) |
J-Alves | 5bce250 | 2021-06-14 14:27:45 +0100 | [diff] [blame] | 396 | { |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 397 | return (uint32_t)(ret.arg2 >> FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT) |
J-Alves | 5bce250 | 2021-06-14 14:27:45 +0100 | [diff] [blame] | 398 | & FFA_NOTIFICATIONS_LISTS_COUNT_MASK; |
| 399 | } |
| 400 | |
| 401 | static inline uint32_t ffa_notifications_info_get_list_size( |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 402 | struct ffa_value ret, uint32_t list) |
J-Alves | 5bce250 | 2021-06-14 14:27:45 +0100 | [diff] [blame] | 403 | { |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 404 | return (uint32_t)(ret.arg2 >> FFA_NOTIFICATIONS_LIST_SHIFT(list)) & |
J-Alves | 5bce250 | 2021-06-14 14:27:45 +0100 | [diff] [blame] | 405 | FFA_NOTIFICATIONS_LIST_SIZE_MASK; |
| 406 | } |
| 407 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 408 | static inline bool ffa_notifications_info_get_more_pending(struct ffa_value ret) |
J-Alves | 5bce250 | 2021-06-14 14:27:45 +0100 | [diff] [blame] | 409 | { |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 410 | return (ret.arg2 & FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING) != 0U; |
J-Alves | 5bce250 | 2021-06-14 14:27:45 +0100 | [diff] [blame] | 411 | } |
| 412 | |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 413 | enum ffa_data_access { |
| 414 | FFA_DATA_ACCESS_NOT_SPECIFIED, |
| 415 | FFA_DATA_ACCESS_RO, |
| 416 | FFA_DATA_ACCESS_RW, |
| 417 | FFA_DATA_ACCESS_RESERVED, |
| 418 | }; |
| 419 | |
| 420 | enum ffa_instruction_access { |
| 421 | FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED, |
| 422 | FFA_INSTRUCTION_ACCESS_NX, |
| 423 | FFA_INSTRUCTION_ACCESS_X, |
| 424 | FFA_INSTRUCTION_ACCESS_RESERVED, |
| 425 | }; |
| 426 | |
| 427 | enum ffa_memory_type { |
| 428 | FFA_MEMORY_NOT_SPECIFIED_MEM, |
| 429 | FFA_MEMORY_DEVICE_MEM, |
| 430 | FFA_MEMORY_NORMAL_MEM, |
| 431 | }; |
| 432 | |
| 433 | enum ffa_memory_cacheability { |
| 434 | FFA_MEMORY_CACHE_RESERVED = 0x0, |
| 435 | FFA_MEMORY_CACHE_NON_CACHEABLE = 0x1, |
| 436 | FFA_MEMORY_CACHE_RESERVED_1 = 0x2, |
| 437 | FFA_MEMORY_CACHE_WRITE_BACK = 0x3, |
| 438 | FFA_MEMORY_DEV_NGNRNE = 0x0, |
| 439 | FFA_MEMORY_DEV_NGNRE = 0x1, |
| 440 | FFA_MEMORY_DEV_NGRE = 0x2, |
| 441 | FFA_MEMORY_DEV_GRE = 0x3, |
| 442 | }; |
| 443 | |
| 444 | enum ffa_memory_shareability { |
| 445 | FFA_MEMORY_SHARE_NON_SHAREABLE, |
| 446 | FFA_MEMORY_SHARE_RESERVED, |
| 447 | FFA_MEMORY_OUTER_SHAREABLE, |
| 448 | FFA_MEMORY_INNER_SHAREABLE, |
| 449 | }; |
| 450 | |
Karl Meakin | 92aa770 | 2023-10-11 18:48:01 +0100 | [diff] [blame] | 451 | typedef struct { |
| 452 | uint8_t data_access : 2; |
| 453 | uint8_t instruction_access : 2; |
| 454 | } ffa_memory_access_permissions_t; |
| 455 | |
| 456 | _Static_assert(sizeof(ffa_memory_access_permissions_t) == sizeof(uint8_t), |
| 457 | "ffa_memory_access_permissions_t must be 1 byte wide"); |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 458 | |
| 459 | /** |
J-Alves | d13d760 | 2023-05-05 14:19:03 +0100 | [diff] [blame] | 460 | * FF-A v1.1 REL0 Table 10.18 memory region attributes descriptor NS Bit 6. |
| 461 | * Per section 10.10.4.1, NS bit is reserved for FFA_MEM_DONATE/LEND/SHARE |
| 462 | * and FFA_MEM_RETRIEVE_REQUEST. |
| 463 | */ |
| 464 | enum ffa_memory_security { |
| 465 | FFA_MEMORY_SECURITY_UNSPECIFIED = 0, |
| 466 | FFA_MEMORY_SECURITY_SECURE = 0, |
| 467 | FFA_MEMORY_SECURITY_NON_SECURE, |
| 468 | }; |
| 469 | |
| 470 | /** |
J-Alves | b42d17f | 2022-07-04 12:42:13 +0100 | [diff] [blame] | 471 | * This corresponds to table 10.18 of the FF-A v1.1 EAC0 specification, "Memory |
| 472 | * region attributes descriptor". |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 473 | */ |
Karl Meakin | 92aa770 | 2023-10-11 18:48:01 +0100 | [diff] [blame] | 474 | typedef struct { |
| 475 | uint16_t shareability : 2; |
| 476 | uint16_t cacheability : 2; |
| 477 | uint16_t type : 2; |
| 478 | uint16_t security : 1; |
| 479 | } ffa_memory_attributes_t; |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 480 | |
Karl Meakin | 92aa770 | 2023-10-11 18:48:01 +0100 | [diff] [blame] | 481 | _Static_assert(sizeof(ffa_memory_attributes_t) == sizeof(uint16_t), |
| 482 | "ffa_memory_attributes_t must be 2 bytes wide"); |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 483 | |
Karl Meakin | 0d4f5ff | 2023-10-13 20:03:16 +0100 | [diff] [blame] | 484 | #define FFA_MEMORY_HANDLE_ALLOCATOR_MASK UINT64_C(1) |
| 485 | #define FFA_MEMORY_HANDLE_ALLOCATOR_SHIFT 63U |
| 486 | #define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR UINT64_C(1) |
| 487 | #define FFA_MEMORY_HANDLE_ALLOCATOR_SPMC UINT64_C(0) |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 488 | #define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0)) |
| 489 | |
| 490 | /** |
| 491 | * A set of contiguous pages which is part of a memory region. This corresponds |
J-Alves | b42d17f | 2022-07-04 12:42:13 +0100 | [diff] [blame] | 492 | * to table 10.14 of the FF-A v1.1 EAC0 specification, "Constituent memory |
| 493 | * region descriptor". |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 494 | */ |
| 495 | struct ffa_memory_region_constituent { |
| 496 | /** |
| 497 | * The base IPA of the constituent memory region, aligned to 4 kiB page |
| 498 | * size granularity. |
| 499 | */ |
| 500 | void *address; |
| 501 | /** The number of 4 kiB pages in the constituent memory region. */ |
| 502 | uint32_t page_count; |
| 503 | /** Reserved field, must be 0. */ |
| 504 | uint32_t reserved; |
| 505 | }; |
| 506 | |
| 507 | /** |
J-Alves | b42d17f | 2022-07-04 12:42:13 +0100 | [diff] [blame] | 508 | * A set of pages comprising a memory region. This corresponds to table 10.13 of |
| 509 | * the FF-A v1.1 EAC0 specification, "Composite memory region descriptor". |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 510 | */ |
| 511 | struct ffa_composite_memory_region { |
| 512 | /** |
| 513 | * The total number of 4 kiB pages included in this memory region. This |
| 514 | * must be equal to the sum of page counts specified in each |
| 515 | * `ffa_memory_region_constituent`. |
| 516 | */ |
| 517 | uint32_t page_count; |
| 518 | /** |
| 519 | * The number of constituents (`ffa_memory_region_constituent`) |
| 520 | * included in this memory region range. |
| 521 | */ |
| 522 | uint32_t constituent_count; |
| 523 | /** Reserved field, must be 0. */ |
| 524 | uint64_t reserved_0; |
| 525 | /** An array of `constituent_count` memory region constituents. */ |
| 526 | struct ffa_memory_region_constituent constituents[]; |
| 527 | }; |
| 528 | |
| 529 | /** |
| 530 | * This corresponds to table "Memory access permissions descriptor" of the FFA |
| 531 | * 1.0 specification. |
| 532 | */ |
| 533 | struct ffa_memory_region_attributes { |
| 534 | /** The ID of the VM to which the memory is being given or shared. */ |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 535 | ffa_id_t receiver; |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 536 | /** |
| 537 | * The permissions with which the memory region should be mapped in the |
| 538 | * receiver's page table. |
| 539 | */ |
| 540 | ffa_memory_access_permissions_t permissions; |
| 541 | /** |
| 542 | * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP |
| 543 | * for memory regions with multiple borrowers. |
| 544 | */ |
| 545 | ffa_memory_receiver_flags_t flags; |
| 546 | }; |
| 547 | |
Karl Meakin | bff9b3c | 2024-01-18 16:08:35 +0000 | [diff] [blame] | 548 | /** |
| 549 | * Endpoint RX/TX descriptor, as defined by Table 13.27 in FF-A v1.1 EAC0. |
| 550 | * It's used by the Hypervisor to describe the RX/TX buffers mapped by a VM |
| 551 | * to the SPMC, in order to allow indirect messaging. |
| 552 | */ |
| 553 | struct ffa_endpoint_rxtx_descriptor { |
| 554 | ffa_id_t endpoint_id; |
| 555 | uint16_t reserved; |
| 556 | |
| 557 | /* |
| 558 | * 8-byte aligned offset from the base address of this descriptor to the |
| 559 | * `ffa_composite_memory_region` describing the RX buffer. |
| 560 | */ |
| 561 | uint32_t rx_offset; |
| 562 | |
| 563 | /* |
| 564 | * 8-byte aligned offset from the base address of this descriptor to the |
| 565 | * `ffa_composite_memory_region` describing the TX buffer. |
| 566 | */ |
| 567 | uint32_t tx_offset; |
| 568 | |
| 569 | /* Pad to align on 16-byte boundary. */ |
| 570 | uint32_t pad; |
| 571 | }; |
| 572 | |
| 573 | _Static_assert(sizeof(struct ffa_endpoint_rxtx_descriptor) == 16, |
| 574 | "ffa_endpoint_rx_tx_descriptor must be 16 bytes wide"); |
| 575 | |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 576 | /** Flags to control the behaviour of a memory sharing transaction. */ |
| 577 | typedef uint32_t ffa_memory_region_flags_t; |
| 578 | |
| 579 | /** |
| 580 | * Clear memory region contents after unmapping it from the sender and before |
| 581 | * mapping it for any receiver. |
| 582 | */ |
| 583 | #define FFA_MEMORY_REGION_FLAG_CLEAR 0x1U |
| 584 | |
| 585 | /** |
| 586 | * Whether the hypervisor may time slice the memory sharing or retrieval |
| 587 | * operation. |
| 588 | */ |
| 589 | #define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2U |
| 590 | |
| 591 | /** |
| 592 | * Whether the hypervisor should clear the memory region after the receiver |
| 593 | * relinquishes it or is aborted. |
| 594 | */ |
| 595 | #define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4U |
| 596 | |
| 597 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3) |
| 598 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3) |
| 599 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3) |
| 600 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3) |
| 601 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3) |
| 602 | |
J-Alves | 0435cae | 2020-11-06 10:49:56 +0000 | [diff] [blame] | 603 | /** The maximum number of recipients a memory region may be sent to. */ |
J-Alves | f325331 | 2024-01-18 17:05:26 +0000 | [diff] [blame] | 604 | #define MAX_MEM_SHARE_RECIPIENTS 2U |
J-Alves | 0435cae | 2020-11-06 10:49:56 +0000 | [diff] [blame] | 605 | |
Daniel Boulby | a24f23a | 2023-11-15 18:23:40 +0000 | [diff] [blame] | 606 | struct ffa_memory_access_impdef { |
| 607 | uint64_t val[2]; |
| 608 | }; |
| 609 | |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 610 | /** |
| 611 | * This corresponds to table "Endpoint memory access descriptor" of the FFA 1.0 |
| 612 | * specification. |
| 613 | */ |
| 614 | struct ffa_memory_access { |
| 615 | struct ffa_memory_region_attributes receiver_permissions; |
| 616 | /** |
| 617 | * Offset in bytes from the start of the outer `ffa_memory_region` to |
| 618 | * an `ffa_composite_memory_region` struct. |
| 619 | */ |
| 620 | uint32_t composite_memory_region_offset; |
Daniel Boulby | a24f23a | 2023-11-15 18:23:40 +0000 | [diff] [blame] | 621 | /* Space for implementation defined information */ |
| 622 | struct ffa_memory_access_impdef impdef; |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 623 | uint64_t reserved_0; |
| 624 | }; |
| 625 | |
| 626 | /** |
| 627 | * Information about a set of pages which are being shared. This corresponds to |
J-Alves | b42d17f | 2022-07-04 12:42:13 +0100 | [diff] [blame] | 628 | * table 10.20 of the FF-A v1.1 EAC0 specification, "Lend, donate or share |
| 629 | * memory transaction descriptor". Note that it is also used for retrieve |
| 630 | * requests and responses. |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 631 | */ |
| 632 | struct ffa_memory_region { |
| 633 | /** |
| 634 | * The ID of the VM which originally sent the memory region, i.e. the |
| 635 | * owner. |
| 636 | */ |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 637 | ffa_id_t sender; |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 638 | ffa_memory_attributes_t attributes; |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 639 | /** Flags to control behaviour of the transaction. */ |
| 640 | ffa_memory_region_flags_t flags; |
| 641 | ffa_memory_handle_t handle; |
| 642 | /** |
| 643 | * An implementation defined value associated with the receiver and the |
| 644 | * memory region. |
| 645 | */ |
| 646 | uint64_t tag; |
J-Alves | b42d17f | 2022-07-04 12:42:13 +0100 | [diff] [blame] | 647 | /** Size of the memory access descriptor. */ |
| 648 | uint32_t memory_access_desc_size; |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 649 | /** |
| 650 | * The number of `ffa_memory_access` entries included in this |
| 651 | * transaction. |
| 652 | */ |
| 653 | uint32_t receiver_count; |
| 654 | /** |
J-Alves | b42d17f | 2022-07-04 12:42:13 +0100 | [diff] [blame] | 655 | * Offset of the 'receivers' field, which relates to the memory access |
| 656 | * descriptors. |
| 657 | */ |
| 658 | uint32_t receivers_offset; |
| 659 | /** Reserved field (12 bytes) must be 0. */ |
| 660 | uint32_t reserved[3]; |
| 661 | /** |
| 662 | * An array of `receiver_count` endpoint memory access descriptors. |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 663 | * Each one specifies a memory region offset, an endpoint and the |
| 664 | * attributes with which this memory region should be mapped in that |
| 665 | * endpoint's page table. |
| 666 | */ |
| 667 | struct ffa_memory_access receivers[]; |
| 668 | }; |
| 669 | |
| 670 | /** |
| 671 | * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table |
J-Alves | b42d17f | 2022-07-04 12:42:13 +0100 | [diff] [blame] | 672 | * 16.25 of the FF-A v1.1 EAC0 specification, "Descriptor to relinquish a memory |
| 673 | * region". |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 674 | */ |
| 675 | struct ffa_mem_relinquish { |
| 676 | ffa_memory_handle_t handle; |
| 677 | ffa_memory_region_flags_t flags; |
| 678 | uint32_t endpoint_count; |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 679 | ffa_id_t endpoints[]; |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 680 | }; |
| 681 | |
| 682 | static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t h1, uint32_t h2) |
| 683 | { |
J-Alves | 18c2805 | 2021-03-09 09:58:53 +0000 | [diff] [blame] | 684 | return (ffa_notification_bitmap_t)h1 | |
| 685 | (ffa_notification_bitmap_t)h2 << 32; |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 686 | } |
| 687 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 688 | static inline ffa_memory_handle_t ffa_mem_success_handle(struct ffa_value r) |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 689 | { |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 690 | return ffa_assemble_handle(r.arg2, r.arg3); |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 691 | } |
| 692 | |
Karl Meakin | 0d4f5ff | 2023-10-13 20:03:16 +0100 | [diff] [blame] | 693 | static inline ffa_memory_handle_t ffa_frag_handle(struct ffa_value r) |
| 694 | { |
| 695 | return ffa_assemble_handle(r.arg1, r.arg2); |
| 696 | } |
| 697 | |
| 698 | static inline ffa_id_t ffa_frag_sender(struct ffa_value args) |
| 699 | { |
| 700 | return (args.arg4 >> 16) & 0xffff; |
| 701 | } |
| 702 | |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 703 | /** |
J-Alves | f0b3bd6 | 2024-01-18 17:01:37 +0000 | [diff] [blame] | 704 | * To maintain forwards compatability we can't make assumptions about the size |
| 705 | * of the endpoint memory access descriptor so provide a helper function |
| 706 | * to get a receiver from the receiver array using the memory access descriptor |
| 707 | * size field from the memory region descriptor struct. |
| 708 | * Returns NULL if we cannot return the receiver. |
| 709 | */ |
| 710 | static inline struct ffa_memory_access *ffa_memory_region_get_receiver( |
| 711 | struct ffa_memory_region *memory_region, uint32_t receiver_index) |
| 712 | { |
| 713 | uint32_t memory_access_desc_size = |
| 714 | memory_region->memory_access_desc_size; |
| 715 | |
| 716 | if (receiver_index >= memory_region->receiver_count) { |
| 717 | return NULL; |
| 718 | } |
| 719 | |
| 720 | /* |
| 721 | * Memory access descriptor size cannot be greater than the size of |
| 722 | * the memory access descriptor defined by the current FF-A version. |
| 723 | */ |
| 724 | if (memory_access_desc_size > sizeof(struct ffa_memory_access)) { |
| 725 | return NULL; |
| 726 | } |
| 727 | |
| 728 | /* Check we cannot use receivers offset to cause overflow. */ |
| 729 | if (memory_region->receivers_offset != |
| 730 | sizeof(struct ffa_memory_region)) { |
| 731 | return NULL; |
| 732 | } |
| 733 | |
| 734 | return (struct ffa_memory_access *)((uint8_t *)memory_region + |
| 735 | memory_region->receivers_offset + |
| 736 | (receiver_index * |
| 737 | memory_access_desc_size)); |
| 738 | } |
| 739 | |
| 740 | /** |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 741 | * Gets the `ffa_composite_memory_region` for the given receiver from an |
| 742 | * `ffa_memory_region`, or NULL if it is not valid. |
| 743 | */ |
| 744 | static inline struct ffa_composite_memory_region * |
| 745 | ffa_memory_region_get_composite(struct ffa_memory_region *memory_region, |
| 746 | uint32_t receiver_index) |
| 747 | { |
| 748 | uint32_t offset = memory_region->receivers[receiver_index] |
| 749 | .composite_memory_region_offset; |
| 750 | |
| 751 | if (offset == 0) { |
| 752 | return NULL; |
| 753 | } |
| 754 | |
| 755 | return (struct ffa_composite_memory_region *)((uint8_t *)memory_region + |
| 756 | offset); |
| 757 | } |
| 758 | |
| 759 | static inline uint32_t ffa_mem_relinquish_init( |
| 760 | struct ffa_mem_relinquish *relinquish_request, |
| 761 | ffa_memory_handle_t handle, ffa_memory_region_flags_t flags, |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 762 | ffa_id_t sender) |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 763 | { |
| 764 | relinquish_request->handle = handle; |
| 765 | relinquish_request->flags = flags; |
| 766 | relinquish_request->endpoint_count = 1; |
| 767 | relinquish_request->endpoints[0] = sender; |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 768 | return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_id_t); |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | uint32_t ffa_memory_retrieve_request_init( |
| 772 | struct ffa_memory_region *memory_region, ffa_memory_handle_t handle, |
Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 773 | ffa_id_t sender, struct ffa_memory_access receivers[], |
| 774 | uint32_t receiver_count, uint32_t tag, ffa_memory_region_flags_t flags, |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 775 | enum ffa_memory_type type, enum ffa_memory_cacheability cacheability, |
| 776 | enum ffa_memory_shareability shareability); |
| 777 | |
Karl Meakin | 3d879b8 | 2023-06-16 10:32:08 +0100 | [diff] [blame] | 778 | void ffa_hypervisor_retrieve_request_init(struct ffa_memory_region *region, |
| 779 | ffa_memory_handle_t handle); |
| 780 | |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 781 | uint32_t ffa_memory_region_init( |
| 782 | struct ffa_memory_region *memory_region, size_t memory_region_max_size, |
Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 783 | ffa_id_t sender, struct ffa_memory_access receivers[], |
| 784 | uint32_t receiver_count, |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 785 | const struct ffa_memory_region_constituent constituents[], |
| 786 | uint32_t constituent_count, uint32_t tag, |
Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 787 | ffa_memory_region_flags_t flags, enum ffa_memory_type type, |
| 788 | enum ffa_memory_cacheability cacheability, |
J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 789 | enum ffa_memory_shareability shareability, uint32_t *total_length, |
| 790 | uint32_t *fragment_length); |
| 791 | |
Karl Meakin | 0d4f5ff | 2023-10-13 20:03:16 +0100 | [diff] [blame] | 792 | uint32_t ffa_memory_fragment_init( |
| 793 | struct ffa_memory_region_constituent *fragment, |
| 794 | size_t fragment_max_size, |
| 795 | const struct ffa_memory_region_constituent constituents[], |
| 796 | uint32_t constituent_count, uint32_t *fragment_length); |
| 797 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 798 | static inline ffa_id_t ffa_dir_msg_dest(struct ffa_value val) { |
| 799 | return (ffa_id_t)val.arg1 & U(0xFFFF); |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 802 | static inline ffa_id_t ffa_dir_msg_source(struct ffa_value val) { |
| 803 | return (ffa_id_t)(val.arg1 >> 16U); |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 804 | } |
| 805 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 806 | struct ffa_value ffa_msg_send_direct_req64(ffa_id_t source_id, |
| 807 | ffa_id_t dest_id, uint64_t arg0, |
| 808 | uint64_t arg1, uint64_t arg2, |
| 809 | uint64_t arg3, uint64_t arg4); |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 810 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 811 | struct ffa_value ffa_msg_send_direct_req32(ffa_id_t source_id, |
| 812 | ffa_id_t dest_id, uint32_t arg0, |
| 813 | uint32_t arg1, uint32_t arg2, |
| 814 | uint32_t arg3, uint32_t arg4); |
J-Alves | ecd3074 | 2021-02-19 18:31:06 +0000 | [diff] [blame] | 815 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 816 | struct ffa_value ffa_msg_send_direct_resp64(ffa_id_t source_id, |
| 817 | ffa_id_t dest_id, uint64_t arg0, |
| 818 | uint64_t arg1, uint64_t arg2, |
| 819 | uint64_t arg3, uint64_t arg4); |
J-Alves | ecd3074 | 2021-02-19 18:31:06 +0000 | [diff] [blame] | 820 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 821 | struct ffa_value ffa_msg_send_direct_resp32(ffa_id_t source_id, |
| 822 | ffa_id_t dest_id, uint32_t arg0, |
| 823 | uint32_t arg1, uint32_t arg2, |
| 824 | uint32_t arg3, uint32_t arg4); |
J-Alves | 035b7d0 | 2021-02-11 10:40:35 +0000 | [diff] [blame] | 825 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 826 | struct ffa_value ffa_run(uint32_t dest_id, uint32_t vcpu_id); |
| 827 | struct ffa_value ffa_version(uint32_t input_version); |
| 828 | struct ffa_value ffa_id_get(void); |
| 829 | struct ffa_value ffa_spm_id_get(void); |
| 830 | struct ffa_value ffa_msg_wait(void); |
| 831 | struct ffa_value ffa_error(int32_t error_code); |
| 832 | struct ffa_value ffa_features(uint32_t feature); |
Karl Meakin | 31b8177 | 2023-03-14 15:38:17 +0000 | [diff] [blame] | 833 | struct ffa_value ffa_features_with_input_property(uint32_t feature, |
| 834 | uint32_t param); |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 835 | struct ffa_value ffa_partition_info_get(const struct ffa_uuid uuid); |
J-Alves | 067daca | 2024-04-08 17:31:54 +0100 | [diff] [blame] | 836 | struct ffa_value ffa_rx_release_with_id(ffa_id_t vm_id); |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 837 | struct ffa_value ffa_rx_release(void); |
| 838 | struct ffa_value ffa_rxtx_map(uintptr_t send, uintptr_t recv, uint32_t pages); |
Karl Meakin | bff9b3c | 2024-01-18 16:08:35 +0000 | [diff] [blame] | 839 | struct ffa_value ffa_rxtx_unmap_with_id(uint32_t id); |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 840 | struct ffa_value ffa_rxtx_unmap(void); |
J-Alves | 779fba6 | 2024-04-05 14:14:40 +0100 | [diff] [blame^] | 841 | struct ffa_value ffa_msg_send2(uint32_t flags); |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 842 | struct ffa_value ffa_mem_donate(uint32_t descriptor_length, |
| 843 | uint32_t fragment_length); |
| 844 | struct ffa_value ffa_mem_lend(uint32_t descriptor_length, |
J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 845 | uint32_t fragment_length); |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 846 | struct ffa_value ffa_mem_share(uint32_t descriptor_length, |
| 847 | uint32_t fragment_length); |
| 848 | struct ffa_value ffa_mem_retrieve_req(uint32_t descriptor_length, |
| 849 | uint32_t fragment_length); |
| 850 | struct ffa_value ffa_mem_relinquish(void); |
| 851 | struct ffa_value ffa_mem_reclaim(uint64_t handle, uint32_t flags); |
Karl Meakin | 0d4f5ff | 2023-10-13 20:03:16 +0100 | [diff] [blame] | 852 | struct ffa_value ffa_mem_frag_rx(ffa_memory_handle_t handle, |
| 853 | uint32_t fragment_length); |
| 854 | struct ffa_value ffa_mem_frag_tx(ffa_memory_handle_t handle, |
| 855 | uint32_t fragment_length); |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 856 | struct ffa_value ffa_notification_bitmap_create(ffa_id_t vm_id, |
| 857 | ffa_vcpu_count_t vcpu_count); |
| 858 | struct ffa_value ffa_notification_bitmap_destroy(ffa_id_t vm_id); |
| 859 | struct ffa_value ffa_notification_bind(ffa_id_t sender, ffa_id_t receiver, |
| 860 | uint32_t flags, |
J-Alves | 18c2805 | 2021-03-09 09:58:53 +0000 | [diff] [blame] | 861 | ffa_notification_bitmap_t notifications); |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 862 | struct ffa_value ffa_notification_unbind(ffa_id_t sender, ffa_id_t receiver, |
| 863 | ffa_notification_bitmap_t notifications); |
| 864 | struct ffa_value ffa_notification_set(ffa_id_t sender, ffa_id_t receiver, |
| 865 | uint32_t flags, |
| 866 | ffa_notification_bitmap_t bitmap); |
| 867 | struct ffa_value ffa_notification_get(ffa_id_t receiver, uint32_t vcpu_id, |
| 868 | uint32_t flags); |
| 869 | struct ffa_value ffa_notification_info_get(void); |
Maksims Svecovs | 0b45223 | 2022-05-24 11:30:34 +0100 | [diff] [blame] | 870 | |
| 871 | struct ffa_value ffa_console_log(const char* message, size_t char_count); |
Raghu Krishnamurthy | ab5321a | 2023-04-23 16:14:28 -0700 | [diff] [blame] | 872 | struct ffa_value ffa_partition_info_get_regs(const struct ffa_uuid uuid, |
| 873 | const uint16_t start_index, |
| 874 | const uint16_t tag); |
Karl Meakin | 367ff54 | 2023-11-01 15:05:37 +0000 | [diff] [blame] | 875 | |
Daniel Boulby | a24f23a | 2023-11-15 18:23:40 +0000 | [diff] [blame] | 876 | struct ffa_memory_access ffa_memory_access_init( |
Karl Meakin | 367ff54 | 2023-11-01 15:05:37 +0000 | [diff] [blame] | 877 | ffa_id_t receiver_id, enum ffa_data_access data_access, |
| 878 | enum ffa_instruction_access instruction_access, |
Daniel Boulby | a24f23a | 2023-11-15 18:23:40 +0000 | [diff] [blame] | 879 | ffa_memory_receiver_flags_t flags, |
| 880 | struct ffa_memory_access_impdef *impdef); |
Karl Meakin | 367ff54 | 2023-11-01 15:05:37 +0000 | [diff] [blame] | 881 | |
Karl Meakin | bff9b3c | 2024-01-18 16:08:35 +0000 | [diff] [blame] | 882 | void ffa_endpoint_rxtx_descriptor_init( |
| 883 | struct ffa_endpoint_rxtx_descriptor *desc, ffa_id_t endpoint_id, |
| 884 | void *rx_address, void *tx_address); |
| 885 | |
| 886 | struct ffa_value ffa_rxtx_map_forward( |
| 887 | struct ffa_endpoint_rxtx_descriptor *desc, ffa_id_t endpoint_id, |
| 888 | void *rx_address, void *tx_address); |
| 889 | |
J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 890 | #endif /* __ASSEMBLY__ */ |
| 891 | |
| 892 | #endif /* FFA_HELPERS_H */ |