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 |
Raghu Krishnamurthy | ea6d25f | 2021-09-14 15:27:06 -0700 | [diff] [blame] | 80 | #define FFA_MEM_PERM_GET_64 0xC4000088 |
| 81 | #define FFA_MEM_PERM_SET_64 0xC4000089 |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 82 | |
| 83 | /* FF-A error codes. */ |
| 84 | #define FFA_NOT_SUPPORTED INT32_C(-1) |
| 85 | #define FFA_INVALID_PARAMETERS INT32_C(-2) |
| 86 | #define FFA_NO_MEMORY INT32_C(-3) |
| 87 | #define FFA_BUSY INT32_C(-4) |
| 88 | #define FFA_INTERRUPTED INT32_C(-5) |
| 89 | #define FFA_DENIED INT32_C(-6) |
| 90 | #define FFA_RETRY INT32_C(-7) |
| 91 | #define FFA_ABORTED INT32_C(-8) |
J-Alves | c8e8a22 | 2021-06-08 17:33:52 +0100 | [diff] [blame] | 92 | #define FFA_NO_DATA INT32_C(-9) |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 93 | |
| 94 | /* clang-format on */ |
| 95 | |
J-Alves | 6f72ca8 | 2021-11-01 12:34:58 +0000 | [diff] [blame] | 96 | /** |
| 97 | * FF-A Feature ID, to be used with interface FFA_FEATURES. |
| 98 | * As defined in the FF-A v1.1 Beta specification, table 13.10, in section |
| 99 | * 13.2. |
| 100 | */ |
| 101 | |
| 102 | #define FFA_FEATURES_FUNC_ID_MASK UINT32_C(0x1 << 31) |
| 103 | #define FFA_FEATURES_FEATURE_ID_MASK UINT32_C(0x7F) |
| 104 | |
| 105 | /* Query interrupt ID of Notification Pending Interrupt. */ |
| 106 | #define FFA_FEATURE_NPI 0x1U |
| 107 | |
| 108 | /* Query interrupt ID of Schedule Receiver Interrupt. */ |
| 109 | #define FFA_FEATURE_SRI 0x2U |
| 110 | |
| 111 | /* Query interrupt ID of the Managed Exit Interrupt. */ |
| 112 | #define FFA_FEATURE_MEI 0x3U |
| 113 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 114 | /* FF-A function specific constants. */ |
| 115 | #define FFA_MSG_RECV_BLOCK 0x1 |
| 116 | #define FFA_MSG_RECV_BLOCK_MASK 0x1 |
| 117 | |
| 118 | #define FFA_MSG_SEND_NOTIFY 0x1 |
| 119 | #define FFA_MSG_SEND_NOTIFY_MASK 0x1 |
| 120 | |
| 121 | #define FFA_MEM_RECLAIM_CLEAR 0x1 |
| 122 | |
| 123 | #define FFA_SLEEP_INDEFINITE 0 |
| 124 | |
Raghu Krishnamurthy | ea6d25f | 2021-09-14 15:27:06 -0700 | [diff] [blame] | 125 | #define FFA_MEM_PERM_RO UINT32_C(0x7) |
| 126 | #define FFA_MEM_PERM_RW UINT32_C(0x5) |
| 127 | #define FFA_MEM_PERM_RX UINT32_C(0x3) |
| 128 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 129 | /** |
| 130 | * For use where the FF-A specification refers explicitly to '4K pages'. Not to |
| 131 | * be confused with PAGE_SIZE, which is the translation granule Hafnium is |
| 132 | * configured to use. |
| 133 | */ |
| 134 | #define FFA_PAGE_SIZE 4096 |
| 135 | |
| 136 | /* The maximum length possible for a single message. */ |
| 137 | #define FFA_MSG_PAYLOAD_MAX HF_MAILBOX_SIZE |
| 138 | |
| 139 | enum ffa_data_access { |
| 140 | FFA_DATA_ACCESS_NOT_SPECIFIED, |
| 141 | FFA_DATA_ACCESS_RO, |
| 142 | FFA_DATA_ACCESS_RW, |
| 143 | FFA_DATA_ACCESS_RESERVED, |
| 144 | }; |
| 145 | |
| 146 | enum ffa_instruction_access { |
| 147 | FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED, |
| 148 | FFA_INSTRUCTION_ACCESS_NX, |
| 149 | FFA_INSTRUCTION_ACCESS_X, |
| 150 | FFA_INSTRUCTION_ACCESS_RESERVED, |
| 151 | }; |
| 152 | |
| 153 | enum ffa_memory_type { |
| 154 | FFA_MEMORY_NOT_SPECIFIED_MEM, |
| 155 | FFA_MEMORY_DEVICE_MEM, |
| 156 | FFA_MEMORY_NORMAL_MEM, |
| 157 | }; |
| 158 | |
| 159 | enum ffa_memory_cacheability { |
| 160 | FFA_MEMORY_CACHE_RESERVED = 0x0, |
| 161 | FFA_MEMORY_CACHE_NON_CACHEABLE = 0x1, |
| 162 | FFA_MEMORY_CACHE_RESERVED_1 = 0x2, |
| 163 | FFA_MEMORY_CACHE_WRITE_BACK = 0x3, |
| 164 | FFA_MEMORY_DEV_NGNRNE = 0x0, |
| 165 | FFA_MEMORY_DEV_NGNRE = 0x1, |
| 166 | FFA_MEMORY_DEV_NGRE = 0x2, |
| 167 | FFA_MEMORY_DEV_GRE = 0x3, |
| 168 | }; |
| 169 | |
| 170 | enum ffa_memory_shareability { |
| 171 | FFA_MEMORY_SHARE_NON_SHAREABLE, |
| 172 | FFA_MEMORY_SHARE_RESERVED, |
| 173 | FFA_MEMORY_OUTER_SHAREABLE, |
| 174 | FFA_MEMORY_INNER_SHAREABLE, |
| 175 | }; |
| 176 | |
| 177 | typedef uint8_t ffa_memory_access_permissions_t; |
| 178 | |
| 179 | /** |
| 180 | * This corresponds to table 44 of the FF-A 1.0 EAC specification, "Memory |
| 181 | * region attributes descriptor". |
| 182 | */ |
| 183 | typedef uint8_t ffa_memory_attributes_t; |
| 184 | |
| 185 | #define FFA_DATA_ACCESS_OFFSET (0x0U) |
| 186 | #define FFA_DATA_ACCESS_MASK ((0x3U) << FFA_DATA_ACCESS_OFFSET) |
| 187 | |
| 188 | #define FFA_INSTRUCTION_ACCESS_OFFSET (0x2U) |
| 189 | #define FFA_INSTRUCTION_ACCESS_MASK ((0x3U) << FFA_INSTRUCTION_ACCESS_OFFSET) |
| 190 | |
| 191 | #define FFA_MEMORY_TYPE_OFFSET (0x4U) |
| 192 | #define FFA_MEMORY_TYPE_MASK ((0x3U) << FFA_MEMORY_TYPE_OFFSET) |
| 193 | |
| 194 | #define FFA_MEMORY_CACHEABILITY_OFFSET (0x2U) |
| 195 | #define FFA_MEMORY_CACHEABILITY_MASK ((0x3U) << FFA_MEMORY_CACHEABILITY_OFFSET) |
| 196 | |
| 197 | #define FFA_MEMORY_SHAREABILITY_OFFSET (0x0U) |
| 198 | #define FFA_MEMORY_SHAREABILITY_MASK ((0x3U) << FFA_MEMORY_SHAREABILITY_OFFSET) |
| 199 | |
| 200 | #define ATTR_FUNCTION_SET(name, container_type, offset, mask) \ |
| 201 | static inline void ffa_set_##name##_attr(container_type *attr, \ |
| 202 | const enum ffa_##name perm) \ |
| 203 | { \ |
| 204 | *attr = (*attr & ~(mask)) | ((perm << offset) & mask); \ |
| 205 | } |
| 206 | |
| 207 | #define ATTR_FUNCTION_GET(name, container_type, offset, mask) \ |
| 208 | static inline enum ffa_##name ffa_get_##name##_attr( \ |
| 209 | container_type attr) \ |
| 210 | { \ |
| 211 | return (enum ffa_##name)((attr & mask) >> offset); \ |
| 212 | } |
| 213 | |
| 214 | ATTR_FUNCTION_SET(data_access, ffa_memory_access_permissions_t, |
| 215 | FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK) |
| 216 | ATTR_FUNCTION_GET(data_access, ffa_memory_access_permissions_t, |
| 217 | FFA_DATA_ACCESS_OFFSET, FFA_DATA_ACCESS_MASK) |
| 218 | |
| 219 | ATTR_FUNCTION_SET(instruction_access, ffa_memory_access_permissions_t, |
| 220 | FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK) |
| 221 | ATTR_FUNCTION_GET(instruction_access, ffa_memory_access_permissions_t, |
| 222 | FFA_INSTRUCTION_ACCESS_OFFSET, FFA_INSTRUCTION_ACCESS_MASK) |
| 223 | |
| 224 | ATTR_FUNCTION_SET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET, |
| 225 | FFA_MEMORY_TYPE_MASK) |
| 226 | ATTR_FUNCTION_GET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET, |
| 227 | FFA_MEMORY_TYPE_MASK) |
| 228 | |
| 229 | ATTR_FUNCTION_SET(memory_cacheability, ffa_memory_attributes_t, |
| 230 | FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK) |
| 231 | ATTR_FUNCTION_GET(memory_cacheability, ffa_memory_attributes_t, |
| 232 | FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK) |
| 233 | |
| 234 | ATTR_FUNCTION_SET(memory_shareability, ffa_memory_attributes_t, |
| 235 | FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK) |
| 236 | ATTR_FUNCTION_GET(memory_shareability, ffa_memory_attributes_t, |
| 237 | FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK) |
| 238 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 239 | /** |
| 240 | * A globally-unique ID assigned by the hypervisor for a region of memory being |
| 241 | * sent between VMs. |
| 242 | */ |
| 243 | typedef uint64_t ffa_memory_handle_t; |
| 244 | |
J-Alves | 917d2f2 | 2020-10-30 18:39:30 +0000 | [diff] [blame] | 245 | #define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \ |
| 246 | ((ffa_memory_handle_t)(UINT64_C(1) << 63)) |
| 247 | #define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR \ |
| 248 | ((ffa_memory_handle_t)(UINT64_C(1) << 63)) |
| 249 | |
| 250 | #define FFA_MEMORY_HANDLE_ALLOCATOR_SPMC (UINT64_C(0) << 63) |
| 251 | #define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0)) |
| 252 | |
| 253 | /** The ID of a VM. These are assigned sequentially starting with an offset. */ |
| 254 | typedef uint16_t ffa_vm_id_t; |
| 255 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 256 | /** |
| 257 | * A count of VMs. This has the same range as the VM IDs but we give it a |
| 258 | * different name to make the different semantics clear. |
| 259 | */ |
| 260 | typedef ffa_vm_id_t ffa_vm_count_t; |
| 261 | |
| 262 | /** The index of a vCPU within a particular VM. */ |
| 263 | typedef uint16_t ffa_vcpu_index_t; |
| 264 | |
| 265 | /** |
| 266 | * A count of vCPUs. This has the same range as the vCPU indices but we give it |
| 267 | * a different name to make the different semantics clear. |
| 268 | */ |
| 269 | typedef ffa_vcpu_index_t ffa_vcpu_count_t; |
| 270 | |
| 271 | /** Parameter and return type of FF-A functions. */ |
| 272 | struct ffa_value { |
| 273 | uint64_t func; |
| 274 | uint64_t arg1; |
| 275 | uint64_t arg2; |
| 276 | uint64_t arg3; |
| 277 | uint64_t arg4; |
| 278 | uint64_t arg5; |
| 279 | uint64_t arg6; |
| 280 | uint64_t arg7; |
| 281 | }; |
| 282 | |
Olivier Deprez | e562e54 | 2020-06-11 17:31:54 +0200 | [diff] [blame] | 283 | static inline uint32_t ffa_func_id(struct ffa_value args) |
| 284 | { |
| 285 | return args.func; |
| 286 | } |
| 287 | |
J-Alves | 13318e3 | 2021-02-22 17:21:00 +0000 | [diff] [blame] | 288 | static inline int32_t ffa_error_code(struct ffa_value val) |
| 289 | { |
| 290 | return (int32_t)val.arg2; |
| 291 | } |
| 292 | |
J-Alves | d6f4e14 | 2021-03-05 13:33:59 +0000 | [diff] [blame] | 293 | static inline ffa_vm_id_t ffa_sender(struct ffa_value args) |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 294 | { |
| 295 | return (args.arg1 >> 16) & 0xffff; |
| 296 | } |
| 297 | |
J-Alves | d6f4e14 | 2021-03-05 13:33:59 +0000 | [diff] [blame] | 298 | static inline ffa_vm_id_t ffa_receiver(struct ffa_value args) |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 299 | { |
| 300 | return args.arg1 & 0xffff; |
| 301 | } |
| 302 | |
| 303 | static inline uint32_t ffa_msg_send_size(struct ffa_value args) |
| 304 | { |
| 305 | return args.arg3; |
| 306 | } |
| 307 | |
| 308 | static inline uint32_t ffa_msg_send_attributes(struct ffa_value args) |
| 309 | { |
| 310 | return args.arg4; |
| 311 | } |
| 312 | |
Olivier Deprez | e562e54 | 2020-06-11 17:31:54 +0200 | [diff] [blame] | 313 | static inline uint32_t ffa_partition_info_get_count(struct ffa_value args) |
| 314 | { |
| 315 | return args.arg2; |
| 316 | } |
| 317 | |
Andrew Walbran | 1bbe940 | 2020-04-30 16:47:13 +0100 | [diff] [blame] | 318 | static inline ffa_memory_handle_t ffa_assemble_handle(uint32_t a1, uint32_t a2) |
| 319 | { |
| 320 | return (uint64_t)a1 | (uint64_t)a2 << 32; |
| 321 | } |
| 322 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 323 | static inline ffa_memory_handle_t ffa_mem_success_handle(struct ffa_value args) |
| 324 | { |
Andrew Walbran | 1bbe940 | 2020-04-30 16:47:13 +0100 | [diff] [blame] | 325 | return ffa_assemble_handle(args.arg2, args.arg3); |
| 326 | } |
| 327 | |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 328 | static inline ffa_memory_handle_t ffa_frag_handle(struct ffa_value args) |
| 329 | { |
| 330 | return ffa_assemble_handle(args.arg1, args.arg2); |
| 331 | } |
| 332 | |
Andrew Walbran | 1bbe940 | 2020-04-30 16:47:13 +0100 | [diff] [blame] | 333 | static inline struct ffa_value ffa_mem_success(ffa_memory_handle_t handle) |
| 334 | { |
| 335 | return (struct ffa_value){.func = FFA_SUCCESS_32, |
| 336 | .arg2 = (uint32_t)handle, |
| 337 | .arg3 = (uint32_t)(handle >> 32)}; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static inline ffa_vm_id_t ffa_vm_id(struct ffa_value args) |
| 341 | { |
| 342 | return (args.arg1 >> 16) & 0xffff; |
| 343 | } |
| 344 | |
| 345 | static inline ffa_vcpu_index_t ffa_vcpu_index(struct ffa_value args) |
| 346 | { |
| 347 | return args.arg1 & 0xffff; |
| 348 | } |
| 349 | |
| 350 | static inline uint64_t ffa_vm_vcpu(ffa_vm_id_t vm_id, |
| 351 | ffa_vcpu_index_t vcpu_index) |
| 352 | { |
| 353 | return ((uint32_t)vm_id << 16) | vcpu_index; |
| 354 | } |
| 355 | |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 356 | static inline ffa_vm_id_t ffa_frag_sender(struct ffa_value args) |
| 357 | { |
| 358 | return (args.arg4 >> 16) & 0xffff; |
| 359 | } |
| 360 | |
J-Alves | 6f72ca8 | 2021-11-01 12:34:58 +0000 | [diff] [blame] | 361 | static inline uint32_t ffa_feature_intid(struct ffa_value args) |
| 362 | { |
| 363 | return (uint32_t)args.arg2; |
| 364 | } |
| 365 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 366 | /** |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 367 | * Holds the UUID in a struct that is mappable directly to the SMCC calling |
| 368 | * convention, which is used for FF-A calls. |
| 369 | * |
| 370 | * Refer to table 84 of the FF-A 1.0 EAC specification as well as section 5.3 |
| 371 | * of the SMCC Spec 1.2. |
| 372 | */ |
| 373 | struct ffa_uuid { |
| 374 | uint32_t uuid[4]; |
| 375 | }; |
| 376 | |
| 377 | static inline void ffa_uuid_init(uint32_t w0, uint32_t w1, uint32_t w2, |
| 378 | uint32_t w3, struct ffa_uuid *uuid) |
| 379 | { |
| 380 | uuid->uuid[0] = w0; |
| 381 | uuid->uuid[1] = w1; |
| 382 | uuid->uuid[2] = w2; |
| 383 | uuid->uuid[3] = w3; |
| 384 | } |
| 385 | |
| 386 | static inline bool ffa_uuid_equal(const struct ffa_uuid *uuid1, |
| 387 | const struct ffa_uuid *uuid2) |
| 388 | { |
| 389 | return (uuid1->uuid[0] == uuid2->uuid[0]) && |
| 390 | (uuid1->uuid[1] == uuid2->uuid[1]) && |
| 391 | (uuid1->uuid[2] == uuid2->uuid[2]) && |
| 392 | (uuid1->uuid[3] == uuid2->uuid[3]); |
| 393 | } |
| 394 | |
| 395 | static inline bool ffa_uuid_is_null(const struct ffa_uuid *uuid) |
| 396 | { |
| 397 | return (uuid->uuid[0] == 0) && (uuid->uuid[1] == 0) && |
| 398 | (uuid->uuid[2] == 0) && (uuid->uuid[3] == 0); |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Flags to determine the partition properties, as required by |
| 403 | * FFA_PARTITION_INFO_GET. |
| 404 | * |
| 405 | * The values of the flags are specified in table 82 of the FF-A 1.0 EAC |
| 406 | * specification, "Partition information descriptor, partition properties". |
| 407 | */ |
| 408 | typedef uint32_t ffa_partition_properties_t; |
| 409 | |
| 410 | /** Partition property: partition supports receipt of direct requests. */ |
Maksims Svecovs | b596eab | 2021-04-27 00:52:27 +0100 | [diff] [blame] | 411 | #define FFA_PARTITION_DIRECT_REQ_RECV 0x1 |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 412 | |
| 413 | /** Partition property: partition can send direct requests. */ |
Maksims Svecovs | b596eab | 2021-04-27 00:52:27 +0100 | [diff] [blame] | 414 | #define FFA_PARTITION_DIRECT_REQ_SEND 0x2 |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 415 | |
| 416 | /** Partition property: partition can send and receive indirect messages. */ |
| 417 | #define FFA_PARTITION_INDIRECT_MSG 0x4 |
| 418 | |
J-Alves | 09ff9d8 | 2021-11-02 11:55:20 +0000 | [diff] [blame] | 419 | /** Partition property: partition can receive notifications. */ |
| 420 | #define FFA_PARTITION_NOTIFICATION 0x8 |
| 421 | |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 422 | /** |
| 423 | * Holds information returned for each partition by the FFA_PARTITION_INFO_GET |
| 424 | * interface. |
| 425 | * This corresponds to table 82 of the FF-A 1.0 EAC specification, "Partition |
| 426 | * information descriptor". |
| 427 | */ |
| 428 | struct ffa_partition_info { |
| 429 | ffa_vm_id_t vm_id; |
| 430 | ffa_vcpu_count_t vcpu_count; |
| 431 | ffa_partition_properties_t properties; |
| 432 | }; |
| 433 | |
| 434 | /** |
J-Alves | 980d199 | 2021-03-18 12:49:18 +0000 | [diff] [blame] | 435 | * FF-A v1.1 specification restricts the number of notifications to a maximum |
| 436 | * of 64. Following all possible bitmaps. |
| 437 | */ |
| 438 | #define FFA_NOTIFICATION_MASK(ID) (UINT64_C(1) << ID) |
| 439 | |
| 440 | typedef uint64_t ffa_notifications_bitmap_t; |
| 441 | |
| 442 | #define MAX_FFA_NOTIFICATIONS 64U |
| 443 | |
| 444 | /** |
J-Alves | c003a7a | 2021-03-18 13:06:53 +0000 | [diff] [blame] | 445 | * Flag for notification bind and set, to specify call is about per-vCPU |
| 446 | * notifications. |
| 447 | */ |
| 448 | #define FFA_NOTIFICATION_FLAG_PER_VCPU UINT32_C(1 << 0) |
| 449 | |
| 450 | /** |
J-Alves | 980d199 | 2021-03-18 12:49:18 +0000 | [diff] [blame] | 451 | * Helper function to assemble a 64-bit sized bitmap, from the 32-bit sized lo |
| 452 | * and hi. |
| 453 | * Helpful as FF-A specification defines that the notifications interfaces |
| 454 | * arguments are 32-bit registers. |
| 455 | */ |
| 456 | static inline ffa_notifications_bitmap_t ffa_notifications_bitmap(uint32_t lo, |
| 457 | uint32_t hi) |
| 458 | { |
| 459 | return (ffa_notifications_bitmap_t)hi << 32U | lo; |
| 460 | } |
| 461 | |
J-Alves | 98ff956 | 2021-09-09 14:39:41 +0100 | [diff] [blame] | 462 | static inline ffa_notifications_bitmap_t ffa_notification_get_from_sp( |
| 463 | struct ffa_value val) |
| 464 | { |
| 465 | return ffa_notifications_bitmap((uint32_t)val.arg2, (uint32_t)val.arg3); |
| 466 | } |
| 467 | |
| 468 | static inline ffa_notifications_bitmap_t ffa_notification_get_from_vm( |
| 469 | struct ffa_value val) |
| 470 | { |
| 471 | return ffa_notifications_bitmap((uint32_t)val.arg4, (uint32_t)val.arg5); |
| 472 | } |
| 473 | |
J-Alves | 980d199 | 2021-03-18 12:49:18 +0000 | [diff] [blame] | 474 | /** |
J-Alves | aa79c01 | 2021-07-09 14:29:45 +0100 | [diff] [blame] | 475 | * Flags used in calls to FFA_NOTIFICATION_GET interface. |
| 476 | */ |
| 477 | #define FFA_NOTIFICATION_FLAG_BITMAP_SP UINT32_C(0x1 << 0) |
| 478 | #define FFA_NOTIFICATION_FLAG_BITMAP_VM UINT32_C(0x1 << 1) |
| 479 | #define FFA_NOTIFICATION_FLAG_BITMAP_SPM UINT32_C(0x1 << 2) |
| 480 | #define FFA_NOTIFICATION_FLAG_BITMAP_HYP UINT32_C(0x1 << 3) |
| 481 | |
J-Alves | 1339402 | 2021-06-30 13:48:49 +0100 | [diff] [blame] | 482 | /** Flag for FFA_NOTIFICATION_SET to delay Schedule Receiver Interrupt */ |
| 483 | #define FFA_NOTIFICATIONS_FLAG_DELAY_SRI UINT32_C(0x1 << 1) |
| 484 | |
J-Alves | be6e303 | 2021-11-30 14:54:12 +0000 | [diff] [blame] | 485 | static inline ffa_vcpu_index_t ffa_notifications_get_vcpu(struct ffa_value args) |
J-Alves | aa79c01 | 2021-07-09 14:29:45 +0100 | [diff] [blame] | 486 | { |
J-Alves | be6e303 | 2021-11-30 14:54:12 +0000 | [diff] [blame] | 487 | return (ffa_vcpu_index_t)(args.arg1 >> 16 & 0xffffU); |
J-Alves | aa79c01 | 2021-07-09 14:29:45 +0100 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | /** |
J-Alves | c8e8a22 | 2021-06-08 17:33:52 +0100 | [diff] [blame] | 491 | * The max number of IDs for return of FFA_NOTIFICATION_INFO_GET. |
| 492 | */ |
| 493 | #define FFA_NOTIFICATIONS_INFO_GET_MAX_IDS 20U |
| 494 | |
| 495 | /** |
| 496 | * Number of registers to use in successfull return of interface |
| 497 | * FFA_NOTIFICATION_INFO_GET. |
| 498 | */ |
| 499 | #define FFA_NOTIFICATIONS_INFO_GET_REGS_RET 5U |
| 500 | |
| 501 | #define FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING 0x1U |
| 502 | |
| 503 | /** |
| 504 | * Helper macros for return parameter encoding as described in section 17.7.1 |
| 505 | * of the FF-A v1.1 Beta0 specification. |
| 506 | */ |
| 507 | #define FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT 0x7U |
| 508 | #define FFA_NOTIFICATIONS_LISTS_COUNT_MASK 0x1fU |
| 509 | #define FFA_NOTIFICATIONS_LIST_SHIFT(l) (2 * (l - 1) + 12) |
| 510 | #define FFA_NOTIFICATIONS_LIST_SIZE_MASK 0x3U |
| 511 | |
| 512 | static inline uint32_t ffa_notification_info_get_lists_count( |
| 513 | struct ffa_value args) |
| 514 | { |
| 515 | return (uint32_t)(args.arg2 >> FFA_NOTIFICATIONS_LISTS_COUNT_SHIFT) & |
| 516 | FFA_NOTIFICATIONS_LISTS_COUNT_MASK; |
| 517 | } |
| 518 | |
| 519 | static inline uint32_t ffa_notification_info_get_list_size( |
| 520 | struct ffa_value args, unsigned int list_idx) |
| 521 | { |
| 522 | return ((uint32_t)args.arg2 >> FFA_NOTIFICATIONS_LIST_SHIFT(list_idx)) & |
| 523 | FFA_NOTIFICATIONS_LIST_SIZE_MASK; |
| 524 | } |
| 525 | |
| 526 | static inline bool ffa_notification_info_get_more_pending(struct ffa_value args) |
| 527 | { |
| 528 | return (args.arg2 & FFA_NOTIFICATIONS_INFO_GET_FLAG_MORE_PENDING) != 0U; |
| 529 | } |
| 530 | |
| 531 | /** |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 532 | * A set of contiguous pages which is part of a memory region. This corresponds |
| 533 | * to table 40 of the FF-A 1.0 EAC specification, "Constituent memory region |
| 534 | * descriptor". |
| 535 | */ |
| 536 | struct ffa_memory_region_constituent { |
| 537 | /** |
| 538 | * The base IPA of the constituent memory region, aligned to 4 kiB page |
| 539 | * size granularity. |
| 540 | */ |
| 541 | uint64_t address; |
| 542 | /** The number of 4 kiB pages in the constituent memory region. */ |
| 543 | uint32_t page_count; |
| 544 | /** Reserved field, must be 0. */ |
| 545 | uint32_t reserved; |
| 546 | }; |
| 547 | |
| 548 | /** |
| 549 | * A set of pages comprising a memory region. This corresponds to table 39 of |
| 550 | * the FF-A 1.0 EAC specification, "Composite memory region descriptor". |
| 551 | */ |
| 552 | struct ffa_composite_memory_region { |
| 553 | /** |
| 554 | * The total number of 4 kiB pages included in this memory region. This |
| 555 | * must be equal to the sum of page counts specified in each |
| 556 | * `ffa_memory_region_constituent`. |
| 557 | */ |
| 558 | uint32_t page_count; |
| 559 | /** |
| 560 | * The number of constituents (`ffa_memory_region_constituent`) |
| 561 | * included in this memory region range. |
| 562 | */ |
| 563 | uint32_t constituent_count; |
| 564 | /** Reserved field, must be 0. */ |
| 565 | uint64_t reserved_0; |
| 566 | /** An array of `constituent_count` memory region constituents. */ |
| 567 | struct ffa_memory_region_constituent constituents[]; |
| 568 | }; |
| 569 | |
| 570 | /** Flags to indicate properties of receivers during memory region retrieval. */ |
| 571 | typedef uint8_t ffa_memory_receiver_flags_t; |
| 572 | |
| 573 | /** |
| 574 | * This corresponds to table 41 of the FF-A 1.0 EAC specification, "Memory |
| 575 | * access permissions descriptor". |
| 576 | */ |
| 577 | struct ffa_memory_region_attributes { |
| 578 | /** The ID of the VM to which the memory is being given or shared. */ |
| 579 | ffa_vm_id_t receiver; |
| 580 | /** |
| 581 | * The permissions with which the memory region should be mapped in the |
| 582 | * receiver's page table. |
| 583 | */ |
| 584 | ffa_memory_access_permissions_t permissions; |
| 585 | /** |
| 586 | * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP |
| 587 | * for memory regions with multiple borrowers. |
| 588 | */ |
| 589 | ffa_memory_receiver_flags_t flags; |
| 590 | }; |
| 591 | |
| 592 | /** Flags to control the behaviour of a memory sharing transaction. */ |
| 593 | typedef uint32_t ffa_memory_region_flags_t; |
| 594 | |
| 595 | /** |
| 596 | * Clear memory region contents after unmapping it from the sender and before |
| 597 | * mapping it for any receiver. |
| 598 | */ |
| 599 | #define FFA_MEMORY_REGION_FLAG_CLEAR 0x1 |
| 600 | |
| 601 | /** |
| 602 | * Whether the hypervisor may time slice the memory sharing or retrieval |
| 603 | * operation. |
| 604 | */ |
| 605 | #define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2 |
| 606 | |
| 607 | /** |
| 608 | * Whether the hypervisor should clear the memory region after the receiver |
| 609 | * relinquishes it or is aborted. |
| 610 | */ |
| 611 | #define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4 |
| 612 | |
| 613 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3) |
| 614 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3) |
| 615 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3) |
| 616 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3) |
| 617 | #define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3) |
| 618 | |
| 619 | /** |
| 620 | * This corresponds to table 42 of the FF-A 1.0 EAC specification, "Endpoint |
| 621 | * memory access descriptor". |
| 622 | */ |
| 623 | struct ffa_memory_access { |
| 624 | struct ffa_memory_region_attributes receiver_permissions; |
| 625 | /** |
| 626 | * Offset in bytes from the start of the outer `ffa_memory_region` to |
| 627 | * an `ffa_composite_memory_region` struct. |
| 628 | */ |
| 629 | uint32_t composite_memory_region_offset; |
| 630 | uint64_t reserved_0; |
| 631 | }; |
| 632 | |
| 633 | /** |
| 634 | * Information about a set of pages which are being shared. This corresponds to |
| 635 | * table 45 of the FF-A 1.0 EAC specification, "Lend, donate or share memory |
| 636 | * transaction descriptor". Note that it is also used for retrieve requests and |
| 637 | * responses. |
| 638 | */ |
| 639 | struct ffa_memory_region { |
| 640 | /** |
| 641 | * The ID of the VM which originally sent the memory region, i.e. the |
| 642 | * owner. |
| 643 | */ |
| 644 | ffa_vm_id_t sender; |
| 645 | ffa_memory_attributes_t attributes; |
| 646 | /** Reserved field, must be 0. */ |
| 647 | uint8_t reserved_0; |
| 648 | /** Flags to control behaviour of the transaction. */ |
| 649 | ffa_memory_region_flags_t flags; |
| 650 | ffa_memory_handle_t handle; |
| 651 | /** |
| 652 | * An implementation defined value associated with the receiver and the |
| 653 | * memory region. |
| 654 | */ |
| 655 | uint64_t tag; |
| 656 | /** Reserved field, must be 0. */ |
| 657 | uint32_t reserved_1; |
| 658 | /** |
| 659 | * The number of `ffa_memory_access` entries included in this |
| 660 | * transaction. |
| 661 | */ |
| 662 | uint32_t receiver_count; |
| 663 | /** |
| 664 | * An array of `attribute_count` endpoint memory access descriptors. |
| 665 | * Each one specifies a memory region offset, an endpoint and the |
| 666 | * attributes with which this memory region should be mapped in that |
| 667 | * endpoint's page table. |
| 668 | */ |
| 669 | struct ffa_memory_access receivers[]; |
| 670 | }; |
| 671 | |
| 672 | /** |
| 673 | * Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table |
| 674 | * 150 of the FF-A 1.0 EAC specification, "Descriptor to relinquish a memory |
| 675 | * region". |
| 676 | */ |
| 677 | struct ffa_mem_relinquish { |
| 678 | ffa_memory_handle_t handle; |
| 679 | ffa_memory_region_flags_t flags; |
| 680 | uint32_t endpoint_count; |
| 681 | ffa_vm_id_t endpoints[]; |
| 682 | }; |
| 683 | |
| 684 | /** |
| 685 | * Gets the `ffa_composite_memory_region` for the given receiver from an |
| 686 | * `ffa_memory_region`, or NULL if it is not valid. |
| 687 | */ |
| 688 | static inline struct ffa_composite_memory_region * |
| 689 | ffa_memory_region_get_composite(struct ffa_memory_region *memory_region, |
| 690 | uint32_t receiver_index) |
| 691 | { |
| 692 | uint32_t offset = memory_region->receivers[receiver_index] |
| 693 | .composite_memory_region_offset; |
| 694 | |
| 695 | if (offset == 0) { |
| 696 | return NULL; |
| 697 | } |
| 698 | |
| 699 | return (struct ffa_composite_memory_region *)((uint8_t *)memory_region + |
| 700 | offset); |
| 701 | } |
| 702 | |
| 703 | static inline uint32_t ffa_mem_relinquish_init( |
| 704 | struct ffa_mem_relinquish *relinquish_request, |
| 705 | ffa_memory_handle_t handle, ffa_memory_region_flags_t flags, |
| 706 | ffa_vm_id_t sender) |
| 707 | { |
| 708 | relinquish_request->handle = handle; |
| 709 | relinquish_request->flags = flags; |
| 710 | relinquish_request->endpoint_count = 1; |
| 711 | relinquish_request->endpoints[0] = sender; |
| 712 | return sizeof(struct ffa_mem_relinquish) + sizeof(ffa_vm_id_t); |
| 713 | } |
| 714 | |
| 715 | uint32_t ffa_memory_region_init( |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 716 | struct ffa_memory_region *memory_region, size_t memory_region_max_size, |
| 717 | ffa_vm_id_t sender, ffa_vm_id_t receiver, |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 718 | const struct ffa_memory_region_constituent constituents[], |
| 719 | uint32_t constituent_count, uint32_t tag, |
| 720 | ffa_memory_region_flags_t flags, enum ffa_data_access data_access, |
| 721 | enum ffa_instruction_access instruction_access, |
| 722 | enum ffa_memory_type type, enum ffa_memory_cacheability cacheability, |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 723 | enum ffa_memory_shareability shareability, uint32_t *fragment_length, |
| 724 | uint32_t *total_length); |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 725 | uint32_t ffa_memory_retrieve_request_init( |
| 726 | struct ffa_memory_region *memory_region, ffa_memory_handle_t handle, |
| 727 | ffa_vm_id_t sender, ffa_vm_id_t receiver, uint32_t tag, |
| 728 | ffa_memory_region_flags_t flags, enum ffa_data_access data_access, |
| 729 | enum ffa_instruction_access instruction_access, |
| 730 | enum ffa_memory_type type, enum ffa_memory_cacheability cacheability, |
| 731 | enum ffa_memory_shareability shareability); |
| 732 | uint32_t ffa_memory_lender_retrieve_request_init( |
| 733 | struct ffa_memory_region *memory_region, ffa_memory_handle_t handle, |
| 734 | ffa_vm_id_t sender); |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 735 | bool ffa_retrieved_memory_region_init( |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 736 | struct ffa_memory_region *response, size_t response_max_size, |
| 737 | ffa_vm_id_t sender, ffa_memory_attributes_t attributes, |
| 738 | ffa_memory_region_flags_t flags, ffa_memory_handle_t handle, |
| 739 | ffa_vm_id_t receiver, ffa_memory_access_permissions_t permissions, |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 740 | uint32_t page_count, uint32_t total_constituent_count, |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 741 | const struct ffa_memory_region_constituent constituents[], |
Andrew Walbran | ca808b1 | 2020-05-15 17:22:28 +0100 | [diff] [blame] | 742 | uint32_t fragment_constituent_count, uint32_t *total_length, |
| 743 | uint32_t *fragment_length); |
| 744 | uint32_t ffa_memory_fragment_init( |
| 745 | struct ffa_memory_region_constituent *fragment, |
| 746 | size_t fragment_max_size, |
| 747 | const struct ffa_memory_region_constituent constituents[], |
| 748 | uint32_t constituent_count, uint32_t *fragment_length); |