X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FCore%2FPei%2FDispatcher%2FDispatcher.c;h=bdbb00b205f86dcec674c108743fe5a830811168;hp=3103fac03724b914cb72557d10cd823b0ac20744;hb=f3198cba84f56f85281b87c4e9bf96e77a934f16;hpb=90e128e28adcdcf2e236db7b26933aa16cbe645c diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c index 3103fac037..bdbb00b205 100644 --- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c @@ -1,7 +1,7 @@ /** @file EFI PEI Core dispatch services -Copyright (c) 2006 - 2009, Intel Corporation +Copyright (c) 2006 - 2010, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -15,7 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "PeiMain.h" /// -/// CAR is filled with this initial value during SEC phase +/// temporary memory is filled with this initial value during SEC phase /// #define INIT_CAR_VALUE 0x5AA55AA5 @@ -30,14 +30,14 @@ typedef struct { Apriori file in one FV. - @param Private - Pointer to the private data passed in from caller - @param VolumeHandle - Fv handle. + @param Private Pointer to the private data passed in from caller + @param CoreFileHandle The instance of PEI_CORE_FV_HANDLE. **/ VOID DiscoverPeimsAndOrderWithApriori ( IN PEI_CORE_INSTANCE *Private, - IN EFI_PEI_FV_HANDLE VolumeHandle + IN PEI_CORE_FV_HANDLE *CoreFileHandle ) { EFI_STATUS Status; @@ -51,7 +51,11 @@ DiscoverPeimsAndOrderWithApriori ( EFI_GUID *Guid; EFI_PEI_FV_HANDLE TempFileHandles[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)]; EFI_GUID FileGuid[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)]; - + EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi; + EFI_FV_FILE_INFO FileInfo; + + FvPpi = CoreFileHandle->FvPpi; + // // Walk the FV and find all the PEIMs and the Apriori file. // @@ -71,33 +75,39 @@ DiscoverPeimsAndOrderWithApriori ( // // Go ahead to scan this Fv, and cache FileHandles within it. // - for (PeimCount = 0; PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv); PeimCount++) { - Status = PeiFindFileEx ( - VolumeHandle, - NULL, - PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE, - &FileHandle, - &AprioriFileHandle - ); + for (PeimCount = 0; PeimCount < PcdGet32 (PcdPeiCoreMaxPeimPerFv); PeimCount++) { + Status = FvPpi->FindFileByType (FvPpi, PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE, CoreFileHandle->FvHandle, &FileHandle); if (Status != EFI_SUCCESS) { break; } Private->CurrentFvFileHandles[PeimCount] = FileHandle; } + + // + // Check whether the count of Peims exceeds the max support PEIMs in a FV image + // If more Peims are required in a FV image, PcdPeiCoreMaxPeimPerFv can be set to a larger value in DSC file. + // + ASSERT (PeimCount < PcdGet32 (PcdPeiCoreMaxPeimPerFv)); + // + // Get Apriori File handle + // Private->AprioriCount = 0; - if (AprioriFileHandle != NULL) { + Status = FvPpi->FindFileByName (FvPpi, &gPeiAprioriFileNameGuid, &CoreFileHandle->FvHandle, &AprioriFileHandle); + if (!EFI_ERROR(Status) && AprioriFileHandle != NULL) { // // Read the Apriori file // - Status = PeiServicesFfsFindSectionData (EFI_SECTION_RAW, AprioriFileHandle, (VOID **) &Apriori); + Status = FvPpi->FindSectionByType (FvPpi, EFI_SECTION_RAW, AprioriFileHandle, (VOID **) &Apriori); if (!EFI_ERROR (Status)) { // // Calculate the number of PEIMs in the A Priori list // - Private->AprioriCount = *(UINT32 *)(((EFI_FFS_FILE_HEADER *)AprioriFileHandle)->Size) & 0x00FFFFFF; - Private->AprioriCount -= sizeof (EFI_FFS_FILE_HEADER) - sizeof (EFI_COMMON_SECTION_HEADER); + Status = FvPpi->GetFileInfo (FvPpi, AprioriFileHandle, &FileInfo); + ASSERT_EFI_ERROR (Status); + Private->AprioriCount = FileInfo.BufferSize & 0x00FFFFFF; + Private->AprioriCount -= sizeof (EFI_COMMON_SECTION_HEADER); Private->AprioriCount /= sizeof (EFI_GUID); ZeroMem (FileGuid, sizeof (FileGuid)); @@ -106,7 +116,8 @@ DiscoverPeimsAndOrderWithApriori ( // Make an array of file name guids that matches the FileHandle array so we can convert // quickly from file name to file handle // - CopyMem (&FileGuid[Index], &((EFI_FFS_FILE_HEADER *)Private->CurrentFvFileHandles[Index])->Name,sizeof(EFI_GUID)); + Status = FvPpi->GetFileInfo (FvPpi, Private->CurrentFvFileHandles[Index], &FileInfo); + CopyMem (&FileGuid[Index], &FileInfo.FileName, sizeof(EFI_GUID)); } // @@ -196,13 +207,12 @@ ShadowPeiCore( // // Find the PEI Core in the BFV // - Status = PeiFindFileEx ( - (EFI_PEI_FV_HANDLE)PrivateInMem->Fv[0].FvHeader, - NULL, - EFI_FV_FILETYPE_PEI_CORE, - &PeiCoreFileHandle, - NULL - ); + Status = PrivateInMem->Fv[0].FvPpi->FindFileByType ( + PrivateInMem->Fv[0].FvPpi, + EFI_FV_FILETYPE_PEI_CORE, + PrivateInMem->Fv[0].FvHandle, + &PeiCoreFileHandle + ); ASSERT_EFI_ERROR (Status); // @@ -211,6 +221,7 @@ ShadowPeiCore( Status = PeiLoadImage ( PeiServices, *((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle), + PEIM_STATE_REGISITER_FOR_SHADOW, &EntryPoint, &AuthenticationState ); @@ -242,7 +253,6 @@ PeiDispatcher ( UINT32 Index1; UINT32 Index2; CONST EFI_PEI_SERVICES **PeiServices; - EFI_PEI_FV_HANDLE VolumeHandle; EFI_PEI_FILE_HANDLE PeimFileHandle; UINTN FvCount; UINTN PeimCount; @@ -266,7 +276,7 @@ PeiDispatcher ( EFI_FV_FILE_INFO FvFileInfo; UINTN OldCheckingTop; UINTN OldCheckingBottom; - + PEI_CORE_FV_HANDLE *CoreFvHandle; PeiServices = (CONST EFI_PEI_SERVICES **) &Private->PS; PeimEntryPoint = NULL; @@ -283,12 +293,13 @@ PeiDispatcher ( SaveCurrentFileHandle = Private->CurrentFileHandle; for (Index1 = 0; Index1 <= SaveCurrentFvCount; Index1++) { - for (Index2 = 0; (Index2 < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->Fv[Index1].FvFileHandles[Index2] != NULL); Index2++) { + for (Index2 = 0; (Index2 < PcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->Fv[Index1].FvFileHandles[Index2] != NULL); Index2++) { if (Private->Fv[Index1].PeimState[Index2] == PEIM_STATE_REGISITER_FOR_SHADOW) { PeimFileHandle = Private->Fv[Index1].FvFileHandles[Index2]; Status = PeiLoadImage ( (CONST EFI_PEI_SERVICES **) &Private->PS, PeimFileHandle, + PEIM_STATE_REGISITER_FOR_SHADOW, &EntryPoint, &AuthenticationState ); @@ -305,9 +316,9 @@ PeiDispatcher ( // PeimEntryPoint = (EFI_PEIM_ENTRY_POINT2)(UINTN)EntryPoint; - PERF_START (0, "PEIM", NULL, 0); + PERF_START (PeimFileHandle, "PEIM", NULL, 0); PeimEntryPoint(PeimFileHandle, (const EFI_PEI_SERVICES **) &Private->PS); - PERF_END (0, "PEIM", NULL, 0); + PERF_END (PeimFileHandle, "PEIM", NULL, 0); } // @@ -343,11 +354,17 @@ PeiDispatcher ( } for (FvCount = Private->CurrentPeimFvCount; FvCount < Private->FvCount; FvCount++) { - Private->CurrentPeimFvCount = FvCount; + CoreFvHandle = FindNextCoreFvHandle (Private, FvCount); + ASSERT (CoreFvHandle != NULL); + // - // Get this Fv Handle by PeiService FvFindNextVolume. + // If the FV has corresponding EFI_PEI_FIRMWARE_VOLUME_PPI instance, then dispatch it. // - PeiFvFindNextVolume (PeiServices, FvCount, &VolumeHandle); + if (CoreFvHandle->FvPpi == NULL) { + continue; + } + + Private->CurrentPeimFvCount = FvCount; if (Private->CurrentPeimCount == 0) { // @@ -355,14 +372,14 @@ PeiDispatcher ( // reorder all PEIMs to ensure the PEIMs in Apriori file to get // dispatch at first. // - DiscoverPeimsAndOrderWithApriori (Private, VolumeHandle); + DiscoverPeimsAndOrderWithApriori (Private, CoreFvHandle); } // // Start to dispatch all modules within the current Fv. // for (PeimCount = Private->CurrentPeimCount; - (PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->CurrentFvFileHandles[PeimCount] != NULL); + (PeimCount < PcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->CurrentFvFileHandles[PeimCount] != NULL); PeimCount++) { Private->CurrentPeimCount = PeimCount; PeimFileHandle = Private->CurrentFileHandle = Private->CurrentFvFileHandles[PeimCount]; @@ -371,13 +388,14 @@ PeiDispatcher ( if (!DepexSatisfied (Private, PeimFileHandle, PeimCount)) { Private->PeimNeedingDispatch = TRUE; } else { - Status = PeiFfsGetFileInfo (PeimFileHandle, &FvFileInfo); + Status = CoreFvHandle->FvPpi->GetFileInfo (CoreFvHandle->FvPpi, PeimFileHandle, &FvFileInfo); ASSERT_EFI_ERROR (Status); if (FvFileInfo.FileType == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) { // // For Fv type file, Produce new FV PPI and FV hob // - Status = ProcessFvFile (PeiServices, PeimFileHandle, &AuthenticationState); + Status = ProcessFvFile (&Private->Fv[FvCount], PeimFileHandle); + AuthenticationState = 0; } else { // // For PEIM driver, Load its entry point @@ -385,6 +403,7 @@ PeiDispatcher ( Status = PeiLoadImage ( PeiServices, PeimFileHandle, + PEIM_STATE_NOT_DISPATCHED, &EntryPoint, &AuthenticationState ); @@ -395,18 +414,18 @@ PeiDispatcher ( // The PEIM has its dependencies satisfied, and its entry point // has been found, so invoke it. // - PERF_START (0, "PEIM", NULL, 0); + PERF_START (PeimFileHandle, "PEIM", NULL, 0); ExtendedData.Handle = (EFI_HANDLE)PeimFileHandle; REPORT_STATUS_CODE_WITH_EXTENDED_DATA ( EFI_PROGRESS_CODE, - FixedPcdGet32(PcdStatusCodeValuePeimDispatch), + (EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_BEGIN), (VOID *)(&ExtendedData), sizeof (ExtendedData) ); - Status = VerifyPeim (Private, VolumeHandle, PeimFileHandle); + Status = VerifyPeim (Private, CoreFvHandle->FvHandle, PeimFileHandle); if (Status != EFI_SECURITY_VIOLATION && (AuthenticationState == 0)) { // // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED @@ -426,17 +445,17 @@ PeiDispatcher ( REPORT_STATUS_CODE_WITH_EXTENDED_DATA ( EFI_PROGRESS_CODE, - FixedPcdGet32(PcdStatusCodeValuePeimDispatch), + (EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_BEGIN), (VOID *)(&ExtendedData), sizeof (ExtendedData) ); - PERF_END (0, "PEIM", NULL, 0); + PERF_END (PeimFileHandle, "PEIM", NULL, 0); } if (Private->SwitchStackSignal) { // - // Before switch stack from CAR to permenent memory, caculate the heap and stack + // Before switch stack from temporary memory to permenent memory, caculate the heap and stack // usage in temporary memory for debuging. // DEBUG_CODE_BEGIN (); @@ -447,11 +466,11 @@ PeiDispatcher ( && (*StackPointer == INIT_CAR_VALUE); StackPointer ++); - DEBUG ((EFI_D_INFO, "Total Cache as RAM: %d bytes.\n", (UINT32)SecCoreData->TemporaryRamSize)); - DEBUG ((EFI_D_INFO, " CAR stack ever used: %d bytes.\n", + DEBUG ((EFI_D_INFO, "Total temporary memory: %d bytes.\n", (UINT32)SecCoreData->TemporaryRamSize)); + DEBUG ((EFI_D_INFO, " temporary memory stack ever used: %d bytes.\n", (SecCoreData->StackSize - ((UINTN) StackPointer - (UINTN)SecCoreData->StackBase)) )); - DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n", + DEBUG ((EFI_D_INFO, " temporary memory heap used: %d bytes.\n", ((UINTN) Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom - (UINTN) Private->HobList.Raw) )); @@ -462,10 +481,10 @@ PeiDispatcher ( // OldPeiStackSize = (UINT64) SecCoreData->StackSize; NewPeiStackSize = (RShiftU64 (Private->PhysicalMemoryLength, 1) + EFI_PAGE_MASK) & ~EFI_PAGE_MASK; - if (FixedPcdGet32(PcdPeiCoreMaxPeiStackSize) > (UINT32) NewPeiStackSize) { + if (PcdGet32(PcdPeiCoreMaxPeiStackSize) > (UINT32) NewPeiStackSize) { Private->StackSize = NewPeiStackSize; } else { - Private->StackSize = FixedPcdGet32(PcdPeiCoreMaxPeiStackSize); + Private->StackSize = PcdGet32(PcdPeiCoreMaxPeiStackSize); } // @@ -492,7 +511,7 @@ PeiDispatcher ( NewPermenentMemoryBase = Private->PhysicalMemoryBegin + StackGap; // - // Caculate stack offset and heap offset between CAR and new permement + // Caculate stack offset and heap offset between temporary memory and new permement // memory seperately. // StackOffset = (UINTN) NewPermenentMemoryBase - (UINTN) SecCoreData->StackBase; @@ -523,7 +542,7 @@ PeiDispatcher ( // 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. + // memory but not in temporary memory. // TemporaryRamSupportPpi->TemporaryRamMigration ( (CONST EFI_PEI_SERVICES **) PeiServices, @@ -632,6 +651,7 @@ PeiDispatcher ( // We call the entry point a 2nd time so the module knows it's shadowed. // //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0); + ASSERT (PeimEntryPoint != NULL); PeimEntryPoint (PeimFileHandle, (const EFI_PEI_SERVICES **) PeiServices); //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0); @@ -704,6 +724,8 @@ InitializeDispatcherData ( if (OldCoreData == NULL) { PrivateData->PeimDispatcherReenter = FALSE; PeiInitializeFv (PrivateData, SecCoreData); + } else { + PeiReinitializeFv (PrivateData); } return; @@ -800,3 +822,5 @@ PeiRegisterForShadow ( return EFI_SUCCESS; } + +