1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* 3 * Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved. 4 */ 5 6 #ifndef LIBSP_INCLUDE_FFA_API_DEFINES_H_ 7 #define LIBSP_INCLUDE_FFA_API_DEFINES_H_ 8 9 #include <stdint.h> 10 #include "util.h" 11 12 #define FFA_VERSION_1_0 (0x00010000) 13 #define FFA_VERSION_1_1 (0x00010001) 14 15 #ifndef CFG_FFA_VERSION 16 #error CFG_FFA_VERSION must be defined 17 #elif CFG_FFA_VERSION != FFA_VERSION_1_0 && CFG_FFA_VERSION != FFA_VERSION_1_1 18 #error Only FF-A versions 1.0 and 1.1 are supported 19 #endif 20 21 /* Status codes */ 22 #define FFA_OK (0) 23 #define FFA_NOT_SUPPORTED (-1) 24 #define FFA_INVALID_PARAMETERS (-2) 25 #define FFA_NO_MEMORY (-3) 26 #define FFA_BUSY (-4) 27 #define FFA_INTERRUPTED (-5) 28 #define FFA_DENIED (-6) 29 #define FFA_RETRY (-7) 30 #define FFA_ABORTED (-8) 31 32 /* Function IDs */ 33 #define FFA_ERROR UINT32_C(0x84000060) 34 #define FFA_SUCCESS_32 UINT32_C(0x84000061) 35 #define FFA_SUCCESS_64 UINT32_C(0xC4000061) 36 #define FFA_INTERRUPT UINT32_C(0x84000062) 37 #define FFA_VERSION UINT32_C(0x84000063) 38 #define FFA_FEATURES UINT32_C(0x84000064) 39 #define FFA_RX_RELEASE UINT32_C(0x84000065) 40 #define FFA_RXTX_MAP_32 UINT32_C(0x84000066) 41 #define FFA_RXTX_MAP_64 UINT32_C(0xC4000066) 42 #define FFA_RXTX_UNMAP UINT32_C(0x84000067) 43 #define FFA_PARTITION_INFO_GET UINT32_C(0x84000068) 44 #define FFA_ID_GET UINT32_C(0x84000069) 45 #define FFA_MSG_WAIT UINT32_C(0x8400006B) 46 #define FFA_MSG_YIELD UINT32_C(0x8400006C) 47 #define FFA_MSG_RUN UINT32_C(0x8400006D) 48 #define FFA_MSG_SEND UINT32_C(0x8400006E) 49 #define FFA_MSG_SEND_DIRECT_REQ_32 UINT32_C(0x8400006F) 50 #define FFA_MSG_SEND_DIRECT_REQ_64 UINT32_C(0xC400006F) 51 #define FFA_MSG_SEND_DIRECT_RESP_32 UINT32_C(0x84000070) 52 #define FFA_MSG_SEND_DIRECT_RESP_64 UINT32_C(0xC4000070) 53 #define FFA_MSG_POLL UINT32_C(0x8400006A) 54 #define FFA_MEM_DONATE_32 UINT32_C(0x84000071) 55 #define FFA_MEM_DONATE_64 UINT32_C(0xC4000071) 56 #define FFA_MEM_LEND_32 UINT32_C(0x84000072) 57 #define FFA_MEM_LEND_64 UINT32_C(0xC4000072) 58 #define FFA_MEM_SHARE_32 UINT32_C(0x84000073) 59 #define FFA_MEM_SHARE_64 UINT32_C(0xC4000073) 60 #define FFA_MEM_RETRIEVE_REQ_32 UINT32_C(0x84000074) 61 #define FFA_MEM_RETRIEVE_REQ_64 UINT32_C(0xC4000074) 62 #define FFA_MEM_RETRIEVE_RESP UINT32_C(0x84000075) 63 #define FFA_MEM_RELINQUISH UINT32_C(0x84000076) 64 #define FFA_MEM_RECLAIM UINT32_C(0x84000077) 65 #define FFA_MEM_FRAG_RX UINT32_C(0x8400007A) 66 #define FFA_MEM_FRAG_TX UINT32_C(0x8400007B) 67 #define FFA_MEM_PERM_GET UINT32_C(0x84000088) 68 #define FFA_MEM_PERM_SET UINT32_C(0x84000089) 69 #define FFA_CONSOLE_LOG_32 UINT32_C(0x8400008A) 70 #define FFA_CONSOLE_LOG_64 UINT32_C(0xC400008A) 71 72 /* Utility macros */ 73 #define FFA_TO_32_BIT_FUNC(x) ((x) & (~UINT32_C(0x40000000))) 74 #define FFA_TO_64_BIT_FUNC(x) ((x) | UINT32_C(0x40000000)) 75 #define FFA_IS_32_BIT_FUNC(x) (((x) & UINT32_C(0x40000000)) == 0) 76 #define FFA_IS_64_BIT_FUNC(x) (((x) & UINT32_C(0x40000000)) != 0) 77 78 /* Special value for MBZ parameters */ 79 #define FFA_PARAM_MBZ UINT32_C(0x0) 80 81 /* Boot information signature */ 82 #define FFA_BOOT_INFO_SIGNATURE_V1_0 UINT32_C(0x412D4646) /* FF-A ASCII */ 83 #define FFA_BOOT_INFO_SIGNATURE_V1_1 UINT32_C(0x0FFA) 84 85 /* Boot information type */ 86 #define FFA_BOOT_INFO_TYPE_SHIFT UINT32_C(7) 87 #define FFA_BOOT_INFO_TYPE_MASK UINT32_C(1) 88 89 #define FFA_BOOT_INFO_TYPE_STD UINT32_C(0) 90 #define FFA_BOOT_INFO_TYPE_IMPDEF UINT32_C(1) 91 92 /* Boot information ID */ 93 #define FFA_BOOT_INFO_ID_SHIFT UINT32_C(0) 94 #define FFA_BOOT_INFO_ID_MASK GENMASK_32(6, 0) 95 96 #define FFA_BOOT_INFO_ID_STD_FDT UINT32_C(0) 97 #define FFA_BOOT_INFO_ID_STD_HOB UINT32_C(1) 98 99 /* Boot information flags */ 100 #define FFA_BOOT_INFO_CONTENT_FMT_SHIFT UINT32_C(2) 101 #define FFA_BOOT_INFO_CONTENT_FMT_MASK GENMASK_32(1, 0) 102 103 #define FFA_BOOT_INFO_CONTENT_FMT_ADDR UINT32_C(0) 104 #define FFA_BOOT_INFO_CONTENT_FMT_VAL UINT32_C(1) 105 106 #define FFA_BOOT_INFO_NAME_FMT_SHIFT UINT32_C(0) 107 #define FFA_BOOT_INFO_NAME_FMT_MASK GENMASK_32(1, 0) 108 109 #define FFA_BOOT_INFO_NAME_FMT_STR UINT32_C(0) 110 #define FFA_BOOT_INFO_NAME_FMT_UUID UINT32_C(1) 111 112 /* FFA_VERSION */ 113 #if CFG_FFA_VERSION == FFA_VERSION_1_0 114 #define FFA_VERSION_MAJOR UINT32_C(1) 115 #define FFA_VERSION_MINOR UINT32_C(0) 116 #elif CFG_FFA_VERSION == FFA_VERSION_1_1 117 #define FFA_VERSION_MAJOR UINT32_C(1) 118 #define FFA_VERSION_MINOR UINT32_C(1) 119 #endif /* CFG_FFA_VERSION */ 120 121 #define FFA_VERSION_MAJOR_SHIFT UINT32_C(16) 122 #define FFA_VERSION_MAJOR_MASK GENMASK_32(14, 0) 123 #define FFA_VERSION_MINOR_SHIFT UINT32_C(0) 124 #define FFA_VERSION_MINOR_MASK GENMASK_32(15, 0) 125 126 /* FFA_FEATURES */ 127 128 /* Features of FFA_RXTX_MAP */ 129 #define FFA_FEATURES_RXTX_MAP_GRANULARITY_INDEX UINT32_C(0) 130 #define FFA_FEATURES_RXTX_MAP_GRANULARITY_SHIFT UINT32_C(0) 131 #define FFA_FEATURES_RXTX_MAP_GRANULARITY_MASK GENMASK_32(1, 0) 132 133 #define FFA_FEATURES_RXTX_MAP_GRANULARITY_4K UINT32_C(0x00) 134 #define FFA_FEATURES_RXTX_MAP_GRANULARITY_64K UINT32_C(0x01) 135 #define FFA_FEATURES_RXTX_MAP_GRANULARITY_16K UINT32_C(0x02) 136 137 /* Features of FFA_MEM_DONATE, FFA_MEM_LEND, FFA_MEM_SHARE */ 138 #define FFA_FEATURES_MEM_DYNAMIC_BUFFER_SUPPORT_INDEX UINT32_C(0) 139 #define FFA_FEATURES_MEM_DYNAMIC_BUFFER_SUPPORT BIT32(0) 140 141 /* Features of FFA_MEM_RETRIEVE_REQ */ 142 #define FFA_FEATURES_MEM_RETRIEVE_REQ_RETRIEVALS_INDEX UINT32_C(0) 143 #define FFA_FEATURES_MEM_RETRIEVE_REQ_RETRIEVALS_SHIFT UINT32_C(0) 144 #define FFA_FEATURES_MEM_RETRIEVE_REQ_RETRIEVALS_MASK GENMASK_32(7, 0) 145 146 /* FFA_RXTX_MAP */ 147 #define FFA_RXTX_MAP_PAGE_COUNT_SHIFT UINT32_C(0) 148 #define FFA_RXTX_MAP_PAGE_COUNT_MASK GENMASK_32(5, 0) 149 #define FFA_RXTX_MAP_PAGE_COUNT_MAX FFA_RXTX_MAP_PAGE_COUNT_MASK 150 #define FFA_RXTX_MAP_PAGE_SIZE UINT32_C(4096) 151 152 /* FFA_RXTX_UNMAP */ 153 #define FFA_RXTX_UNMAP_ID_SHIFT UINT32_C(16) 154 #define FFA_RXTX_UNMAP_ID_MASK GENMASK_32(15, 0) 155 156 /* FFA_PARTITION_INFO_GET */ 157 #if CFG_FFA_VERSION >= FFA_VERSION_1_1 158 #define FFA_PARTITION_INFO_GET_FLAG_COUNT_ONLY BIT32(0) 159 #endif /* CFG_FFA_VERSION */ 160 161 #define FFA_PARTITION_SUPPORTS_DIRECT_REQUESTS BIT32(0) 162 #define FFA_PARTITION_CAN_SEND_DIRECT_REQUESTS BIT32(1) 163 #define FFA_PARTITION_SUPPORTS_INDIRECT_REQUESTS BIT32(2) 164 #if CFG_FFA_VERSION >= FFA_VERSION_1_1 165 #define FFA_PARTITION_SUPPORTS_NOTIFICATIONS BIT32(3) 166 167 #define FFA_PARTITION_PART_ID_SHIFT UINT32_C(4) 168 #define FFA_PARTITION_PART_ID_MASK GENMASK_32(1, 0) 169 #define FFA_PARTITION_PART_ID_PE_ENDPOINT_ID UINT16_C(0) 170 #define FFA_PARTITION_PART_ID_SEPID_INDEPENDENT UINT16_C(1) 171 #define FFA_PARTITION_PART_ID_SEPID_DEPENDENT UINT16_C(2) 172 #define FFA_PARTITION_PART_ID_PE_AUX_ID UINT16_C(3) 173 174 #define FFA_PARTITION_INFORM_VM_CREATE BIT32(6) 175 #define FFA_PARTITION_INFORM_VM_DESTROY BIT32(7) 176 177 #define FFA_PARTITION_AARCH64_EXECUTION_STATE BIT32(8) 178 #endif /* CFG_FFA_VERSION */ 179 180 /* FFA_ID_GET */ 181 #define FFA_ID_GET_ID_SHIFT UINT32_C(0) 182 #define FFA_ID_GET_ID_MASK GENMASK_32(15, 0) 183 184 /* FFA_MSG_SEND_DIRECT_REQ */ 185 #define FFA_MSG_SEND_DIRECT_REQ_SOURCE_ID_MASK GENMASK_32(15, 0) 186 #define FFA_MSG_SEND_DIRECT_REQ_SOURCE_ID_SHIFT UINT32_C(16) 187 188 #define FFA_MSG_SEND_DIRECT_REQ_DEST_ID_MASK GENMASK_32(15, 0) 189 #define FFA_MSG_SEND_DIRECT_REQ_DEST_ID_SHIFT UINT32_C(0) 190 191 /* FFA_MSG_SEND_DIRECT_RESP */ 192 #define FFA_MSG_SEND_DIRECT_RESP_SOURCE_ID_MASK GENMASK_32(15, 0) 193 #define FFA_MSG_SEND_DIRECT_RESP_SOURCE_ID_SHIFT UINT32_C(16) 194 195 #define FFA_MSG_SEND_DIRECT_RESP_DEST_ID_MASK GENMASK_32(15, 0) 196 #define FFA_MSG_SEND_DIRECT_RESP_DEST_ID_SHIFT UINT32_C(0) 197 198 /* FF-A direct message flags */ 199 #define FFA_MSG_FLAG_FRAMEWORK BIT32(31) 200 #define FFA_FRAMEWORK_MSG_TYPE_SHIFT UINT32_C(0) 201 #define FFA_FRAMEWORK_MSG_TYPE_MASK GENMASK_32(7, 0) 202 #define FFA_FRAMEWORK_MSG_PSCI UINT32_C(0x0) 203 #define FFA_FRAMEWORK_MSG_VM_CREATED UINT32_C(0x4) 204 #define FFA_FRAMEWORK_MSG_VM_CREATED_ACK UINT32_C(0x5) 205 #define FFA_FRAMEWORK_MSG_VM_DESTROYED UINT32_C(0x6) 206 #define FFA_FRAMEWORK_MSG_VM_DESTROYED_ACK UINT32_C(0x7) 207 #define FFA_IS_FRAMEWORK_MSG(x) (((x) & FFA_MSG_FLAG_FRAMEWORK) != 0) 208 209 /* Table 5.15: Memory access permissions descriptor */ 210 211 /* Memory access permissions */ 212 #define FFA_MEM_ACCESS_PERM_INSTRUCTION_MASK GENMASK_32(1, 0) 213 #define FFA_MEM_ACCESS_PERM_INSTRUCTION_SHIFT UINT32_C(2) 214 215 #define FFA_MEM_ACCESS_PERM_INSTRUCTION_NOT_SPECIFIED UINT32_C(0x00) 216 #define FFA_MEM_ACCESS_PERM_INSTRUCTION_NOT_EXECUTABLE UINT32_C(0x01) 217 #define FFA_MEM_ACCESS_PERM_INSTRUCTION_EXECUTABLE UINT32_C(0x02) 218 219 #define FFA_MEM_ACCESS_PERM_DATA_MASK GENMASK_32(1, 0) 220 #define FFA_MEM_ACCESS_PERM_DATA_SHIFT UINT32_C(0) 221 222 #define FFA_MEM_ACCESS_PERM_DATA_NOT_SPECIFIED UINT32_C(0x00) 223 #define FFA_MEM_ACCESS_PERM_DATA_READ_ONLY UINT32_C(0x01) 224 #define FFA_MEM_ACCESS_PERM_DATA_READ_WRITE UINT32_C(0x02) 225 226 #define FFA_MEM_ACCESS_PERM_FLAGS_NON_RETRIEVAL_BORROWER BIT(0) 227 228 /* Table 5.18: Memory region attributes descriptor */ 229 230 /* Memory type */ 231 #define FFA_MEM_REGION_ATTR_MEMORY_TYPE_MASK GENMASK_32(1, 0) 232 #define FFA_MEM_REGION_ATTR_MEMORY_TYPE_SHIFT UINT32_C(4) 233 234 #if CFG_FFA_VERSION >= FFA_VERSION_1_1 235 #define FFA_MEM_REGION_ATTR_NS_BIT BIT32(6) 236 #endif 237 238 #define FFA_MEM_REGION_ATTR_MEMORY_TYPE_NOT_SPECIFIED UINT32_C(0x00) 239 #define FFA_MEM_REGION_ATTR_MEMORY_TYPE_DEVICE UINT32_C(0x01) 240 #define FFA_MEM_REGION_ATTR_MEMORY_TYPE_NORMAL UINT32_C(0x02) 241 242 /* Cacheability */ 243 #define FFA_MEM_REGION_ATTR_CACHEABILITY_MASK GENMASK_32(1, 0) 244 #define FFA_MEM_REGION_ATTR_CACHEABILITY_SHIFT UINT32_C(2) 245 246 #define FFA_MEM_REGION_ATTR_CACHEABILITY_NON_CACHEABLE UINT32_C(0x01) 247 #define FFA_MEM_REGION_ATTR_CACHEABILITY_WRITE_BACK UINT32_C(0x03) 248 249 /* Device memory attributes */ 250 #define FFA_MEM_REGION_ATTR_DEVICE_MEM_ATTR_MASK GENMASK_32(1, 0) 251 #define FFA_MEM_REGION_ATTR_DEVICE_MEM_ATTR_SHIFT UINT32_C(2) 252 253 #define FFA_MEM_REGION_ATTR_DEVICE_MEM_ATTR_NGNRNE UINT32_C(0x00) 254 #define FFA_MEM_REGION_ATTR_DEVICE_MEM_ATTR_NGNRE UINT32_C(0x01) 255 #define FFA_MEM_REGION_ATTR_DEVICE_MEM_ATTR_NGRE UINT32_C(0x02) 256 #define FFA_MEM_REGION_ATTR_DEVICE_MEM_ATTR_GRE UINT32_C(0x03) 257 258 /* Shareability */ 259 #define FFA_MEM_REGION_ATTR_SHAREABILITY_MASK GENMASK_32(1, 0) 260 #define FFA_MEM_REGION_ATTR_SHAREABILITY_SHIFT UINT32_C(0) 261 262 #define FFA_MEM_REGION_ATTR_SHAREABILITY_NON_SHAREABLE UINT32_C(0x00) 263 #define FFA_MEM_REGION_ATTR_SHAREABILITY_OUTER_SHAREABLE UINT32_C(0x02) 264 #define FFA_MEM_REGION_ATTR_SHAREABILITY_INNER_SHAREABLE UINT32_C(0x03) 265 266 /* Table 5.19: Lend, donate or share memory transaction descriptor */ 267 268 #define FFA_MEM_TRANSACTION_PAGE_SIZE UINT32_C(4096) 269 #define FFA_MEM_TRANSACTION_PAGE_MASK GENMASK_64(11, 0) 270 271 /* Flags for donate, lend, share */ 272 273 #define FFA_MEM_TRANSACTION_FLAGS_ZERO_MEMORY BIT32(0) 274 #define FFA_MEM_TRANSACTION_FLAGS_OPERATION_TIME_SLICING BIT32(1) 275 276 /* Flags for retrieve request */ 277 #define FFA_MEM_TRANSACTION_FLAGS_ZERO_MEMORY_BEFORE_RETRIEVE BIN32(0) 278 /* FFA_MEM_TRANSACTION_FLAGS_OPERATION_TIME_SLICING is available too */ 279 #define FFA_MEM_TRANSACTION_FLAGS_ZERO_MEMORY_AFTER_RELINQIUSH BIT32(2) 280 281 #define FFA_MEM_TRANSACTION_FLAGS_TYPE_MASK GENMASK_32(1, 0) 282 #define FFA_MEM_TRANSACTION_FLAGS_TYPE_SHIFT UINT32_C(3) 283 284 #define FFA_MEM_TRANSACTION_FLAGS_TYPE_RELAYER_SPECIFIES UINT32_C(0x00) 285 #define FFA_MEM_TRANSACTION_FLAGS_TYPE_SHARE UINT32_C(0x01) 286 #define FFA_MEM_TRANSACTION_FLAGS_TYPE_LEND UINT32_C(0x02) 287 #define FFA_MEM_TRANSACTION_FLAGS_TYPE_DONATE UINT32_C(0x03) 288 289 #define FFA_MEM_TRANSACTION_FLAGS_ALIGNMENT_HINT_MASK GENMASK_32(3, 0) 290 #define FFA_MEM_TRANSACTION_FLAGS_ALIGNMENT_HINT_SHIFT UINT32_C(5) 291 292 #define FFA_MEM_TRANSACTION_FLAGS_ALIGNMENT_HINT_VALID BIT32(9) 293 294 /* Flags for retrieve response */ 295 /* FFA_MEM_TRANSACTION_FLAGS_ZERO_MEMORY is available too */ 296 /* FFA_MEM_TRANSACTION_FLAGS_TYPE_* is available too */ 297 298 /* Handle */ 299 #define FFA_MEM_HANDLE_INVALID GENMASK_64(63, 0) 300 301 /* Table 11.25: Descriptor to relinquish a memory region */ 302 #define FFA_RELINQUISH_FLAGS_ZERO_MEMORY_AFTER_RELINQUISH BIT32(0) 303 #define FFA_RELINQUISH_FLAGS_OPERATION_TIME_SLICING BIT32(1) 304 305 /* Flags for memory permission get/set */ 306 #ifndef FFA_MEM_PERM_PAGE_SIZE 307 #define FFA_MEM_PERM_PAGE_SIZE UINT32_C(4096) 308 #endif /* FFA_MEM_PERM_PAGE_SIZE */ 309 310 #define FFA_MEM_PERM_PAGE_MASK (FFA_MEM_PERM_PAGE_SIZE - 1) 311 312 #define FFA_MEM_PERM_PAGE_COUNT_MAX GENMASK_32(31, 0) 313 314 #define FFA_MEM_PERM_DATA_ACCESS_PERM_INDEX UINT32_C(2) 315 #define FFA_MEM_PERM_DATA_ACCESS_PERM_SHIFT UINT32_C(0) 316 #define FFA_MEM_PERM_DATA_ACCESS_PERM_MASK GENMASK_32(1, 0) 317 318 #define FFA_MEM_PERM_DATA_ACCESS_PERM_NO_ACCESS UINT32_C(0x00) 319 #define FFA_MEM_PERM_DATA_ACCESS_PERM_RW UINT32_C(0x01) 320 #define FFA_MEM_PERM_DATA_ACCESS_PERM_RESERVED UINT32_C(0x02) 321 #define FFA_MEM_PERM_DATA_ACCESS_PERM_RO UINT32_C(0x03) 322 323 #define FFA_MEM_PERM_INSTRUCTION_ACCESS_PERM_INDEX UINT32_C(2) 324 #define FFA_MEM_PERM_INSTRUCTION_ACCESS_PERM_MASK BIT(2) 325 326 #define FFA_MEM_PERM_INSTRUCTION_ACCESS_PERM_X UINT32_C(0x00) 327 #define FFA_MEM_PERM_INSTRUCTION_ACCESS_PERM_NX BIT(2) 328 329 #define FFA_MEM_PERM_RESERVED_MASK GENMASK_32(31, 3) 330 331 /* FFA_CONSOLE_LOG */ 332 #define FFA_CONSOLE_LOG_32_MAX_LENGTH UINT32_C(24) 333 #define FFA_CONSOLE_LOG_64_MAX_LENGTH UINT32_C(48) 334 335 #endif /* LIBSP_INCLUDE_FFA_API_DEFINES_H_ */ 336