]>
Commit | Line | Data |
---|---|---|
96226baa | 1 | /** @file\r |
b0d803fe | 2 | Last PEIM.\r |
3 | Responsibility of this module is to load the DXE Core from a Firmware Volume.\r | |
95276127 | 4 | \r |
ebaafbe6 | 5 | Copyright (c) 2016 HP Development Company, L.P.\r |
e761d18f | 6 | Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r |
9d510e61 | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
95276127 | 8 | \r |
b0d803fe | 9 | **/\r |
95276127 | 10 | \r |
95276127 | 11 | #include "DxeIpl.h"\r |
b0d803fe | 12 | \r |
95276127 | 13 | //\r |
48557c65 | 14 | // Module Globals used in the DXE to PEI hand off\r |
95276127 | 15 | // These must be module globals, so the stack can be switched\r |
16 | //\r | |
1436aea4 | 17 | CONST EFI_DXE_IPL_PPI mDxeIplPpi = {\r |
95276127 | 18 | DxeLoadCore\r |
19 | };\r | |
20 | \r | |
1436aea4 | 21 | CONST EFI_PEI_PPI_DESCRIPTOR mDxeIplPpiList = {\r |
ebaafbe6 EC |
22 | EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r |
23 | &gEfiDxeIplPpiGuid,\r | |
1436aea4 | 24 | (VOID *)&mDxeIplPpi\r |
ebaafbe6 EC |
25 | };\r |
26 | \r | |
1436aea4 | 27 | CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi = {\r |
18fd8d65 | 28 | CustomGuidedSectionExtract\r |
95276127 | 29 | };\r |
30 | \r | |
1436aea4 | 31 | CONST EFI_PEI_DECOMPRESS_PPI mDecompressPpi = {\r |
b0d803fe | 32 | Decompress\r |
d8c79a81 LG |
33 | };\r |
34 | \r | |
1436aea4 | 35 | CONST EFI_PEI_PPI_DESCRIPTOR mDecompressPpiList = {\r |
ebaafbe6 EC |
36 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r |
37 | &gEfiPeiDecompressPpiGuid,\r | |
1436aea4 | 38 | (VOID *)&mDecompressPpi\r |
95276127 | 39 | };\r |
40 | \r | |
1436aea4 | 41 | CONST EFI_PEI_PPI_DESCRIPTOR gEndOfPeiSignalPpi = {\r |
95276127 | 42 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r |
43 | &gEfiEndOfPeiSignalPpiGuid,\r | |
44 | NULL\r | |
45 | };\r | |
46 | \r | |
1436aea4 | 47 | CONST EFI_PEI_NOTIFY_DESCRIPTOR mMemoryDiscoveredNotifyList = {\r |
ebaafbe6 EC |
48 | (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r |
49 | &gEfiPeiMemoryDiscoveredPpiGuid,\r | |
50 | InstallIplPermanentMemoryPpis\r | |
51 | };\r | |
52 | \r | |
b0d803fe | 53 | /**\r |
48557c65 | 54 | Entry point of DXE IPL PEIM.\r |
ebaafbe6 EC |
55 | \r |
56 | This function installs DXE IPL PPI. It also reloads\r | |
48557c65 | 57 | itself to memory on non-S3 resume boot path.\r |
b0d803fe | 58 | \r |
a55caa53 LG |
59 | @param FileHandle Handle of the file being invoked.\r |
60 | @param PeiServices Describes the list of possible PEI Services.\r | |
91d92e25 | 61 | \r |
48557c65 | 62 | @retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfully.\r |
d1102dba | 63 | @retval Others Some error occurs during the execution of this function.\r |
48557c65 | 64 | \r |
91d92e25 | 65 | **/\r |
95276127 | 66 | EFI_STATUS\r |
67 | EFIAPI\r | |
68 | PeimInitializeDxeIpl (\r | |
a55caa53 LG |
69 | IN EFI_PEI_FILE_HANDLE FileHandle,\r |
70 | IN CONST EFI_PEI_SERVICES **PeiServices\r | |
95276127 | 71 | )\r |
95276127 | 72 | {\r |
1436aea4 MK |
73 | EFI_STATUS Status;\r |
74 | EFI_BOOT_MODE BootMode;\r | |
75 | VOID *Dummy;\r | |
ebaafbe6 | 76 | \r |
b98da1b1 | 77 | BootMode = GetBootModeHob ();\r |
95276127 | 78 | \r |
b0d803fe | 79 | if (BootMode != BOOT_ON_S3_RESUME) {\r |
a55caa53 | 80 | Status = PeiServicesRegisterForShadow (FileHandle);\r |
b0d803fe | 81 | if (Status == EFI_SUCCESS) {\r |
b0d803fe | 82 | //\r |
d1102dba LG |
83 | // EFI_SUCESS means it is the first time to call register for shadow.\r |
84 | //\r | |
b0d803fe | 85 | return Status;\r |
48557c65 | 86 | }\r |
ebaafbe6 | 87 | \r |
48557c65 | 88 | //\r |
89 | // Ensure that DXE IPL is shadowed to permanent memory.\r | |
90 | //\r | |
91 | ASSERT (Status == EFI_ALREADY_STARTED);\r | |
ebaafbe6 EC |
92 | \r |
93 | //\r | |
94 | // DXE core load requires permanent memory.\r | |
95 | //\r | |
96 | Status = PeiServicesLocatePpi (\r | |
97 | &gEfiPeiMemoryDiscoveredPpiGuid,\r | |
98 | 0,\r | |
99 | NULL,\r | |
1436aea4 | 100 | (VOID **)&Dummy\r |
ebaafbe6 EC |
101 | );\r |
102 | ASSERT_EFI_ERROR (Status);\r | |
103 | if (EFI_ERROR (Status)) {\r | |
104 | return Status;\r | |
105 | }\r | |
106 | \r | |
107 | //\r | |
108 | // Now the permanent memory exists, install the PPIs for decompression\r | |
109 | // and section extraction.\r | |
110 | //\r | |
111 | Status = InstallIplPermanentMemoryPpis (NULL, NULL, NULL);\r | |
d1102dba | 112 | ASSERT_EFI_ERROR (Status);\r |
ebaafbe6 EC |
113 | } else {\r |
114 | //\r | |
115 | // Install memory discovered PPI notification to install PPIs for\r | |
116 | // decompression and section extraction.\r | |
117 | //\r | |
118 | Status = PeiServicesNotifyPpi (&mMemoryDiscoveredNotifyList);\r | |
119 | ASSERT_EFI_ERROR (Status);\r | |
25bc8326 | 120 | }\r |
ebaafbe6 EC |
121 | \r |
122 | //\r | |
123 | // Install DxeIpl PPI.\r | |
124 | //\r | |
125 | Status = PeiServicesInstallPpi (&mDxeIplPpiList);\r | |
1436aea4 | 126 | ASSERT_EFI_ERROR (Status);\r |
ebaafbe6 EC |
127 | \r |
128 | return Status;\r | |
129 | }\r | |
130 | \r | |
131 | /**\r | |
132 | This function installs the PPIs that require permanent memory.\r | |
133 | \r | |
134 | @param PeiServices Indirect reference to the PEI Services Table.\r | |
135 | @param NotifyDescriptor Address of the notification descriptor data structure.\r | |
136 | @param Ppi Address of the PPI that was installed.\r | |
137 | \r | |
138 | @return EFI_SUCCESS The PPIs were installed successfully.\r | |
139 | @return Others Some error occurs during the execution of this function.\r | |
140 | \r | |
141 | **/\r | |
142 | EFI_STATUS\r | |
143 | EFIAPI\r | |
144 | InstallIplPermanentMemoryPpis (\r | |
145 | IN EFI_PEI_SERVICES **PeiServices,\r | |
146 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r | |
147 | IN VOID *Ppi\r | |
148 | )\r | |
149 | {\r | |
1436aea4 MK |
150 | EFI_STATUS Status;\r |
151 | EFI_GUID *ExtractHandlerGuidTable;\r | |
152 | UINTN ExtractHandlerNumber;\r | |
153 | EFI_PEI_PPI_DESCRIPTOR *GuidPpi;\r | |
ebaafbe6 | 154 | \r |
25bc8326 | 155 | //\r |
d1102dba | 156 | // Get custom extract guided section method guid list\r |
25bc8326 LG |
157 | //\r |
158 | ExtractHandlerNumber = ExtractGuidedSectionGetGuidList (&ExtractHandlerGuidTable);\r | |
ebaafbe6 | 159 | \r |
25bc8326 | 160 | //\r |
ebaafbe6 | 161 | // Install custom guided section extraction PPI\r |
25bc8326 LG |
162 | //\r |
163 | if (ExtractHandlerNumber > 0) {\r | |
1436aea4 | 164 | GuidPpi = (EFI_PEI_PPI_DESCRIPTOR *)AllocatePool (ExtractHandlerNumber * sizeof (EFI_PEI_PPI_DESCRIPTOR));\r |
25bc8326 LG |
165 | ASSERT (GuidPpi != NULL);\r |
166 | while (ExtractHandlerNumber-- > 0) {\r | |
167 | GuidPpi->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;\r | |
1436aea4 | 168 | GuidPpi->Ppi = (VOID *)&mCustomGuidedSectionExtractionPpi;\r |
25bc8326 | 169 | GuidPpi->Guid = &ExtractHandlerGuidTable[ExtractHandlerNumber];\r |
1436aea4 MK |
170 | Status = PeiServicesInstallPpi (GuidPpi++);\r |
171 | ASSERT_EFI_ERROR (Status);\r | |
d8c79a81 | 172 | }\r |
95276127 | 173 | }\r |
ebaafbe6 | 174 | \r |
b0d803fe | 175 | //\r |
ebaafbe6 | 176 | // Install Decompress PPI.\r |
b0d803fe | 177 | //\r |
ebaafbe6 | 178 | Status = PeiServicesInstallPpi (&mDecompressPpiList);\r |
1436aea4 | 179 | ASSERT_EFI_ERROR (Status);\r |
288f9b38 | 180 | \r |
95276127 | 181 | return Status;\r |
182 | }\r | |
183 | \r | |
a95b6045 | 184 | /**\r |
d1102dba | 185 | Validate variable data for the MemoryTypeInformation.\r |
a95b6045 ED |
186 | \r |
187 | @param MemoryData Variable data.\r | |
188 | @param MemoryDataSize Variable data length.\r | |
189 | \r | |
190 | @return TRUE The variable data is valid.\r | |
191 | @return FALSE The variable data is invalid.\r | |
192 | \r | |
193 | **/\r | |
194 | BOOLEAN\r | |
195 | ValidateMemoryTypeInfoVariable (\r | |
1436aea4 MK |
196 | IN EFI_MEMORY_TYPE_INFORMATION *MemoryData,\r |
197 | IN UINTN MemoryDataSize\r | |
a95b6045 ED |
198 | )\r |
199 | {\r | |
1436aea4 MK |
200 | UINTN Count;\r |
201 | UINTN Index;\r | |
a95b6045 ED |
202 | \r |
203 | // Check the input parameter.\r | |
204 | if (MemoryData == NULL) {\r | |
205 | return FALSE;\r | |
206 | }\r | |
207 | \r | |
208 | // Get Count\r | |
209 | Count = MemoryDataSize / sizeof (*MemoryData);\r | |
210 | \r | |
211 | // Check Size\r | |
1436aea4 | 212 | if (Count * sizeof (*MemoryData) != MemoryDataSize) {\r |
a95b6045 ED |
213 | return FALSE;\r |
214 | }\r | |
215 | \r | |
216 | // Check last entry type filed.\r | |
217 | if (MemoryData[Count - 1].Type != EfiMaxMemoryType) {\r | |
218 | return FALSE;\r | |
219 | }\r | |
220 | \r | |
221 | // Check the type filed.\r | |
222 | for (Index = 0; Index < Count - 1; Index++) {\r | |
223 | if (MemoryData[Index].Type >= EfiMaxMemoryType) {\r | |
224 | return FALSE;\r | |
225 | }\r | |
226 | }\r | |
227 | \r | |
228 | return TRUE;\r | |
229 | }\r | |
230 | \r | |
b0d803fe | 231 | /**\r |
d1102dba | 232 | Main entry point to last PEIM.\r |
48557c65 | 233 | \r |
234 | This function finds DXE Core in the firmware volume and transfer the control to\r | |
235 | DXE core.\r | |
d1102dba | 236 | \r |
b98da1b1 | 237 | @param This Entry point for DXE IPL PPI.\r |
b0d803fe | 238 | @param PeiServices General purpose services available to every PEIM.\r |
b98da1b1 | 239 | @param HobList Address to the Pei HOB list.\r |
d1102dba LG |
240 | \r |
241 | @return EFI_SUCCESS DXE core was successfully loaded.\r | |
b0d803fe | 242 | @return EFI_OUT_OF_RESOURCES There are not enough resources to load DXE core.\r |
91d92e25 | 243 | \r |
b0d803fe | 244 | **/\r |
95276127 | 245 | EFI_STATUS\r |
246 | EFIAPI\r | |
247 | DxeLoadCore (\r | |
1436aea4 MK |
248 | IN CONST EFI_DXE_IPL_PPI *This,\r |
249 | IN EFI_PEI_SERVICES **PeiServices,\r | |
250 | IN EFI_PEI_HOB_POINTERS HobList\r | |
95276127 | 251 | )\r |
95276127 | 252 | {\r |
1436aea4 MK |
253 | EFI_STATUS Status;\r |
254 | EFI_FV_FILE_INFO DxeCoreFileInfo;\r | |
255 | EFI_PHYSICAL_ADDRESS DxeCoreAddress;\r | |
256 | UINT64 DxeCoreSize;\r | |
257 | EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint;\r | |
258 | EFI_BOOT_MODE BootMode;\r | |
259 | EFI_PEI_FILE_HANDLE FileHandle;\r | |
260 | EFI_PEI_READ_ONLY_VARIABLE2_PPI *Variable;\r | |
261 | EFI_PEI_LOAD_FILE_PPI *LoadFile;\r | |
262 | UINTN Instance;\r | |
263 | UINT32 AuthenticationState;\r | |
264 | UINTN DataSize;\r | |
265 | EFI_PEI_S3_RESUME2_PPI *S3Resume;\r | |
266 | EFI_PEI_RECOVERY_MODULE_PPI *PeiRecovery;\r | |
267 | EDKII_PEI_CAPSULE_ON_DISK_PPI *PeiCapsuleOnDisk;\r | |
268 | EFI_MEMORY_TYPE_INFORMATION MemoryData[EfiMaxMemoryType + 1];\r | |
269 | VOID *CapsuleOnDiskModePpi;\r | |
95276127 | 270 | \r |
271 | //\r | |
272 | // if in S3 Resume, restore configure\r | |
273 | //\r | |
b98da1b1 | 274 | BootMode = GetBootModeHob ();\r |
95276127 | 275 | \r |
276 | if (BootMode == BOOT_ON_S3_RESUME) {\r | |
28efc722 | 277 | Status = PeiServicesLocatePpi (\r |
77215d10 | 278 | &gEfiPeiS3Resume2PpiGuid,\r |
28efc722 | 279 | 0,\r |
280 | NULL,\r | |
1436aea4 | 281 | (VOID **)&S3Resume\r |
28efc722 | 282 | );\r |
37623a5c | 283 | if (EFI_ERROR (Status)) {\r |
284 | //\r | |
285 | // Report Status code that S3Resume PPI can not be found\r | |
286 | //\r | |
287 | REPORT_STATUS_CODE (\r | |
288 | EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r | |
289 | (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_S3_RESUME_PPI_NOT_FOUND)\r | |
290 | );\r | |
291 | }\r | |
1436aea4 | 292 | \r |
28efc722 | 293 | ASSERT_EFI_ERROR (Status);\r |
d1102dba | 294 | \r |
77215d10 | 295 | Status = S3Resume->S3RestoreConfig2 (S3Resume);\r |
95276127 | 296 | ASSERT_EFI_ERROR (Status);\r |
297 | } else if (BootMode == BOOT_IN_RECOVERY_MODE) {\r | |
37623a5c | 298 | REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_RECOVERY_BEGIN));\r |
28efc722 | 299 | Status = PeiServicesLocatePpi (\r |
300 | &gEfiPeiRecoveryModulePpiGuid,\r | |
301 | 0,\r | |
302 | NULL,\r | |
1436aea4 | 303 | (VOID **)&PeiRecovery\r |
28efc722 | 304 | );\r |
83d06ed9 | 305 | \r |
306 | if (EFI_ERROR (Status)) {\r | |
307 | DEBUG ((DEBUG_ERROR, "Locate Recovery PPI Failed.(Status = %r)\n", Status));\r | |
308 | //\r | |
d1102dba | 309 | // Report Status code the failure of locating Recovery PPI\r |
83d06ed9 | 310 | //\r |
311 | REPORT_STATUS_CODE (\r | |
312 | EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r | |
313 | (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_RECOVERY_PPI_NOT_FOUND)\r | |
314 | );\r | |
315 | CpuDeadLoop ();\r | |
316 | }\r | |
317 | \r | |
37623a5c | 318 | REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_CAPSULE_LOAD));\r |
28efc722 | 319 | Status = PeiRecovery->LoadRecoveryCapsule (PeiServices, PeiRecovery);\r |
95276127 | 320 | if (EFI_ERROR (Status)) {\r |
91d92e25 | 321 | DEBUG ((DEBUG_ERROR, "Load Recovery Capsule Failed.(Status = %r)\n", Status));\r |
37623a5c | 322 | //\r |
83d06ed9 | 323 | // Report Status code that recovery image can not be found\r |
37623a5c | 324 | //\r |
325 | REPORT_STATUS_CODE (\r | |
326 | EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r | |
327 | (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_NO_RECOVERY_CAPSULE)\r | |
328 | );\r | |
95276127 | 329 | CpuDeadLoop ();\r |
330 | }\r | |
1436aea4 | 331 | \r |
37623a5c | 332 | REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_CAPSULE_START));\r |
95276127 | 333 | //\r |
48557c65 | 334 | // Now should have a HOB with the DXE core\r |
95276127 | 335 | //\r |
e761d18f WX |
336 | } else if (BootMode == BOOT_ON_FLASH_UPDATE) {\r |
337 | //\r | |
338 | // If Capsule On Disk mode, call storage stack to read Capsule Relocation file\r | |
339 | // IoMmmu is highly recommmended to enable before reading\r | |
340 | //\r | |
341 | Status = PeiServicesLocatePpi (\r | |
342 | &gEdkiiPeiBootInCapsuleOnDiskModePpiGuid,\r | |
343 | 0,\r | |
344 | NULL,\r | |
345 | &CapsuleOnDiskModePpi\r | |
346 | );\r | |
1436aea4 | 347 | if (!EFI_ERROR (Status)) {\r |
e761d18f WX |
348 | Status = PeiServicesLocatePpi (\r |
349 | &gEdkiiPeiCapsuleOnDiskPpiGuid,\r | |
350 | 0,\r | |
351 | NULL,\r | |
1436aea4 | 352 | (VOID **)&PeiCapsuleOnDisk\r |
e761d18f WX |
353 | );\r |
354 | \r | |
355 | //\r | |
356 | // Whether failed, still goes to Firmware Update boot path. BDS will clear corresponding indicator and reboot later on\r | |
357 | //\r | |
358 | if (!EFI_ERROR (Status)) {\r | |
359 | Status = PeiCapsuleOnDisk->LoadCapsuleOnDisk (PeiServices, PeiCapsuleOnDisk);\r | |
360 | }\r | |
361 | }\r | |
95276127 | 362 | }\r |
288f9b38 | 363 | \r |
d1d89e86 LG |
364 | if (GetFirstGuidHob ((CONST EFI_GUID *)&gEfiMemoryTypeInformationGuid) == NULL) {\r |
365 | //\r | |
366 | // Don't build GuidHob if GuidHob has been installed.\r | |
367 | //\r | |
368 | Status = PeiServicesLocatePpi (\r | |
369 | &gEfiPeiReadOnlyVariable2PpiGuid,\r | |
370 | 0,\r | |
371 | NULL,\r | |
372 | (VOID **)&Variable\r | |
373 | );\r | |
374 | if (!EFI_ERROR (Status)) {\r | |
375 | DataSize = sizeof (MemoryData);\r | |
1436aea4 MK |
376 | Status = Variable->GetVariable (\r |
377 | Variable,\r | |
378 | EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r | |
379 | &gEfiMemoryTypeInformationGuid,\r | |
380 | NULL,\r | |
381 | &DataSize,\r | |
382 | &MemoryData\r | |
383 | );\r | |
384 | if (!EFI_ERROR (Status) && ValidateMemoryTypeInfoVariable (MemoryData, DataSize)) {\r | |
d1d89e86 LG |
385 | //\r |
386 | // Build the GUID'd HOB for DXE\r | |
387 | //\r | |
388 | BuildGuidDataHob (\r | |
389 | &gEfiMemoryTypeInformationGuid,\r | |
390 | MemoryData,\r | |
391 | DataSize\r | |
392 | );\r | |
393 | }\r | |
1ad76c34 | 394 | }\r |
b74350e9 | 395 | }\r |
288f9b38 | 396 | \r |
95276127 | 397 | //\r |
b6b98e91 | 398 | // Look in all the FVs present in PEI and find the DXE Core FileHandle\r |
95276127 | 399 | //\r |
b6b98e91 | 400 | FileHandle = DxeIplFindDxeCore ();\r |
b0d803fe | 401 | \r |
95276127 | 402 | //\r |
28efc722 | 403 | // Load the DXE Core from a Firmware Volume.\r |
95276127 | 404 | //\r |
28efc722 | 405 | Instance = 0;\r |
406 | do {\r | |
1436aea4 | 407 | Status = PeiServicesLocatePpi (&gEfiPeiLoadFilePpiGuid, Instance++, NULL, (VOID **)&LoadFile);\r |
28efc722 | 408 | //\r |
409 | // These must exist an instance of EFI_PEI_LOAD_FILE_PPI to support to load DxeCore file handle successfully.\r | |
410 | //\r | |
411 | ASSERT_EFI_ERROR (Status);\r | |
412 | \r | |
413 | Status = LoadFile->LoadFile (\r | |
414 | LoadFile,\r | |
415 | FileHandle,\r | |
416 | &DxeCoreAddress,\r | |
417 | &DxeCoreSize,\r | |
418 | &DxeCoreEntryPoint,\r | |
419 | &AuthenticationState\r | |
420 | );\r | |
421 | } while (EFI_ERROR (Status));\r | |
95276127 | 422 | \r |
b6b98e91 | 423 | //\r |
424 | // Get the DxeCore File Info from the FileHandle for the DxeCore GUID file name.\r | |
425 | //\r | |
426 | Status = PeiServicesFfsGetFileInfo (FileHandle, &DxeCoreFileInfo);\r | |
427 | ASSERT_EFI_ERROR (Status);\r | |
428 | \r | |
95276127 | 429 | //\r |
430 | // Add HOB for the DXE Core\r | |
431 | //\r | |
432 | BuildModuleHob (\r | |
b6b98e91 | 433 | &DxeCoreFileInfo.FileName,\r |
95276127 | 434 | DxeCoreAddress,\r |
48557c65 | 435 | ALIGN_VALUE (DxeCoreSize, EFI_PAGE_SIZE),\r |
95276127 | 436 | DxeCoreEntryPoint\r |
437 | );\r | |
438 | \r | |
439 | //\r | |
440 | // Report Status Code EFI_SW_PEI_PC_HANDOFF_TO_NEXT\r | |
441 | //\r | |
f9876ecf | 442 | REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_CORE | EFI_SW_PEI_CORE_PC_HANDOFF_TO_NEXT));\r |
95276127 | 443 | \r |
4e2dd553 | 444 | DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading DXE CORE at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN)DxeCoreAddress, FUNCTION_ENTRY_POINT (DxeCoreEntryPoint)));\r |
e98cd821 | 445 | \r |
95276127 | 446 | //\r |
447 | // Transfer control to the DXE Core\r | |
48557c65 | 448 | // The hand off state is simply a pointer to the HOB list\r |
95276127 | 449 | //\r |
9b937a73 | 450 | HandOffToDxeCore (DxeCoreEntryPoint, HobList);\r |
95276127 | 451 | //\r |
452 | // If we get here, then the DXE Core returned. This is an error\r | |
48557c65 | 453 | // DxeCore should not return.\r |
95276127 | 454 | //\r |
455 | ASSERT (FALSE);\r | |
456 | CpuDeadLoop ();\r | |
457 | \r | |
458 | return EFI_OUT_OF_RESOURCES;\r | |
459 | }\r | |
460 | \r | |
b0d803fe | 461 | /**\r |
9b937a73 | 462 | Searches DxeCore in all firmware Volumes and loads the first\r |
463 | instance that contains DxeCore.\r | |
b0d803fe | 464 | \r |
9b937a73 | 465 | @return FileHandle of DxeCore to load DxeCore.\r |
d1102dba | 466 | \r |
91d92e25 | 467 | **/\r |
9b937a73 | 468 | EFI_PEI_FILE_HANDLE\r |
288f9b38 | 469 | DxeIplFindDxeCore (\r |
b6b98e91 | 470 | VOID\r |
b0d803fe | 471 | )\r |
95276127 | 472 | {\r |
1436aea4 MK |
473 | EFI_STATUS Status;\r |
474 | UINTN Instance;\r | |
475 | EFI_PEI_FV_HANDLE VolumeHandle;\r | |
476 | EFI_PEI_FILE_HANDLE FileHandle;\r | |
d1102dba | 477 | \r |
1436aea4 | 478 | Instance = 0;\r |
9b937a73 | 479 | while (TRUE) {\r |
480 | //\r | |
481 | // Traverse all firmware volume instances\r | |
482 | //\r | |
483 | Status = PeiServicesFfsFindNextVolume (Instance, &VolumeHandle);\r | |
484 | //\r | |
485 | // If some error occurs here, then we cannot find any firmware\r | |
486 | // volume that may contain DxeCore.\r | |
487 | //\r | |
3d0a2385 | 488 | if (EFI_ERROR (Status)) {\r |
489 | REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_CORE_EC_DXE_CORRUPT));\r | |
490 | }\r | |
1436aea4 | 491 | \r |
9b937a73 | 492 | ASSERT_EFI_ERROR (Status);\r |
d1102dba | 493 | \r |
9b937a73 | 494 | //\r |
495 | // Find the DxeCore file type from the beginning in this firmware volume.\r | |
496 | //\r | |
497 | FileHandle = NULL;\r | |
1436aea4 | 498 | Status = PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE, VolumeHandle, &FileHandle);\r |
288f9b38 | 499 | if (!EFI_ERROR (Status)) {\r |
9b937a73 | 500 | //\r |
b6b98e91 | 501 | // Find DxeCore FileHandle in this volume, then we skip other firmware volume and\r |
502 | // return the FileHandle.\r | |
9b937a73 | 503 | //\r |
b6b98e91 | 504 | return FileHandle;\r |
95276127 | 505 | }\r |
1436aea4 | 506 | \r |
9b937a73 | 507 | //\r |
508 | // We cannot find DxeCore in this firmware volume, then search the next volume.\r | |
509 | //\r | |
510 | Instance++;\r | |
511 | }\r | |
95276127 | 512 | }\r |
513 | \r | |
d8c79a81 LG |
514 | /**\r |
515 | The ExtractSection() function processes the input section and\r | |
516 | returns a pointer to the section contents. If the section being\r | |
517 | extracted does not require processing (if the section\r | |
518 | GuidedSectionHeader.Attributes has the\r | |
519 | EFI_GUIDED_SECTION_PROCESSING_REQUIRED field cleared), then\r | |
520 | OutputBuffer is just updated to point to the start of the\r | |
521 | section's contents. Otherwise, *Buffer must be allocated\r | |
522 | from PEI permanent memory.\r | |
523 | \r | |
524 | @param This Indicates the\r | |
525 | EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI instance.\r | |
526 | Buffer containing the input GUIDed section to be\r | |
527 | processed. OutputBuffer OutputBuffer is\r | |
528 | allocated from PEI permanent memory and contains\r | |
529 | the new section stream.\r | |
91d92e25 | 530 | @param InputSection A pointer to the input buffer, which contains\r |
531 | the input section to be processed.\r | |
532 | @param OutputBuffer A pointer to a caller-allocated buffer, whose\r | |
533 | size is specified by the contents of OutputSize.\r | |
d8c79a81 LG |
534 | @param OutputSize A pointer to a caller-allocated\r |
535 | UINTN in which the size of *OutputBuffer\r | |
536 | allocation is stored. If the function\r | |
537 | returns anything other than EFI_SUCCESS,\r | |
538 | the value of OutputSize is undefined.\r | |
d8c79a81 LG |
539 | @param AuthenticationStatus A pointer to a caller-allocated\r |
540 | UINT32 that indicates the\r | |
541 | authentication status of the\r | |
542 | output buffer. If the input\r | |
543 | section's GuidedSectionHeader.\r | |
544 | Attributes field has the\r | |
d1102dba | 545 | EFI_GUIDED_SECTION_AUTH_STATUS_VALID\r |
d8c79a81 LG |
546 | bit as clear,\r |
547 | AuthenticationStatus must return\r | |
548 | zero. These bits reflect the\r | |
549 | status of the extraction\r | |
550 | operation. If the function\r | |
551 | returns anything other than\r | |
552 | EFI_SUCCESS, the value of\r | |
553 | AuthenticationStatus is\r | |
554 | undefined.\r | |
d1102dba | 555 | \r |
d8c79a81 LG |
556 | @retval EFI_SUCCESS The InputSection was\r |
557 | successfully processed and the\r | |
558 | section contents were returned.\r | |
d1102dba | 559 | \r |
d8c79a81 LG |
560 | @retval EFI_OUT_OF_RESOURCES The system has insufficient\r |
561 | resources to process the request.\r | |
d1102dba | 562 | \r |
708919be | 563 | @retval EFI_INVALID_PARAMETER The GUID in InputSection does\r |
d8c79a81 LG |
564 | not match this instance of the\r |
565 | GUIDed Section Extraction PPI.\r | |
91d92e25 | 566 | \r |
d8c79a81 LG |
567 | **/\r |
568 | EFI_STATUS\r | |
6d3ea23f | 569 | EFIAPI\r |
18fd8d65 | 570 | CustomGuidedSectionExtract (\r |
1436aea4 MK |
571 | IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,\r |
572 | IN CONST VOID *InputSection,\r | |
573 | OUT VOID **OutputBuffer,\r | |
574 | OUT UINTN *OutputSize,\r | |
575 | OUT UINT32 *AuthenticationStatus\r | |
576 | )\r | |
d8c79a81 | 577 | {\r |
1436aea4 MK |
578 | EFI_STATUS Status;\r |
579 | UINT8 *ScratchBuffer;\r | |
580 | UINT32 ScratchBufferSize;\r | |
581 | UINT32 OutputBufferSize;\r | |
582 | UINT16 SectionAttribute;\r | |
d1102dba | 583 | \r |
d8c79a81 | 584 | //\r |
18fd8d65 | 585 | // Init local variable\r |
d8c79a81 | 586 | //\r |
18fd8d65 LG |
587 | ScratchBuffer = NULL;\r |
588 | \r | |
d8c79a81 | 589 | //\r |
18fd8d65 | 590 | // Call GetInfo to get the size and attribute of input guided section data.\r |
d8c79a81 | 591 | //\r |
18fd8d65 | 592 | Status = ExtractGuidedSectionGetInfo (\r |
b6b98e91 | 593 | InputSection,\r |
594 | &OutputBufferSize,\r | |
595 | &ScratchBufferSize,\r | |
596 | &SectionAttribute\r | |
597 | );\r | |
d1102dba | 598 | \r |
d8c79a81 | 599 | if (EFI_ERROR (Status)) {\r |
91d92e25 | 600 | DEBUG ((DEBUG_ERROR, "GetInfo from guided section Failed - %r\n", Status));\r |
18fd8d65 LG |
601 | return Status;\r |
602 | }\r | |
d1102dba | 603 | \r |
18fd8d65 | 604 | if (ScratchBufferSize != 0) {\r |
95276127 | 605 | //\r |
18fd8d65 | 606 | // Allocate scratch buffer\r |
95276127 | 607 | //\r |
18fd8d65 LG |
608 | ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r |
609 | if (ScratchBuffer == NULL) {\r | |
610 | return EFI_OUT_OF_RESOURCES;\r | |
611 | }\r | |
d8c79a81 | 612 | }\r |
95276127 | 613 | \r |
1436aea4 | 614 | if (((SectionAttribute & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) && (OutputBufferSize > 0)) {\r |
18fd8d65 LG |
615 | //\r |
616 | // Allocate output buffer\r | |
617 | //\r | |
5367f17d | 618 | *OutputBuffer = AllocatePages (EFI_SIZE_TO_PAGES (OutputBufferSize));\r |
18fd8d65 LG |
619 | if (*OutputBuffer == NULL) {\r |
620 | return EFI_OUT_OF_RESOURCES;\r | |
621 | }\r | |
1436aea4 | 622 | \r |
48557c65 | 623 | DEBUG ((DEBUG_INFO, "Customized Guided section Memory Size required is 0x%x and address is 0x%p\n", OutputBufferSize, *OutputBuffer));\r |
95276127 | 624 | }\r |
d1102dba | 625 | \r |
18fd8d65 | 626 | Status = ExtractGuidedSectionDecode (\r |
d1102dba | 627 | InputSection,\r |
18fd8d65 LG |
628 | OutputBuffer,\r |
629 | ScratchBuffer,\r | |
630 | AuthenticationStatus\r | |
48557c65 | 631 | );\r |
d8c79a81 LG |
632 | if (EFI_ERROR (Status)) {\r |
633 | //\r | |
18fd8d65 | 634 | // Decode failed\r |
d8c79a81 | 635 | //\r |
91d92e25 | 636 | DEBUG ((DEBUG_ERROR, "Extract guided section Failed - %r\n", Status));\r |
d8c79a81 LG |
637 | return Status;\r |
638 | }\r | |
d1102dba | 639 | \r |
1436aea4 | 640 | *OutputSize = (UINTN)OutputBufferSize;\r |
d1102dba | 641 | \r |
95276127 | 642 | return EFI_SUCCESS;\r |
643 | }\r | |
b0d803fe | 644 | \r |
91d92e25 | 645 | /**\r |
646 | Decompresses a section to the output buffer.\r | |
647 | \r | |
48557c65 | 648 | This function looks up the compression type field in the input section and\r |
91d92e25 | 649 | applies the appropriate compression algorithm to compress the section to a\r |
650 | callee allocated buffer.\r | |
d1102dba | 651 | \r |
91d92e25 | 652 | @param This Points to this instance of the\r |
653 | EFI_PEI_DECOMPRESS_PEI PPI.\r | |
654 | @param CompressionSection Points to the compressed section.\r | |
655 | @param OutputBuffer Holds the returned pointer to the decompressed\r | |
656 | sections.\r | |
657 | @param OutputSize Holds the returned size of the decompress\r | |
658 | section streams.\r | |
d1102dba | 659 | \r |
91d92e25 | 660 | @retval EFI_SUCCESS The section was decompressed successfully.\r |
661 | OutputBuffer contains the resulting data and\r | |
662 | OutputSize contains the resulting size.\r | |
663 | \r | |
664 | **/\r | |
b0d803fe | 665 | EFI_STATUS\r |
d1102dba | 666 | EFIAPI\r |
b0d803fe | 667 | Decompress (\r |
1436aea4 MK |
668 | IN CONST EFI_PEI_DECOMPRESS_PPI *This,\r |
669 | IN CONST EFI_COMPRESSION_SECTION *CompressionSection,\r | |
670 | OUT VOID **OutputBuffer,\r | |
671 | OUT UINTN *OutputSize\r | |
672 | )\r | |
b0d803fe | 673 | {\r |
1436aea4 MK |
674 | EFI_STATUS Status;\r |
675 | UINT8 *DstBuffer;\r | |
676 | UINT8 *ScratchBuffer;\r | |
677 | UINT32 DstBufferSize;\r | |
678 | UINT32 ScratchBufferSize;\r | |
679 | VOID *CompressionSource;\r | |
680 | UINT32 CompressionSourceSize;\r | |
681 | UINT32 UncompressedLength;\r | |
682 | UINT8 CompressionType;\r | |
b0d803fe | 683 | \r |
684 | if (CompressionSection->CommonHeader.Type != EFI_SECTION_COMPRESSION) {\r | |
685 | ASSERT (FALSE);\r | |
686 | return EFI_INVALID_PARAMETER;\r | |
687 | }\r | |
688 | \r | |
890e5417 | 689 | if (IS_SECTION2 (CompressionSection)) {\r |
1436aea4 MK |
690 | CompressionSource = (VOID *)((UINT8 *)CompressionSection + sizeof (EFI_COMPRESSION_SECTION2));\r |
691 | CompressionSourceSize = (UINT32)(SECTION2_SIZE (CompressionSection) - sizeof (EFI_COMPRESSION_SECTION2));\r | |
692 | UncompressedLength = ((EFI_COMPRESSION_SECTION2 *)CompressionSection)->UncompressedLength;\r | |
693 | CompressionType = ((EFI_COMPRESSION_SECTION2 *)CompressionSection)->CompressionType;\r | |
890e5417 | 694 | } else {\r |
1436aea4 MK |
695 | CompressionSource = (VOID *)((UINT8 *)CompressionSection + sizeof (EFI_COMPRESSION_SECTION));\r |
696 | CompressionSourceSize = (UINT32)(SECTION_SIZE (CompressionSection) - sizeof (EFI_COMPRESSION_SECTION));\r | |
697 | UncompressedLength = CompressionSection->UncompressedLength;\r | |
698 | CompressionType = CompressionSection->CompressionType;\r | |
890e5417 | 699 | }\r |
d1102dba | 700 | \r |
b0d803fe | 701 | //\r |
702 | // This is a compression set, expand it\r | |
703 | //\r | |
890e5417 | 704 | switch (CompressionType) {\r |
1436aea4 MK |
705 | case EFI_STANDARD_COMPRESSION:\r |
706 | if (FeaturePcdGet (PcdDxeIplSupportUefiDecompress)) {\r | |
707 | //\r | |
708 | // Load EFI standard compression.\r | |
709 | // For compressed data, decompress them to destination buffer.\r | |
710 | //\r | |
711 | Status = UefiDecompressGetInfo (\r | |
712 | CompressionSource,\r | |
713 | CompressionSourceSize,\r | |
714 | &DstBufferSize,\r | |
715 | &ScratchBufferSize\r | |
716 | );\r | |
717 | if (EFI_ERROR (Status)) {\r | |
718 | //\r | |
719 | // GetInfo failed\r | |
720 | //\r | |
721 | DEBUG ((DEBUG_ERROR, "Decompress GetInfo Failed - %r\n", Status));\r | |
722 | return EFI_NOT_FOUND;\r | |
723 | }\r | |
724 | \r | |
725 | //\r | |
726 | // Allocate scratch buffer\r | |
727 | //\r | |
728 | ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r | |
729 | if (ScratchBuffer == NULL) {\r | |
730 | return EFI_OUT_OF_RESOURCES;\r | |
731 | }\r | |
732 | \r | |
733 | //\r | |
734 | // Allocate destination buffer\r | |
735 | //\r | |
736 | DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize));\r | |
737 | if (DstBuffer == NULL) {\r | |
738 | return EFI_OUT_OF_RESOURCES;\r | |
739 | }\r | |
740 | \r | |
873b7997 | 741 | //\r |
1436aea4 | 742 | // Call decompress function\r |
873b7997 | 743 | //\r |
1436aea4 MK |
744 | Status = UefiDecompress (\r |
745 | CompressionSource,\r | |
746 | DstBuffer,\r | |
747 | ScratchBuffer\r | |
748 | );\r | |
749 | if (EFI_ERROR (Status)) {\r | |
750 | //\r | |
751 | // Decompress failed\r | |
752 | //\r | |
753 | DEBUG ((DEBUG_ERROR, "Decompress Failed - %r\n", Status));\r | |
754 | return EFI_NOT_FOUND;\r | |
755 | }\r | |
756 | \r | |
757 | break;\r | |
758 | } else {\r | |
759 | //\r | |
760 | // PcdDxeIplSupportUefiDecompress is FALSE\r | |
761 | // Don't support UEFI decompression algorithm.\r | |
762 | //\r | |
763 | ASSERT (FALSE);\r | |
873b7997 | 764 | return EFI_NOT_FOUND;\r |
765 | }\r | |
1436aea4 MK |
766 | \r |
767 | case EFI_NOT_COMPRESSED:\r | |
873b7997 | 768 | //\r |
d40695ad | 769 | // Allocate destination buffer\r |
873b7997 | 770 | //\r |
1436aea4 MK |
771 | DstBufferSize = UncompressedLength;\r |
772 | DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize));\r | |
873b7997 | 773 | if (DstBuffer == NULL) {\r |
774 | return EFI_OUT_OF_RESOURCES;\r | |
775 | }\r | |
1436aea4 | 776 | \r |
b0d803fe | 777 | //\r |
1436aea4 | 778 | // stream is not actually compressed, just encapsulated. So just copy it.\r |
873b7997 | 779 | //\r |
1436aea4 | 780 | CopyMem (DstBuffer, CompressionSource, DstBufferSize);\r |
873b7997 | 781 | break;\r |
1436aea4 MK |
782 | \r |
783 | default:\r | |
12b3e61e | 784 | //\r |
1436aea4 | 785 | // Don't support other unknown compression type.\r |
12b3e61e LG |
786 | //\r |
787 | ASSERT (FALSE);\r | |
b0d803fe | 788 | return EFI_NOT_FOUND;\r |
b0d803fe | 789 | }\r |
790 | \r | |
1436aea4 | 791 | *OutputSize = DstBufferSize;\r |
b0d803fe | 792 | *OutputBuffer = DstBuffer;\r |
793 | \r | |
794 | return EFI_SUCCESS;\r | |
795 | }\r | |
796 | \r | |
91d92e25 | 797 | /**\r |
798 | Updates the Stack HOB passed to DXE phase.\r | |
799 | \r | |
800 | This function traverses the whole HOB list and update the stack HOB to\r | |
801 | reflect the real stack that is used by DXE core.\r | |
802 | \r | |
803 | @param BaseAddress The lower address of stack used by DxeCore.\r | |
804 | @param Length The length of stack used by DxeCore.\r | |
805 | \r | |
806 | **/\r | |
30c8f861 | 807 | VOID\r |
808 | UpdateStackHob (\r | |
1436aea4 MK |
809 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r |
810 | IN UINT64 Length\r | |
30c8f861 | 811 | )\r |
812 | {\r | |
1436aea4 | 813 | EFI_PEI_HOB_POINTERS Hob;\r |
30c8f861 | 814 | \r |
815 | Hob.Raw = GetHobList ();\r | |
816 | while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {\r | |
817 | if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &(Hob.MemoryAllocationStack->AllocDescriptor.Name))) {\r | |
818 | //\r | |
d1102dba LG |
819 | // Build a new memory allocation HOB with old stack info with EfiBootServicesData type. Need to\r |
820 | // avoid this region be reclaimed by DXE core as the IDT built in SEC might be on stack, and some\r | |
9a43bc39 | 821 | // PEIMs may also keep key information on stack\r |
30c8f861 | 822 | //\r |
823 | BuildMemoryAllocationHob (\r | |
824 | Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress,\r | |
825 | Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength,\r | |
9a43bc39 | 826 | EfiBootServicesData\r |
30c8f861 | 827 | );\r |
828 | //\r | |
829 | // Update the BSP Stack Hob to reflect the new stack info.\r | |
830 | //\r | |
831 | Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r | |
1436aea4 | 832 | Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength = Length;\r |
30c8f861 | 833 | break;\r |
834 | }\r | |
1436aea4 | 835 | \r |
30c8f861 | 836 | Hob.Raw = GET_NEXT_HOB (Hob);\r |
837 | }\r | |
838 | }\r |