2 Library that helps implement monolithic PEI. (SEC goes to DXE)
4 Copyright (c) 2008-2009 Apple Inc. All rights reserved.<BR>
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef __PRE_PI_LIB_H__
17 #define __PRE_PI_LIB_H__
19 #include <Guid/ExtractSection.h>
22 This service enables discovery of additional firmware volumes.
24 @param Instance This instance of the firmware volume to find. The value 0 is the
25 Boot Firmware Volume (BFV).
26 @param FwVolHeader Pointer to the firmware volume header of the volume to return.
28 @retval EFI_SUCCESS The volume was found.
29 @retval EFI_NOT_FOUND The volume was not found.
30 @retval EFI_INVALID_PARAMETER FwVolHeader is NULL.
37 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
42 This service enables discovery of additional firmware files.
44 @param SearchType A filter to find files only of this type.
45 @param FwVolHeader Pointer to the firmware volume header of the volume to search.
46 This parameter must point to a valid FFS volume.
47 @param FileHeader Pointer to the current file from which to begin searching.
49 @retval EFI_SUCCESS The file was found.
50 @retval EFI_NOT_FOUND The file was not found.
51 @retval EFI_NOT_FOUND The header checksum was not zero.
57 IN EFI_FV_FILETYPE SearchType
,
58 IN EFI_PEI_FV_HANDLE VolumeHandle
,
59 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
64 This service enables discovery sections of a given type within a valid FFS file.
66 @param SearchType The value of the section type to find.
67 @param FfsFileHeader A pointer to the file header that contains the set of sections to
69 @param SectionData A pointer to the discovered section, if successful.
71 @retval EFI_SUCCESS The section was found.
72 @retval EFI_NOT_FOUND The section was not found.
78 IN EFI_SECTION_TYPE SectionType
,
79 IN EFI_PEI_FILE_HANDLE FileHandle
,
80 OUT VOID
**SectionData
85 Find a file in the volume by name
87 @param FileName A pointer to the name of the file to
88 find within the firmware volume.
90 @param VolumeHandle The firmware volume to search FileHandle
91 Upon exit, points to the found file's
92 handle or NULL if it could not be found.
94 @retval EFI_SUCCESS File was found.
96 @retval EFI_NOT_FOUND File was not found.
98 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or
105 IN CONST EFI_GUID
*FileName
,
106 IN CONST EFI_PEI_FV_HANDLE VolumeHandle
,
107 OUT EFI_PEI_FILE_HANDLE
*FileHandle
112 Get information about the file by name.
114 @param FileHandle Handle of the file.
116 @param FileInfo Upon exit, points to the file's
119 @retval EFI_SUCCESS File information returned.
121 @retval EFI_INVALID_PARAMETER If FileHandle does not
122 represent a valid file.
124 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
130 IN CONST EFI_PEI_FILE_HANDLE FileHandle
,
131 OUT EFI_FV_FILE_INFO
*FileInfo
136 Get Information about the volume by name
138 @param VolumeHandle Handle of the volume.
140 @param VolumeInfo Upon exit, points to the volume's
143 @retval EFI_SUCCESS File information returned.
145 @retval EFI_INVALID_PARAMETER If FileHandle does not
146 represent a valid file.
148 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
154 IN EFI_PEI_FV_HANDLE VolumeHandle
,
155 OUT EFI_FV_INFO
*VolumeInfo
161 Get Fv image from the FV type file, then add FV & FV2 Hob.
163 @param FileHandle File handle of a Fv type file.
166 @retval EFI_NOT_FOUND FV image can't be found.
167 @retval EFI_SUCCESS Successfully to process it.
173 IN EFI_PEI_FILE_HANDLE FvFileHandle
178 Search through every FV until you find a file of type FileType
180 @param FileType File handle of a Fv type file.
181 @param Volumehandle On succes Volume Handle of the match
182 @param FileHandle On success File Handle of the match
184 @retval EFI_NOT_FOUND FV image can't be found.
185 @retval EFI_SUCCESS Successfully found FileType
190 FfsAnyFvFindFirstFile (
191 IN EFI_FV_FILETYPE FileType
,
192 OUT EFI_PEI_FV_HANDLE
*VolumeHandle
,
193 OUT EFI_PEI_FILE_HANDLE
*FileHandle
198 Get Fv image from the FV type file, then add FV & FV2 Hob.
200 @param FileHandle File handle of a Fv type file.
203 @retval EFI_NOT_FOUND FV image can't be found.
204 @retval EFI_SUCCESS Successfully to process it.
210 IN EFI_PEI_FILE_HANDLE FvFileHandle
215 This service enables PEIMs to ascertain the present value of the boot mode.
229 This service enables PEIMs to update the boot mode variable.
231 @param BootMode The value of the boot mode to set.
233 @retval EFI_SUCCESS The value was successfully updated
239 IN EFI_BOOT_MODE BootMode
243 This service enables a PEIM to ascertain the address of the list of HOBs in memory.
245 @param HobList A pointer to the list of HOBs that the PEI Foundation will initialize.
247 @retval EFI_SUCCESS The list was successfully returned.
248 @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.
259 Updates the pointer to the HOB list.
261 @param HobList Hob list pointer to store
272 Retrieves the magic value from the PE/COFF header.
274 @param Hdr The buffer in which to return the PE32, PE32+, or TE header.
276 @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32
277 @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+
282 IN VOID
*MemoryBegin
,
283 IN UINTN MemoryLength
,
290 This service enables PEIMs to create various types of HOBs.
292 @param Type The type of HOB to be installed.
293 @param Length The length of the HOB to be added.
295 @retval !NULL The HOB was successfully created.
296 @retval NULL There is no additional space for HOB creation.
307 Returns the next instance of a HOB type from the starting HOB.
309 This function searches the first instance of a HOB type from the starting HOB pointer.
310 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
311 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
312 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
313 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
314 If HobStart is NULL, then ASSERT().
316 @param Type The HOB type to return.
317 @param HobStart The starting HOB pointer to search from.
319 @return The next instance of a HOB type from the starting HOB.
326 IN CONST VOID
*HobStart
330 Returns the first instance of a HOB type among the whole HOB list.
332 This function searches the first instance of a HOB type among the whole HOB list.
333 If there does not exist such HOB type in the HOB list, it will return NULL.
335 @param Type The HOB type to return.
337 @return The next instance of a HOB type from the starting HOB.
347 This function searches the first instance of a HOB from the starting HOB pointer.
348 Such HOB should satisfy two conditions:
349 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
350 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
351 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
352 to extract the data section and its size info respectively.
353 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
354 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
355 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
356 If Guid is NULL, then ASSERT().
357 If HobStart is NULL, then ASSERT().
359 @param Guid The GUID to match with in the HOB list.
360 @param HobStart A pointer to a Guid.
362 @return The next instance of the matched GUID HOB from the starting HOB.
368 IN CONST EFI_GUID
*Guid
,
369 IN CONST VOID
*HobStart
373 This function searches the first instance of a HOB among the whole HOB list.
374 Such HOB should satisfy two conditions:
375 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
376 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
377 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
378 to extract the data section and its size info respectively.
379 If Guid is NULL, then ASSERT().
381 @param Guid The GUID to match with in the HOB list.
383 @return The first instance of the matched GUID HOB among the whole HOB list.
389 IN CONST EFI_GUID
*Guid
394 Builds a HOB for a loaded PE32 module.
396 This function builds a HOB for a loaded PE32 module.
397 It can only be invoked during PEI phase;
398 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
399 If ModuleName is NULL, then ASSERT().
400 If there is no additional space for HOB creation, then ASSERT().
402 @param ModuleName The GUID File Name of the module.
403 @param MemoryAllocationModule The 64 bit physical address of the module.
404 @param ModuleLength The length of the module in bytes.
405 @param EntryPoint The 64 bit physical address of the module entry point.
411 IN CONST EFI_GUID
*ModuleName
,
412 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
413 IN UINT64 ModuleLength
,
414 IN EFI_PHYSICAL_ADDRESS EntryPoint
418 Builds a HOB that describes a chunk of system memory.
420 This function builds a HOB that describes a chunk of system memory.
421 It can only be invoked during PEI phase;
422 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
423 If there is no additional space for HOB creation, then ASSERT().
425 @param ResourceType The type of resource described by this HOB.
426 @param ResourceAttribute The resource attributes of the memory described by this HOB.
427 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
428 @param NumberOfBytes The length of the memory described by this HOB in bytes.
433 BuildResourceDescriptorHob (
434 IN EFI_RESOURCE_TYPE ResourceType
,
435 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
436 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
437 IN UINT64 NumberOfBytes
441 Builds a GUID HOB with a certain data length.
443 This function builds a customized HOB tagged with a GUID for identification
444 and returns the start address of GUID HOB data so that caller can fill the customized data.
445 The HOB Header and Name field is already stripped.
446 It can only be invoked during PEI phase;
447 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
448 If Guid is NULL, then ASSERT().
449 If there is no additional space for HOB creation, then ASSERT().
450 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
452 @param Guid The GUID to tag the customized HOB.
453 @param DataLength The size of the data payload for the GUID HOB.
455 @return The start address of GUID HOB data.
461 IN CONST EFI_GUID
*Guid
,
466 Copies a data buffer to a newly-built HOB.
468 This function builds a customized HOB tagged with a GUID for identification,
469 copies the input data to the HOB data field and returns the start address of the GUID HOB data.
470 The HOB Header and Name field is already stripped.
471 It can only be invoked during PEI phase;
472 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
473 If Guid is NULL, then ASSERT().
474 If Data is NULL and DataLength > 0, then ASSERT().
475 If there is no additional space for HOB creation, then ASSERT().
476 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
478 @param Guid The GUID to tag the customized HOB.
479 @param Data The data to be copied into the data field of the GUID HOB.
480 @param DataLength The size of the data payload for the GUID HOB.
482 @return The start address of GUID HOB data.
488 IN CONST EFI_GUID
*Guid
,
494 Builds a Firmware Volume HOB.
496 This function builds a Firmware Volume HOB.
497 It can only be invoked during PEI phase;
498 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
499 If there is no additional space for HOB creation, then ASSERT().
501 @param BaseAddress The base address of the Firmware Volume.
502 @param Length The size of the Firmware Volume in bytes.
508 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
513 Builds a Firmware Volume HOB and a resrouce descriptor hob
515 This function builds a Firmware Volume HOB.
516 It can only be invoked during PEI phase;
517 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
518 If there is no additional space for HOB creation, then ASSERT().
520 @param BaseAddress The base address of the Firmware Volume.
521 @param Length The size of the Firmware Volume in bytes.
527 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
528 IN UINT64 NumberOfBytes
,
529 IN EFI_RESOURCE_ATTRIBUTE_TYPE
*ResourceAttribute OPTIONAL
534 Builds a EFI_HOB_TYPE_FV2 HOB.
536 This function builds a EFI_HOB_TYPE_FV2 HOB.
537 It can only be invoked during PEI phase;
538 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
539 If there is no additional space for HOB creation, then ASSERT().
541 @param BaseAddress The base address of the Firmware Volume.
542 @param Length The size of the Firmware Volume in bytes.
543 @param FvName The name of the Firmware Volume.
544 @param FileName The name of the file.
550 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
552 IN CONST EFI_GUID
*FvName
,
553 IN CONST EFI_GUID
*FileName
557 Builds a Capsule Volume HOB.
559 This function builds a Capsule Volume HOB.
560 It can only be invoked during PEI phase;
561 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
562 If there is no additional space for HOB creation, then ASSERT().
564 @param BaseAddress The base address of the Capsule Volume.
565 @param Length The size of the Capsule Volume in bytes.
571 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
576 Builds a HOB for the CPU.
578 This function builds a HOB for the CPU.
579 It can only be invoked during PEI phase;
580 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
581 If there is no additional space for HOB creation, then ASSERT().
583 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
584 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
590 IN UINT8 SizeOfMemorySpace
,
591 IN UINT8 SizeOfIoSpace
595 Builds a HOB for the Stack.
597 This function builds a HOB for the stack.
598 It can only be invoked during PEI phase;
599 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
600 If there is no additional space for HOB creation, then ASSERT().
602 @param BaseAddress The 64 bit physical address of the Stack.
603 @param Length The length of the stack in bytes.
609 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
614 Update the Stack Hob if the stack has been moved
616 @param BaseAddress The 64 bit physical address of the Stack.
617 @param Length The length of the stack in bytes.
622 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
628 Builds a HOB for the BSP store.
630 This function builds a HOB for BSP store.
631 It can only be invoked during PEI phase;
632 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
633 If there is no additional space for HOB creation, then ASSERT().
635 @param BaseAddress The 64 bit physical address of the BSP.
636 @param Length The length of the BSP store in bytes.
637 @param MemoryType Type of memory allocated by this HOB.
643 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
645 IN EFI_MEMORY_TYPE MemoryType
649 Builds a HOB for the memory allocation.
651 This function builds a HOB for the memory allocation.
652 It can only be invoked during PEI phase;
653 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
654 If there is no additional space for HOB creation, then ASSERT().
656 @param BaseAddress The 64 bit physical address of the memory.
657 @param Length The length of the memory allocation in bytes.
658 @param MemoryType Type of memory allocated by this HOB.
663 BuildMemoryAllocationHob (
664 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
666 IN EFI_MEMORY_TYPE MemoryType
672 BuildExtractSectionHob (
674 IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER SectionGetInfo
,
675 IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER SectionExtraction
680 BuildPeCoffLoaderHob (
686 Allocates one or more 4KB pages of type EfiBootServicesData.
688 Allocates the number of 4KB pages of MemoryType and returns a pointer to the
689 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
690 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
693 @param Pages The number of 4 KB pages to allocate.
695 @return A pointer to the allocated buffer or NULL if allocation fails.
705 Allocates a buffer of type EfiBootServicesData.
707 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
708 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
709 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
711 @param AllocationSize The number of bytes to allocate.
713 @return A pointer to the allocated buffer or NULL if allocation fails.
719 IN UINTN AllocationSize
724 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
726 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
727 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
728 returned. If there is not enough memory at the specified alignment remaining to satisfy the
729 request, then NULL is returned.
730 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
732 @param Pages The number of 4 KB pages to allocate.
733 @param Alignment The requested alignment of the allocation. Must be a power of two.
734 If Alignment is zero, then byte alignment is used.
736 @return A pointer to the allocated buffer or NULL if allocation fails.
741 AllocateAlignedPages (
750 IN VOID
*PeCoffImage
,
751 OUT EFI_PHYSICAL_ADDRESS
*ImageAddress
,
752 OUT UINT64
*ImageSize
,
753 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
758 LoadDxeCoreFromFfsFile (
759 IN EFI_PEI_FILE_HANDLE FileHandle
,
766 IN UINTN
*FvInstance
, OPTIONAL
778 AddDxeCoreReportStatusCodeCallback (