1 | /** @file
|
---|
2 | This file contains DXE driver for publishing empty HSTI table
|
---|
3 |
|
---|
4 | Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
|
---|
5 | Copyright (c) 2024, Red Hat. Inc
|
---|
6 |
|
---|
7 | SPDX-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 |
|
---|
29 | VOID
|
---|
30 | VirtHstiSetSupported (
|
---|
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 |
|
---|
41 | BOOLEAN
|
---|
42 | VirtHstiIsSupported (
|
---|
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 |
|
---|
52 | VOID
|
---|
53 | VirtHstiTestResult (
|
---|
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 |
|
---|
82 | STATIC
|
---|
83 | UINT16
|
---|
84 | VirtHstiGetHostBridgeDevId (
|
---|
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 |
|
---|
97 | STATIC
|
---|
98 | VOID
|
---|
99 | EFIAPI
|
---|
100 | VirtHstiOnReadyToBoot (
|
---|
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 | **/
|
---|
132 | EFI_STATUS
|
---|
133 | EFIAPI
|
---|
134 | VirtHstiDxeEntrypoint (
|
---|
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 | }
|
---|