]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
MdeModulePkg/PeiCore: Enable T-RAM evacuation in PeiCore (CVE-2019-11098)
[mirror_edk2.git] / MdeModulePkg / Core / Pei / PeiMain / PeiMain.c
CommitLineData
615c6dd0 1/** @file\r
b1f6a7c6 2 Pei Core Main Entry Point\r
d1102dba 3\r
9b23c7ba 4Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
192f6d4c 6\r
615c6dd0 7**/\r
192f6d4c 8\r
0d516397 9#include "PeiMain.h"\r
192f6d4c 10\r
fe1e36e5 11EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {\r
192f6d4c 12 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
13 &gEfiPeiMemoryDiscoveredPpiGuid,\r
14 NULL\r
15};\r
16\r
40f26b8f 17///\r
82b8c8df 18/// Pei service instance\r
40f26b8f 19///\r
fe1e36e5 20EFI_PEI_SERVICES gPs = {\r
192f6d4c 21 {\r
22 PEI_SERVICES_SIGNATURE,\r
23 PEI_SERVICES_REVISION,\r
24 sizeof (EFI_PEI_SERVICES),\r
25 0,\r
26 0\r
27 },\r
28 PeiInstallPpi,\r
29 PeiReInstallPpi,\r
30 PeiLocatePpi,\r
31 PeiNotifyPpi,\r
32\r
33 PeiGetBootMode,\r
34 PeiSetBootMode,\r
35\r
36 PeiGetHobList,\r
37 PeiCreateHob,\r
38\r
3b428ade 39 PeiFfsFindNextVolume,\r
192f6d4c 40 PeiFfsFindNextFile,\r
41 PeiFfsFindSectionData,\r
42\r
d1102dba 43 PeiInstallPeiMemory,\r
192f6d4c 44 PeiAllocatePages,\r
45 PeiAllocatePool,\r
46 (EFI_PEI_COPY_MEM)CopyMem,\r
47 (EFI_PEI_SET_MEM)SetMem,\r
48\r
49 PeiReportStatusCode,\r
14e8823a 50 PeiResetSystem,\r
b0d803fe 51\r
8d415937 52 &gPeiDefaultCpuIoPpi,\r
53 &gPeiDefaultPciCfg2Ppi,\r
b0d803fe 54\r
55 PeiFfsFindFileByName,\r
56 PeiFfsGetFileInfo,\r
57 PeiFfsGetVolumeInfo,\r
c7935105
SZ
58 PeiRegisterForShadow,\r
59 PeiFfsFindSectionData3,\r
672473ea 60 PeiFfsGetFileInfo2,\r
b2374cec
SZ
61 PeiResetSystem2,\r
62 PeiFreePages,\r
192f6d4c 63};\r
64\r
ef05e063 65/**\r
66 Shadow PeiCore module from flash to installed memory.\r
d1102dba 67\r
ef05e063 68 @param PrivateData PeiCore's private data structure\r
69\r
70 @return PeiCore function address after shadowing.\r
71**/\r
72PEICORE_FUNCTION_POINTER\r
73ShadowPeiCore (\r
74 IN PEI_CORE_INSTANCE *PrivateData\r
75 )\r
76{\r
9b23c7ba
CC
77 EFI_PEI_FILE_HANDLE PeiCoreFileHandle;\r
78 EFI_PHYSICAL_ADDRESS EntryPoint;\r
79 EFI_STATUS Status;\r
80 UINT32 AuthenticationState;\r
81 UINTN Index;\r
82 EFI_PEI_CORE_FV_LOCATION_PPI *PeiCoreFvLocationPpi;\r
83 UINTN PeiCoreFvIndex;\r
ef05e063 84\r
85 PeiCoreFileHandle = NULL;\r
ef05e063 86 //\r
9b23c7ba
CC
87 // Default PeiCore is in BFV\r
88 //\r
89 PeiCoreFvIndex = 0;\r
90 //\r
91 // Find the PEI Core either from EFI_PEI_CORE_FV_LOCATION_PPI indicated FV or BFV\r
92 //\r
93 Status = PeiServicesLocatePpi (\r
94 &gEfiPeiCoreFvLocationPpiGuid,\r
95 0,\r
96 NULL,\r
97 (VOID **) &PeiCoreFvLocationPpi\r
98 );\r
99 if (!EFI_ERROR (Status) && (PeiCoreFvLocationPpi->PeiCoreFvLocation != NULL)) {\r
100 //\r
101 // If PeiCoreFvLocation present, the PEI Core should be found from indicated FV\r
102 //\r
103 for (Index = 0; Index < PrivateData->FvCount; Index ++) {\r
104 if (PrivateData->Fv[Index].FvHandle == PeiCoreFvLocationPpi->PeiCoreFvLocation) {\r
105 PeiCoreFvIndex = Index;\r
106 break;\r
107 }\r
108 }\r
109 ASSERT (Index < PrivateData->FvCount);\r
110 }\r
111 //\r
112 // Find PEI Core from the given FV index\r
ef05e063 113 //\r
9b23c7ba
CC
114 Status = PrivateData->Fv[PeiCoreFvIndex].FvPpi->FindFileByType (\r
115 PrivateData->Fv[PeiCoreFvIndex].FvPpi,\r
116 EFI_FV_FILETYPE_PEI_CORE,\r
117 PrivateData->Fv[PeiCoreFvIndex].FvHandle,\r
118 &PeiCoreFileHandle\r
119 );\r
ef05e063 120 ASSERT_EFI_ERROR (Status);\r
121\r
122 //\r
123 // Shadow PEI Core into memory so it will run faster\r
124 //\r
125 Status = PeiLoadImage (\r
126 GetPeiServicesTablePointer (),\r
127 *((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle),\r
c2c4199b 128 PEIM_STATE_REGISTER_FOR_SHADOW,\r
ef05e063 129 &EntryPoint,\r
130 &AuthenticationState\r
131 );\r
132 ASSERT_EFI_ERROR (Status);\r
133\r
134 //\r
93b8ed68 135 // Compute the PeiCore's function address after shadowed PeiCore.\r
ef05e063 136 // _ModuleEntryPoint is PeiCore main function entry\r
137 //\r
138 return (PEICORE_FUNCTION_POINTER)((UINTN) EntryPoint + (UINTN) PeiCore - (UINTN) _ModuleEntryPoint);\r
139}\r
140\r
b1f6a7c6 141/**\r
82b8c8df 142 This routine is invoked by main entry of PeiMain module during transition\r
192f6d4c 143 from SEC to PEI. After switching stack in the PEI core, it will restart\r
144 with the old core data.\r
145\r
0f9ebb32 146 @param SecCoreDataPtr Points to a data structure containing information about the PEI core's operating\r
5aae0aa7 147 environment, such as the size and location of temporary RAM, the stack location and\r
148 the BFV location.\r
b1f6a7c6 149 @param PpiList Points to a list of one or more PPI descriptors to be installed initially by the PEI core.\r
5aae0aa7 150 An empty PPI list consists of a single descriptor with the end-tag\r
151 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization\r
152 phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such\r
153 that both the PEI Foundation and any modules can leverage the associated service\r
154 calls and/or code in these early PPIs\r
b1f6a7c6 155 @param Data Pointer to old core data that is used to initialize the\r
192f6d4c 156 core's data areas.\r
82b8c8df 157 If NULL, it is first PeiCore entering.\r
192f6d4c 158\r
b1f6a7c6 159**/\r
0308e20d 160VOID\r
b1f6a7c6 161EFIAPI\r
162PeiCore (\r
0f9ebb32 163 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreDataPtr,\r
b1f6a7c6 164 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,\r
165 IN VOID *Data\r
166 )\r
192f6d4c 167{\r
ef05e063 168 PEI_CORE_INSTANCE PrivateData;\r
0f9ebb32
LG
169 EFI_SEC_PEI_HAND_OFF *SecCoreData;\r
170 EFI_SEC_PEI_HAND_OFF NewSecCoreData;\r
ef05e063 171 EFI_STATUS Status;\r
172 PEI_CORE_TEMP_POINTERS TempPtr;\r
ef05e063 173 PEI_CORE_INSTANCE *OldCoreData;\r
174 EFI_PEI_CPU_IO_PPI *CpuIo;\r
175 EFI_PEI_PCI_CFG2_PPI *PciCfg;\r
176 EFI_HOB_HANDOFF_INFO_TABLE *HandoffInformationTable;\r
0f9ebb32 177 EFI_PEI_TEMPORARY_RAM_DONE_PPI *TemporaryRamDonePpi;\r
fe781940 178 UINTN Index;\r
d1102dba 179\r
6b22483f 180 //\r
181 // Retrieve context passed into PEI Core\r
182 //\r
0f9ebb32
LG
183 OldCoreData = (PEI_CORE_INSTANCE *) Data;\r
184 SecCoreData = (EFI_SEC_PEI_HAND_OFF *) SecCoreDataPtr;\r
192f6d4c 185\r
40f26b8f 186 //\r
6b22483f 187 // Perform PEI Core phase specific actions.\r
188 //\r
189 if (OldCoreData == NULL) {\r
190 //\r
191 // If OldCoreData is NULL, means current is the first entry into the PEI Core before memory is available.\r
192 //\r
193 ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));\r
194 PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;\r
195 CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r
196 } else {\r
197 //\r
198 // Memory is available to the PEI Core. See if the PEI Core has been shadowed to memory yet.\r
199 //\r
ef05e063 200 if (OldCoreData->ShadowedPeiCore == NULL) {\r
ef05e063 201 //\r
202 // Fixup the PeiCore's private data\r
203 //\r
6b22483f 204 OldCoreData->Ps = &OldCoreData->ServiceTableShadow;\r
205 OldCoreData->CpuIo = &OldCoreData->ServiceTableShadow.CpuIo;\r
ef05e063 206 if (OldCoreData->HeapOffsetPositive) {\r
207 OldCoreData->HobList.Raw = (VOID *)(OldCoreData->HobList.Raw + OldCoreData->HeapOffset);\r
111e6c92
SZ
208 if (OldCoreData->UnknownFvInfo != NULL) {\r
209 OldCoreData->UnknownFvInfo = (PEI_CORE_UNKNOW_FORMAT_FV_INFO *) ((UINT8 *) OldCoreData->UnknownFvInfo + OldCoreData->HeapOffset);\r
210 }\r
b62fe570
SZ
211 if (OldCoreData->CurrentFvFileHandles != NULL) {\r
212 OldCoreData->CurrentFvFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->CurrentFvFileHandles + OldCoreData->HeapOffset);\r
213 }\r
f2bc359c
SZ
214 if (OldCoreData->PpiData.PpiList.PpiPtrs != NULL) {\r
215 OldCoreData->PpiData.PpiList.PpiPtrs = (PEI_PPI_LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.PpiList.PpiPtrs + OldCoreData->HeapOffset);\r
216 }\r
217 if (OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs != NULL) {\r
218 OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs = (PEI_PPI_LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs + OldCoreData->HeapOffset);\r
219 }\r
220 if (OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs != NULL) {\r
221 OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs = (PEI_PPI_LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs + OldCoreData->HeapOffset);\r
222 }\r
fe781940 223 OldCoreData->Fv = (PEI_CORE_FV_HANDLE *) ((UINT8 *) OldCoreData->Fv + OldCoreData->HeapOffset);\r
111e6c92 224 for (Index = 0; Index < OldCoreData->FvCount; Index ++) {\r
b62fe570
SZ
225 if (OldCoreData->Fv[Index].PeimState != NULL) {\r
226 OldCoreData->Fv[Index].PeimState = (UINT8 *) OldCoreData->Fv[Index].PeimState + OldCoreData->HeapOffset;\r
227 }\r
228 if (OldCoreData->Fv[Index].FvFileHandles != NULL) {\r
229 OldCoreData->Fv[Index].FvFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->Fv[Index].FvFileHandles + OldCoreData->HeapOffset);\r
230 }\r
fe781940 231 }\r
b62fe570
SZ
232 OldCoreData->TempFileGuid = (EFI_GUID *) ((UINT8 *) OldCoreData->TempFileGuid + OldCoreData->HeapOffset);\r
233 OldCoreData->TempFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->TempFileHandles + OldCoreData->HeapOffset);\r
ef05e063 234 } else {\r
235 OldCoreData->HobList.Raw = (VOID *)(OldCoreData->HobList.Raw - OldCoreData->HeapOffset);\r
111e6c92
SZ
236 if (OldCoreData->UnknownFvInfo != NULL) {\r
237 OldCoreData->UnknownFvInfo = (PEI_CORE_UNKNOW_FORMAT_FV_INFO *) ((UINT8 *) OldCoreData->UnknownFvInfo - OldCoreData->HeapOffset);\r
238 }\r
b62fe570
SZ
239 if (OldCoreData->CurrentFvFileHandles != NULL) {\r
240 OldCoreData->CurrentFvFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->CurrentFvFileHandles - OldCoreData->HeapOffset);\r
241 }\r
f2bc359c
SZ
242 if (OldCoreData->PpiData.PpiList.PpiPtrs != NULL) {\r
243 OldCoreData->PpiData.PpiList.PpiPtrs = (PEI_PPI_LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.PpiList.PpiPtrs - OldCoreData->HeapOffset);\r
244 }\r
245 if (OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs != NULL) {\r
246 OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs = (PEI_PPI_LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs - OldCoreData->HeapOffset);\r
247 }\r
248 if (OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs != NULL) {\r
249 OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs = (PEI_PPI_LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs - OldCoreData->HeapOffset);\r
250 }\r
fe781940 251 OldCoreData->Fv = (PEI_CORE_FV_HANDLE *) ((UINT8 *) OldCoreData->Fv - OldCoreData->HeapOffset);\r
111e6c92 252 for (Index = 0; Index < OldCoreData->FvCount; Index ++) {\r
b62fe570
SZ
253 if (OldCoreData->Fv[Index].PeimState != NULL) {\r
254 OldCoreData->Fv[Index].PeimState = (UINT8 *) OldCoreData->Fv[Index].PeimState - OldCoreData->HeapOffset;\r
255 }\r
256 if (OldCoreData->Fv[Index].FvFileHandles != NULL) {\r
257 OldCoreData->Fv[Index].FvFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->Fv[Index].FvFileHandles - OldCoreData->HeapOffset);\r
258 }\r
fe781940 259 }\r
b62fe570
SZ
260 OldCoreData->TempFileGuid = (EFI_GUID *) ((UINT8 *) OldCoreData->TempFileGuid - OldCoreData->HeapOffset);\r
261 OldCoreData->TempFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->TempFileHandles - OldCoreData->HeapOffset);\r
ef05e063 262 }\r
263\r
264 //\r
265 // Fixup for PeiService's address\r
266 //\r
267 SetPeiServicesTablePointer ((CONST EFI_PEI_SERVICES **)&OldCoreData->Ps);\r
268\r
75fe0a78
LG
269 //\r
270 // Initialize libraries that the PEI Core is linked against\r
271 //\r
272 ProcessLibraryConstructorList (NULL, (CONST EFI_PEI_SERVICES **)&OldCoreData->Ps);\r
273\r
ef05e063 274 //\r
6393d9c8 275 // Update HandOffHob for new installed permanent memory\r
ef05e063 276 //\r
277 HandoffInformationTable = OldCoreData->HobList.HandoffInformationTable;\r
278 if (OldCoreData->HeapOffsetPositive) {\r
279 HandoffInformationTable->EfiEndOfHobList = HandoffInformationTable->EfiEndOfHobList + OldCoreData->HeapOffset;\r
280 } else {\r
281 HandoffInformationTable->EfiEndOfHobList = HandoffInformationTable->EfiEndOfHobList - OldCoreData->HeapOffset;\r
282 }\r
283 HandoffInformationTable->EfiMemoryTop = OldCoreData->PhysicalMemoryBegin + OldCoreData->PhysicalMemoryLength;\r
284 HandoffInformationTable->EfiMemoryBottom = OldCoreData->PhysicalMemoryBegin;\r
285 HandoffInformationTable->EfiFreeMemoryTop = OldCoreData->FreePhysicalMemoryTop;\r
286 HandoffInformationTable->EfiFreeMemoryBottom = HandoffInformationTable->EfiEndOfHobList + sizeof (EFI_HOB_GENERIC_HEADER);\r
287\r
b2374cec
SZ
288 //\r
289 // We need convert MemoryBaseAddress in memory allocation HOBs\r
290 //\r
291 ConvertMemoryAllocationHobs (OldCoreData);\r
292\r
ef05e063 293 //\r
424b7c9f 294 // We need convert the PPI descriptor's pointer\r
ef05e063 295 //\r
424b7c9f 296 ConvertPpiPointers (SecCoreData, OldCoreData);\r
ef05e063 297\r
298 //\r
299 // After the whole temporary memory is migrated, then we can allocate page in\r
6393d9c8 300 // permanent memory.\r
ef05e063 301 //\r
302 OldCoreData->PeiMemoryInstalled = TRUE;\r
303\r
304 //\r
305 // Indicate that PeiCore reenter\r
306 //\r
307 OldCoreData->PeimDispatcherReenter = TRUE;\r
d1102dba 308\r
ef05e063 309 if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 && (OldCoreData->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
310 //\r
311 // if Loading Module at Fixed Address is enabled, allocate the PEI code memory range usage bit map array.\r
312 // Every bit in the array indicate the status of the corresponding memory page available or not\r
313 //\r
314 OldCoreData->PeiCodeMemoryRangeUsageBitMap = AllocateZeroPool (((PcdGet32(PcdLoadFixAddressPeiCodePageNumber)>>6) + 1)*sizeof(UINT64));\r
315 }\r
316\r
ef05e063 317 //\r
d39d1260 318 // Shadow PEI Core. When permanent memory is available, shadow\r
ef05e063 319 // PEI Core and PEIMs to get high performance.\r
320 //\r
3d44658c 321 OldCoreData->ShadowedPeiCore = (PEICORE_FUNCTION_POINTER) (UINTN) PeiCore;\r
9bedaec0
MK
322 if (PcdGetBool (PcdMigrateTemporaryRamFirmwareVolumes) ||\r
323 (HandoffInformationTable->BootMode == BOOT_ON_S3_RESUME && PcdGetBool (PcdShadowPeimOnS3Boot)) ||\r
324 (HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME && PcdGetBool (PcdShadowPeimOnBoot))) {\r
3d44658c
LG
325 OldCoreData->ShadowedPeiCore = ShadowPeiCore (OldCoreData);\r
326 }\r
d1102dba 327\r
ef05e063 328 //\r
6b22483f 329 // PEI Core has now been shadowed to memory. Restart PEI Core in memory.\r
ef05e063 330 //\r
331 OldCoreData->ShadowedPeiCore (SecCoreData, PpiList, OldCoreData);\r
d1102dba 332\r
6b22483f 333 //\r
334 // Should never reach here.\r
335 //\r
336 ASSERT (FALSE);\r
337 CpuDeadLoop();\r
3a7daf9e
MH
338\r
339 UNREACHABLE ();\r
58dcdada 340 }\r
341\r
6b22483f 342 //\r
343 // Memory is available to the PEI Core and the PEI Core has been shadowed to memory.\r
344 //\r
0f9ebb32
LG
345 CopyMem (&NewSecCoreData, SecCoreDataPtr, sizeof (NewSecCoreData));\r
346 SecCoreData = &NewSecCoreData;\r
347\r
ef05e063 348 CopyMem (&PrivateData, OldCoreData, sizeof (PrivateData));\r
0f9ebb32 349\r
b0d803fe 350 CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;\r
351 PciCfg = (VOID*)PrivateData.ServiceTableShadow.PciCfg;\r
d1102dba 352\r
b1f6a7c6 353 CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r
d1102dba 354\r
b0d803fe 355 PrivateData.ServiceTableShadow.CpuIo = CpuIo;\r
356 PrivateData.ServiceTableShadow.PciCfg = PciCfg;\r
192f6d4c 357 }\r
d1102dba 358\r
6b22483f 359 //\r
360 // Cache a pointer to the PEI Services Table that is either in temporary memory or permanent memory\r
361 //\r
4140a663 362 PrivateData.Ps = &PrivateData.ServiceTableShadow;\r
192f6d4c 363\r
364 //\r
75fe0a78 365 // Save PeiServicePointer so that it can be retrieved anywhere.\r
192f6d4c 366 //\r
75fe0a78 367 SetPeiServicesTablePointer ((CONST EFI_PEI_SERVICES **)&PrivateData.Ps);\r
192f6d4c 368\r
81c7803c 369 //\r
75fe0a78 370 // Initialize libraries that the PEI Core is linked against\r
81c7803c 371 //\r
75fe0a78 372 ProcessLibraryConstructorList (NULL, (CONST EFI_PEI_SERVICES **)&PrivateData.Ps);\r
192f6d4c 373\r
6b22483f 374 //\r
375 // Initialize PEI Core Services\r
fe781940 376 //\r
b62fe570 377 InitializeMemoryServices (&PrivateData, SecCoreData, OldCoreData);\r
d1102dba 378\r
6b22483f 379 //\r
d1102dba 380 // Update performance measurements\r
6b22483f 381 //\r
382 if (OldCoreData == NULL) {\r
67e9ab84 383 PERF_EVENT ("SEC"); // Means the end of SEC phase.\r
192f6d4c 384\r
192f6d4c 385 //\r
6b22483f 386 // If first pass, start performance measurement.\r
192f6d4c 387 //\r
67e9ab84
BD
388 PERF_CROSSMODULE_BEGIN ("PEI");\r
389 PERF_INMODULE_BEGIN ("PreMem");\r
192f6d4c 390\r
391 } else {\r
67e9ab84
BD
392 PERF_INMODULE_END ("PreMem");\r
393 PERF_INMODULE_BEGIN ("PostMem");\r
6b22483f 394 }\r
395\r
396 //\r
397 // Complete PEI Core Service initialization\r
d1102dba 398 //\r
6b22483f 399 InitializeSecurityServices (&PrivateData.Ps, OldCoreData);\r
400 InitializeDispatcherData (&PrivateData, OldCoreData, SecCoreData);\r
401 InitializeImageServices (&PrivateData, OldCoreData);\r
192f6d4c 402\r
6b22483f 403 //\r
404 // Perform PEI Core Phase specific actions\r
d1102dba 405 //\r
6b22483f 406 if (OldCoreData == NULL) {\r
192f6d4c 407 //\r
408 // Report Status Code EFI_SW_PC_INIT\r
409 //\r
410 REPORT_STATUS_CODE (\r
411 EFI_PROGRESS_CODE,\r
f9876ecf 412 (EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT)\r
192f6d4c 413 );\r
d1102dba 414\r
192f6d4c 415 //\r
884200f9 416 // If SEC provided the PpiList, process it.\r
192f6d4c 417 //\r
5088e385 418 if (PpiList != NULL) {\r
884200f9 419 ProcessPpiListFromSec ((CONST EFI_PEI_SERVICES **) &PrivateData.Ps, PpiList);\r
192f6d4c 420 }\r
6b22483f 421 } else {\r
9bedaec0
MK
422 if (PcdGetBool (PcdMigrateTemporaryRamFirmwareVolumes)) {\r
423 //\r
424 // When PcdMigrateTemporaryRamFirmwareVolumes is TRUE, alway shadow all\r
425 // PEIMs no matter the condition of PcdShadowPeimOnBoot and PcdShadowPeimOnS3Boot\r
426 //\r
427 DEBUG ((DEBUG_VERBOSE, "PPI lists before temporary RAM evacuation:\n"));\r
428 DumpPpiList (&PrivateData);\r
429\r
430 //\r
431 // Migrate installed content from Temporary RAM to Permanent RAM\r
432 //\r
433 EvacuateTempRam (&PrivateData, SecCoreData);\r
434\r
435 DEBUG ((DEBUG_VERBOSE, "PPI lists after temporary RAM evacuation:\n"));\r
436 DumpPpiList (&PrivateData);\r
437 }\r
438\r
0f9ebb32
LG
439 //\r
440 // Try to locate Temporary RAM Done Ppi.\r
441 //\r
442 Status = PeiServicesLocatePpi (\r
443 &gEfiTemporaryRamDonePpiGuid,\r
444 0,\r
445 NULL,\r
446 (VOID**)&TemporaryRamDonePpi\r
447 );\r
448 if (!EFI_ERROR (Status)) {\r
449 //\r
450 // Disable the use of Temporary RAM after the transition from Temporary RAM to Permanent RAM is complete.\r
451 //\r
452 TemporaryRamDonePpi->TemporaryRamDone ();\r
453 }\r
454\r
6b22483f 455 //\r
456 // Alert any listeners that there is permanent memory available\r
457 //\r
67e9ab84 458 PERF_INMODULE_BEGIN ("DisMem");\r
6b22483f 459 Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);\r
b0d803fe 460\r
6b22483f 461 //\r
462 // Process the Notify list and dispatch any notifies for the Memory Discovered PPI\r
463 //\r
f2bc359c 464 ProcessDispatchNotifyList (&PrivateData);\r
b0d803fe 465\r
67e9ab84 466 PERF_INMODULE_END ("DisMem");\r
6b22483f 467 }\r
192f6d4c 468\r
469 //\r
470 // Call PEIM dispatcher\r
471 //\r
b0d803fe 472 PeiDispatcher (SecCoreData, &PrivateData);\r
192f6d4c 473\r
ebaafbe6
EC
474 if (PrivateData.HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME) {\r
475 //\r
476 // Check if InstallPeiMemory service was called on non-S3 resume boot path.\r
477 //\r
478 ASSERT(PrivateData.PeiMemoryInstalled == TRUE);\r
479 }\r
192f6d4c 480\r
40f26b8f 481 //\r
6b22483f 482 // Measure PEI Core execution time.\r
40f26b8f 483 //\r
67e9ab84 484 PERF_INMODULE_END ("PostMem");\r
192f6d4c 485\r
6b22483f 486 //\r
487 // Lookup DXE IPL PPI\r
488 //\r
192f6d4c 489 Status = PeiServicesLocatePpi (\r
490 &gEfiDxeIplPpiGuid,\r
491 0,\r
492 NULL,\r
493 (VOID **)&TempPtr.DxeIpl\r
494 );\r
495 ASSERT_EFI_ERROR (Status);\r
496\r
206f4121
EL
497 if (EFI_ERROR (Status)) {\r
498 //\r
499 // Report status code to indicate DXE IPL PPI could not be found.\r
500 //\r
501 REPORT_STATUS_CODE (\r
502 EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r
503 (EFI_SOFTWARE_PEI_CORE | EFI_SW_PEI_CORE_EC_DXEIPL_NOT_FOUND)\r
504 );\r
505 CpuDeadLoop ();\r
506 }\r
507\r
40f26b8f 508 //\r
509 // Enter DxeIpl to load Dxe core.\r
510 //\r
192f6d4c 511 DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));\r
512 Status = TempPtr.DxeIpl->Entry (\r
513 TempPtr.DxeIpl,\r
4140a663 514 &PrivateData.Ps,\r
192f6d4c 515 PrivateData.HobList\r
516 );\r
0308e20d 517 //\r
518 // Should never reach here.\r
519 //\r
192f6d4c 520 ASSERT_EFI_ERROR (Status);\r
0308e20d 521 CpuDeadLoop();\r
3a7daf9e
MH
522\r
523 UNREACHABLE ();\r
192f6d4c 524}\r