3 Copyright (c) 2004 - 2010, 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.
22 #include "TianoCommon.h"
26 #include "EfiCommonLib.h"
44 Set Buffer to zero for Size bytes.
48 Buffer - Memory to set.
50 Size - Number of bytes to set
58 EfiCommonLibZeroMem (Buffer
, Size
);
71 Copy Length bytes from Source to Destination.
75 Destination - Target of copy
77 Source - Place to copy from
79 Length - Number of bytes to copy
87 EfiCommonLibCopyMem (Destination
, Source
, Length
);
100 Copy Length bytes from Source to Destination.
104 Destination - Target of copy
106 Source - Place to copy from
108 Length - Number of bytes to copy
116 EfiCommonLibCopyMem (Destination
, Source
, Length
);
133 Guid1 - guid to compare
134 Guid2 - guid to compare
137 = TRUE if Guid1 == Guid2
138 = FALSE if Guid1 != Guid2
142 if ((((INT32
*) Guid1
)[0] - ((INT32
*) Guid2
)[0]) == 0) {
143 if ((((INT32
*) Guid1
)[1] - ((INT32
*) Guid2
)[1]) == 0) {
144 if ((((INT32
*) Guid1
)[2] - ((INT32
*) Guid2
)[2]) == 0) {
145 if ((((INT32
*) Guid1
)[3] - ((INT32
*) Guid2
)[3]) == 0) {
159 IN EFI_PEI_SERVICES
**PeiServices
,
160 IN PEI_PCI_CFG_PPI
*PciCfg
,
161 IN PEI_PCI_CFG_PPI_WIDTH Width
,
170 PCI read-modify-write operations.
172 PIWG's PI specification replaces Inte's EFI Specification 1.10.
173 EFI_PEI_PCI_CFG_PPI defined in Inte's EFI Specification 1.10 is replaced by
174 EFI_PEI_PCI_CFG2_PPI in PI 1.0. "Modify" function in these two PPI are not
175 compatibile with each other.
178 For Framework code that make the following call:
188 it will be updated to the following code which call this library API:
202 PeiServices An indirect pointer to the PEI Services Table
203 published by the PEI Foundation.
204 PciCfg A pointer to the this pointer of EFI_PEI_PCI_CFG_PPI.
205 This parameter is unused as a place holder to make
206 the parameter list identical to PEI_PCI_CFG_PPI_RW.
207 Width The width of the access. Enumerated in bytes. Type
208 EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().
210 Address The physical address of the access.
212 SetBits Points to value to bitwise-OR with the read configuration value.
214 The size of the value is determined by Width.
216 ClearBits Points to the value to negate and bitwise-AND with the read configuration value.
217 The size of the value is determined by Width.
222 EFI_SUCCESS The function completed successfully.
224 EFI_DEVICE_ERROR There was a problem with the transaction.
229 EFI_PEI_PCI_CFG2_PPI
*PciCfg2
;
231 Status
= (*PeiServices
)->LocatePpi (
238 ASSERT_PEI_ERROR ((CONST EFI_PEI_SERVICES
**) PeiServices
, Status
);
240 Status
= PciCfg2
->Modify (
241 (CONST EFI_PEI_SERVICES
**) PeiServices
,
243 (EFI_PEI_PCI_CFG_PPI_WIDTH
) Width
,
253 #if (PI_SPECIFICATION_VERSION >= 0x00010000)
266 Scans a target buffer for a GUID, and returns a pointer to the matching GUID
267 in the target buffer.
269 This function searches target the buffer specified by Buffer and Length from
270 the lowest address to the highest address at 128-bit increments for the 128-bit
271 GUID value that matches Guid. If a match is found, then a pointer to the matching
272 GUID in the target buffer is returned. If no match is found, then NULL is returned.
273 If Length is 0, then NULL is returned.
274 If Length > 0 and Buffer is NULL, then ASSERT().
275 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
276 If Length is not aligned on a 128-bit boundary, then ASSERT().
277 If Length is greater than (EFI_MAX_ADDRESS ?Buffer + 1), then ASSERT().
281 Buffer - Pointer to the target buffer to scan.
282 Length - Number of bytes in Buffer to scan.
283 Guid - Value to search for in the target buffer.
286 A pointer to the matching Guid in the target buffer or NULL otherwise.
291 EFI_PEI_SERVICES
**PeiServices
;
293 PeiServices
= GetPeiServicesTablePointer();
294 PEI_ASSERT(PeiServices
, (((UINTN
)Buffer
& (sizeof (Guid
->Data1
) - 1)) == 0));
295 PEI_ASSERT(PeiServices
, (Length
<= (EFI_MAX_ADDRESS
- (UINTN
)Buffer
+ 1)));
296 PEI_ASSERT(PeiServices
, ((Length
& (sizeof (*GuidPtr
) - 1)) == 0));
298 GuidPtr
= (EFI_GUID
*)Buffer
;
299 Buffer
= GuidPtr
+ Length
/ sizeof (*GuidPtr
);
300 while (GuidPtr
< (EFI_GUID
*)Buffer
) {
301 if (CompareGuid (GuidPtr
, Guid
)) {
302 return (VOID
*)GuidPtr
;
312 InvalidateInstructionCacheRange (
320 Invalidates a range of instruction cache lines in the cache coherency domain
323 Invalidates the instruction cache lines specified by Address and Length. If
324 Address is not aligned on a cache line boundary, then entire instruction
325 cache line containing Address is invalidated. If Address + Length is not
326 aligned on a cache line boundary, then the entire instruction cache line
327 containing Address + Length -1 is invalidated. This function may choose to
328 invalidate the entire instruction cache if that is more efficient than
329 invalidating the specified range. If Length is 0, the no instruction cache
330 lines are invalidated. Address is returned.
332 If Length is greater than (EFI_MAX_ADDRESS - Address + 1), then ASSERT().
336 Address - The base address of the instruction cache lines to
337 invalidate. If the CPU is in a physical addressing mode, then
338 Address is a physical address. If the CPU is in a virtual
339 addressing mode, then Address is a virtual address.
341 Length - The number of bytes to invalidate from the instruction cache.
348 PEI_ASSERT(GetPeiServicesTablePointer() , (Length
<= EFI_MAX_ADDRESS
- (UINTN
)Address
+ 1));
355 PeiLibFfsFindNextVolume (
357 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
363 The wrapper of Pei Core Service function FfsFindNextVolume.
367 Instance - The Fv Volume Instance.
368 VolumeHandle - Pointer to the current Fv Volume to search.
376 EFI_PEI_SERVICES
**PeiServices
;
378 PeiServices
= GetPeiServicesTablePointer();
379 return (*PeiServices
)->FfsFindNextVolume (PeiServices
, Instance
, VolumeHandle
);
384 PeiLibFfsFindNextFile (
385 IN EFI_FV_FILETYPE SearchType
,
386 IN EFI_PEI_FV_HANDLE FvHandle
,
387 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
393 The wrapper of Pei Core Service function FfsFindNextFile.
397 SearchType - Filter to find only file of this type.
398 FvHandle - Pointer to the current FV to search.
399 FileHandle - Pointer to the file matching SearchType in FwVolHeader.
400 - NULL if file not found
407 EFI_PEI_SERVICES
**PeiServices
;
409 PeiServices
= GetPeiServicesTablePointer();
410 return (*PeiServices
)->FfsFindNextFile (PeiServices
, SearchType
, FvHandle
, FileHandle
);
416 PeiLibFfsFindFileByName (
417 IN EFI_GUID
*FileName
,
418 IN EFI_PEI_FV_HANDLE VolumeHandle
,
419 OUT EFI_PEI_FILE_HANDLE
*FileHandle
425 The wrapper of Pei Core Service function FfsFindFileByName.
429 FileName - File name to search.
430 VolumeHandle - The current FV to search.
431 FileHandle - Pointer to the file matching name in VolumeHandle.
432 - NULL if file not found
439 EFI_PEI_SERVICES
**PeiServices
;
441 PeiServices
= GetPeiServicesTablePointer();
442 return (*PeiServices
)->FfsFindFileByName (FileName
, VolumeHandle
, FileHandle
);
449 PeiLibFfsFindSectionData (
450 IN EFI_SECTION_TYPE SectionType
,
451 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
452 IN OUT VOID
**SectionData
458 The wrapper of Pei Core Service function FfsFindSectionData.
462 SearchType - Filter to find only sections of this type.
463 FileHandle - Pointer to the current file to search.
464 SectionData - Pointer to the Section matching SectionType in FfsFileHeader.
465 - NULL if section not found
471 EFI_PEI_SERVICES
**PeiServices
;
473 PeiServices
= GetPeiServicesTablePointer();
474 return (*PeiServices
)->FfsFindSectionData (PeiServices
, SectionType
, (EFI_PEI_FILE_HANDLE
)FfsFileHeader
, SectionData
);
479 PeiLibFfsGetVolumeInfo (
480 IN EFI_PEI_FV_HANDLE VolumeHandle
,
481 OUT EFI_FV_INFO
*VolumeInfo
487 The wrapper of Pei Core Service function FfsGetVolumeInfo.
491 VolumeHandle - The handle to Fv Volume.
492 VolumeInfo - The pointer to volume information.
498 EFI_PEI_SERVICES
**PeiServices
;
500 PeiServices
= GetPeiServicesTablePointer();
501 return (*PeiServices
)->FfsGetVolumeInfo (VolumeHandle
, VolumeInfo
);
509 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
520 BaseAddress - Fv base address.
529 EFI_HOB_FIRMWARE_VOLUME
*Hob
;
530 EFI_PEI_SERVICES
**PeiServices
;
532 PeiServices
= GetPeiServicesTablePointer();
535 // Check FV Signature
537 PEI_ASSERT (PeiServices
, ((EFI_FIRMWARE_VOLUME_HEADER
*)((UINTN
)BaseAddress
))->Signature
== EFI_FVH_SIGNATURE
);
540 Status
= (*PeiServices
)->CreateHob (
543 sizeof (EFI_HOB_FIRMWARE_VOLUME
),
546 Hob
->BaseAddress
= BaseAddress
;
547 Hob
->Length
= Length
;
553 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
555 IN EFI_GUID
*FvNameGuid
,
556 IN EFI_GUID
*FileNameGuid
566 BaseAddress - Fv base address.
568 FvNameGuid - Fv name.
569 FileNameGuid - File name which contians encapsulated Fv.
577 EFI_HOB_FIRMWARE_VOLUME2
*Hob
;
578 EFI_PEI_SERVICES
**PeiServices
;
580 PeiServices
= GetPeiServicesTablePointer();
583 // Check FV Signature
585 PEI_ASSERT (PeiServices
, ((EFI_FIRMWARE_VOLUME_HEADER
*)((UINTN
)BaseAddress
))->Signature
== EFI_FVH_SIGNATURE
);
587 Status
= (*PeiServices
)->CreateHob (
590 sizeof (EFI_HOB_FIRMWARE_VOLUME2
),
593 Hob
->BaseAddress
= BaseAddress
;
594 Hob
->Length
= Length
;
595 CopyMem ((VOID
*)&Hob
->FvName
, FvNameGuid
, sizeof(EFI_GUID
));
596 CopyMem ((VOID
*)&Hob
->FileName
, FileNameGuid
, sizeof(EFI_GUID
));
601 PeiServicesLocatePpi (
604 IN OUT EFI_PEI_PPI_DESCRIPTOR
**PpiDescriptor
,
611 The wrapper of Pei Core Service function LocatePpi.
615 Guid - Pointer to GUID of the PPI.
616 Instance - Instance Number to discover.
617 PpiDescriptor - Pointer to reference the found descriptor. If not NULL,
618 returns a pointer to the descriptor (includes flags, etc)
619 Ppi - Pointer to reference the found PPI
623 Status - EFI_SUCCESS if the PPI is in the database
624 EFI_NOT_FOUND if the PPI is not in the database
627 EFI_PEI_SERVICES
**PeiServices
;
629 PeiServices
= GetPeiServicesTablePointer();
630 return (*PeiServices
)->LocatePpi (PeiServices
, Guid
, Instance
, PpiDescriptor
, Ppi
);
649 Guid - guid to build data hob.
650 Data - data to build data hob.
651 DataLength - the length of data.
658 EFI_HOB_GUID_TYPE
*Hob
;
659 EFI_PEI_SERVICES
**PeiServices
;
661 PeiServices
= GetPeiServicesTablePointer();
662 (*PeiServices
)->CreateHob (
664 EFI_HOB_TYPE_GUID_EXTENSION
,
665 (UINT16
) (sizeof (EFI_HOB_GUID_TYPE
) + DataLength
),
668 CopyMem ((VOID
*)&Hob
->Name
, (VOID
*)Guid
, sizeof(EFI_GUID
));
672 CopyMem (HobData
, Data
, DataLength
);
689 Pages - Pages to allocate.
692 = Address if successful to allocate memory.
693 = NULL if fail to allocate memory.
698 EFI_PHYSICAL_ADDRESS Memory
;
699 EFI_PEI_SERVICES
**PeiServices
;
705 PeiServices
= GetPeiServicesTablePointer();
706 Status
= (*PeiServices
)->AllocatePages (PeiServices
, EfiBootServicesData
, Pages
, &Memory
);
707 if (EFI_ERROR (Status
)) {
710 return (VOID
*) (UINTN
) Memory
;