microsoft/mu_feature_ffa
Publicmirrored fromhttps://github.com/microsoft/mu_feature_ffaAvailable
FfaFeaturePkg/Include/Library/ArmFfaLibEx.h
510lines · modecode
| 1 | /** @file |
| 2 | Platform layer for the secure partition interrupt handler using FF-A. |
| 3 | |
| 4 | Copyright (c) 2020 - 2022, Arm Ltd. All rights reserved.<BR> |
| 5 | Copyright (c), Microsoft Corporation. |
| 6 | SPDX-License-Identifier: BSD-2-Clause-Patent |
| 7 | |
| 8 | **/ |
| 9 | |
| 10 | #ifndef FF_A_HELPER_LIB_H_ |
| 11 | #define FF_A_HELPER_LIB_H_ |
| 12 | |
| 13 | #include <Base.h> |
| 14 | |
| 15 | #if PcdGetBool (PcdFfaLibConduitSmc) == 1 |
| 16 | typedef ARM_SMC_ARGS ARM_SXC_ARGS; |
| 17 | #else |
| 18 | typedef ARM_SVC_ARGS ARM_SXC_ARGS; |
| 19 | #endif |
| 20 | |
| 21 | /** |
| 22 | * @brief Direct message type |
| 23 | */ |
| 24 | typedef struct { |
| 25 | UINT32 FunctionId; |
| 26 | |
| 27 | UINT16 SourceId; |
| 28 | |
| 29 | UINT16 DestinationId; |
| 30 | |
| 31 | /// Not applicable for v1 |
| 32 | EFI_GUID ServiceGuid; |
| 33 | |
| 34 | /// Implementation define argument 0, this will be set to/from x4(v2) |
| 35 | UINTN Arg0; |
| 36 | |
| 37 | /// Implementation define argument 1, this will be set to/from x5(v2) |
| 38 | UINTN Arg1; |
| 39 | |
| 40 | /// Implementation define argument 2, this will be set to/from x6(v2) |
| 41 | UINTN Arg2; |
| 42 | |
| 43 | /// Implementation define argument 3, this will be set to/from x7(v2) |
| 44 | UINTN Arg3; |
| 45 | |
| 46 | /// Implementation define argument 4, this will be set to/from x8(v2) |
| 47 | UINTN Arg4; |
| 48 | |
| 49 | /// Implementation define argument 5, this will be set to/from x9(v2) |
| 50 | UINTN Arg5; |
| 51 | |
| 52 | /// Implementation define argument 6, this will be set to/from x10(v2) |
| 53 | UINTN Arg6; |
| 54 | |
| 55 | /// Implementation define argument 7, this will be set to/from x11(v2) |
| 56 | UINTN Arg7; |
| 57 | |
| 58 | /// Implementation define argument 8, this will be set to/from x12(v2) |
| 59 | UINTN Arg8; |
| 60 | |
| 61 | /// Implementation define argument 9, this will be set to/from x13(v2) |
| 62 | UINTN Arg9; |
| 63 | |
| 64 | /// Implementation define argument 10, this will be set to/from x14(v2) |
| 65 | UINTN Arg10; |
| 66 | |
| 67 | /// Implementation define argument 11, this will be set to/from x15(v2) |
| 68 | UINTN Arg11; |
| 69 | |
| 70 | /// Implementation define argument 12, this will be set to/from x16(v2) |
| 71 | UINTN Arg12; |
| 72 | |
| 73 | /// Implementation define argument 13, this will be set to/from x17(v2) |
| 74 | UINTN Arg13; |
| 75 | } DIRECT_MSG_ARGS_EX; |
| 76 | |
| 77 | #pragma pack(1) |
| 78 | |
| 79 | /** |
| 80 | * Resource Information Descriptor Header |
| 81 | * Section 13.13: FFA_NS_RES_INFO_GET - Table 13.61 |
| 82 | */ |
| 83 | typedef struct { |
| 84 | UINT32 AmdSize; |
| 85 | UINT32 AmdCount; |
| 86 | UINT32 AmdOffset; |
| 87 | UINT32 Reserved; |
| 88 | } FFA_RESOURCE_INFO_DESC_HEADER; |
| 89 | |
| 90 | /** |
| 91 | * Address Map Descriptor |
| 92 | * Section 13.13: FFA_NS_RES_INFO_GET - Table 13.62 |
| 93 | */ |
| 94 | typedef struct { |
| 95 | UINT64 BaseAddress; |
| 96 | UINT32 PageCount; |
| 97 | UINT8 Permissions; |
| 98 | UINT16 EndpointId; |
| 99 | UINT8 Flags; |
| 100 | } FFA_ADDRESS_MAP_DESC; |
| 101 | #pragma pack() |
| 102 | |
| 103 | /** |
| 104 | * CPU cycle management interfaces |
| 105 | */ |
| 106 | |
| 107 | /** |
| 108 | * @brief Blocks the caller until a message is available or until an |
| 109 | * interrupt happens. It is also used to indicate the completion of |
| 110 | * the boot phase and the end of the interrupt handling. |
| 111 | * @note The ffa_interrupt_handler function can be called during the |
| 112 | * execution of this function. |
| 113 | * |
| 114 | * @param[out] msg The incoming message |
| 115 | * |
| 116 | * @return The FF-A error status code |
| 117 | */ |
| 118 | EFI_STATUS |
| 119 | EFIAPI |
| 120 | FfaMessageWait ( |
| 121 | OUT DIRECT_MSG_ARGS_EX *Message |
| 122 | ); |
| 123 | |
| 124 | /** Messaging interfaces */ |
| 125 | |
| 126 | /** |
| 127 | * @brief Sends a 32 bit partition message in parameter registers as a |
| 128 | * request and blocks until the response is available. |
| 129 | * @note The ffa_interrupt_handler function can be called during the |
| 130 | * execution of this function |
| 131 | * |
| 132 | * @param[in] source Source endpoint ID |
| 133 | * @param[in] dest Destination endpoint ID |
| 134 | * @param[in] a0,a1,a2,a3,a4 Implementation defined message values |
| 135 | * @param[out] msg The response message |
| 136 | * |
| 137 | * @return The FF-A error status code |
| 138 | */ |
| 139 | EFI_STATUS |
| 140 | EFIAPI |
| 141 | FfaMessageSendDirectReq2 ( |
| 142 | IN UINT16 DestPartId, |
| 143 | IN EFI_GUID *ServiceGuid OPTIONAL, |
| 144 | IN OUT DIRECT_MSG_ARGS_EX *ImpDefArgs |
| 145 | ); |
| 146 | |
| 147 | /** |
| 148 | * @brief Sends a 32 bit partition message in parameter registers as a |
| 149 | * response and blocks until the response is available. |
| 150 | * @note The ffa_interrupt_handler function can be called during the |
| 151 | * execution of this function |
| 152 | * |
| 153 | * @param[in] source Source endpoint ID |
| 154 | * @param[in] dest Destination endpoint ID |
| 155 | * @param[in] a0,a1,a2,a3,a4 Implementation defined message values |
| 156 | * @param[out] msg The response message |
| 157 | * |
| 158 | * @return The FF-A error status code |
| 159 | */ |
| 160 | EFI_STATUS |
| 161 | EFIAPI |
| 162 | FfaMessageSendDirectResp32 ( |
| 163 | DIRECT_MSG_ARGS_EX *req, |
| 164 | DIRECT_MSG_ARGS_EX *resp |
| 165 | ); |
| 166 | |
| 167 | /** |
| 168 | * @brief Sends a 64 bit partition message in parameter registers as a |
| 169 | * response and blocks until the response is available. |
| 170 | * @note The ffa_interrupt_handler function can be called during the |
| 171 | * execution of this function |
| 172 | * |
| 173 | * @param[in] source Source endpoint ID |
| 174 | * @param[in] dest Destination endpoint ID |
| 175 | * @param[in] a0,a1,a2,a3,a4 Implementation defined message values |
| 176 | * @param[out] msg The response message |
| 177 | * |
| 178 | * @return The FF-A error status code |
| 179 | */ |
| 180 | EFI_STATUS |
| 181 | EFIAPI |
| 182 | FfaMessageSendDirectResp64 ( |
| 183 | IN DIRECT_MSG_ARGS_EX *Request, |
| 184 | OUT DIRECT_MSG_ARGS_EX *Response |
| 185 | ); |
| 186 | |
| 187 | EFI_STATUS |
| 188 | EFIAPI |
| 189 | FfaMessageSendDirectResp2 ( |
| 190 | IN DIRECT_MSG_ARGS_EX *Request, |
| 191 | OUT DIRECT_MSG_ARGS_EX *Response |
| 192 | ); |
| 193 | |
| 194 | EFI_STATUS |
| 195 | EFIAPI |
| 196 | FfaNsResInfoGet ( |
| 197 | IN UINT16 TargetId, |
| 198 | IN UINT64 Flags, |
| 199 | OUT UINT32 *WrittenSize, |
| 200 | OUT UINT32 *RemainingSize |
| 201 | ); |
| 202 | |
| 203 | EFI_STATUS |
| 204 | EFIAPI |
| 205 | FfaNotificationSet ( |
| 206 | IN UINT16 DestinationId, |
| 207 | IN UINT64 Flags, |
| 208 | IN UINT64 NotificationBitmap |
| 209 | ); |
| 210 | |
| 211 | EFI_STATUS |
| 212 | EFIAPI |
| 213 | FfaNotificationGet ( |
| 214 | IN UINT16 VCpuId, |
| 215 | IN UINT64 Flags, |
| 216 | IN UINT64 *NotificationBitmap |
| 217 | ); |
| 218 | |
| 219 | EFI_STATUS |
| 220 | EFIAPI |
| 221 | FfaPartitionInfoGetRegs ( |
| 222 | IN EFI_GUID *ServiceGuid, |
| 223 | IN UINT16 StartIndex, |
| 224 | IN OUT UINT16 *Tag OPTIONAL, |
| 225 | IN OUT UINT32 *PartDescCount, |
| 226 | OUT EFI_FFA_PART_INFO_DESC *PartDesc OPTIONAL |
| 227 | ); |
| 228 | |
| 229 | EFI_STATUS |
| 230 | EFIAPI |
| 231 | FfaNotificationBitmapCreate ( |
| 232 | IN UINT16 VCpuCount |
| 233 | ); |
| 234 | |
| 235 | EFI_STATUS |
| 236 | EFIAPI |
| 237 | FfaNotificationBitmapDestroy ( |
| 238 | VOID |
| 239 | ); |
| 240 | |
| 241 | EFI_STATUS |
| 242 | EFIAPI |
| 243 | FfaNotificationBind ( |
| 244 | IN UINT16 DestinationId, |
| 245 | IN UINT32 Flags, |
| 246 | IN UINT64 NotificationBitmap |
| 247 | ); |
| 248 | |
| 249 | EFI_STATUS |
| 250 | EFIAPI |
| 251 | FfaNotificationUnbind ( |
| 252 | IN UINT16 DestinationId, |
| 253 | IN UINT64 NotificationBitmap |
| 254 | ); |
| 255 | |
| 256 | /** |
| 257 | * Memory management interfaces |
| 258 | * |
| 259 | * @note Functions with _rxtx suffix use the RX/TX buffers mapped by |
| 260 | * ffa_rxtx_map to transmit memory descriptors instead of an distinct buffer |
| 261 | * allocated by the owner. |
| 262 | */ |
| 263 | |
| 264 | /** |
| 265 | * @brief Starts a transaction to transfer of ownership of a memory region |
| 266 | * from a Sender endpoint to a Receiver endpoint. |
| 267 | * |
| 268 | * @param[in] total_length Total length of the memory transaction |
| 269 | * descriptor in bytes |
| 270 | * @param[in] fragment_length Length in bytes of the memory transaction |
| 271 | * descriptor passed in this ABI invocation |
| 272 | * @param[in] buffer_address Base address of a buffer allocated by the Owner |
| 273 | * and distinct from the TX buffer |
| 274 | * @param[in] page_count Number of 4K pages in the buffer allocated by |
| 275 | * the Owner and distinct from the TX buffer |
| 276 | * @param[out] handle Globally unique Handle to identify the memory |
| 277 | * region upon successful transmission of the |
| 278 | * transaction descriptor. |
| 279 | * |
| 280 | * @return The FF-A error status code |
| 281 | */ |
| 282 | EFI_STATUS |
| 283 | ffa_mem_donate ( |
| 284 | UINT32 total_length, |
| 285 | UINT32 fragment_length, |
| 286 | VOID *buffer_address, |
| 287 | UINT32 page_count, |
| 288 | UINT64 *handle |
| 289 | ); |
| 290 | |
| 291 | EFI_STATUS |
| 292 | ffa_mem_donate_rxtx ( |
| 293 | UINT32 total_length, |
| 294 | UINT32 fragment_length, |
| 295 | UINT64 *handle |
| 296 | ); |
| 297 | |
| 298 | /** |
| 299 | * @brief Starts a transaction to transfer an Owner’s access to a memory |
| 300 | * region and grant access to it to one or more Borrowers. |
| 301 | * |
| 302 | * @param[in] total_length Total length of the memory transaction |
| 303 | * descriptor in bytes |
| 304 | * @param[in] fragment_length Length in bytes of the memory transaction |
| 305 | * descriptor passed in this ABI invocation |
| 306 | * @param[in] buffer_address Base address of a buffer allocated by the Owner |
| 307 | * and distinct from the TX buffer |
| 308 | * @param[in] page_count Number of 4K pages in the buffer allocated by |
| 309 | * the Owner and distinct from the TX buffer |
| 310 | * @param[out] handle Globally unique Handle to identify the memory |
| 311 | * region upon successful transmission of the |
| 312 | * transaction descriptor. |
| 313 | * |
| 314 | * @return The FF-A error status code |
| 315 | */ |
| 316 | EFI_STATUS |
| 317 | EFIAPI |
| 318 | FfaMemLend ( |
| 319 | UINT32 TotalLength, |
| 320 | UINT32 FragmentLength, |
| 321 | VOID *BufferAddr, |
| 322 | UINT32 PageCount, |
| 323 | UINT64 *Handle |
| 324 | ); |
| 325 | |
| 326 | EFI_STATUS |
| 327 | EFIAPI |
| 328 | FfaMemLendRxTx ( |
| 329 | UINT32 TotalLength, |
| 330 | UINT32 FragmentLength, |
| 331 | UINT64 *Handle |
| 332 | ); |
| 333 | |
| 334 | /** |
| 335 | * @brief Starts a transaction to grant access to a memory region to one or |
| 336 | * more Borrowers. |
| 337 | * |
| 338 | * @param[in] total_length Total length of the memory transaction |
| 339 | * descriptor in bytes |
| 340 | * @param[in] fragment_length Length in bytes of the memory transaction |
| 341 | * descriptor passed in this ABI invocation |
| 342 | * @param[in] buffer_address Base address of a buffer allocated by the Owner |
| 343 | * and distinct from the TX buffer |
| 344 | * @param[in] page_count Number of 4K pages in the buffer allocated by |
| 345 | * the Owner and distinct from the TX buffer |
| 346 | * @param[out] handle Globally unique Handle to identify the memory |
| 347 | * region upon successful transmission of the |
| 348 | * transaction descriptor. |
| 349 | * |
| 350 | * @return The FF-A error status code |
| 351 | */ |
| 352 | EFI_STATUS |
| 353 | EFIAPI |
| 354 | FfaMemShare ( |
| 355 | UINT32 TotalLength, |
| 356 | UINT32 FragmentLength, |
| 357 | VOID *BufferAddr, |
| 358 | UINT32 PageCount, |
| 359 | UINT64 *Handle |
| 360 | ); |
| 361 | |
| 362 | EFI_STATUS |
| 363 | EFIAPI |
| 364 | FfaMemShareRxTx ( |
| 365 | UINT32 TotalLength, |
| 366 | UINT32 FragmentLength, |
| 367 | UINT64 *Handle |
| 368 | ); |
| 369 | |
| 370 | /** |
| 371 | * @brief Requests completion of a donate, lend or share memory management |
| 372 | * transaction. |
| 373 | * |
| 374 | * @param[in] total_length Total length of the memory transaction |
| 375 | * descriptor in bytes |
| 376 | * @param[in] fragment_length Length in bytes of the memory transaction |
| 377 | * descriptor passed in this ABI invocation |
| 378 | * @param[in] buffer_address Base address of a buffer allocated by the |
| 379 | * Owner and distinct from the TX buffer |
| 380 | * @param[in] page_count Number of 4K pages in the buffer allocated |
| 381 | * by the Owner and distinct from the TX |
| 382 | * buffer |
| 383 | * @param[out] resp_total_length Total length of the response memory |
| 384 | * transaction descriptor in bytes |
| 385 | * @param[out] resp_fragment_length Length in bytes of the response memory |
| 386 | * transaction descriptor passed in this ABI |
| 387 | * invocation |
| 388 | * |
| 389 | * @return The FF-A error status code |
| 390 | */ |
| 391 | EFI_STATUS |
| 392 | EFIAPI |
| 393 | FfaMemRetrieveReq ( |
| 394 | UINT32 TotalLength, |
| 395 | UINT32 FragmentLength, |
| 396 | VOID *BufferAddr, |
| 397 | UINT32 PageCount, |
| 398 | UINT32 *RespTotalLength, |
| 399 | UINT32 *RespFragmentLength |
| 400 | ); |
| 401 | |
| 402 | EFI_STATUS |
| 403 | EFIAPI |
| 404 | FfaMemRetrieveReqRxTx ( |
| 405 | UINT32 TotalLength, |
| 406 | UINT32 FragmentLength, |
| 407 | UINT32 *RespTotalLength, |
| 408 | UINT32 *RespFragmentLength |
| 409 | ); |
| 410 | |
| 411 | /** |
| 412 | * @brief Starts a transaction to transfer access to a shared or lent |
| 413 | * memory region from a Borrower back to its Owner. |
| 414 | * |
| 415 | * @return The FF-A error status code |
| 416 | */ |
| 417 | EFI_STATUS |
| 418 | EFIAPI |
| 419 | FfaMemRelinquish ( |
| 420 | VOID |
| 421 | ); |
| 422 | |
| 423 | /** |
| 424 | * @brief Restores exclusive access to a memory region back to its Owner. |
| 425 | * |
| 426 | * @param[in] handle Globally unique Handle to identify the memory region |
| 427 | * @param[in] flags Flags for modifying the reclaim behavior |
| 428 | * |
| 429 | * @return The FF-A error status code |
| 430 | */ |
| 431 | EFI_STATUS |
| 432 | EFIAPI |
| 433 | FfaMemReclaim ( |
| 434 | UINT64 Handle, |
| 435 | UINT32 Flags |
| 436 | ); |
| 437 | |
| 438 | /** |
| 439 | * @brief Queries the memory attributes of a memory region. This function |
| 440 | * can only access the regions of the SP's own translation regine. |
| 441 | * Moreover this interface is only available in the boot phase, |
| 442 | * i.e. before invoking FFA_MSG_WAIT interface. |
| 443 | * |
| 444 | * @param[in] base_address Base VA of a translation granule whose |
| 445 | * permission attributes must be returned. |
| 446 | * @param[out] mem_perm Permission attributes of the memory region |
| 447 | * |
| 448 | * @return The FF-A error status code |
| 449 | */ |
| 450 | EFI_STATUS |
| 451 | EFIAPI |
| 452 | FfaMemPermGet ( |
| 453 | CONST VOID *BaseAddr, |
| 454 | UINT32 *MemoryPerm |
| 455 | ); |
| 456 | |
| 457 | /** |
| 458 | * @brief Sets the memory attributes of a memory regions. This function |
| 459 | * can only access the regions of the SP's own translation regine. |
| 460 | * Moreover this interface is only available in the boot phase, |
| 461 | * i.e. before invoking FFA_MSG_WAIT interface. |
| 462 | * |
| 463 | * @param[in] base_address Base VA of a memory region whose permission |
| 464 | * attributes must be set. |
| 465 | * @param[in] page_count Number of translation granule size pages |
| 466 | * starting from the Base address whose permissions |
| 467 | * must be set. |
| 468 | * @param[in] mem_perm Permission attributes to be set for the memory |
| 469 | * region |
| 470 | * @return The FF-A error status code |
| 471 | */ |
| 472 | EFI_STATUS |
| 473 | EFIAPI |
| 474 | FfaMemPermSet ( |
| 475 | CONST VOID *BaseAddr, |
| 476 | UINT32 PageCount, |
| 477 | UINT32 MemoryPerm |
| 478 | ); |
| 479 | |
| 480 | /** |
| 481 | * @brief Allow an entity to provide debug logging to the console. Uses |
| 482 | * 32 bit registers to pass characters. |
| 483 | * |
| 484 | * @param message Message characters |
| 485 | * @param length Message length, max FFA_CONSOLE_LOG_32_MAX_LENGTH |
| 486 | * @return The FF-A error status code |
| 487 | */ |
| 488 | EFI_STATUS |
| 489 | EFIAPI |
| 490 | FfaConsoleLog32 ( |
| 491 | CONST CHAR8 *Message, |
| 492 | UINTN Length |
| 493 | ); |
| 494 | |
| 495 | /** |
| 496 | * @brief Allow an entity to provide debug logging to the console. Uses |
| 497 | * 64 bit registers to pass characters. |
| 498 | * |
| 499 | * @param message Message characters |
| 500 | * @param length Message length, max FFA_CONSOLE_LOG_64_MAX_LENGTH |
| 501 | * @return The FF-A error status code |
| 502 | */ |
| 503 | EFI_STATUS |
| 504 | EFIAPI |
| 505 | FfaConsoleLog64 ( |
| 506 | CONST char *Message, |
| 507 | UINTN Length |
| 508 | ); |
| 509 | |
| 510 | #endif /* FF_A_HELPER_LIB_H_ */ |