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