]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Core/DxeIplPeim/DxeLoad.c
Clean up DEC files:
[mirror_edk2.git] / MdeModulePkg / Core / DxeIplPeim / DxeLoad.c
... / ...
CommitLineData
1/** @file\r
2 Last PEIM.\r
3 Responsibility of this module is to load the DXE Core from a Firmware Volume.\r
4\r
5Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "DxeIpl.h"\r
17\r
18\r
19//\r
20// Module Globals used in the DXE to PEI hand off\r
21// These must be module globals, so the stack can be switched\r
22//\r
23CONST EFI_DXE_IPL_PPI mDxeIplPpi = {\r
24 DxeLoadCore\r
25};\r
26\r
27CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi = {\r
28 CustomGuidedSectionExtract\r
29};\r
30\r
31CONST EFI_PEI_DECOMPRESS_PPI mDecompressPpi = {\r
32 Decompress\r
33};\r
34\r
35CONST EFI_PEI_PPI_DESCRIPTOR mPpiList[] = {\r
36 {\r
37 EFI_PEI_PPI_DESCRIPTOR_PPI,\r
38 &gEfiDxeIplPpiGuid,\r
39 (VOID *) &mDxeIplPpi\r
40 },\r
41 {\r
42 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
43 &gEfiPeiDecompressPpiGuid,\r
44 (VOID *) &mDecompressPpi\r
45 }\r
46};\r
47\r
48CONST EFI_PEI_PPI_DESCRIPTOR gEndOfPeiSignalPpi = {\r
49 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
50 &gEfiEndOfPeiSignalPpiGuid,\r
51 NULL\r
52};\r
53\r
54/**\r
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
59\r
60 @param FileHandle Handle of the file being invoked.\r
61 @param PeiServices Describes the list of possible PEI Services.\r
62\r
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
66**/\r
67EFI_STATUS\r
68EFIAPI\r
69PeimInitializeDxeIpl (\r
70 IN EFI_PEI_FILE_HANDLE FileHandle,\r
71 IN CONST EFI_PEI_SERVICES **PeiServices\r
72 )\r
73{\r
74 EFI_STATUS Status;\r
75 EFI_BOOT_MODE BootMode;\r
76 EFI_GUID *ExtractHandlerGuidTable;\r
77 UINTN ExtractHandlerNumber;\r
78 EFI_PEI_PPI_DESCRIPTOR *GuidPpi;\r
79 \r
80 BootMode = GetBootModeHob ();\r
81\r
82 if (BootMode != BOOT_ON_S3_RESUME) {\r
83 Status = PeiServicesRegisterForShadow (FileHandle);\r
84 if (Status == EFI_SUCCESS) {\r
85 //\r
86 // EFI_SUCESS means it is the first time to call register for shadow. \r
87 // \r
88 return Status;\r
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
95 \r
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
113 }\r
114 }\r
115 \r
116 }\r
117 \r
118 //\r
119 // Install DxeIpl and Decompress PPIs.\r
120 //\r
121 Status = PeiServicesInstallPpi (mPpiList);\r
122 ASSERT_EFI_ERROR(Status);\r
123\r
124 return Status;\r
125}\r
126\r
127/**\r
128 Main entry point to last PEIM. \r
129\r
130 This function finds DXE Core in the firmware volume and transfer the control to\r
131 DXE core.\r
132 \r
133 @param This Entry point for DXE IPL PPI.\r
134 @param PeiServices General purpose services available to every PEIM.\r
135 @param HobList Address to the Pei HOB list.\r
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
139\r
140**/\r
141EFI_STATUS\r
142EFIAPI\r
143DxeLoadCore (\r
144 IN CONST EFI_DXE_IPL_PPI *This,\r
145 IN EFI_PEI_SERVICES **PeiServices,\r
146 IN EFI_PEI_HOB_POINTERS HobList\r
147 )\r
148{\r
149 EFI_STATUS Status;\r
150 EFI_FV_FILE_INFO DxeCoreFileInfo;\r
151 EFI_PHYSICAL_ADDRESS DxeCoreAddress;\r
152 UINT64 DxeCoreSize;\r
153 EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint;\r
154 EFI_BOOT_MODE BootMode;\r
155 EFI_PEI_FILE_HANDLE FileHandle;\r
156 EFI_PEI_READ_ONLY_VARIABLE2_PPI *Variable;\r
157 EFI_PEI_LOAD_FILE_PPI *LoadFile;\r
158 UINTN Instance;\r
159 UINT32 AuthenticationState;\r
160 UINTN DataSize;\r
161 EFI_PEI_S3_RESUME2_PPI *S3Resume;\r
162 EFI_PEI_RECOVERY_MODULE_PPI *PeiRecovery;\r
163 EFI_MEMORY_TYPE_INFORMATION MemoryData[EfiMaxMemoryType + 1];\r
164\r
165 //\r
166 // if in S3 Resume, restore configure\r
167 //\r
168 BootMode = GetBootModeHob ();\r
169\r
170 if (BootMode == BOOT_ON_S3_RESUME) {\r
171 Status = PeiServicesLocatePpi (\r
172 &gEfiPeiS3Resume2PpiGuid,\r
173 0,\r
174 NULL,\r
175 (VOID **) &S3Resume\r
176 );\r
177 ASSERT_EFI_ERROR (Status);\r
178 \r
179 Status = S3Resume->S3RestoreConfig2 (S3Resume);\r
180 ASSERT_EFI_ERROR (Status);\r
181 } else if (BootMode == BOOT_IN_RECOVERY_MODE) {\r
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
191 if (EFI_ERROR (Status)) {\r
192 DEBUG ((DEBUG_ERROR, "Load Recovery Capsule Failed.(Status = %r)\n", Status));\r
193 CpuDeadLoop ();\r
194 }\r
195\r
196 //\r
197 // Now should have a HOB with the DXE core\r
198 //\r
199 }\r
200\r
201 Status = PeiServicesLocatePpi (\r
202 &gEfiPeiReadOnlyVariable2PpiGuid,\r
203 0,\r
204 NULL,\r
205 (VOID **)&Variable\r
206 );\r
207 if (!EFI_ERROR (Status)) {\r
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
227 }\r
228\r
229 //\r
230 // Look in all the FVs present in PEI and find the DXE Core FileHandle\r
231 //\r
232 FileHandle = DxeIplFindDxeCore ();\r
233\r
234 //\r
235 // Load the DXE Core from a Firmware Volume.\r
236 //\r
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
254\r
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
261 //\r
262 // Add HOB for the DXE Core\r
263 //\r
264 BuildModuleHob (\r
265 &DxeCoreFileInfo.FileName,\r
266 DxeCoreAddress,\r
267 ALIGN_VALUE (DxeCoreSize, EFI_PAGE_SIZE),\r
268 DxeCoreEntryPoint\r
269 );\r
270\r
271 //\r
272 // Report Status Code EFI_SW_PEI_PC_HANDOFF_TO_NEXT\r
273 //\r
274 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_CORE | EFI_SW_PEI_CORE_PC_HANDOFF_TO_NEXT));\r
275\r
276 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading DXE CORE at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN)DxeCoreAddress, FUNCTION_ENTRY_POINT (DxeCoreEntryPoint)));\r
277\r
278 //\r
279 // Transfer control to the DXE Core\r
280 // The hand off state is simply a pointer to the HOB list\r
281 //\r
282 HandOffToDxeCore (DxeCoreEntryPoint, HobList);\r
283 //\r
284 // If we get here, then the DXE Core returned. This is an error\r
285 // DxeCore should not return.\r
286 //\r
287 ASSERT (FALSE);\r
288 CpuDeadLoop ();\r
289\r
290 return EFI_OUT_OF_RESOURCES;\r
291}\r
292\r
293\r
294/**\r
295 Searches DxeCore in all firmware Volumes and loads the first\r
296 instance that contains DxeCore.\r
297\r
298 @return FileHandle of DxeCore to load DxeCore.\r
299 \r
300**/\r
301EFI_PEI_FILE_HANDLE\r
302DxeIplFindDxeCore (\r
303 VOID\r
304 )\r
305{\r
306 EFI_STATUS Status;\r
307 UINTN Instance;\r
308 EFI_PEI_FV_HANDLE VolumeHandle;\r
309 EFI_PEI_FILE_HANDLE FileHandle;\r
310 \r
311 Instance = 0;\r
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
328 if (!EFI_ERROR (Status)) {\r
329 //\r
330 // Find DxeCore FileHandle in this volume, then we skip other firmware volume and\r
331 // return the FileHandle.\r
332 //\r
333 return FileHandle;\r
334 }\r
335 //\r
336 // We cannot find DxeCore in this firmware volume, then search the next volume.\r
337 //\r
338 Instance++;\r
339 }\r
340}\r
341\r
342\r
343\r
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
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
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
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
393 @retval EFI_INVALID_PARAMETER The GUID in InputSection does\r
394 not match this instance of the\r
395 GUIDed Section Extraction PPI.\r
396\r
397**/\r
398EFI_STATUS\r
399EFIAPI\r
400CustomGuidedSectionExtract (\r
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
410 UINT32 ScratchBufferSize;\r
411 UINT32 OutputBufferSize;\r
412 UINT16 SectionAttribute;\r
413 \r
414 //\r
415 // Init local variable\r
416 //\r
417 ScratchBuffer = NULL;\r
418\r
419 //\r
420 // Call GetInfo to get the size and attribute of input guided section data.\r
421 //\r
422 Status = ExtractGuidedSectionGetInfo (\r
423 InputSection,\r
424 &OutputBufferSize,\r
425 &ScratchBufferSize,\r
426 &SectionAttribute\r
427 );\r
428 \r
429 if (EFI_ERROR (Status)) {\r
430 DEBUG ((DEBUG_ERROR, "GetInfo from guided section Failed - %r\n", Status));\r
431 return Status;\r
432 }\r
433 \r
434 if (ScratchBufferSize != 0) {\r
435 //\r
436 // Allocate scratch buffer\r
437 //\r
438 ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r
439 if (ScratchBuffer == NULL) {\r
440 return EFI_OUT_OF_RESOURCES;\r
441 }\r
442 }\r
443\r
444 if (((SectionAttribute & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) && OutputBufferSize > 0) { \r
445 //\r
446 // Allocate output buffer\r
447 //\r
448 *OutputBuffer = AllocatePages (EFI_SIZE_TO_PAGES (OutputBufferSize) + 1);\r
449 if (*OutputBuffer == NULL) {\r
450 return EFI_OUT_OF_RESOURCES;\r
451 }\r
452 DEBUG ((DEBUG_INFO, "Customized Guided section Memory Size required is 0x%x and address is 0x%p\n", OutputBufferSize, *OutputBuffer));\r
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
458 }\r
459 \r
460 Status = ExtractGuidedSectionDecode (\r
461 InputSection, \r
462 OutputBuffer,\r
463 ScratchBuffer,\r
464 AuthenticationStatus\r
465 );\r
466 if (EFI_ERROR (Status)) {\r
467 //\r
468 // Decode failed\r
469 //\r
470 DEBUG ((DEBUG_ERROR, "Extract guided section Failed - %r\n", Status));\r
471 return Status;\r
472 }\r
473 \r
474 *OutputSize = (UINTN) OutputBufferSize;\r
475 \r
476 return EFI_SUCCESS;\r
477}\r
478\r
479\r
480\r
481/**\r
482 Decompresses a section to the output buffer.\r
483\r
484 This function looks up the compression type field in the input section and\r
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
501EFI_STATUS\r
502EFIAPI \r
503Decompress (\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
513 UINT32 DstBufferSize;\r
514 UINT32 ScratchBufferSize;\r
515 EFI_COMMON_SECTION_HEADER *Section;\r
516 UINT32 SectionLength;\r
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
524 SectionLength = *(UINT32 *) (Section->Size) & 0x00ffffff;\r
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
531 if (FeaturePcdGet(PcdDxeIplSupportUefiDecompress)) {\r
532 //\r
533 // Load EFI standard compression.\r
534 // For compressed data, decompress them to destination buffer.\r
535 //\r
536 Status = UefiDecompressGetInfo (\r
537 (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
538 SectionLength - sizeof (EFI_COMPRESSION_SECTION),\r
539 &DstBufferSize,\r
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
551 //\r
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
563 //\r
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
585 //\r
586 // PcdDxeIplSupportUefiDecompress is FALSE\r
587 // Don't support UEFI decompression algorithm.\r
588 //\r
589 ASSERT (FALSE);\r
590 return EFI_NOT_FOUND;\r
591 }\r
592\r
593 case EFI_NOT_COMPRESSED:\r
594 //\r
595 // Allocate destination buffer\r
596 //\r
597 DstBufferSize = CompressionSection->UncompressedLength;\r
598 DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize) + 1);\r
599 if (DstBuffer == NULL) {\r
600 return EFI_OUT_OF_RESOURCES;\r
601 }\r
602 //\r
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
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
627\r
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
638VOID\r
639UpdateStackHob (\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
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
653 //\r
654 BuildMemoryAllocationHob (\r
655 Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress,\r
656 Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength,\r
657 EfiBootServicesData\r
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