]>
Commit | Line | Data |
---|---|---|
4fe26784 MX |
1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>\r | |
4 | \r | |
5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | \r | |
7 | **/\r | |
8 | \r | |
9 | #include <PiPei.h>\r | |
10 | #include <Library/BaseLib.h>\r | |
11 | #include <Library/BaseMemoryLib.h>\r | |
12 | #include <Library/MemoryAllocationLib.h>\r | |
13 | #include <Library/DebugLib.h>\r | |
14 | #include <Protocol/DebugSupport.h>\r | |
15 | #include <Library/TdxLib.h>\r | |
16 | #include <IndustryStandard/Tdx.h>\r | |
17 | #include <Library/PrePiLib.h>\r | |
18 | #include <Library/PeilessStartupLib.h>\r | |
19 | #include <Library/PlatformInitLib.h>\r | |
20 | #include <ConfidentialComputingGuestAttr.h>\r | |
21 | #include <Guid/MemoryTypeInformation.h>\r | |
22 | #include <OvmfPlatforms.h>\r | |
23 | #include "PeilessStartupInternal.h"\r | |
24 | \r | |
25 | #define GET_GPAW_INIT_STATE(INFO) ((UINT8) ((INFO) & 0x3f))\r | |
26 | \r | |
27 | EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {\r | |
28 | { EfiACPIMemoryNVS, 0x004 },\r | |
29 | { EfiACPIReclaimMemory, 0x008 },\r | |
30 | { EfiReservedMemoryType, 0x004 },\r | |
31 | { EfiRuntimeServicesData, 0x024 },\r | |
32 | { EfiRuntimeServicesCode, 0x030 },\r | |
33 | { EfiBootServicesCode, 0x180 },\r | |
34 | { EfiBootServicesData, 0xF00 },\r | |
35 | { EfiMaxMemoryType, 0x000 }\r | |
36 | };\r | |
37 | \r | |
38 | EFI_STATUS\r | |
39 | EFIAPI\r | |
40 | InitializePlatform (\r | |
41 | EFI_HOB_PLATFORM_INFO *PlatformInfoHob\r | |
42 | )\r | |
43 | {\r | |
44 | UINT32 LowerMemorySize;\r | |
45 | \r | |
46 | DEBUG ((DEBUG_INFO, "InitializePlatform in Pei-less boot\n"));\r | |
47 | PlatformDebugDumpCmos ();\r | |
48 | \r | |
49 | PlatformInfoHob->DefaultMaxCpuNumber = 64;\r | |
50 | PlatformInfoHob->PcdPciMmio64Size = 0x800000000;\r | |
51 | \r | |
52 | PlatformInfoHob->HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);\r | |
53 | DEBUG ((DEBUG_INFO, "HostBridgeDeviceId = 0x%x\n", PlatformInfoHob->HostBridgeDevId));\r | |
54 | \r | |
55 | PlatformAddressWidthInitialization (PlatformInfoHob);\r | |
56 | DEBUG ((\r | |
57 | DEBUG_INFO,\r | |
58 | "PhysMemAddressWidth=0x%x, Pci64Base=0x%llx, Pci64Size=0x%llx\n",\r | |
59 | PlatformInfoHob->PhysMemAddressWidth,\r | |
60 | PlatformInfoHob->PcdPciMmio64Base,\r | |
61 | PlatformInfoHob->PcdPciMmio64Size\r | |
62 | ));\r | |
63 | \r | |
64 | PlatformMaxCpuCountInitialization (PlatformInfoHob);\r | |
65 | DEBUG ((\r | |
66 | DEBUG_INFO,\r | |
67 | "MaxCpuCount=%d, BootCpuCount=%d\n",\r | |
68 | PlatformInfoHob->PcdCpuMaxLogicalProcessorNumber,\r | |
69 | PlatformInfoHob->PcdCpuBootLogicalProcessorNumber\r | |
70 | ));\r | |
71 | \r | |
72 | LowerMemorySize = PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob);\r | |
73 | PlatformQemuUc32BaseInitialization (PlatformInfoHob);\r | |
74 | DEBUG ((\r | |
75 | DEBUG_INFO,\r | |
76 | "Uc32Base = 0x%x, Uc32Size = 0x%x, LowerMemorySize = 0x%x\n",\r | |
77 | PlatformInfoHob->Uc32Base,\r | |
78 | PlatformInfoHob->Uc32Size,\r | |
79 | LowerMemorySize\r | |
80 | ));\r | |
81 | \r | |
82 | if (TdIsEnabled ()) {\r | |
83 | PlatformTdxPublishRamRegions ();\r | |
84 | } else {\r | |
85 | PlatformQemuInitializeRam (PlatformInfoHob);\r | |
86 | PlatformQemuInitializeRamForS3 (PlatformInfoHob);\r | |
87 | }\r | |
88 | \r | |
89 | //\r | |
90 | // Create Memory Type Information HOB\r | |
91 | //\r | |
92 | BuildGuidDataHob (\r | |
93 | &gEfiMemoryTypeInformationGuid,\r | |
94 | mDefaultMemoryTypeInformation,\r | |
95 | sizeof (mDefaultMemoryTypeInformation)\r | |
96 | );\r | |
97 | \r | |
98 | PlatformMemMapInitialization (PlatformInfoHob);\r | |
99 | \r | |
100 | PlatformNoexecDxeInitialization (PlatformInfoHob);\r | |
101 | \r | |
102 | if (TdIsEnabled ()) {\r | |
103 | PlatformInfoHob->PcdConfidentialComputingGuestAttr = CCAttrIntelTdx;\r | |
104 | PlatformInfoHob->PcdTdxSharedBitMask = TdSharedPageMask ();\r | |
105 | PlatformInfoHob->PcdSetNxForStack = TRUE;\r | |
106 | }\r | |
107 | \r | |
108 | PlatformMiscInitialization (PlatformInfoHob);\r | |
109 | \r | |
110 | return EFI_SUCCESS;\r | |
111 | }\r | |
112 | \r | |
113 | /**\r | |
114 | * This function brings up the Tdx guest from SEC phase to DXE phase.\r | |
115 | * PEI phase is skipped because most of the components in PEI phase\r | |
116 | * is not needed for Tdx guest, for example, MP Services, TPM etc.\r | |
117 | * In this way, the attack surfaces are reduced as much as possible.\r | |
118 | *\r | |
119 | * @param Context The pointer to the SecCoreData\r | |
120 | * @return VOID This function never returns\r | |
121 | */\r | |
122 | VOID\r | |
123 | EFIAPI\r | |
124 | PeilessStartup (\r | |
125 | IN VOID *Context\r | |
126 | )\r | |
127 | {\r | |
128 | EFI_SEC_PEI_HAND_OFF *SecCoreData;\r | |
129 | EFI_FIRMWARE_VOLUME_HEADER *BootFv;\r | |
130 | EFI_STATUS Status;\r | |
131 | EFI_HOB_PLATFORM_INFO PlatformInfoHob;\r | |
132 | UINT32 DxeCodeBase;\r | |
133 | UINT32 DxeCodeSize;\r | |
134 | TD_RETURN_DATA TdReturnData;\r | |
135 | VOID *VmmHobList;\r | |
4b0a6226 | 136 | UINT8 *CfvBase;\r |
4fe26784 MX |
137 | \r |
138 | Status = EFI_SUCCESS;\r | |
139 | BootFv = NULL;\r | |
140 | VmmHobList = NULL;\r | |
141 | SecCoreData = (EFI_SEC_PEI_HAND_OFF *)Context;\r | |
4b0a6226 | 142 | CfvBase = (UINT8 *)(UINTN)FixedPcdGet32 (PcdCfvBase);\r |
4fe26784 MX |
143 | \r |
144 | ZeroMem (&PlatformInfoHob, sizeof (PlatformInfoHob));\r | |
145 | \r | |
146 | if (TdIsEnabled ()) {\r | |
147 | VmmHobList = (VOID *)(UINTN)FixedPcdGet32 (PcdOvmfSecGhcbBase);\r | |
148 | Status = TdCall (TDCALL_TDINFO, 0, 0, 0, &TdReturnData);\r | |
149 | ASSERT (Status == EFI_SUCCESS);\r | |
150 | \r | |
151 | DEBUG ((\r | |
152 | DEBUG_INFO,\r | |
153 | "Tdx started with(Hob: 0x%x, Gpaw: 0x%x, Cpus: %d)\n",\r | |
154 | (UINT32)(UINTN)VmmHobList,\r | |
155 | GET_GPAW_INIT_STATE (TdReturnData.TdInfo.Gpaw),\r | |
156 | TdReturnData.TdInfo.NumVcpus\r | |
157 | ));\r | |
158 | \r | |
159 | Status = ConstructFwHobList (VmmHobList);\r | |
160 | } else {\r | |
161 | DEBUG ((DEBUG_INFO, "Ovmf started\n"));\r | |
162 | Status = ConstructSecHobList ();\r | |
163 | }\r | |
164 | \r | |
165 | if (EFI_ERROR (Status)) {\r | |
166 | ASSERT (FALSE);\r | |
167 | CpuDeadLoop ();\r | |
168 | }\r | |
169 | \r | |
170 | DEBUG ((DEBUG_INFO, "HobList: %p\n", GetHobList ()));\r | |
171 | \r | |
4b0a6226 MX |
172 | if (TdIsEnabled ()) {\r |
173 | //\r | |
174 | // Measure HobList\r | |
175 | //\r | |
176 | Status = MeasureHobList (VmmHobList);\r | |
177 | if (EFI_ERROR (Status)) {\r | |
178 | ASSERT (FALSE);\r | |
179 | CpuDeadLoop ();\r | |
180 | }\r | |
181 | \r | |
182 | //\r | |
183 | // Validate Tdx CFV\r | |
184 | //\r | |
185 | if (!TdxValidateCfv (CfvBase, FixedPcdGet32 (PcdCfvRawDataSize))) {\r | |
186 | ASSERT (FALSE);\r | |
187 | CpuDeadLoop ();\r | |
188 | }\r | |
189 | \r | |
190 | //\r | |
191 | // Measure Tdx CFV\r | |
192 | //\r | |
193 | Status = MeasureFvImage ((EFI_PHYSICAL_ADDRESS)(UINTN)CfvBase, FixedPcdGet32 (PcdCfvRawDataSize), 1);\r | |
194 | if (EFI_ERROR (Status)) {\r | |
195 | ASSERT (FALSE);\r | |
196 | CpuDeadLoop ();\r | |
197 | }\r | |
198 | }\r | |
199 | \r | |
4fe26784 MX |
200 | //\r |
201 | // Initialize the Platform\r | |
202 | //\r | |
203 | Status = InitializePlatform (&PlatformInfoHob);\r | |
204 | if (EFI_ERROR (Status)) {\r | |
205 | ASSERT (FALSE);\r | |
206 | CpuDeadLoop ();\r | |
207 | }\r | |
208 | \r | |
209 | BuildGuidDataHob (&gUefiOvmfPkgPlatformInfoGuid, &PlatformInfoHob, sizeof (EFI_HOB_PLATFORM_INFO));\r | |
210 | \r | |
211 | //\r | |
212 | // SecFV\r | |
213 | //\r | |
214 | BootFv = (EFI_FIRMWARE_VOLUME_HEADER *)SecCoreData->BootFirmwareVolumeBase;\r | |
215 | BuildFvHob ((UINTN)BootFv, BootFv->FvLength);\r | |
216 | \r | |
217 | //\r | |
218 | // DxeFV\r | |
219 | //\r | |
220 | DxeCodeBase = PcdGet32 (PcdBfvBase);\r | |
221 | DxeCodeSize = PcdGet32 (PcdBfvRawDataSize) - (UINT32)BootFv->FvLength;\r | |
222 | BuildFvHob (DxeCodeBase, DxeCodeSize);\r | |
223 | \r | |
224 | DEBUG ((DEBUG_INFO, "SecFv : %p, 0x%x\n", BootFv, BootFv->FvLength));\r | |
225 | DEBUG ((DEBUG_INFO, "DxeFv : %x, 0x%x\n", DxeCodeBase, DxeCodeSize));\r | |
226 | \r | |
227 | BuildStackHob ((UINTN)SecCoreData->StackBase, SecCoreData->StackSize <<= 1);\r | |
228 | \r | |
229 | BuildResourceDescriptorHob (\r | |
230 | EFI_RESOURCE_SYSTEM_MEMORY,\r | |
231 | EFI_RESOURCE_ATTRIBUTE_PRESENT |\r | |
232 | EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r | |
233 | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r | |
234 | EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r | |
235 | EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r | |
236 | EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |\r | |
237 | EFI_RESOURCE_ATTRIBUTE_TESTED,\r | |
238 | (UINT64)SecCoreData->TemporaryRamBase,\r | |
239 | (UINT64)SecCoreData->TemporaryRamSize\r | |
240 | );\r | |
241 | \r | |
242 | //\r | |
243 | // Load the DXE Core and transfer control to it.\r | |
244 | // Only DxeFV is in the compressed section.\r | |
245 | //\r | |
246 | Status = DxeLoadCore (1);\r | |
247 | \r | |
248 | //\r | |
249 | // Never arrive here.\r | |
250 | //\r | |
251 | ASSERT (FALSE);\r | |
252 | CpuDeadLoop ();\r | |
253 | }\r |