22#define AP_SAFE_STACK_SIZE 128
28volatile BOOLEAN mStopCheckAllApsStatus =
TRUE;
60 ASSERT (mCpuMpData !=
NULL);
74 mCpuMpData = CpuMpData;
119 StartAddress = mSevEsDxeWakeupBuffer;
121 StartAddress = 0x88000;
124 Status =
gBS->AllocatePages (
131 if (EFI_ERROR (Status)) {
137 mSevEsDxeWakeupBuffer = StartAddress;
142 "WakeupBufferStart = %x, WakeupBufferSize = %x\n",
147 return (
UINTN)StartAddress;
170 StartAddress = BASE_4GB - 1;
171 Status =
gBS->AllocatePages (
177 if (EFI_ERROR (Status)) {
181 return (
UINTN)StartAddress;
201 BOOLEAN InterruptState;
206 StartAddress = BASE_4GB - 1;
207 Status =
gBS->AllocatePages (
215 DEBUG ((DEBUG_INFO,
"Dxe: SevEsAPMemory = %lx\n", (
UINTN)StartAddress));
227 return (
UINTN)StartAddress;
239 UINTN ProcessorNumber;
248 if (CpuMpData->WaitEvent !=
NULL) {
253 if (Status != EFI_NOT_READY) {
254 Status =
gBS->SignalEvent (CpuMpData->WaitEvent);
255 CpuMpData->WaitEvent =
NULL;
262 for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {
263 if (CpuMpData->CpuData[ProcessorNumber].WaitEvent ==
NULL) {
269 if (Status != EFI_NOT_READY) {
270 gBS->SignalEvent (CpuMpData->CpuData[ProcessorNumber].WaitEvent);
271 CpuMpData->CpuData[ProcessorNumber].WaitEvent =
NULL;
297 if (!mStopCheckAllApsStatus) {
313 IA32_DESCRIPTOR GdtrDesc;
314 IA32_SEGMENT_DESCRIPTOR *GdtEntry;
317 UINT16 CodeSegmentValue;
322 GdtEntryCount = (GdtrDesc.Limit + 1) /
sizeof (IA32_SEGMENT_DESCRIPTOR);
323 GdtEntry = (IA32_SEGMENT_DESCRIPTOR *)GdtrDesc.Base;
324 for (Index = 0; Index < GdtEntryCount; Index++) {
325 if (GdtEntry->Bits.L == 0) {
326 if ((GdtEntry->Bits.Type > 8) && (GdtEntry->Bits.DB == 0)) {
335 if (EFI_ERROR (Status)) {
341 if (EFI_ERROR (Status)) {
346 return CodeSegmentValue;
359 IA32_DESCRIPTOR GdtrDesc;
360 IA32_SEGMENT_DESCRIPTOR *GdtEntry;
363 UINT16 CodeSegmentValue;
367 GdtEntryCount = (GdtrDesc.Limit + 1) /
sizeof (IA32_SEGMENT_DESCRIPTOR);
368 GdtEntry = (IA32_SEGMENT_DESCRIPTOR *)GdtrDesc.Base;
369 for (Index = 0; Index < GdtEntryCount; Index++) {
370 if (GdtEntry->Bits.L == 0) {
371 if ((GdtEntry->Bits.Type > 8) && (GdtEntry->Bits.DB == 1)) {
380 if (EFI_ERROR (Status)) {
386 if (EFI_ERROR (Status)) {
391 return CodeSegmentValue;
408 Status =
gBS->AllocatePages (
439 Status =
gDS->GetMemorySpaceDescriptor (BaseAddress, &MemDesc);
440 if (!EFI_ERROR (Status)) {
441 gDS->SetMemorySpaceAttributes (
469 CpuMpData->ApLoopMode =
PcdGet8 (PcdCpuApLoopMode);
470 mNumberToFinish = CpuMpData->CpuCount - 1;
472 while (mNumberToFinish > 0) {
476 if (CpuMpData->UseSevEsAPMethod && (CpuMpData->WakeupBuffer != (
UINTN)-1)) {
483 (VOID *)CpuMpData->WakeupBuffer,
484 (VOID *)(CpuMpData->AddressMap.RendezvousFunnelAddress +
485 CpuMpData->AddressMap.SwitchToRealPM16ModeOffset),
486 CpuMpData->AddressMap.SwitchToRealPM16ModeSize
490 DEBUG ((DEBUG_INFO,
"%a() done!\n", __func__));
511 if (CpuMpData->CpuCount == 1) {
522 if (CpuMpData->CpuApStackSize <= EFI_PAGE_SIZE) {
523 DEBUG ((DEBUG_ERROR,
"PcdCpuApStackSize is not big enough for Stack Guard!\n"));
536 for (Index = 0; Index < CpuMpData->CpuCount; ++Index) {
537 if ((CpuInfoInHob !=
NULL) && (CpuInfoInHob[Index].ApTopOfStack != 0)) {
538 StackBase = (
UINTN)CpuInfoInHob[Index].ApTopOfStack - CpuMpData->CpuApStackSize;
540 StackBase = CpuMpData->Buffer + Index * CpuMpData->CpuApStackSize;
543 Status =
gDS->GetMemorySpaceDescriptor (StackBase, &MemDesc);
546 Status =
gDS->SetMemorySpaceAttributes (
555 "Stack Guard set at %lx [cpu%lu]!\n",
564 Status =
gBS->CreateEvent (
565 EVT_TIMER | EVT_NOTIFY_SIGNAL,
576 Status =
gBS->SetTimer (
580 PcdGet32 (PcdCpuApStatusCheckIntervalInMicroSeconds)
585 Status =
gBS->CreateEvent (
586 EVT_SIGNAL_EXIT_BOOT_SERVICES,
590 &mMpInitExitBootServicesEvent
594 Status =
gBS->CreateEventEx (
599 &gEfiEventLegacyBootGuid,
684 IN BOOLEAN SingleThread,
686 IN UINTN TimeoutInMicroseconds,
687 IN VOID *ProcedureArgument OPTIONAL,
696 mStopCheckAllApsStatus =
TRUE;
703 TimeoutInMicroseconds,
711 mStopCheckAllApsStatus =
FALSE;
793 IN UINTN TimeoutInMicroseconds,
794 IN VOID *ProcedureArgument OPTIONAL,
795 OUT BOOLEAN *Finished OPTIONAL
803 mStopCheckAllApsStatus =
TRUE;
809 TimeoutInMicroseconds,
814 mStopCheckAllApsStatus =
FALSE;
849 IN BOOLEAN EnableOldBSP
860 Status =
gBS->LocateProtocol (&gEfiTimerArchProtocolGuid,
NULL, (VOID **)&Timer);
861 if (EFI_ERROR (Status)) {
869 Timer->GetTimerPeriod (Timer, &TimerPeriod);
873 Timer->SetTimerPeriod (Timer, 0);
882 Timer->SetTimerPeriod (Timer, TimerPeriod);
923 IN UINT32 *HealthFlag OPTIONAL
927 BOOLEAN TempStopCheckState;
929 TempStopCheckState =
FALSE;
933 if (!mStopCheckAllApsStatus) {
934 mStopCheckAllApsStatus =
TRUE;
935 TempStopCheckState =
TRUE;
940 if (TempStopCheckState) {
941 mStopCheckAllApsStatus =
FALSE;
968 return EFI_UNSUPPORTED;
VOID EFIAPI CpuPause(VOID)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
UINT64 EFIAPI CcExitVmgExit(IN OUT GHCB *Ghcb, IN UINT64 ExitCode, IN UINT64 ExitInfo1, IN UINT64 ExitInfo2)
VOID EFIAPI CcExitVmgInit(IN OUT GHCB *Ghcb, IN OUT BOOLEAN *InterruptState)
VOID EFIAPI CcExitVmgDone(IN OUT GHCB *Ghcb, IN BOOLEAN InterruptState)
VOID EFIAPI InitializeDebugAgent(IN UINT32 InitFlag, IN VOID *Context OPTIONAL, IN DEBUG_AGENT_CONTINUE Function OPTIONAL)
STATIC BOOLEAN EFIAPI ConfidentialComputingGuestHas(IN CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr)
EFI_STATUS EFIAPI MpInitLibEnableDisableAP(IN UINTN ProcessorNumber, IN BOOLEAN EnableAP, IN UINT32 *HealthFlag OPTIONAL)
UINT16 GetProtectedModeCS(VOID)
EFI_STATUS EFIAPI MpInitLibStartupAllAPs(IN EFI_AP_PROCEDURE Procedure, IN BOOLEAN SingleThread, IN EFI_EVENT WaitEvent OPTIONAL, IN UINTN TimeoutInMicroseconds, IN VOID *ProcedureArgument OPTIONAL, OUT UINTN **FailedCpuList OPTIONAL)
VOID EFIAPI MpInitChangeApLoopCallback(IN EFI_EVENT Event, IN VOID *Context)
VOID CheckAndUpdateApsStatus(VOID)
VOID RemoveNxprotection(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINTN Length)
UINTN GetWakeupBuffer(IN UINTN WakeupBufferSize)
UINT16 GetProtectedMode16CS(VOID)
EFI_STATUS EFIAPI MpInitLibSwitchBSP(IN UINTN ProcessorNumber, IN BOOLEAN EnableOldBSP)
VOID EFIAPI CheckApsStatus(IN EFI_EVENT Event, IN VOID *Context)
VOID AllocateApLoopCodeBuffer(IN UINTN Pages, IN OUT EFI_PHYSICAL_ADDRESS *Address)
UINTN AllocateCodeBuffer(IN UINTN BufferSize)
CPU_MP_DATA * GetCpuMpData(VOID)
EFI_STATUS PlatformShadowMicrocode(IN OUT CPU_MP_DATA *CpuMpData)
UINTN GetSevEsAPMemory(VOID)
VOID InitMpGlobalData(IN CPU_MP_DATA *CpuMpData)
VOID EnableDebugAgent(VOID)
EFI_STATUS EFIAPI MpInitLibStartupThisAP(IN EFI_AP_PROCEDURE Procedure, IN UINTN ProcessorNumber, IN EFI_EVENT WaitEvent OPTIONAL, IN UINTN TimeoutInMicroseconds, IN VOID *ProcedureArgument OPTIONAL, OUT BOOLEAN *Finished OPTIONAL)
VOID SaveCpuMpData(IN CPU_MP_DATA *CpuMpData)
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
EFI_STATUS StartupThisAPWorker(IN EFI_AP_PROCEDURE Procedure, IN UINTN ProcessorNumber, IN EFI_EVENT WaitEvent OPTIONAL, IN UINTN TimeoutInMicroseconds, IN VOID *ProcedureArgument OPTIONAL, OUT BOOLEAN *Finished OPTIONAL)
VOID WakeUpAP(IN CPU_MP_DATA *CpuMpData, IN BOOLEAN Broadcast, IN UINTN ProcessorNumber, IN EFI_AP_PROCEDURE Procedure OPTIONAL, IN VOID *ProcedureArgument OPTIONAL, IN BOOLEAN WakeUpDisabledAps)
EFI_STATUS StartupAllCPUsWorker(IN EFI_AP_PROCEDURE Procedure, IN BOOLEAN SingleThread, IN BOOLEAN ExcludeBsp, IN EFI_EVENT WaitEvent OPTIONAL, IN UINTN TimeoutInMicroseconds, IN VOID *ProcedureArgument OPTIONAL, OUT UINTN **FailedCpuList OPTIONAL)
EFI_STATUS CheckThisAP(IN UINTN ProcessorNumber)
EFI_STATUS CheckAllAPs(VOID)
EFI_STATUS EnableDisableApWorker(IN UINTN ProcessorNumber, IN BOOLEAN EnableAP, IN UINT32 *HealthFlag OPTIONAL)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
VOID EFIAPI RelocateApLoop(IN OUT VOID *Buffer)
VOID PrepareApLoopCode(IN CPU_MP_DATA *CpuMpData)
EFI_STATUS SwitchBSPWorker(IN UINTN ProcessorNumber, IN BOOLEAN EnableOldBSP)
#define PcdGet8(TokenName)
#define PcdGet32(TokenName)
#define PcdGetBool(TokenName)
VOID(EFIAPI * EFI_AP_PROCEDURE)(IN OUT VOID *Buffer)
RETURN_STATUS EFIAPI SafeUint16Mult(IN UINT16 Multiplicand, IN UINT16 Multiplier, OUT UINT16 *Result)
RETURN_STATUS EFIAPI SafeUintnToUint16(IN UINTN Operand, OUT UINT16 *Result)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)
#define EFI_SIZE_TO_PAGES(Size)
#define EFI_TIMER_PERIOD_MICROSECONDS(Microseconds)
VOID EFIAPI AsmReadGdtr(OUT IA32_DESCRIPTOR *Gdtr)