2 Library that helps implement monolithic PEI. (SEC goes to DXE)
4 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef __PRE_PI_LIB_H__
11 #define __PRE_PI_LIB_H__
13 #include <Guid/ExtractSection.h>
16 This service enables discovery of additional firmware volumes.
18 @param Instance This instance of the firmware volume to find. The value 0 is the
19 Boot Firmware Volume (BFV).
20 @param FwVolHeader Pointer to the firmware volume header of the volume to return.
22 @retval EFI_SUCCESS The volume was found.
23 @retval EFI_NOT_FOUND The volume was not found.
24 @retval EFI_INVALID_PARAMETER FwVolHeader is NULL.
31 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
35 This service enables discovery of additional firmware files.
37 @param SearchType A filter to find files only of this type.
38 @param FwVolHeader Pointer to the firmware volume header of the volume to search.
39 This parameter must point to a valid FFS volume.
40 @param FileHeader Pointer to the current file from which to begin searching.
42 @retval EFI_SUCCESS The file was found.
43 @retval EFI_NOT_FOUND The file was not found.
44 @retval EFI_NOT_FOUND The header checksum was not zero.
50 IN EFI_FV_FILETYPE SearchType
,
51 IN EFI_PEI_FV_HANDLE VolumeHandle
,
52 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
56 * This is a hook which is used to check if the section is the target one.
61 (EFIAPI
*FFS_CHECK_SECTION_HOOK
)(
62 IN EFI_COMMON_SECTION_HEADER
*Section
66 This service enables discovery sections of a given type within a valid FFS file.
67 Caller also can provide a SectionCheckHook to do additional checking.
69 @param SectionType The value of the section type to find.
70 @param SectionCheckHook A hook which can check if the section is the target one.
71 @param FileHeader A pointer to the file header that contains the set of sections to
73 @param SectionData A pointer to the discovered section, if successful.
75 @retval EFI_SUCCESS The section was found.
76 @retval EFI_NOT_FOUND The section was not found.
82 IN EFI_SECTION_TYPE SectionType
,
83 IN FFS_CHECK_SECTION_HOOK SectionCheckHook
,
84 IN EFI_PEI_FILE_HANDLE FileHandle
,
85 OUT VOID
**SectionData
89 Find a file in the volume by name
91 @param FileName A pointer to the name of the file to
92 find within the firmware volume.
94 @param VolumeHandle The firmware volume to search FileHandle
95 Upon exit, points to the found file's
96 handle or NULL if it could not be found.
98 @retval EFI_SUCCESS File was found.
100 @retval EFI_NOT_FOUND File was not found.
102 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or
109 IN CONST EFI_GUID
*FileName
,
110 IN CONST EFI_PEI_FV_HANDLE VolumeHandle
,
111 OUT EFI_PEI_FILE_HANDLE
*FileHandle
115 Get information about the file by name.
117 @param FileHandle Handle of the file.
119 @param FileInfo Upon exit, points to the file's
122 @retval EFI_SUCCESS File information returned.
124 @retval EFI_INVALID_PARAMETER If FileHandle does not
125 represent a valid file.
127 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
133 IN CONST EFI_PEI_FILE_HANDLE FileHandle
,
134 OUT EFI_FV_FILE_INFO
*FileInfo
138 Get Information about the volume by name
140 @param VolumeHandle Handle of the volume.
142 @param VolumeInfo Upon exit, points to the volume's
145 @retval EFI_SUCCESS File information returned.
147 @retval EFI_INVALID_PARAMETER If FileHandle does not
148 represent a valid file.
150 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
156 IN EFI_PEI_FV_HANDLE VolumeHandle
,
157 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.
165 @retval EFI_NOT_FOUND FV image can't be found.
166 @retval EFI_SUCCESS Successfully to process it.
172 IN EFI_PEI_FILE_HANDLE FvFileHandle
176 Search through every FV until you find a file of type FileType
178 @param FileType File handle of a Fv type file.
179 @param Volumehandle On success Volume Handle of the match
180 @param FileHandle On success File Handle of the match
182 @retval EFI_NOT_FOUND FV image can't be found.
183 @retval EFI_SUCCESS Successfully found FileType
188 FfsAnyFvFindFirstFile (
189 IN EFI_FV_FILETYPE FileType
,
190 OUT EFI_PEI_FV_HANDLE
*VolumeHandle
,
191 OUT EFI_PEI_FILE_HANDLE
*FileHandle
195 Get Fv image from the FV type file, then add FV & FV2 Hob.
197 @param FileHandle File handle of a Fv type file.
200 @retval EFI_NOT_FOUND FV image can't be found.
201 @retval EFI_SUCCESS Successfully to process it.
207 IN EFI_PEI_FILE_HANDLE FvFileHandle
211 This service enables PEIMs to ascertain the present value of the boot mode.
224 This service enables PEIMs to update the boot mode variable.
226 @param BootMode The value of the boot mode to set.
228 @retval EFI_SUCCESS The value was successfully updated
234 IN EFI_BOOT_MODE BootMode
238 This service enables a PEIM to ascertain the address of the list of HOBs in memory.
240 @param HobList A pointer to the list of HOBs that the PEI Foundation will initialize.
242 @retval EFI_SUCCESS The list was successfully returned.
243 @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.
253 Updates the pointer to the HOB list.
255 @param HobList Hob list pointer to store
264 EFI_HOB_HANDOFF_INFO_TABLE
*
266 IN VOID
*EfiMemoryBegin
,
267 IN UINTN EfiMemoryLength
,
268 IN VOID
*EfiFreeMemoryBottom
,
269 IN VOID
*EfiFreeMemoryTop
273 This service enables PEIMs to create various types of HOBs.
275 @param Type The type of HOB to be installed.
276 @param Length The length of the HOB to be added.
278 @retval !NULL The HOB was successfully created.
279 @retval NULL There is no additional space for HOB creation.
289 Returns the next instance of a HOB type from the starting HOB.
291 This function searches the first instance of a HOB type from the starting HOB pointer.
292 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
293 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
294 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
295 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
296 If HobStart is NULL, then ASSERT().
298 @param Type The HOB type to return.
299 @param HobStart The starting HOB pointer to search from.
301 @return The next instance of a HOB type from the starting HOB.
308 IN CONST VOID
*HobStart
312 Returns the first instance of a HOB type among the whole HOB list.
314 This function searches the first instance of a HOB type among the whole HOB list.
315 If there does not exist such HOB type in the HOB list, it will return NULL.
317 @param Type The HOB type to return.
319 @return The next instance of a HOB type from the starting HOB.
329 This function searches the first instance of a HOB from the starting HOB pointer.
330 Such HOB should satisfy two conditions:
331 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
332 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
333 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
334 to extract the data section and its size info respectively.
335 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
336 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
337 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
338 If Guid is NULL, then ASSERT().
339 If HobStart is NULL, then ASSERT().
341 @param Guid The GUID to match with in the HOB list.
342 @param HobStart A pointer to a Guid.
344 @return The next instance of the matched GUID HOB from the starting HOB.
350 IN CONST EFI_GUID
*Guid
,
351 IN CONST VOID
*HobStart
355 This function searches the first instance of a HOB among the whole HOB list.
356 Such HOB should satisfy two conditions:
357 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
358 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
359 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
360 to extract the data section and its size info respectively.
361 If Guid is NULL, then ASSERT().
363 @param Guid The GUID to match with in the HOB list.
365 @return The first instance of the matched GUID HOB among the whole HOB list.
371 IN CONST EFI_GUID
*Guid
375 Builds a HOB for a loaded PE32 module.
377 This function builds a HOB for a loaded PE32 module.
378 It can only be invoked during PEI phase;
379 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
380 If ModuleName is NULL, then ASSERT().
381 If there is no additional space for HOB creation, then ASSERT().
383 @param ModuleName The GUID File Name of the module.
384 @param MemoryAllocationModule The 64 bit physical address of the module.
385 @param ModuleLength The length of the module in bytes.
386 @param EntryPoint The 64 bit physical address of the module entry point.
392 IN CONST EFI_GUID
*ModuleName
,
393 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
394 IN UINT64 ModuleLength
,
395 IN EFI_PHYSICAL_ADDRESS EntryPoint
399 Builds a HOB that describes a chunk of system memory.
401 This function builds a HOB that describes a chunk of system memory.
402 It can only be invoked during PEI phase;
403 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
404 If there is no additional space for HOB creation, then ASSERT().
406 @param ResourceType The type of resource described by this HOB.
407 @param ResourceAttribute The resource attributes of the memory described by this HOB.
408 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
409 @param NumberOfBytes The length of the memory described by this HOB in bytes.
414 BuildResourceDescriptorHob (
415 IN EFI_RESOURCE_TYPE ResourceType
,
416 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
417 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
418 IN UINT64 NumberOfBytes
422 Builds a GUID HOB with a certain data length.
424 This function builds a customized HOB tagged with a GUID for identification
425 and returns the start address of GUID HOB data so that caller can fill the customized data.
426 The HOB Header and Name field is already stripped.
427 It can only be invoked during PEI phase;
428 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
429 If Guid is NULL, then ASSERT().
430 If there is no additional space for HOB creation, then ASSERT().
431 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
433 @param Guid The GUID to tag the customized HOB.
434 @param DataLength The size of the data payload for the GUID HOB.
436 @return The start address of GUID HOB data.
442 IN CONST EFI_GUID
*Guid
,
447 Copies a data buffer to a newly-built HOB.
449 This function builds a customized HOB tagged with a GUID for identification,
450 copies the input data to the HOB data field and returns the start address of the GUID HOB data.
451 The HOB Header and Name field is already stripped.
452 It can only be invoked during PEI phase;
453 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
454 If Guid is NULL, then ASSERT().
455 If Data is NULL and DataLength > 0, then ASSERT().
456 If there is no additional space for HOB creation, then ASSERT().
457 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
459 @param Guid The GUID to tag the customized HOB.
460 @param Data The data to be copied into the data field of the GUID HOB.
461 @param DataLength The size of the data payload for the GUID HOB.
463 @return The start address of GUID HOB data.
469 IN CONST EFI_GUID
*Guid
,
475 Builds a Firmware Volume HOB.
477 This function builds a Firmware Volume HOB.
478 It can only be invoked during PEI phase;
479 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
480 If there is no additional space for HOB creation, then ASSERT().
482 @param BaseAddress The base address of the Firmware Volume.
483 @param Length The size of the Firmware Volume in bytes.
489 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
494 Builds a Firmware Volume HOB and a resource descriptor 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 PhysicalStart
,
509 IN UINT64 NumberOfBytes
,
510 IN EFI_RESOURCE_ATTRIBUTE_TYPE
*ResourceAttribute OPTIONAL
514 Builds a EFI_HOB_TYPE_FV2 HOB.
516 This function builds a EFI_HOB_TYPE_FV2 HOB.
517 It can only be invoked during PEI phase;
518 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
519 If there is no additional space for HOB creation, then ASSERT().
521 @param BaseAddress The base address of the Firmware Volume.
522 @param Length The size of the Firmware Volume in bytes.
523 @param FvName The name of the Firmware Volume.
524 @param FileName The name of the file.
530 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
532 IN CONST EFI_GUID
*FvName
,
533 IN CONST EFI_GUID
*FileName
537 Builds a Capsule Volume HOB.
539 This function builds a Capsule Volume HOB.
540 It can only be invoked during PEI phase;
541 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
542 If there is no additional space for HOB creation, then ASSERT().
544 @param BaseAddress The base address of the Capsule Volume.
545 @param Length The size of the Capsule Volume in bytes.
551 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
556 Builds a HOB for the CPU.
558 This function builds a HOB for the CPU.
559 It can only be invoked during PEI phase;
560 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
561 If there is no additional space for HOB creation, then ASSERT().
563 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
564 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
570 IN UINT8 SizeOfMemorySpace
,
571 IN UINT8 SizeOfIoSpace
575 Builds a HOB for the Stack.
577 This function builds a HOB for the stack.
578 It can only be invoked during PEI phase;
579 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
580 If there is no additional space for HOB creation, then ASSERT().
582 @param BaseAddress The 64 bit physical address of the Stack.
583 @param Length The length of the stack in bytes.
589 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
594 Update the Stack Hob if the stack has been moved
596 @param BaseAddress The 64 bit physical address of the Stack.
597 @param Length The length of the stack in bytes.
602 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
607 Builds a HOB for the BSP store.
609 This function builds a HOB for BSP store.
610 It can only be invoked during PEI phase;
611 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
612 If there is no additional space for HOB creation, then ASSERT().
614 @param BaseAddress The 64 bit physical address of the BSP.
615 @param Length The length of the BSP store in bytes.
616 @param MemoryType Type of memory allocated by this HOB.
622 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
624 IN EFI_MEMORY_TYPE MemoryType
628 Builds a HOB for the memory allocation.
630 This function builds a HOB for the memory allocation.
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 memory.
636 @param Length The length of the memory allocation in bytes.
637 @param MemoryType Type of memory allocated by this HOB.
642 BuildMemoryAllocationHob (
643 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
645 IN EFI_MEMORY_TYPE MemoryType
650 BuildExtractSectionHob (
652 IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER SectionGetInfo
,
653 IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER SectionExtraction
658 BuildPeCoffLoaderHob (
663 Allocates one or more 4KB pages of type EfiBootServicesData.
665 Allocates the number of 4KB pages of MemoryType and returns a pointer to the
666 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
667 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
670 @param Pages The number of 4 KB pages to allocate.
672 @return A pointer to the allocated buffer or NULL if allocation fails.
682 Allocates one or more 4KB pages of type EfiRuntimeServicesData.
684 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
685 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
686 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
689 @param Pages The number of 4 KB pages to allocate.
691 @return A pointer to the allocated buffer or NULL if allocation fails.
696 AllocateRuntimePages (
701 Allocates a buffer of type EfiBootServicesData.
703 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
704 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
705 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
707 @param AllocationSize The number of bytes to allocate.
709 @return A pointer to the allocated buffer or NULL if allocation fails.
715 IN UINTN AllocationSize
719 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
721 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
722 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
723 returned. If there is not enough memory at the specified alignment remaining to satisfy the
724 request, then NULL is returned.
725 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
727 @param Pages The number of 4 KB pages to allocate.
728 @param Alignment The requested alignment of the allocation. Must be a power of two.
729 If Alignment is zero, then byte alignment is used.
731 @return A pointer to the allocated buffer or NULL if allocation fails.
736 AllocateAlignedPages (
744 IN VOID
*PeCoffImage
,
745 OUT EFI_PHYSICAL_ADDRESS
*ImageAddress
,
746 OUT UINT64
*ImageSize
,
747 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
752 LoadDxeCoreFromFfsFile (
753 IN EFI_PEI_FILE_HANDLE FileHandle
,
760 IN UINTN
*FvInstance OPTIONAL
,