2 Library that helps implement monolithic PEI. (SEC goes to DXE)
4 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
6 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.
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
177 Search through every FV until you find a file of type FileType
179 @param FileType File handle of a Fv type file.
180 @param Volumehandle On succes Volume Handle of the match
181 @param FileHandle On success File Handle of the match
183 @retval EFI_NOT_FOUND FV image can't be found.
184 @retval EFI_SUCCESS Successfully found FileType
189 FfsAnyFvFindFirstFile (
190 IN EFI_FV_FILETYPE FileType
,
191 OUT EFI_PEI_FV_HANDLE
*VolumeHandle
,
192 OUT EFI_PEI_FILE_HANDLE
*FileHandle
197 Get Fv image from the FV type file, then add FV & FV2 Hob.
199 @param FileHandle File handle of a Fv type file.
202 @retval EFI_NOT_FOUND FV image can't be found.
203 @retval EFI_SUCCESS Successfully to process it.
209 IN EFI_PEI_FILE_HANDLE FvFileHandle
214 This service enables PEIMs to ascertain the present value of the boot mode.
228 This service enables PEIMs to update the boot mode variable.
230 @param BootMode The value of the boot mode to set.
232 @retval EFI_SUCCESS The value was successfully updated
238 IN EFI_BOOT_MODE BootMode
242 This service enables a PEIM to ascertain the address of the list of HOBs in memory.
244 @param HobList A pointer to the list of HOBs that the PEI Foundation will initialize.
246 @retval EFI_SUCCESS The list was successfully returned.
247 @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.
258 Updates the pointer to the HOB list.
260 @param HobList Hob list pointer to store
269 EFI_HOB_HANDOFF_INFO_TABLE
*
271 IN VOID
*EfiMemoryBegin
,
272 IN UINTN EfiMemoryLength
,
273 IN VOID
*EfiFreeMemoryBottom
,
274 IN VOID
*EfiFreeMemoryTop
278 This service enables PEIMs to create various types of HOBs.
280 @param Type The type of HOB to be installed.
281 @param Length The length of the HOB to be added.
283 @retval !NULL The HOB was successfully created.
284 @retval NULL There is no additional space for HOB creation.
295 Returns the next instance of a HOB type from the starting HOB.
297 This function searches the first instance of a HOB type from the starting HOB pointer.
298 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
299 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
300 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
301 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
302 If HobStart is NULL, then ASSERT().
304 @param Type The HOB type to return.
305 @param HobStart The starting HOB pointer to search from.
307 @return The next instance of a HOB type from the starting HOB.
314 IN CONST VOID
*HobStart
318 Returns the first instance of a HOB type among the whole HOB list.
320 This function searches the first instance of a HOB type among the whole HOB list.
321 If there does not exist such HOB type in the HOB list, it will return NULL.
323 @param Type The HOB type to return.
325 @return The next instance of a HOB type from the starting HOB.
335 This function searches the first instance of a HOB from the starting HOB pointer.
336 Such HOB should satisfy two conditions:
337 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
338 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
339 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
340 to extract the data section and its size info respectively.
341 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
342 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
343 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
344 If Guid is NULL, then ASSERT().
345 If HobStart is NULL, then ASSERT().
347 @param Guid The GUID to match with in the HOB list.
348 @param HobStart A pointer to a Guid.
350 @return The next instance of the matched GUID HOB from the starting HOB.
356 IN CONST EFI_GUID
*Guid
,
357 IN CONST VOID
*HobStart
361 This function searches the first instance of a HOB among the whole HOB list.
362 Such HOB should satisfy two conditions:
363 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
364 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
365 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
366 to extract the data section and its size info respectively.
367 If Guid is NULL, then ASSERT().
369 @param Guid The GUID to match with in the HOB list.
371 @return The first instance of the matched GUID HOB among the whole HOB list.
377 IN CONST EFI_GUID
*Guid
382 Builds a HOB for a loaded PE32 module.
384 This function builds a HOB for a loaded PE32 module.
385 It can only be invoked during PEI phase;
386 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
387 If ModuleName is NULL, then ASSERT().
388 If there is no additional space for HOB creation, then ASSERT().
390 @param ModuleName The GUID File Name of the module.
391 @param MemoryAllocationModule The 64 bit physical address of the module.
392 @param ModuleLength The length of the module in bytes.
393 @param EntryPoint The 64 bit physical address of the module entry point.
399 IN CONST EFI_GUID
*ModuleName
,
400 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
401 IN UINT64 ModuleLength
,
402 IN EFI_PHYSICAL_ADDRESS EntryPoint
406 Builds a HOB that describes a chunk of system memory.
408 This function builds a HOB that describes a chunk of system memory.
409 It can only be invoked during PEI phase;
410 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
411 If there is no additional space for HOB creation, then ASSERT().
413 @param ResourceType The type of resource described by this HOB.
414 @param ResourceAttribute The resource attributes of the memory described by this HOB.
415 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
416 @param NumberOfBytes The length of the memory described by this HOB in bytes.
421 BuildResourceDescriptorHob (
422 IN EFI_RESOURCE_TYPE ResourceType
,
423 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
424 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
425 IN UINT64 NumberOfBytes
429 Builds a GUID HOB with a certain data length.
431 This function builds a customized HOB tagged with a GUID for identification
432 and returns the start address of GUID HOB data so that caller can fill the customized data.
433 The HOB Header and Name field is already stripped.
434 It can only be invoked during PEI phase;
435 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
436 If Guid is NULL, then ASSERT().
437 If there is no additional space for HOB creation, then ASSERT().
438 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
440 @param Guid The GUID to tag the customized HOB.
441 @param DataLength The size of the data payload for the GUID HOB.
443 @return The start address of GUID HOB data.
449 IN CONST EFI_GUID
*Guid
,
454 Copies a data buffer to a newly-built HOB.
456 This function builds a customized HOB tagged with a GUID for identification,
457 copies the input data to the HOB data field and returns the start address of the GUID HOB data.
458 The HOB Header and Name field is already stripped.
459 It can only be invoked during PEI phase;
460 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
461 If Guid is NULL, then ASSERT().
462 If Data is NULL and DataLength > 0, then ASSERT().
463 If there is no additional space for HOB creation, then ASSERT().
464 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
466 @param Guid The GUID to tag the customized HOB.
467 @param Data The data to be copied into the data field of the GUID HOB.
468 @param DataLength The size of the data payload for the GUID HOB.
470 @return The start address of GUID HOB data.
476 IN CONST EFI_GUID
*Guid
,
482 Builds a Firmware Volume HOB.
484 This function builds a Firmware Volume HOB.
485 It can only be invoked during PEI phase;
486 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
487 If there is no additional space for HOB creation, then ASSERT().
489 @param BaseAddress The base address of the Firmware Volume.
490 @param Length The size of the Firmware Volume in bytes.
496 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
501 Builds a Firmware Volume HOB and a resrouce descriptor hob
503 This function builds a Firmware Volume HOB.
504 It can only be invoked during PEI phase;
505 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
506 If there is no additional space for HOB creation, then ASSERT().
508 @param BaseAddress The base address of the Firmware Volume.
509 @param Length The size of the Firmware Volume in bytes.
515 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
516 IN UINT64 NumberOfBytes
,
517 IN EFI_RESOURCE_ATTRIBUTE_TYPE
*ResourceAttribute OPTIONAL
522 Builds a EFI_HOB_TYPE_FV2 HOB.
524 This function builds a EFI_HOB_TYPE_FV2 HOB.
525 It can only be invoked during PEI phase;
526 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
527 If there is no additional space for HOB creation, then ASSERT().
529 @param BaseAddress The base address of the Firmware Volume.
530 @param Length The size of the Firmware Volume in bytes.
531 @param FvName The name of the Firmware Volume.
532 @param FileName The name of the file.
538 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
540 IN CONST EFI_GUID
*FvName
,
541 IN CONST EFI_GUID
*FileName
545 Builds a Capsule Volume HOB.
547 This function builds a Capsule Volume HOB.
548 It can only be invoked during PEI phase;
549 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
550 If there is no additional space for HOB creation, then ASSERT().
552 @param BaseAddress The base address of the Capsule Volume.
553 @param Length The size of the Capsule Volume in bytes.
559 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
564 Builds a HOB for the CPU.
566 This function builds a HOB for the CPU.
567 It can only be invoked during PEI phase;
568 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
569 If there is no additional space for HOB creation, then ASSERT().
571 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
572 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
578 IN UINT8 SizeOfMemorySpace
,
579 IN UINT8 SizeOfIoSpace
583 Builds a HOB for the Stack.
585 This function builds a HOB for the stack.
586 It can only be invoked during PEI phase;
587 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
588 If there is no additional space for HOB creation, then ASSERT().
590 @param BaseAddress The 64 bit physical address of the Stack.
591 @param Length The length of the stack in bytes.
597 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
602 Update the Stack Hob if the stack has been moved
604 @param BaseAddress The 64 bit physical address of the Stack.
605 @param Length The length of the stack in bytes.
610 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
616 Builds a HOB for the BSP store.
618 This function builds a HOB for BSP store.
619 It can only be invoked during PEI phase;
620 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
621 If there is no additional space for HOB creation, then ASSERT().
623 @param BaseAddress The 64 bit physical address of the BSP.
624 @param Length The length of the BSP store in bytes.
625 @param MemoryType Type of memory allocated by this HOB.
631 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
633 IN EFI_MEMORY_TYPE MemoryType
637 Builds a HOB for the memory allocation.
639 This function builds a HOB for the memory allocation.
640 It can only be invoked during PEI phase;
641 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
642 If there is no additional space for HOB creation, then ASSERT().
644 @param BaseAddress The 64 bit physical address of the memory.
645 @param Length The length of the memory allocation in bytes.
646 @param MemoryType Type of memory allocated by this HOB.
651 BuildMemoryAllocationHob (
652 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
654 IN EFI_MEMORY_TYPE MemoryType
660 BuildExtractSectionHob (
662 IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER SectionGetInfo
,
663 IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER SectionExtraction
668 BuildPeCoffLoaderHob (
674 Allocates one or more 4KB pages of type EfiBootServicesData.
676 Allocates the number of 4KB pages of MemoryType and returns a pointer to the
677 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
678 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
681 @param Pages The number of 4 KB pages to allocate.
683 @return A pointer to the allocated buffer or NULL if allocation fails.
693 Allocates a buffer of type EfiBootServicesData.
695 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
696 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
697 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
699 @param AllocationSize The number of bytes to allocate.
701 @return A pointer to the allocated buffer or NULL if allocation fails.
707 IN UINTN AllocationSize
712 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
714 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
715 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
716 returned. If there is not enough memory at the specified alignment remaining to satisfy the
717 request, then NULL is returned.
718 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
720 @param Pages The number of 4 KB pages to allocate.
721 @param Alignment The requested alignment of the allocation. Must be a power of two.
722 If Alignment is zero, then byte alignment is used.
724 @return A pointer to the allocated buffer or NULL if allocation fails.
729 AllocateAlignedPages (
738 IN VOID
*PeCoffImage
,
739 OUT EFI_PHYSICAL_ADDRESS
*ImageAddress
,
740 OUT UINT64
*ImageSize
,
741 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
746 LoadDxeCoreFromFfsFile (
747 IN EFI_PEI_FILE_HANDLE FileHandle
,
754 IN UINTN
*FvInstance
, OPTIONAL
766 AddDxeCoreReportStatusCodeCallback (