mirror of https://github.com/acidanthera/audk.git
Revert "UefiCpuPkg: Duplicated AsmRelocateApLoop as AsmRelocateApLoopAmd"
This reverts commit 7bda8c6481
.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=4234
Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Cc: James Lu <james.lu@intel.com>
Cc: Gua Guo <gua.guo@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com>
This commit is contained in:
parent
ae80fe997d
commit
33a3408fbb
|
@ -1,7 +1,7 @@
|
||||||
/** @file
|
/** @file
|
||||||
MP initialize support functions for DXE phase.
|
MP initialize support functions for DXE phase.
|
||||||
|
|
||||||
Copyright (c) 2016 - 2022, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2016 - 2020, Intel Corporation. All rights reserved.<BR>
|
||||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
@ -381,28 +381,18 @@ RelocateApLoop (
|
||||||
CPU_MP_DATA *CpuMpData;
|
CPU_MP_DATA *CpuMpData;
|
||||||
BOOLEAN MwaitSupport;
|
BOOLEAN MwaitSupport;
|
||||||
ASM_RELOCATE_AP_LOOP AsmRelocateApLoopFunc;
|
ASM_RELOCATE_AP_LOOP AsmRelocateApLoopFunc;
|
||||||
ASM_RELOCATE_AP_LOOP_AMD AsmRelocateApLoopFuncAmd;
|
|
||||||
UINTN ProcessorNumber;
|
UINTN ProcessorNumber;
|
||||||
UINTN StackStart;
|
UINTN StackStart;
|
||||||
|
|
||||||
MpInitLibWhoAmI (&ProcessorNumber);
|
MpInitLibWhoAmI (&ProcessorNumber);
|
||||||
CpuMpData = GetCpuMpData ();
|
CpuMpData = GetCpuMpData ();
|
||||||
MwaitSupport = IsMwaitSupport ();
|
MwaitSupport = IsMwaitSupport ();
|
||||||
if (StandardSignatureIsAuthenticAMD ()) {
|
if (CpuMpData->UseSevEsAPMethod) {
|
||||||
StackStart = CpuMpData->UseSevEsAPMethod ? CpuMpData->SevEsAPResetStackStart : mReservedTopOfApStack;
|
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 {
|
} else {
|
||||||
StackStart = mReservedTopOfApStack;
|
StackStart = mReservedTopOfApStack;
|
||||||
|
}
|
||||||
|
|
||||||
AsmRelocateApLoopFunc = (ASM_RELOCATE_AP_LOOP)(UINTN)mReservedApLoopFunc;
|
AsmRelocateApLoopFunc = (ASM_RELOCATE_AP_LOOP)(UINTN)mReservedApLoopFunc;
|
||||||
AsmRelocateApLoopFunc (
|
AsmRelocateApLoopFunc (
|
||||||
MwaitSupport,
|
MwaitSupport,
|
||||||
|
@ -414,8 +404,6 @@ RelocateApLoop (
|
||||||
CpuMpData->SevEsAPBuffer,
|
CpuMpData->SevEsAPBuffer,
|
||||||
CpuMpData->WakeupBuffer
|
CpuMpData->WakeupBuffer
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// It should never reach here
|
// It should never reach here
|
||||||
//
|
//
|
||||||
|
|
|
@ -26,8 +26,6 @@ struc MP_ASSEMBLY_ADDRESS_MAP
|
||||||
.RendezvousFunnelSize CTYPE_UINTN 1
|
.RendezvousFunnelSize CTYPE_UINTN 1
|
||||||
.RelocateApLoopFuncAddress CTYPE_UINTN 1
|
.RelocateApLoopFuncAddress CTYPE_UINTN 1
|
||||||
.RelocateApLoopFuncSize CTYPE_UINTN 1
|
.RelocateApLoopFuncSize CTYPE_UINTN 1
|
||||||
.RelocateApLoopFuncAddressAmd CTYPE_UINTN 1
|
|
||||||
.RelocateApLoopFuncSizeAmd CTYPE_UINTN 1
|
|
||||||
.ModeTransitionOffset CTYPE_UINTN 1
|
.ModeTransitionOffset CTYPE_UINTN 1
|
||||||
.SwitchToRealNoNxOffset CTYPE_UINTN 1
|
.SwitchToRealNoNxOffset CTYPE_UINTN 1
|
||||||
.SwitchToRealPM16ModeOffset CTYPE_UINTN 1
|
.SwitchToRealPM16ModeOffset CTYPE_UINTN 1
|
||||||
|
|
|
@ -179,8 +179,6 @@ typedef struct {
|
||||||
UINTN RendezvousFunnelSize;
|
UINTN RendezvousFunnelSize;
|
||||||
UINT8 *RelocateApLoopFuncAddress;
|
UINT8 *RelocateApLoopFuncAddress;
|
||||||
UINTN RelocateApLoopFuncSize;
|
UINTN RelocateApLoopFuncSize;
|
||||||
UINT8 *RelocateApLoopFuncAddressAmd;
|
|
||||||
UINTN RelocateApLoopFuncSizeAmd;
|
|
||||||
UINTN ModeTransitionOffset;
|
UINTN ModeTransitionOffset;
|
||||||
UINTN SwitchToRealNoNxOffset;
|
UINTN SwitchToRealNoNxOffset;
|
||||||
UINTN SwitchToRealPM16ModeOffset;
|
UINTN SwitchToRealPM16ModeOffset;
|
||||||
|
@ -348,31 +346,6 @@ typedef
|
||||||
|
|
||||||
extern EFI_GUID mCpuInitMpLibHobGuid;
|
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] MwaitSupport TRUE indicates MONITOR is supported.
|
|
||||||
FALSE indicates MONITOR is not supported.
|
|
||||||
@param[in] ApTargetCState Target C-State value.
|
|
||||||
@param[in] PmCodeSegment Protected mode code segment value.
|
|
||||||
**/
|
|
||||||
typedef
|
|
||||||
VOID
|
|
||||||
(EFIAPI *ASM_RELOCATE_AP_LOOP_AMD)(
|
|
||||||
IN BOOLEAN MwaitSupport,
|
|
||||||
IN UINTN ApTargetCState,
|
|
||||||
IN UINTN PmCodeSegment,
|
|
||||||
IN UINTN TopOfApStack,
|
|
||||||
IN UINTN NumberToFinish,
|
|
||||||
IN UINTN Pm16CodeSegment,
|
|
||||||
IN UINTN SevEsAPJumpTable,
|
|
||||||
IN UINTN WakeupBuffer
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Assembly code to place AP into safe loop mode.
|
Assembly code to place AP into safe loop mode.
|
||||||
|
|
||||||
|
|
|
@ -346,172 +346,3 @@ PM16Mode:
|
||||||
iret
|
iret
|
||||||
|
|
||||||
SwitchToRealProcEnd:
|
SwitchToRealProcEnd:
|
||||||
;-------------------------------------------------------------------------------------
|
|
||||||
; AsmRelocateApLoopAmd (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack, CountTofinish, Pm16CodeSegment, SevEsAPJumpTable, WakeupBuffer);
|
|
||||||
;-------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
AsmRelocateApLoopStartAmd:
|
|
||||||
BITS 64
|
|
||||||
cmp qword [rsp + 56], 0 ; SevEsAPJumpTable
|
|
||||||
je NoSevEsAmd
|
|
||||||
|
|
||||||
;
|
|
||||||
; Perform some SEV-ES related setup before leaving 64-bit mode
|
|
||||||
;
|
|
||||||
push rcx
|
|
||||||
push rdx
|
|
||||||
|
|
||||||
;
|
|
||||||
; Get the RDX reset value using CPUID
|
|
||||||
;
|
|
||||||
mov rax, 1
|
|
||||||
cpuid
|
|
||||||
mov rsi, rax ; Save off the reset value for RDX
|
|
||||||
|
|
||||||
;
|
|
||||||
; Prepare the GHCB for the AP_HLT_LOOP VMGEXIT call
|
|
||||||
; - Must be done while in 64-bit long mode so that writes to
|
|
||||||
; the GHCB memory will be unencrypted.
|
|
||||||
; - No NAE events can be generated once this is set otherwise
|
|
||||||
; the AP_RESET_HOLD SW_EXITCODE will be overwritten.
|
|
||||||
;
|
|
||||||
mov rcx, 0xc0010130
|
|
||||||
rdmsr ; Retrieve current GHCB address
|
|
||||||
shl rdx, 32
|
|
||||||
or rdx, rax
|
|
||||||
|
|
||||||
mov rdi, rdx
|
|
||||||
xor rax, rax
|
|
||||||
mov rcx, 0x800
|
|
||||||
shr rcx, 3
|
|
||||||
rep stosq ; Clear the GHCB
|
|
||||||
|
|
||||||
mov rax, 0x80000004 ; VMGEXIT AP_RESET_HOLD
|
|
||||||
mov [rdx + 0x390], rax
|
|
||||||
mov rax, 114 ; Set SwExitCode valid bit
|
|
||||||
bts [rdx + 0x3f0], rax
|
|
||||||
inc rax ; Set SwExitInfo1 valid bit
|
|
||||||
bts [rdx + 0x3f0], rax
|
|
||||||
inc rax ; Set SwExitInfo2 valid bit
|
|
||||||
bts [rdx + 0x3f0], rax
|
|
||||||
|
|
||||||
pop rdx
|
|
||||||
pop rcx
|
|
||||||
|
|
||||||
NoSevEsAmd:
|
|
||||||
cli ; Disable interrupt before switching to 32-bit mode
|
|
||||||
mov rax, [rsp + 40] ; CountTofinish
|
|
||||||
lock dec dword [rax] ; (*CountTofinish)--
|
|
||||||
|
|
||||||
mov r10, [rsp + 48] ; Pm16CodeSegment
|
|
||||||
mov rax, [rsp + 56] ; SevEsAPJumpTable
|
|
||||||
mov rbx, [rsp + 64] ; WakeupBuffer
|
|
||||||
mov rsp, r9 ; TopOfApStack
|
|
||||||
|
|
||||||
push rax ; Save SevEsAPJumpTable
|
|
||||||
push rbx ; Save WakeupBuffer
|
|
||||||
push r10 ; Save Pm16CodeSegment
|
|
||||||
push rcx ; Save MwaitSupport
|
|
||||||
push rdx ; Save ApTargetCState
|
|
||||||
|
|
||||||
lea rax, [PmEntryAmd] ; rax <- The start address of transition code
|
|
||||||
|
|
||||||
push r8
|
|
||||||
push rax
|
|
||||||
|
|
||||||
;
|
|
||||||
; Clear R8 - R15, for reset, before going into 32-bit mode
|
|
||||||
;
|
|
||||||
xor r8, r8
|
|
||||||
xor r9, r9
|
|
||||||
xor r10, r10
|
|
||||||
xor r11, r11
|
|
||||||
xor r12, r12
|
|
||||||
xor r13, r13
|
|
||||||
xor r14, r14
|
|
||||||
xor r15, r15
|
|
||||||
|
|
||||||
;
|
|
||||||
; Far return into 32-bit mode
|
|
||||||
;
|
|
||||||
o64 retf
|
|
||||||
|
|
||||||
BITS 32
|
|
||||||
PmEntryAmd:
|
|
||||||
mov eax, cr0
|
|
||||||
btr eax, 31 ; Clear CR0.PG
|
|
||||||
mov cr0, eax ; Disable paging and caches
|
|
||||||
|
|
||||||
mov ecx, 0xc0000080
|
|
||||||
rdmsr
|
|
||||||
and ah, ~ 1 ; Clear LME
|
|
||||||
wrmsr
|
|
||||||
mov eax, cr4
|
|
||||||
and al, ~ (1 << 5) ; Clear PAE
|
|
||||||
mov cr4, eax
|
|
||||||
|
|
||||||
pop edx
|
|
||||||
add esp, 4
|
|
||||||
pop ecx,
|
|
||||||
add esp, 4
|
|
||||||
|
|
||||||
MwaitCheckAmd:
|
|
||||||
cmp cl, 1 ; Check mwait-monitor support
|
|
||||||
jnz HltLoopAmd
|
|
||||||
mov ebx, edx ; Save C-State to ebx
|
|
||||||
MwaitLoopAmd:
|
|
||||||
cli
|
|
||||||
mov eax, esp ; Set Monitor Address
|
|
||||||
xor ecx, ecx ; ecx = 0
|
|
||||||
xor edx, edx ; edx = 0
|
|
||||||
monitor
|
|
||||||
mov eax, ebx ; Mwait Cx, Target C-State per eax[7:4]
|
|
||||||
shl eax, 4
|
|
||||||
mwait
|
|
||||||
jmp MwaitLoopAmd
|
|
||||||
|
|
||||||
HltLoopAmd:
|
|
||||||
pop edx ; PM16CodeSegment
|
|
||||||
add esp, 4
|
|
||||||
pop ebx ; WakeupBuffer
|
|
||||||
add esp, 4
|
|
||||||
pop eax ; SevEsAPJumpTable
|
|
||||||
add esp, 4
|
|
||||||
cmp eax, 0 ; Check for SEV-ES
|
|
||||||
je DoHltAmd
|
|
||||||
|
|
||||||
cli
|
|
||||||
;
|
|
||||||
; SEV-ES is enabled, use VMGEXIT (GHCB information already
|
|
||||||
; set by caller)
|
|
||||||
;
|
|
||||||
BITS 64
|
|
||||||
rep vmmcall
|
|
||||||
BITS 32
|
|
||||||
|
|
||||||
;
|
|
||||||
; Back from VMGEXIT AP_HLT_LOOP
|
|
||||||
; Push the FLAGS/CS/IP values to use
|
|
||||||
;
|
|
||||||
push word 0x0002 ; EFLAGS
|
|
||||||
xor ecx, ecx
|
|
||||||
mov cx, [eax + 2] ; CS
|
|
||||||
push cx
|
|
||||||
mov cx, [eax] ; IP
|
|
||||||
push cx
|
|
||||||
push word 0x0000 ; For alignment, will be discarded
|
|
||||||
|
|
||||||
push edx
|
|
||||||
push ebx
|
|
||||||
|
|
||||||
mov edx, esi ; Restore RDX reset value
|
|
||||||
|
|
||||||
retf
|
|
||||||
|
|
||||||
DoHltAmd:
|
|
||||||
cli
|
|
||||||
hlt
|
|
||||||
jmp DoHltAmd
|
|
||||||
|
|
||||||
BITS 64
|
|
||||||
AsmRelocateApLoopEndAmd:
|
|
||||||
|
|
|
@ -460,11 +460,6 @@ ASM_PFX(AsmGetAddressMap):
|
||||||
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncAddress], rax
|
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncAddress], rax
|
||||||
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncSize], AsmRelocateApLoopEnd - AsmRelocateApLoopStart
|
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncSize], AsmRelocateApLoopEnd - AsmRelocateApLoopStart
|
||||||
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.ModeTransitionOffset], Flat32Start - RendezvousFunnelProcStart
|
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.ModeTransitionOffset], Flat32Start - RendezvousFunnelProcStart
|
||||||
|
|
||||||
lea rax, [AsmRelocateApLoopStartAmd]
|
|
||||||
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncAddressAmd], rax
|
|
||||||
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncSizeAmd], AsmRelocateApLoopEndAmd - AsmRelocateApLoopStartAmd
|
|
||||||
|
|
||||||
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealNoNxOffset], SwitchToRealProcStart - Flat32Start
|
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealNoNxOffset], SwitchToRealProcStart - Flat32Start
|
||||||
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealPM16ModeOffset], PM16Mode - RendezvousFunnelProcStart
|
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealPM16ModeOffset], PM16Mode - RendezvousFunnelProcStart
|
||||||
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealPM16ModeSize], SwitchToRealProcEnd - PM16Mode
|
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealPM16ModeSize], SwitchToRealProcEnd - PM16Mode
|
||||||
|
|
Loading…
Reference in New Issue