TianoCore EDK2 master
Loading...
Searching...
No Matches
VirtHstiDxe.c
Go to the documentation of this file.
1
11#include <PiDxe.h>
12#include <Library/BaseLib.h>
13#include <Library/DebugLib.h>
15#include <Library/HobLib.h>
16#include <Library/HstiLib.h>
19#include <Library/UefiLib.h>
20#include <Library/PcdLib.h>
22
26
27#include "VirtHstiDxe.h"
28
29VOID
30VirtHstiSetSupported (
32 IN UINT32 ByteIndex,
33 IN UINT8 BitMask
34 )
35{
36 ASSERT (ByteIndex < VIRT_HSTI_SECURITY_FEATURE_SIZE);
37 VirtHsti->SecurityFeaturesRequired[ByteIndex] |= BitMask;
38 VirtHsti->SecurityFeaturesImplemented[ByteIndex] |= BitMask;
39}
40
41BOOLEAN
42VirtHstiIsSupported (
44 IN UINT32 ByteIndex,
45 IN UINT8 BitMask
46 )
47{
48 ASSERT (ByteIndex < VIRT_HSTI_SECURITY_FEATURE_SIZE);
49 return VirtHsti->SecurityFeaturesImplemented[ByteIndex] & BitMask;
50}
51
52VOID
53VirtHstiTestResult (
54 CHAR16 *ErrorMsg,
55 IN UINT32 ByteIndex,
56 IN UINT8 BitMask
57 )
58{
59 EFI_STATUS Status;
60
61 ASSERT (ByteIndex < VIRT_HSTI_SECURITY_FEATURE_SIZE);
62
63 if (ErrorMsg) {
64 DEBUG ((DEBUG_ERROR, "VirtHsti: Test failed: %s\n", ErrorMsg));
66 PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE,
67 NULL,
68 ErrorMsg
69 );
70 ASSERT_EFI_ERROR (Status);
71 } else {
73 PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE,
74 NULL,
75 ByteIndex,
76 BitMask
77 );
78 ASSERT_EFI_ERROR (Status);
79 }
80}
81
83UINT16
84VirtHstiGetHostBridgeDevId (
85 VOID
86 )
87{
88 EFI_HOB_GUID_TYPE *GuidHob;
89 EFI_HOB_PLATFORM_INFO *PlatformInfo;
90
91 GuidHob = GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid);
92 ASSERT (GuidHob);
93 PlatformInfo = (EFI_HOB_PLATFORM_INFO *)GET_GUID_HOB_DATA (GuidHob);
94 return PlatformInfo->HostBridgeDevId;
95}
96
98VOID
99EFIAPI
100VirtHstiOnReadyToBoot (
101 EFI_EVENT Event,
102 VOID *Context
103 )
104{
105 switch (VirtHstiGetHostBridgeDevId ()) {
106 case INTEL_82441_DEVICE_ID:
107 VirtHstiQemuPCVerify ();
108 VirtHstiQemuCommonVerify ();
109 break;
110 case INTEL_Q35_MCH_DEVICE_ID:
111 VirtHstiQemuQ35Verify ();
112 VirtHstiQemuCommonVerify ();
113 break;
114 default:
115 ASSERT (FALSE);
116 }
117
118 if (Event != NULL) {
119 gBS->CloseEvent (Event);
120 }
121}
122
133EFIAPI
135 IN EFI_HANDLE ImageHandle,
136 IN EFI_SYSTEM_TABLE *SystemTable
137 )
138{
140 UINT16 DevId;
141 EFI_STATUS Status;
142 EFI_EVENT Event;
143
144 if (PcdGet64 (PcdConfidentialComputingGuestAttr)) {
145 DEBUG ((DEBUG_INFO, "%a: confidential guest\n", __func__));
146 return EFI_UNSUPPORTED;
147 }
148
149 DevId = VirtHstiGetHostBridgeDevId ();
150 switch (DevId) {
151 case INTEL_82441_DEVICE_ID:
152 VirtHsti = VirtHstiQemuPCInit ();
153 VirtHstiQemuCommonInit (VirtHsti);
154 break;
155 case INTEL_Q35_MCH_DEVICE_ID:
156 VirtHsti = VirtHstiQemuQ35Init ();
157 VirtHstiQemuCommonInit (VirtHsti);
158 break;
159 default:
160 DEBUG ((DEBUG_INFO, "%a: unknown platform (0x%x)\n", __func__, DevId));
161 return EFI_UNSUPPORTED;
162 }
163
164 Status = HstiLibSetTable (VirtHsti, sizeof (*VirtHsti));
165 if (EFI_ERROR (Status)) {
166 if (Status != EFI_ALREADY_STARTED) {
167 ASSERT_EFI_ERROR (Status);
168 }
169 }
170
172 TPL_NOTIFY,
173 VirtHstiOnReadyToBoot,
174 NULL,
175 &Event
176 );
177
178 return EFI_SUCCESS;
179}
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
EFI_STATUS EFIAPI HstiLibAppendErrorString(IN UINT32 Role, IN CHAR16 *ImplementationID OPTIONAL, IN CHAR16 *ErrorString)
Definition: HstiDxe.c:579
EFI_STATUS EFIAPI HstiLibSetFeaturesVerified(IN UINT32 Role, IN CHAR16 *ImplementationID OPTIONAL, IN UINT32 ByteIndex, IN UINT8 BitMask)
Definition: HstiDxe.c:448
EFI_STATUS EFIAPI HstiLibSetTable(IN VOID *Hsti, IN UINTN HstiSize)
Definition: HstiDxe.c:275
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdGet64(TokenName)
Definition: PcdLib.h:375
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI EfiCreateEventReadyToBootEx(IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL, IN VOID *NotifyContext OPTIONAL, OUT EFI_EVENT *ReadyToBootEvent)
Definition: UefiNotTiano.c:164
EFI_STATUS EFIAPI VirtHstiDxeEntrypoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: VirtHstiDxe.c:134