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"
28 #include EFI_PROTOCOL_DEFINITION (Decompress)
29 #include EFI_PROTOCOL_DEFINITION (TianoDecompress)
30 #include EFI_GUID_DEFINITION (PeiPeCoffLoader)
31 #include EFI_PPI_DEFINITION (FindFv)
34 #if (PI_SPECIFICATION_VERSION >= 0x00010000)
37 UINT32 PeiServiceTable
;
52 Scans a target buffer for a GUID, and returns a pointer to the matching GUID
55 This function searches target the buffer specified by Buffer and Length from
56 the lowest address to the highest address at 128-bit increments for the 128-bit
57 GUID value that matches Guid. If a match is found, then a pointer to the matching
58 GUID in the target buffer is returned. If no match is found, then NULL is returned.
59 If Length is 0, then NULL is returned.
60 If Length > 0 and Buffer is NULL, then ASSERT().
61 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
62 If Length is not aligned on a 128-bit boundary, then ASSERT().
63 If Length is greater than (EFI_MAX_ADDRESS ?Buffer + 1), then ASSERT().
67 Buffer - Pointer to the target buffer to scan.
68 Length - Number of bytes in Buffer to scan.
69 Guid - Value to search for in the target buffer.
72 A pointer to the matching Guid in the target buffer or NULL otherwise.
79 InvalidateInstructionCacheRange (
87 Invalidates a range of instruction cache lines in the cache coherency domain
90 Invalidates the instruction cache lines specified by Address and Length. If
91 Address is not aligned on a cache line boundary, then entire instruction
92 cache line containing Address is invalidated. If Address + Length is not
93 aligned on a cache line boundary, then the entire instruction cache line
94 containing Address + Length -1 is invalidated. This function may choose to
95 invalidate the entire instruction cache if that is more efficient than
96 invalidating the specified range. If Length is 0, the no instruction cache
97 lines are invalidated. Address is returned.
99 If Length is greater than (EFI_MAX_ADDRESS - Address + 1), then ASSERT().
103 Address - The base address of the instruction cache lines to
104 invalidate. If the CPU is in a physical addressing mode, then
105 Address is a physical address. If the CPU is in a virtual
106 addressing mode, then Address is a virtual address.
108 Length - The number of bytes to invalidate from the instruction cache.
118 PeiLibFfsFindNextVolume (
120 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
126 The wrapper of Pei Core Service function FfsFindNextVolume.
130 Instance - The Fv Volume Instance.
131 VolumeHandle - Pointer to the current Fv Volume to search.
141 PeiLibFfsFindNextFile (
142 IN EFI_FV_FILETYPE SearchType
,
143 IN EFI_PEI_FV_HANDLE FwVolHeader
,
144 IN OUT EFI_PEI_FILE_HANDLE
*FileHeader
150 The wrapper of Pei Core Service function FfsFindNextFile.
154 SearchType - Filter to find only file of this type.
155 FwVolHeader - Pointer to the current FV to search.
156 FileHandle - Pointer to the file matching SearchType in FwVolHeader.
157 - NULL if file not found
167 PeiLibFfsFindFileByName (
168 IN EFI_GUID
*FileName
,
169 IN EFI_PEI_FV_HANDLE VolumeHandle
,
170 OUT EFI_PEI_FILE_HANDLE
*FileHandle
176 The wrapper of Pei Core Service function FfsFindFileByName.
180 FileName - File name to search.
181 VolumeHandle - The current FV to search.
182 FileHandle - Pointer to the file matching name in VolumeHandle.
183 - NULL if file not found
193 PeiLibFfsFindSectionData (
194 IN EFI_SECTION_TYPE SectionType
,
195 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
196 IN OUT VOID
**SectionData
202 The wrapper of Pei Core Service function FfsFindSectionData.
206 SearchType - Filter to find only sections of this type.
207 FileHandle - Pointer to the current file to search.
208 SectionData - Pointer to the Section matching SectionType in FfsFileHeader.
209 - NULL if section not found
218 PeiLibFfsGetVolumeInfo (
219 IN EFI_PEI_FV_HANDLE
*VolumeHandle
,
220 OUT EFI_FV_INFO
*VolumeInfo
226 The wrapper of Pei Core Service function FfsGetVolumeInfo.
230 VolumeHandle - The handle to Fv Volume.
231 VolumeInfo - The pointer to volume information.
240 PeiServicesLocatePpi (
243 IN OUT EFI_PEI_PPI_DESCRIPTOR
**PpiDescriptor
,
250 The wrapper of Pei Core Service function LocatePpi.
254 Guid - Pointer to GUID of the PPI.
255 Instance - Instance Number to discover.
256 PpiDescriptor - Pointer to reference the found descriptor. If not NULL,
257 returns a pointer to the descriptor (includes flags, etc)
258 Ppi - Pointer to reference the found PPI
262 Status - EFI_SUCCESS if the PPI is in the database
263 EFI_NOT_FOUND if the PPI is not in the database
270 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
281 BaseAddress - Fv base address.
293 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
295 IN EFI_GUID
*FvNameGuid
,
296 IN EFI_GUID
*FileNameGuid
306 BaseAddress - Fv base address.
308 FvNameGuid - Fv name.
309 FileNameGuid - File name which contians encapsulated Fv.
332 Guid - guid to build data hob.
333 Data - data to build data hob.
334 DataLength - the length of data.
355 Pages - Pages to allocate.
358 Address if successful to allocate memory.
359 NULL if fail to allocate memory.
365 SetPeiServicesTablePointer (
366 IN EFI_PEI_SERVICES
**PeiServices
372 Save PeiService pointer so that it can be retrieved anywhere.
376 PeiServices - The direct pointer to PeiServiceTable.
385 GetPeiServicesTablePointer (
392 Get PeiService pointer.
399 The direct pointer to PeiServiceTable.
406 IN EFI_PEI_SERVICES
**PeiServices
412 Migrate IDT from CAR to real memory where preceded with 4 bytes for
413 storing PeiService pointer.
417 PeiServices - The direct pointer to PeiServiceTable.
435 Read IDT Register BaseAddress.
442 IDT Register BaseAddress.
456 Read IDT Register Limit.
478 Set IDT Register BaseAddress.
482 IdtBase - IDT.BaseAddress
498 Write 64 bit into Kernel Register7 on IPF.
502 Address - Data to write into kr7.
519 Read 64 bit from Kernel Register7 on IPF.
535 IN VOID
*Destination
,
543 Copy Length bytes from Source to Destination.
547 Destination - Target of copy
549 Source - Place to copy from
551 Length - Number of bytes to copy
569 Set Buffer to zero for Size bytes.
573 Buffer - Memory to set.
575 Size - Number of bytes to set
586 IN VOID
*Destination
,
594 Copy Length bytes from Source to Destination.
598 Destination - Target of copy
600 Source - Place to copy from
602 Length - Number of bytes to copy
624 Guid1 - guid to compare
625 Guid2 - guid to compare
628 = TRUE if Guid1 == Guid2
629 = FALSE if Guid1 != Guid2
635 InstallEfiPeiPeCoffLoader (
636 IN EFI_PEI_SERVICES
**PeiServices
,
637 IN EFI_PEI_PE_COFF_LOADER_PROTOCOL
**This
,
638 IN EFI_PEI_PPI_DESCRIPTOR
*ThisPpi
644 Install EFI Pei PE coff loader protocol.
648 PeiServices - The PEI core services table.
650 This - Pointer to get Pei PE coff loader protocol as output
652 ThisPpi - Passed in as EFI_NT_LOAD_AS_DLL_PPI on NT_EMULATOR platform
662 InstallEfiPeiPeCoffLoader64 (
663 IN EFI_PEI_SERVICES
**PeiServices
,
664 IN OUT EFI_PEI_PE_COFF_LOADER_PROTOCOL
**This
,
665 IN EFI_PEI_PPI_DESCRIPTOR
*ThisPpi
671 InstallEfiDecompress (
672 EFI_DECOMPRESS_PROTOCOL
**This
678 Install EFI decompress protocol.
682 This - Pointer to get decompress protocol as output
686 EFI_SUCCESS - EFI decompress protocol successfully installed.
692 InstallTianoDecompress (
693 EFI_TIANO_DECOMPRESS_PROTOCOL
**This
699 Install Tiano decompress protocol.
703 This - Pointer to get decompress protocol as output
707 EFI_SUCCESS - Tiano decompress protocol successfully installed.
714 EFI_PEI_SERVICES
**PeiServices
,
716 IN EFI_FFS_FILE_HEADER
*FileHeader
,
717 IN BOOLEAN EntryExit
,
724 Log a timestamp count.
728 PeiServices - Pointer to the PEI Core Services table
730 Token - Pointer to Token Name
732 FileHeader - Pointer to the file header
734 EntryExit - Indicates start or stop measurement
736 Value - The start time or the stop time
745 OUT UINT64
*TimerValue
755 TimerValue - Pointer to the returned timer value
759 EFI_SUCCESS - Successfully got timer value
764 #ifdef EFI_PEI_PERFORMANCE
765 #define PEI_PERF_START(Ps, Token, FileHeader, Value) PeiPerfMeasure (Ps, Token, FileHeader, FALSE, Value)
766 #define PEI_PERF_END(Ps, Token, FileHeader, Value) PeiPerfMeasure (Ps, Token, FileHeader, TRUE, Value)
768 #define PEI_PERF_START(Ps, Token, FileHeader, Value)
769 #define PEI_PERF_END(Ps, Token, FileHeader, Value)
772 #ifdef EFI_NT_EMULATOR
774 PeCoffLoaderWinNtLoadAsDll (
775 IN CHAR8
*PdbFileName
,
776 IN VOID
**ImageEntryPoint
,
783 Loads the .DLL file is present when a PE/COFF file is loaded. This provides source level
784 debugging for drivers that have cooresponding .DLL files on the local system.
788 PdbFileName - The name of the .PDB file. This was found from the PE/COFF
789 file's debug directory entry.
791 ImageEntryPoint - A pointer to the DLL entry point of the .DLL file was loaded.
793 ModHandle - Pointer to loaded library.
797 EFI_SUCCESS - The .DLL file was loaded, and the DLL entry point is returned in ImageEntryPoint
799 EFI_NOT_FOUND - The .DLL file could not be found
801 EFI_UNSUPPORTED - The .DLL file was loaded, but the entry point to the .DLL file could not
813 IN EFI_PEI_SERVICES
**PeiServices
,
814 IN EFI_GUID
*ModuleName
,
815 IN EFI_PHYSICAL_ADDRESS Module
,
816 IN UINT64 ModuleLength
,
817 IN EFI_PHYSICAL_ADDRESS EntryPoint
823 Builds a HOB for a loaded PE32 module
827 PeiServices - The PEI core services table.
828 ModuleName - The GUID File Name of the module
829 Memory - The 64 bit physical address of the module
830 ModuleLength - The length of the module in bytes
831 EntryPoint - The 64 bit physical address of the entry point
836 EFI_SUCCESS - Hob is successfully built.
837 Others - Errors occur while creating new Hob
843 PeiBuildHobResourceDescriptor (
844 IN EFI_PEI_SERVICES
**PeiServices
,
845 IN EFI_RESOURCE_TYPE ResourceType
,
846 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
847 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
848 IN UINT64 NumberOfBytes
854 Builds a HOB that describes a chunck of system memory
858 PeiServices - The PEI core services table.
860 ResourceType - The type of resource described by this HOB
862 ResourceAttribute - The resource attributes of the memory described by this HOB
864 PhysicalStart - The 64 bit physical address of memory described by this HOB
866 NumberOfBytes - The length of the memoty described by this HOB in bytes
870 EFI_SUCCESS - Hob is successfully built.
871 Others - Errors occur while creating new Hob
878 IN EFI_PEI_SERVICES
**PeiServices
,
887 Builds a custom HOB that is tagged with a GUID for identification
891 PeiServices - The PEI core services table.
893 Guid - The GUID of the custome HOB type
895 DataLength - The size of the data payload for the GUIDed HOB
897 Hob - Pointer to the Hob
901 EFI_SUCCESS - Hob is successfully built.
902 Others - Errors occur while creating new Hob
908 PeiBuildHobGuidData (
909 IN EFI_PEI_SERVICES
**PeiServices
,
918 Builds a custom HOB that is tagged with a GUID for identification
922 PeiServices - The PEI core services table.
924 Guid - The GUID of the custome HOB type
926 Data - The data to be copied into the GUIDed HOB data field.
928 DataLength - The data field length.
932 EFI_SUCCESS - Hob is successfully built.
933 Others - Errors occur while creating new Hob
940 IN EFI_PEI_SERVICES
**PeiServices
,
941 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
948 Builds a Firmware Volume HOB
952 PeiServices - The PEI core services table.
954 BaseAddress - The base address of the Firmware Volume
956 Length - The size of the Firmware Volume in bytes
960 EFI_SUCCESS - Hob is successfully built.
961 Others - Errors occur while creating new Hob
968 IN EFI_PEI_SERVICES
**PeiServices
,
969 IN UINT8 SizeOfMemorySpace
,
970 IN UINT8 SizeOfIoSpace
976 Builds a HOB for the CPU
980 PeiServices - The PEI core services table.
982 SizeOfMemorySpace - Identifies the maximum
983 physical memory addressibility of the processor.
985 SizeOfIoSpace - Identifies the maximum physical I/O addressibility
990 EFI_SUCCESS - Hob is successfully built.
991 Others - Errors occur while creating new Hob
998 IN EFI_PEI_SERVICES
**PeiServices
,
999 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
1004 Routine Description:
1006 Builds a HOB for the Stack
1010 PeiServices - The PEI core services table.
1012 BaseAddress - The 64 bit physical address of the Stack
1014 Length - The length of the stack in bytes
1018 EFI_SUCCESS - Hob is successfully built.
1019 Others - Errors occur while creating new Hob
1025 PeiBuildHobBspStore (
1026 IN EFI_PEI_SERVICES
**PeiServices
,
1027 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
1029 IN EFI_MEMORY_TYPE MemoryType
1033 Routine Description:
1035 Builds a HOB for the bsp store
1039 PeiServices - The PEI core services table.
1041 BaseAddress - The 64 bit physical address of the bsp store
1043 Length - The length of the bsp store in bytes
1045 MemoryType - Memory type
1049 EFI_SUCCESS - Hob is successfully built.
1050 Others - Errors occur while creating new Hob
1056 PeiBuildHobMemoryAllocation (
1057 IN EFI_PEI_SERVICES
**PeiServices
,
1058 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
1061 IN EFI_MEMORY_TYPE MemoryType
1065 Routine Description:
1067 Builds a HOB for the memory allocation
1071 PeiServices - The PEI core services table.
1073 BaseAddress - The 64 bit physical address of the memory
1075 Length - The length of the memory allocation in bytes
1079 MemoryType - Memory type
1083 EFI_SUCCESS - Hob is successfully built.
1084 Others - Errors occur while creating new Hob
1094 OUT CHAR8
*StartOfBuffer
,
1096 IN CONST CHAR8
*Format
,
1101 Routine Description:
1103 AvSPrint function to process format and place the results in Buffer. Since a
1104 VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
1105 this is the main print working routine
1109 StartOfBuffer - Ascii buffer to print the results of the parsing of Format into.
1111 StrSize - Maximum number of characters to put into buffer. Zero means
1114 FormatString - Ascii format string see file header for more details.
1116 Marker - Vararg list consumed by processing Format.
1120 Number of characters printed.
1128 IN UINTN BufferSize
,
1129 IN CONST CHAR8
*Format
,
1134 Routine Description:
1136 ASPrint function to process format and place the results in Buffer.
1140 Buffer - Ascii buffer to print the results of the parsing of Format into.
1142 BufferSize - Maximum number of characters to put into buffer. Zero means no
1145 Format - Ascii format string see file header for more details.
1147 ... - Vararg list consumed by processing Format.
1151 Number of characters printed.
1161 IN UINT64 Multiplicand
,
1166 Routine Description:
1168 This routine allows a 64 bit value to be multiplied with a 32 bit
1169 value returns 64bit result.
1170 No checking if the result is greater than 64bits
1174 Multiplicand - multiplicand
1175 Multiplier - multiplier
1179 Multiplicand * Multiplier
1188 OUT UINTN
*Remainder OPTIONAL
1192 Routine Description:
1194 This routine allows a 64 bit value to be divided with a 32 bit value returns
1195 64bit result and the Remainder.
1196 N.B. only works for 31bit divisors!!
1202 Remainder - buffer for remainder
1207 Remainder = Dividend mod Divisor
1219 Routine Description:
1221 This routine allows a 64 bit value to be right shifted by 32 bits and returns the
1223 Count is valid up 63. (Only Bits 0-5 is valid for Count)
1227 Operand - Value to be shifted
1228 Count - Number of times to shift right.
1232 Value shifted right identified by the Count.
1244 Routine Description:
1246 This routine allows a 64 bit value to be left shifted by 32 bits and
1247 returns the shifted value.
1248 Count is valid up 63. (Only Bits 0-5 is valid for Count)
1252 Operand - Value to be shifted
1253 Count - Number of times to shift left.
1257 Value shifted left identified by the Count.
1263 RegisterNativeCpuIo (
1264 IN EFI_PEI_SERVICES
**PeiServices
,
1269 Routine Description:
1271 Register a native Cpu IO
1275 PeiServices - Calling context
1276 CpuIo - CpuIo instance to register
1287 IN EFI_PEI_SERVICES
**PeiServices
,
1292 Routine Description:
1294 Get registered Cpu IO.
1298 PeiServices - Calling context
1299 CpuIo - CpuIo instance registered before
1310 IN EFI_FIND_FV_PPI
*This
,
1311 IN EFI_PEI_SERVICES
**PeiServices
,
1312 IN OUT UINT8
*FvNumber
,
1313 IN OUT EFI_FIRMWARE_VOLUME_HEADER
**FVAddress
1317 Routine Description:
1323 This - Interface pointer that implement the Find Fv PPI
1325 PeiServices - Pointer to the PEI Service Table
1327 FvNumber - On input, the number of the fireware volume which supports FFS to locate
1328 On output, the next FV number which supports FFS.
1330 FVAddress - The address of the volume which supports FFS to discover
1334 EFI_SUCCESS - An addtional FV which supports FFS found
1335 EFI_OUT_OF_RESOURCES - There are no fireware volume which supports FFS for given fvnumber
1336 EFI_INVALID_PARAMETER - FvAddress is NULL