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