1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 /* 20 * Subset of Arm PSA Firmware Framework for Arm v8-A 1.0 EAC 21 * (https://developer.arm.com/docs/den0077/a) needed for shared memory. 22 */ 23 24 #include <interface/smc/smc_def.h> 25 #include <stdint.h> 26 27 #ifndef STATIC_ASSERT 28 #define STATIC_ASSERT(e) _Static_assert(e, #e) 29 #endif 30 31 #define FFA_CURRENT_VERSION_MAJOR (1U) 32 #define FFA_CURRENT_VERSION_MINOR (2U) 33 34 #define FFA_VERSION_TO_MAJOR(version) ((version) >> 16) 35 #define FFA_VERSION_TO_MINOR(version) ((version) & (0xffff)) 36 #define FFA_VERSION(major, minor) (((major) << 16) | (minor)) 37 #define FFA_CURRENT_VERSION \ 38 FFA_VERSION(FFA_CURRENT_VERSION_MAJOR, FFA_CURRENT_VERSION_MINOR) 39 40 #define SMC_ENTITY_SHARED_MEMORY 4 41 42 #define SMC_FASTCALL_NR_SHARED_MEMORY(nr) \ 43 SMC_FASTCALL_NR(SMC_ENTITY_SHARED_MEMORY, nr) 44 #define SMC_FASTCALL64_NR_SHARED_MEMORY(nr) \ 45 SMC_FASTCALL64_NR(SMC_ENTITY_SHARED_MEMORY, nr) 46 47 #define FFA_PAGE_SIZE (4096) 48 49 /** 50 * typedef ffa_endpoint_id16_t - Endpoint ID 51 * 52 * Current implementation only supports VMIDs. FFA spec also support stream 53 * endpoint ids. 54 */ 55 typedef uint16_t ffa_endpoint_id16_t; 56 57 /** 58 * struct ffa_cons_mrd - Constituent memory region descriptor 59 * @address: 60 * Start address of contiguous memory region. Must be 4K page aligned. 61 * @page_count: 62 * Number of 4K pages in region. 63 * @reserved_12_15: 64 * Reserve bytes 12-15 to pad struct size to 16 bytes. 65 */ 66 struct ffa_cons_mrd { 67 uint64_t address; 68 uint32_t page_count; 69 uint32_t reserved_12_15; 70 }; 71 STATIC_ASSERT(sizeof(struct ffa_cons_mrd) == 16); 72 73 /** 74 * struct ffa_comp_mrd - Composite memory region descriptor 75 * @total_page_count: 76 * Number of 4k pages in memory region. Must match sum of 77 * @address_range_array[].page_count. 78 * @address_range_count: 79 * Number of entries in @address_range_array. 80 * @reserved_8_15: 81 * Reserve bytes 8-15 to pad struct size to 16 byte alignment and 82 * make @address_range_array 16 byte aligned. 83 * @address_range_array: 84 * Array of &struct ffa_cons_mrd entries. 85 */ 86 struct ffa_comp_mrd { 87 uint32_t total_page_count; 88 uint32_t address_range_count; 89 uint64_t reserved_8_15; 90 struct ffa_cons_mrd address_range_array[]; 91 }; 92 STATIC_ASSERT(sizeof(struct ffa_comp_mrd) == 16); 93 94 /** 95 * typedef ffa_mem_attr8_t - Memory region attributes 96 * 97 * * @FFA_MEM_ATTR_DEVICE_NGNRNE: 98 * Device-nGnRnE. 99 * * @FFA_MEM_ATTR_DEVICE_NGNRE: 100 * Device-nGnRE. 101 * * @FFA_MEM_ATTR_DEVICE_NGRE: 102 * Device-nGRE. 103 * * @FFA_MEM_ATTR_DEVICE_GRE: 104 * Device-GRE. 105 * * @FFA_MEM_ATTR_NORMAL_MEMORY_UNCACHED 106 * Normal memory. Non-cacheable. 107 * * @FFA_MEM_ATTR_NORMAL_MEMORY_CACHED_WB 108 * Normal memory. Write-back cached. 109 * * @FFA_MEM_ATTR_NON_SHAREABLE 110 * Non-shareable. Combine with FFA_MEM_ATTR_NORMAL_MEMORY_*. 111 * * @FFA_MEM_ATTR_OUTER_SHAREABLE 112 * Outer Shareable. Combine with FFA_MEM_ATTR_NORMAL_MEMORY_*. 113 * * @FFA_MEM_ATTR_INNER_SHAREABLE 114 * Inner Shareable. Combine with FFA_MEM_ATTR_NORMAL_MEMORY_*. 115 * * @FFA_MEM_ATTR_NONSECURE 116 * Nonsecure. 117 * Uses reserved bit 6, the same bit which a NONSECURE flag is in a 118 * spec draft. 119 */ 120 typedef uint8_t ffa_mem_attr8_t; 121 #define FFA_MEM_ATTR_DEVICE_NGNRNE ((1U << 4) | (0x0U << 2)) 122 #define FFA_MEM_ATTR_DEVICE_NGNRE ((1U << 4) | (0x1U << 2)) 123 #define FFA_MEM_ATTR_DEVICE_NGRE ((1U << 4) | (0x2U << 2)) 124 #define FFA_MEM_ATTR_DEVICE_GRE ((1U << 4) | (0x3U << 2)) 125 #define FFA_MEM_ATTR_NORMAL_MEMORY_UNCACHED ((2U << 4) | (0x1U << 2)) 126 #define FFA_MEM_ATTR_NORMAL_MEMORY_CACHED_WB ((2U << 4) | (0x3U << 2)) 127 #define FFA_MEM_ATTR_NON_SHAREABLE (0x0U << 0) 128 #define FFA_MEM_ATTR_OUTER_SHAREABLE (0x2U << 0) 129 #define FFA_MEM_ATTR_INNER_SHAREABLE (0x3U << 0) 130 #define FFA_MEM_ATTR_NONSECURE (1U << 6) 131 132 /** 133 * typedef ffa_mem_perm8_t - Memory access permissions 134 * 135 * * @FFA_MEM_ATTR_RO 136 * Request or specify read-only mapping. 137 * * @FFA_MEM_ATTR_RW 138 * Request or allow read-write mapping. 139 * * @FFA_MEM_PERM_NX 140 * Deny executable mapping. 141 * * @FFA_MEM_PERM_X 142 * Request executable mapping. 143 */ 144 typedef uint8_t ffa_mem_perm8_t; 145 #define FFA_MEM_PERM_RO (1U << 0) 146 #define FFA_MEM_PERM_RW (1U << 1) 147 #define FFA_MEM_PERM_NX (1U << 2) 148 #define FFA_MEM_PERM_X (1U << 3) 149 150 /** 151 * typedef ffa_mem_flag8_t - Endpoint memory flags 152 * 153 * * @FFA_MEM_FLAG_NON_RETRIEVAL_BORROWER 154 * Non-retrieval Borrower. Memory region must not be or was not retrieved on 155 * behalf of this endpoint. 156 */ 157 typedef uint8_t ffa_mem_flag8_t; 158 #define FFA_MEM_FLAG_NON_RETRIEVAL_BORROWER (1U << 0) 159 160 /** 161 * typedef ffa_mtd_flag32_t - Memory transaction descriptor flags 162 * 163 * * @FFA_MTD_FLAG_ZERO_MEMORY 164 * Zero memory after unmapping from sender (must be 0 for share). 165 * * @FFA_MTD_FLAG_TIME_SLICING 166 * Not supported by this implementation. 167 * * @FFA_MTD_FLAG_ZERO_MEMORY_AFTER_RELINQUISH 168 * Zero memory after unmapping from borrowers (must be 0 for share). 169 * * @FFA_MTD_FLAG_TYPE_MASK 170 * Bit-mask to extract memory management transaction type from flags. 171 * * @FFA_MTD_FLAG_TYPE_SHARE_MEMORY 172 * Share memory transaction flag. 173 * Used by @SMC_FC_FFA_MEM_RETRIEVE_RESP to indicate that memory came from 174 * @SMC_FC_FFA_MEM_SHARE and by @SMC_FC_FFA_MEM_RETRIEVE_REQ to specify that 175 * it must have. 176 * * @FFA_MTD_FLAG_TYPE_LEND_MEMORY 177 * Lend memory transaction flag. 178 * Used by @SMC_FC_FFA_MEM_RETRIEVE_RESP to indicate that memory came from 179 * @SMC_FC_FFA_MEM_LEND and by @SMC_FC_FFA_MEM_RETRIEVE_REQ to specify that 180 * it must have. 181 * * @FFA_MTD_FLAG_TYPE_DONATE_MEMORY 182 * Donate memory transaction flag. 183 * Used by @SMC_FC_FFA_MEM_RETRIEVE_RESP to indicate that memory came from 184 * @SMC_FC_FFA_MEM_DONATE and by @SMC_FC_FFA_MEM_RETRIEVE_REQ to specify 185 * that it must have. 186 * * @FFA_MTD_FLAG_ADDRESS_RANGE_ALIGNMENT_HINT_MASK 187 * Not supported by this implementation. 188 */ 189 typedef uint32_t ffa_mtd_flag32_t; 190 #define FFA_MTD_FLAG_ZERO_MEMORY (1U << 0) 191 #define FFA_MTD_FLAG_TIME_SLICING (1U << 1) 192 #define FFA_MTD_FLAG_ZERO_MEMORY_AFTER_RELINQUISH (1U << 2) 193 #define FFA_MTD_FLAG_TYPE_MASK (3U << 3) 194 #define FFA_MTD_FLAG_TYPE_SHARE_MEMORY (1U << 3) 195 #define FFA_MTD_FLAG_TYPE_LEND_MEMORY (2U << 3) 196 #define FFA_MTD_FLAG_TYPE_DONATE_MEMORY (3U << 3) 197 #define FFA_MTD_FLAG_ADDRESS_RANGE_ALIGNMENT_HINT_MASK (0x1FU << 5) 198 199 /** 200 * typedef ffa_mem_relinquish_flag32_t - Memory relinquish descriptor flags 201 * 202 * * @FFA_MEM_RELINQUISH_FLAG_ZERO_MEMORY 203 * Zero memory after unmapping from sender (must be 0 for share). 204 * * @FFA_MEM_RELINQUISH_FLAG_TIME_SLICING 205 * Not supported by this implementation. 206 */ 207 typedef uint32_t ffa_mem_relinquish_flag32_t; 208 #define FFA_MEM_RELINQUISH_FLAG_ZERO_MEMORY (1U << 0) 209 #define FFA_MEM_RELINQUISH_FLAG_TIME_SLICING (1U << 1) 210 211 /** 212 * struct ffa_mapd - Memory access permissions descriptor 213 * @endpoint_id: 214 * Endpoint id that @memory_access_permissions and @flags apply to. 215 * (&typedef ffa_endpoint_id16_t). 216 * @memory_access_permissions: 217 * FFA_MEM_PERM_* values or'ed together (&typedef ffa_mem_perm8_t). 218 * @flags: 219 * FFA_MEM_FLAG_* values or'ed together (&typedef ffa_mem_flag8_t). 220 */ 221 struct ffa_mapd { 222 ffa_endpoint_id16_t endpoint_id; 223 ffa_mem_perm8_t memory_access_permissions; 224 ffa_mem_flag8_t flags; 225 }; 226 STATIC_ASSERT(sizeof(struct ffa_mapd) == 4); 227 228 /** 229 * struct ffa_emad - Endpoint memory access descriptor. 230 * @mapd: &struct ffa_mapd. 231 * @comp_mrd_offset: 232 * Offset of &struct ffa_comp_mrd form start of &struct ffa_mtd_common. 233 * @reserved_8_15: 234 * Reserved bytes 8-15. Must be 0. 235 */ 236 struct ffa_emad { 237 struct ffa_mapd mapd; 238 uint32_t comp_mrd_offset; 239 uint64_t reserved_8_15; 240 }; 241 STATIC_ASSERT(sizeof(struct ffa_emad) == 16); 242 243 /** 244 * struct ffa_mtd_common - Memory transaction descriptor. 245 * @sender_id: 246 * Sender endpoint id. 247 * @memory_region_attributes: 248 * FFA_MEM_ATTR_* values or'ed together (&typedef ffa_mem_attr8_t). 249 * @reserved_3: 250 * Reserved bytes 3. Must be 0. 251 * @flags: 252 * FFA_MTD_FLAG_* values or'ed together (&typedef ffa_mtd_flag32_t). 253 * @handle: 254 * Id of shared memory object. Most be 0 for MEM_SHARE. 255 * @tag: Client allocated tag. Must match original value. 256 */ 257 struct ffa_mtd_common { 258 ffa_endpoint_id16_t sender_id; 259 ffa_mem_attr8_t memory_region_attributes; 260 uint8_t reserved_3; 261 ffa_mtd_flag32_t flags; 262 uint64_t handle; 263 uint64_t tag; 264 }; 265 STATIC_ASSERT(sizeof(struct ffa_mtd_common) == 24); 266 267 /** 268 * struct ffa_mtd_v1_0 - Memory transaction descriptor for v1.0. 269 * @common: 270 * The common part of the descriptor (shared with v1.1). 271 * @reserved_24_27: 272 * Reserved bytes 24-27. Must be 0. 273 * @emad_count: 274 * Number of entries in @emad. Must be 1 in current implementation. 275 * FFA spec allows more entries. 276 * @emad: 277 * Endpoint memory access descriptor array (see @struct ffa_emad). 278 */ 279 struct ffa_mtd_v1_0 { 280 struct ffa_mtd_common common; 281 uint32_t reserved_24_27; 282 uint32_t emad_count; 283 struct ffa_emad emad[]; 284 }; 285 STATIC_ASSERT(sizeof(struct ffa_mtd_v1_0) == 32); 286 287 /** 288 * struct ffa_mtd_v1_1 - Memory transaction descriptor for v1.1 and higher. 289 * @common: 290 * The common part of the descriptor (shared with v1.0). 291 * @emad_size: 292 * Size of each endpoint memory access descriptor. 293 * @emad_count: 294 * Number of entries at @emad_offset. 295 * Must be 1 in current implementation. 296 * FFA spec allows more entries. 297 * @emad_offset: 298 * Offset from the base address of this descriptor to the 299 * endpoint memory access descriptor array (see @struct ffa_emad). 300 * @reserved_36: Reserved bytes at offset 36. Must be 0. 301 * @reserved_40: Reserved bytes at offset 40. Must be 0. 302 */ 303 struct ffa_mtd_v1_1 { 304 struct ffa_mtd_common common; 305 uint32_t emad_size; 306 uint32_t emad_count; 307 uint32_t emad_offset; 308 uint32_t reserved_36; 309 uint64_t reserved_40; 310 }; 311 STATIC_ASSERT(sizeof(struct ffa_mtd_v1_1) == 48); 312 313 /** 314 * struct ffa_mem_relinquish_descriptor - Relinquish request descriptor. 315 * @handle: 316 * Id of shared memory object to relinquish. 317 * @flags: 318 * FFA_MEM_RELINQUISH_FLAG_* values or'ed together 319 * (&typedef ffa_mem_relinquish_flag32_t). 320 * @endpoint_count: 321 * Number of entries in @endpoint_array. 322 * @endpoint_array: 323 * Array of endpoint ids. 324 */ 325 struct ffa_mem_relinquish_descriptor { 326 uint64_t handle; 327 uint32_t flags; 328 uint32_t endpoint_count; 329 ffa_endpoint_id16_t endpoint_array[]; 330 }; 331 STATIC_ASSERT(sizeof(struct ffa_mem_relinquish_descriptor) == 16); 332 333 /** 334 * typedef ffa_features2_t - FFA_FEATURES values returned in w2 335 * 336 * * @FFA_FEATURES2_RXTX_MAP_BUF_SIZE_MASK 337 * For RXTX_MAP: min buffer size and alignment boundary mask. 338 * * @FFA_FEATURES2_RXTX_MAP_BUF_SIZE_4K 339 * For RXTX_MAP: min buffer size and alignment boundary is 4K. 340 * * @FFA_FEATURES2_RXTX_MAP_BUF_SIZE_64K 341 * For RXTX_MAP: min buffer size and alignment boundary is 64K. 342 * * @FFA_FEATURES2_RXTX_MAP_BUF_SIZE_16K 343 * For RXTX_MAP: min buffer size and alignment boundary is 16K. 344 * * @FFA_FEATURES2_MEM_DYNAMIC_BUFFER 345 * Supports custom buffers for memory transactions. 346 * * @FFA_FEATURES2_MEM_RETRIEVE_REQ_NS_BIT 347 * Supports setting the NS bit on retrieved descriptors. 348 * 349 * For all other bits and commands: must be 0. 350 */ 351 typedef uint32_t ffa_features2_t; 352 #define FFA_FEATURES2_RXTX_MAP_BUF_SIZE_MASK 0x3U 353 #define FFA_FEATURES2_RXTX_MAP_BUF_SIZE_4K 0x0U 354 #define FFA_FEATURES2_RXTX_MAP_BUF_SIZE_64K 0x1U 355 #define FFA_FEATURES2_RXTX_MAP_BUF_SIZE_16K 0x2U 356 #define FFA_FEATURES2_MEM_DYNAMIC_BUFFER 0x1U 357 #define FFA_FEATURES2_MEM_RETRIEVE_REQ_NS_BIT 0x2U 358 359 /** 360 * typedef ffa_features3_t - FFA_FEATURES values returned in w3 361 * 362 * * @FFA_FEATURES3_MEM_RETRIEVE_REQ_REFCOUNT_MASK 363 * For FFA_MEM_RETRIEVE_REQ, bit[7-0]: Number of times receiver can 364 * retrieve each memory region before relinquishing it specified as 365 * ((1U << (value + 1)) - 1 (or value = bits in reference count - 1). 366 * 367 * For all other bits and commands: must be 0. 368 */ 369 typedef uint32_t ffa_features3_t; 370 #define FFA_FEATURES3_MEM_RETRIEVE_REQ_REFCOUNT_MASK 0xffU 371 372 /** 373 * Flags passed to FFA_PARTITION_INFO_GET 374 * 375 * * @FFA_PARTITION_INFO_GET_FLAG_RETURN_COUNT_ONLY 376 * Return only the count of partitions corresponding to the given UUID. 377 */ 378 typedef uint32_t ffa_partition_info_get_flag32_t; 379 #define FFA_PARTITION_INFO_GET_FLAG_RETURN_COUNT_ONLY (1U << 0) 380 381 struct ffa_part_info_desc { 382 uint16_t partition_id; 383 uint16_t exec_ctx_or_proxy_id; 384 uint32_t properties; 385 uint64_t uuid_lo; 386 uint64_t uuid_hi; 387 }; 388 STATIC_ASSERT(sizeof(struct ffa_part_info_desc) == 24); 389 390 /** 391 * enum ffa_error - FF-A error code 392 * @FFA_ERROR_NOT_SUPPORTED: 393 * Operation is not supported by the current implementation. 394 * @FFA_ERROR_INVALID_PARAMETERS: 395 * Invalid parameters. Conditions function specific. 396 * @FFA_ERROR_NO_MEMORY: 397 * Not enough memory. 398 * @FFA_ERROR_BUSY: 399 * Operation temporarily not possible. Conditions function specific. 400 * @FFA_ERROR_INTERRUPTED: 401 * This error code is not specified in the FF-A specification. 402 * @FFA_ERROR_DENIED: 403 * Operation not allowed. Conditions function specific. 404 * @FFA_ERROR_RETRY: 405 * Operation temporarily not possible. Conditions function specific. 406 * @FFA_ERROR_ABORTED: 407 * Operation aborted. Reason for abort is implementation specific. 408 * @FFA_ERROR_NO_DATA: 409 * Requested information not available. 410 * @FFA_ERROR_NOT_READY: 411 * Callee is not ready to handle the request. 412 * 413 */ 414 enum ffa_error { 415 FFA_ERROR_NOT_SUPPORTED = -1, 416 FFA_ERROR_INVALID_PARAMETERS = -2, 417 FFA_ERROR_NO_MEMORY = -3, 418 FFA_ERROR_BUSY = -4, 419 FFA_ERROR_INTERRUPTED = -5, 420 FFA_ERROR_DENIED = -6, 421 FFA_ERROR_RETRY = -7, 422 FFA_ERROR_ABORTED = -8, 423 FFA_ERROR_NO_DATA = -9, 424 FFA_ERROR_NOT_READY = -10, 425 }; 426 427 /** 428 * SMC_FC32_FFA_MIN - First 32 bit SMC opcode reserved for FFA 429 */ 430 #define SMC_FC32_FFA_MIN SMC_FASTCALL_NR_SHARED_MEMORY(0x60) 431 432 /** 433 * SMC_FC32_FFA_MAX - Last 32 bit SMC opcode reserved for FFA 434 */ 435 #define SMC_FC32_FFA_MAX SMC_FASTCALL_NR_SHARED_MEMORY(0x7F) 436 437 /** 438 * SMC_FC64_FFA_MIN - First 64 bit SMC opcode reserved for FFA 439 */ 440 #define SMC_FC64_FFA_MIN SMC_FASTCALL64_NR_SHARED_MEMORY(0x60) 441 442 /** 443 * SMC_FC64_FFA_MAX - Last 64 bit SMC opcode reserved for FFA 444 */ 445 #define SMC_FC64_FFA_MAX SMC_FASTCALL64_NR_SHARED_MEMORY(0x7F) 446 447 /** 448 * SMC_FC_FFA_ERROR - SMC error return opcode 449 * 450 * Register arguments: 451 * 452 * * w1: VMID in [31:16], vCPU in [15:0] 453 * * w2: Error code (&enum ffa_error) 454 */ 455 #define SMC_FC_FFA_ERROR SMC_FASTCALL_NR_SHARED_MEMORY(0x60) 456 457 /** 458 * SMC_FC_FFA_SUCCESS - 32 bit SMC success return opcode 459 * 460 * Register arguments: 461 * 462 * * w1: VMID in [31:16], vCPU in [15:0] 463 * * w2-w7: Function specific 464 */ 465 #define SMC_FC_FFA_SUCCESS SMC_FASTCALL_NR_SHARED_MEMORY(0x61) 466 467 /** 468 * SMC_FC64_FFA_SUCCESS - 64 bit SMC success return opcode 469 * 470 * Register arguments: 471 * 472 * * w1: VMID in [31:16], vCPU in [15:0] 473 * * w2/x2-w7/x7: Function specific 474 */ 475 #define SMC_FC64_FFA_SUCCESS SMC_FASTCALL64_NR_SHARED_MEMORY(0x61) 476 477 /** 478 * SMC_FC_FFA_INTERRUPT - SMC interrupt return opcode 479 * 480 * Register arguments: 481 * 482 * * w1: VMID in [31:16], vCPU in [15:0] 483 * * w2: Interrupt ID 484 */ 485 #define SMC_FC_FFA_INTERRUPT SMC_FASTCALL_NR_SHARED_MEMORY(0x62) 486 487 /** 488 * SMC_FC_FFA_VERSION - SMC opcode to return supported FF-A version 489 * 490 * Register arguments: 491 * 492 * * w1: Major version bit[30:16] and minor version in bit[15:0] supported 493 * by caller. Bit[31] must be 0. 494 * 495 * Return: 496 * * w0: &SMC_FC_FFA_SUCCESS 497 * * w2: Major version bit[30:16], minor version in bit[15:0], bit[31] must 498 * be 0. 499 * 500 * or 501 * 502 * * w0: &SMC_FC_FFA_ERROR 503 * * w2: %FFA_ERROR_NOT_SUPPORTED if major version passed in is less than 504 * the minimum major version supported. 505 */ 506 #define SMC_FC_FFA_VERSION SMC_FASTCALL_NR_SHARED_MEMORY(0x63) 507 508 /** 509 * SMC_FC_FFA_FEATURES - SMC opcode to check optional feature support 510 * 511 * Register arguments: 512 * 513 * * w1: FF-A function ID 514 * 515 * Return: 516 * * w0: &SMC_FC_FFA_SUCCESS 517 * * w2: &typedef ffa_features2_t 518 * * w3: &typedef ffa_features3_t 519 * 520 * or 521 * 522 * * w0: &SMC_FC_FFA_ERROR 523 * * w2: %FFA_ERROR_NOT_SUPPORTED if function is not implemented, or 524 * %FFA_ERROR_INVALID_PARAMETERS if function id is not valid. 525 */ 526 #define SMC_FC_FFA_FEATURES SMC_FASTCALL_NR_SHARED_MEMORY(0x64) 527 528 /** 529 * SMC_FC_FFA_RX_RELEASE - SMC opcode to Relinquish ownership of a RX buffer 530 * 531 * Return: 532 * * w0: &SMC_FC_FFA_SUCCESS 533 * 534 * or 535 * 536 * * w0: &SMC_FC_FFA_ERROR 537 * * w2: %FFA_ERROR_DENIED Caller did not have ownership of the RX buffer. 538 * %FFA_ERROR_NOT_SUPPORTED if operation not supported 539 */ 540 #define SMC_FC_FFA_RX_RELEASE SMC_FASTCALL_NR_SHARED_MEMORY(0x65) 541 542 /** 543 * SMC_FC_FFA_RXTX_MAP - 32 bit SMC opcode to map message buffers 544 * 545 * Register arguments: 546 * 547 * * w1: TX address 548 * * w2: RX address 549 * * w3: RX/TX page count in bit[5:0] 550 * 551 * Return: 552 * * w0: &SMC_FC_FFA_SUCCESS 553 */ 554 #define SMC_FC_FFA_RXTX_MAP SMC_FASTCALL_NR_SHARED_MEMORY(0x66) 555 556 /** 557 * SMC_FC64_FFA_RXTX_MAP - 64 bit SMC opcode to map message buffers 558 * 559 * Register arguments: 560 * 561 * * x1: TX address 562 * * x2: RX address 563 * * x3: RX/TX page count in bit[5:0] 564 * 565 * Return: 566 * * w0: &SMC_FC_FFA_SUCCESS 567 */ 568 #define SMC_FC64_FFA_RXTX_MAP SMC_FASTCALL64_NR_SHARED_MEMORY(0x66) 569 570 /** 571 * SMC_FC_FFA_RXTX_UNMAP - SMC opcode to unmap message buffers 572 * 573 * Register arguments: 574 * 575 * * w1: ID in [31:16] 576 * 577 * Return: 578 * * w0: &SMC_FC_FFA_SUCCESS 579 */ 580 #define SMC_FC_FFA_RXTX_UNMAP SMC_FASTCALL_NR_SHARED_MEMORY(0x67) 581 582 /** 583 * SMC_FC_FFA_PARTITION_INFO_GET - SMC opcode to get info about FF-A components 584 * 585 * Register arguments: 586 * 587 * w1: Bytes[0..3] of UUID in little-endian. 588 * w2: Bytes[4..7] of UUID in little-endian. 589 * w3: Bytes[8..11] of UUID in little-endian. 590 * w4: Bytes[12..15] of UUID in little-endian. 591 * w5: bit[0] : Information type flag. 1 for just the partition count 592 * with the UUID and 0 for the partition info descriptors. 593 * bit[31:1] : SBZ 594 * w6-w7: Reserved (SBZ). 595 * 596 */ 597 #define SMC_FC_FFA_PARTITION_INFO_GET SMC_FASTCALL_NR_SHARED_MEMORY(0x68) 598 599 /** 600 * SMC_FC_FFA_ID_GET - SMC opcode to get endpoint id of caller 601 * 602 * Return: 603 * * w0: &SMC_FC_FFA_SUCCESS 604 * * w2: ID in bit[15:0], bit[31:16] must be 0. 605 */ 606 #define SMC_FC_FFA_ID_GET SMC_FASTCALL_NR_SHARED_MEMORY(0x69) 607 608 /** 609 * SMC_FC_FFA_MSG_WAIT - SMC opcode to transition from running to waiting state 610 */ 611 #define SMC_FC_FFA_MSG_WAIT SMC_FASTCALL_NR_SHARED_MEMORY(0x6B) 612 613 /** 614 * SMC_FC_FFA_YIELD - SMC opcode to yield execution back to the component that 615 * scheduled it. 616 * 617 * Register arguments: 618 * 619 * * w1: Endpoint ID in [31:16], vCPU in [15:0]. 620 * * w2: Lower 32-bits of timeout interval in nanoseconds after which vCPU 621 * in w1 must run. 622 * * w3: Upper 32-bits of timeout interval in nanoseconds after which vCPU 623 * in w1 must run. 624 */ 625 #define SMC_FC_FFA_YIELD SMC_FASTCALL_NR_SHARED_MEMORY(0x6C) 626 627 /** 628 * SMC_FC_FFA_MSG_RUN - SMC opcode to allocate cycles to an endpoint 629 * 630 * Register arguments: 631 * 632 * * w1: SP/VM ID in [31:16], vCPU in [15:0] 633 */ 634 #define SMC_FC_FFA_RUN SMC_FASTCALL_NR_SHARED_MEMORY(0x6D) 635 636 /** 637 * SMC_FC_FFA_MSG_SEND_DIRECT_REQ - 32 bit SMC opcode to send direct message as 638 * a request 639 * 640 * Register arguments: 641 * 642 * * w1: Sender ID in bit[31:16], receiver ID in [15:0] 643 * * w2: Message Flags. 644 * bit[31] : Message type. 0 for partition message and 1 for 645 * framework message. 646 * bit[30:8] : Reserved. Must be 0. 647 * bit[7:0] : Framework message type. Must be 0 if partition message. 648 * * w3-w7: Implementation defined. 649 */ 650 #define SMC_FC_FFA_MSG_SEND_DIRECT_REQ SMC_FASTCALL_NR_SHARED_MEMORY(0x6F) 651 652 /** 653 * SMC_FC64_FFA_MSG_SEND_DIRECT_REQ - 64 bit SMC opcode to send direct message 654 * as a request 655 * 656 * Register arguments: 657 * 658 * * w1: Sender ID in bit[31:16], receiver ID in [15:0] 659 * * w2: Message Flags. 660 * bit[31] : Message type. 0 for partition message and 1 for 661 * framework message. 662 * bit[30:8] : Reserved. Must be 0. 663 * bit[7:0] : Framework message type. Must be 0 if partition message. 664 * * x3-x7: Implementation defined. 665 */ 666 #define SMC_FC64_FFA_MSG_SEND_DIRECT_REQ SMC_FASTCALL64_NR_SHARED_MEMORY(0x6F) 667 668 /** 669 * SMC_FC_FFA_MSG_SEND_DIRECT_RESP - 32 bit SMC opcode to send direct message as 670 * a response 671 * 672 * Register arguments: 673 * 674 * * w1: Sender ID in bit[31:16], receiver ID in [15:0] 675 * * w2: Message Flags. 676 * bit[31] : Message type. 0 for partition message and 1 for 677 * framework message. 678 * bit[30:8] : Reserved. Must be 0. 679 * bit[7:0] : Framework message type. Must be 0 if partition message. 680 * * w3-w7: Implementation defined. 681 */ 682 #define SMC_FC_FFA_MSG_SEND_DIRECT_RESP SMC_FASTCALL_NR_SHARED_MEMORY(0x70) 683 684 /** 685 * SMC_FC64_FFA_MSG_SEND_DIRECT_RESP - 64 bit SMC opcode to send direct message 686 * as a response 687 * 688 * Register arguments: 689 * 690 * * w1: Sender ID in bit[31:16], receiver ID in [15:0] 691 * * w2: Message Flags. 692 * bit[31] : Message type. 0 for partition message and 1 for 693 * framework message. 694 * bit[30:8] : Reserved. Must be 0. 695 * bit[7:0] : Framework message type. Must be 0 if partition message. 696 * * x3-x7: Implementation defined. 697 */ 698 #define SMC_FC64_FFA_MSG_SEND_DIRECT_RESP SMC_FASTCALL64_NR_SHARED_MEMORY(0x70) 699 700 /** 701 * SMC_FC64_FFA_MSG_SEND_DIRECT_REQ2 - 64 bit SMC opcode to send direct message 702 * as a request 703 * 704 * Register arguments: 705 * 706 * * w1: Sender ID in bit[31:16], receiver ID in [15:0] 707 * * x2: Bytes[0..7] of UUID. 708 * * x3: Bytes[8..15] of UUID. 709 * * x4-x17: Implementation defined. 710 */ 711 #define SMC_FC64_FFA_MSG_SEND_DIRECT_REQ2 SMC_FASTCALL64_NR_SHARED_MEMORY(0x8D) 712 713 /** 714 * SMC_FC64_FFA_MSG_SEND_DIRECT_RESP2 - 64 bit SMC opcode to send direct message 715 * as a response 716 * 717 * Register arguments: 718 * 719 * * w1: Sender ID in bit[31:16], receiver ID in [15:0] 720 * * w2: Should be zero. 721 * * w3: Should be zero. 722 * * x4-x17: Implementation defined. 723 */ 724 #define SMC_FC64_FFA_MSG_SEND_DIRECT_RESP2 SMC_FASTCALL64_NR_SHARED_MEMORY(0x8E) 725 726 /** 727 * SMC_FC_FFA_MEM_DONATE - 32 bit SMC opcode to donate memory 728 * 729 * Not supported. 730 */ 731 #define SMC_FC_FFA_MEM_DONATE SMC_FASTCALL_NR_SHARED_MEMORY(0x71) 732 733 /** 734 * SMC_FC_FFA_MEM_LEND - 32 bit SMC opcode to lend memory 735 * 736 * Not currently supported. 737 */ 738 #define SMC_FC_FFA_MEM_LEND SMC_FASTCALL_NR_SHARED_MEMORY(0x72) 739 740 /** 741 * SMC_FC_FFA_MEM_SHARE - 32 bit SMC opcode to share memory 742 * 743 * Register arguments: 744 * 745 * * w1: Total length 746 * * w2: Fragment length 747 * * w3: Address 748 * * w4: Page count 749 * 750 * Return: 751 * * w0: &SMC_FC_FFA_SUCCESS 752 * * w2/w3: Handle 753 * 754 * or 755 * 756 * * w0: &SMC_FC_FFA_MEM_FRAG_RX 757 * * w1-: See &SMC_FC_FFA_MEM_FRAG_RX 758 * 759 * or 760 * 761 * * w0: &SMC_FC_FFA_ERROR 762 * * w2: Error code (&enum ffa_error) 763 */ 764 #define SMC_FC_FFA_MEM_SHARE SMC_FASTCALL_NR_SHARED_MEMORY(0x73) 765 766 /** 767 * SMC_FC64_FFA_MEM_SHARE - 64 bit SMC opcode to share memory 768 * 769 * Register arguments: 770 * 771 * * w1: Total length 772 * * w2: Fragment length 773 * * x3: Address 774 * * w4: Page count 775 * 776 * Return: 777 * * w0: &SMC_FC_FFA_SUCCESS 778 * * w2/w3: Handle 779 * 780 * or 781 * 782 * * w0: &SMC_FC_FFA_MEM_FRAG_RX 783 * * w1-: See &SMC_FC_FFA_MEM_FRAG_RX 784 * 785 * or 786 * 787 * * w0: &SMC_FC_FFA_ERROR 788 * * w2: Error code (&enum ffa_error) 789 */ 790 #define SMC_FC64_FFA_MEM_SHARE SMC_FASTCALL64_NR_SHARED_MEMORY(0x73) 791 792 /** 793 * SMC_FC_FFA_MEM_RETRIEVE_REQ - 32 bit SMC opcode to retrieve shared memory 794 * 795 * Register arguments: 796 * 797 * * w1: Total length 798 * * w2: Fragment length 799 * * w3: Address 800 * * w4: Page count 801 * 802 * Return: 803 * * w0: &SMC_FC_FFA_MEM_RETRIEVE_RESP 804 * * w1/x1-w5/x5: See &SMC_FC_FFA_MEM_RETRIEVE_RESP 805 */ 806 #define SMC_FC_FFA_MEM_RETRIEVE_REQ SMC_FASTCALL_NR_SHARED_MEMORY(0x74) 807 808 /** 809 * SMC_FC64_FFA_MEM_RETRIEVE_REQ - 64 bit SMC opcode to retrieve shared memory 810 * 811 * Register arguments: 812 * 813 * * w1: Total length 814 * * w2: Fragment length 815 * * x3: Address 816 * * w4: Page count 817 * 818 * Return: 819 * * w0: &SMC_FC_FFA_MEM_RETRIEVE_RESP 820 * * w1/x1-w5/x5: See &SMC_FC_FFA_MEM_RETRIEVE_RESP 821 */ 822 #define SMC_FC64_FFA_MEM_RETRIEVE_REQ SMC_FASTCALL64_NR_SHARED_MEMORY(0x74) 823 824 /** 825 * SMC_FC_FFA_MEM_RETRIEVE_RESP - Retrieve 32 bit SMC return opcode 826 * 827 * Register arguments: 828 * 829 * * w1: Total length 830 * * w2: Fragment length 831 */ 832 #define SMC_FC_FFA_MEM_RETRIEVE_RESP SMC_FASTCALL_NR_SHARED_MEMORY(0x75) 833 834 /** 835 * SMC_FC_FFA_MEM_RELINQUISH - SMC opcode to relinquish shared memory 836 * 837 * Input in &struct ffa_mem_relinquish_descriptor format in message buffer. 838 * 839 * Return: 840 * * w0: &SMC_FC_FFA_SUCCESS 841 */ 842 #define SMC_FC_FFA_MEM_RELINQUISH SMC_FASTCALL_NR_SHARED_MEMORY(0x76) 843 844 /** 845 * SMC_FC_FFA_MEM_RECLAIM - SMC opcode to reclaim shared memory 846 * 847 * Register arguments: 848 * 849 * * w1/w2: Handle 850 * * w3: Flags 851 * 852 * Return: 853 * * w0: &SMC_FC_FFA_SUCCESS 854 */ 855 #define SMC_FC_FFA_MEM_RECLAIM SMC_FASTCALL_NR_SHARED_MEMORY(0x77) 856 857 /** 858 * SMC_FC_FFA_MEM_FRAG_RX - SMC opcode to request next fragment. 859 * 860 * Register arguments: 861 * 862 * * w1/w2: Handle 863 * * w3: Fragment offset. 864 * * w4: Endpoint id ID in [31:16], if client is hypervisor. 865 * 866 * Return: 867 * * w0: &SMC_FC_FFA_MEM_FRAG_TX 868 * * w1/x1-w5/x5: See &SMC_FC_FFA_MEM_FRAG_TX 869 */ 870 #define SMC_FC_FFA_MEM_FRAG_RX SMC_FASTCALL_NR_SHARED_MEMORY(0x7A) 871 872 /** 873 * SMC_FC_FFA_MEM_FRAG_TX - SMC opcode to transmit next fragment 874 * 875 * Register arguments: 876 * 877 * * w1/w2: Handle 878 * * w3: Fragment length. 879 * * w4: Sender endpoint id ID in [31:16], if client is hypervisor. 880 * 881 * Return: 882 * * w0: &SMC_FC_FFA_MEM_FRAG_RX or &SMC_FC_FFA_SUCCESS. 883 * * w1/x1-w5/x5: See opcode in w0. 884 */ 885 #define SMC_FC_FFA_MEM_FRAG_TX SMC_FASTCALL_NR_SHARED_MEMORY(0x7B) 886 887 /** 888 * SMC_FC_FFA_CONSOLE_LOG - SMC opcode to log to console 889 * 890 * Register arguments: 891 * 892 * * w1: Count of characters 893 * * w2/x2-w7/x7: Packed characters 894 * 895 * Return: 896 * * w0: &SMC_FC_FFA_SUCCESS 897 * 898 * or 899 * 900 * * w0: &SMC_FC_FFA_ERROR 901 * * w2: Error code (&enum ffa_error) 902 * * w3: Num characters logged (if w2 is RETRY) 903 */ 904 #define SMC_FC_FFA_CONSOLE_LOG SMC_FASTCALL_NR_SHARED_MEMORY(0x8A) 905 #define SMC_FC64_FFA_CONSOLE_LOG SMC_FASTCALL64_NR_SHARED_MEMORY(0x8A) 906 907 /* FF-A v1.1 */ 908 /** 909 * SMC_FC64_FFA_SECONDARY_EP_REGISTER - SMC opcode to register secondary 910 * core entrypoint. 911 * 912 * Register arguments: 913 * 914 * * x1: Entry point address of a secondary execution context 915 * 916 * Return: 917 * * x0: &SMC_FC64_FFA_SUCCESS 918 * 919 * or 920 * 921 * * x0: &SMC_FC_FFA_ERROR 922 * * x2: %FFA_ERROR_NOT_SUPPORTED Not supported 923 * %FFA_ERROR_INVALID_PARAMETERS Invalid entry point specified 924 */ 925 #define SMC_FC64_FFA_SECONDARY_EP_REGISTER SMC_FASTCALL64_NR_SHARED_MEMORY(0x87) 926 927 /* Framework messages */ 928 /** 929 * FFA_FRAMEWORK_MSG_FLAG - Direct message flag for framework messages. 930 * 931 * Framework messages have &FFA_FRAMEWORK_MSG_FLAG set in w2. 932 */ 933 #define FFA_FRAMEWORK_MSG_FLAG (1U << 31) 934 935 /** 936 * FFA_FRAMEWORK_MSG_MASK - Mask for the framework message type. 937 * 938 * Mask the value in w2 against &FFA_FRAMEWORK_MSG_MASK 939 * to get the framework message type. 940 */ 941 #define FFA_FRAMEWORK_MSG_MASK (0xffU) 942 943 /** 944 * FFA_FRAMEWORK_MSG_VM_CREATED_REQ - VM creation request. 945 * 946 * Register arguments: 947 * 948 * * w0: &SMC_FC_FFA_MSG_SEND_DIRECT_REQ 949 * * w1: Hypervisor ID in bit[31:16], SP ID in [15:0] 950 * * w2: Message Flags. 951 * bit[31] : 1 for framework message. 952 * bit[30:8] : Reserved. Must be 0. 953 * bit[7:0] : &FFA_FRAMEWORK_MSG_VM_CREATED_REQ 954 * * w3/w4: Handle to identify a memory region. 955 * * w5: ID of VM in [15:0], remaining SBZ. 956 * * w6-7: Should be zero. 957 */ 958 #define FFA_FRAMEWORK_MSG_VM_CREATED_REQ 4 959 960 /** 961 * FFA_FRAMEWORK_MSG_VM_CREATED_RESP - VM creation response. 962 * 963 * Register arguments: 964 * 965 * * w0: &SMC_FC_FFA_MSG_SEND_DIRECT_RESP 966 * * w1: SP ID in bit[31:16], hypervisor ID in [15:0] 967 * * w2: Message Flags. 968 * bit[31] : 1 for framework message. 969 * bit[30:8] : Reserved. Must be 0. 970 * bit[7:0] : &FFA_FRAMEWORK_MSG_VM_CREATED_RESP 971 * * w3: SP return status code: 972 * %0 in case of success 973 * %FFA_ERROR_INVALID_PARAMETERS 974 * %FFA_ERROR_INTERRUPTED 975 * %FFA_ERROR_DENIED 976 * %FFA_ERROR_RETRY 977 * * w4-7: Should be zero. 978 */ 979 #define FFA_FRAMEWORK_MSG_VM_CREATED_RESP 5 980 981 /** 982 * FFA_FRAMEWORK_MSG_VM_DESTROYED_REQ - VM destruction request. 983 * 984 * Register arguments: 985 * 986 * * w0: &SMC_FC_FFA_MSG_SEND_DIRECT_REQ 987 * * w1: Hypervisor ID in bit[31:16], SP ID in [15:0] 988 * * w2: Message Flags. 989 * bit[31] : 1 for framework message. 990 * bit[30:8] : Reserved. Must be 0. 991 * bit[7:0] : &FFA_FRAMEWORK_MSG_VM_DESTROYED_REQ 992 * * w3/w4: Handle to identify a memory region. 993 * * w5: ID of VM in [15:0], remaining SBZ. 994 * * w6-7: Should be zero. 995 */ 996 #define FFA_FRAMEWORK_MSG_VM_DESTROYED_REQ 6 997 998 /** 999 * FFA_FRAMEWORK_MSG_VM_DESTROYED_RESP - VM destruction response. 1000 * 1001 * Register arguments: 1002 * 1003 * * w0: &SMC_FC_FFA_MSG_SEND_DIRECT_RESP 1004 * * w1: SP ID in bit[31:16], hypervisor ID in [15:0] 1005 * * w2: Message Flags. 1006 * bit[31] : 1 for framework message. 1007 * bit[30:8] : Reserved. Must be 0. 1008 * bit[7:0] : &FFA_FRAMEWORK_MSG_VM_DESTROYED_RESP 1009 * * w3: SP return status code: 1010 * %0 in case of success 1011 * %FFA_ERROR_INVALID_PARAMETERS 1012 * %FFA_ERROR_INTERRUPTED 1013 * %FFA_ERROR_DENIED 1014 * %FFA_ERROR_RETRY 1015 * * w4-7: Should be zero. 1016 */ 1017 #define FFA_FRAMEWORK_MSG_VM_DESTROYED_RESP 7 1018