Merge Temporary Ram support patch.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4782 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@@ -28,13 +28,6 @@ typedef struct {
|
||||
EFI_HANDLE Handle;
|
||||
} PEIM_FILE_HANDLE_EXTENDED_DATA;
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
InvokePeiCore (
|
||||
VOID *Context1,
|
||||
VOID *Context2
|
||||
);
|
||||
|
||||
VOID
|
||||
DiscoverPeimsAndOrderWithApriori (
|
||||
IN PEI_CORE_INSTANCE *Private,
|
||||
@@ -55,7 +48,7 @@ Returns:
|
||||
|
||||
NONE
|
||||
|
||||
--*/
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_PEI_FV_HANDLE FileHandle;
|
||||
@@ -90,20 +83,20 @@ Returns:
|
||||
//
|
||||
for (PeimCount = 0; PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv); PeimCount++) {
|
||||
Status = PeiFindFileEx (
|
||||
VolumeHandle,
|
||||
NULL,
|
||||
PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE,
|
||||
VolumeHandle,
|
||||
NULL,
|
||||
PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE,
|
||||
&FileHandle,
|
||||
&AprioriFileHandle
|
||||
);
|
||||
if (Status != EFI_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Private->CurrentFvFileHandles[PeimCount] = FileHandle;
|
||||
}
|
||||
|
||||
Private->AprioriCount = 0;
|
||||
Private->AprioriCount = 0;
|
||||
if (AprioriFileHandle != NULL) {
|
||||
//
|
||||
// Read the Apriori file
|
||||
@@ -114,21 +107,21 @@ Returns:
|
||||
// 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);
|
||||
Private->AprioriCount -= sizeof (EFI_FFS_FILE_HEADER) - sizeof (EFI_COMMON_SECTION_HEADER);
|
||||
Private->AprioriCount /= sizeof (EFI_GUID);
|
||||
|
||||
|
||||
SetMem (FileGuid, sizeof (FileGuid), 0);
|
||||
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));
|
||||
CopyMem (&FileGuid[Index], &((EFI_FFS_FILE_HEADER *)Private->CurrentFvFileHandles[Index])->Name,sizeof(EFI_GUID));
|
||||
}
|
||||
|
||||
//
|
||||
// Walk through FileGuid array to find out who is invalid PEIM guid in Apriori file.
|
||||
// Add avalible PEIMs in Apriori file into TempFileHandles array at first.
|
||||
// Add avalible PEIMs in Apriori file into TempFileHandles array at first.
|
||||
//
|
||||
Index2 = 0;
|
||||
for (Index = 0; Index2 < Private->AprioriCount; Index++) {
|
||||
@@ -139,7 +132,7 @@ Returns:
|
||||
}
|
||||
}
|
||||
if (Guid == NULL) {
|
||||
break;
|
||||
break;
|
||||
}
|
||||
PeimIndex = ((UINTN)Guid - (UINTN)&FileGuid[0])/sizeof (EFI_GUID);
|
||||
TempFileHandles[Index] = Private->CurrentFvFileHandles[PeimIndex];
|
||||
@@ -154,7 +147,7 @@ Returns:
|
||||
// Update valid Aprioricount
|
||||
//
|
||||
Private->AprioriCount = Index;
|
||||
|
||||
|
||||
//
|
||||
// Add in any PEIMs not in the Apriori file
|
||||
//
|
||||
@@ -171,11 +164,11 @@ Returns:
|
||||
//Index the end of array contains re-range Pei moudle.
|
||||
//
|
||||
TempFileHandles[Index] = NULL;
|
||||
|
||||
|
||||
//
|
||||
// Private->CurrentFvFileHandles is currently in PEIM in the FV order.
|
||||
// We need to update it to start with files in the A Priori list and
|
||||
// then the remaining files in PEIM order.
|
||||
// We need to update it to start with files in the A Priori list and
|
||||
// then the remaining files in PEIM order.
|
||||
//
|
||||
CopyMem (Private->CurrentFvFileHandles, TempFileHandles, sizeof (Private->CurrentFvFileHandles));
|
||||
}
|
||||
@@ -186,7 +179,46 @@ Returns:
|
||||
//
|
||||
Private->Fv[Private->CurrentPeimFvCount].ScanFv = TRUE;
|
||||
CopyMem (Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, Private->CurrentFvFileHandles, sizeof (Private->CurrentFvFileHandles));
|
||||
|
||||
|
||||
}
|
||||
|
||||
VOID*
|
||||
ShadowPeiCore(
|
||||
EFI_PEI_SERVICES **PeiServices,
|
||||
PEI_CORE_INSTANCE *PrivateInMem
|
||||
)
|
||||
{
|
||||
EFI_PEI_FILE_HANDLE PeiCoreFileHandle;
|
||||
EFI_PHYSICAL_ADDRESS EntryPoint;
|
||||
EFI_STATUS Status;
|
||||
UINT32 AuthenticationState;
|
||||
|
||||
PeiCoreFileHandle = NULL;
|
||||
|
||||
//
|
||||
// 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
|
||||
);
|
||||
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);
|
||||
|
||||
return (VOID*) ((UINTN) EntryPoint + (UINTN) PeiCore - (UINTN) _ModuleEntryPoint);
|
||||
}
|
||||
|
||||
VOID
|
||||
@@ -220,9 +252,8 @@ Returns:
|
||||
UINT32 Index1;
|
||||
UINT32 Index2;
|
||||
EFI_PEI_SERVICES **PeiServices;
|
||||
VOID *PrivateInMem;
|
||||
EFI_PEI_FV_HANDLE VolumeHandle;
|
||||
EFI_PEI_FILE_HANDLE PeiCoreFileHandle;
|
||||
EFI_PEI_FV_HANDLE VolumeHandle;
|
||||
//EFI_PHYSICAL_ADDRESS PeiCoreFileHandle;
|
||||
EFI_PEI_FILE_HANDLE PeimFileHandle;
|
||||
UINTN FvCount;
|
||||
UINTN PeimCount;
|
||||
@@ -234,10 +265,19 @@ Returns:
|
||||
UINTN SaveCurrentPeimCount;
|
||||
UINTN SaveCurrentFvCount;
|
||||
EFI_PEI_FILE_HANDLE SaveCurrentFileHandle;
|
||||
VOID *TopOfStack;
|
||||
PEI_CORE_PARAMETERS PeiCoreParameters;
|
||||
PEIM_FILE_HANDLE_EXTENDED_DATA ExtendedData;
|
||||
EFI_PHYSICAL_ADDRESS NewPermenentMemoryBase;
|
||||
TEMPORARY_RAM_SUPPORT_PPI *TemporaryRamSupportPpi;
|
||||
EFI_HOB_HANDOFF_INFO_TABLE *OldHandOffTable;
|
||||
EFI_HOB_HANDOFF_INFO_TABLE *NewHandOffTable;
|
||||
INTN Offset;
|
||||
PEI_CORE_INSTANCE *PrivateInMem;
|
||||
UINT64 NewPeiStackSize;
|
||||
UINT64 OldPeiStackSize;
|
||||
UINT64 StackGap;
|
||||
EFI_FV_FILE_INFO FvFileInfo;
|
||||
UINTN OldCheckingTop;
|
||||
UINTN OldCheckingBottom;
|
||||
|
||||
|
||||
PeiServices = &Private->PS;
|
||||
@@ -257,11 +297,11 @@ Returns:
|
||||
for (Index1 = 0; Index1 <= SaveCurrentFvCount; Index1++) {
|
||||
for (Index2 = 0; (Index2 < FixedPcdGet32 (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];
|
||||
PeimFileHandle = Private->Fv[Index1].FvFileHandles[Index2];
|
||||
Status = PeiLoadImage (
|
||||
&Private->PS,
|
||||
PeimFileHandle,
|
||||
&EntryPoint,
|
||||
&Private->PS,
|
||||
PeimFileHandle,
|
||||
&EntryPoint,
|
||||
&AuthenticationState
|
||||
);
|
||||
if (Status == EFI_SUCCESS) {
|
||||
@@ -270,18 +310,18 @@ Returns:
|
||||
//
|
||||
Private->Fv[Index1].PeimState[Index2]++;
|
||||
Private->CurrentFileHandle = PeimFileHandle;
|
||||
Private->CurrentPeimFvCount = Index1;
|
||||
Private->CurrentPeimCount = Index2;
|
||||
Private->CurrentPeimFvCount = Index1;
|
||||
Private->CurrentPeimCount = Index2;
|
||||
//
|
||||
// Call the PEIM entry point
|
||||
//
|
||||
PeimEntryPoint = (EFI_PEIM_ENTRY_POINT2)(UINTN)EntryPoint;
|
||||
|
||||
|
||||
PERF_START (0, "PEIM", NULL, 0);
|
||||
PeimEntryPoint(PeimFileHandle, (const EFI_PEI_SERVICES **) &Private->PS);
|
||||
PERF_END (0, "PEIM", NULL, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Process the Notify list and dispatch any notifies for
|
||||
// newly installed PPIs.
|
||||
@@ -290,9 +330,9 @@ Returns:
|
||||
}
|
||||
}
|
||||
}
|
||||
Private->CurrentFileHandle = SaveCurrentFileHandle;
|
||||
Private->CurrentPeimFvCount = SaveCurrentFvCount;
|
||||
Private->CurrentPeimCount = SaveCurrentPeimCount;
|
||||
Private->CurrentFileHandle = SaveCurrentFileHandle;
|
||||
Private->CurrentPeimFvCount = SaveCurrentFvCount;
|
||||
Private->CurrentPeimCount = SaveCurrentPeimCount;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -314,7 +354,7 @@ Returns:
|
||||
if (Private->CurrentPeimCount == 0) {
|
||||
//
|
||||
// When going through each FV, at first, search Apriori file to
|
||||
// reorder all PEIMs to ensure the PEIMs in Apriori file to get
|
||||
// reorder all PEIMs to ensure the PEIMs in Apriori file to get
|
||||
// dispatch at first.
|
||||
//
|
||||
DiscoverPeimsAndOrderWithApriori (Private, VolumeHandle);
|
||||
@@ -323,8 +363,8 @@ Returns:
|
||||
//
|
||||
// Start to dispatch all modules within the current Fv.
|
||||
//
|
||||
for (PeimCount = Private->CurrentPeimCount;
|
||||
(PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->CurrentFvFileHandles[PeimCount] != NULL);
|
||||
for (PeimCount = Private->CurrentPeimCount;
|
||||
(PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->CurrentFvFileHandles[PeimCount] != NULL);
|
||||
PeimCount++) {
|
||||
Private->CurrentPeimCount = PeimCount;
|
||||
PeimFileHandle = Private->CurrentFileHandle = Private->CurrentFvFileHandles[PeimCount];
|
||||
@@ -345,16 +385,17 @@ Returns:
|
||||
// For PEIM driver, Load its entry point
|
||||
//
|
||||
Status = PeiLoadImage (
|
||||
PeiServices,
|
||||
PeimFileHandle,
|
||||
&EntryPoint,
|
||||
PeiServices,
|
||||
PeimFileHandle,
|
||||
&EntryPoint,
|
||||
&AuthenticationState
|
||||
);
|
||||
}
|
||||
|
||||
if ((Status == EFI_SUCCESS)) {
|
||||
//
|
||||
// The PEIM has its dependencies satisfied, and is processed.
|
||||
// The PEIM has its dependencies satisfied, and its entry point
|
||||
// has been found, so invoke it.
|
||||
//
|
||||
PERF_START (0, "PEIM", NULL, 0);
|
||||
|
||||
@@ -373,7 +414,7 @@ Returns:
|
||||
// PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED
|
||||
//
|
||||
Private->Fv[FvCount].PeimState[PeimCount]++;
|
||||
|
||||
|
||||
if (FvFileInfo.FileType != EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) {
|
||||
//
|
||||
// Call the PEIM entry point for PEIM driver
|
||||
@@ -393,12 +434,185 @@ Returns:
|
||||
);
|
||||
PERF_END (0, "PEIM", NULL, 0);
|
||||
|
||||
} else {
|
||||
}
|
||||
|
||||
if (Private->SwitchStackSignal) {
|
||||
|
||||
//
|
||||
// If PeiLoadImage fails, the section extraction PPI or Decompress PPI may not be ready,
|
||||
// we flag that more Peims need to be dispatched.
|
||||
// Reserve the size of new stack at bottom of physical memory
|
||||
//
|
||||
PeimNeedingDispatch = TRUE;
|
||||
OldPeiStackSize = Private->StackSize;
|
||||
NewPeiStackSize = (RShiftU64 (Private->PhysicalMemoryLength, 1) + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
|
||||
if (FixedPcdGet32(PcdPeiCoreMaxPeiStackSize) > (UINT32) NewPeiStackSize) {
|
||||
Private->StackSize = NewPeiStackSize;
|
||||
} else {
|
||||
Private->StackSize = FixedPcdGet32(PcdPeiCoreMaxPeiStackSize);
|
||||
}
|
||||
|
||||
//
|
||||
// In theory, the size of new stack in permenent memory should large than
|
||||
// size of old stack in temporary memory.
|
||||
// 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;
|
||||
}
|
||||
|
||||
//
|
||||
// Update HandOffHob for new installed permenent memory
|
||||
//
|
||||
OldHandOffTable = Private->HobList.HandoffInformationTable;
|
||||
OldCheckingBottom = (UINTN)OldHandOffTable;
|
||||
OldCheckingTop = (UINTN)(OldCheckingBottom + SecCoreData->TemporaryRamSize);
|
||||
|
||||
//
|
||||
// The whole temporary memory will be migrated to physical memory.
|
||||
// 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);
|
||||
|
||||
//
|
||||
// TemporaryRamSupportPpi is produced by platform's SEC
|
||||
//
|
||||
Status = PeiLocatePpi (
|
||||
(CONST EFI_PEI_SERVICES **) PeiServices,
|
||||
&gEfiTemporaryRamSupportPpiGuid,
|
||||
0,
|
||||
NULL,
|
||||
(VOID**)&TemporaryRamSupportPpi
|
||||
);
|
||||
|
||||
|
||||
if (!EFI_ERROR (Status)) {
|
||||
TemporaryRamSupportPpi->TemporaryRamMigration (
|
||||
(CONST EFI_PEI_SERVICES **) PeiServices,
|
||||
(EFI_PHYSICAL_ADDRESS)(UINTN) SecCoreData->TemporaryRamBase,
|
||||
(EFI_PHYSICAL_ADDRESS)(UINTN) NewPermenentMemoryBase,
|
||||
SecCoreData->TemporaryRamSize
|
||||
);
|
||||
|
||||
} else {
|
||||
CopyMem (
|
||||
(VOID*)(UINTN) NewPermenentMemoryBase,
|
||||
SecCoreData->TemporaryRamBase,
|
||||
SecCoreData->TemporaryRamSize
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// Fixup the PeiCore's private data
|
||||
//
|
||||
PrivateInMem->PS = &PrivateInMem->ServiceTableShadow;
|
||||
PrivateInMem->CpuIo = &PrivateInMem->ServiceTableShadow.CpuIo;
|
||||
PrivateInMem->HobList.Raw = (VOID*) ((UINTN) PrivateInMem->HobList.Raw + Offset);
|
||||
PrivateInMem->StackBase = (EFI_PHYSICAL_ADDRESS)(((UINTN)PrivateInMem->PhysicalMemoryBegin + EFI_PAGE_MASK) & ~EFI_PAGE_MASK);
|
||||
|
||||
PeiServices = &PrivateInMem->PS;
|
||||
|
||||
//
|
||||
// Fixup for PeiService's address
|
||||
//
|
||||
SetPeiServicesTablePointer(PeiServices);
|
||||
|
||||
//
|
||||
// Update HandOffHob for new installed permenent memory
|
||||
//
|
||||
NewHandOffTable->EfiEndOfHobList =
|
||||
(EFI_PHYSICAL_ADDRESS)(VOID*)((UINTN) NewHandOffTable->EfiEndOfHobList + Offset);
|
||||
NewHandOffTable->EfiMemoryTop = PrivateInMem->PhysicalMemoryBegin +
|
||||
PrivateInMem->PhysicalMemoryLength;
|
||||
NewHandOffTable->EfiMemoryBottom = PrivateInMem->PhysicalMemoryBegin;
|
||||
NewHandOffTable->EfiFreeMemoryTop = PrivateInMem->FreePhysicalMemoryTop;
|
||||
NewHandOffTable->EfiFreeMemoryBottom = NewHandOffTable->EfiEndOfHobList +
|
||||
sizeof (EFI_HOB_GENERIC_HEADER);
|
||||
|
||||
//
|
||||
// We need convert the PPI desciptor's pointer
|
||||
//
|
||||
ConvertPpiPointers ((CONST EFI_PEI_SERVICES **)PeiServices,
|
||||
OldCheckingBottom,
|
||||
OldCheckingTop,
|
||||
NewHandOffTable);
|
||||
|
||||
DEBUG ((EFI_D_INFO, "Stack Hob: BaseAddress=0x%X Length=0x%X\n",
|
||||
(UINTN)PrivateInMem->StackBase,
|
||||
PrivateInMem->StackSize));
|
||||
BuildStackHob (PrivateInMem->StackBase, PrivateInMem->StackSize);
|
||||
|
||||
//
|
||||
// After the whole temporary memory is migrated, then we can allocate page in
|
||||
// permenent memory.
|
||||
//
|
||||
PrivateInMem->PeiMemoryInstalled = TRUE;
|
||||
|
||||
//
|
||||
// Make sure we don't retry the same PEIM that added memory
|
||||
//
|
||||
PrivateInMem->CurrentPeimCount++;
|
||||
|
||||
//
|
||||
// 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
|
||||
);
|
||||
//
|
||||
// Process the Notify list and dispatch any notifies for
|
||||
// newly installed PPIs.
|
||||
//
|
||||
ProcessNotifyList (PrivateInMem);
|
||||
|
||||
//
|
||||
// Entry PEI Phase 2
|
||||
//
|
||||
PeiCore (SecCoreData, NULL, PrivateInMem);
|
||||
|
||||
//((PEI_CORE_ENTRY_POINT) (UINTN) PrivateInMem->ShadowedPeiCore) (
|
||||
// SecCoreData,
|
||||
// NULL,
|
||||
// PrivateInMem
|
||||
// );
|
||||
|
||||
//
|
||||
// Code should not come here
|
||||
//
|
||||
ASSERT_EFI_ERROR(FALSE);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -407,88 +621,16 @@ Returns:
|
||||
//
|
||||
ProcessNotifyList (Private);
|
||||
|
||||
//
|
||||
// If permanent memory was discovered and installed by this
|
||||
// PEIM, shadow PEI Core and switch the stacks to the new memory.
|
||||
//
|
||||
if (Private->SwitchStackSignal) {
|
||||
|
||||
//
|
||||
// Make sure we don't retry the same PEIM that added memory
|
||||
//
|
||||
Private->CurrentPeimCount++;
|
||||
|
||||
//
|
||||
// Migrate IDT from CAR into real memory, so after stack switches to
|
||||
// the new memory, the caller can get memory version PeiServiceTable.
|
||||
//
|
||||
MigrateIdtTable (PeiServices);
|
||||
|
||||
//
|
||||
// Since we are at dispatch level, only the Core's private data
|
||||
// is preserved, nobody else should have any data on the stack.
|
||||
// So we need to copy PEI core instance data to memory.
|
||||
//
|
||||
PrivateInMem = AllocateCopyPool (sizeof (PEI_CORE_INSTANCE), Private);
|
||||
ASSERT (PrivateInMem != NULL);
|
||||
|
||||
//
|
||||
// Shadow PEI Core. When permanent memory is avaiable, shadow
|
||||
// PEI Core and PEIMs to get high performance.
|
||||
//
|
||||
PeiCoreFileHandle = NULL;
|
||||
//
|
||||
// Find the PEI Core in the BFV
|
||||
//
|
||||
Status = PeiFindFileEx (
|
||||
(EFI_PEI_FV_HANDLE)Private->Fv[0].FvHeader,
|
||||
NULL,
|
||||
EFI_FV_FILETYPE_PEI_CORE,
|
||||
&PeiCoreFileHandle,
|
||||
NULL
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
//
|
||||
// Shadow PEI Core into memory so it will run faster
|
||||
//
|
||||
Status = PeiLoadImage (PeiServices, PeiCoreFileHandle, &EntryPoint, &AuthenticationState);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
//
|
||||
// Switch to memory based stack and reenter PEI Core that has been
|
||||
// shadowed to memory.
|
||||
//
|
||||
//
|
||||
// Adjust the top of stack to be aligned at CPU_STACK_ALIGNMENT
|
||||
//
|
||||
TopOfStack = (VOID *)((UINTN)Private->StackBase + (UINTN)Private->StackSize - CPU_STACK_ALIGNMENT);
|
||||
TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
|
||||
|
||||
PeiCoreParameters.SecCoreData = SecCoreData;
|
||||
PeiCoreParameters.PpiList = NULL;
|
||||
PeiCoreParameters.Data = PrivateInMem;
|
||||
ASSERT (PeiCoreParameters.Data != 0);
|
||||
|
||||
PeiSwitchStacks (
|
||||
InvokePeiCore,
|
||||
(VOID*) ((UINTN) EntryPoint + ((UINTN) PeiCore - (UINTN) _ModuleEntryPoint)),
|
||||
(VOID*) &PeiCoreParameters,
|
||||
TopOfStack,
|
||||
(VOID*)(UINTN)Private->StackBase
|
||||
);
|
||||
}
|
||||
|
||||
if ((Private->PeiMemoryInstalled) && (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW) && \
|
||||
(Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {
|
||||
//
|
||||
// If memory is availble we shadow images by default for performance reasons.
|
||||
// We call the entry point a 2nd time so the module knows it's shadowed.
|
||||
// If memory is availble we shadow images by default for performance reasons.
|
||||
// We call the entry point a 2nd time so the module knows it's shadowed.
|
||||
//
|
||||
//PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);
|
||||
PeimEntryPoint (PeimFileHandle, (const EFI_PEI_SERVICES **) PeiServices);
|
||||
//PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);
|
||||
|
||||
|
||||
//
|
||||
// PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE
|
||||
//
|
||||
@@ -518,16 +660,16 @@ Returns:
|
||||
}
|
||||
|
||||
//
|
||||
// Before making another pass, we should set Private->CurrentPeimFvCount =0 to go
|
||||
// Before making another pass, we should set Private->CurrentPeimFvCount =0 to go
|
||||
// through all the FV.
|
||||
//
|
||||
Private->CurrentPeimFvCount = 0;
|
||||
|
||||
//
|
||||
// PeimNeedingDispatch being TRUE means we found a PEIM that did not get
|
||||
// PeimNeedingDispatch being TRUE means we found a PEIM that did not get
|
||||
// dispatched. So we need to make another pass
|
||||
//
|
||||
// PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this
|
||||
// PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this
|
||||
// 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).
|
||||
//
|
||||
@@ -602,13 +744,13 @@ Returns:
|
||||
//
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Depex section not in the encapsulated section.
|
||||
// Depex section not in the encapsulated section.
|
||||
//
|
||||
Status = PeiServicesFfsFindSectionData (
|
||||
EFI_SECTION_PEI_DEPEX,
|
||||
FileHandle,
|
||||
FileHandle,
|
||||
(VOID **)&DepexData
|
||||
);
|
||||
|
||||
@@ -630,12 +772,12 @@ Returns:
|
||||
discovery permanent memory.
|
||||
|
||||
@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.
|
||||
|
||||
**/
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
PeiRegisterForShadow (
|
||||
@@ -658,52 +800,13 @@ PeiRegisterForShadow (
|
||||
//
|
||||
return EFI_ALREADY_STARTED;
|
||||
}
|
||||
|
||||
|
||||
Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] = PEIM_STATE_REGISITER_FOR_SHADOW;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
This routine invoke the PeiCore's entry in new stack environment.
|
||||
|
||||
@param Context1 The first context parameter is entry of PeiCore
|
||||
@param Context2 The second context parameter is parameter structure point for PeiCore
|
||||
|
||||
**/
|
||||
STATIC
|
||||
VOID
|
||||
InvokePeiCore (
|
||||
VOID *Context1,
|
||||
VOID *Context2
|
||||
)
|
||||
{
|
||||
PEI_CORE_ENTRY_POINT PeiCoreEntryPoint;
|
||||
PEI_CORE_PARAMETERS *PeiCoreParameters;
|
||||
|
||||
//
|
||||
// Running on new stack in SEC Core
|
||||
//
|
||||
|
||||
PeiCoreEntryPoint = (PEI_CORE_ENTRY_POINT) (UINTN) Context1;
|
||||
PeiCoreParameters = (PEI_CORE_PARAMETERS *)Context2;
|
||||
|
||||
//
|
||||
// Call PEI Core using new stack
|
||||
//
|
||||
PeiCoreEntryPoint (
|
||||
PeiCoreParameters->SecCoreData,
|
||||
PeiCoreParameters->PpiList,
|
||||
PeiCoreParameters->Data
|
||||
);
|
||||
|
||||
//
|
||||
// Never returns
|
||||
//
|
||||
ASSERT (FALSE);
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
|
||||
/**
|
||||
Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.
|
||||
@@ -712,7 +815,7 @@ InvokePeiCore (
|
||||
@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.
|
||||
|
||||
@@ -730,12 +833,12 @@ ProcessFvFile (
|
||||
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
|
||||
// Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
|
||||
// been extracted.
|
||||
//
|
||||
HobFv2.Raw = GetHobList ();
|
||||
@@ -748,7 +851,7 @@ ProcessFvFile (
|
||||
}
|
||||
HobFv2.Raw = GET_NEXT_HOB (HobFv2);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Find FvImage in FvFile
|
||||
//
|
||||
@@ -758,7 +861,7 @@ ProcessFvFile (
|
||||
FvFileHandle,
|
||||
(VOID **)&FvImageHandle
|
||||
);
|
||||
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
@@ -774,7 +877,7 @@ ProcessFvFile (
|
||||
if (FvAlignment < 8) {
|
||||
FvAlignment = 8;
|
||||
}
|
||||
//
|
||||
//
|
||||
// Check FvImage
|
||||
//
|
||||
if ((UINTN) FvImageInfo.FvStart % FvAlignment != 0) {
|
||||
@@ -788,7 +891,7 @@ ProcessFvFile (
|
||||
//
|
||||
PeiFfsGetVolumeInfo ((EFI_PEI_FV_HANDLE) FvBuffer, &FvImageInfo);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Install FvPpi and Build FvHob
|
||||
//
|
||||
@@ -817,6 +920,6 @@ ProcessFvFile (
|
||||
&FvImageInfo.FvName,
|
||||
&(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name)
|
||||
);
|
||||
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
Reference in New Issue
Block a user