3 Copyright (c) 2004 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
27 #include "PeiHobLib.h"
29 #include EFI_PROTOCOL_DEFINITION (Decompress)
30 #include EFI_PROTOCOL_DEFINITION (TianoDecompress)
31 #include EFI_GUID_DEFINITION (PeiPeCoffLoader)
32 #include EFI_PPI_DEFINITION (FindFv)
35 #if (PI_SPECIFICATION_VERSION >= 0x00010000)
38 UINT32 PeiServiceTable
;
53 Scans a target buffer for a GUID, and returns a pointer to the matching GUID
56 This function searches target the buffer specified by Buffer and Length from
57 the lowest address to the highest address at 128-bit increments for the 128-bit
58 GUID value that matches Guid. If a match is found, then a pointer to the matching
59 GUID in the target buffer is returned. If no match is found, then NULL is returned.
60 If Length is 0, then NULL is returned.
61 If Length > 0 and Buffer is NULL, then ASSERT().
62 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
63 If Length is not aligned on a 128-bit boundary, then ASSERT().
64 If Length is greater than (EFI_MAX_ADDRESS ?Buffer + 1), then ASSERT().
68 Buffer - Pointer to the target buffer to scan.
69 Length - Number of bytes in Buffer to scan.
70 Guid - Value to search for in the target buffer.
73 A pointer to the matching Guid in the target buffer or NULL otherwise.
80 InvalidateInstructionCacheRange (
88 Invalidates a range of instruction cache lines in the cache coherency domain
91 Invalidates the instruction cache lines specified by Address and Length. If
92 Address is not aligned on a cache line boundary, then entire instruction
93 cache line containing Address is invalidated. If Address + Length is not
94 aligned on a cache line boundary, then the entire instruction cache line
95 containing Address + Length -1 is invalidated. This function may choose to
96 invalidate the entire instruction cache if that is more efficient than
97 invalidating the specified range. If Length is 0, the no instruction cache
98 lines are invalidated. Address is returned.
100 If Length is greater than (EFI_MAX_ADDRESS - Address + 1), then ASSERT().
104 Address - The base address of the instruction cache lines to
105 invalidate. If the CPU is in a physical addressing mode, then
106 Address is a physical address. If the CPU is in a virtual
107 addressing mode, then Address is a virtual address.
109 Length - The number of bytes to invalidate from the instruction cache.
119 PeiLibFfsFindNextVolume (
121 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
127 The wrapper of Pei Core Service function FfsFindNextVolume.
131 Instance - The Fv Volume Instance.
132 VolumeHandle - Pointer to the current Fv Volume to search.
142 PeiLibFfsFindNextFile (
143 IN EFI_FV_FILETYPE SearchType
,
144 IN EFI_PEI_FV_HANDLE FwVolHeader
,
145 IN OUT EFI_PEI_FILE_HANDLE
*FileHeader
151 The wrapper of Pei Core Service function FfsFindNextFile.
155 SearchType - Filter to find only file of this type.
156 FwVolHeader - Pointer to the current FV to search.
157 FileHandle - Pointer to the file matching SearchType in FwVolHeader.
158 - NULL if file not found
168 PeiLibFfsFindFileByName (
169 IN EFI_GUID
*FileName
,
170 IN EFI_PEI_FV_HANDLE VolumeHandle
,
171 OUT EFI_PEI_FILE_HANDLE
*FileHandle
177 The wrapper of Pei Core Service function FfsFindFileByName.
181 FileName - File name to search.
182 VolumeHandle - The current FV to search.
183 FileHandle - Pointer to the file matching name in VolumeHandle.
184 - NULL if file not found
194 PeiLibFfsFindSectionData (
195 IN EFI_SECTION_TYPE SectionType
,
196 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
197 IN OUT VOID
**SectionData
203 The wrapper of Pei Core Service function FfsFindSectionData.
207 SearchType - Filter to find only sections of this type.
208 FileHandle - Pointer to the current file to search.
209 SectionData - Pointer to the Section matching SectionType in FfsFileHeader.
210 - NULL if section not found
219 PeiLibFfsGetVolumeInfo (
220 IN EFI_PEI_FV_HANDLE
*VolumeHandle
,
221 OUT EFI_FV_INFO
*VolumeInfo
227 The wrapper of Pei Core Service function FfsGetVolumeInfo.
231 VolumeHandle - The handle to Fv Volume.
232 VolumeInfo - The pointer to volume information.
241 PeiServicesLocatePpi (
244 IN OUT EFI_PEI_PPI_DESCRIPTOR
**PpiDescriptor
,
251 The wrapper of Pei Core Service function LocatePpi.
255 Guid - Pointer to GUID of the PPI.
256 Instance - Instance Number to discover.
257 PpiDescriptor - Pointer to reference the found descriptor. If not NULL,
258 returns a pointer to the descriptor (includes flags, etc)
259 Ppi - Pointer to reference the found PPI
263 Status - EFI_SUCCESS if the PPI is in the database
264 EFI_NOT_FOUND if the PPI is not in the database
271 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
282 BaseAddress - Fv base address.
294 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
296 IN EFI_GUID
*FvNameGuid
,
297 IN EFI_GUID
*FileNameGuid
307 BaseAddress - Fv base address.
309 FvNameGuid - Fv name.
310 FileNameGuid - File name which contians encapsulated Fv.
333 Guid - guid to build data hob.
334 Data - data to build data hob.
335 DataLength - the length of data.
356 Pages - Pages to allocate.
359 Address if successful to allocate memory.
360 NULL if fail to allocate memory.
366 SetPeiServicesTablePointer (
367 IN EFI_PEI_SERVICES
**PeiServices
373 Save PeiService pointer so that it can be retrieved anywhere.
377 PeiServices - The direct pointer to PeiServiceTable.
386 GetPeiServicesTablePointer (
393 Get PeiService pointer.
400 The direct pointer to PeiServiceTable.
407 IN EFI_PEI_SERVICES
**PeiServices
413 Migrate IDT from CAR to real memory where preceded with 4 bytes for
414 storing PeiService pointer.
418 PeiServices - The direct pointer to PeiServiceTable.
436 Read IDT Register BaseAddress.
443 IDT Register BaseAddress.
457 Read IDT Register Limit.
479 Set IDT Register BaseAddress.
483 IdtBase - IDT.BaseAddress
499 Write 64 bit into Kernel Register7 on IPF.
503 Address - Data to write into kr7.
520 Read 64 bit from Kernel Register7 on IPF.
536 IN VOID
*Destination
,
544 Copy Length bytes from Source to Destination.
548 Destination - Target of copy
550 Source - Place to copy from
552 Length - Number of bytes to copy
570 Set Buffer to zero for Size bytes.
574 Buffer - Memory to set.
576 Size - Number of bytes to set
587 IN VOID
*Destination
,
595 Copy Length bytes from Source to Destination.
599 Destination - Target of copy
601 Source - Place to copy from
603 Length - Number of bytes to copy
625 Guid1 - guid to compare
626 Guid2 - guid to compare
629 = TRUE if Guid1 == Guid2
630 = FALSE if Guid1 != Guid2
636 InstallEfiPeiPeCoffLoader (
637 IN EFI_PEI_SERVICES
**PeiServices
,
638 IN EFI_PEI_PE_COFF_LOADER_PROTOCOL
**This
,
639 IN EFI_PEI_PPI_DESCRIPTOR
*ThisPpi
645 Install EFI Pei PE coff loader protocol.
649 PeiServices - The PEI core services table.
651 This - Pointer to get Pei PE coff loader protocol as output
653 ThisPpi - Passed in as EFI_NT_LOAD_AS_DLL_PPI on NT_EMULATOR platform
663 InstallEfiPeiPeCoffLoader64 (
664 IN EFI_PEI_SERVICES
**PeiServices
,
665 IN OUT EFI_PEI_PE_COFF_LOADER_PROTOCOL
**This
,
666 IN EFI_PEI_PPI_DESCRIPTOR
*ThisPpi
672 InstallEfiDecompress (
673 EFI_DECOMPRESS_PROTOCOL
**This
679 Install EFI decompress protocol.
683 This - Pointer to get decompress protocol as output
687 EFI_SUCCESS - EFI decompress protocol successfully installed.
693 InstallTianoDecompress (
694 EFI_TIANO_DECOMPRESS_PROTOCOL
**This
700 Install Tiano decompress protocol.
704 This - Pointer to get decompress protocol as output
708 EFI_SUCCESS - Tiano decompress protocol successfully installed.
715 OUT UINT64
*TimerValue
725 TimerValue - Pointer to the returned timer value
729 EFI_SUCCESS - Successfully got timer value
734 #ifdef EFI_NT_EMULATOR
736 PeCoffLoaderWinNtLoadAsDll (
737 IN CHAR8
*PdbFileName
,
738 IN VOID
**ImageEntryPoint
,
745 Loads the .DLL file is present when a PE/COFF file is loaded. This provides source level
746 debugging for drivers that have cooresponding .DLL files on the local system.
750 PdbFileName - The name of the .PDB file. This was found from the PE/COFF
751 file's debug directory entry.
753 ImageEntryPoint - A pointer to the DLL entry point of the .DLL file was loaded.
755 ModHandle - Pointer to loaded library.
759 EFI_SUCCESS - The .DLL file was loaded, and the DLL entry point is returned in ImageEntryPoint
761 EFI_NOT_FOUND - The .DLL file could not be found
763 EFI_UNSUPPORTED - The .DLL file was loaded, but the entry point to the .DLL file could not
775 IN EFI_PEI_SERVICES
**PeiServices
,
776 IN EFI_GUID
*ModuleName
,
777 IN EFI_PHYSICAL_ADDRESS Module
,
778 IN UINT64 ModuleLength
,
779 IN EFI_PHYSICAL_ADDRESS EntryPoint
785 Builds a HOB for a loaded PE32 module
789 PeiServices - The PEI core services table.
790 ModuleName - The GUID File Name of the module
791 Memory - The 64 bit physical address of the module
792 ModuleLength - The length of the module in bytes
793 EntryPoint - The 64 bit physical address of the entry point
798 EFI_SUCCESS - Hob is successfully built.
799 Others - Errors occur while creating new Hob
805 PeiBuildHobResourceDescriptor (
806 IN EFI_PEI_SERVICES
**PeiServices
,
807 IN EFI_RESOURCE_TYPE ResourceType
,
808 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
809 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
810 IN UINT64 NumberOfBytes
816 Builds a HOB that describes a chunck of system memory
820 PeiServices - The PEI core services table.
822 ResourceType - The type of resource described by this HOB
824 ResourceAttribute - The resource attributes of the memory described by this HOB
826 PhysicalStart - The 64 bit physical address of memory described by this HOB
828 NumberOfBytes - The length of the memoty described by this HOB in bytes
832 EFI_SUCCESS - Hob is successfully built.
833 Others - Errors occur while creating new Hob
840 IN EFI_PEI_SERVICES
**PeiServices
,
849 Builds a custom HOB that is tagged with a GUID for identification
853 PeiServices - The PEI core services table.
855 Guid - The GUID of the custome HOB type
857 DataLength - The size of the data payload for the GUIDed HOB
859 Hob - Pointer to the Hob
863 EFI_SUCCESS - Hob is successfully built.
864 Others - Errors occur while creating new Hob
870 PeiBuildHobGuidData (
871 IN EFI_PEI_SERVICES
**PeiServices
,
880 Builds a custom HOB that is tagged with a GUID for identification
884 PeiServices - The PEI core services table.
886 Guid - The GUID of the custome HOB type
888 Data - The data to be copied into the GUIDed HOB data field.
890 DataLength - The data field length.
894 EFI_SUCCESS - Hob is successfully built.
895 Others - Errors occur while creating new Hob
902 IN EFI_PEI_SERVICES
**PeiServices
,
903 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
910 Builds a Firmware Volume HOB
914 PeiServices - The PEI core services table.
916 BaseAddress - The base address of the Firmware Volume
918 Length - The size of the Firmware Volume in bytes
922 EFI_SUCCESS - Hob is successfully built.
923 Others - Errors occur while creating new Hob
930 IN EFI_PEI_SERVICES
**PeiServices
,
931 IN UINT8 SizeOfMemorySpace
,
932 IN UINT8 SizeOfIoSpace
938 Builds a HOB for the CPU
942 PeiServices - The PEI core services table.
944 SizeOfMemorySpace - Identifies the maximum
945 physical memory addressibility of the processor.
947 SizeOfIoSpace - Identifies the maximum physical I/O addressibility
952 EFI_SUCCESS - Hob is successfully built.
953 Others - Errors occur while creating new Hob
960 IN EFI_PEI_SERVICES
**PeiServices
,
961 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
968 Builds a HOB for the Stack
972 PeiServices - The PEI core services table.
974 BaseAddress - The 64 bit physical address of the Stack
976 Length - The length of the stack in bytes
980 EFI_SUCCESS - Hob is successfully built.
981 Others - Errors occur while creating new Hob
987 PeiBuildHobBspStore (
988 IN EFI_PEI_SERVICES
**PeiServices
,
989 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
991 IN EFI_MEMORY_TYPE MemoryType
997 Builds a HOB for the bsp store
1001 PeiServices - The PEI core services table.
1003 BaseAddress - The 64 bit physical address of the bsp store
1005 Length - The length of the bsp store in bytes
1007 MemoryType - Memory type
1011 EFI_SUCCESS - Hob is successfully built.
1012 Others - Errors occur while creating new Hob
1018 PeiBuildHobMemoryAllocation (
1019 IN EFI_PEI_SERVICES
**PeiServices
,
1020 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
1023 IN EFI_MEMORY_TYPE MemoryType
1027 Routine Description:
1029 Builds a HOB for the memory allocation
1033 PeiServices - The PEI core services table.
1035 BaseAddress - The 64 bit physical address of the memory
1037 Length - The length of the memory allocation in bytes
1041 MemoryType - Memory type
1045 EFI_SUCCESS - Hob is successfully built.
1046 Others - Errors occur while creating new Hob
1056 OUT CHAR8
*StartOfBuffer
,
1058 IN CONST CHAR8
*Format
,
1063 Routine Description:
1065 AvSPrint function to process format and place the results in Buffer. Since a
1066 VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
1067 this is the main print working routine
1071 StartOfBuffer - Ascii buffer to print the results of the parsing of Format into.
1073 StrSize - Maximum number of characters to put into buffer. Zero means
1076 FormatString - Ascii format string see file header for more details.
1078 Marker - Vararg list consumed by processing Format.
1082 Number of characters printed.
1090 IN UINTN BufferSize
,
1091 IN CONST CHAR8
*Format
,
1096 Routine Description:
1098 ASPrint function to process format and place the results in Buffer.
1102 Buffer - Ascii buffer to print the results of the parsing of Format into.
1104 BufferSize - Maximum number of characters to put into buffer. Zero means no
1107 Format - Ascii format string see file header for more details.
1109 ... - Vararg list consumed by processing Format.
1113 Number of characters printed.
1123 IN UINT64 Multiplicand
,
1128 Routine Description:
1130 This routine allows a 64 bit value to be multiplied with a 32 bit
1131 value returns 64bit result.
1132 No checking if the result is greater than 64bits
1136 Multiplicand - multiplicand
1137 Multiplier - multiplier
1141 Multiplicand * Multiplier
1150 OUT UINTN
*Remainder OPTIONAL
1154 Routine Description:
1156 This routine allows a 64 bit value to be divided with a 32 bit value returns
1157 64bit result and the Remainder.
1158 N.B. only works for 31bit divisors!!
1164 Remainder - buffer for remainder
1169 Remainder = Dividend mod Divisor
1181 Routine Description:
1183 This routine allows a 64 bit value to be right shifted by 32 bits and returns the
1185 Count is valid up 63. (Only Bits 0-5 is valid for Count)
1189 Operand - Value to be shifted
1190 Count - Number of times to shift right.
1194 Value shifted right identified by the Count.
1206 Routine Description:
1208 This routine allows a 64 bit value to be left shifted by 32 bits and
1209 returns the shifted value.
1210 Count is valid up 63. (Only Bits 0-5 is valid for Count)
1214 Operand - Value to be shifted
1215 Count - Number of times to shift left.
1219 Value shifted left identified by the Count.
1225 RegisterNativeCpuIo (
1226 IN EFI_PEI_SERVICES
**PeiServices
,
1231 Routine Description:
1233 Register a native Cpu IO
1237 PeiServices - Calling context
1238 CpuIo - CpuIo instance to register
1249 IN EFI_PEI_SERVICES
**PeiServices
,
1254 Routine Description:
1256 Get registered Cpu IO.
1260 PeiServices - Calling context
1261 CpuIo - CpuIo instance registered before
1273 IN EFI_FIND_FV_PPI
*This
,
1274 IN EFI_PEI_SERVICES
**PeiServices
,
1275 IN OUT UINT8
*FvNumber
,
1276 IN OUT EFI_FIRMWARE_VOLUME_HEADER
**FVAddress
1280 Routine Description:
1286 This - Interface pointer that implement the Find Fv PPI
1288 PeiServices - Pointer to the PEI Service Table
1290 FvNumber - On input, the number of the fireware volume which supports FFS to locate
1291 On output, the next FV number which supports FFS.
1293 FVAddress - The address of the volume which supports FFS to discover
1297 EFI_SUCCESS - An addtional FV which supports FFS found
1298 EFI_OUT_OF_RESOURCES - There are no fireware volume which supports FFS for given fvnumber
1299 EFI_INVALID_PARAMETER - FvAddress is NULL