mirror of https://github.com/acidanthera/audk.git
OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937 There are below major changes in PlatformInitLib/PlatformPei 1. ProcessHobList The unaccepted memory is accepted if it is under 4G address. Please be noted: in current stage, we only accept the memory under 4G. We will re-visit here in the future when on-demand accept memory is required. 2. TransferTdxHobList Transfer the unaccepted memory hob to EFI_RESOURCE_SYSTEM_MEMORY hob if it is accepted. Cc: Erdem Aktas <erdemaktas@google.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: James Bottomley <jejb@linux.ibm.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Tom Lendacky <thomas.lendacky@amd.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Min Xu <min.m.xu@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
This commit is contained in:
parent
6ca9f410d1
commit
d1e41c620f
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
#include <Base.h>
|
||||||
#include <PiPei.h>
|
#include <PiPei.h>
|
||||||
#include <Library/BaseLib.h>
|
#include <Library/BaseLib.h>
|
||||||
#include <Library/DebugLib.h>
|
#include <Library/DebugLib.h>
|
||||||
|
@ -25,6 +26,7 @@
|
||||||
#include <ConfidentialComputingGuestAttr.h>
|
#include <ConfidentialComputingGuestAttr.h>
|
||||||
|
|
||||||
#define ALIGNED_2MB_MASK 0x1fffff
|
#define ALIGNED_2MB_MASK 0x1fffff
|
||||||
|
#define MEGABYTE_SHIFT 20
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This function will be called to accept pages. Only BSP accepts pages.
|
This function will be called to accept pages. Only BSP accepts pages.
|
||||||
|
@ -375,11 +377,15 @@ ProcessHobList (
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
EFI_PEI_HOB_POINTERS Hob;
|
EFI_PEI_HOB_POINTERS Hob;
|
||||||
EFI_PHYSICAL_ADDRESS PhysicalEnd;
|
EFI_PHYSICAL_ADDRESS PhysicalEnd;
|
||||||
|
UINT64 ResourceLength;
|
||||||
|
UINT64 AccumulateAcceptedMemory;
|
||||||
|
|
||||||
Status = EFI_SUCCESS;
|
Status = EFI_SUCCESS;
|
||||||
ASSERT (VmmHobList != NULL);
|
ASSERT (VmmHobList != NULL);
|
||||||
Hob.Raw = (UINT8 *)VmmHobList;
|
Hob.Raw = (UINT8 *)VmmHobList;
|
||||||
|
|
||||||
|
AccumulateAcceptedMemory = 0;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Parse the HOB list until end of list or matching type is found.
|
// Parse the HOB list until end of list or matching type is found.
|
||||||
//
|
//
|
||||||
|
@ -394,6 +400,14 @@ ProcessHobList (
|
||||||
DEBUG ((DEBUG_INFO, "Owner: %g\n\n", &Hob.ResourceDescriptor->Owner));
|
DEBUG ((DEBUG_INFO, "Owner: %g\n\n", &Hob.ResourceDescriptor->Owner));
|
||||||
|
|
||||||
PhysicalEnd = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength;
|
PhysicalEnd = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength;
|
||||||
|
ResourceLength = Hob.ResourceDescriptor->ResourceLength;
|
||||||
|
|
||||||
|
if (Hob.ResourceDescriptor->PhysicalStart >= BASE_4GB) {
|
||||||
|
//
|
||||||
|
// In current stage, we only accept the memory under 4G
|
||||||
|
//
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
Status = BspAcceptMemoryResourceRange (
|
Status = BspAcceptMemoryResourceRange (
|
||||||
Hob.ResourceDescriptor->PhysicalStart,
|
Hob.ResourceDescriptor->PhysicalStart,
|
||||||
|
@ -402,6 +416,8 @@ ProcessHobList (
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AccumulateAcceptedMemory += ResourceLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -460,6 +476,60 @@ ProcessTdxHobList (
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build ResourceDescriptorHob for the unaccepted memory region.
|
||||||
|
* This memory region may be splitted into 2 parts because of lazy accept.
|
||||||
|
*
|
||||||
|
* @param Hob Point to the EFI_HOB_RESOURCE_DESCRIPTOR
|
||||||
|
* @return VOID
|
||||||
|
*/
|
||||||
|
VOID
|
||||||
|
BuildResourceDescriptorHobForUnacceptedMemory (
|
||||||
|
IN EFI_HOB_RESOURCE_DESCRIPTOR *Hob
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_PHYSICAL_ADDRESS PhysicalStart;
|
||||||
|
EFI_PHYSICAL_ADDRESS PhysicalEnd;
|
||||||
|
UINT64 ResourceLength;
|
||||||
|
EFI_RESOURCE_TYPE ResourceType;
|
||||||
|
EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute;
|
||||||
|
UINT64 MaxAcceptedMemoryAddress;
|
||||||
|
|
||||||
|
ASSERT (Hob->ResourceType == BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED);
|
||||||
|
|
||||||
|
ResourceType = BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED;
|
||||||
|
ResourceAttribute = Hob->ResourceAttribute;
|
||||||
|
PhysicalStart = Hob->PhysicalStart;
|
||||||
|
ResourceLength = Hob->ResourceLength;
|
||||||
|
PhysicalEnd = PhysicalStart + ResourceLength;
|
||||||
|
|
||||||
|
//
|
||||||
|
// In the first stage of lazy-accept, all the memory under 4G will be accepted.
|
||||||
|
// The memory above 4G will not be accepted.
|
||||||
|
//
|
||||||
|
MaxAcceptedMemoryAddress = BASE_4GB;
|
||||||
|
|
||||||
|
if (PhysicalEnd <= MaxAcceptedMemoryAddress) {
|
||||||
|
//
|
||||||
|
// This memory region has been accepted.
|
||||||
|
//
|
||||||
|
ResourceType = EFI_RESOURCE_SYSTEM_MEMORY;
|
||||||
|
ResourceAttribute |= (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED);
|
||||||
|
} else if (PhysicalStart >= MaxAcceptedMemoryAddress) {
|
||||||
|
//
|
||||||
|
// This memory region hasn't been accepted.
|
||||||
|
// So keep the ResourceType and ResourceAttribute unchange.
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
BuildResourceDescriptorHob (
|
||||||
|
ResourceType,
|
||||||
|
ResourceAttribute,
|
||||||
|
PhysicalStart,
|
||||||
|
ResourceLength
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Transfer the incoming HobList for the TD to the final HobList for Dxe.
|
Transfer the incoming HobList for the TD to the final HobList for Dxe.
|
||||||
The Hobs transferred in this function are ResourceDescriptor hob and
|
The Hobs transferred in this function are ResourceDescriptor hob and
|
||||||
|
@ -489,16 +559,16 @@ TransferTdxHobList (
|
||||||
ResourceAttribute = Hob.ResourceDescriptor->ResourceAttribute;
|
ResourceAttribute = Hob.ResourceDescriptor->ResourceAttribute;
|
||||||
|
|
||||||
if (ResourceType == BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED) {
|
if (ResourceType == BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED) {
|
||||||
ResourceType = EFI_RESOURCE_SYSTEM_MEMORY;
|
BuildResourceDescriptorHobForUnacceptedMemory (Hob.ResourceDescriptor);
|
||||||
ResourceAttribute |= (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED);
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
BuildResourceDescriptorHob (
|
BuildResourceDescriptorHob (
|
||||||
ResourceType,
|
ResourceType,
|
||||||
ResourceAttribute,
|
ResourceAttribute,
|
||||||
Hob.ResourceDescriptor->PhysicalStart,
|
Hob.ResourceDescriptor->PhysicalStart,
|
||||||
Hob.ResourceDescriptor->ResourceLength
|
Hob.ResourceDescriptor->ResourceLength
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EFI_HOB_TYPE_MEMORY_ALLOCATION:
|
case EFI_HOB_TYPE_MEMORY_ALLOCATION:
|
||||||
BuildMemoryAllocationHob (
|
BuildMemoryAllocationHob (
|
||||||
|
|
|
@ -42,6 +42,8 @@ Module Name:
|
||||||
|
|
||||||
#include <Library/PlatformInitLib.h>
|
#include <Library/PlatformInitLib.h>
|
||||||
|
|
||||||
|
#define MEGABYTE_SHIFT 20
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
EFIAPI
|
EFIAPI
|
||||||
PlatformQemuUc32BaseInitialization (
|
PlatformQemuUc32BaseInitialization (
|
||||||
|
|
Loading…
Reference in New Issue