VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/OvmfPkg/VirtHstiDxe/VirtHstiDxe.c

最後變更 在這個檔案是 105670,由 vboxsync 提交於 7 月 前

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

  • 屬性 svn:eol-style 設為 native
檔案大小: 4.3 KB
 
1/** @file
2 This file contains DXE driver for publishing empty HSTI table
3
4Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5Copyright (c) 2024, Red Hat. Inc
6
7SPDX-License-Identifier: BSD-2-Clause-Patent
8
9**/
10
11#include <PiDxe.h>
12#include <Library/BaseLib.h>
13#include <Library/DebugLib.h>
14#include <Library/BaseMemoryLib.h>
15#include <Library/HobLib.h>
16#include <Library/HstiLib.h>
17#include <Library/MemoryAllocationLib.h>
18#include <Library/UefiBootServicesTableLib.h>
19#include <Library/UefiLib.h>
20#include <Library/PcdLib.h>
21#include <Library/PlatformInitLib.h>
22
23#include <IndustryStandard/Hsti.h>
24#include <IndustryStandard/I440FxPiix4.h>
25#include <IndustryStandard/Q35MchIch9.h>
26
27#include "VirtHstiDxe.h"
28
29VOID
30VirtHstiSetSupported (
31 VIRT_ADAPTER_INFO_PLATFORM_SECURITY *VirtHsti,
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 (
43 VIRT_ADAPTER_INFO_PLATFORM_SECURITY *VirtHsti,
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));
65 Status = HstiLibAppendErrorString (
66 PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE,
67 NULL,
68 ErrorMsg
69 );
70 ASSERT_EFI_ERROR (Status);
71 } else {
72 Status = HstiLibSetFeaturesVerified (
73 PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE,
74 NULL,
75 ByteIndex,
76 BitMask
77 );
78 ASSERT_EFI_ERROR (Status);
79 }
80}
81
82STATIC
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
97STATIC
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
123/**
124 The driver's entry point.
125
126 @param[in] ImageHandle The firmware allocated handle for the EFI image.
127 @param[in] SystemTable A pointer to the EFI System Table.
128
129 @retval EFI_SUCCESS The entry point is executed successfully.
130 @retval other Some error occurs when executing this entry point.
131**/
132EFI_STATUS
133EFIAPI
134VirtHstiDxeEntrypoint (
135 IN EFI_HANDLE ImageHandle,
136 IN EFI_SYSTEM_TABLE *SystemTable
137 )
138{
139 VIRT_ADAPTER_INFO_PLATFORM_SECURITY *VirtHsti;
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
171 EfiCreateEventReadyToBootEx (
172 TPL_NOTIFY,
173 VirtHstiOnReadyToBoot,
174 NULL,
175 &Event
176 );
177
178 return EFI_SUCCESS;
179}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette