X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FCore%2FPei%2FDispatcher%2FDispatcher.c;h=bdbb00b205f86dcec674c108743fe5a830811168;hp=cf9ea5d173fe1a78ddb813cc405f3a2d3f014fcd;hb=f3198cba84f56f85281b87c4e9bf96e77a934f16;hpb=58dcdada561c36394c819d3105e867208b84227d diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c index cf9ea5d173..bdbb00b205 100644 --- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c @@ -1,6 +1,7 @@ -/*++ - -Copyright (c) 2006, Intel Corporation +/** @file + EFI PEI Core dispatch services + +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 @@ -9,46 +10,35 @@ 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: - - Dispatcher.c - -Abstract: - - EFI PEI Core dispatch services - -Revision History +**/ ---*/ +#include "PeiMain.h" -#include +/// +/// temporary memory is filled with this initial value during SEC phase +/// +#define INIT_CAR_VALUE 0x5AA55AA5 typedef struct { EFI_STATUS_CODE_DATA DataHeader; EFI_HANDLE Handle; } PEIM_FILE_HANDLE_EXTENDED_DATA; -VOID -DiscoverPeimsAndOrderWithApriori ( - IN PEI_CORE_INSTANCE *Private, - IN EFI_PEI_FV_HANDLE VolumeHandle - ) -/*++ - -Routine Description: +/** Discover all Peims and optional Apriori file in one FV. There is at most one Apriori file in one FV. -Arguments: - - Private - Pointer to the private data passed in from caller - VolumeHandle - Fv handle. -Returns: - NONE + @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 PEI_CORE_FV_HANDLE *CoreFileHandle + ) { EFI_STATUS Status; EFI_PEI_FV_HANDLE FileHandle; @@ -61,7 +51,11 @@ Returns: 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. // @@ -81,42 +75,49 @@ Returns: // // 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); - SetMem (FileGuid, sizeof (FileGuid), 0); + ZeroMem (FileGuid, sizeof (FileGuid)); for (Index = 0; Index < PeimCount; Index++) { // // 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)); } // @@ -182,10 +183,18 @@ Returns: } +/** + Shadow PeiCore module from flash to installed memory. + + @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation. + @param PrivateInMem PeiCore's private data structure + + @return PeiCore function address after shadowing. +**/ VOID* ShadowPeiCore( - EFI_PEI_SERVICES **PeiServices, - PEI_CORE_INSTANCE *PrivateInMem + IN CONST EFI_PEI_SERVICES **PeiServices, + IN PEI_CORE_INSTANCE *PrivateInMem ) { EFI_PEI_FILE_HANDLE PeiCoreFileHandle; @@ -198,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); // @@ -213,55 +221,44 @@ ShadowPeiCore( Status = PeiLoadImage ( PeiServices, *((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle), + PEIM_STATE_REGISITER_FOR_SHADOW, &EntryPoint, &AuthenticationState ); ASSERT_EFI_ERROR (Status); + // + // Compute the PeiCore's function address after shaowed PeiCore. + // _ModuleEntryPoint is PeiCore main function entry + // return (VOID*) ((UINTN) EntryPoint + (UINTN) PeiCore - (UINTN) _ModuleEntryPoint); } -VOID -PeiDispatcher ( - IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData, - IN PEI_CORE_INSTANCE *Private - ) - -/*++ - -Routine Description: - +/** Conduct PEIM dispatch. -Arguments: - - SecCoreData - Points to a data structure containing information about the PEI core's operating + @param SecCoreData Points to a data structure containing information about the PEI core's operating environment, such as the size and location of temporary RAM, the stack location and the BFV location. - PrivateData - Pointer to the private data passed in from caller - DispatchData - Pointer to PEI_CORE_DISPATCH_DATA data. - -Returns: + @param Private Pointer to the private data passed in from caller - EFI_SUCCESS - Successfully dispatched PEIM. - EFI_NOT_FOUND - The dispatch failed. - ---*/ +**/ +VOID +PeiDispatcher ( + IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData, + IN PEI_CORE_INSTANCE *Private + ) { EFI_STATUS Status; UINT32 Index1; UINT32 Index2; - EFI_PEI_SERVICES **PeiServices; - EFI_PEI_FV_HANDLE VolumeHandle; - //EFI_PHYSICAL_ADDRESS PeiCoreFileHandle; + CONST EFI_PEI_SERVICES **PeiServices; EFI_PEI_FILE_HANDLE PeimFileHandle; UINTN FvCount; UINTN PeimCount; UINT32 AuthenticationState; EFI_PHYSICAL_ADDRESS EntryPoint; EFI_PEIM_ENTRY_POINT2 PeimEntryPoint; - BOOLEAN PeimNeedingDispatch; - BOOLEAN PeimDispatchOnThisPass; UINTN SaveCurrentPeimCount; UINTN SaveCurrentFvCount; EFI_PEI_FILE_HANDLE SaveCurrentFileHandle; @@ -270,7 +267,8 @@ Returns: TEMPORARY_RAM_SUPPORT_PPI *TemporaryRamSupportPpi; EFI_HOB_HANDOFF_INFO_TABLE *OldHandOffTable; EFI_HOB_HANDOFF_INFO_TABLE *NewHandOffTable; - INTN Offset; + INTN StackOffset; + INTN HeapOffset; PEI_CORE_INSTANCE *PrivateInMem; UINT64 NewPeiStackSize; UINT64 OldPeiStackSize; @@ -278,9 +276,9 @@ Returns: EFI_FV_FILE_INFO FvFileInfo; UINTN OldCheckingTop; UINTN OldCheckingBottom; + PEI_CORE_FV_HANDLE *CoreFvHandle; - - PeiServices = &Private->PS; + PeiServices = (CONST EFI_PEI_SERVICES **) &Private->PS; PeimEntryPoint = NULL; PeimFileHandle = NULL; EntryPoint = 0; @@ -295,12 +293,13 @@ Returns: 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 ( - &Private->PS, + (CONST EFI_PEI_SERVICES **) &Private->PS, PeimFileHandle, + PEIM_STATE_REGISITER_FOR_SHADOW, &EntryPoint, &AuthenticationState ); @@ -317,9 +316,9 @@ Returns: // 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); } // @@ -344,12 +343,28 @@ Returns: // satisfied, this dipatcher should run only once. // do { - PeimNeedingDispatch = FALSE; - PeimDispatchOnThisPass = FALSE; - + // + // In case that reenter PeiCore happens, the last pass record is still available. + // + if (!Private->PeimDispatcherReenter) { + Private->PeimNeedingDispatch = FALSE; + Private->PeimDispatchOnThisPass = FALSE; + } else { + Private->PeimDispatcherReenter = FALSE; + } + for (FvCount = Private->CurrentPeimFvCount; FvCount < Private->FvCount; FvCount++) { + CoreFvHandle = FindNextCoreFvHandle (Private, FvCount); + ASSERT (CoreFvHandle != NULL); + + // + // If the FV has corresponding EFI_PEI_FIRMWARE_VOLUME_PPI instance, then dispatch it. + // + if (CoreFvHandle->FvPpi == NULL) { + continue; + } + Private->CurrentPeimFvCount = FvCount; - VolumeHandle = Private->Fv[FvCount].FvHeader; if (Private->CurrentPeimCount == 0) { // @@ -357,29 +372,30 @@ Returns: // 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]; if (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_NOT_DISPATCHED) { if (!DepexSatisfied (Private, PeimFileHandle, PeimCount)) { - PeimNeedingDispatch = TRUE; + 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 @@ -387,6 +403,7 @@ Returns: Status = PeiLoadImage ( PeiServices, PeimFileHandle, + PEIM_STATE_NOT_DISPATCHED, &EntryPoint, &AuthenticationState ); @@ -397,18 +414,18 @@ Returns: // 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 @@ -423,30 +440,51 @@ Returns: PeimEntryPoint (PeimFileHandle, (const EFI_PEI_SERVICES **) PeiServices); } - PeimDispatchOnThisPass = TRUE; + Private->PeimDispatchOnThisPass = TRUE; } 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 temporary memory to permenent memory, caculate the heap and stack + // usage in temporary memory for debuging. + // + DEBUG_CODE_BEGIN (); + UINT32 *StackPointer; + + for (StackPointer = (UINT32*)SecCoreData->StackBase; + (StackPointer < (UINT32*)((UINTN)SecCoreData->StackBase + SecCoreData->StackSize)) \ + && (*StackPointer == INIT_CAR_VALUE); + StackPointer ++); + + 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, " temporary memory heap used: %d bytes.\n", + ((UINTN) Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom - + (UINTN) Private->HobList.Raw) + )); + DEBUG_CODE_END (); + // // Reserve the size of new stack at bottom of physical memory // - OldPeiStackSize = Private->StackSize; + 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); } // @@ -455,16 +493,15 @@ Returns: // But if new stack is smaller than the size of old stack, we also reserve // the size of old stack at bottom of permenent memory. // - StackGap = 0; - if (Private->StackSize > OldPeiStackSize) { - StackGap = Private->StackSize - OldPeiStackSize; - } + DEBUG ((EFI_D_INFO, "Old Stack size %d, New stack size %d\n", (INT32) OldPeiStackSize, (INT32) Private->StackSize)); + ASSERT (Private->StackSize >= OldPeiStackSize); + StackGap = Private->StackSize - OldPeiStackSize; // // Update HandOffHob for new installed permenent memory // OldHandOffTable = Private->HobList.HandoffInformationTable; - OldCheckingBottom = (UINTN)OldHandOffTable; + OldCheckingBottom = (UINTN)(SecCoreData->TemporaryRamBase); OldCheckingTop = (UINTN)(OldCheckingBottom + SecCoreData->TemporaryRamSize); // @@ -472,9 +509,21 @@ Returns: // CAUTION: The new base is computed accounding to gap of new stack. // NewPermenentMemoryBase = Private->PhysicalMemoryBegin + StackGap; - Offset = (UINTN) NewPermenentMemoryBase - (UINTN) SecCoreData->TemporaryRamBase; - NewHandOffTable = (EFI_HOB_HANDOFF_INFO_TABLE *)((UINTN)OldHandOffTable + Offset); - PrivateInMem = (PEI_CORE_INSTANCE *)((UINTN) (VOID*) Private + Offset); + + // + // Caculate stack offset and heap offset between temporary memory 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%lX Stack Offset = 0x%lX\n", (INT64)HeapOffset, (INT64)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); // // TemporaryRamSupportPpi is produced by platform's SEC @@ -489,6 +538,12 @@ Returns: 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 temporary memory. + // TemporaryRamSupportPpi->TemporaryRamMigration ( (CONST EFI_PEI_SERVICES **) PeiServices, (EFI_PHYSICAL_ADDRESS)(UINTN) SecCoreData->TemporaryRamBase, @@ -497,11 +552,11 @@ Returns: ); } else { - CopyMem ( - (VOID*)(UINTN) NewPermenentMemoryBase, - SecCoreData->TemporaryRamBase, - SecCoreData->TemporaryRamSize - ); + // + // In IA32/x64/Itanium architecture, we need platform provide + // TEMPORAY_RAM_MIGRATION_PPI. + // + ASSERT (FALSE); } @@ -511,10 +566,10 @@ Returns: // PrivateInMem->PS = &PrivateInMem->ServiceTableShadow; PrivateInMem->CpuIo = &PrivateInMem->ServiceTableShadow.CpuIo; - PrivateInMem->HobList.Raw = (VOID*) ((UINTN) PrivateInMem->HobList.Raw + Offset); + PrivateInMem->HobList.Raw = (VOID*) ((UINTN) PrivateInMem->HobList.Raw + HeapOffset); PrivateInMem->StackBase = (EFI_PHYSICAL_ADDRESS)(((UINTN)PrivateInMem->PhysicalMemoryBegin + EFI_PAGE_MASK) & ~EFI_PAGE_MASK); - PeiServices = &PrivateInMem->PS; + PeiServices = (CONST EFI_PEI_SERVICES **) &PrivateInMem->PS; // // Fixup for PeiService's address @@ -525,7 +580,7 @@ Returns: // Update HandOffHob for new installed permenent memory // NewHandOffTable->EfiEndOfHobList = - (EFI_PHYSICAL_ADDRESS)(VOID*)((UINTN) NewHandOffTable->EfiEndOfHobList + Offset); + (EFI_PHYSICAL_ADDRESS)((UINTN) NewHandOffTable->EfiEndOfHobList + HeapOffset); NewHandOffTable->EfiMemoryTop = PrivateInMem->PhysicalMemoryBegin + PrivateInMem->PhysicalMemoryLength; NewHandOffTable->EfiMemoryBottom = PrivateInMem->PhysicalMemoryBegin; @@ -536,13 +591,14 @@ Returns: // // We need convert the PPI desciptor's pointer // - ConvertPpiPointers ((CONST EFI_PEI_SERVICES **)PeiServices, + ConvertPpiPointers (PrivateInMem, OldCheckingBottom, OldCheckingTop, - NewHandOffTable); + HeapOffset + ); - DEBUG ((EFI_D_INFO, "Stack Hob: BaseAddress=0x%X Length=0x%X\n", - (UINTN)PrivateInMem->StackBase, + DEBUG ((EFI_D_INFO, "Stack Hob: BaseAddress=0x%lX Length=0x%lX\n", + PrivateInMem->StackBase, PrivateInMem->StackSize)); BuildStackHob (PrivateInMem->StackBase, PrivateInMem->StackSize); @@ -553,41 +609,14 @@ Returns: PrivateInMem->PeiMemoryInstalled = TRUE; // - // Make sure we don't retry the same PEIM that added memory + // Indicate that PeiCore reenter // - PrivateInMem->CurrentPeimCount++; - + PrivateInMem->PeimDispatcherReenter = TRUE; + // // Shadow PEI Core. When permanent memory is avaiable, shadow // PEI Core and PEIMs to get high performance. // - //PeiCoreFileHandle = 0; - // - // Find the PEI Core in the BFV - // - //Status = PeiFindFileEx ( - // (EFI_PEI_FV_HANDLE)PrivateInMem->Fv[0].FvHeader, - // NULL, - // EFI_FV_FILETYPE_PEI_CORE, - // (EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle, - // NULL - // ); - //ASSERT_EFI_ERROR (Status); - - // - // Shadow PEI Core into memory so it will run faster - // - //Status = PeiLoadImage ( - // PeiServices, - // *((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle), - // &EntryPoint, - // &AuthenticationState - // ); - //ASSERT_EFI_ERROR (Status); - - //PrivateInMem->ShadowedPeiCore = (VOID*) ((UINTN) EntryPoint + - // (UINTN) PeiCore - - // (UINTN) _ModuleEntryPoint); PrivateInMem->ShadowedPeiCore = ShadowPeiCore ( PeiServices, PrivateInMem @@ -603,12 +632,6 @@ Returns: // PeiCore (SecCoreData, NULL, PrivateInMem); - //((PEI_CORE_ENTRY_POINT) (UINTN) PrivateInMem->ShadowedPeiCore) ( - // SecCoreData, - // NULL, - // PrivateInMem - // ); - // // Code should not come here // @@ -628,6 +651,7 @@ Returns: // 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); @@ -673,67 +697,59 @@ Returns: // pass. If we did not dispatch a PEIM there is no point in trying again // as it will fail the next time too (nothing has changed). // - } while (PeimNeedingDispatch && PeimDispatchOnThisPass); + } while (Private->PeimNeedingDispatch && Private->PeimDispatchOnThisPass); } -VOID -InitializeDispatcherData ( - IN PEI_CORE_INSTANCE *PrivateData, - IN PEI_CORE_INSTANCE *OldCoreData, - IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData - ) -/*++ - -Routine Description: - +/** Initialize the Dispatcher's data members -Arguments: - - PeiServices - The PEI core services table. - OldCoreData - Pointer to old core data (before switching stack). + @param PrivateData PeiCore's private data structure + @param OldCoreData Old data from SecCore NULL if being run in non-permament memory mode. - SecCoreData - Points to a data structure containing information about the PEI core's operating + @param SecCoreData Points to a data structure containing information about the PEI core's operating environment, such as the size and location of temporary RAM, the stack location and the BFV location. -Returns: - - None. + @return None. ---*/ +**/ +VOID +InitializeDispatcherData ( + IN PEI_CORE_INSTANCE *PrivateData, + IN PEI_CORE_INSTANCE *OldCoreData, + IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData + ) { if (OldCoreData == NULL) { + PrivateData->PeimDispatcherReenter = FALSE; PeiInitializeFv (PrivateData, SecCoreData); + } else { + PeiReinitializeFv (PrivateData); } return; } +/** + This routine parses the Dependency Expression, if available, and + decides if the module can be executed. + + @param Private PeiCore's private data structure + @param FileHandle PEIM's file handle + @param PeimCount Peim count in all dispatched PEIMs. + + @retval TRUE Can be dispatched + @retval FALSE Cannot be dispatched + +**/ BOOLEAN DepexSatisfied ( IN PEI_CORE_INSTANCE *Private, IN EFI_PEI_FILE_HANDLE FileHandle, IN UINTN PeimCount ) -/*++ - -Routine Description: - - This routine parses the Dependency Expression, if available, and - decides if the module can be executed. - -Arguments: - PeiServices - The PEI Service Table - CurrentPeimAddress - Address of the PEIM Firmware File under investigation - -Returns: - TRUE - Can be dispatched - FALSE - Cannot be dispatched - ---*/ { EFI_STATUS Status; VOID *DepexData; @@ -771,11 +787,11 @@ Returns: This routine enable a PEIM to register itself to shadow when PEI Foundation discovery permanent memory. - @param FileHandle File handle of a PEIM. + @param FileHandle File handle of a PEIM. - @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself. - @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself. - @retval EFI_SUCCESS Successfully to register itself. + @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself. + @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself. + @retval EFI_SUCCESS Successfully to register itself. **/ EFI_STATUS @@ -808,118 +824,3 @@ PeiRegisterForShadow ( -/** - Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob. - - @param PeiServices Pointer to the PEI Core Services Table. - @param FileHandle File handle of a Fv type file. - @param AuthenticationState Pointer to attestation authentication state of image. - - - @retval EFI_NOT_FOUND FV image can't be found. - @retval EFI_SUCCESS Successfully to process it. - -**/ -EFI_STATUS -ProcessFvFile ( - IN EFI_PEI_SERVICES **PeiServices, - IN EFI_PEI_FILE_HANDLE FvFileHandle, - OUT UINT32 *AuthenticationState - ) -{ - EFI_STATUS Status; - EFI_PEI_FV_HANDLE FvImageHandle; - EFI_FV_INFO FvImageInfo; - UINT32 FvAlignment; - VOID *FvBuffer; - EFI_PEI_HOB_POINTERS HobFv2; - - FvBuffer = NULL; - *AuthenticationState = 0; - - // - // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already - // been extracted. - // - HobFv2.Raw = GetHobList (); - while ((HobFv2.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobFv2.Raw)) != NULL) { - if (CompareGuid (&(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name), &HobFv2.FirmwareVolume2->FileName)) { - // - // this FILE has been dispatched, it will not be dispatched again. - // - return EFI_SUCCESS; - } - HobFv2.Raw = GET_NEXT_HOB (HobFv2); - } - - // - // Find FvImage in FvFile - // - Status = PeiFfsFindSectionData ( - (CONST EFI_PEI_SERVICES **) PeiServices, - EFI_SECTION_FIRMWARE_VOLUME_IMAGE, - FvFileHandle, - (VOID **)&FvImageHandle - ); - - if (EFI_ERROR (Status)) { - return Status; - } - // - // Collect FvImage Info. - // - Status = PeiFfsGetVolumeInfo (FvImageHandle, &FvImageInfo); - ASSERT_EFI_ERROR (Status); - // - // FvAlignment must be more than 8 bytes required by FvHeader structure. - // - FvAlignment = 1 << ((FvImageInfo.FvAttributes & EFI_FVB2_ALIGNMENT) >> 16); - if (FvAlignment < 8) { - FvAlignment = 8; - } - // - // Check FvImage - // - if ((UINTN) FvImageInfo.FvStart % FvAlignment != 0) { - FvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvImageInfo.FvSize), FvAlignment); - if (FvBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - CopyMem (FvBuffer, FvImageInfo.FvStart, (UINTN) FvImageInfo.FvSize); - // - // Update FvImageInfo after reload FvImage to new aligned memory - // - PeiFfsGetVolumeInfo ((EFI_PEI_FV_HANDLE) FvBuffer, &FvImageInfo); - } - - // - // Install FvPpi and Build FvHob - // - PiLibInstallFvInfoPpi ( - NULL, - FvImageInfo.FvStart, - (UINT32) FvImageInfo.FvSize, - &(FvImageInfo.FvName), - &(((EFI_FFS_FILE_HEADER*)FvFileHandle)->Name) - ); - - // - // Inform HOB consumer phase, i.e. DXE core, the existance of this FV - // - BuildFvHob ( - (EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart, - FvImageInfo.FvSize - ); - // - // Makes the encapsulated volume show up in DXE phase to skip processing of - // encapsulated file again. - // - BuildFv2Hob ( - (EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart, - FvImageInfo.FvSize, - &FvImageInfo.FvName, - &(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name) - ); - - return EFI_SUCCESS; -}