]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/PeiMain.h
MdeModulePkg: Change OPTIONAL keyword usage style
[mirror_edk2.git] / MdeModulePkg / Core / Pei / PeiMain.h
index 322e7cd84524b9c6029cfc531ac5de8504e6e160..196944ca21008b9d798c8633b57cbbf79b55338a 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   Definition of Pei Core Structures and Services\r
 \r
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -31,6 +25,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Ppi/TemporaryRamSupport.h>\r
 #include <Ppi/TemporaryRamDone.h>\r
 #include <Ppi/SecHobData.h>\r
+#include <Ppi/PeiCoreFvLocation.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/PeiCoreEntryPoint.h>\r
 #include <Library/BaseLib.h>\r
@@ -49,10 +44,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Guid/FirmwareFileSystem2.h>\r
 #include <Guid/FirmwareFileSystem3.h>\r
 #include <Guid/AprioriFileName.h>\r
+#include <Guid/MigratedFvInfo.h>\r
 \r
 ///\r
 /// It is an FFS type extension used for PeiFindFileEx. It indicates current\r
-/// Ffs searching is for all PEIMs can be dispatched by PeiCore.\r
+/// FFS searching is for all PEIMs can be dispatched by PeiCore.\r
 ///\r
 #define PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE   0xff\r
 \r
@@ -121,7 +117,7 @@ typedef struct {
 } PEI_PPI_DATABASE;\r
 \r
 //\r
-// PEI_CORE_FV_HANDE.PeimState\r
+// PEI_CORE_FV_HANDLE.PeimState\r
 // Do not change these values as there is code doing math to change states.\r
 // Look for Private->Fv[FvCount].PeimState[PeimCount]++;\r
 //\r
@@ -141,11 +137,11 @@ typedef struct {
   EFI_PEI_FV_HANDLE                   FvHandle;\r
   UINTN                               PeimCount;\r
   //\r
-  // Ponter to the buffer with the PeimCount number of Entries.\r
+  // Pointer to the buffer with the PeimCount number of Entries.\r
   //\r
   UINT8                               *PeimState;\r
   //\r
-  // Ponter to the buffer with the PeimCount number of Entries.\r
+  // Pointer to the buffer with the PeimCount number of Entries.\r
   //\r
   EFI_PEI_FILE_HANDLE                 *FvFileHandles;\r
   BOOLEAN                             ScanFv;\r
@@ -282,12 +278,12 @@ struct _PEI_CORE_INSTANCE {
   //\r
   // For Loading modules at fixed address feature to cache the top address below which the\r
   // Runtime code, boot time code and PEI memory will be placed. Please note that the offset between this field\r
-  // and  Ps should not be changed since maybe user could get this top address by using the offet to Ps.\r
+  // and Ps should not be changed since maybe user could get this top address by using the offset to Ps.\r
   //\r
   EFI_PHYSICAL_ADDRESS               LoadModuleAtFixAddressTopAddress;\r
   //\r
   // The field is define for Loading modules at fixed address feature to tracker the PEI code\r
-  // memory range usage. It is a bit mapped array in which every bit indicates the correspoding memory page\r
+  // memory range usage. It is a bit mapped array in which every bit indicates the corresponding memory page\r
   // available or not.\r
   //\r
   UINT64                            *PeiCodeMemoryRangeUsageBitMap;\r
@@ -377,7 +373,7 @@ PeiCore (
 \r
   This is the POSTFIX version of the dependency evaluator.  When a\r
   PUSH [PPI GUID] is encountered, a pointer to the GUID is stored on\r
-  the evaluation stack.  When that entry is poped from the evaluation\r
+  the evaluation stack.  When that entry is popped from the evaluation\r
   stack, the PPI is checked if it is installed.  This method allows\r
   some time savings as not all PPIs must be checked for certain\r
   operation types (AND, OR).\r
@@ -399,6 +395,41 @@ PeimDispatchReadiness (
   IN VOID               *DependencyExpression\r
   );\r
 \r
+/**\r
+  Migrate a PEIM from temporary RAM to permanent memory.\r
+\r
+  @param PeimFileHandle       Pointer to the FFS file header of the image.\r
+  @param MigratedFileHandle   Pointer to the FFS file header of the migrated image.\r
+\r
+  @retval EFI_SUCCESS         Sucessfully migrated the PEIM to permanent memory.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MigratePeim (\r
+  IN  EFI_PEI_FILE_HANDLE     FileHandle,\r
+  IN  EFI_PEI_FILE_HANDLE     MigratedFileHandle\r
+  );\r
+\r
+/**\r
+  Migrate FVs out of temporary RAM before the cache is flushed.\r
+\r
+  @param Private         PeiCore's private data structure\r
+  @param SecCoreData     Points to a data structure containing information about the PEI core's operating\r
+                         environment, such as the size and location of temporary RAM, the stack location and\r
+                         the BFV location.\r
+\r
+  @retval EFI_SUCCESS           Successfully migrated installed FVs from temporary RAM to permanent memory.\r
+  @retval EFI_OUT_OF_RESOURCES  Insufficient memory exists to allocate needed pages.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EvacuateTempRam (\r
+  IN PEI_CORE_INSTANCE            *Private,\r
+  IN CONST EFI_SEC_PEI_HAND_OFF   *SecCoreData\r
+  );\r
+\r
 /**\r
   Conduct PEIM dispatch.\r
 \r
@@ -417,7 +448,7 @@ PeiDispatcher (
 \r
   @param PrivateData     PeiCore's private data structure\r
   @param OldCoreData     Old data from SecCore\r
-                         NULL if being run in non-permament memory mode.\r
+                         NULL if being run in non-permanent memory mode.\r
   @param SecCoreData     Points to a data structure containing SEC to PEI handoff data, such as the size\r
                          and location of temporary RAM, the stack location and the BFV location.\r
 \r
@@ -458,7 +489,7 @@ DepexSatisfied (
 \r
   @param PrivateData     Pointer to the PEI Core data.\r
   @param OldCoreData     Pointer to old PEI Core data.\r
-                         NULL if being run in non-permament memory mode.\r
+                         NULL if being run in non-permanent memory mode.\r
 \r
 **/\r
 VOID\r
@@ -482,12 +513,56 @@ ConvertPpiPointers (
   IN PEI_CORE_INSTANCE           *PrivateData\r
   );\r
 \r
+/**\r
+\r
+  Migrate Notify Pointers inside an FV from temporary memory to permanent memory.\r
+\r
+  @param PrivateData      Pointer to PeiCore's private data structure.\r
+  @param OrgFvHandle      Address of FV Handle in temporary memory.\r
+  @param FvHandle         Address of FV Handle in permanent memory.\r
+  @param FvSize           Size of the FV.\r
+\r
+**/\r
+VOID\r
+ConvertPpiPointersFv (\r
+  IN  PEI_CORE_INSTANCE       *PrivateData,\r
+  IN  UINTN                   OrgFvHandle,\r
+  IN  UINTN                   FvHandle,\r
+  IN  UINTN                   FvSize\r
+  );\r
+\r
+/**\r
+\r
+  Migrate PPI Pointers of PEI_CORE from temporary memory to permanent memory.\r
+\r
+  @param PrivateData      Pointer to PeiCore's private data structure.\r
+  @param CoreFvHandle     Address of PEI_CORE FV Handle in temporary memory.\r
+\r
+**/\r
+VOID\r
+ConvertPeiCorePpiPointers (\r
+  IN  PEI_CORE_INSTANCE        *PrivateData,\r
+  IN  PEI_CORE_FV_HANDLE       *CoreFvHandle\r
+  );\r
+\r
+/**\r
+\r
+  Dumps the PPI lists to debug output.\r
+\r
+  @param PrivateData     Points to PeiCore's private instance data.\r
+\r
+**/\r
+VOID\r
+DumpPpiList (\r
+  IN PEI_CORE_INSTANCE    *PrivateData\r
+  );\r
+\r
 /**\r
 \r
   Install PPI services. It is implementation of EFI_PEI_SERVICE.InstallPpi.\r
 \r
   @param PeiServices                An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
-  @param PpiList                    Pointer to ppi array that want to be installed.\r
+  @param PpiList                    Pointer to PPI array that want to be installed.\r
 \r
   @retval EFI_SUCCESS               if all PPIs in PpiList are successfully installed.\r
   @retval EFI_INVALID_PARAMETER     if PpiList is NULL pointer\r
@@ -560,7 +635,7 @@ PeiLocatePpi (
 \r
   @retval EFI_SUCCESS           if successful\r
   @retval EFI_OUT_OF_RESOURCES  if no space in the database\r
-  @retval EFI_INVALID_PARAMETER if not a good decriptor\r
+  @retval EFI_INVALID_PARAMETER if not a good descriptor\r
 \r
 **/\r
 EFI_STATUS\r
@@ -664,7 +739,7 @@ PeiSetBootMode (
 \r
   @param PeiServices     An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
   @param OldCoreData     Pointer to the old core data.\r
-                         NULL if being run in non-permament memory mode.\r
+                         NULL if being run in non-permanent memory mode.\r
 \r
 **/\r
 VOID\r
@@ -692,7 +767,7 @@ VerifyFv (
 \r
   @param PrivateData     PeiCore's private data structure\r
   @param VolumeHandle    Handle of FV\r
-  @param FileHandle      Handle of PEIM's ffs\r
+  @param FileHandle      Handle of PEIM's FFS\r
   @param AuthenticationStatus Authentication status\r
 \r
   @retval EFI_SUCCESS              Image is OK\r
@@ -735,7 +810,7 @@ PeiGetHobList (
   @param Length             Length of the new HOB to allocate.\r
   @param Hob                Pointer to the new HOB.\r
 \r
-  @return  EFI_SUCCESS           Success to create hob.\r
+  @return  EFI_SUCCESS           Success to create HOB.\r
   @retval  EFI_INVALID_PARAMETER if Hob is NULL\r
   @retval  EFI_NOT_AVAILABLE_YET if HobList is still not available.\r
   @retval  EFI_OUT_OF_RESOURCES  if there is no more memory to grow the Hoblist.\r
@@ -813,6 +888,37 @@ PeiFfsFindNextFile (
   IN OUT EFI_PEI_FILE_HANDLE     *FileHandle\r
   );\r
 \r
+/**\r
+  Go through the file to search SectionType section.\r
+  Search within encapsulation sections (compression and GUIDed) recursively,\r
+  until the match section is found.\r
+\r
+  @param PeiServices          An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
+  @param SectionType          Filter to find only section of this type.\r
+  @param SectionInstance      Pointer to the filter to find the specific instance of section.\r
+  @param Section              From where to search.\r
+  @param SectionSize          The file size to search.\r
+  @param OutputBuffer         A pointer to the discovered section, if successful.\r
+                              NULL if section not found.\r
+  @param AuthenticationStatus Updated upon return to point to the authentication status for this section.\r
+  @param IsFfs3Fv             Indicates the FV format.\r
+\r
+  @return EFI_NOT_FOUND       The match section is not found.\r
+  @return EFI_SUCCESS         The match section is found.\r
+\r
+**/\r
+EFI_STATUS\r
+ProcessSection (\r
+  IN CONST EFI_PEI_SERVICES     **PeiServices,\r
+  IN EFI_SECTION_TYPE           SectionType,\r
+  IN OUT UINTN                  *SectionInstance,\r
+  IN EFI_COMMON_SECTION_HEADER  *Section,\r
+  IN UINTN                      SectionSize,\r
+  OUT VOID                      **OutputBuffer,\r
+  OUT UINT32                    *AuthenticationStatus,\r
+  IN BOOLEAN                    IsFfs3Fv\r
+  );\r
+\r
 /**\r
   Searches for the next matching section within the specified file.\r
 \r
@@ -892,7 +998,7 @@ PeiFfsFindNextVolume (
   @param SecCoreData     Points to a data structure containing SEC to PEI handoff data, such as the size\r
                          and location of temporary RAM, the stack location and the BFV location.\r
   @param OldCoreData     Pointer to the PEI Core data.\r
-                         NULL if being run in non-permament memory mode.\r
+                         NULL if being run in non-permanent memory mode.\r
 \r
 **/\r
 VOID\r
@@ -936,6 +1042,33 @@ MigrateMemoryPages (
   IN BOOLEAN                TemporaryRamMigrated\r
   );\r
 \r
+/**\r
+  Removes any FV HOBs whose base address is not in PEI installed memory.\r
+\r
+  @param[in] Private          Pointer to PeiCore's private data structure.\r
+\r
+**/\r
+VOID\r
+RemoveFvHobsInTemporaryMemory (\r
+  IN PEI_CORE_INSTANCE        *Private\r
+  );\r
+\r
+/**\r
+  Migrate the base address in firmware volume allocation HOBs\r
+  from temporary memory to PEI installed memory.\r
+\r
+  @param[in] PrivateData      Pointer to PeiCore's private data structure.\r
+  @param[in] OrgFvHandle      Address of FV Handle in temporary memory.\r
+  @param[in] FvHandle         Address of FV Handle in permanent memory.\r
+\r
+**/\r
+VOID\r
+ConvertFvHob (\r
+  IN PEI_CORE_INSTANCE          *PrivateData,\r
+  IN UINTN                      OrgFvHandle,\r
+  IN UINTN                      FvHandle\r
+  );\r
+\r
 /**\r
   Migrate MemoryBaseAddress in memory allocation HOBs\r
   from the temporary memory to PEI installed memory.\r
@@ -1102,9 +1235,7 @@ PeiResetSystem (
                             the data buffer starts with a Null-terminated string, optionally\r
                             followed by additional binary data. The string is a description\r
                             that the caller may use to further indicate the reason for the\r
-                            system reset. ResetData is only valid if ResetStatus is something\r
-                            other than EFI_SUCCESS unless the ResetType is EfiResetPlatformSpecific\r
-                            where a minimum amount of ResetData is always required.\r
+                            system reset.\r
 \r
 **/\r
 VOID\r
@@ -1118,7 +1249,7 @@ PeiResetSystem2 (
 \r
 /**\r
 \r
-  Initialize PeiCore Fv List.\r
+  Initialize PeiCore FV List.\r
 \r
 \r
   @param PrivateData     - Pointer to PEI_CORE_INSTANCE.\r
@@ -1132,7 +1263,7 @@ PeiInitializeFv (
   );\r
 \r
 /**\r
-  Process Firmware Volum Information once FvInfoPPI install.\r
+  Process Firmware Volume Information once FvInfoPPI install.\r
 \r
   @param PeiServices       An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
   @param NotifyDescriptor  Address of the notification descriptor data structure.\r
@@ -1143,7 +1274,7 @@ PeiInitializeFv (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-FirmwareVolmeInfoPpiNotifyCallback (\r
+FirmwareVolumeInfoPpiNotifyCallback (\r
   IN EFI_PEI_SERVICES              **PeiServices,\r
   IN EFI_PEI_NOTIFY_DESCRIPTOR     *NotifyDescriptor,\r
   IN VOID                          *Ppi\r
@@ -1224,8 +1355,8 @@ PeiFfsGetVolumeInfo (
   );\r
 \r
 /**\r
-  This routine enable a PEIM to register itself to shadow when PEI Foundation\r
-  discovery permanent memory.\r
+  This routine enables a PEIM to register itself for shadow when the PEI Foundation\r
+  discovers permanent memory.\r
 \r
   @param FileHandle             File handle of a PEIM.\r
 \r
@@ -1256,6 +1387,38 @@ InitializeImageServices (
   IN  PEI_CORE_INSTANCE   *OldCoreData\r
   );\r
 \r
+/**\r
+  Loads and relocates a PE/COFF image in place.\r
+\r
+  @param Pe32Data         The base address of the PE/COFF file that is to be loaded and relocated\r
+  @param ImageAddress     The base address of the relocated PE/COFF image\r
+\r
+  @retval EFI_SUCCESS     The file was loaded and relocated\r
+  @retval Others          The file not be loaded and error occurred.\r
+\r
+**/\r
+EFI_STATUS\r
+LoadAndRelocatePeCoffImageInPlace (\r
+  IN  VOID    *Pe32Data,\r
+  IN  VOID    *ImageAddress\r
+  );\r
+\r
+/**\r
+  Find the PE32 Data for an FFS file.\r
+\r
+  @param FileHandle       Pointer to the FFS file header of the image.\r
+  @param Pe32Data         Pointer to a (VOID *) PE32 Data pointer.\r
+\r
+  @retval EFI_SUCCESS      Image is successfully loaded.\r
+  @retval EFI_NOT_FOUND    Fail to locate PE32 Data.\r
+\r
+**/\r
+EFI_STATUS\r
+PeiGetPe32Data (\r
+  IN     EFI_PEI_FILE_HANDLE          FileHandle,\r
+  OUT    VOID                         **Pe32Data\r
+  );\r
+\r
 /**\r
   The wrapper function of PeiLoadImageLoadImage().\r
 \r
@@ -1274,8 +1437,8 @@ EFIAPI
 PeiLoadImageLoadImageWrapper (\r
   IN     CONST EFI_PEI_LOAD_FILE_PPI  *This,\r
   IN     EFI_PEI_FILE_HANDLE          FileHandle,\r
-  OUT    EFI_PHYSICAL_ADDRESS         *ImageAddressArg,  OPTIONAL\r
-  OUT    UINT64                       *ImageSizeArg,     OPTIONAL\r
+  OUT    EFI_PHYSICAL_ADDRESS         *ImageAddressArg   OPTIONAL,\r
+  OUT    UINT64                       *ImageSizeArg      OPTIONAL,\r
   OUT    EFI_PHYSICAL_ADDRESS         *EntryPoint,\r
   OUT    UINT32                       *AuthenticationState\r
   );\r
@@ -1300,11 +1463,11 @@ SecurityPpiNotifyCallback (
   );\r
 \r
 /**\r
-  Get Fv image(s) from the FV type file, then install FV INFO(2) ppi, Build FV(2, 3) hob.\r
+  Get FV image(s) from the FV type file, then install FV INFO(2) PPI, Build FV(2, 3) HOB.\r
 \r
   @param PrivateData          PeiCore's private data structure\r
-  @param ParentFvCoreHandle   Pointer of EFI_CORE_FV_HANDLE to parent Fv image that contain this Fv image.\r
-  @param ParentFvFileHandle   File handle of a Fv type file that contain this Fv image.\r
+  @param ParentFvCoreHandle   Pointer of EFI_CORE_FV_HANDLE to parent FV image that contain this FV image.\r
+  @param ParentFvFileHandle   File handle of a FV type file that contain this FV image.\r
 \r
   @retval EFI_NOT_FOUND         FV image can't be found.\r
   @retval EFI_SUCCESS           Successfully to process it.\r
@@ -1321,12 +1484,13 @@ ProcessFvFile (
   );\r
 \r
 /**\r
-  Get instance of PEI_CORE_FV_HANDLE for next volume according to given index.\r
+  Gets a PEI_CORE_FV_HANDLE instance for the next volume according to the given index.\r
 \r
-  This routine also will install FvInfo ppi for FV hob in PI ways.\r
+  This routine also will install an instance of the FvInfo PPI for the FV HOB\r
+  as defined in the PI specification.\r
 \r
   @param Private    Pointer of PEI_CORE_INSTANCE\r
-  @param Instance   The index of FV want to be searched.\r
+  @param Instance   Index of the FV to search\r
 \r
   @return Instance of PEI_CORE_FV_HANDLE.\r
 **/\r