UefiCpuPkg/MpInitLib: move SEV specific routines in AmdSev.c
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3275 Move all the SEV specific function in AmdSev.c. No functional change intended. Cc: Eric Dong <eric.dong@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Rahul Kumar <rahul1.kumar@intel.com> Cc: Michael Roth <michael.roth@amd.com> Cc: James Bottomley <jejb@linux.ibm.com> Cc: Min Xu <min.m.xu@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Tom Lendacky <thomas.lendacky@amd.com> Cc: Jordan Justen <jordan.l.justen@intel.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Erdem Aktas <erdemaktas@google.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Suggested-by: Jiewen Yao <Jiewen.yao@intel.com> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
This commit is contained in:
committed by
mergify[bot]
parent
2ddacfb6b8
commit
e2289d19d8
@@ -15,6 +15,15 @@
|
||||
%include "MpEqu.inc"
|
||||
extern ASM_PFX(InitializeFloatingPointUnits)
|
||||
|
||||
%macro OneTimeCall 1
|
||||
jmp %1
|
||||
%1 %+ OneTimerCallReturn:
|
||||
%endmacro
|
||||
|
||||
%macro OneTimeCallRet 1
|
||||
jmp %1 %+ OneTimerCallReturn
|
||||
%endmacro
|
||||
|
||||
DEFAULT REL
|
||||
|
||||
SECTION .text
|
||||
@@ -144,6 +153,12 @@ SkipEnable5LevelPaging:
|
||||
jmp far [edi]
|
||||
|
||||
BITS 64
|
||||
|
||||
;
|
||||
; Required for the AMD SEV helper functions
|
||||
;
|
||||
%include "AmdSev.nasm"
|
||||
|
||||
LongModeStart:
|
||||
mov esi, ebx
|
||||
lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (InitFlag)]
|
||||
@@ -175,94 +190,17 @@ LongModeStart:
|
||||
add rax, qword [edi]
|
||||
mov rsp, rax
|
||||
|
||||
lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (SevEsIsEnabled)]
|
||||
cmp byte [edi], 1 ; SevEsIsEnabled
|
||||
jne CProcedureInvoke
|
||||
|
||||
;
|
||||
; program GHCB
|
||||
; Each page after the GHCB is a per-CPU page, so the calculation programs
|
||||
; a GHCB to be every 8KB.
|
||||
; Setup the GHCB when AMD SEV-ES active.
|
||||
;
|
||||
mov eax, SIZE_4KB
|
||||
shl eax, 1 ; EAX = SIZE_4K * 2
|
||||
mov ecx, ebx
|
||||
mul ecx ; EAX = SIZE_4K * 2 * CpuNumber
|
||||
mov edi, esi
|
||||
add edi, MP_CPU_EXCHANGE_INFO_FIELD (GhcbBase)
|
||||
add rax, qword [edi]
|
||||
mov rdx, rax
|
||||
shr rdx, 32
|
||||
mov rcx, 0xc0010130
|
||||
wrmsr
|
||||
OneTimeCall SevEsSetupGhcb
|
||||
jmp CProcedureInvoke
|
||||
|
||||
GetApicId:
|
||||
lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (SevEsIsEnabled)]
|
||||
cmp byte [edi], 1 ; SevEsIsEnabled
|
||||
jne DoCpuid
|
||||
|
||||
;
|
||||
; Since we don't have a stack yet, we can't take a #VC
|
||||
; exception. Use the GHCB protocol to perform the CPUID
|
||||
; calls.
|
||||
; Use the GHCB protocol to get the ApicId when SEV-ES is active.
|
||||
;
|
||||
mov rcx, 0xc0010130
|
||||
rdmsr
|
||||
shl rdx, 32
|
||||
or rax, rdx
|
||||
mov rdi, rax ; RDI now holds the original GHCB GPA
|
||||
|
||||
mov rdx, 0 ; CPUID function 0
|
||||
mov rax, 0 ; RAX register requested
|
||||
or rax, 4
|
||||
wrmsr
|
||||
rep vmmcall
|
||||
rdmsr
|
||||
cmp edx, 0bh
|
||||
jb NoX2ApicSevEs ; CPUID level below CPUID_EXTENDED_TOPOLOGY
|
||||
|
||||
mov rdx, 0bh ; CPUID function 0x0b
|
||||
mov rax, 040000000h ; RBX register requested
|
||||
or rax, 4
|
||||
wrmsr
|
||||
rep vmmcall
|
||||
rdmsr
|
||||
test edx, 0ffffh
|
||||
jz NoX2ApicSevEs ; CPUID.0BH:EBX[15:0] is zero
|
||||
|
||||
mov rdx, 0bh ; CPUID function 0x0b
|
||||
mov rax, 0c0000000h ; RDX register requested
|
||||
or rax, 4
|
||||
wrmsr
|
||||
rep vmmcall
|
||||
rdmsr
|
||||
|
||||
; Processor is x2APIC capable; 32-bit x2APIC ID is now in EDX
|
||||
jmp RestoreGhcb
|
||||
|
||||
NoX2ApicSevEs:
|
||||
; Processor is not x2APIC capable, so get 8-bit APIC ID
|
||||
mov rdx, 1 ; CPUID function 1
|
||||
mov rax, 040000000h ; RBX register requested
|
||||
or rax, 4
|
||||
wrmsr
|
||||
rep vmmcall
|
||||
rdmsr
|
||||
shr edx, 24
|
||||
|
||||
RestoreGhcb:
|
||||
mov rbx, rdx ; Save x2APIC/APIC ID
|
||||
|
||||
mov rdx, rdi ; RDI holds the saved GHCB GPA
|
||||
shr rdx, 32
|
||||
mov eax, edi
|
||||
wrmsr
|
||||
|
||||
mov rdx, rbx
|
||||
|
||||
; x2APIC ID or APIC ID is in EDX
|
||||
jmp GetProcessorNumber
|
||||
OneTimeCall SevEsGetApicId
|
||||
|
||||
DoCpuid:
|
||||
mov eax, 0
|
||||
|
Reference in New Issue
Block a user