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.
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
121 that the caller shall install.
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
126 not have the EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES
127 bit set in the Flags field.
128 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
133 PeiServicesNotifyPpi (
134 IN CONST EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyList
137 CONST EFI_PEI_SERVICES
**PeiServices
;
139 PeiServices
= GetPeiServicesTablePointer ();
140 return (*PeiServices
)->NotifyPpi (PeiServices
, NotifyList
);
144 This service enables PEIMs to ascertain the present value of the boot mode.
146 @param BootMode A pointer to contain the value of the boot mode.
148 @retval EFI_SUCCESS The boot mode was returned successfully.
149 @retval EFI_INVALID_PARAMETER BootMode is NULL.
154 PeiServicesGetBootMode (
155 OUT EFI_BOOT_MODE
*BootMode
158 CONST EFI_PEI_SERVICES
**PeiServices
;
160 PeiServices
= GetPeiServicesTablePointer ();
161 return (*PeiServices
)->GetBootMode (PeiServices
, BootMode
);
165 This service enables PEIMs to update the boot mode variable.
167 @param BootMode The value of the boot mode to set.
169 @retval EFI_SUCCESS The value was successfully updated
174 PeiServicesSetBootMode (
175 IN EFI_BOOT_MODE BootMode
178 CONST EFI_PEI_SERVICES
**PeiServices
;
180 PeiServices
= GetPeiServicesTablePointer ();
181 return (*PeiServices
)->SetBootMode (PeiServices
, BootMode
);
185 This service enables a PEIM to ascertain the address of the list of HOBs in memory.
187 @param HobList A pointer to the list of HOBs that the PEI Foundation
190 @retval EFI_SUCCESS The list was successfully returned.
191 @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.
196 PeiServicesGetHobList (
200 CONST EFI_PEI_SERVICES
**PeiServices
;
202 PeiServices
= GetPeiServicesTablePointer ();
203 return (*PeiServices
)->GetHobList (PeiServices
, HobList
);
207 This service enables PEIMs to create various types of HOBs.
209 @param Type The type of HOB to be installed.
210 @param Length The length of the HOB to be added.
211 @param Hob The address of a pointer that will contain the
214 @retval EFI_SUCCESS The HOB was successfully created.
215 @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
220 PeiServicesCreateHob (
226 CONST EFI_PEI_SERVICES
**PeiServices
;
228 PeiServices
= GetPeiServicesTablePointer ();
229 return (*PeiServices
)->CreateHob (PeiServices
, Type
, Length
, Hob
);
233 This service enables PEIMs to discover additional firmware volumes.
235 @param Instance This instance of the firmware volume to find. The
236 value 0 is the Boot Firmware Volume (BFV).
237 @param VolumeHandle Handle of the firmware volume header of the volume
240 @retval EFI_SUCCESS The volume was found.
241 @retval EFI_NOT_FOUND The volume was not found.
242 @retval EFI_INVALID_PARAMETER FwVolHeader is NULL.
247 PeiServicesFfsFindNextVolume (
249 IN OUT EFI_PEI_FV_HANDLE
*VolumeHandle
252 CONST EFI_PEI_SERVICES
**PeiServices
;
254 PeiServices
= GetPeiServicesTablePointer ();
255 return (*PeiServices
)->FfsFindNextVolume (PeiServices
, Instance
, VolumeHandle
);
259 This service enables PEIMs to discover additional firmware files.
261 @param SearchType A filter to find files only of this type.
262 @param VolumeHandle The pointer to the firmware volume header of the
263 volume to search. This parameter must point to a
265 @param FileHandle Handle of the current file from which to begin searching.
267 @retval EFI_SUCCESS The file was found.
268 @retval EFI_NOT_FOUND The file was not found.
269 @retval EFI_NOT_FOUND The header checksum was not zero.
274 PeiServicesFfsFindNextFile (
275 IN EFI_FV_FILETYPE SearchType
,
276 IN EFI_PEI_FV_HANDLE VolumeHandle
,
277 IN OUT EFI_PEI_FILE_HANDLE
*FileHandle
280 CONST EFI_PEI_SERVICES
**PeiServices
;
282 PeiServices
= GetPeiServicesTablePointer ();
283 return (*PeiServices
)->FfsFindNextFile (PeiServices
, SearchType
, VolumeHandle
, FileHandle
);
287 This service enables PEIMs to discover sections of a given type within a valid FFS file.
289 @param SectionType The value of the section type to find.
290 @param FileHandle A pointer to the file header that contains the set
291 of sections to be searched.
292 @param SectionData A pointer to the discovered section, if successful.
294 @retval EFI_SUCCESS The section was found.
295 @retval EFI_NOT_FOUND The section was not found.
300 PeiServicesFfsFindSectionData (
301 IN EFI_SECTION_TYPE SectionType
,
302 IN EFI_PEI_FILE_HANDLE FileHandle
,
303 OUT VOID
**SectionData
306 CONST EFI_PEI_SERVICES
**PeiServices
;
308 PeiServices
= GetPeiServicesTablePointer ();
309 return (*PeiServices
)->FfsFindSectionData (PeiServices
, SectionType
, FileHandle
, SectionData
);
313 This service enables PEIMs to register the permanent memory configuration
314 that has been initialized with the PEI Foundation.
316 @param MemoryBegin The value of a region of installed memory.
317 @param MemoryLength The corresponding length of a region of installed memory.
319 @retval EFI_SUCCESS The region was successfully installed in a HOB.
320 @retval EFI_INVALID_PARAMETER MemoryBegin and MemoryLength are illegal for this system.
321 @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
326 PeiServicesInstallPeiMemory (
327 IN EFI_PHYSICAL_ADDRESS MemoryBegin
,
328 IN UINT64 MemoryLength
331 CONST EFI_PEI_SERVICES
**PeiServices
;
333 PeiServices
= GetPeiServicesTablePointer ();
334 return (*PeiServices
)->InstallPeiMemory (PeiServices
, MemoryBegin
, MemoryLength
);
338 This service enables PEIMs to allocate memory after the permanent memory has been
341 @param MemoryType Type of memory to allocate.
342 @param Pages The number of pages to allocate.
343 @param Memory Pointer of memory allocated.
345 @retval EFI_SUCCESS The memory range was successfully allocated.
346 @retval EFI_INVALID_PARAMETER Type is not equal to AllocateAnyPages.
347 @retval EFI_NOT_AVAILABLE_YET Called with permanent memory not available.
348 @retval EFI_OUT_OF_RESOURCES The pages could not be allocated.
353 PeiServicesAllocatePages (
354 IN EFI_MEMORY_TYPE MemoryType
,
356 OUT EFI_PHYSICAL_ADDRESS
*Memory
359 CONST EFI_PEI_SERVICES
**PeiServices
;
361 PeiServices
= GetPeiServicesTablePointer ();
362 return (*PeiServices
)->AllocatePages (PeiServices
, MemoryType
, Pages
, Memory
);
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 (
383 CONST EFI_PEI_SERVICES
**PeiServices
;
385 PeiServices
= GetPeiServicesTablePointer ();
386 return (*PeiServices
)->AllocatePool (PeiServices
, Size
, Buffer
);
390 Resets the entire platform.
392 @retval EFI_SUCCESS The function completed successfully.
393 @retval EFI_NOT_AVAILABLE_YET The service has not been installed yet.
398 PeiServicesResetSystem (
402 CONST EFI_PEI_SERVICES
**PeiServices
;
404 PeiServices
= GetPeiServicesTablePointer ();
405 return (*PeiServices
)->ResetSystem (PeiServices
);
409 This service is a wrapper for the PEI Service RegisterForShadow(), except the
410 pointer to the PEI Services Table has been removed. See the Platform
411 Initialization Pre-EFI Initialization Core Interface Specification for details.
413 @param FileHandle PEIM's file handle. Must be the currently
416 @retval EFI_SUCCESS The PEIM was successfully registered for
419 @retval EFI_ALREADY_STARTED The PEIM was previously
420 registered for shadowing.
422 @retval EFI_NOT_FOUND The FileHandle does not refer to a
427 PeiServicesRegisterForShadow (
428 IN EFI_PEI_FILE_HANDLE FileHandle
431 return (*GetPeiServicesTablePointer())->RegisterForShadow (FileHandle
);
435 This service is a wrapper for the PEI Service FfsGetFileInfo(), except the pointer to the PEI Services
436 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
437 Specification for details.
439 @param FileHandle The handle of the file.
441 @param FileInfo Upon exit, points to the file's
444 @retval EFI_SUCCESS File information returned.
446 @retval EFI_INVALID_PARAMETER If FileHandle does not
447 represent a valid file.
449 @retval EFI_INVALID_PARAMETER FileInfo is NULL.
454 PeiServicesFfsGetFileInfo (
455 IN CONST EFI_PEI_FILE_HANDLE FileHandle
,
456 OUT EFI_FV_FILE_INFO
*FileInfo
459 return (*GetPeiServicesTablePointer())->FfsGetFileInfo (FileHandle
, FileInfo
);
464 This service is a wrapper for the PEI Service FfsFindByName(), except the pointer to the PEI Services
465 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
466 Specification for details.
468 @param FileName A pointer to the name of the file to
469 find within the firmware volume.
471 @param VolumeHandle The firmware volume to search FileHandle
472 Upon exit, points to the found file's
473 handle or NULL if it could not be found.
474 @param FileHandle The pointer to found file handle
476 @retval EFI_SUCCESS File was found.
478 @retval EFI_NOT_FOUND File was not found.
480 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or
486 PeiServicesFfsFindFileByName (
487 IN CONST EFI_GUID
*FileName
,
488 IN CONST EFI_PEI_FV_HANDLE VolumeHandle
,
489 OUT EFI_PEI_FILE_HANDLE
*FileHandle
492 return (*GetPeiServicesTablePointer())->FfsFindFileByName (FileName
, VolumeHandle
, FileHandle
);
497 This service is a wrapper for the PEI Service FfsGetVolumeInfo(), except the pointer to the PEI Services
498 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
499 Specification for details.
501 @param VolumeHandle Handle of the volume.
503 @param VolumeInfo Upon exit, points to the volume's
506 @retval EFI_SUCCESS File information returned.
508 @retval EFI_INVALID_PARAMETER If FileHandle does not
509 represent a valid file.
511 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
516 PeiServicesFfsGetVolumeInfo (
517 IN EFI_PEI_FV_HANDLE VolumeHandle
,
518 OUT EFI_FV_INFO
*VolumeInfo
521 return (*GetPeiServicesTablePointer())->FfsGetVolumeInfo (VolumeHandle
, VolumeInfo
);
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
565 EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
*FvInfoPpi
;
566 EFI_PEI_PPI_DESCRIPTOR
*FvInfoPpiDescriptor
;
567 EFI_GUID
*ParentFvNameValue
;
568 EFI_GUID
*ParentFileNameValue
;
570 ParentFvNameValue
= NULL
;
571 ParentFileNameValue
= NULL
;
572 FvInfoPpi
= AllocateZeroPool (sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI
));
573 ASSERT(FvInfoPpi
!= NULL
);
575 if (FvFormat
!= NULL
) {
576 CopyGuid (&FvInfoPpi
->FvFormat
, FvFormat
);
578 CopyGuid (&FvInfoPpi
->FvFormat
, &gEfiFirmwareFileSystem2Guid
);
580 FvInfoPpi
->FvInfo
= (VOID
*) FvInfo
;
581 FvInfoPpi
->FvInfoSize
= FvInfoSize
;
582 if (ParentFvName
!= NULL
) {
583 ParentFvNameValue
= AllocateCopyPool (sizeof (EFI_GUID
), ParentFvName
);
584 ASSERT (ParentFvNameValue
!= NULL
);
585 FvInfoPpi
->ParentFvName
= ParentFvNameValue
;
587 if (ParentFileName
!= NULL
) {
588 ParentFileNameValue
= AllocateCopyPool (sizeof (EFI_GUID
), ParentFileName
);
589 ASSERT (ParentFileNameValue
!= NULL
);
590 FvInfoPpi
->ParentFileName
= ParentFileNameValue
;
593 FvInfoPpiDescriptor
= AllocateCopyPool (sizeof(EFI_PEI_PPI_DESCRIPTOR
), mPpiListTemplate
);
594 ASSERT (FvInfoPpiDescriptor
!= NULL
);
596 FvInfoPpiDescriptor
->Ppi
= (VOID
*) FvInfoPpi
;
597 Status
= PeiServicesInstallPpi (FvInfoPpiDescriptor
);
598 ASSERT_EFI_ERROR (Status
);