#include <Library/UefiBootServicesTableLib.h>\r
#include <Library/DebugAgentLib.h>\r
#include <Library/DxeServicesTableLib.h>\r
+#include <Library/VmgExitLib.h>\r
#include <Register/Amd/Fam17Msr.h>\r
#include <Register/Amd/Ghcb.h>\r
\r
{\r
EFI_STATUS Status;\r
EFI_PHYSICAL_ADDRESS StartAddress;\r
+ EFI_MEMORY_TYPE MemoryType;\r
+\r
+ if (PcdGetBool (PcdSevEsIsEnabled)) {\r
+ MemoryType = EfiReservedMemoryType;\r
+ } else {\r
+ MemoryType = EfiBootServicesData;\r
+ }\r
\r
//\r
// Try to allocate buffer below 1M for waking vector.\r
StartAddress = 0x88000;\r
Status = gBS->AllocatePages (\r
AllocateMaxAddress,\r
- EfiBootServicesData,\r
+ MemoryType,\r
EFI_SIZE_TO_PAGES (WakeupBufferSize),\r
&StartAddress\r
);\r
VOID\r
)\r
{\r
- EFI_STATUS Status;\r
- EFI_PHYSICAL_ADDRESS StartAddress;\r
+ EFI_STATUS Status;\r
+ EFI_PHYSICAL_ADDRESS StartAddress;\r
+ MSR_SEV_ES_GHCB_REGISTER Msr;\r
+ GHCB *Ghcb;\r
\r
//\r
// Allocate 1 page for AP jump table page\r
\r
DEBUG ((DEBUG_INFO, "Dxe: SevEsAPMemory = %lx\n", (UINTN) StartAddress));\r
\r
+ //\r
+ // Save the SevEsAPMemory as the AP jump table.\r
+ //\r
+ Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);\r
+ Ghcb = Msr.Ghcb;\r
+\r
+ VmgInit (Ghcb);\r
+ VmgExit (Ghcb, SVM_EXIT_AP_JUMP_TABLE, 0, (UINT64) (UINTN) StartAddress);\r
+ VmgDone (Ghcb);\r
+\r
return (UINTN) StartAddress;\r
}\r
\r
BOOLEAN MwaitSupport;\r
ASM_RELOCATE_AP_LOOP AsmRelocateApLoopFunc;\r
UINTN ProcessorNumber;\r
+ UINTN StackStart;\r
\r
MpInitLibWhoAmI (&ProcessorNumber);\r
CpuMpData = GetCpuMpData ();\r
MwaitSupport = IsMwaitSupport ();\r
+ if (CpuMpData->SevEsIsEnabled) {\r
+ StackStart = CpuMpData->SevEsAPResetStackStart;\r
+ } else {\r
+ StackStart = mReservedTopOfApStack;\r
+ }\r
AsmRelocateApLoopFunc = (ASM_RELOCATE_AP_LOOP) (UINTN) mReservedApLoopFunc;\r
AsmRelocateApLoopFunc (\r
MwaitSupport,\r
CpuMpData->ApTargetCState,\r
CpuMpData->PmCodeSegment,\r
- mReservedTopOfApStack - ProcessorNumber * AP_SAFE_STACK_SIZE,\r
- (UINTN) &mNumberToFinish\r
+ StackStart - ProcessorNumber * AP_SAFE_STACK_SIZE,\r
+ (UINTN) &mNumberToFinish,\r
+ CpuMpData->Pm16CodeSegment,\r
+ CpuMpData->SevEsAPBuffer,\r
+ CpuMpData->WakeupBuffer\r
);\r
//\r
// It should never reach here\r
while (mNumberToFinish > 0) {\r
CpuPause ();\r
}\r
+\r
+ if (CpuMpData->SevEsIsEnabled && (CpuMpData->WakeupBuffer != (UINTN) -1)) {\r
+ //\r
+ // There are APs present. Re-use reserved memory area below 1MB from\r
+ // WakeupBuffer as the area to be used for transitioning to 16-bit mode\r
+ // in support of booting of the AP by an OS.\r
+ //\r
+ CopyMem (\r
+ (VOID *) CpuMpData->WakeupBuffer,\r
+ (VOID *) (CpuMpData->AddressMap.RendezvousFunnelAddress +\r
+ CpuMpData->AddressMap.SwitchToRealPM16ModeOffset),\r
+ CpuMpData->AddressMap.SwitchToRealPM16ModeSize\r
+ );\r
+ }\r
+\r
DEBUG ((DEBUG_INFO, "%a() done!\n", __FUNCTION__));\r
}\r
\r