2 Implementation for PEI Services Library.
4 Copyright (c) 2006 - 2009, 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.
18 #include <Ppi/FirmwareVolumeInfo.h>
19 #include <Guid/FirmwareFileSystem2.h>
21 #include <Library/PeiServicesLib.h>
22 #include <Library/PeiServicesTablePointerLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/MemoryAllocationLib.h>
25 #include <Library/BaseMemoryLib.h>
28 GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_PEI_PPI_DESCRIPTOR mPpiListTemplate
[] = {
30 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
31 &gEfiPeiFirmwareVolumeInfoPpiGuid
,
37 This service enables a given PEIM to register an interface into the PEI Foundation.
39 @param PpiList A pointer to the list of interfaces that the caller shall install.
41 @retval EFI_SUCCESS The interface was successfully installed.
42 @retval EFI_INVALID_PARAMETER The PpiList pointer is NULL.
43 @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
44 EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
45 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
50 PeiServicesInstallPpi (
51 IN CONST EFI_PEI_PPI_DESCRIPTOR
*PpiList
54 CONST EFI_PEI_SERVICES
**PeiServices
;
56 PeiServices
= GetPeiServicesTablePointer ();
57 return (*PeiServices
)->InstallPpi (PeiServices
, PpiList
);
61 This service enables PEIMs to replace an entry in the PPI database with an alternate entry.
63 @param OldPpi The pointer to the old PEI PPI Descriptors.
64 @param NewPpi The pointer to the new PEI PPI Descriptors.
66 @retval EFI_SUCCESS The interface was successfully installed.
67 @retval EFI_INVALID_PARAMETER The OldPpi or NewPpi is NULL.
68 @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
69 EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
70 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
71 @retval EFI_NOT_FOUND The PPI for which the reinstallation was requested has not been
77 PeiServicesReInstallPpi (
78 IN CONST EFI_PEI_PPI_DESCRIPTOR
*OldPpi
,
79 IN CONST EFI_PEI_PPI_DESCRIPTOR
*NewPpi
82 CONST EFI_PEI_SERVICES
**PeiServices
;
84 PeiServices
= GetPeiServicesTablePointer ();
85 return (*PeiServices
)->ReInstallPpi (PeiServices
, OldPpi
, NewPpi
);
89 This service enables PEIMs to discover a given instance of an interface.
91 @param Guid A pointer to the GUID whose corresponding interface needs to be
93 @param Instance The N-th instance of the interface that is required.
94 @param PpiDescriptor A pointer to instance of the EFI_PEI_PPI_DESCRIPTOR.
95 @param Ppi A pointer to the instance of the interface.
97 @retval EFI_SUCCESS The interface was successfully returned.
98 @retval EFI_NOT_FOUND The PPI descriptor is not found in the database.
103 PeiServicesLocatePpi (
104 IN CONST EFI_GUID
*Guid
,
106 IN OUT EFI_PEI_PPI_DESCRIPTOR
**PpiDescriptor
,
110 CONST EFI_PEI_SERVICES
**PeiServices
;
112 PeiServices
= GetPeiServicesTablePointer ();
113 return (*PeiServices
)->LocatePpi (PeiServices
, Guid
, Instance
, PpiDescriptor
, Ppi
);
117 This service enables PEIMs to register a given service to be invoked when another service is
118 installed or reinstalled.
120 @param NotifyList A pointer to the list of notification interfaces that the caller
123 @retval EFI_SUCCESS The interface was successfully installed.
124 @retval EFI_INVALID_PARAMETER The NotifyList pointer is NULL.
125 @retval EFI_INVALID_PARAMETER Any of the PEI notify descriptors in the list do not have the
126 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES bit set in the Flags field.
127 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
132 PeiServicesNotifyPpi (
133 IN CONST EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyList
136 CONST EFI_PEI_SERVICES
**PeiServices
;
138 PeiServices
= GetPeiServicesTablePointer ();
139 return (*PeiServices
)->NotifyPpi (PeiServices
, NotifyList
);
143 This service enables PEIMs to ascertain the present value of the boot mode.
145 @param BootMode A pointer to contain the value of the boot mode.
147 @retval EFI_SUCCESS The boot mode was returned successfully.
148 @retval EFI_INVALID_PARAMETER BootMode is NULL.
153 PeiServicesGetBootMode (
154 OUT EFI_BOOT_MODE
*BootMode
157 CONST EFI_PEI_SERVICES
**PeiServices
;
159 PeiServices
= GetPeiServicesTablePointer ();
160 return (*PeiServices
)->GetBootMode (PeiServices
, BootMode
);
164 This service enables PEIMs to update the boot mode variable.
166 @param BootMode The value of the boot mode to set.
168 @retval EFI_SUCCESS The value was successfully updated
173 PeiServicesSetBootMode (
174 IN EFI_BOOT_MODE BootMode
177 CONST EFI_PEI_SERVICES
**PeiServices
;
179 PeiServices
= GetPeiServicesTablePointer ();
180 return (*PeiServices
)->SetBootMode (PeiServices
, BootMode
);
184 This service enables a PEIM to ascertain the address of the list of HOBs in memory.
186 @param HobList A pointer to the list of HOBs that the PEI Foundation will initialize.
188 @retval EFI_SUCCESS The list was successfully returned.
189 @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.
194 PeiServicesGetHobList (
198 CONST EFI_PEI_SERVICES
**PeiServices
;
200 PeiServices
= GetPeiServicesTablePointer ();
201 return (*PeiServices
)->GetHobList (PeiServices
, HobList
);
205 This service enables PEIMs to create various types of HOBs.
207 @param Type The type of HOB to be installed.
208 @param Length The length of the HOB to be added.
209 @param Hob The address of a pointer that will contain the HOB header.
211 @retval EFI_SUCCESS The HOB was successfully created.
212 @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
217 PeiServicesCreateHob (
223 CONST EFI_PEI_SERVICES
**PeiServices
;
225 PeiServices
= GetPeiServicesTablePointer ();
226 return (*PeiServices
)->CreateHob (PeiServices
, Type
, Length
, Hob
);
230 This service enables PEIMs to discover additional firmware volumes.
232 @param Instance This instance of the firmware volume to find. The value 0 is the
233 Boot Firmware Volume (BFV).
234 @param VolumeHandle Handle of the firmware volume header of the volume to return.
236 @retval EFI_SUCCESS The volume was found.
237 @retval EFI_NOT_FOUND The volume was not found.
238 @retval EFI_INVALID_PARAMETER FwVolHeader is NULL.
243 PeiServicesFfsFindNextVolume (
245 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
248 CONST EFI_PEI_SERVICES
**PeiServices
;
250 PeiServices
= GetPeiServicesTablePointer ();
251 return (*PeiServices
)->FfsFindNextVolume (PeiServices
, Instance
, VolumeHandle
);
255 This service enables PEIMs to discover additional firmware files.
257 @param SearchType A filter to find files only of this type.
258 @param VolumeHandle The pointer to the firmware volume header of the volume to search.
259 This parameter must point to a valid FFS volume.
260 @param FileHandle Handle of the current file from which to begin searching.
262 @retval EFI_SUCCESS The file was found.
263 @retval EFI_NOT_FOUND The file was not found.
264 @retval EFI_NOT_FOUND The header checksum was not zero.
269 PeiServicesFfsFindNextFile (
270 IN EFI_FV_FILETYPE SearchType
,
271 IN EFI_PEI_FV_HANDLE VolumeHandle
,
272 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
275 CONST EFI_PEI_SERVICES
**PeiServices
;
277 PeiServices
= GetPeiServicesTablePointer ();
278 return (*PeiServices
)->FfsFindNextFile (PeiServices
, SearchType
, VolumeHandle
, FileHandle
);
282 This service enables PEIMs to discover sections of a given type within a valid FFS file.
284 @param SectionType The value of the section type to find.
285 @param FileHandle A pointer to the file header that contains the set of sections to
287 @param SectionData A pointer to the discovered section, if successful.
289 @retval EFI_SUCCESS The section was found.
290 @retval EFI_NOT_FOUND The section was not found.
295 PeiServicesFfsFindSectionData (
296 IN EFI_SECTION_TYPE SectionType
,
297 IN EFI_PEI_FILE_HANDLE FileHandle
,
298 OUT VOID
**SectionData
301 CONST EFI_PEI_SERVICES
**PeiServices
;
303 PeiServices
= GetPeiServicesTablePointer ();
304 return (*PeiServices
)->FfsFindSectionData (PeiServices
, SectionType
, FileHandle
, SectionData
);
308 This service enables PEIMs to register the permanent memory configuration
309 that has been initialized with the PEI Foundation.
311 @param MemoryBegin The value of a region of installed memory.
312 @param MemoryLength The corresponding length of a region of installed memory.
314 @retval EFI_SUCCESS The region was successfully installed in a HOB.
315 @retval EFI_INVALID_PARAMETER MemoryBegin and MemoryLength are illegal for this system.
316 @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
321 PeiServicesInstallPeiMemory (
322 IN EFI_PHYSICAL_ADDRESS MemoryBegin
,
323 IN UINT64 MemoryLength
326 CONST EFI_PEI_SERVICES
**PeiServices
;
328 PeiServices
= GetPeiServicesTablePointer ();
329 return (*PeiServices
)->InstallPeiMemory (PeiServices
, MemoryBegin
, MemoryLength
);
333 This service enables PEIMs to allocate memory after the permanent memory has been installed by a
336 @param MemoryType Type of memory to allocate.
337 @param Pages The number of pages to allocate.
338 @param Memory Pointer of memory allocated.
340 @retval EFI_SUCCESS The memory range was successfully allocated.
341 @retval EFI_INVALID_PARAMETER Type is not equal to AllocateAnyPages.
342 @retval EFI_NOT_AVAILABLE_YET Called with permanent memory not available.
343 @retval EFI_OUT_OF_RESOURCES The pages could not be allocated.
348 PeiServicesAllocatePages (
349 IN EFI_MEMORY_TYPE MemoryType
,
351 OUT EFI_PHYSICAL_ADDRESS
*Memory
354 CONST EFI_PEI_SERVICES
**PeiServices
;
356 PeiServices
= GetPeiServicesTablePointer ();
357 return (*PeiServices
)->AllocatePages (PeiServices
, MemoryType
, Pages
, Memory
);
361 This service allocates memory from the Hand-Off Block (HOB) heap.
363 @param Size The number of bytes to allocate from the pool.
364 @param Buffer If the call succeeds, a pointer to a pointer to the allocate
365 buffer; undefined otherwise.
367 @retval EFI_SUCCESS The allocation was successful
368 @retval EFI_OUT_OF_RESOURCES There is not enough heap to allocate the requested size.
373 PeiServicesAllocatePool (
378 CONST EFI_PEI_SERVICES
**PeiServices
;
380 PeiServices
= GetPeiServicesTablePointer ();
381 return (*PeiServices
)->AllocatePool (PeiServices
, Size
, Buffer
);
385 Resets the entire platform.
387 @retval EFI_SUCCESS The function completed successfully.
388 @retval EFI_NOT_AVAILABLE_YET The service has not been installed yet.
393 PeiServicesResetSystem (
397 CONST EFI_PEI_SERVICES
**PeiServices
;
399 PeiServices
= GetPeiServicesTablePointer ();
400 return (*PeiServices
)->ResetSystem (PeiServices
);
404 This service is a wrapper for the PEI Service RegisterForShadow(), except the pointer to the PEI Services
405 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
406 Specification for details.
408 @param FileHandle PEIM's file handle. Must be the currently
411 @retval EFI_SUCCESS The PEIM was successfully registered for
414 @retval EFI_ALREADY_STARTED The PEIM was previously
415 registered for shadowing.
417 @retval EFI_NOT_FOUND The FileHandle does not refer to a
422 PeiServicesRegisterForShadow (
423 IN EFI_PEI_FILE_HANDLE FileHandle
426 return (*GetPeiServicesTablePointer())->RegisterForShadow (FileHandle
);
430 This service is a wrapper for the PEI Service FfsGetFileInfo(), except the pointer to the PEI Services
431 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
432 Specification for details.
434 @param FileHandle Handle of the file.
436 @param FileInfo Upon exit, points to the file's
439 @retval EFI_SUCCESS File information returned.
441 @retval EFI_INVALID_PARAMETER If FileHandle does not
442 represent a valid file.
444 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
449 PeiServicesFfsGetFileInfo (
450 IN CONST EFI_PEI_FILE_HANDLE FileHandle
,
451 OUT EFI_FV_FILE_INFO
*FileInfo
454 return (*GetPeiServicesTablePointer())->FfsGetFileInfo (FileHandle
, FileInfo
);
459 This service is a wrapper for the PEI Service FfsFindByName(), except the pointer to the PEI Services
460 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
461 Specification for details.
463 @param FileName A pointer to the name of the file to
464 find within the firmware volume.
466 @param VolumeHandle The firmware volume to search FileHandle
467 Upon exit, points to the found file's
468 handle or NULL if it could not be found.
469 @param FileHandle The pointer to found file handle
471 @retval EFI_SUCCESS File was found.
473 @retval EFI_NOT_FOUND File was not found.
475 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or
481 PeiServicesFfsFindFileByName (
482 IN CONST EFI_GUID
*FileName
,
483 IN CONST EFI_PEI_FV_HANDLE VolumeHandle
,
484 OUT EFI_PEI_FILE_HANDLE
*FileHandle
487 return (*GetPeiServicesTablePointer())->FfsFindFileByName (FileName
, VolumeHandle
, FileHandle
);
492 This service is a wrapper for the PEI Service FfsGetVolumeInfo(), except the pointer to the PEI Services
493 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
494 Specification for details.
496 @param VolumeHandle Handle of the volume.
498 @param VolumeInfo Upon exit, points to the volume's
501 @retval EFI_SUCCESS File information returned.
503 @retval EFI_INVALID_PARAMETER If FileHandle does not
504 represent a valid file.
506 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
511 PeiServicesFfsGetVolumeInfo (
512 IN EFI_PEI_FV_HANDLE VolumeHandle
,
513 OUT EFI_FV_INFO
*VolumeInfo
516 return (*GetPeiServicesTablePointer())->FfsGetVolumeInfo (VolumeHandle
, VolumeInfo
);
520 Install a EFI_PEI_FIRMWARE_VOLUME_INFO_PPI instance so the PEI Core will be notified about a new firmware volume.
522 This function allocates, initializes, and installs a new EFI_PEI_FIRMWARE_VOLUME_INFO_PPI using
523 the parameters passed in to initialize the fields of the EFI_PEI_FIRMWARE_VOLUME_INFO_PPI instance.
524 If the resources can not be allocated for EFI_PEI_FIRMWARE_VOLUME_INFO_PPI, then ASSERT().
525 If the EFI_PEI_FIRMWARE_VOLUME_INFO_PPI can not be installed, then ASSERT().
528 @param FvFormat Unique identifier of the format of the memory-mapped firmware volume.
529 This parameter is optional and may be NULL.
530 If NULL is specified, the EFI_FIRMWARE_FILE_SYSTEM2_GUID format is assumed.
531 @param FvInfo Points to a buffer which allows the EFI_PEI_FIRMWARE_VOLUME_PPI to process the volume.
532 The format of this buffer is specific to the FvFormat. For memory-mapped firmware volumes,
533 this typically points to the first byte of the firmware volume.
534 @param FvInfoSize The size, in bytes, of FvInfo. For memory-mapped firmware volumes,
535 this is typically the size of the firmware volume.
536 @param ParentFvName If the new firmware volume originated from a file in a different firmware volume,
537 then this parameter specifies the GUID name of the originating firmware volume.
538 Otherwise, this parameter must be NULL.
539 @param ParentFileName If the new firmware volume originated from a file in a different firmware volume,
540 then this parameter specifies the GUID file name of the originating firmware file.
541 Otherwise, this parameter must be NULL.
545 PeiServicesInstallFvInfoPpi (
546 IN CONST EFI_GUID
*FvFormat
, OPTIONAL
547 IN CONST VOID
*FvInfo
,
548 IN UINT32 FvInfoSize
,
549 IN CONST EFI_GUID
*ParentFvName
, OPTIONAL
550 IN CONST EFI_GUID
*ParentFileName OPTIONAL
554 EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
*FvInfoPpi
;
555 EFI_PEI_PPI_DESCRIPTOR
*FvInfoPpiDescriptor
;
556 EFI_GUID
*ParentFvNameValue
;
557 EFI_GUID
*ParentFileNameValue
;
559 ParentFvNameValue
= NULL
;
560 ParentFileNameValue
= NULL
;
561 FvInfoPpi
= AllocateZeroPool (sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
));
562 ASSERT(FvInfoPpi
!= NULL
);
564 if (FvFormat
!= NULL
) {
565 CopyGuid (&FvInfoPpi
->FvFormat
, FvFormat
);
567 CopyGuid (&FvInfoPpi
->FvFormat
, &gEfiFirmwareFileSystem2Guid
);
569 FvInfoPpi
->FvInfo
= (VOID
*) FvInfo
;
570 FvInfoPpi
->FvInfoSize
= FvInfoSize
;
571 if (ParentFvName
!= NULL
) {
572 ParentFvNameValue
= AllocateCopyPool (sizeof (EFI_GUID
), ParentFvName
);
573 ASSERT (ParentFvNameValue
!= NULL
);
574 FvInfoPpi
->ParentFvName
= ParentFvNameValue
;
576 if (ParentFileName
!= NULL
) {
577 ParentFileNameValue
= AllocateCopyPool (sizeof (EFI_GUID
), ParentFileName
);
578 ASSERT (ParentFileNameValue
!= NULL
);
579 FvInfoPpi
->ParentFileName
= ParentFileNameValue
;
582 FvInfoPpiDescriptor
= AllocateCopyPool (sizeof(EFI_PEI_PPI_DESCRIPTOR
), mPpiListTemplate
);
583 ASSERT (FvInfoPpiDescriptor
!= NULL
);
585 FvInfoPpiDescriptor
->Ppi
= (VOID
*) FvInfoPpi
;
586 Status
= PeiServicesInstallPpi (FvInfoPpiDescriptor
);
587 ASSERT_EFI_ERROR (Status
);