2 Implementation for PEI Services Library.
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/EmuMagicPageLib.h>
18 #include <Library/PeiServicesLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/BaseMemoryLib.h>
26 IN EFI_FV_FILETYPE SearchType
,
27 IN EFI_PEI_FV_HANDLE VolumeHandle
,
28 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
32 SecFfsFindSectionData (
33 IN EFI_SECTION_TYPE SectionType
,
34 IN EFI_PEI_FILE_HANDLE FileHandle
,
35 OUT VOID
**SectionData
40 This service enables a given PEIM to register an interface into the PEI Foundation.
42 @param PpiList A pointer to the list of interfaces that the caller shall install.
44 @retval EFI_SUCCESS The interface was successfully installed.
45 @retval EFI_INVALID_PARAMETER The PpiList pointer is NULL.
46 @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
47 EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
48 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
53 PeiServicesInstallPpi (
54 IN CONST EFI_PEI_PPI_DESCRIPTOR
*PpiList
58 return EFI_OUT_OF_RESOURCES
;
62 This service enables PEIMs to replace an entry in the PPI database with an alternate entry.
64 @param OldPpi The pointer to the old PEI PPI Descriptors.
65 @param NewPpi The pointer to the new PEI PPI Descriptors.
67 @retval EFI_SUCCESS The interface was successfully installed.
68 @retval EFI_INVALID_PARAMETER The OldPpi or NewPpi is NULL.
69 @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
70 EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
71 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
72 @retval EFI_NOT_FOUND The PPI for which the reinstallation was requested has not been
78 PeiServicesReInstallPpi (
79 IN CONST EFI_PEI_PPI_DESCRIPTOR
*OldPpi
,
80 IN CONST EFI_PEI_PPI_DESCRIPTOR
*NewPpi
84 return EFI_OUT_OF_RESOURCES
;
88 This service enables PEIMs to discover a given instance of an interface.
90 So this is, well a hack, so we can reuse the same libraries as the PEI Core
93 @param Guid A pointer to the GUID whose corresponding interface needs to be
95 @param Instance The N-th instance of the interface that is required.
96 @param PpiDescriptor A pointer to instance of the EFI_PEI_PPI_DESCRIPTOR.
97 @param Ppi A pointer to the instance of the interface.
99 @retval EFI_SUCCESS The interface was successfully returned.
100 @retval EFI_NOT_FOUND The PPI descriptor is not found in the database.
105 PeiServicesLocatePpi (
106 IN CONST EFI_GUID
*Guid
,
108 IN OUT EFI_PEI_PPI_DESCRIPTOR
**PpiDescriptor
,
112 EFI_PEI_PPI_DESCRIPTOR
*PpiList
;
115 return EFI_NOT_FOUND
;
118 for (PpiList
= EMU_MAGIC_PAGE()->PpiList
; ; PpiList
++) {
119 if (CompareGuid (PpiList
->Guid
, Guid
)) {
120 if (PpiDescriptor
!= NULL
) {
121 *PpiDescriptor
= PpiList
;
129 if ((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) == EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) {
135 return EFI_NOT_FOUND
;
139 This service enables PEIMs to register a given service to be invoked when another service is
140 installed or reinstalled.
142 @param NotifyList A pointer to the list of notification interfaces
143 that the caller shall install.
145 @retval EFI_SUCCESS The interface was successfully installed.
146 @retval EFI_INVALID_PARAMETER The NotifyList pointer is NULL.
147 @retval EFI_INVALID_PARAMETER Any of the PEI notify descriptors in the list do
148 not have the EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES
149 bit set in the Flags field.
150 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
155 PeiServicesNotifyPpi (
156 IN CONST EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyList
160 return EFI_OUT_OF_RESOURCES
;
164 This service enables PEIMs to ascertain the present value of the boot mode.
166 @param BootMode A pointer to contain the value of the boot mode.
168 @retval EFI_SUCCESS The boot mode was returned successfully.
169 @retval EFI_INVALID_PARAMETER BootMode is NULL.
174 PeiServicesGetBootMode (
175 OUT EFI_BOOT_MODE
*BootMode
179 return EFI_OUT_OF_RESOURCES
;
183 This service enables PEIMs to update the boot mode variable.
185 @param BootMode The value of the boot mode to set.
187 @retval EFI_SUCCESS The value was successfully updated
192 PeiServicesSetBootMode (
193 IN EFI_BOOT_MODE BootMode
197 return EFI_OUT_OF_RESOURCES
;
201 This service enables a PEIM to ascertain the address of the list of HOBs in memory.
203 @param HobList A pointer to the list of HOBs that the PEI Foundation
206 @retval EFI_SUCCESS The list was successfully returned.
207 @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.
212 PeiServicesGetHobList (
217 return EFI_OUT_OF_RESOURCES
;
221 This service enables PEIMs to create various types of HOBs.
223 @param Type The type of HOB to be installed.
224 @param Length The length of the HOB to be added.
225 @param Hob The address of a pointer that will contain the
228 @retval EFI_SUCCESS The HOB was successfully created.
229 @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
234 PeiServicesCreateHob (
241 return EFI_OUT_OF_RESOURCES
;
245 This service enables PEIMs to discover additional firmware volumes.
247 @param Instance This instance of the firmware volume to find. The
248 value 0 is the Boot Firmware Volume (BFV).
249 @param VolumeHandle Handle of the firmware volume header of the volume
252 @retval EFI_SUCCESS The volume was found.
253 @retval EFI_NOT_FOUND The volume was not found.
254 @retval EFI_INVALID_PARAMETER FwVolHeader is NULL.
259 PeiServicesFfsFindNextVolume (
261 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
265 return EFI_OUT_OF_RESOURCES
;
269 This service enables PEIMs to discover additional firmware files.
271 @param SearchType A filter to find files only of this type.
272 @param VolumeHandle The pointer to the firmware volume header of the
273 volume to search. This parameter must point to a
275 @param FileHandle Handle of the current file from which to begin searching.
277 @retval EFI_SUCCESS The file was found.
278 @retval EFI_NOT_FOUND The file was not found.
279 @retval EFI_NOT_FOUND The header checksum was not zero.
284 PeiServicesFfsFindNextFile (
285 IN EFI_FV_FILETYPE SearchType
,
286 IN EFI_PEI_FV_HANDLE VolumeHandle
,
287 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
290 return SecFfsFindNextFile (SearchType
, VolumeHandle
, FileHandle
);
294 This service enables PEIMs to discover sections of a given type within a valid FFS file.
296 @param SectionType The value of the section type to find.
297 @param FileHandle A pointer to the file header that contains the set
298 of sections to be searched.
299 @param SectionData A pointer to the discovered section, if successful.
301 @retval EFI_SUCCESS The section was found.
302 @retval EFI_NOT_FOUND The section was not found.
307 PeiServicesFfsFindSectionData (
308 IN EFI_SECTION_TYPE SectionType
,
309 IN EFI_PEI_FILE_HANDLE FileHandle
,
310 OUT VOID
**SectionData
313 return SecFfsFindSectionData (SectionType
, FileHandle
, SectionData
);
317 This service enables PEIMs to register the permanent memory configuration
318 that has been initialized with the PEI Foundation.
320 @param MemoryBegin The value of a region of installed memory.
321 @param MemoryLength The corresponding length of a region of installed memory.
323 @retval EFI_SUCCESS The region was successfully installed in a HOB.
324 @retval EFI_INVALID_PARAMETER MemoryBegin and MemoryLength are illegal for this system.
325 @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
330 PeiServicesInstallPeiMemory (
331 IN EFI_PHYSICAL_ADDRESS MemoryBegin
,
332 IN UINT64 MemoryLength
336 return EFI_OUT_OF_RESOURCES
;
340 This service enables PEIMs to allocate memory after the permanent memory has been
343 @param MemoryType Type of memory to allocate.
344 @param Pages The number of pages to allocate.
345 @param Memory Pointer of memory allocated.
347 @retval EFI_SUCCESS The memory range was successfully allocated.
348 @retval EFI_INVALID_PARAMETER Type is not equal to AllocateAnyPages.
349 @retval EFI_NOT_AVAILABLE_YET Called with permanent memory not available.
350 @retval EFI_OUT_OF_RESOURCES The pages could not be allocated.
355 PeiServicesAllocatePages (
356 IN EFI_MEMORY_TYPE MemoryType
,
358 OUT EFI_PHYSICAL_ADDRESS
*Memory
362 return EFI_OUT_OF_RESOURCES
;
366 This service allocates memory from the Hand-Off Block (HOB) heap.
368 @param Size The number of bytes to allocate from the pool.
369 @param Buffer If the call succeeds, a pointer to a pointer to
370 the allocate buffer; otherwise, undefined.
372 @retval EFI_SUCCESS The allocation was successful
373 @retval EFI_OUT_OF_RESOURCES There is not enough heap to allocate the requested size.
378 PeiServicesAllocatePool (
384 return EFI_OUT_OF_RESOURCES
;
388 Resets the entire platform.
390 @retval EFI_SUCCESS The function completed successfully.
391 @retval EFI_NOT_AVAILABLE_YET The service has not been installed yet.
396 PeiServicesResetSystem (
401 return EFI_OUT_OF_RESOURCES
;
405 This service is a wrapper for the PEI Service RegisterForShadow(), except the
406 pointer to the PEI Services Table has been removed. See the Platform
407 Initialization Pre-EFI Initialization Core Interface Specification for details.
409 @param FileHandle PEIM's file handle. Must be the currently
412 @retval EFI_SUCCESS The PEIM was successfully registered for
415 @retval EFI_ALREADY_STARTED The PEIM was previously
416 registered for shadowing.
418 @retval EFI_NOT_FOUND The FileHandle does not refer to a
423 PeiServicesRegisterForShadow (
424 IN EFI_PEI_FILE_HANDLE FileHandle
428 return EFI_OUT_OF_RESOURCES
;
432 This service is a wrapper for the PEI Service FfsGetFileInfo(), except the pointer to the PEI Services
433 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
434 Specification for details.
436 @param FileHandle The handle of the file.
438 @param FileInfo Upon exit, points to the file's
441 @retval EFI_SUCCESS File information returned.
443 @retval EFI_INVALID_PARAMETER If FileHandle does not
444 represent a valid file.
446 @retval EFI_INVALID_PARAMETER FileInfo is NULL.
451 PeiServicesFfsGetFileInfo (
452 IN CONST EFI_PEI_FILE_HANDLE FileHandle
,
453 OUT EFI_FV_FILE_INFO
*FileInfo
457 return EFI_OUT_OF_RESOURCES
;
462 This service is a wrapper for the PEI Service FfsFindByName(), except the pointer to the PEI Services
463 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
464 Specification for details.
466 @param FileName A pointer to the name of the file to
467 find within the firmware volume.
469 @param VolumeHandle The firmware volume to search FileHandle
470 Upon exit, points to the found file's
471 handle or NULL if it could not be found.
472 @param FileHandle The pointer to found file handle
474 @retval EFI_SUCCESS File was found.
476 @retval EFI_NOT_FOUND File was not found.
478 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or
484 PeiServicesFfsFindFileByName (
485 IN CONST EFI_GUID
*FileName
,
486 IN CONST EFI_PEI_FV_HANDLE VolumeHandle
,
487 OUT EFI_PEI_FILE_HANDLE
*FileHandle
491 return EFI_OUT_OF_RESOURCES
;
496 This service is a wrapper for the PEI Service FfsGetVolumeInfo(), except the pointer to the PEI Services
497 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
498 Specification for details.
500 @param VolumeHandle Handle of the volume.
502 @param VolumeInfo Upon exit, points to the volume's
505 @retval EFI_SUCCESS File information returned.
507 @retval EFI_INVALID_PARAMETER If FileHandle does not
508 represent a valid file.
510 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
515 PeiServicesFfsGetVolumeInfo (
516 IN EFI_PEI_FV_HANDLE VolumeHandle
,
517 OUT EFI_FV_INFO
*VolumeInfo
521 return EFI_OUT_OF_RESOURCES
;
525 Install a EFI_PEI_FIRMWARE_VOLUME_INFO_PPI instance so the PEI Core will be notified about a new firmware volume.
527 This function allocates, initializes, and installs a new EFI_PEI_FIRMWARE_VOLUME_INFO_PPI using
528 the parameters passed in to initialize the fields of the EFI_PEI_FIRMWARE_VOLUME_INFO_PPI instance.
529 If the resources can not be allocated for EFI_PEI_FIRMWARE_VOLUME_INFO_PPI, then ASSERT().
530 If the EFI_PEI_FIRMWARE_VOLUME_INFO_PPI can not be installed, then ASSERT().
533 @param FvFormat Unique identifier of the format of the memory-mapped
534 firmware volume. This parameter is optional and
535 may be NULL. If NULL is specified, the
536 EFI_FIRMWARE_FILE_SYSTEM2_GUID format is assumed.
537 @param FvInfo Points to a buffer which allows the
538 EFI_PEI_FIRMWARE_VOLUME_PPI to process the volume.
539 The format of this buffer is specific to the FvFormat.
540 For memory-mapped firmware volumes, this typically
541 points to the first byte of the firmware volume.
542 @param FvInfoSize The size, in bytes, of FvInfo. For memory-mapped
543 firmware volumes, this is typically the size of
545 @param ParentFvName If the new firmware volume originated from a file
546 in a different firmware volume, then this parameter
547 specifies the GUID name of the originating firmware
548 volume. Otherwise, this parameter must be NULL.
549 @param ParentFileName If the new firmware volume originated from a file
550 in a different firmware volume, then this parameter
551 specifies the GUID file name of the originating
552 firmware file. Otherwise, this parameter must be NULL.
556 PeiServicesInstallFvInfoPpi (
557 IN CONST EFI_GUID
*FvFormat
, OPTIONAL
558 IN CONST VOID
*FvInfo
,
559 IN UINT32 FvInfoSize
,
560 IN CONST EFI_GUID
*ParentFvName
, OPTIONAL
561 IN CONST EFI_GUID
*ParentFileName OPTIONAL