From 40f26b8f443f271f0b6d9df3c0214df4269b7485 Mon Sep 17 00:00:00 2001 From: klu2 Date: Wed, 23 Jul 2008 09:15:14 +0000 Subject: [PATCH] Code scrub for PeiCore module. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5558 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Core/Pei/Dependency/Dependency.c | 1 - MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 16 +++++++- MdeModulePkg/Core/Pei/FwVol/FwVol.c | 32 +++++----------- MdeModulePkg/Core/Pei/Hob/Hob.c | 31 +++++++-------- MdeModulePkg/Core/Pei/Memory/MemoryServices.c | 6 ++- MdeModulePkg/Core/Pei/PeiMain.h | 38 +++++++++---------- MdeModulePkg/Core/Pei/PeiMain.inf | 13 +++---- MdeModulePkg/Core/Pei/PeiMain/PeiMain.c | 24 +++++++++--- MdeModulePkg/Core/Pei/Ppi/Ppi.c | 16 ++------ MdeModulePkg/Core/Pei/Security/Security.c | 6 +-- MdeModulePkg/Core/Pei/StatusCode/StatusCode.c | 3 +- 11 files changed, 91 insertions(+), 95 deletions(-) diff --git a/MdeModulePkg/Core/Pei/Dependency/Dependency.c b/MdeModulePkg/Core/Pei/Dependency/Dependency.c index 9ce8b4a34d..cbdbe35b1e 100644 --- a/MdeModulePkg/Core/Pei/Dependency/Dependency.c +++ b/MdeModulePkg/Core/Pei/Dependency/Dependency.c @@ -229,7 +229,6 @@ PeimDispatchReadiness ( // The grammar should never arrive here // return FALSE; - break; } } } diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c index f18e954f2a..53bbecd5bc 100644 --- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c @@ -481,11 +481,19 @@ PeiDispatcher ( // CAUTION: The new base is computed accounding to gap of new stack. // NewPermenentMemoryBase = Private->PhysicalMemoryBegin + StackGap; + + // + // Caculate stack offset and heap offset between CAR and new permement + // memory seperately. + // StackOffset = (UINTN) NewPermenentMemoryBase - (UINTN) SecCoreData->StackBase; HeapOffset = (INTN) ((UINTN) Private->PhysicalMemoryBegin + Private->StackSize - \ (UINTN) SecCoreData->PeiTemporaryRamBase); DEBUG ((EFI_D_INFO, "Heap Offset = 0x%X Stack Offset = 0x%X\n", HeapOffset, StackOffset)); + // + // Caculate new HandOffTable and PrivateData address in permenet memory's stack + // NewHandOffTable = (EFI_HOB_HANDOFF_INFO_TABLE *)((UINTN)OldHandOffTable + HeapOffset); PrivateInMem = (PEI_CORE_INSTANCE *)((UINTN) (VOID*) Private + StackOffset); @@ -502,6 +510,12 @@ PeiDispatcher ( if (!EFI_ERROR (Status)) { + // + // Temporary Ram support Ppi is provided by platform, it will copy + // temporary memory to permenent memory and do stack switching. + // After invoken temporary Ram support, following code's stack is in + // memory but not in CAR. + // TemporaryRamSupportPpi->TemporaryRamMigration ( (CONST EFI_PEI_SERVICES **) PeiServices, (EFI_PHYSICAL_ADDRESS)(UINTN) SecCoreData->TemporaryRamBase, @@ -549,7 +563,7 @@ PeiDispatcher ( // // We need convert the PPI desciptor's pointer // - ConvertPpiPointers ((CONST EFI_PEI_SERVICES **)PeiServices, + ConvertPpiPointers (PrivateInMem, OldCheckingBottom, OldCheckingTop, HeapOffset diff --git a/MdeModulePkg/Core/Pei/FwVol/FwVol.c b/MdeModulePkg/Core/Pei/FwVol/FwVol.c index d5af3a0b1d..689e0953bd 100644 --- a/MdeModulePkg/Core/Pei/FwVol/FwVol.c +++ b/MdeModulePkg/Core/Pei/FwVol/FwVol.c @@ -10,14 +10,6 @@ http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module Name: - - FwVol.c - -Abstract: - - - **/ #include @@ -35,7 +27,6 @@ STATIC EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnFvInfoList = { /** Returns the highest bit set of the State field - @param ErasePolarity Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY in the Attributes field. @param FfsHeader Pointer to FFS File Header. @@ -222,8 +213,8 @@ PeiFindFileEx ( switch (FileState) { case EFI_FILE_HEADER_INVALID: - FileOffset += sizeof(EFI_FFS_FILE_HEADER); - FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + sizeof(EFI_FFS_FILE_HEADER)); + FileOffset += sizeof(EFI_FFS_FILE_HEADER); + FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + sizeof(EFI_FFS_FILE_HEADER)); break; case EFI_FILE_DATA_VALID: @@ -234,7 +225,7 @@ PeiFindFileEx ( return EFI_NOT_FOUND; } - FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF; + FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF; FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8); if (FileName != NULL) { @@ -262,15 +253,15 @@ PeiFindFileEx ( return EFI_SUCCESS; } - FileOffset += FileOccupiedSize; - FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize); + FileOffset += FileOccupiedSize; + FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize); break; case EFI_FILE_DELETED: - FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF; - FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8); - FileOffset += FileOccupiedSize; - FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize); + FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF; + FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8); + FileOffset += FileOccupiedSize; + FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize); break; default: @@ -284,15 +275,10 @@ PeiFindFileEx ( } /** - Initialize PeiCore Fv List. - @param PrivateData - Pointer to PEI_CORE_INSTANCE. @param SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF. - - @return NONE - **/ VOID PeiInitializeFv ( diff --git a/MdeModulePkg/Core/Pei/Hob/Hob.c b/MdeModulePkg/Core/Pei/Hob/Hob.c index aa38228bec..4eb4b9a892 100644 --- a/MdeModulePkg/Core/Pei/Hob/Hob.c +++ b/MdeModulePkg/Core/Pei/Hob/Hob.c @@ -18,7 +18,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Gets the pointer to the HOB List. - @param PeiServices The PEI core services table. @param HobList Pointer to the HOB List. @@ -35,7 +34,6 @@ PeiGetHobList ( ) { PEI_CORE_INSTANCE *PrivateData; - // // Only check this parameter in debug mode @@ -51,7 +49,6 @@ PeiGetHobList ( *HobList = PrivateData->HobList.Raw; - return EFI_SUCCESS; } @@ -59,10 +56,10 @@ PeiGetHobList ( /** Add a new HOB to the HOB List. - @param PeiServices - The PEI core services table. - @param Type - Type of the new HOB. - @param Length - Length of the new HOB to allocate. - @param Hob - Pointer to the new HOB. + @param PeiServices The PEI core services table. + @param Type Type of the new HOB. + @param Length Length of the new HOB to allocate. + @param Hob Pointer to the new HOB. @return EFI_SUCCESS Success to create hob. @retval EFI_INVALID_PARAMETER if Hob is NULL @@ -118,11 +115,9 @@ PeiCreateHob ( HobEnd++; HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd; - return EFI_SUCCESS; } - /** Builds a Handoff Information Table HOB @@ -144,15 +139,15 @@ PeiCoreBuildHobHandoffInfoTable ( EFI_HOB_HANDOFF_INFO_TABLE *Hob; EFI_HOB_GENERIC_HEADER *HobEnd; - Hob = (VOID *)(UINTN)MemoryBegin; - HobEnd = (EFI_HOB_GENERIC_HEADER*) (Hob+1); - Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF; - Hob->Header.HobLength = sizeof(EFI_HOB_HANDOFF_INFO_TABLE); - Hob->Header.Reserved = 0; + Hob = (VOID *)(UINTN)MemoryBegin; + HobEnd = (EFI_HOB_GENERIC_HEADER*) (Hob+1); + Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF; + Hob->Header.HobLength = sizeof(EFI_HOB_HANDOFF_INFO_TABLE); + Hob->Header.Reserved = 0; - HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST; - HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER); - HobEnd->Reserved = 0; + HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST; + HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER); + HobEnd->Reserved = 0; Hob->Version = EFI_HOB_HANDOFF_TABLE_VERSION; Hob->BootMode = BootMode; @@ -160,7 +155,7 @@ PeiCoreBuildHobHandoffInfoTable ( Hob->EfiMemoryTop = MemoryBegin + MemoryLength; Hob->EfiMemoryBottom = MemoryBegin; Hob->EfiFreeMemoryTop = MemoryBegin + MemoryLength; - Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) (HobEnd+1); + Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) (HobEnd + 1); Hob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd; return EFI_SUCCESS; diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c index 58c5d81517..de32b69bd2 100644 --- a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c +++ b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c @@ -37,6 +37,10 @@ InitializeMemoryServices ( PrivateData->SwitchStackSignal = FALSE; + // + // First entering PeiCore, following code will initialized some field + // in PeiCore's private data according to hand off data from sec core. + // if (OldCoreData == NULL) { PrivateData->PeiMemoryInstalled = FALSE; @@ -159,8 +163,6 @@ PeiAllocatePages ( FreeMemoryBottom = &(Hob.HandoffInformationTable->EfiFreeMemoryBottom); } - - // // Check to see if on 4k boundary // diff --git a/MdeModulePkg/Core/Pei/PeiMain.h b/MdeModulePkg/Core/Pei/PeiMain.h index 7f7ac196d6..3cd642ea4f 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.h +++ b/MdeModulePkg/Core/Pei/PeiMain.h @@ -58,6 +58,9 @@ typedef union { VOID *Raw; } PEI_PPI_LIST_POINTERS; +/// +/// PPI database structure +/// typedef struct { INTN PpiListEnd; INTN NotifyListEnd; @@ -94,12 +97,12 @@ typedef struct { UINTN SectionIndex; } CACHE_SECTION_DATA; -// -// Pei Core private data structure instance -// #define PEI_CORE_HANDLE_SIGNATURE EFI_SIGNATURE_32('P','e','i','C') +/// +/// Pei Core private data structure instance +/// typedef struct{ UINTN Signature; EFI_PEI_SERVICES *PS; // Point to ServiceTableShadow @@ -134,10 +137,9 @@ typedef struct{ CACHE_SECTION_DATA CacheSection; } PEI_CORE_INSTANCE; -// -// Pei Core Instance Data Macros -// - +/// +/// Pei Core Instance Data Macros +/// #define PEI_CORE_INSTANCE_FROM_PS_THIS(a) \ CR(a, PEI_CORE_INSTANCE, PS, PEI_CORE_HANDLE_SIGNATURE) @@ -266,8 +268,6 @@ PeiDispatcher ( environment, such as the size and location of temporary RAM, the stack location and the BFV location. - @return None. - **/ VOID InitializeDispatcherData ( @@ -305,7 +305,6 @@ DepexSatisfied ( Initialize PPI services. - @param PrivateData Pointer to the PEI Core data. @param OldCoreData Pointer to old PEI Core data. NULL if being run in non-permament memory mode. @@ -331,10 +330,10 @@ InitializePpiServices ( **/ VOID ConvertPpiPointers ( - IN CONST EFI_PEI_SERVICES **PeiServices, - IN UINTN OldCheckingBottom, - IN UINTN OldCheckingTop, - IN UINTN Fixup + IN PEI_CORE_INSTANCE *PrivateData, + IN UINTN OldCheckingBottom, + IN UINTN OldCheckingTop, + IN INTN Fixup ) ; @@ -512,9 +511,8 @@ PeiSetBootMode ( Initialize the security services. - - @param PeiServices - The PEI core services table. - @param OldCoreData - Pointer to the old core data. + @param PeiServices The PEI core services table. + @param OldCoreData Pointer to the old core data. NULL if being run in non-permament memory mode. **/ @@ -528,10 +526,10 @@ InitializeSecurityServices ( /** Verify a Firmware volume - @param CurrentFvAddress - Pointer to the current Firmware Volume under consideration + @param CurrentFvAddress Pointer to the current Firmware Volume under consideration - @retval EFI_SUCCESS - Firmware Volume is legal - @retval EFI_SECURITY_VIOLATION - Firmware Volume fails integrity test + @retval EFI_SUCCESS Firmware Volume is legal + @retval EFI_SECURITY_VIOLATION Firmware Volume fails integrity test **/ EFI_STATUS diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf b/MdeModulePkg/Core/Pei/PeiMain.inf index 09e380d628..af8e2acdac 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.inf +++ b/MdeModulePkg/Core/Pei/PeiMain.inf @@ -75,12 +75,12 @@ gEfiPeiStatusCodePpiGuid # PPI SOMETIMES_CONSUMED gEfiPeiResetPpiGuid # PPI SOMETIMES_CONSUMED gEfiDxeIplPpiGuid # PPI ALWAYS_CONSUMED - gEfiPeiMemoryDiscoveredPpiGuid # PPI ALWAYS_PRODUCED - gEfiPeiDecompressPpiGuid - gEfiPeiFirmwareVolumeInfoPpiGuid - gEfiPeiLoadFilePpiGuid - gEfiPeiSecurity2PpiGuid - gEfiTemporaryRamSupportPpiGuid + gEfiPeiMemoryDiscoveredPpiGuid # PPI ALWAYS_CONSUMED + gEfiPeiDecompressPpiGuid # PPI ALWAYS_CONSUMED + gEfiPeiFirmwareVolumeInfoPpiGuid # PPI ALWAYS_CONSUMED + gEfiPeiLoadFilePpiGuid # PPI ALWAYS_CONSUMED + gEfiPeiSecurity2PpiGuid # PPI ALWAYS_CONSUMED + gEfiTemporaryRamSupportPpiGuid # PPI ALWAYS_CONSUMED [FixedPcd.common] gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported @@ -90,7 +90,6 @@ gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValuePeiCoreEntry gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize - [FeaturePcd.common] gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreImageLoaderSearchTeSectionFirst diff --git a/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c b/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c index 056165e689..1524abf81c 100644 --- a/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c +++ b/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c @@ -20,10 +20,10 @@ STATIC EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = { NULL }; -// -// Pei Core Module Variables -// -// +/// +/// Pei Core Module Variables +/// +/// STATIC EFI_PEI_SERVICES gPs = { { PEI_SERVICES_SIGNATURE, @@ -107,12 +107,20 @@ PeiCore ( mTick = 0; OldCoreData = (PEI_CORE_INSTANCE *) Data; + // + // Record the system tick for first entering PeiCore. + // This tick is duration of executing platform seccore module. + // if (PerformanceMeasurementEnabled()) { if (OldCoreData == NULL) { mTick = GetPerformanceCounter (); } } + // + // PeiCore has been shadowed to memory for first entering, so + // just jump to PeiCore in memory here. + // if (OldCoreData != NULL) { ShadowedPeiCore = (PEI_CORE_ENTRY_POINT) (UINTN) OldCoreData->ShadowedPeiCore; if (ShadowedPeiCore != NULL) { @@ -143,7 +151,6 @@ PeiCore ( // // Initialize libraries that the PeiCore is linked against - // BUGBUG: The FileHandle is passed in as NULL. Do we look it up or remove it from the lib init? // ProcessLibraryConstructorList (NULL, &PrivateData.PS); @@ -213,6 +220,10 @@ PeiCore ( // ASSERT(PrivateData.PeiMemoryInstalled == TRUE); + // + // Till now, PEI phase will be finished, get performace count + // for computing duration of PEI phase + // PERF_END (NULL, "PostMem", NULL, 0); Status = PeiServicesLocatePpi ( @@ -223,6 +234,9 @@ PeiCore ( ); ASSERT_EFI_ERROR (Status); + // + // Enter DxeIpl to load Dxe core. + // DEBUG ((EFI_D_INFO, "DXE IPL Entry\n")); Status = TempPtr.DxeIpl->Entry ( TempPtr.DxeIpl, diff --git a/MdeModulePkg/Core/Pei/Ppi/Ppi.c b/MdeModulePkg/Core/Pei/Ppi/Ppi.c index b7a9b12321..28ddd99e3c 100644 --- a/MdeModulePkg/Core/Pei/Ppi/Ppi.c +++ b/MdeModulePkg/Core/Pei/Ppi/Ppi.c @@ -18,7 +18,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Initialize PPI services. - @param PrivateData Pointer to the PEI Core data. @param OldCoreData Pointer to old PEI Core data. NULL if being run in non-permament memory mode. @@ -50,18 +49,15 @@ InitializePpiServices ( **/ VOID ConvertPpiPointers ( - IN CONST EFI_PEI_SERVICES **PeiServices, - IN UINTN OldCheckingBottom, - IN UINTN OldCheckingTop, - IN UINTN Fixup + IN PEI_CORE_INSTANCE *PrivateData, + IN UINTN OldCheckingBottom, + IN UINTN OldCheckingTop, + IN INTN Fixup ) { - PEI_CORE_INSTANCE *PrivateData; UINT8 Index; PEI_PPI_LIST_POINTERS *PpiPointer; - PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices); - for (Index = 0; Index < FixedPcdGet32 (PcdPeiCoreMaxPpiSupported); Index++) { if (Index < PrivateData->PpiData.PpiListEnd || Index > PrivateData->PpiData.NotifyListEnd) { @@ -342,7 +338,6 @@ PeiLocatePpi ( Install a notification for a given PPI. - @param PeiServices - Pointer to the PEI Service Table @param NotifyList - Pointer to list of Descriptors to notify upon. @@ -451,7 +446,6 @@ PeiNotifyPpi ( PrivateData->PpiData.NotifyListEnd ); - return EFI_SUCCESS; } @@ -578,7 +572,5 @@ DispatchNotify ( } } } - - return; } diff --git a/MdeModulePkg/Core/Pei/Security/Security.c b/MdeModulePkg/Core/Pei/Security/Security.c index cf33447602..b7cc10058e 100644 --- a/MdeModulePkg/Core/Pei/Security/Security.c +++ b/MdeModulePkg/Core/Pei/Security/Security.c @@ -40,12 +40,10 @@ STATIC EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList = { }; /** - Initialize the security services. - - @param PeiServices - The PEI core services table. - @param OldCoreData - Pointer to the old core data. + @param PeiServices The PEI core services table. + @param OldCoreData Pointer to the old core data. NULL if being run in non-permament memory mode. **/ diff --git a/MdeModulePkg/Core/Pei/StatusCode/StatusCode.c b/MdeModulePkg/Core/Pei/StatusCode/StatusCode.c index 8e271d5e63..d39311c7a4 100644 --- a/MdeModulePkg/Core/Pei/StatusCode/StatusCode.c +++ b/MdeModulePkg/Core/Pei/StatusCode/StatusCode.c @@ -43,10 +43,9 @@ PeiReportStatusCode ( { EFI_STATUS Status; EFI_PEI_PROGRESS_CODE_PPI *StatusCodePpi; - // - //Locate StatusCode Ppi. + // Locate StatusCode Ppi. // Status = PeiServicesLocatePpi ( &gEfiPeiStatusCodePpiGuid, -- 2.39.2