mirror of https://github.com/acidanthera/audk.git
Add support for PI1.2.1 TempRam Done PPI.
Signed-off-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Jeff Fan <jeff.fan@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14847 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
fcfd5fb01b
commit
0f9ebb3216
|
@ -606,6 +606,29 @@ PeiLoadFixAddressHook(
|
|||
PrivateData->PhysicalMemoryBegin = TopLoadingAddress - TotalReservedMemorySize;
|
||||
PrivateData->FreePhysicalMemoryTop = PrivateData->PhysicalMemoryBegin + PeiMemorySize;
|
||||
}
|
||||
|
||||
/**
|
||||
This routine is invoked in switch stack as PeiCore Entry.
|
||||
|
||||
@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.
|
||||
@param Private Pointer to old core data that is used to initialize the
|
||||
core's data areas.
|
||||
**/
|
||||
VOID
|
||||
EFIAPI
|
||||
PeiCoreEntry (
|
||||
IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
|
||||
IN PEI_CORE_INSTANCE *Private
|
||||
)
|
||||
{
|
||||
//
|
||||
// Entry PEI Phase 2
|
||||
//
|
||||
PeiCore (SecCoreData, NULL, Private);
|
||||
}
|
||||
|
||||
/**
|
||||
Conduct PEIM dispatch.
|
||||
|
||||
|
@ -637,17 +660,28 @@ PeiDispatcher (
|
|||
PEIM_FILE_HANDLE_EXTENDED_DATA ExtendedData;
|
||||
EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI *TemporaryRamSupportPpi;
|
||||
UINT64 NewStackSize;
|
||||
EFI_PHYSICAL_ADDRESS BaseOfNewHeap;
|
||||
EFI_PHYSICAL_ADDRESS TopOfNewStack;
|
||||
EFI_PHYSICAL_ADDRESS TopOfOldStack;
|
||||
EFI_PHYSICAL_ADDRESS TemporaryRamBase;
|
||||
UINTN TemporaryRamSize;
|
||||
EFI_PHYSICAL_ADDRESS TemporaryStackSize;
|
||||
UINTN TemporaryStackSize;
|
||||
VOID *TemporaryStackBase;
|
||||
UINTN PeiTemporaryRamSize;
|
||||
VOID *PeiTemporaryRamBase;
|
||||
UINTN StackOffset;
|
||||
BOOLEAN StackOffsetPositive;
|
||||
EFI_PHYSICAL_ADDRESS HoleMemBase;
|
||||
UINTN HoleMemSize;
|
||||
EFI_FV_FILE_INFO FvFileInfo;
|
||||
PEI_CORE_FV_HANDLE *CoreFvHandle;
|
||||
VOID *LoadFixPeiCodeBegin;
|
||||
|
||||
EFI_PHYSICAL_ADDRESS TempBase1;
|
||||
UINTN TempSize1;
|
||||
EFI_PHYSICAL_ADDRESS TempBase2;
|
||||
UINTN TempSize2;
|
||||
UINTN Index;
|
||||
|
||||
PeiServices = (CONST EFI_PEI_SERVICES **) &Private->Ps;
|
||||
PeimEntryPoint = NULL;
|
||||
PeimFileHandle = NULL;
|
||||
|
@ -881,13 +915,6 @@ PeiDispatcher (
|
|||
//
|
||||
TopOfOldStack = (UINTN)SecCoreData->StackBase + SecCoreData->StackSize;
|
||||
TopOfNewStack = Private->PhysicalMemoryBegin + NewStackSize;
|
||||
if (TopOfNewStack >= (UINTN)SecCoreData->PeiTemporaryRamBase) {
|
||||
Private->HeapOffsetPositive = TRUE;
|
||||
Private->HeapOffset = (UINTN)(TopOfNewStack - (UINTN)SecCoreData->PeiTemporaryRamBase);
|
||||
} else {
|
||||
Private->HeapOffsetPositive = FALSE;
|
||||
Private->HeapOffset = (UINTN)((UINTN)SecCoreData->PeiTemporaryRamBase - TopOfNewStack);
|
||||
}
|
||||
if (TopOfNewStack >= TopOfOldStack) {
|
||||
StackOffsetPositive = TRUE;
|
||||
StackOffset = (UINTN)(TopOfNewStack - TopOfOldStack);
|
||||
|
@ -909,21 +936,13 @@ PeiDispatcher (
|
|||
//
|
||||
// Cache information from SecCoreData into locals before SecCoreData is converted to a permanent memory address
|
||||
//
|
||||
TemporaryRamBase = (EFI_PHYSICAL_ADDRESS)(UINTN)SecCoreData->TemporaryRamBase;
|
||||
TemporaryRamSize = SecCoreData->TemporaryRamSize;
|
||||
TemporaryStackSize = SecCoreData->StackSize;
|
||||
|
||||
//
|
||||
// Caculate new HandOffTable and PrivateData address in permanent memory's stack
|
||||
//
|
||||
if (StackOffsetPositive) {
|
||||
SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID *)SecCoreData + StackOffset);
|
||||
Private = (PEI_CORE_INSTANCE *)((UINTN)(VOID *)Private + StackOffset);
|
||||
} else {
|
||||
SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID *)SecCoreData - StackOffset);
|
||||
Private = (PEI_CORE_INSTANCE *)((UINTN)(VOID *)Private - StackOffset);
|
||||
}
|
||||
|
||||
TemporaryRamBase = (EFI_PHYSICAL_ADDRESS)(UINTN)SecCoreData->TemporaryRamBase;
|
||||
TemporaryRamSize = SecCoreData->TemporaryRamSize;
|
||||
TemporaryStackSize = SecCoreData->StackSize;
|
||||
TemporaryStackBase = SecCoreData->StackBase;
|
||||
PeiTemporaryRamSize = SecCoreData->PeiTemporaryRamSize;
|
||||
PeiTemporaryRamBase = SecCoreData->PeiTemporaryRamBase;
|
||||
|
||||
//
|
||||
// TemporaryRamSupportPpi is produced by platform's SEC
|
||||
//
|
||||
|
@ -934,6 +953,29 @@ PeiDispatcher (
|
|||
(VOID**)&TemporaryRamSupportPpi
|
||||
);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
//
|
||||
// Heap Offset
|
||||
//
|
||||
BaseOfNewHeap = TopOfNewStack;
|
||||
if (BaseOfNewHeap >= (UINTN)SecCoreData->PeiTemporaryRamBase) {
|
||||
Private->HeapOffsetPositive = TRUE;
|
||||
Private->HeapOffset = (UINTN)(BaseOfNewHeap - (UINTN)SecCoreData->PeiTemporaryRamBase);
|
||||
} else {
|
||||
Private->HeapOffsetPositive = FALSE;
|
||||
Private->HeapOffset = (UINTN)((UINTN)SecCoreData->PeiTemporaryRamBase - BaseOfNewHeap);
|
||||
}
|
||||
|
||||
//
|
||||
// Caculate new HandOffTable and PrivateData address in permanent memory's stack
|
||||
//
|
||||
if (StackOffsetPositive) {
|
||||
SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID *)SecCoreData + StackOffset);
|
||||
Private = (PEI_CORE_INSTANCE *)((UINTN)(VOID *)Private + StackOffset);
|
||||
} else {
|
||||
SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID *)SecCoreData - StackOffset);
|
||||
Private = (PEI_CORE_INSTANCE *)((UINTN)(VOID *)Private - StackOffset);
|
||||
}
|
||||
|
||||
//
|
||||
// Temporary Ram Support PPI is provided by platform, it will copy
|
||||
// temporary memory to permenent memory and do stack switching.
|
||||
|
@ -947,18 +989,98 @@ PeiDispatcher (
|
|||
TemporaryRamSize
|
||||
);
|
||||
|
||||
//
|
||||
// Entry PEI Phase 2
|
||||
//
|
||||
PeiCore (SecCoreData, NULL, Private);
|
||||
} else {
|
||||
//
|
||||
// In IA32/x64/Itanium architecture, we need platform provide
|
||||
// TEMPORARY_RAM_MIGRATION_PPI.
|
||||
// Heap Offset
|
||||
//
|
||||
ASSERT (FALSE);
|
||||
}
|
||||
BaseOfNewHeap = TopOfNewStack;
|
||||
HoleMemBase = TopOfNewStack;
|
||||
HoleMemSize = TemporaryRamSize - PeiTemporaryRamSize - TemporaryStackSize;
|
||||
if (HoleMemSize != 0) {
|
||||
BaseOfNewHeap = BaseOfNewHeap + HoleMemSize;
|
||||
}
|
||||
if (BaseOfNewHeap >= (UINTN)SecCoreData->PeiTemporaryRamBase) {
|
||||
Private->HeapOffsetPositive = TRUE;
|
||||
Private->HeapOffset = (UINTN)(BaseOfNewHeap - (UINTN)SecCoreData->PeiTemporaryRamBase);
|
||||
} else {
|
||||
Private->HeapOffsetPositive = FALSE;
|
||||
Private->HeapOffset = (UINTN)((UINTN)SecCoreData->PeiTemporaryRamBase - BaseOfNewHeap);
|
||||
}
|
||||
|
||||
//
|
||||
// Entry PEI Phase 2
|
||||
//
|
||||
PeiCore (SecCoreData, NULL, Private);
|
||||
//
|
||||
// Migrate Heap
|
||||
//
|
||||
CopyMem ((UINT8 *) (UINTN) BaseOfNewHeap, (UINT8 *) PeiTemporaryRamBase, PeiTemporaryRamSize);
|
||||
|
||||
//
|
||||
// Migrate Stack
|
||||
//
|
||||
CopyMem ((UINT8 *) (UINTN) (TopOfNewStack - TemporaryStackSize), TemporaryStackBase, TemporaryStackSize);
|
||||
|
||||
//
|
||||
// Copy Hole Range Data
|
||||
// Convert PPI from Hole.
|
||||
//
|
||||
if (HoleMemSize != 0) {
|
||||
//
|
||||
// Prepare Hole
|
||||
//
|
||||
if (PeiTemporaryRamBase < TemporaryStackBase) {
|
||||
TempBase1 = (EFI_PHYSICAL_ADDRESS) (UINTN) PeiTemporaryRamBase;
|
||||
TempSize1 = PeiTemporaryRamSize;
|
||||
TempBase2 = (EFI_PHYSICAL_ADDRESS) (UINTN) TemporaryStackBase;
|
||||
TempSize2 = TemporaryStackSize;
|
||||
} else {
|
||||
TempBase1 = (EFI_PHYSICAL_ADDRESS) (UINTN) TemporaryStackBase;
|
||||
TempSize1 = TemporaryStackSize;
|
||||
TempBase2 =(EFI_PHYSICAL_ADDRESS) (UINTN) PeiTemporaryRamBase;
|
||||
TempSize2 = PeiTemporaryRamSize;
|
||||
}
|
||||
if (TemporaryRamBase < TempBase1) {
|
||||
Private->HoleData[0].Base = TemporaryRamBase;
|
||||
Private->HoleData[0].Size = (UINTN) (TempBase1 - TemporaryRamBase);
|
||||
}
|
||||
if (TempBase1 + TempSize1 < TempBase2) {
|
||||
Private->HoleData[1].Base = TempBase1 + TempSize1;
|
||||
Private->HoleData[1].Size = (UINTN) (TempBase2 - TempBase1 - TempSize1);
|
||||
}
|
||||
if (TempBase2 + TempSize2 < TemporaryRamBase + TemporaryRamSize) {
|
||||
Private->HoleData[2].Base = TempBase2 + TempSize2;
|
||||
Private->HoleData[2].Size = (UINTN) (TemporaryRamBase + TemporaryRamSize - TempBase2 - TempSize2);
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Hole Range data.
|
||||
//
|
||||
for (Index = 0; Index < HOLE_MAX_NUMBER; Index ++) {
|
||||
if (Private->HoleData[Index].Size > 0) {
|
||||
if (HoleMemBase > Private->HoleData[Index].Base) {
|
||||
Private->HoleData[Index].OffsetPositive = TRUE;
|
||||
Private->HoleData[Index].Offset = (UINTN) (HoleMemBase - Private->HoleData[Index].Base);
|
||||
} else {
|
||||
Private->HoleData[Index].OffsetPositive = FALSE;
|
||||
Private->HoleData[Index].Offset = (UINTN) (Private->HoleData[Index].Base - HoleMemBase);
|
||||
}
|
||||
CopyMem ((VOID *) (UINTN) HoleMemBase, (VOID *) (UINTN) Private->HoleData[Index].Base, Private->HoleData[Index].Size);
|
||||
HoleMemBase = HoleMemBase + Private->HoleData[Index].Size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Switch new stack
|
||||
//
|
||||
SwitchStack (
|
||||
(SWITCH_STACK_ENTRY_POINT)(UINTN)PeiCoreEntry,
|
||||
(VOID *) SecCoreData,
|
||||
(VOID *) Private,
|
||||
(VOID *) (UINTN) TopOfNewStack
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Code should not come here
|
||||
|
|
|
@ -28,6 +28,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
#include <Ppi/LoadFile.h>
|
||||
#include <Ppi/Security2.h>
|
||||
#include <Ppi/TemporaryRamSupport.h>
|
||||
#include <Ppi/TemporaryRamDone.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/PeiCoreEntryPoint.h>
|
||||
#include <Library/BaseLib.h>
|
||||
|
@ -132,6 +133,14 @@ typedef struct {
|
|||
UINTN SectionIndex;
|
||||
} CACHE_SECTION_DATA;
|
||||
|
||||
#define HOLE_MAX_NUMBER 0x3
|
||||
typedef struct {
|
||||
EFI_PHYSICAL_ADDRESS Base;
|
||||
UINTN Size;
|
||||
UINTN Offset;
|
||||
BOOLEAN OffsetPositive;
|
||||
} HOLE_MEMORY_DATA;
|
||||
|
||||
///
|
||||
/// Forward declaration for PEI_CORE_INSTANCE
|
||||
///
|
||||
|
@ -225,6 +234,11 @@ struct _PEI_CORE_INSTANCE {
|
|||
// This field points to the shadowed image read function
|
||||
//
|
||||
PE_COFF_LOADER_READ_FILE ShadowedImageRead;
|
||||
//
|
||||
// Temp Memory Range is not covered by PeiTempMem and Stack.
|
||||
// Those Memory Range will be migrated into phisical memory.
|
||||
//
|
||||
HOLE_MEMORY_DATA HoleData[HOLE_MAX_NUMBER];
|
||||
};
|
||||
|
||||
///
|
||||
|
|
|
@ -84,7 +84,8 @@
|
|||
gEfiPeiFirmwareVolumeInfo2PpiGuid ## NOTIFY ## SOMETIMES_PRODUCES (Produce FvInfo2Ppi if the encapsulated FvImage is found)
|
||||
gEfiPeiLoadFilePpiGuid ## PRODUCES ## SOMETIMES_CONSUMES (The default load PeImage logic will be used when this PPI doesn't exist)
|
||||
gEfiPeiSecurity2PpiGuid ## NOTIFY
|
||||
gEfiTemporaryRamSupportPpiGuid ## CONSUMES
|
||||
gEfiTemporaryRamSupportPpiGuid ## SOMETIMES_CONSUMES
|
||||
gEfiTemporaryRamDonePpiGuid ## SOMETIMES_CONSUMES
|
||||
|
||||
[FixedPcd]
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported ## CONSUMES
|
||||
|
|
|
@ -120,7 +120,7 @@ ShadowPeiCore (
|
|||
from SEC to PEI. After switching stack in the PEI core, it will restart
|
||||
with the old core data.
|
||||
|
||||
@param SecCoreData Points to a data structure containing information about the PEI core's operating
|
||||
@param SecCoreDataPtr 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.
|
||||
@param PpiList Points to a list of one or more PPI descriptors to be installed initially by the PEI core.
|
||||
|
@ -137,23 +137,27 @@ ShadowPeiCore (
|
|||
VOID
|
||||
EFIAPI
|
||||
PeiCore (
|
||||
IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
|
||||
IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreDataPtr,
|
||||
IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
|
||||
IN VOID *Data
|
||||
)
|
||||
{
|
||||
PEI_CORE_INSTANCE PrivateData;
|
||||
EFI_SEC_PEI_HAND_OFF *SecCoreData;
|
||||
EFI_SEC_PEI_HAND_OFF NewSecCoreData;
|
||||
EFI_STATUS Status;
|
||||
PEI_CORE_TEMP_POINTERS TempPtr;
|
||||
PEI_CORE_INSTANCE *OldCoreData;
|
||||
EFI_PEI_CPU_IO_PPI *CpuIo;
|
||||
EFI_PEI_PCI_CFG2_PPI *PciCfg;
|
||||
EFI_HOB_HANDOFF_INFO_TABLE *HandoffInformationTable;
|
||||
|
||||
EFI_PEI_TEMPORARY_RAM_DONE_PPI *TemporaryRamDonePpi;
|
||||
|
||||
//
|
||||
// Retrieve context passed into PEI Core
|
||||
//
|
||||
OldCoreData = (PEI_CORE_INSTANCE *)Data;
|
||||
OldCoreData = (PEI_CORE_INSTANCE *) Data;
|
||||
SecCoreData = (EFI_SEC_PEI_HAND_OFF *) SecCoreDataPtr;
|
||||
|
||||
//
|
||||
// Perform PEI Core phase specific actions.
|
||||
|
@ -250,9 +254,11 @@ PeiCore (
|
|||
//
|
||||
// Memory is available to the PEI Core and the PEI Core has been shadowed to memory.
|
||||
//
|
||||
|
||||
CopyMem (&NewSecCoreData, SecCoreDataPtr, sizeof (NewSecCoreData));
|
||||
SecCoreData = &NewSecCoreData;
|
||||
|
||||
CopyMem (&PrivateData, OldCoreData, sizeof (PrivateData));
|
||||
|
||||
|
||||
CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;
|
||||
PciCfg = (VOID*)PrivateData.ServiceTableShadow.PciCfg;
|
||||
|
||||
|
@ -328,6 +334,22 @@ PeiCore (
|
|||
ASSERT_EFI_ERROR (Status);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// Try to locate Temporary RAM Done Ppi.
|
||||
//
|
||||
Status = PeiServicesLocatePpi (
|
||||
&gEfiTemporaryRamDonePpiGuid,
|
||||
0,
|
||||
NULL,
|
||||
(VOID**)&TemporaryRamDonePpi
|
||||
);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
//
|
||||
// Disable the use of Temporary RAM after the transition from Temporary RAM to Permanent RAM is complete.
|
||||
//
|
||||
TemporaryRamDonePpi->TemporaryRamDone ();
|
||||
}
|
||||
|
||||
//
|
||||
// Alert any listeners that there is permanent memory available
|
||||
//
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/** @file
|
||||
EFI PEI Core PPI services
|
||||
|
||||
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
|
||||
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
|
||||
|
@ -38,7 +38,72 @@ InitializePpiServices (
|
|||
|
||||
/**
|
||||
|
||||
Migrate the Hob list from the temporary memory stack to PEI installed memory.
|
||||
Migrate Single PPI Pointer from the temporary memory to PEI installed memory.
|
||||
|
||||
@param PpiPointer Pointer to Ppi
|
||||
@param TempBottom Base of old temporary memory
|
||||
@param TempTop Top of old temporary memory
|
||||
@param Offset Offset of new memory to old temporary memory.
|
||||
@param OffsetPositive Positive flag of Offset value.
|
||||
|
||||
**/
|
||||
VOID
|
||||
ConverSinglePpiPointer (
|
||||
IN PEI_PPI_LIST_POINTERS *PpiPointer,
|
||||
IN UINTN TempBottom,
|
||||
IN UINTN TempTop,
|
||||
IN UINTN Offset,
|
||||
IN BOOLEAN OffsetPositive
|
||||
)
|
||||
{
|
||||
if (((UINTN)PpiPointer->Raw < TempTop) &&
|
||||
((UINTN)PpiPointer->Raw >= TempBottom)) {
|
||||
//
|
||||
// Convert the pointer to the PPI descriptor from the old TempRam
|
||||
// to the relocated physical memory.
|
||||
//
|
||||
if (OffsetPositive) {
|
||||
PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw + Offset);
|
||||
} else {
|
||||
PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw - Offset);
|
||||
}
|
||||
|
||||
//
|
||||
// Only when the PEIM descriptor is in the old TempRam should it be necessary
|
||||
// to try to convert the pointers in the PEIM descriptor
|
||||
//
|
||||
|
||||
if (((UINTN)PpiPointer->Ppi->Guid < TempTop) &&
|
||||
((UINTN)PpiPointer->Ppi->Guid >= TempBottom)) {
|
||||
//
|
||||
// Convert the pointer to the GUID in the PPI or NOTIFY descriptor
|
||||
// from the old TempRam to the relocated physical memory.
|
||||
//
|
||||
if (OffsetPositive) {
|
||||
PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid + Offset);
|
||||
} else {
|
||||
PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid - Offset);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Convert the pointer to the PPI interface structure in the PPI descriptor
|
||||
// from the old TempRam to the relocated physical memory.
|
||||
//
|
||||
if ((UINTN)PpiPointer->Ppi->Ppi < TempTop &&
|
||||
(UINTN)PpiPointer->Ppi->Ppi >= TempBottom) {
|
||||
if (OffsetPositive) {
|
||||
PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi + Offset);
|
||||
} else {
|
||||
PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi - Offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Migrate PPI Pointers from the temporary memory stack to PEI installed memory.
|
||||
|
||||
@param SecCoreData Points to a data structure containing SEC to PEI handoff data, such as the size
|
||||
and location of temporary RAM, the stack location and the BFV location.
|
||||
|
@ -52,114 +117,47 @@ ConvertPpiPointers (
|
|||
)
|
||||
{
|
||||
UINT8 Index;
|
||||
PEI_PPI_LIST_POINTERS *PpiPointer;
|
||||
UINTN OldHeapTop;
|
||||
UINTN OldHeapBottom;
|
||||
UINTN OldStackTop;
|
||||
UINTN OldStackBottom;
|
||||
|
||||
OldHeapBottom = (UINTN)SecCoreData->PeiTemporaryRamBase;
|
||||
OldHeapTop = (UINTN)SecCoreData->PeiTemporaryRamBase + SecCoreData->PeiTemporaryRamSize;
|
||||
OldStackBottom = (UINTN)SecCoreData->StackBase;
|
||||
OldStackTop = (UINTN)SecCoreData->StackBase + SecCoreData->StackSize;
|
||||
UINT8 IndexHole;
|
||||
|
||||
for (Index = 0; Index < FixedPcdGet32 (PcdPeiCoreMaxPpiSupported); Index++) {
|
||||
if (Index < PrivateData->PpiData.PpiListEnd ||
|
||||
Index > PrivateData->PpiData.NotifyListEnd) {
|
||||
PpiPointer = &PrivateData->PpiData.PpiListPtrs[Index];
|
||||
|
||||
if (((UINTN)PpiPointer->Raw < OldHeapTop) &&
|
||||
((UINTN)PpiPointer->Raw >= OldHeapBottom)) {
|
||||
//
|
||||
// Convert the pointer to the PPI descriptor from the old HOB heap
|
||||
// to the relocated HOB heap.
|
||||
//
|
||||
if (PrivateData->HeapOffsetPositive) {
|
||||
PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw + PrivateData->HeapOffset);
|
||||
} else {
|
||||
PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw - PrivateData->HeapOffset);
|
||||
}
|
||||
|
||||
//
|
||||
// Only when the PEIM descriptor is in the old HOB should it be necessary
|
||||
// to try to convert the pointers in the PEIM descriptor
|
||||
//
|
||||
|
||||
if (((UINTN)PpiPointer->Ppi->Guid < OldHeapTop) &&
|
||||
((UINTN)PpiPointer->Ppi->Guid >= OldHeapBottom)) {
|
||||
//
|
||||
// Convert the pointer to the GUID in the PPI or NOTIFY descriptor
|
||||
// from the old HOB heap to the relocated HOB heap.
|
||||
//
|
||||
if (PrivateData->HeapOffsetPositive) {
|
||||
PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid + PrivateData->HeapOffset);
|
||||
} else {
|
||||
PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid - PrivateData->HeapOffset);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Assume that no code is located in the temporary memory, so the pointer to
|
||||
// the notification function in the NOTIFY descriptor needs not be converted.
|
||||
//
|
||||
if (Index < PrivateData->PpiData.PpiListEnd &&
|
||||
(UINTN)PpiPointer->Ppi->Ppi < OldHeapTop &&
|
||||
(UINTN)PpiPointer->Ppi->Ppi >= OldHeapBottom) {
|
||||
//
|
||||
// Convert the pointer to the PPI interface structure in the PPI descriptor
|
||||
// from the old HOB heap to the relocated HOB heap.
|
||||
//
|
||||
if (PrivateData->HeapOffsetPositive) {
|
||||
PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi + PrivateData->HeapOffset);
|
||||
} else {
|
||||
PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi - PrivateData->HeapOffset);
|
||||
}
|
||||
}
|
||||
} else if (((UINTN)PpiPointer->Raw < OldStackTop) && ((UINTN)PpiPointer->Raw >= OldStackBottom)) {
|
||||
//
|
||||
// Convert the pointer to the PPI descriptor from the temporary stack
|
||||
// to the permanent PEI stack.
|
||||
//
|
||||
if (PrivateData->StackOffsetPositive) {
|
||||
PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw + PrivateData->StackOffset);
|
||||
} else {
|
||||
PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw - PrivateData->StackOffset);
|
||||
}
|
||||
|
||||
//
|
||||
// Try to convert the pointers in the PEIM descriptor
|
||||
//
|
||||
|
||||
if (((UINTN)PpiPointer->Ppi->Guid < OldStackTop) &&
|
||||
((UINTN)PpiPointer->Ppi->Guid >= OldStackBottom)) {
|
||||
//
|
||||
// Convert the pointer to the GUID in the PPI or NOTIFY descriptor
|
||||
// from the the temporary stack to the permanent PEI stack.
|
||||
//
|
||||
if (PrivateData->StackOffsetPositive) {
|
||||
PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid + PrivateData->StackOffset);
|
||||
} else {
|
||||
PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid - PrivateData->StackOffset);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Assume that no code is located in the temporary memory, so the pointer to
|
||||
// the notification function in the NOTIFY descriptor needs not be converted.
|
||||
//
|
||||
if (Index < PrivateData->PpiData.PpiListEnd &&
|
||||
(UINTN)PpiPointer->Ppi->Ppi < OldStackTop &&
|
||||
(UINTN)PpiPointer->Ppi->Ppi >= OldStackBottom) {
|
||||
//
|
||||
// Convert the pointer to the PPI interface structure in the PPI descriptor
|
||||
// from the the temporary stack to the permanent PEI stack.
|
||||
//
|
||||
if (PrivateData->StackOffsetPositive) {
|
||||
PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi + PrivateData->StackOffset);
|
||||
} else {
|
||||
PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi - PrivateData->StackOffset);
|
||||
}
|
||||
if (Index < PrivateData->PpiData.PpiListEnd || Index > PrivateData->PpiData.NotifyListEnd) {
|
||||
//
|
||||
// Convert PPI pointer in old Heap
|
||||
//
|
||||
ConverSinglePpiPointer (
|
||||
&PrivateData->PpiData.PpiListPtrs[Index],
|
||||
(UINTN)SecCoreData->PeiTemporaryRamBase,
|
||||
(UINTN)SecCoreData->PeiTemporaryRamBase + SecCoreData->PeiTemporaryRamSize,
|
||||
PrivateData->HeapOffset,
|
||||
PrivateData->HeapOffsetPositive
|
||||
);
|
||||
|
||||
//
|
||||
// Convert PPI pointer in old Stack
|
||||
//
|
||||
ConverSinglePpiPointer (
|
||||
&PrivateData->PpiData.PpiListPtrs[Index],
|
||||
(UINTN)SecCoreData->StackBase,
|
||||
(UINTN)SecCoreData->StackBase + SecCoreData->StackSize,
|
||||
PrivateData->StackOffset,
|
||||
PrivateData->StackOffsetPositive
|
||||
);
|
||||
|
||||
//
|
||||
// Convert PPI pointer in old TempRam Hole
|
||||
//
|
||||
for (IndexHole = 0; IndexHole < HOLE_MAX_NUMBER; IndexHole ++) {
|
||||
if (PrivateData->HoleData[IndexHole].Size == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ConverSinglePpiPointer (
|
||||
&PrivateData->PpiData.PpiListPtrs[Index],
|
||||
(UINTN)PrivateData->HoleData[IndexHole].Base,
|
||||
(UINTN)PrivateData->HoleData[IndexHole].Base + PrivateData->HoleData[IndexHole].Size,
|
||||
PrivateData->HoleData[IndexHole].Offset,
|
||||
PrivateData->HoleData[IndexHole].OffsetPositive
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue