.ModeHighSegment: CTYPE_UINT16 1\r
.Enable5LevelPaging: CTYPE_BOOLEAN 1\r
.SevEsIsEnabled: CTYPE_BOOLEAN 1\r
+ .SevSnpIsEnabled CTYPE_BOOLEAN 1\r
.GhcbBase: CTYPE_UINTN 1\r
endstruc\r
\r
ExchangeInfo->Enable5LevelPaging = (BOOLEAN)(Cr4.Bits.LA57 == 1);\r
DEBUG ((DEBUG_INFO, "%a: 5-Level Paging = %d\n", gEfiCallerBaseName, ExchangeInfo->Enable5LevelPaging));\r
\r
- ExchangeInfo->SevEsIsEnabled = CpuMpData->SevEsIsEnabled;\r
- ExchangeInfo->GhcbBase = (UINTN)CpuMpData->GhcbBase;\r
+ ExchangeInfo->SevEsIsEnabled = CpuMpData->SevEsIsEnabled;\r
+ ExchangeInfo->SevSnpIsEnabled = CpuMpData->SevSnpIsEnabled;\r
+ ExchangeInfo->GhcbBase = (UINTN)CpuMpData->GhcbBase;\r
\r
//\r
// Get the BSP's data of GDT and IDT\r
CpuMpData->CpuData = (CPU_AP_DATA *)(CpuMpData + 1);\r
CpuMpData->CpuInfoInHob = (UINT64)(UINTN)(CpuMpData->CpuData + MaxLogicalProcessorNumber);\r
InitializeSpinLock (&CpuMpData->MpLock);\r
- CpuMpData->SevEsIsEnabled = ConfidentialComputingGuestHas (CCAttrAmdSevEs);\r
- CpuMpData->SevEsAPBuffer = (UINTN)-1;\r
- CpuMpData->GhcbBase = PcdGet64 (PcdGhcbBase);\r
+ CpuMpData->SevEsIsEnabled = ConfidentialComputingGuestHas (CCAttrAmdSevEs);\r
+ CpuMpData->SevSnpIsEnabled = ConfidentialComputingGuestHas (CCAttrAmdSevSnp);\r
+ CpuMpData->SevEsAPBuffer = (UINTN)-1;\r
+ CpuMpData->GhcbBase = PcdGet64 (PcdGhcbBase);\r
\r
//\r
// Make sure no memory usage outside of the allocated buffer.\r
//\r
BOOLEAN Enable5LevelPaging;\r
BOOLEAN SevEsIsEnabled;\r
+ BOOLEAN SevSnpIsEnabled;\r
UINTN GhcbBase;\r
} MP_CPU_EXCHANGE_INFO;\r
\r
BOOLEAN WakeUpByInitSipiSipi;\r
\r
BOOLEAN SevEsIsEnabled;\r
+ BOOLEAN SevSnpIsEnabled;\r
UINTN SevEsAPBuffer;\r
UINTN SevEsAPResetStackStart;\r
CPU_MP_DATA *NewCpuMpData;\r
\r
%define SIZE_4KB 0x1000\r
\r
+RegisterGhcbGpa:\r
+ ;\r
+ ; Register GHCB GPA when SEV-SNP is enabled\r
+ ;\r
+ lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (SevSnpIsEnabled)]\r
+ cmp byte [edi], 1 ; SevSnpIsEnabled\r
+ jne RegisterGhcbGpaDone\r
+\r
+ ; Save the rdi and rsi to used for later comparison\r
+ push rdi\r
+ push rsi\r
+ mov edi, eax\r
+ mov esi, edx\r
+ or eax, 18 ; Ghcb registration request\r
+ wrmsr\r
+ rep vmmcall\r
+ rdmsr\r
+ mov r12, rax\r
+ and r12, 0fffh\r
+ cmp r12, 19 ; Ghcb registration response\r
+ jne GhcbGpaRegisterFailure\r
+\r
+ ; Verify that GPA is not changed\r
+ and eax, 0fffff000h\r
+ cmp edi, eax\r
+ jne GhcbGpaRegisterFailure\r
+ cmp esi, edx\r
+ jne GhcbGpaRegisterFailure\r
+ pop rsi\r
+ pop rdi\r
+ jmp RegisterGhcbGpaDone\r
+\r
+ ;\r
+ ; Request the guest termination\r
+ ;\r
+GhcbGpaRegisterFailure:\r
+ xor edx, edx\r
+ mov eax, 256 ; GHCB terminate\r
+ wrmsr\r
+ rep vmmcall\r
+\r
+ ; We should not return from the above terminate request, but if we do\r
+ ; then enter into the hlt loop.\r
+DoHltLoop:\r
+ cli\r
+ hlt\r
+ jmp DoHltLoop\r
+\r
+RegisterGhcbGpaDone:\r
+ OneTimeCallRet RegisterGhcbGpa\r
+\r
;\r
; The function checks whether SEV-ES is enabled, if enabled\r
; then setup the GHCB page.\r
mov rdx, rax\r
shr rdx, 32\r
mov rcx, 0xc0010130\r
+\r
+ OneTimeCall RegisterGhcbGpa\r
+\r
wrmsr\r
\r
SevEsSetupGhcbExit:\r