3 Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>
4 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)
34 #if defined(__GNUC__) && defined(ECP_CPU_IPF)
45 Generates a breakpoint on the CPU.
47 Generates a breakpoint on the CPU. The breakpoint must be implemented such
48 that code can resume normal execution after the breakpoint.
70 Used to serialize load and store operations.
72 All loads and stores that proceed calls to this function are guaranteed to be
73 globally visible when this function returns.
89 #if (PI_SPECIFICATION_VERSION >= 0x00010000)
92 UINT32 PeiServiceTable
;
107 Scans a target buffer for a GUID, and returns a pointer to the matching GUID
108 in the target buffer.
110 This function searches target the buffer specified by Buffer and Length from
111 the lowest address to the highest address at 128-bit increments for the 128-bit
112 GUID value that matches Guid. If a match is found, then a pointer to the matching
113 GUID in the target buffer is returned. If no match is found, then NULL is returned.
114 If Length is 0, then NULL is returned.
115 If Length > 0 and Buffer is NULL, then ASSERT().
116 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
117 If Length is not aligned on a 128-bit boundary, then ASSERT().
118 If Length is greater than (EFI_MAX_ADDRESS ?Buffer + 1), then ASSERT().
122 Buffer - Pointer to the target buffer to scan.
123 Length - Number of bytes in Buffer to scan.
124 Guid - Value to search for in the target buffer.
127 A pointer to the matching Guid in the target buffer or NULL otherwise.
134 InvalidateInstructionCacheRange (
142 Invalidates a range of instruction cache lines in the cache coherency domain
145 Invalidates the instruction cache lines specified by Address and Length. If
146 Address is not aligned on a cache line boundary, then entire instruction
147 cache line containing Address is invalidated. If Address + Length is not
148 aligned on a cache line boundary, then the entire instruction cache line
149 containing Address + Length -1 is invalidated. This function may choose to
150 invalidate the entire instruction cache if that is more efficient than
151 invalidating the specified range. If Length is 0, the no instruction cache
152 lines are invalidated. Address is returned.
154 If Length is greater than (EFI_MAX_ADDRESS - Address + 1), then ASSERT().
158 Address - The base address of the instruction cache lines to
159 invalidate. If the CPU is in a physical addressing mode, then
160 Address is a physical address. If the CPU is in a virtual
161 addressing mode, then Address is a virtual address.
163 Length - The number of bytes to invalidate from the instruction cache.
173 PeiLibFfsFindNextVolume (
175 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
181 The wrapper of Pei Core Service function FfsFindNextVolume.
185 Instance - The Fv Volume Instance.
186 VolumeHandle - Pointer to the current Fv Volume to search.
196 PeiLibFfsFindNextFile (
197 IN EFI_FV_FILETYPE SearchType
,
198 IN EFI_PEI_FV_HANDLE FwVolHeader
,
199 IN OUT EFI_PEI_FILE_HANDLE
*FileHeader
205 The wrapper of Pei Core Service function FfsFindNextFile.
209 SearchType - Filter to find only file of this type.
210 FwVolHeader - Pointer to the current FV to search.
211 FileHandle - Pointer to the file matching SearchType in FwVolHeader.
212 - NULL if file not found
222 PeiLibFfsFindFileByName (
223 IN EFI_GUID
*FileName
,
224 IN EFI_PEI_FV_HANDLE VolumeHandle
,
225 OUT EFI_PEI_FILE_HANDLE
*FileHandle
231 The wrapper of Pei Core Service function FfsFindFileByName.
235 FileName - File name to search.
236 VolumeHandle - The current FV to search.
237 FileHandle - Pointer to the file matching name in VolumeHandle.
238 - NULL if file not found
248 PeiLibFfsFindSectionData (
249 IN EFI_SECTION_TYPE SectionType
,
250 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
251 IN OUT VOID
**SectionData
257 The wrapper of Pei Core Service function FfsFindSectionData.
261 SearchType - Filter to find only sections of this type.
262 FileHandle - Pointer to the current file to search.
263 SectionData - Pointer to the Section matching SectionType in FfsFileHeader.
264 - NULL if section not found
273 PeiLibFfsGetVolumeInfo (
274 IN EFI_PEI_FV_HANDLE
*VolumeHandle
,
275 OUT EFI_FV_INFO
*VolumeInfo
281 The wrapper of Pei Core Service function FfsGetVolumeInfo.
285 VolumeHandle - The handle to Fv Volume.
286 VolumeInfo - The pointer to volume information.
295 PeiServicesLocatePpi (
298 IN OUT EFI_PEI_PPI_DESCRIPTOR
**PpiDescriptor
,
305 The wrapper of Pei Core Service function LocatePpi.
309 Guid - Pointer to GUID of the PPI.
310 Instance - Instance Number to discover.
311 PpiDescriptor - Pointer to reference the found descriptor. If not NULL,
312 returns a pointer to the descriptor (includes flags, etc)
313 Ppi - Pointer to reference the found PPI
317 Status - EFI_SUCCESS if the PPI is in the database
318 EFI_NOT_FOUND if the PPI is not in the database
325 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
336 BaseAddress - Fv base address.
348 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
350 IN EFI_GUID
*FvNameGuid
,
351 IN EFI_GUID
*FileNameGuid
361 BaseAddress - Fv base address.
363 FvNameGuid - Fv name.
364 FileNameGuid - File name which contians encapsulated Fv.
387 Guid - guid to build data hob.
388 Data - data to build data hob.
389 DataLength - the length of data.
410 Pages - Pages to allocate.
413 Address if successful to allocate memory.
414 NULL if fail to allocate memory.
420 SetPeiServicesTablePointer (
421 IN EFI_PEI_SERVICES
**PeiServices
427 Save PeiService pointer so that it can be retrieved anywhere.
431 PeiServices - The direct pointer to PeiServiceTable.
440 GetPeiServicesTablePointer (
447 Get PeiService pointer.
454 The direct pointer to PeiServiceTable.
461 IN EFI_PEI_SERVICES
**PeiServices
467 Migrate IDT from temporary memory to real memory where preceded with 4 bytes for
468 storing PeiService pointer.
472 PeiServices - The direct pointer to PeiServiceTable.
490 Read IDT Register BaseAddress.
497 IDT Register BaseAddress.
511 Read IDT Register Limit.
533 Set IDT Register BaseAddress.
537 IdtBase - IDT.BaseAddress
553 Write 64 bit into Kernel Register7 on IPF.
557 Address - Data to write into kr7.
574 Read 64 bit from Kernel Register7 on IPF.
590 IN VOID
*Destination
,
598 Copy Length bytes from Source to Destination.
602 Destination - Target of copy
604 Source - Place to copy from
606 Length - Number of bytes to copy
624 Set Buffer to zero for Size bytes.
628 Buffer - Memory to set.
630 Size - Number of bytes to set
641 IN VOID
*Destination
,
649 Copy Length bytes from Source to Destination.
653 Destination - Target of copy
655 Source - Place to copy from
657 Length - Number of bytes to copy
679 Guid1 - guid to compare
680 Guid2 - guid to compare
683 = TRUE if Guid1 == Guid2
684 = FALSE if Guid1 != Guid2
690 InstallEfiPeiPeCoffLoader (
691 IN EFI_PEI_SERVICES
**PeiServices
,
692 IN EFI_PEI_PE_COFF_LOADER_PROTOCOL
**This
,
693 IN EFI_PEI_PPI_DESCRIPTOR
*ThisPpi
699 Install EFI Pei PE coff loader protocol.
703 PeiServices - The PEI core services table.
705 This - Pointer to get Pei PE coff loader protocol as output
707 ThisPpi - Passed in as EFI_NT_LOAD_AS_DLL_PPI on NT_EMULATOR platform
717 InstallEfiPeiPeCoffLoader64 (
718 IN EFI_PEI_SERVICES
**PeiServices
,
719 IN OUT EFI_PEI_PE_COFF_LOADER_PROTOCOL
**This
,
720 IN EFI_PEI_PPI_DESCRIPTOR
*ThisPpi
726 InstallEfiDecompress (
727 EFI_DECOMPRESS_PROTOCOL
**This
733 Install EFI decompress protocol.
737 This - Pointer to get decompress protocol as output
741 EFI_SUCCESS - EFI decompress protocol successfully installed.
747 InstallTianoDecompress (
748 EFI_TIANO_DECOMPRESS_PROTOCOL
**This
754 Install Tiano decompress protocol.
758 This - Pointer to get decompress protocol as output
762 EFI_SUCCESS - Tiano decompress protocol successfully installed.
769 OUT UINT64
*TimerValue
779 TimerValue - Pointer to the returned timer value
783 EFI_SUCCESS - Successfully got timer value
788 #ifdef EFI_NT_EMULATOR
790 PeCoffLoaderWinNtLoadAsDll (
791 IN CHAR8
*PdbFileName
,
792 IN VOID
**ImageEntryPoint
,
799 Loads the .DLL file is present when a PE/COFF file is loaded. This provides source level
800 debugging for drivers that have cooresponding .DLL files on the local system.
804 PdbFileName - The name of the .PDB file. This was found from the PE/COFF
805 file's debug directory entry.
807 ImageEntryPoint - A pointer to the DLL entry point of the .DLL file was loaded.
809 ModHandle - Pointer to loaded library.
813 EFI_SUCCESS - The .DLL file was loaded, and the DLL entry point is returned in ImageEntryPoint
815 EFI_NOT_FOUND - The .DLL file could not be found
817 EFI_UNSUPPORTED - The .DLL file was loaded, but the entry point to the .DLL file could not
829 IN EFI_PEI_SERVICES
**PeiServices
,
830 IN EFI_GUID
*ModuleName
,
831 IN EFI_PHYSICAL_ADDRESS Module
,
832 IN UINT64 ModuleLength
,
833 IN EFI_PHYSICAL_ADDRESS EntryPoint
839 Builds a HOB for a loaded PE32 module
843 PeiServices - The PEI core services table.
844 ModuleName - The GUID File Name of the module
845 Memory - The 64 bit physical address of the module
846 ModuleLength - The length of the module in bytes
847 EntryPoint - The 64 bit physical address of the entry point
852 EFI_SUCCESS - Hob is successfully built.
853 Others - Errors occur while creating new Hob
859 PeiBuildHobResourceDescriptor (
860 IN EFI_PEI_SERVICES
**PeiServices
,
861 IN EFI_RESOURCE_TYPE ResourceType
,
862 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
863 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
864 IN UINT64 NumberOfBytes
870 Builds a HOB that describes a chunck of system memory
874 PeiServices - The PEI core services table.
876 ResourceType - The type of resource described by this HOB
878 ResourceAttribute - The resource attributes of the memory described by this HOB
880 PhysicalStart - The 64 bit physical address of memory described by this HOB
882 NumberOfBytes - The length of the memoty described by this HOB in bytes
886 EFI_SUCCESS - Hob is successfully built.
887 Others - Errors occur while creating new Hob
894 IN EFI_PEI_SERVICES
**PeiServices
,
903 Builds a custom HOB that is tagged with a GUID for identification
907 PeiServices - The PEI core services table.
909 Guid - The GUID of the custome HOB type
911 DataLength - The size of the data payload for the GUIDed HOB
913 Hob - Pointer to the Hob
917 EFI_SUCCESS - Hob is successfully built.
918 Others - Errors occur while creating new Hob
924 PeiBuildHobGuidData (
925 IN EFI_PEI_SERVICES
**PeiServices
,
934 Builds a custom HOB that is tagged with a GUID for identification
938 PeiServices - The PEI core services table.
940 Guid - The GUID of the custome HOB type
942 Data - The data to be copied into the GUIDed HOB data field.
944 DataLength - The data field length.
948 EFI_SUCCESS - Hob is successfully built.
949 Others - Errors occur while creating new Hob
956 IN EFI_PEI_SERVICES
**PeiServices
,
957 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
964 Builds a Firmware Volume HOB
968 PeiServices - The PEI core services table.
970 BaseAddress - The base address of the Firmware Volume
972 Length - The size of the Firmware Volume in bytes
976 EFI_SUCCESS - Hob is successfully built.
977 Others - Errors occur while creating new Hob
984 IN EFI_PEI_SERVICES
**PeiServices
,
985 IN UINT8 SizeOfMemorySpace
,
986 IN UINT8 SizeOfIoSpace
992 Builds a HOB for the CPU
996 PeiServices - The PEI core services table.
998 SizeOfMemorySpace - Identifies the maximum
999 physical memory addressibility of the processor.
1001 SizeOfIoSpace - Identifies the maximum physical I/O addressibility
1006 EFI_SUCCESS - Hob is successfully built.
1007 Others - Errors occur while creating new Hob
1014 IN EFI_PEI_SERVICES
**PeiServices
,
1015 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
1020 Routine Description:
1022 Builds a HOB for the Stack
1026 PeiServices - The PEI core services table.
1028 BaseAddress - The 64 bit physical address of the Stack
1030 Length - The length of the stack in bytes
1034 EFI_SUCCESS - Hob is successfully built.
1035 Others - Errors occur while creating new Hob
1041 PeiBuildHobBspStore (
1042 IN EFI_PEI_SERVICES
**PeiServices
,
1043 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
1045 IN EFI_MEMORY_TYPE MemoryType
1049 Routine Description:
1051 Builds a HOB for the bsp store
1055 PeiServices - The PEI core services table.
1057 BaseAddress - The 64 bit physical address of the bsp store
1059 Length - The length of the bsp store in bytes
1061 MemoryType - Memory type
1065 EFI_SUCCESS - Hob is successfully built.
1066 Others - Errors occur while creating new Hob
1072 PeiBuildHobMemoryAllocation (
1073 IN EFI_PEI_SERVICES
**PeiServices
,
1074 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
1077 IN EFI_MEMORY_TYPE MemoryType
1081 Routine Description:
1083 Builds a HOB for the memory allocation
1087 PeiServices - The PEI core services table.
1089 BaseAddress - The 64 bit physical address of the memory
1091 Length - The length of the memory allocation in bytes
1095 MemoryType - Memory type
1099 EFI_SUCCESS - Hob is successfully built.
1100 Others - Errors occur while creating new Hob
1110 OUT CHAR8
*StartOfBuffer
,
1112 IN CONST CHAR8
*Format
,
1117 Routine Description:
1119 AvSPrint function to process format and place the results in Buffer. Since a
1120 VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
1121 this is the main print working routine
1125 StartOfBuffer - Ascii buffer to print the results of the parsing of Format into.
1127 StrSize - Maximum number of characters to put into buffer. Zero means
1130 FormatString - Ascii format string see file header for more details.
1132 Marker - Vararg list consumed by processing Format.
1136 Number of characters printed.
1144 IN UINTN BufferSize
,
1145 IN CONST CHAR8
*Format
,
1150 Routine Description:
1152 ASPrint function to process format and place the results in Buffer.
1156 Buffer - Ascii buffer to print the results of the parsing of Format into.
1158 BufferSize - Maximum number of characters to put into buffer. Zero means no
1161 Format - Ascii format string see file header for more details.
1163 ... - Vararg list consumed by processing Format.
1167 Number of characters printed.
1177 IN UINT64 Multiplicand
,
1182 Routine Description:
1184 This routine allows a 64 bit value to be multiplied with a 32 bit
1185 value returns 64bit result.
1186 No checking if the result is greater than 64bits
1190 Multiplicand - multiplicand
1191 Multiplier - multiplier
1195 Multiplicand * Multiplier
1204 OUT UINTN
*Remainder OPTIONAL
1208 Routine Description:
1210 This routine allows a 64 bit value to be divided with a 32 bit value returns
1211 64bit result and the Remainder.
1212 N.B. only works for 31bit divisors!!
1218 Remainder - buffer for remainder
1223 Remainder = Dividend mod Divisor
1235 Routine Description:
1237 This routine allows a 64 bit value to be right shifted by 32 bits and returns the
1239 Count is valid up 63. (Only Bits 0-5 is valid for Count)
1243 Operand - Value to be shifted
1244 Count - Number of times to shift right.
1248 Value shifted right identified by the Count.
1260 Routine Description:
1262 This routine allows a 64 bit value to be left shifted by 32 bits and
1263 returns the shifted value.
1264 Count is valid up 63. (Only Bits 0-5 is valid for Count)
1268 Operand - Value to be shifted
1269 Count - Number of times to shift left.
1273 Value shifted left identified by the Count.
1279 RegisterNativeCpuIo (
1280 IN EFI_PEI_SERVICES
**PeiServices
,
1285 Routine Description:
1287 Register a native Cpu IO
1291 PeiServices - Calling context
1292 CpuIo - CpuIo instance to register
1303 IN EFI_PEI_SERVICES
**PeiServices
,
1308 Routine Description:
1310 Get registered Cpu IO.
1314 PeiServices - Calling context
1315 CpuIo - CpuIo instance registered before
1327 IN EFI_FIND_FV_PPI
*This
,
1328 IN EFI_PEI_SERVICES
**PeiServices
,
1329 IN OUT UINT8
*FvNumber
,
1330 IN OUT EFI_FIRMWARE_VOLUME_HEADER
**FVAddress
1334 Routine Description:
1340 This - Interface pointer that implement the Find Fv PPI
1342 PeiServices - Pointer to the PEI Service Table
1344 FvNumber - On input, the number of the fireware volume which supports FFS to locate
1345 On output, the next FV number which supports FFS.
1347 FVAddress - The address of the volume which supports FFS to discover
1351 EFI_SUCCESS - An addtional FV which supports FFS found
1352 EFI_OUT_OF_RESOURCES - There are no fireware volume which supports FFS for given fvnumber
1353 EFI_INVALID_PARAMETER - FvAddress is NULL
1362 PeiLibPciCfgModify (
1363 IN EFI_PEI_SERVICES
**PeiServices
,
1364 IN PEI_PCI_CFG_PPI
*PciCfg
,
1365 IN PEI_PCI_CFG_PPI_WIDTH Width
,
1372 Routine Description:
1374 PCI read-modify-write operations.
1376 PIWG's PI specification replaces Inte's EFI Specification 1.10.
1377 EFI_PEI_PCI_CFG_PPI defined in Inte's EFI Specification 1.10 is replaced by
1378 EFI_PEI_PCI_CFG2_PPI in PI 1.0. "Modify" function in these two PPI are not
1379 compatibile with each other.
1382 For Framework code that make the following call:
1392 it will be updated to the following code which call this library API:
1393 PeiLibPciCfgModify (
1406 PeiServices An indirect pointer to the PEI Services Table
1407 published by the PEI Foundation.
1408 PciCfg A pointer to the this pointer of EFI_PEI_PCI_CFG_PPI.
1409 This parameter is unused as a place holder to make
1410 the parameter list identical to PEI_PCI_CFG_PPI_RW.
1411 Width The width of the access. Enumerated in bytes. Type
1412 EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().
1414 Address The physical address of the access.
1416 SetBits Points to value to bitwise-OR with the read configuration value.
1418 The size of the value is determined by Width.
1420 ClearBits Points to the value to negate and bitwise-AND with the read configuration value.
1421 The size of the value is determined by Width.
1426 EFI_SUCCESS The function completed successfully.
1428 EFI_DEVICE_ERROR There was a problem with the transaction.