microsoft/mu_feature_ffa
Publicmirrored fromhttps://github.com/microsoft/mu_feature_ffaAvailable
FfaFeaturePkg/SecurePartitions/MsSecurePartition/MsSecurePartition.c
105lines · modecode
| 1 | /** @file |
| 2 | Microsoft Secure Partition |
| 3 | |
| 4 | Copyright (c), Microsoft Corporation. |
| 5 | SPDX-License-Identifier: BSD-2-Clause-Patent |
| 6 | |
| 7 | **/ |
| 8 | |
| 9 | // Secure Partition Headers |
| 10 | #include <PiMm.h> |
| 11 | #include <Base.h> |
| 12 | #include <IndustryStandard/ArmFfaSvc.h> |
| 13 | |
| 14 | #include <Library/StandaloneMmCoreEntryPoint.h> |
| 15 | #include <Library/DebugLib.h> |
| 16 | #include <Library/BaseMemoryLib.h> |
| 17 | #include <Library/IoLib.h> |
| 18 | #include <Library/PcdLib.h> |
| 19 | #include <Library/ArmSvcLib.h> |
| 20 | #include <Library/ArmFfaLib.h> |
| 21 | #include <Library/ArmFfaLibEx.h> |
| 22 | #include <Library/NotificationServiceLib.h> |
| 23 | #include <Library/TestServiceLib.h> |
| 24 | #include <Library/TpmServiceLib.h> |
| 25 | #include <Guid/Tpm2ServiceFfa.h> |
| 26 | |
| 27 | /** |
| 28 | Message Handler for the Microsoft Secure Partition |
| 29 | |
| 30 | @param Request The incoming message |
| 31 | @param Response The outgoing message |
| 32 | |
| 33 | **/ |
| 34 | STATIC |
| 35 | VOID |
| 36 | EFIAPI |
| 37 | MsSecurePartitionHandleMessage ( |
| 38 | DIRECT_MSG_ARGS_EX *Request, |
| 39 | DIRECT_MSG_ARGS_EX *Response |
| 40 | ) |
| 41 | { |
| 42 | ZeroMem (Response, sizeof (DIRECT_MSG_ARGS_EX)); |
| 43 | Response->SourceId = Request->DestinationId; |
| 44 | Response->DestinationId = Request->SourceId; |
| 45 | |
| 46 | if (!CompareMem (&Request->ServiceGuid, &gTpm2ServiceFfaGuid, sizeof (EFI_GUID))) { |
| 47 | #ifdef TPM2_ENABLE |
| 48 | TpmServiceHandle (Request, Response); |
| 49 | #else |
| 50 | Response->Arg0 = EFI_UNSUPPORTED; |
| 51 | #endif |
| 52 | } else { |
| 53 | DEBUG ((DEBUG_ERROR, "Invalid secure partition service UUID\n")); |
| 54 | Response->Arg0 = EFI_NOT_FOUND; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | The Entry Point for Microsoft Secure Partition. |
| 60 | |
| 61 | @param HobStart Pointer to the start of the HOB list. |
| 62 | |
| 63 | @retval EFI_SUCCESS Success. |
| 64 | @retval EFI_UNSUPPORTED Unsupported operation. |
| 65 | **/ |
| 66 | EFI_STATUS |
| 67 | EFIAPI |
| 68 | MsSecurePartitionMain ( |
| 69 | IN VOID *HobStart |
| 70 | ) |
| 71 | { |
| 72 | EFI_STATUS Status; |
| 73 | DIRECT_MSG_ARGS_EX Request; |
| 74 | DIRECT_MSG_ARGS_EX Response; |
| 75 | |
| 76 | // Initialize the services running in this secure partition |
| 77 | #ifdef TPM2_ENABLE |
| 78 | TpmServiceInit (); |
| 79 | #endif |
| 80 | |
| 81 | DEBUG ((DEBUG_INFO, "MS-Services secure partition initialized and running!\n")); |
| 82 | |
| 83 | Status = FfaMessageWait (&Request); |
| 84 | if (EFI_ERROR (Status)) { |
| 85 | DEBUG ((DEBUG_ERROR, "Failed to wait for message %r\n", Status)); |
| 86 | ASSERT (FALSE); |
| 87 | } |
| 88 | |
| 89 | while (1) { |
| 90 | MsSecurePartitionHandleMessage (&Request, &Response); |
| 91 | |
| 92 | Status = FfaMessageSendDirectResp2 (&Response, &Request); |
| 93 | if (EFI_ERROR (Status)) { |
| 94 | DEBUG ((DEBUG_ERROR, "Failed to send direct response %r\n", Status)); |
| 95 | Status = FfaMessageWait (&Request); |
| 96 | if (EFI_ERROR (Status)) { |
| 97 | DEBUG ((DEBUG_ERROR, "Failed to wait for message %r\n", Status)); |
| 98 | ASSERT (FALSE); |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | DEBUG ((DEBUG_ERROR, "Reached the end of %a - Invalid!\n", __func__)); |
| 104 | return EFI_SUCCESS; |
| 105 | } |
| 106 | |