1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* 3 * Copyright (c) 2020, Linaro Limited 4 * Copyright (c) 2018-2023, Arm Limited. All rights reserved. 5 */ 6 7 #ifndef __FFA_H 8 #define __FFA_H 9 10 /* This is based on the FF-A 1.0 EAC specification */ 11 12 #include <smccc.h> 13 #include <stdint.h> 14 #include <util.h> 15 16 /* Error codes */ 17 #define FFA_OK 0 18 #define FFA_NOT_SUPPORTED -1 19 #define FFA_INVALID_PARAMETERS -2 20 #define FFA_NO_MEMORY -3 21 #define FFA_BUSY -4 22 #define FFA_INTERRUPTED -5 23 #define FFA_DENIED -6 24 #define FFA_RETRY -7 25 #define FFA_ABORTED -8 26 27 /* FFA_VERSION helpers */ 28 #define FFA_VERSION_MAJOR U(1) 29 #define FFA_VERSION_MAJOR_SHIFT U(16) 30 #define FFA_VERSION_MAJOR_MASK U(0x7FFF) 31 #define FFA_VERSION_MINOR U(1) 32 #define FFA_VERSION_MINOR_SHIFT U(0) 33 #define FFA_VERSION_MINOR_MASK U(0xFFFF) 34 #define MAKE_FFA_VERSION(major, minor) \ 35 ((((major) & FFA_VERSION_MAJOR_MASK) << FFA_VERSION_MAJOR_SHIFT) | \ 36 ((minor) & FFA_VERSION_MINOR_MASK)) 37 38 #define FFA_VERSION_1_0 MAKE_FFA_VERSION(1, 0) 39 #define FFA_VERSION_1_1 MAKE_FFA_VERSION(1, 1) 40 41 /* Function IDs */ 42 #define FFA_ERROR U(0x84000060) 43 #define FFA_SUCCESS_32 U(0x84000061) 44 #define FFA_SUCCESS_64 U(0xC4000061) 45 #define FFA_INTERRUPT U(0x84000062) 46 #define FFA_VERSION U(0x84000063) 47 #define FFA_FEATURES U(0x84000064) 48 #define FFA_RX_RELEASE U(0x84000065) 49 #define FFA_RXTX_MAP_32 U(0x84000066) 50 #define FFA_RXTX_MAP_64 U(0xC4000066) 51 #define FFA_RXTX_UNMAP U(0x84000067) 52 #define FFA_PARTITION_INFO_GET U(0x84000068) 53 #define FFA_ID_GET U(0x84000069) 54 #define FFA_SPM_ID_GET U(0x84000085) 55 #define FFA_MSG_WAIT U(0x8400006B) 56 #define FFA_MSG_YIELD U(0x8400006C) 57 #define FFA_RUN U(0x8400006D) 58 #define FFA_MSG_SEND2 U(0x84000086) 59 #define FFA_MSG_SEND U(0x8400006E) 60 #define FFA_MSG_SEND_DIRECT_REQ_32 U(0x8400006F) 61 #define FFA_MSG_SEND_DIRECT_REQ_64 U(0xC400006F) 62 #define FFA_MSG_SEND_DIRECT_RESP_32 U(0x84000070) 63 #define FFA_MSG_SEND_DIRECT_RESP_64 U(0xC4000070) 64 #define FFA_MSG_POLL U(0x8400006A) 65 #define FFA_MEM_DONATE_32 U(0x84000071) 66 #define FFA_MEM_DONATE_64 U(0xC4000071) 67 #define FFA_MEM_LEND_32 U(0x84000072) 68 #define FFA_MEM_LEND_64 U(0xC4000072) 69 #define FFA_MEM_SHARE_32 U(0x84000073) 70 #define FFA_MEM_SHARE_64 U(0xC4000073) 71 #define FFA_MEM_RETRIEVE_REQ_32 U(0x84000074) 72 #define FFA_MEM_RETRIEVE_REQ_64 U(0xC4000074) 73 #define FFA_MEM_RETRIEVE_RESP U(0x84000075) 74 #define FFA_MEM_RELINQUISH U(0x84000076) 75 #define FFA_MEM_RECLAIM U(0x84000077) 76 #define FFA_MEM_FRAG_RX U(0x8400007A) 77 #define FFA_MEM_FRAG_TX U(0x8400007B) 78 #define FFA_NOTIFICATION_BITMAP_CREATE U(0x8400007D) 79 #define FFA_NOTIFICATION_BITMAP_DESTROY U(0x8400007E) 80 #define FFA_NOTIFICATION_BIND U(0x8400007F) 81 #define FFA_NOTIFICATION_UNBIND U(0x84000080) 82 #define FFA_NOTIFICATION_SET U(0x84000081) 83 #define FFA_NOTIFICATION_GET U(0x84000082) 84 #define FFA_NOTIFICATION_INFO_GET_32 U(0x84000083) 85 #define FFA_NOTIFICATION_INFO_GET_64 U(0xC4000083) 86 #define FFA_SECONDARY_EP_REGISTER_64 U(0xC4000087) 87 #define FFA_MEM_PERM_GET_32 U(0x84000088) 88 #define FFA_MEM_PERM_GET_64 U(0xC4000088) 89 #define FFA_MEM_PERM_SET_32 U(0x84000089) 90 #define FFA_MEM_PERM_SET_64 U(0xC4000089) 91 #define FFA_CONSOLE_LOG_32 U(0x8400008A) 92 #define FFA_CONSOLE_LOG_64 U(0xC400008A) 93 94 #define FFA_FEATURE_NOTIF_PEND_INTR U(0x1) 95 #define FFA_FEATURE_SCHEDULE_RECV_INTR U(0x2) 96 #define FFA_FEATURE_MANAGED_EXIT_INTR U(0x3) 97 98 /* Special value for traffic targeted to the Hypervisor or SPM */ 99 #define FFA_TARGET_INFO_MBZ U(0x0) 100 101 #define FFA_MSG_FLAG_FRAMEWORK BIT(31) 102 #define FFA_MSG_TYPE_MASK GENMASK_32(7, 0) 103 #define FFA_MSG_PSCI U(0x0) 104 #define FFA_MSG_SEND_VM_CREATED U(0x4) 105 #define FFA_MSG_RESP_VM_CREATED U(0x5) 106 #define FFA_MSG_SEND_VM_DESTROYED U(0x6) 107 #define FFA_MSG_RESP_VM_DESTROYED U(0x7) 108 #define FFA_MSG_VERSION_REQ U(0x8) 109 #define FFA_MSG_VERSION_RESP U(0x9) 110 111 /* 112 * Flag used as parameter to FFA_PARTITION_INFO_GET to return partition 113 * count only. 114 */ 115 #define FFA_PARTITION_INFO_GET_COUNT_FLAG BIT(0) 116 117 /* Memory attributes: Normal memory, Write-Back cacheable, Inner shareable */ 118 #define FFA_NORMAL_MEM_REG_ATTR U(0x2f) 119 120 /* Memory access permissions: Read-write */ 121 #define FFA_MEM_ACC_RW BIT(1) 122 123 /* Memory access permissions: executable */ 124 #define FFA_MEM_ACC_EXE BIT(3) 125 126 /* Memory access permissions mask */ 127 #define FFA_MEM_ACC_MASK 0xf 128 129 /* Clear memory before mapping in receiver */ 130 #define FFA_MEMORY_REGION_FLAG_CLEAR BIT(0) 131 /* Relayer may time slice this operation */ 132 #define FFA_MEMORY_REGION_FLAG_TIME_SLICE BIT(1) 133 /* Clear memory after receiver relinquishes it */ 134 #define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH BIT(2) 135 136 /* Share memory transaction */ 137 #define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE SHIFT_U32(1, 3) 138 /* Relayer must choose the alignment boundary */ 139 #define FFA_MEMORY_REGION_FLAG_ANY_ALIGNMENT 0 140 141 #define FFA_MEM_PERM_DATA_PERM GENMASK_32(1, 0) 142 #define FFA_MEM_PERM_RW U(0x1) 143 #define FFA_MEM_PERM_RO U(0x3) 144 145 #define FFA_MEM_PERM_INSTRUCTION_PERM BIT(2) 146 #define FFA_MEM_PERM_NX BIT(2) 147 #define FFA_MEM_PERM_X U(0) 148 149 #define FFA_MEM_PERM_RESERVED GENMASK_32(31, 3) 150 151 /* Special value for MBZ parameters */ 152 #define FFA_PARAM_MBZ U(0x0) 153 154 /* 155 * The W1 register in FFA_INTERRUPT and FFA_RUN interfaces contains the target 156 * information. This value has two parts, the SP ID and vCPU ID. The SP ID 157 * identifies the SP to resume and the vCPU ID identifies the vCPU or execution 158 * context to resume (FF-A v1.1 section 4.8). 159 */ 160 #define FFA_TARGET_INFO_SET(sp_id, vcpu_id) (((sp_id) << 16) | (vcpu_id)) 161 #define FFA_TARGET_INFO_GET_SP_ID(info) (((info) >> 16) & 0xffff) 162 #define FFA_TARGET_INFO_GET_VCPU_ID(info) ((info) & 0xffff) 163 164 /* 165 * Flags used for the FFA_PARTITION_INFO_GET return message: 166 * BIT(0): Supports receipt of direct requests 167 * BIT(1): Can send direct requests 168 * BIT(2): Can send and receive indirect messages 169 * BIT(3): Supports receipt of notifications 170 * BIT(4-5): Partition ID is a PE endpoint ID 171 */ 172 #define FFA_PART_PROP_DIRECT_REQ_RECV BIT(0) 173 #define FFA_PART_PROP_DIRECT_REQ_SEND BIT(1) 174 #define FFA_PART_PROP_INDIRECT_MSGS BIT(2) 175 #define FFA_PART_PROP_RECV_NOTIF BIT(3) 176 #define FFA_PART_PROP_IS_PE_ID SHIFT_U32(0, 4) 177 #define FFA_PART_PROP_IS_SEPID_INDEP SHIFT_U32(1, 4) 178 #define FFA_PART_PROP_IS_SEPID_DEP SHIFT_U32(2, 4) 179 #define FFA_PART_PROP_IS_AUX_ID SHIFT_U32(3, 4) 180 #define FFA_PART_PROP_NOTIF_CREATED BIT(6) 181 #define FFA_PART_PROP_NOTIF_DESTROYED BIT(7) 182 #define FFA_PART_PROP_AARCH64_STATE BIT(8) 183 184 #define FFA_MEMORY_HANDLE_HYPERVISOR_BIT BIT64(63) 185 #define FFA_MEMORY_HANDLE_SECURE_BIT BIT64(45) 186 #define FFA_MEMORY_HANDLE_NON_SECURE_BIT BIT64(44) 187 /* 188 * Codes the OP-TEE partition/guest ID into a cookie in order to know which 189 * partition to activate when reclaiming the shared memory. This field is 0 190 * unless CFG_NS_VIRTUALIZATION is enabled. 191 */ 192 #define FFA_MEMORY_HANDLE_PRTN_SHIFT 16 193 #define FFA_MEMORY_HANDLE_PRTN_MASK GENMASK_32(16, 0) 194 195 196 #define FFA_BOOT_INFO_NAME_LEN U(16) 197 198 /* Boot Info descriptors type */ 199 #define FFA_BOOT_INFO_TYPE_IMDEF BIT(7) 200 #define FFA_BOOT_INFO_TYPE_ID_MASK GENMASK_32(6, 0) 201 #define FFA_BOOT_INFO_TYPE_ID_FDT U(0) 202 #define FFA_BOOT_INFO_TYPE_ID_HOB U(1) 203 204 /* Boot Info descriptors flags */ 205 #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK GENMASK_32(1, 0) 206 #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING U(0) 207 #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID U(1) 208 209 /** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */ 210 #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT U(2) 211 #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK GENMASK_32(3, 2) 212 #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE U(1) 213 #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR U(0) 214 215 #define FFA_BOOT_INFO_SIGNATURE U(0xFFA) 216 #define FFA_BOOT_INFO_VERSION U(0x10001) 217 218 #define FFA_CONSOLE_LOG_CHAR_COUNT_MASK GENMASK_32(7, 0) 219 #define FFA_CONSOLE_LOG_32_MAX_MSG_LEN U(24) 220 #define FFA_CONSOLE_LOG_64_MAX_MSG_LEN U(48) 221 222 #ifndef __ASSEMBLER__ 223 /* Constituent memory region descriptor */ 224 struct ffa_address_range { 225 uint64_t address; 226 uint32_t page_count; 227 uint32_t reserved; 228 }; 229 230 /* Composite memory region descriptor */ 231 struct ffa_mem_region { 232 uint32_t total_page_count; 233 uint32_t address_range_count; 234 uint64_t reserved; 235 struct ffa_address_range address_range_array[]; 236 }; 237 238 /* Memory access permissions descriptor */ 239 struct ffa_mem_access_perm { 240 uint16_t endpoint_id; 241 uint8_t perm; 242 uint8_t flags; 243 }; 244 245 /* Endpoint memory access descriptor */ 246 struct ffa_mem_access { 247 struct ffa_mem_access_perm access_perm; 248 uint32_t region_offs; 249 uint64_t reserved; 250 }; 251 252 /* Lend, donate or share memory transaction descriptor */ 253 struct ffa_mem_transaction_1_0 { 254 uint16_t sender_id; 255 uint8_t mem_reg_attr; 256 uint8_t reserved0; 257 uint32_t flags; 258 uint64_t global_handle; 259 uint64_t tag; 260 uint32_t reserved1; 261 uint32_t mem_access_count; 262 struct ffa_mem_access mem_access_array[]; 263 }; 264 265 struct ffa_mem_transaction_1_1 { 266 uint16_t sender_id; 267 uint16_t mem_reg_attr; 268 uint32_t flags; 269 uint64_t global_handle; 270 uint64_t tag; 271 uint32_t mem_access_size; 272 uint32_t mem_access_count; 273 uint32_t mem_access_offs; 274 uint8_t reserved[12]; 275 }; 276 277 /* 278 * The parts needed from struct ffa_mem_transaction_1_0 or struct 279 * ffa_mem_transaction_1_1, used to provide an abstraction of difference in 280 * data structures between version 1.0 and 1.1. This is just an internal 281 * interface and can be changed without changing any ABI. 282 */ 283 struct ffa_mem_transaction_x { 284 uint16_t sender_id; 285 uint8_t mem_reg_attr; 286 uint8_t flags; 287 uint8_t mem_access_size; 288 uint8_t mem_access_count; 289 uint16_t mem_access_offs; 290 uint64_t global_handle; 291 uint64_t tag; 292 }; 293 294 #define FFA_UUID_SIZE 16 295 296 /* Partition information descriptor */ 297 struct ffa_partition_info_x { 298 uint16_t id; 299 uint16_t execution_context; 300 uint32_t partition_properties; 301 /* 302 * The uuid field is absent in FF-A 1.0, and an array of 16 303 * (FFA_UUID_SIZE) from FF-A 1.1 304 */ 305 uint8_t uuid[]; 306 }; 307 308 /* Descriptor to relinquish a memory region (FFA_MEM_RELINQUISH) */ 309 struct ffa_mem_relinquish { 310 uint64_t handle; 311 uint32_t flags; 312 uint32_t endpoint_count; 313 uint16_t endpoint_id_array[]; 314 }; 315 316 /* FF-A v1.0 boot information name-value pairs */ 317 struct ffa_boot_info_nvp_1_0 { 318 uint32_t name[4]; 319 uint64_t value; 320 uint64_t size; 321 }; 322 323 /* FF-A v1.0 boot information descriptor */ 324 struct ffa_boot_info_1_0 { 325 uint32_t magic; 326 uint32_t count; 327 struct ffa_boot_info_nvp_1_0 nvp[]; 328 }; 329 330 /* FF-A v1.1 boot information descriptor */ 331 struct ffa_boot_info_1_1 { 332 char name[FFA_BOOT_INFO_NAME_LEN]; 333 uint8_t type; 334 uint8_t reserved; 335 uint16_t flags; 336 uint32_t size; 337 uint64_t contents; 338 }; 339 340 /* FF-A v1.1 boot information header */ 341 struct ffa_boot_info_header_1_1 { 342 uint32_t signature; 343 uint32_t version; 344 uint32_t blob_size; 345 uint32_t desc_size; 346 uint32_t desc_count; 347 uint32_t desc_offset; 348 uint64_t reserved; 349 }; 350 351 #endif /*__ASSEMBLER__*/ 352 #endif /* __FFA_H */ 353