AsmRelocateApLoop is replicated for future Intel Logic Extraction,
further brings AP into 64-bit, and enables paging.
Signed-off-by: Yuanhao Xie
---
UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 51
+++
UefiCpuPkg/Library/MpInitLib/MpEqu.inc| 2 ++
UefiCpuPkg/Library/MpInitLib/MpLib.h | 27 +++
UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm | 169
+
UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 6 ++
5 files changed, 235 insertions(+), 20 deletions(-)
diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index a84e9e33ba..31caa9211f 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -378,32 +378,43 @@ RelocateApLoop (
IN OUT VOID *Buffer
)
{
- CPU_MP_DATA *CpuMpData;
- BOOLEAN MwaitSupport;
- ASM_RELOCATE_AP_LOOP AsmRelocateApLoopFunc;
- UINTN ProcessorNumber;
- UINTN StackStart;
+ CPU_MP_DATA *CpuMpData;
+ BOOLEAN MwaitSupport;
+ ASM_RELOCATE_AP_LOOP AsmRelocateApLoopFunc;
+ ASM_RELOCATE_AP_LOOP_AMD AsmRelocateApLoopFuncAmd;
+ UINTN ProcessorNumber;
+ UINTN StackStart;
MpInitLibWhoAmI (&ProcessorNumber);
CpuMpData= GetCpuMpData ();
MwaitSupport = IsMwaitSupport ();
- if (CpuMpData->UseSevEsAPMethod) {
-StackStart = CpuMpData->SevEsAPResetStackStart;
+ if (StandardSignatureIsAuthenticAMD ()) {
+StackStart = CpuMpData->SevEsAPResetStackStart;
+AsmRelocateApLoopFuncAmd =
(ASM_RELOCATE_AP_LOOP_AMD)(UINTN)mReservedApLoopFunc;
+AsmRelocateApLoopFuncAmd (
+ MwaitSupport,
+ CpuMpData->ApTargetCState,
+ CpuMpData->PmCodeSegment,
+ StackStart - ProcessorNumber * AP_SAFE_STACK_SIZE,
+ (UINTN)&mNumberToFinish,
+ CpuMpData->Pm16CodeSegment,
+ CpuMpData->SevEsAPBuffer,
+ CpuMpData->WakeupBuffer
+ );
} else {
-StackStart = mReservedTopOfApStack;
+StackStart= mReservedTopOfApStack;
+AsmRelocateApLoopFunc = (ASM_RELOCATE_AP_LOOP)(UINTN)mReservedApLoopFunc;
+AsmRelocateApLoopFunc (
+ MwaitSupport,
+ CpuMpData->ApTargetCState,
+ CpuMpData->PmCodeSegment,
+ StackStart - ProcessorNumber * AP_SAFE_STACK_SIZE,
+ (UINTN)&mNumberToFinish,
+ CpuMpData->Pm16CodeSegment,
+ CpuMpData->SevEsAPBuffer,
+ CpuMpData->WakeupBuffer
+ );
}
-
- AsmRelocateApLoopFunc = (ASM_RELOCATE_AP_LOOP)(UINTN)mReservedApLoopFunc;
- AsmRelocateApLoopFunc (
-MwaitSupport,
-CpuMpData->ApTargetCState,
-CpuMpData->PmCodeSegment,
-StackStart - ProcessorNumber * AP_SAFE_STACK_SIZE,
-(UINTN)&mNumberToFinish,
-CpuMpData->Pm16CodeSegment,
-CpuMpData->SevEsAPBuffer,
-CpuMpData->WakeupBuffer
-);
//
// It should never reach here
//
diff --git a/UefiCpuPkg/Library/MpInitLib/MpEqu.inc
b/UefiCpuPkg/Library/MpInitLib/MpEqu.inc
index ebadcc6fb3..ea202d4aef 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpEqu.inc
+++ b/UefiCpuPkg/Library/MpInitLib/MpEqu.inc
@@ -26,6 +26,8 @@ struc MP_ASSEMBLY_ADDRESS_MAP
.RendezvousFunnelSize CTYPE_UINTN 1
.RelocateApLoopFuncAddress CTYPE_UINTN 1
.RelocateApLoopFuncSizeCTYPE_UINTN 1
+ .RelocateApLoopFuncAddressAmd CTYPE_UINTN 1
+ .RelocateApLoopFuncSizeAmd CTYPE_UINTN 1
.ModeTransitionOffset CTYPE_UINTN 1
.SwitchToRealNoNxOffsetCTYPE_UINTN 1
.SwitchToRealPM16ModeOffsetCTYPE_UINTN 1
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index f5086e497e..1102003a93 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -179,6 +179,8 @@ typedef struct {
UINTNRendezvousFunnelSize;
UINT8*RelocateApLoopFuncAddress;
UINTNRelocateApLoopFuncSize;
+ UINT8*RelocateApLoopFuncAddressAmd;
+ UINTNRelocateApLoopFuncSizeAmd;
UINTNModeTransitionOffset;
UINTNSwitchToRealNoNxOffset;
UINTNSwitchToRealPM16ModeOffset;
@@ -346,6 +348,31 @@ typedef
extern EFI_GUID mCpuInitMpLibHobGuid;
+/**
+ Assembly code to place AP into safe loop mode for Amd.
+ Place AP into targeted C-State if MONITOR is supported, otherwise
+ place AP into hlt state.
+ Place AP in protected mode if the current is long mode. Due to AP maybe
+ wakeup by some hardware event. It could avoid accessing page table that
+ may not available during booting to OS.
+ @param[in] MwaitSupportTRUE indicates MONITOR is supported.
+ FALSE indicates MONITOR is not supported.
+ @param[in] ApTargetCState Target C-State value.
+ @param[in] PmCodeSegm