Home | History | Annotate | Download | only in PeiServicesLib
      1 /** @file
      2   Implementation for PEI Services Library.
      3 
      4   Copyright (c) 2006 - 2016, 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.
      9 
     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.
     12 
     13 **/
     14 
     15 
     16 #include <PiPei.h>
     17 
     18 #include <Ppi/FirmwareVolumeInfo.h>
     19 #include <Ppi/FirmwareVolumeInfo2.h>
     20 #include <Guid/FirmwareFileSystem2.h>
     21 
     22 #include <Library/PeiServicesLib.h>
     23 #include <Library/PeiServicesTablePointerLib.h>
     24 #include <Library/DebugLib.h>
     25 #include <Library/MemoryAllocationLib.h>
     26 #include <Library/BaseMemoryLib.h>
     27 
     28 /**
     29   This service enables a given PEIM to register an interface into the PEI Foundation.
     30 
     31   @param  PpiList               A pointer to the list of interfaces that the caller shall install.
     32 
     33   @retval EFI_SUCCESS           The interface was successfully installed.
     34   @retval EFI_INVALID_PARAMETER The PpiList pointer is NULL.
     35   @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
     36                                 EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
     37   @retval EFI_OUT_OF_RESOURCES  There is no additional space in the PPI database.
     38 
     39 **/
     40 EFI_STATUS
     41 EFIAPI
     42 PeiServicesInstallPpi (
     43   IN CONST EFI_PEI_PPI_DESCRIPTOR     *PpiList
     44   )
     45 {
     46   CONST EFI_PEI_SERVICES  **PeiServices;
     47 
     48   PeiServices = GetPeiServicesTablePointer ();
     49   return (*PeiServices)->InstallPpi (PeiServices, PpiList);
     50 }
     51 
     52 /**
     53   This service enables PEIMs to replace an entry in the PPI database with an alternate entry.
     54 
     55   @param  OldPpi                The pointer to the old PEI PPI Descriptors.
     56   @param  NewPpi                The pointer to the new PEI PPI Descriptors.
     57 
     58   @retval EFI_SUCCESS           The interface was successfully installed.
     59   @retval EFI_INVALID_PARAMETER The OldPpi or NewPpi is NULL.
     60   @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
     61                                 EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
     62   @retval EFI_OUT_OF_RESOURCES  There is no additional space in the PPI database.
     63   @retval EFI_NOT_FOUND         The PPI for which the reinstallation was requested has not been
     64                                 installed.
     65 
     66 **/
     67 EFI_STATUS
     68 EFIAPI
     69 PeiServicesReInstallPpi (
     70   IN CONST EFI_PEI_PPI_DESCRIPTOR     *OldPpi,
     71   IN CONST EFI_PEI_PPI_DESCRIPTOR     *NewPpi
     72   )
     73 {
     74   CONST EFI_PEI_SERVICES **PeiServices;
     75 
     76   PeiServices = GetPeiServicesTablePointer ();
     77   return (*PeiServices)->ReInstallPpi (PeiServices, OldPpi, NewPpi);
     78 }
     79 
     80 /**
     81   This service enables PEIMs to discover a given instance of an interface.
     82 
     83   @param  Guid                  A pointer to the GUID whose corresponding interface needs to be
     84                                 found.
     85   @param  Instance              The N-th instance of the interface that is required.
     86   @param  PpiDescriptor         A pointer to instance of the EFI_PEI_PPI_DESCRIPTOR.
     87   @param  Ppi                   A pointer to the instance of the interface.
     88 
     89   @retval EFI_SUCCESS           The interface was successfully returned.
     90   @retval EFI_NOT_FOUND         The PPI descriptor is not found in the database.
     91 
     92 **/
     93 EFI_STATUS
     94 EFIAPI
     95 PeiServicesLocatePpi (
     96   IN CONST EFI_GUID                   *Guid,
     97   IN UINTN                      Instance,
     98   IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
     99   IN OUT VOID                   **Ppi
    100   )
    101 {
    102   CONST EFI_PEI_SERVICES **PeiServices;
    103 
    104   PeiServices = GetPeiServicesTablePointer ();
    105   return (*PeiServices)->LocatePpi (PeiServices, Guid, Instance, PpiDescriptor, Ppi);
    106 }
    107 
    108 /**
    109   This service enables PEIMs to register a given service to be invoked when another service is
    110   installed or reinstalled.
    111 
    112   @param  NotifyList            A pointer to the list of notification interfaces
    113                                 that the caller shall install.
    114 
    115   @retval EFI_SUCCESS           The interface was successfully installed.
    116   @retval EFI_INVALID_PARAMETER The NotifyList pointer is NULL.
    117   @retval EFI_INVALID_PARAMETER Any of the PEI notify descriptors in the list do
    118                                  not have the EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES
    119                                  bit set in the Flags field.
    120   @retval EFI_OUT_OF_RESOURCES  There is no additional space in the PPI database.
    121 
    122 **/
    123 EFI_STATUS
    124 EFIAPI
    125 PeiServicesNotifyPpi (
    126   IN CONST EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyList
    127   )
    128 {
    129   CONST EFI_PEI_SERVICES **PeiServices;
    130 
    131   PeiServices = GetPeiServicesTablePointer ();
    132   return (*PeiServices)->NotifyPpi (PeiServices, NotifyList);
    133 }
    134 
    135 /**
    136   This service enables PEIMs to ascertain the present value of the boot mode.
    137 
    138   @param  BootMode              A pointer to contain the value of the boot mode.
    139 
    140   @retval EFI_SUCCESS           The boot mode was returned successfully.
    141   @retval EFI_INVALID_PARAMETER BootMode is NULL.
    142 
    143 **/
    144 EFI_STATUS
    145 EFIAPI
    146 PeiServicesGetBootMode (
    147   OUT EFI_BOOT_MODE          *BootMode
    148   )
    149 {
    150   CONST EFI_PEI_SERVICES **PeiServices;
    151 
    152   PeiServices = GetPeiServicesTablePointer ();
    153   return (*PeiServices)->GetBootMode (PeiServices, BootMode);
    154 }
    155 
    156 /**
    157   This service enables PEIMs to update the boot mode variable.
    158 
    159   @param  BootMode              The value of the boot mode to set.
    160 
    161   @retval EFI_SUCCESS           The value was successfully updated
    162 
    163 **/
    164 EFI_STATUS
    165 EFIAPI
    166 PeiServicesSetBootMode (
    167   IN EFI_BOOT_MODE              BootMode
    168   )
    169 {
    170   CONST EFI_PEI_SERVICES **PeiServices;
    171 
    172   PeiServices = GetPeiServicesTablePointer ();
    173   return (*PeiServices)->SetBootMode (PeiServices, BootMode);
    174 }
    175 
    176 /**
    177   This service enables a PEIM to ascertain the address of the list of HOBs in memory.
    178 
    179   @param  HobList               A pointer to the list of HOBs that the PEI Foundation
    180                                 will initialize.
    181 
    182   @retval EFI_SUCCESS           The list was successfully returned.
    183   @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.
    184 
    185 **/
    186 EFI_STATUS
    187 EFIAPI
    188 PeiServicesGetHobList (
    189   OUT VOID                      **HobList
    190   )
    191 {
    192   CONST EFI_PEI_SERVICES **PeiServices;
    193 
    194   PeiServices = GetPeiServicesTablePointer ();
    195   return (*PeiServices)->GetHobList (PeiServices, HobList);
    196 }
    197 
    198 /**
    199   This service enables PEIMs to create various types of HOBs.
    200 
    201   @param  Type                  The type of HOB to be installed.
    202   @param  Length                The length of the HOB to be added.
    203   @param  Hob                   The address of a pointer that will contain the
    204                                 HOB header.
    205 
    206   @retval EFI_SUCCESS           The HOB was successfully created.
    207   @retval EFI_OUT_OF_RESOURCES  There is no additional space for HOB creation.
    208 
    209 **/
    210 EFI_STATUS
    211 EFIAPI
    212 PeiServicesCreateHob (
    213   IN UINT16                     Type,
    214   IN UINT16                     Length,
    215   OUT VOID                      **Hob
    216   )
    217 {
    218   CONST EFI_PEI_SERVICES **PeiServices;
    219 
    220   PeiServices = GetPeiServicesTablePointer ();
    221   return (*PeiServices)->CreateHob (PeiServices, Type, Length, Hob);
    222 }
    223 
    224 /**
    225   This service enables PEIMs to discover additional firmware volumes.
    226 
    227   @param  Instance              This instance of the firmware volume to find.  The
    228                                 value 0 is the Boot Firmware Volume (BFV).
    229   @param  VolumeHandle          Handle of the firmware volume header of the volume
    230                                 to return.
    231 
    232   @retval EFI_SUCCESS           The volume was found.
    233   @retval EFI_NOT_FOUND         The volume was not found.
    234   @retval EFI_INVALID_PARAMETER FwVolHeader is NULL.
    235 
    236 **/
    237 EFI_STATUS
    238 EFIAPI
    239 PeiServicesFfsFindNextVolume (
    240   IN UINTN                          Instance,
    241   IN OUT EFI_PEI_FV_HANDLE          *VolumeHandle
    242   )
    243 {
    244   CONST EFI_PEI_SERVICES **PeiServices;
    245 
    246   PeiServices = GetPeiServicesTablePointer ();
    247   return (*PeiServices)->FfsFindNextVolume (PeiServices, Instance, VolumeHandle);
    248 }
    249 
    250 /**
    251   This service enables PEIMs to discover additional firmware files.
    252 
    253   @param  SearchType            A filter to find files only of this type.
    254   @param  VolumeHandle          The pointer to the firmware volume header of the
    255                                 volume to search. This parameter must point to a
    256                                 valid FFS volume.
    257   @param  FileHandle            Handle of the current file from which to begin searching.
    258 
    259   @retval EFI_SUCCESS           The file was found.
    260   @retval EFI_NOT_FOUND         The file was not found.
    261   @retval EFI_NOT_FOUND         The header checksum was not zero.
    262 
    263 **/
    264 EFI_STATUS
    265 EFIAPI
    266 PeiServicesFfsFindNextFile (
    267   IN EFI_FV_FILETYPE            SearchType,
    268   IN EFI_PEI_FV_HANDLE          VolumeHandle,
    269   IN OUT EFI_PEI_FILE_HANDLE    *FileHandle
    270   )
    271 {
    272   CONST EFI_PEI_SERVICES **PeiServices;
    273 
    274   PeiServices = GetPeiServicesTablePointer ();
    275   return (*PeiServices)->FfsFindNextFile (PeiServices, SearchType, VolumeHandle, FileHandle);
    276 }
    277 
    278 /**
    279   This service enables PEIMs to discover sections of a given type within a valid FFS file.
    280 
    281   @param  SectionType           The value of the section type to find.
    282   @param  FileHandle            A pointer to the file header that contains the set
    283                                 of sections to be searched.
    284   @param  SectionData           A pointer to the discovered section, if successful.
    285 
    286   @retval EFI_SUCCESS           The section was found.
    287   @retval EFI_NOT_FOUND         The section was not found.
    288 
    289 **/
    290 EFI_STATUS
    291 EFIAPI
    292 PeiServicesFfsFindSectionData (
    293   IN EFI_SECTION_TYPE           SectionType,
    294   IN EFI_PEI_FILE_HANDLE        FileHandle,
    295   OUT VOID                      **SectionData
    296   )
    297 {
    298   CONST EFI_PEI_SERVICES **PeiServices;
    299 
    300   PeiServices = GetPeiServicesTablePointer ();
    301   return (*PeiServices)->FfsFindSectionData (PeiServices, SectionType, FileHandle, SectionData);
    302 }
    303 
    304 /**
    305   This service enables PEIMs to discover sections of a given instance and type within a valid FFS file.
    306 
    307   @param  SectionType           The value of the section type to find.
    308   @param  SectionInstance       Section instance to find.
    309   @param  FileHandle            A pointer to the file header that contains the set
    310                                 of sections to be searched.
    311   @param  SectionData           A pointer to the discovered section, if successful.
    312   @param  AuthenticationStatus  A pointer to the authentication status for this section.
    313 
    314   @retval EFI_SUCCESS           The section was found.
    315   @retval EFI_NOT_FOUND         The section was not found.
    316 
    317 **/
    318 EFI_STATUS
    319 EFIAPI
    320 PeiServicesFfsFindSectionData3 (
    321   IN EFI_SECTION_TYPE           SectionType,
    322   IN UINTN                      SectionInstance,
    323   IN EFI_PEI_FILE_HANDLE        FileHandle,
    324   OUT VOID                      **SectionData,
    325   OUT UINT32                    *AuthenticationStatus
    326   )
    327 {
    328   CONST EFI_PEI_SERVICES **PeiServices;
    329 
    330   PeiServices = GetPeiServicesTablePointer ();
    331   return (*PeiServices)->FindSectionData3 (PeiServices, SectionType, SectionInstance, FileHandle, SectionData, AuthenticationStatus);
    332 }
    333 
    334 /**
    335   This service enables PEIMs to register the permanent memory configuration
    336   that has been initialized with the PEI Foundation.
    337 
    338   @param  MemoryBegin           The value of a region of installed memory.
    339   @param  MemoryLength          The corresponding length of a region of installed memory.
    340 
    341   @retval EFI_SUCCESS           The region was successfully installed in a HOB.
    342   @retval EFI_INVALID_PARAMETER MemoryBegin and MemoryLength are illegal for this system.
    343   @retval EFI_OUT_OF_RESOURCES  There is no additional space for HOB creation.
    344 
    345 **/
    346 EFI_STATUS
    347 EFIAPI
    348 PeiServicesInstallPeiMemory (
    349   IN EFI_PHYSICAL_ADDRESS       MemoryBegin,
    350   IN UINT64                     MemoryLength
    351   )
    352 {
    353   CONST EFI_PEI_SERVICES **PeiServices;
    354 
    355   PeiServices = GetPeiServicesTablePointer ();
    356   return (*PeiServices)->InstallPeiMemory (PeiServices, MemoryBegin, MemoryLength);
    357 }
    358 
    359 /**
    360   This service enables PEIMs to allocate memory after the permanent memory has been
    361    installed by a PEIM.
    362 
    363   @param  MemoryType            Type of memory to allocate.
    364   @param  Pages                 The number of pages to allocate.
    365   @param  Memory                Pointer of memory allocated.
    366 
    367   @retval EFI_SUCCESS           The memory range was successfully allocated.
    368   @retval EFI_INVALID_PARAMETER Type is not equal to AllocateAnyPages.
    369   @retval EFI_NOT_AVAILABLE_YET Called with permanent memory not available.
    370   @retval EFI_OUT_OF_RESOURCES  The pages could not be allocated.
    371 
    372 **/
    373 EFI_STATUS
    374 EFIAPI
    375 PeiServicesAllocatePages (
    376   IN EFI_MEMORY_TYPE            MemoryType,
    377   IN UINTN                      Pages,
    378   OUT EFI_PHYSICAL_ADDRESS      *Memory
    379   )
    380 {
    381   CONST EFI_PEI_SERVICES **PeiServices;
    382 
    383   PeiServices = GetPeiServicesTablePointer ();
    384   return (*PeiServices)->AllocatePages (PeiServices, MemoryType, Pages, Memory);
    385 }
    386 
    387 /**
    388   This service allocates memory from the Hand-Off Block (HOB) heap.
    389 
    390   @param  Size                  The number of bytes to allocate from the pool.
    391   @param  Buffer                If the call succeeds, a pointer to a pointer to
    392                                 the allocate buffer; otherwise, undefined.
    393 
    394   @retval EFI_SUCCESS           The allocation was successful
    395   @retval EFI_OUT_OF_RESOURCES  There is not enough heap to allocate the requested size.
    396 
    397 **/
    398 EFI_STATUS
    399 EFIAPI
    400 PeiServicesAllocatePool (
    401   IN UINTN                      Size,
    402   OUT VOID                      **Buffer
    403   )
    404 {
    405   CONST EFI_PEI_SERVICES **PeiServices;
    406 
    407   PeiServices = GetPeiServicesTablePointer ();
    408   return (*PeiServices)->AllocatePool (PeiServices, Size, Buffer);
    409 }
    410 
    411 /**
    412   Resets the entire platform.
    413 
    414   @retval EFI_SUCCESS           The function completed successfully.
    415   @retval EFI_NOT_AVAILABLE_YET The service has not been installed yet.
    416 
    417 **/
    418 EFI_STATUS
    419 EFIAPI
    420 PeiServicesResetSystem (
    421   VOID
    422   )
    423 {
    424   CONST EFI_PEI_SERVICES **PeiServices;
    425 
    426   PeiServices = GetPeiServicesTablePointer ();
    427   return (*PeiServices)->ResetSystem (PeiServices);
    428 }
    429 
    430 /**
    431   This service is a wrapper for the PEI Service RegisterForShadow(), except the
    432   pointer to the PEI Services Table has been removed.  See the Platform
    433   Initialization Pre-EFI Initialization Core Interface Specification for details.
    434 
    435   @param FileHandle             PEIM's file handle. Must be the currently
    436                                 executing PEIM.
    437 
    438   @retval EFI_SUCCESS           The PEIM was successfully registered for
    439                                 shadowing.
    440 
    441   @retval EFI_ALREADY_STARTED   The PEIM was previously
    442                                 registered for shadowing.
    443 
    444   @retval EFI_NOT_FOUND         The FileHandle does not refer to a
    445                                 valid file handle.
    446 **/
    447 EFI_STATUS
    448 EFIAPI
    449 PeiServicesRegisterForShadow (
    450   IN  EFI_PEI_FILE_HANDLE FileHandle
    451   )
    452 {
    453   return (*GetPeiServicesTablePointer())->RegisterForShadow (FileHandle);
    454 }
    455 
    456 /**
    457   This service is a wrapper for the PEI Service FfsGetFileInfo(), except the pointer to the PEI Services
    458   Table has been removed.  See the Platform Initialization Pre-EFI Initialization Core Interface
    459   Specification for details.
    460 
    461   @param FileHandle              The handle of the file.
    462 
    463   @param FileInfo                 Upon exit, points to the file's
    464                                   information.
    465 
    466   @retval EFI_SUCCESS             File information returned.
    467 
    468   @retval EFI_INVALID_PARAMETER   If FileHandle does not
    469                                   represent a valid file.
    470 
    471   @retval EFI_INVALID_PARAMETER   FileInfo is NULL.
    472 
    473 **/
    474 EFI_STATUS
    475 EFIAPI
    476 PeiServicesFfsGetFileInfo (
    477   IN CONST  EFI_PEI_FILE_HANDLE   FileHandle,
    478   OUT EFI_FV_FILE_INFO            *FileInfo
    479   )
    480 {
    481   return (*GetPeiServicesTablePointer())->FfsGetFileInfo (FileHandle, FileInfo);
    482 }
    483 
    484 /**
    485   This service is a wrapper for the PEI Service FfsGetFileInfo2(), except the pointer to the PEI Services
    486   Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
    487   Specification for details.
    488 
    489   @param FileHandle               The handle of the file.
    490   @param FileInfo                 Upon exit, points to the file's
    491                                   information.
    492 
    493   @retval EFI_SUCCESS             File information returned.
    494   @retval EFI_INVALID_PARAMETER   If FileHandle does not
    495                                   represent a valid file.
    496   @retval EFI_INVALID_PARAMETER   FileInfo is NULL.
    497 
    498 **/
    499 EFI_STATUS
    500 EFIAPI
    501 PeiServicesFfsGetFileInfo2 (
    502   IN CONST  EFI_PEI_FILE_HANDLE   FileHandle,
    503   OUT EFI_FV_FILE_INFO2           *FileInfo
    504   )
    505 {
    506   return (*GetPeiServicesTablePointer())->FfsGetFileInfo2 (FileHandle, FileInfo);
    507 }
    508 
    509 /**
    510   This service is a wrapper for the PEI Service FfsFindByName(), except the pointer to the PEI Services
    511   Table has been removed.  See the Platform Initialization Pre-EFI Initialization Core Interface
    512   Specification for details.
    513 
    514   @param FileName                 A pointer to the name of the file to
    515                                   find within the firmware volume.
    516 
    517   @param VolumeHandle             The firmware volume to search FileHandle
    518                                   Upon exit, points to the found file's
    519                                   handle or NULL if it could not be found.
    520   @param FileHandle               The pointer to found file handle
    521 
    522   @retval EFI_SUCCESS             File was found.
    523 
    524   @retval EFI_NOT_FOUND           File was not found.
    525 
    526   @retval EFI_INVALID_PARAMETER   VolumeHandle or FileHandle or
    527                                   FileName was NULL.
    528 
    529 **/
    530 EFI_STATUS
    531 EFIAPI
    532 PeiServicesFfsFindFileByName (
    533   IN CONST  EFI_GUID            *FileName,
    534   IN CONST  EFI_PEI_FV_HANDLE   VolumeHandle,
    535   OUT       EFI_PEI_FILE_HANDLE *FileHandle
    536   )
    537 {
    538   return (*GetPeiServicesTablePointer())->FfsFindFileByName (FileName, VolumeHandle, FileHandle);
    539 }
    540 
    541 
    542 /**
    543   This service is a wrapper for the PEI Service FfsGetVolumeInfo(), except the pointer to the PEI Services
    544   Table has been removed.  See the Platform Initialization Pre-EFI Initialization Core Interface
    545   Specification for details.
    546 
    547   @param VolumeHandle             Handle of the volume.
    548 
    549   @param VolumeInfo               Upon exit, points to the volume's
    550                                   information.
    551 
    552   @retval EFI_SUCCESS             File information returned.
    553 
    554   @retval EFI_INVALID_PARAMETER   If FileHandle does not
    555                                   represent a valid file.
    556 
    557   @retval EFI_INVALID_PARAMETER   If FileInfo is NULL.
    558 
    559 **/
    560 EFI_STATUS
    561 EFIAPI
    562 PeiServicesFfsGetVolumeInfo (
    563   IN  EFI_PEI_FV_HANDLE       VolumeHandle,
    564   OUT EFI_FV_INFO             *VolumeInfo
    565   )
    566 {
    567   return (*GetPeiServicesTablePointer())->FfsGetVolumeInfo (VolumeHandle, VolumeInfo);
    568 }
    569 
    570 /**
    571   Install a EFI_PEI_FIRMWARE_VOLUME_INFO(2)_PPI instance so the PEI Core will be notified about a new firmware volume.
    572 
    573   This function allocates, initializes, and installs a new EFI_PEI_FIRMWARE_VOLUME_INFO(2)_PPI using
    574   the parameters passed in to initialize the fields of the EFI_PEI_FIRMWARE_VOLUME_INFO(2)_PPI instance.
    575   If the resources can not be allocated for EFI_PEI_FIRMWARE_VOLUME_INFO(2)_PPI, then ASSERT().
    576   If the EFI_PEI_FIRMWARE_VOLUME_INFO(2)_PPI can not be installed, then ASSERT().
    577   If NULL is specified for FvFormat, but FvInfo does not have the firmware file system 2 format, then ASSERT.
    578 
    579   @param  InstallFvInfoPpi     Install FvInfo Ppi if it is TRUE. Otherwise, install FvInfo2 Ppi.
    580   @param  FvFormat             Unique identifier of the format of the memory-mapped
    581                                firmware volume.  This parameter is optional and
    582                                may be NULL.  If NULL is specified, the
    583                                EFI_FIRMWARE_FILE_SYSTEM2_GUID format is assumed.
    584   @param  FvInfo               Points to a buffer which allows the
    585                                EFI_PEI_FIRMWARE_VOLUME_PPI to process the volume.
    586                                The format of this buffer is specific to the FvFormat.
    587                                For memory-mapped firmware volumes, this typically
    588                                points to the first byte of the firmware volume.
    589   @param  FvInfoSize           The size, in bytes, of FvInfo. For memory-mapped
    590                                firmware volumes, this is typically the size of
    591                                the firmware volume.
    592   @param  ParentFvName         If the new firmware volume originated from a file
    593                                in a different firmware volume, then this parameter
    594                                specifies the GUID name of the originating firmware
    595                                volume. Otherwise, this parameter must be NULL.
    596   @param  ParentFileName       If the new firmware volume originated from a file
    597                                in a different firmware volume, then this parameter
    598                                specifies the GUID file name of the originating
    599                                firmware file. Otherwise, this parameter must be NULL.
    600   @param  AuthenticationStatus Authentication Status, it will be ignored if InstallFvInfoPpi is TRUE.
    601 **/
    602 VOID
    603 EFIAPI
    604 InternalPeiServicesInstallFvInfoPpi (
    605   IN       BOOLEAN                 InstallFvInfoPpi,
    606   IN CONST EFI_GUID                *FvFormat, OPTIONAL
    607   IN CONST VOID                    *FvInfo,
    608   IN       UINT32                  FvInfoSize,
    609   IN CONST EFI_GUID                *ParentFvName, OPTIONAL
    610   IN CONST EFI_GUID                *ParentFileName, OPTIONAL
    611   IN       UINT32                  AuthenticationStatus
    612   )
    613 {
    614   EFI_STATUS                       Status;
    615   EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *FvInfoPpi;
    616   EFI_PEI_PPI_DESCRIPTOR           *FvInfoPpiDescriptor;
    617   EFI_GUID                         *ParentFvNameValue;
    618   EFI_GUID                         *ParentFileNameValue;
    619   EFI_GUID                         *PpiGuid;
    620 
    621   ParentFvNameValue   = NULL;
    622   ParentFileNameValue = NULL;
    623   if (InstallFvInfoPpi) {
    624     //
    625     // To install FvInfo Ppi.
    626     //
    627     FvInfoPpi = AllocateZeroPool (sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI));
    628     ASSERT (FvInfoPpi != NULL);
    629     PpiGuid = &gEfiPeiFirmwareVolumeInfoPpiGuid;
    630   } else {
    631     //
    632     // To install FvInfo2 Ppi.
    633     //
    634     FvInfoPpi = AllocateZeroPool (sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI));
    635     ASSERT (FvInfoPpi != NULL);
    636     ((EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI *) FvInfoPpi)->AuthenticationStatus = AuthenticationStatus;
    637     PpiGuid = &gEfiPeiFirmwareVolumeInfo2PpiGuid;
    638   }
    639 
    640   if (FvFormat != NULL) {
    641     CopyGuid (&FvInfoPpi->FvFormat, FvFormat);
    642   } else {
    643     CopyGuid (&FvInfoPpi->FvFormat, &gEfiFirmwareFileSystem2Guid);
    644     //
    645     // Since the EFI_FIRMWARE_FILE_SYSTEM2_GUID format is assumed if NULL is specified for FvFormat,
    646     // check the FileSystemGuid pointed by FvInfo against EFI_FIRMWARE_FILE_SYSTEM2_GUID to make sure
    647     // FvInfo has the firmware file system 2 format.
    648     // If the ASSERT really appears, FvFormat needs to be specified correctly, for example,
    649     // EFI_FIRMWARE_FILE_SYSTEM3_GUID can be used for firmware file system 3 format, or
    650     // ((EFI_FIRMWARE_VOLUME_HEADER *) FvInfo)->FileSystemGuid can be just used for both
    651     // firmware file system 2 and 3 format.
    652     //
    653     ASSERT (CompareGuid (&(((EFI_FIRMWARE_VOLUME_HEADER *) FvInfo)->FileSystemGuid), &gEfiFirmwareFileSystem2Guid));
    654   }
    655   FvInfoPpi->FvInfo = (VOID *) FvInfo;
    656   FvInfoPpi->FvInfoSize = FvInfoSize;
    657   if (ParentFvName != NULL) {
    658     ParentFvNameValue = AllocateCopyPool (sizeof (EFI_GUID), ParentFvName);
    659     ASSERT (ParentFvNameValue != NULL);
    660     FvInfoPpi->ParentFvName = ParentFvNameValue;
    661   }
    662   if (ParentFileName != NULL) {
    663     ParentFileNameValue = AllocateCopyPool (sizeof (EFI_GUID), ParentFileName);
    664     ASSERT (ParentFileNameValue != NULL);
    665     FvInfoPpi->ParentFileName = ParentFileNameValue;
    666   }
    667 
    668   FvInfoPpiDescriptor = AllocatePool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
    669   ASSERT (FvInfoPpiDescriptor != NULL);
    670 
    671   FvInfoPpiDescriptor->Guid  = PpiGuid;
    672   FvInfoPpiDescriptor->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
    673   FvInfoPpiDescriptor->Ppi   = (VOID *) FvInfoPpi;
    674   Status = PeiServicesInstallPpi (FvInfoPpiDescriptor);
    675   ASSERT_EFI_ERROR (Status);
    676 
    677 }
    678 
    679 /**
    680   Install a EFI_PEI_FIRMWARE_VOLUME_INFO_PPI instance so the PEI Core will be notified about a new firmware volume.
    681 
    682   This function allocates, initializes, and installs a new EFI_PEI_FIRMWARE_VOLUME_INFO_PPI using
    683   the parameters passed in to initialize the fields of the EFI_PEI_FIRMWARE_VOLUME_INFO_PPI instance.
    684   If the resources can not be allocated for EFI_PEI_FIRMWARE_VOLUME_INFO_PPI, then ASSERT().
    685   If the EFI_PEI_FIRMWARE_VOLUME_INFO_PPI can not be installed, then ASSERT().
    686   If NULL is specified for FvFormat, but FvInfo does not have the firmware file system 2 format, then ASSERT.
    687 
    688   @param  FvFormat             Unique identifier of the format of the memory-mapped
    689                                firmware volume.  This parameter is optional and
    690                                may be NULL.  If NULL is specified, the
    691                                EFI_FIRMWARE_FILE_SYSTEM2_GUID format is assumed.
    692   @param  FvInfo               Points to a buffer which allows the
    693                                EFI_PEI_FIRMWARE_VOLUME_PPI to process the volume.
    694                                The format of this buffer is specific to the FvFormat.
    695                                For memory-mapped firmware volumes, this typically
    696                                points to the first byte of the firmware volume.
    697   @param  FvInfoSize           The size, in bytes, of FvInfo. For memory-mapped
    698                                firmware volumes, this is typically the size of
    699                                the firmware volume.
    700   @param  ParentFvName         If the new firmware volume originated from a file
    701                                in a different firmware volume, then this parameter
    702                                specifies the GUID name of the originating firmware
    703                                volume. Otherwise, this parameter must be NULL.
    704   @param  ParentFileName       If the new firmware volume originated from a file
    705                                in a different firmware volume, then this parameter
    706                                specifies the GUID file name of the originating
    707                                firmware file. Otherwise, this parameter must be NULL.
    708 **/
    709 VOID
    710 EFIAPI
    711 PeiServicesInstallFvInfoPpi (
    712   IN CONST EFI_GUID                *FvFormat, OPTIONAL
    713   IN CONST VOID                    *FvInfo,
    714   IN       UINT32                  FvInfoSize,
    715   IN CONST EFI_GUID                *ParentFvName, OPTIONAL
    716   IN CONST EFI_GUID                *ParentFileName OPTIONAL
    717   )
    718 {
    719   InternalPeiServicesInstallFvInfoPpi (TRUE, FvFormat, FvInfo, FvInfoSize, ParentFvName, ParentFileName, 0);
    720 }
    721 
    722 /**
    723   Install a EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI instance so the PEI Core will be notified about a new firmware volume.
    724 
    725   This function allocates, initializes, and installs a new EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI using
    726   the parameters passed in to initialize the fields of the EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI instance.
    727   If the resources can not be allocated for EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI, then ASSERT().
    728   If the EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI can not be installed, then ASSERT().
    729   If NULL is specified for FvFormat, but FvInfo does not have the firmware file system 2 format, then ASSERT.
    730 
    731   @param  FvFormat             Unique identifier of the format of the memory-mapped
    732                                firmware volume.  This parameter is optional and
    733                                may be NULL.  If NULL is specified, the
    734                                EFI_FIRMWARE_FILE_SYSTEM2_GUID format is assumed.
    735   @param  FvInfo               Points to a buffer which allows the
    736                                EFI_PEI_FIRMWARE_VOLUME_PPI to process the volume.
    737                                The format of this buffer is specific to the FvFormat.
    738                                For memory-mapped firmware volumes, this typically
    739                                points to the first byte of the firmware volume.
    740   @param  FvInfoSize           The size, in bytes, of FvInfo. For memory-mapped
    741                                firmware volumes, this is typically the size of
    742                                the firmware volume.
    743   @param  ParentFvName         If the new firmware volume originated from a file
    744                                in a different firmware volume, then this parameter
    745                                specifies the GUID name of the originating firmware
    746                                volume. Otherwise, this parameter must be NULL.
    747   @param  ParentFileName       If the new firmware volume originated from a file
    748                                in a different firmware volume, then this parameter
    749                                specifies the GUID file name of the originating
    750                                firmware file. Otherwise, this parameter must be NULL.
    751   @param  AuthenticationStatus Authentication Status
    752 **/
    753 VOID
    754 EFIAPI
    755 PeiServicesInstallFvInfo2Ppi (
    756   IN CONST EFI_GUID                *FvFormat, OPTIONAL
    757   IN CONST VOID                    *FvInfo,
    758   IN       UINT32                  FvInfoSize,
    759   IN CONST EFI_GUID                *ParentFvName, OPTIONAL
    760   IN CONST EFI_GUID                *ParentFileName, OPTIONAL
    761   IN       UINT32                  AuthenticationStatus
    762   )
    763 {
    764   InternalPeiServicesInstallFvInfoPpi (FALSE, FvFormat, FvInfo, FvInfoSize, ParentFvName, ParentFileName, AuthenticationStatus);
    765 }
    766 
    767