/** @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
#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
#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
} 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
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
//\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
\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
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
\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
\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
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
\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
\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
\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
@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
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
@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
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
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
\r
/**\r
\r
- Initialize PeiCore Fv List.\r
+ Initialize PeiCore FV List.\r
\r
\r
@param PrivateData - Pointer to PEI_CORE_INSTANCE.\r
);\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
**/\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
);\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
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
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
);\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
);\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