Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 1 | /* |
J-Alves | 13318e3 | 2021-02-22 17:21:00 +0000 | [diff] [blame] | 2 | * Copyright 2021 The Hafnium Authors. |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 3 | * |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style |
| 5 | * license that can be found in the LICENSE file or at |
| 6 | * https://opensource.org/licenses/BSD-3-Clause. |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include "hf/types.h" |
| 12 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 13 | #define FFA_VERSION_MAJOR 0x1 |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 14 | #define FFA_VERSION_MAJOR_OFFSET 16 |
Daniel Boulby | 6e32c61 | 2021-02-17 15:09:41 +0000 | [diff] [blame] | 15 | #define FFA_VERSION_MAJOR_MASK 0x7FFF |
J-Alves | 3829fc0 | 2021-03-18 12:49:18 +0000 | [diff] [blame^] | 16 | #define FFA_VERSION_MINOR 0x1 |
Daniel Boulby | 6e32c61 | 2021-02-17 15:09:41 +0000 | [diff] [blame] | 17 | #define FFA_VERSION_MINOR_OFFSET 0 |
| 18 | #define FFA_VERSION_MINOR_MASK 0xFFFF |
| 19 | |
| 20 | #define MAKE_FFA_VERSION(major, minor) \ |
| 21 | ((((major)&FFA_VERSION_MAJOR_MASK) << FFA_VERSION_MAJOR_OFFSET) | \ |
| 22 | (((minor)&FFA_VERSION_MINOR_MASK) << FFA_VERSION_MINOR_OFFSET)) |
| 23 | #define FFA_VERSION_COMPILED \ |
| 24 | MAKE_FFA_VERSION(FFA_VERSION_MAJOR, FFA_VERSION_MINOR) |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 25 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 26 | /* clang-format off */ |
| 27 | |
| 28 | #define FFA_LOW_32_ID 0x84000060 |
| 29 | #define FFA_HIGH_32_ID 0x8400007F |
| 30 | #define FFA_LOW_64_ID 0xC4000060 |
Fuad Tabba | da72d14 | 2020-07-30 09:17:05 +0100 | [diff] [blame] | 31 | #define FFA_HIGH_64_ID 0xC400007F |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 32 | |
| 33 | /* FF-A function identifiers. */ |
J-Alves | 3829fc0 | 2021-03-18 12:49:18 +0000 | [diff] [blame^] | 34 | #define FFA_ERROR_32 0x84000060 |
| 35 | #define FFA_SUCCESS_32 0x84000061 |
| 36 | #define FFA_SUCCESS_64 0xC4000061 |
| 37 | #define FFA_INTERRUPT_32 0x84000062 |
| 38 | #define FFA_VERSION_32 0x84000063 |
| 39 | #define FFA_FEATURES_32 0x84000064 |
| 40 | #define FFA_RX_RELEASE_32 0x84000065 |
| 41 | #define FFA_RXTX_MAP_32 0x84000066 |
| 42 | #define FFA_RXTX_MAP_64 0xC4000066 |
| 43 | #define FFA_RXTX_UNMAP_32 0x84000067 |
| 44 | #define FFA_PARTITION_INFO_GET_32 0x84000068 |
| 45 | #define FFA_ID_GET_32 0x84000069 |
| 46 | #define FFA_MSG_POLL_32 0x8400006A /* Legacy FF-A v1.0 */ |
| 47 | #define FFA_MSG_WAIT_32 0x8400006B |
| 48 | #define FFA_YIELD_32 0x8400006C |
| 49 | #define FFA_RUN_32 0x8400006D |
| 50 | #define FFA_MSG_SEND_32 0x8400006E /* Legacy FF-A v1.0 */ |
| 51 | #define FFA_MSG_SEND_DIRECT_REQ_32 0x8400006F |
| 52 | #define FFA_MSG_SEND_DIRECT_REQ_64 0xC400006F |
| 53 | #define FFA_MSG_SEND_DIRECT_RESP_32 0x84000070 |
| 54 | #define FFA_MSG_SEND_DIRECT_RESP_64 0xC4000070 |
| 55 | #define FFA_MEM_DONATE_32 0x84000071 |
| 56 | #define FFA_MEM_LEND_32 0x84000072 |
| 57 | #define FFA_MEM_SHARE_32 0x84000073 |
| 58 | #define FFA_MEM_RETRIEVE_REQ_32 0x84000074 |
| 59 | #define FFA_MEM_RETRIEVE_RESP_32 0x84000075 |
| 60 | #define FFA_MEM_RELINQUISH_32 0x84000076 |
| 61 | #define FFA_MEM_RECLAIM_32 0x84000077 |
| 62 | #define FFA_MEM_FRAG_RX_32 0x8400007A |
| 63 | #define FFA_MEM_FRAG_TX_32 0x8400007B |
| 64 | #define FFA_NORMAL_WORLD_RESUME 0x8400007C |
| 65 | |
| 66 | /* FF-A v1.1 */ |
| 67 | #define FFA_NOTIFICATION_BITMAP_CREATE_32 0x8400007D |
| 68 | #define FFA_NOTIFICATION_BITMAP_DESTROY_32 0x8400007E |
| 69 | #define FFA_NOTIFICATION_BIND_32 0x8400007F |
| 70 | #define FFA_NOTIFICATION_UNBIND_32 0x84000080 |
| 71 | #define FFA_NOTIFICATION_SET_32 0x84000081 |
| 72 | #define FFA_NOTIFICATION_GET_32 0x84000082 |
| 73 | #define FFA_NOTIFICATION_INFO_GET_64 0xC4000083 |
| 74 | #define FFA_RX_ACQUIRE_32 0x84000084 |
| 75 | #define FFA_SPM_ID_GET_32 0x84000085 |
| 76 | #define FFA_MSG_SEND2_32 0x84000086 |
| 77 | #define FFA_SECONDARY_EP_REGISTER_64 0xC4000087 |
| 78 | #define FFA_MEM_PERM_GET_32 0x84000088 |
| 79 | #define FFA_MEM_PERM_SET_32 0x84000089 |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 80 | |
| 81 | /* FF-A error codes. */ |
| 82 | #define FFA_NOT_SUPPORTED INT32_C(-1) |
| 83 | #define FFA_INVALID_PARAMETERS INT32_C(-2) |
| 84 | #define FFA_NO_MEMORY INT32_C(-3) |
| 85 | #define FFA_BUSY INT32_C(-4) |
| 86 | #define FFA_INTERRUPTED INT32_C(-5) |
| 87 | #define FFA_DENIED INT32_C(-6) |
| 88 | #define FFA_RETRY INT32_C(-7) |
| 89 | #define FFA_ABORTED INT32_C(-8) |
| 90 | |
| 91 | /* clang-format on */ |
| 92 | |
| 93 | /* FF-A function specific constants. */ |
| 94 | #define FFA_MSG_RECV_BLOCK 0x1 |
| 95 | #define FFA_MSG_RECV_BLOCK_MASK 0x1 |
| 96 | |
| 97 | #define FFA_MSG_SEND_NOTIFY 0x1 |
| 98 | #define FFA_MSG_SEND_NOTIFY_MASK 0x1 |
| 99 | |
| 100 | #define FFA_MEM_RECLAIM_CLEAR 0x1 |
| 101 | |
| 102 | #define FFA_SLEEP_INDEFINITE 0 |
| 103 | |
| 104 | /** |
| 105 | * For use where the FF-A specification refers explicitly to '4K pages'. Not to |
| 106 | * be confused with PAGE_SIZE, which is the translation granule Hafnium is |
| 107 | * configured to use. |
| 108 | */ |
| 109 | #define FFA_PAGE_SIZE 4096 |
| 110 | |
| 111 | /* The maximum length possible for a single message. */ |
| 112 | #define FFA_MSG_PAYLOAD_MAX HF_MAILBOX_SIZE |
| 113 | |
| 114 | enum ffa_data_access { |
| 115 | FFA_DATA_ACCESS_NOT_SPECIFIED, |
| 116 | FFA_DATA_ACCESS_RO, |
| 117 | FFA_DATA_ACCESS_RW, |
| 118 | FFA_DATA_ACCESS_RESERVED, |
| 119 | }; |
| 120 | |
| 121 | enum ffa_instruction_access { |
| 122 | FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED, |
| 123 | FFA_INSTRUCTION_ACCESS_NX, |
| 124 | FFA_INSTRUCTION_ACCESS_X, |
| 125 | FFA_INSTRUCTION_ACCESS_RESERVED, |
| 126 | }; |
| 127 | |
| 128 | enum ffa_memory_type { |
| 129 | FFA_MEMORY_NOT_SPECIFIED_MEM, |
| 130 | FFA_MEMORY_DEVICE_MEM, |
| 131 | FFA_MEMORY_NORMAL_MEM, |
| 132 | }; |
| 133 | |
| 134 | enum ffa_memory_cacheability { |
| 135 | FFA_MEMORY_CACHE_RESERVED = 0x0, |
| 136 | FFA_MEMORY_CACHE_NON_CACHEABLE = 0x1, |
| 137 | FFA_MEMORY_CACHE_RESERVED_1 = 0x2, |
| 138 | FFA_MEMORY_CACHE_WRITE_BACK = 0x3, |
| 139 | FFA_MEMORY_DEV_NGNRNE = 0x0, |
| 140 | FFA_MEMORY_DEV_NGNRE = 0x1, |
| 141 | FFA_MEMORY_DEV_NGRE = 0x2, |
| 142 | FFA_MEMORY_DEV_GRE = 0x3, |
| 143 | }; |
| 144 | |
| 145 | enum ffa_memory_shareability { |
| 146 | FFA_MEMORY_SHARE_NON_SHAREABLE, |
| 147 | FFA_MEMORY_SHARE_RESERVED, |
| 148 | FFA_MEMORY_OUTER_SHAREABLE, |
| 149 | FFA_MEMORY_INNER_SHAREABLE, |
| 150 | }; |
| 151 | |
| 152 | typedef uint8_t ffa_memory_access_permissions_t; |
| 153 | |
| 154 | /** |
| 155 | * This corresponds to table 44 of the FF-A 1.0 EAC specification, "Memory |
| 156 | * region attributes descriptor". |
| 157 | */ |
| 158 | typedef uint8_t ffa_memory_attributes_t; |
| 159 | |
| 160 | #define FFA_DATA_ACCESS_OFFSET (0x0U) |
| 161 | #define FFA_DATA_ACCESS_MASK ((0x3U) << FFA_DATA_ACCESS_OFFSET) |
| 162 | |
| 163 | #define FFA_INSTRUCTION_ACCESS_OFFSET (0x2U) |
| 164 | #define FFA_INSTRUCTION_ACCESS_MASK ((0x3U) << FFA_INSTRUCTION_ACCESS_OFFSET) |
| 165 | |
| 166 | #define FFA_MEMORY_TYPE_OFFSET (0x4U) |
| 167 | #define FFA_MEMORY_TYPE_MASK ((0x3U) << FFA_MEMORY_TYPE_OFFSET) |
| 168 | |
| 169 | #define FFA_MEMORY_CACHEABILITY_OFFSET (0x2U) |
| 170 | #define FFA_MEMORY_CACHEABILITY_MASK ((0x3U) << FFA_MEMORY_CACHEABILITY_OFFSET) |
| 171 | |
| 172 | #define FFA_MEMORY_SHAREABILITY_OFFSET (0x0U) |
| 173 | #define FFA_MEMORY_SHAREABILITY_MASK ((0x3U) << FFA_MEMORY_SHAREABILITY_OFFSET) |
| 174 | |
| 175 | #define ATTR_FUNCTION_SET(name, container_type, offset, mask) \ |
| 176 | static inline void ffa_set_##name##_attr(container_type *attr, \ |
| 177 | const enum ffa_##name perm) \ |
| 178 | { \ |
| 179 | *attr = (*attr & ~(mask)) | ((perm << offset) & mask); \ |
| 180 | } |
| 181 | |
| 182 | #define ATTR_FUNCTION_GET(name, container_type, offset, mask) \ |
| 183 | static inline enum ffa_##name ffa_get_##name##_attr( \ |
| 184 | container_type attr) \ |
| 185 | { \ |
| 186 | return (enum ffa_##name)((attr & mask) >> offset); \ |
| 187 | } |
| 188 | |
| 189 | ATTR_FUNCTION_SET(data_access, ffa_memory_access_permissions_t, |
| 190 | FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK) |
| 191 | ATTR_FUNCTION_GET(data_access, ffa_memory_access_permissions_t, |
| 192 | FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK) |
| 193 | |
| 194 | ATTR_FUNCTION_SET(instruction_access, ffa_memory_access_permissions_t, |
| 195 | FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK) |
| 196 | ATTR_FUNCTION_GET(instruction_access, ffa_memory_access_permissions_t, |
| 197 | FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK) |
| 198 | |
| 199 | ATTR_FUNCTION_SET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET, |
| 200 | FFA_MEMORY_TYPE_MASK) |
| 201 | ATTR_FUNCTION_GET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET, |
| 202 | FFA_MEMORY_TYPE_MASK) |
| 203 | |
| 204 | ATTR_FUNCTION_SET(memory_cacheability, ffa_memory_attributes_t, |
| 205 | FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK) |
| 206 | ATTR_FUNCTION_GET(memory_cacheability, ffa_memory_attributes_t, |
| 207 | FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK) |
| 208 | |
| 209 | ATTR_FUNCTION_SET(memory_shareability, ffa_memory_attributes_t, |
| 210 | FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK) |
| 211 | ATTR_FUNCTION_GET(memory_shareability, ffa_memory_attributes_t, |
| 212 | FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK) |
| 213 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 214 | /** |
| 215 | * A globally-unique ID assigned by the hypervisor for a region of memory being |
| 216 | * sent between VMs. |
| 217 | */ |
| 218 | typedef uint64_t ffa_memory_handle_t; |
| 219 | |
J-Alves | 917d2f2 | 2020-10-30 18:39:30 +0000 | [diff] [blame] | 220 | #define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \ |
| 221 | ((ffa_memory_handle_t)(UINT64_C(1) << 63)) |
| 222 | #define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR \ |
| 223 | ((ffa_memory_handle_t)(UINT64_C(1) << 63)) |
| 224 | |
| 225 | #define FFA_MEMORY_HANDLE_ALLOCATOR_SPMC (UINT64_C(0) << 63) |
| 226 | #define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0)) |
| 227 | |
| 228 | /** The ID of a VM. These are assigned sequentially starting with an offset. */ |
| 229 | typedef uint16_t ffa_vm_id_t; |
| 230 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 231 | /** |
| 232 | * A count of VMs. This has the same range as the VM IDs but we give it a |
| 233 | * different name to make the different semantics clear. |
| 234 | */ |
| 235 | typedef ffa_vm_id_t ffa_vm_count_t; |
| 236 | |
| 237 | /** The index of a vCPU within a particular VM. */ |
| 238 | typedef uint16_t ffa_vcpu_index_t; |
| 239 | |
| 240 | /** |
| 241 | * A count of vCPUs. This has the same range as the vCPU indices but we give it |
| 242 | * a different name to make the different semantics clear. |
| 243 | */ |
| 244 | typedef ffa_vcpu_index_t ffa_vcpu_count_t; |
| 245 | |
| 246 | /** Parameter and return type of FF-A functions. */ |
| 247 | struct ffa_value { |
| 248 | uint64_t func; |
| 249 | uint64_t arg1; |
| 250 | uint64_t arg2; |
| 251 | uint64_t arg3; |
| 252 | uint64_t arg4; |
| 253 | uint64_t arg5; |
| 254 | uint64_t arg6; |
| 255 | uint64_t arg7; |
| 256 | }; |
| 257 | |
J-Alves | 13318e3 | 2021-02-22 17:21:00 +0000 | [diff] [blame] | 258 | static inline int32_t ffa_error_code(struct ffa_value val) |
| 259 | { |
| 260 | return (int32_t)val.arg2; |
| 261 | } |
| 262 | |
J-Alves | d6f4e14 | 2021-03-05 13:33:59 +0000 | [diff] [blame] | 263 | static inline ffa_vm_id_t ffa_sender(struct ffa_value args) |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 264 | { |
| 265 | return (args.arg1 >> 16) & 0xffff; |
| 266 | } |
| 267 | |
J-Alves | d6f4e14 | 2021-03-05 13:33:59 +0000 | [diff] [blame] | 268 | static inline ffa_vm_id_t ffa_receiver(struct ffa_value args) |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 269 | { |
| 270 | return args.arg1 & 0xffff; |
| 271 | } |
| 272 | |
| 273 | static inline uint32_t ffa_msg_send_size(struct ffa_value args) |
| 274 | { |
| 275 | return args.arg3; |
| 276 | } |
| 277 | |
| 278 | static inline uint32_t ffa_msg_send_attributes(struct ffa_value args) |
| 279 | { |
| 280 | return args.arg4; |
| 281 | } |
| 282 | |
Andrew Walbran | 1bbe940 | 2020-04-30 16:47:13 +0100 | [diff] [blame] | 283 | static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t a1, uint32_t a2) |
| 284 | { |
| 285 | return (uint64_t)a1 | (uint64_t)a2 << 32; |
| 286 | } |
| 287 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 288 | static inline ffa_memory_handle_t ffa_mem_success_handle(struct ffa_value args) |
| 289 | { |
Andrew Walbran | 1bbe940 | 2020-04-30 16:47:13 +0100 | [diff] [blame] | 290 | return ffa_assemble_handle(args.arg2, args.arg3); |
| 291 | } |
| 292 | |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 293 | static inline ffa_memory_handle_t ffa_frag_handle(struct ffa_value args) |
| 294 | { |
| 295 | return ffa_assemble_handle(args.arg1, args.arg2); |
| 296 | } |
| 297 | |
Andrew Walbran | 1bbe940 | 2020-04-30 16:47:13 +0100 | [diff] [blame] | 298 | static inline struct ffa_value ffa_mem_success(ffa_memory_handle_t handle) |
| 299 | { |
| 300 | return (struct ffa_value){.func = FFA_SUCCESS_32, |
| 301 | .arg2 = (uint32_t)handle, |
| 302 | .arg3 = (uint32_t)(handle >> 32)}; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | static inline ffa_vm_id_t ffa_vm_id(struct ffa_value args) |
| 306 | { |
| 307 | return (args.arg1 >> 16) & 0xffff; |
| 308 | } |
| 309 | |
| 310 | static inline ffa_vcpu_index_t ffa_vcpu_index(struct ffa_value args) |
| 311 | { |
| 312 | return args.arg1 & 0xffff; |
| 313 | } |
| 314 | |
| 315 | static inline uint64_t ffa_vm_vcpu(ffa_vm_id_t vm_id, |
| 316 | ffa_vcpu_index_t vcpu_index) |
| 317 | { |
| 318 | return ((uint32_t)vm_id << 16) | vcpu_index; |
| 319 | } |
| 320 | |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 321 | static inline ffa_vm_id_t ffa_frag_sender(struct ffa_value args) |
| 322 | { |
| 323 | return (args.arg4 >> 16) & 0xffff; |
| 324 | } |
| 325 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 326 | /** |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 327 | * Holds the UUID in a struct that is mappable directly to the SMCC calling |
| 328 | * convention, which is used for FF-A calls. |
| 329 | * |
| 330 | * Refer to table 84 of the FF-A 1.0 EAC specification as well as section 5.3 |
| 331 | * of the SMCC Spec 1.2. |
| 332 | */ |
| 333 | struct ffa_uuid { |
| 334 | uint32_t uuid[4]; |
| 335 | }; |
| 336 | |
| 337 | static inline void ffa_uuid_init(uint32_t w0, uint32_t w1, uint32_t w2, |
| 338 | uint32_t w3, struct ffa_uuid *uuid) |
| 339 | { |
| 340 | uuid->uuid[0] = w0; |
| 341 | uuid->uuid[1] = w1; |
| 342 | uuid->uuid[2] = w2; |
| 343 | uuid->uuid[3] = w3; |
| 344 | } |
| 345 | |
| 346 | static inline bool ffa_uuid_equal(const struct ffa_uuid *uuid1, |
| 347 | const struct ffa_uuid *uuid2) |
| 348 | { |
| 349 | return (uuid1->uuid[0] == uuid2->uuid[0]) && |
| 350 | (uuid1->uuid[1] == uuid2->uuid[1]) && |
| 351 | (uuid1->uuid[2] == uuid2->uuid[2]) && |
| 352 | (uuid1->uuid[3] == uuid2->uuid[3]); |
| 353 | } |
| 354 | |
| 355 | static inline bool ffa_uuid_is_null(const struct ffa_uuid *uuid) |
| 356 | { |
| 357 | return (uuid->uuid[0] == 0) && (uuid->uuid[1] == 0) && |
| 358 | (uuid->uuid[2] == 0) && (uuid->uuid[3] == 0); |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * Flags to determine the partition properties, as required by |
| 363 | * FFA_PARTITION_INFO_GET. |
| 364 | * |
| 365 | * The values of the flags are specified in table 82 of the FF-A 1.0 EAC |
| 366 | * specification, "Partition information descriptor, partition properties". |
| 367 | */ |
| 368 | typedef uint32_t ffa_partition_properties_t; |
| 369 | |
| 370 | /** Partition property: partition supports receipt of direct requests. */ |
Maksims Svecovs | b596eab | 2021-04-27 00:52:27 +0100 | [diff] [blame] | 371 | #define FFA_PARTITION_DIRECT_REQ_RECV 0x1 |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 372 | |
| 373 | /** Partition property: partition can send direct requests. */ |
Maksims Svecovs | b596eab | 2021-04-27 00:52:27 +0100 | [diff] [blame] | 374 | #define FFA_PARTITION_DIRECT_REQ_SEND 0x2 |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 375 | |
| 376 | /** Partition property: partition can send and receive indirect messages. */ |
| 377 | #define FFA_PARTITION_INDIRECT_MSG 0x4 |
| 378 | |
Maksims Svecovs | b596eab | 2021-04-27 00:52:27 +0100 | [diff] [blame] | 379 | /** Partition property: supports managed exit. */ |
| 380 | #define FFA_PARTITION_MANAGED_EXIT 0x8 |
| 381 | |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 382 | /** |
| 383 | * Holds information returned for each partition by the FFA_PARTITION_INFO_GET |
| 384 | * interface. |
| 385 | * This corresponds to table 82 of the FF-A 1.0 EAC specification, "Partition |
| 386 | * information descriptor". |
| 387 | */ |
| 388 | struct ffa_partition_info { |
| 389 | ffa_vm_id_t vm_id; |
| 390 | ffa_vcpu_count_t vcpu_count; |
| 391 | ffa_partition_properties_t properties; |
| 392 | }; |
| 393 | |
| 394 | /** |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 395 | * A set of contiguous pages which is part of a memory region. This corresponds |
| 396 | * to table 40 of the FF-A 1.0 EAC specification, "Constituent memory region |
| 397 | * descriptor". |
| 398 | */ |
| 399 | struct ffa_memory_region_constituent { |
| 400 | /** |
| 401 | * The base IPA of the constituent memory region, aligned to 4 kiB page |
| 402 | * size granularity. |
| 403 | */ |
| 404 | uint64_t address; |
| 405 | /** The number of 4 kiB pages in the constituent memory region. */ |
| 406 | uint32_t page_count; |
| 407 | /** Reserved field, must be 0. */ |
| 408 | uint32_t reserved; |
| 409 | }; |
| 410 | |
| 411 | /** |
| 412 | * A set of pages comprising a memory region. This corresponds to table 39 of |
| 413 | * the FF-A 1.0 EAC specification, "Composite memory region descriptor". |
| 414 | */ |
| 415 | struct ffa_composite_memory_region { |
| 416 | /** |
| 417 | * The total number of 4 kiB pages included in this memory region. This |
| 418 | * must be equal to the sum of page counts specified in each |
| 419 | * `ffa_memory_region_constituent`. |
| 420 | */ |
| 421 | uint32_t page_count; |
| 422 | /** |
| 423 | * The number of constituents (`ffa_memory_region_constituent`) |
| 424 | * included in this memory region range. |
| 425 | */ |
| 426 | uint32_t constituent_count; |
| 427 | /** Reserved field, must be 0. */ |
| 428 | uint64_t reserved_0; |
| 429 | /** An array of `constituent_count` memory region constituents. */ |
| 430 | struct ffa_memory_region_constituent constituents[]; |
| 431 | }; |
| 432 | |
| 433 | /** Flags to indicate properties of receivers during memory region retrieval. */ |
| 434 | typedef uint8_t ffa_memory_receiver_flags_t; |
| 435 | |
| 436 | /** |
| 437 | * This corresponds to table 41 of the FF-A 1.0 EAC specification, "Memory |
| 438 | * access permissions descriptor". |
| 439 | */ |
| 440 | struct ffa_memory_region_attributes { |
| 441 | /** The ID of the VM to which the memory is being given or shared. */ |
| 442 | ffa_vm_id_t receiver; |
| 443 | /** |
| 444 | * The permissions with which the memory region should be mapped in the |
| 445 | * receiver's page table. |
| 446 | */ |
| 447 | ffa_memory_access_permissions_t permissions; |
| 448 | /** |
| 449 | * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP |
| 450 | * for memory regions with multiple borrowers. |
| 451 | */ |
| 452 | ffa_memory_receiver_flags_t flags; |
| 453 | }; |
| 454 | |
| 455 | /** Flags to control the behaviour of a memory sharing transaction. */ |
| 456 | typedef uint32_t ffa_memory_region_flags_t; |
| 457 | |
| 458 | /** |
| 459 | * Clear memory region contents after unmapping it from the sender and before |
| 460 | * mapping it for any receiver. |
| 461 | */ |
| 462 | #define FFA_MEMORY_REGION_FLAG_CLEAR 0x1 |
| 463 | |
| 464 | /** |
| 465 | * Whether the hypervisor may time slice the memory sharing or retrieval |
| 466 | * operation. |
| 467 | */ |
| 468 | #define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2 |
| 469 | |
| 470 | /** |
| 471 | * Whether the hypervisor should clear the memory region after the receiver |
| 472 | * relinquishes it or is aborted. |
| 473 | */ |
| 474 | #define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4 |
| 475 | |
| 476 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3) |
| 477 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3) |
| 478 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3) |
| 479 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3) |
| 480 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3) |
| 481 | |
| 482 | /** |
| 483 | * This corresponds to table 42 of the FF-A 1.0 EAC specification, "Endpoint |
| 484 | * memory access descriptor". |
| 485 | */ |
| 486 | struct ffa_memory_access { |
| 487 | struct ffa_memory_region_attributes receiver_permissions; |
| 488 | /** |
| 489 | * Offset in bytes from the start of the outer `ffa_memory_region` to |
| 490 | * an `ffa_composite_memory_region` struct. |
| 491 | */ |
| 492 | uint32_t composite_memory_region_offset; |
| 493 | uint64_t reserved_0; |
| 494 | }; |
| 495 | |
| 496 | /** |
| 497 | * Information about a set of pages which are being shared. This corresponds to |
| 498 | * table 45 of the FF-A 1.0 EAC specification, "Lend, donate or share memory |
| 499 | * transaction descriptor". Note that it is also used for retrieve requests and |
| 500 | * responses. |
| 501 | */ |
| 502 | struct ffa_memory_region { |
| 503 | /** |
| 504 | * The ID of the VM which originally sent the memory region, i.e. the |
| 505 | * owner. |
| 506 | */ |
| 507 | ffa_vm_id_t sender; |
| 508 | ffa_memory_attributes_t attributes; |
| 509 | /** Reserved field, must be 0. */ |
| 510 | uint8_t reserved_0; |
| 511 | /** Flags to control behaviour of the transaction. */ |
| 512 | ffa_memory_region_flags_t flags; |
| 513 | ffa_memory_handle_t handle; |
| 514 | /** |
| 515 | * An implementation defined value associated with the receiver and the |
| 516 | * memory region. |
| 517 | */ |
| 518 | uint64_t tag; |
| 519 | /** Reserved field, must be 0. */ |
| 520 | uint32_t reserved_1; |
| 521 | /** |
| 522 | * The number of `ffa_memory_access` entries included in this |
| 523 | * transaction. |
| 524 | */ |
| 525 | uint32_t receiver_count; |
| 526 | /** |
| 527 | * An array of `attribute_count` endpoint memory access descriptors. |
| 528 | * Each one specifies a memory region offset, an endpoint and the |
| 529 | * attributes with which this memory region should be mapped in that |
| 530 | * endpoint's page table. |
| 531 | */ |
| 532 | struct ffa_memory_access receivers[]; |
| 533 | }; |
| 534 | |
| 535 | /** |
| 536 | * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table |
| 537 | * 150 of the FF-A 1.0 EAC specification, "Descriptor to relinquish a memory |
| 538 | * region". |
| 539 | */ |
| 540 | struct ffa_mem_relinquish { |
| 541 | ffa_memory_handle_t handle; |
| 542 | ffa_memory_region_flags_t flags; |
| 543 | uint32_t endpoint_count; |
| 544 | ffa_vm_id_t endpoints[]; |
| 545 | }; |
| 546 | |
| 547 | /** |
| 548 | * Gets the `ffa_composite_memory_region` for the given receiver from an |
| 549 | * `ffa_memory_region`, or NULL if it is not valid. |
| 550 | */ |
| 551 | static inline struct ffa_composite_memory_region * |
| 552 | ffa_memory_region_get_composite(struct ffa_memory_region *memory_region, |
| 553 | uint32_t receiver_index) |
| 554 | { |
| 555 | uint32_t offset = memory_region->receivers[receiver_index] |
| 556 | .composite_memory_region_offset; |
| 557 | |
| 558 | if (offset == 0) { |
| 559 | return NULL; |
| 560 | } |
| 561 | |
| 562 | return (struct ffa_composite_memory_region *)((uint8_t *)memory_region + |
| 563 | offset); |
| 564 | } |
| 565 | |
| 566 | static inline uint32_t ffa_mem_relinquish_init( |
| 567 | struct ffa_mem_relinquish *relinquish_request, |
| 568 | ffa_memory_handle_t handle, ffa_memory_region_flags_t flags, |
| 569 | ffa_vm_id_t sender) |
| 570 | { |
| 571 | relinquish_request->handle = handle; |
| 572 | relinquish_request->flags = flags; |
| 573 | relinquish_request->endpoint_count = 1; |
| 574 | relinquish_request->endpoints[0] = sender; |
| 575 | return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_vm_id_t); |
| 576 | } |
| 577 | |
| 578 | uint32_t ffa_memory_region_init( |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 579 | struct ffa_memory_region *memory_region, size_t memory_region_max_size, |
| 580 | ffa_vm_id_t sender, ffa_vm_id_t receiver, |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 581 | const struct ffa_memory_region_constituent constituents[], |
| 582 | uint32_t constituent_count, uint32_t tag, |
| 583 | ffa_memory_region_flags_t flags, enum ffa_data_access data_access, |
| 584 | enum ffa_instruction_access instruction_access, |
| 585 | enum ffa_memory_type type, enum ffa_memory_cacheability cacheability, |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 586 | enum ffa_memory_shareability shareability, uint32_t *fragment_length, |
| 587 | uint32_t *total_length); |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 588 | uint32_t ffa_memory_retrieve_request_init( |
| 589 | struct ffa_memory_region *memory_region, ffa_memory_handle_t handle, |
| 590 | ffa_vm_id_t sender, ffa_vm_id_t receiver, uint32_t tag, |
| 591 | ffa_memory_region_flags_t flags, enum ffa_data_access data_access, |
| 592 | enum ffa_instruction_access instruction_access, |
| 593 | enum ffa_memory_type type, enum ffa_memory_cacheability cacheability, |
| 594 | enum ffa_memory_shareability shareability); |
| 595 | uint32_t ffa_memory_lender_retrieve_request_init( |
| 596 | struct ffa_memory_region *memory_region, ffa_memory_handle_t handle, |
| 597 | ffa_vm_id_t sender); |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 598 | bool ffa_retrieved_memory_region_init( |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 599 | struct ffa_memory_region *response, size_t response_max_size, |
| 600 | ffa_vm_id_t sender, ffa_memory_attributes_t attributes, |
| 601 | ffa_memory_region_flags_t flags, ffa_memory_handle_t handle, |
| 602 | ffa_vm_id_t receiver, ffa_memory_access_permissions_t permissions, |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 603 | uint32_t page_count, uint32_t total_constituent_count, |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 604 | const struct ffa_memory_region_constituent constituents[], |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 605 | uint32_t fragment_constituent_count, uint32_t *total_length, |
| 606 | uint32_t *fragment_length); |
| 607 | uint32_t ffa_memory_fragment_init( |
| 608 | struct ffa_memory_region_constituent *fragment, |
| 609 | size_t fragment_max_size, |
| 610 | const struct ffa_memory_region_constituent constituents[], |
| 611 | uint32_t constituent_count, uint32_t *fragment_length); |