microsoft/mu_feature_ffa

Public

mirrored from https://github.com/microsoft/mu_feature_ffaAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
858d1559f5d2e1e97ccf62290e96060595aa2dfb

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

FfaFeaturePkg/SecurePartitions/MsSecurePartition/MsSecurePartition.c

113lines · 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#include <Guid/NotificationServiceFfa.h>
27#include <Guid/TestServiceFfa.h>
28
29/**
30 Message Handler for the Microsoft Secure Partition
31
32 @param Request The incoming message
33 @param Response The outgoing message
34
35**/
36STATIC
37VOID
38EFIAPI
39MsSecurePartitionHandleMessage (
40 DIRECT_MSG_ARGS_EX *Request,
41 DIRECT_MSG_ARGS_EX *Response
42 )
43{
44 ZeroMem (Response, sizeof (DIRECT_MSG_ARGS_EX));
45 Response->SourceId = Request->DestinationId;
46 Response->DestinationId = Request->SourceId;
47
48 if (!CompareMem (&Request->ServiceGuid, &gEfiNotificationServiceFfaGuid, sizeof (EFI_GUID))) {
49 NotificationServiceHandle (Request, Response);
50 } else if (!CompareMem (&Request->ServiceGuid, &gEfiTpm2ServiceFfaGuid, sizeof (EFI_GUID))) {
51 #ifdef TPM2_ENABLE
52 TpmServiceHandle (Request, Response);
53 #else
54 Response->Arg0 = EFI_UNSUPPORTED;
55 #endif
56 } else if (!CompareMem (&Request->ServiceGuid, &gEfiTestServiceFfaGuid, sizeof (EFI_GUID))) {
57 TestServiceHandle (Request, Response);
58 } else {
59 DEBUG ((DEBUG_ERROR, "Invalid secure partition service UUID\n"));
60 Response->Arg0 = EFI_NOT_FOUND;
61 }
62}
63
64/**
65 The Entry Point for Microsoft Secure Partition.
66
67 @param HobStart Pointer to the start of the HOB list.
68
69 @retval EFI_SUCCESS Success.
70 @retval EFI_UNSUPPORTED Unsupported operation.
71**/
72EFI_STATUS
73EFIAPI
74MsSecurePartitionMain (
75 IN VOID *HobStart
76 )
77{
78 EFI_STATUS Status;
79 DIRECT_MSG_ARGS_EX Request;
80 DIRECT_MSG_ARGS_EX Response;
81
82 // Initialize the services running in this secure partition
83 NotificationServiceInit ();
84 #ifdef TPM2_ENABLE
85 TpmServiceInit ();
86 #endif
87 TestServiceInit ();
88
89 DEBUG ((DEBUG_INFO, "MS-Services secure partition initialized and running!\n"));
90
91 Status = FfaMessageWait (&Request);
92 if (EFI_ERROR (Status)) {
93 DEBUG ((DEBUG_ERROR, "Failed to wait for message %r\n", Status));
94 ASSERT (FALSE);
95 }
96
97 while (1) {
98 MsSecurePartitionHandleMessage (&Request, &Response);
99
100 Status = FfaMessageSendDirectResp2 (&Response, &Request);
101 if (EFI_ERROR (Status)) {
102 DEBUG ((DEBUG_ERROR, "Failed to send direct response %r\n", Status));
103 Status = FfaMessageWait (&Request);
104 if (EFI_ERROR (Status)) {
105 DEBUG ((DEBUG_ERROR, "Failed to wait for message %r\n", Status));
106 ASSERT (FALSE);
107 }
108 }
109 }
110
111 DEBUG ((DEBUG_ERROR, "Reached the end of %a - Invalid!\n", __func__));
112 return EFI_SUCCESS;
113}
114