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