16EFI_GUID mCpuInitMpLibHobGuid = CPU_INIT_MP_LIB_HOB_GUID;
17EFI_GUID mMpHandOffGuid = MP_HANDOFF_GUID;
18EFI_GUID mMpHandOffConfigGuid = MP_HANDOFF_CONFIG_GUID;
21UINTN mReservedTopOfApStack;
22volatile UINT32 mNumberToFinish = 0;
71 if (Cr0.Bits.PG != 0) {
82 if (Edx.Bits.NX != 0) {
135 return CpuData->State;
151 CpuData->State = State;
166 if (CpuMpData->InitTimerCount != 0) {
171 &CpuMpData->DivideValue,
172 &CpuMpData->PeriodicMode,
190 if (CpuMpData->InitTimerCount != 0) {
195 CpuMpData->DivideValue,
196 CpuMpData->InitTimerCount,
197 CpuMpData->PeriodicMode,
224 if (VersionInfoEdx.
Bits.
DE != 0) {
254 IA32_TSS_DESCRIPTOR *Tss;
261 if (VersionInfoEdx.
Bits.
DE != 0) {
276 if ((VolatileRegisters->Tr != 0) &&
277 (VolatileRegisters->Tr < VolatileRegisters->Gdtr.Limit))
279 Tss = (IA32_TSS_DESCRIPTOR *)(VolatileRegisters->Gdtr.Base +
280 VolatileRegisters->Tr);
281 if (Tss->Bits.P == 1) {
282 Tss->Bits.Type &= 0xD;
314 OUT UINT32 *MonitorFilterSize
320 ASSERT (MonitorFilterSize !=
NULL);
322 ApLoopMode =
PcdGet8 (PcdCpuApLoopMode);
323 ASSERT (ApLoopMode >= ApInHltLoop && ApLoopMode <= ApInRunLoop);
324 if (ApLoopMode == ApInMwaitLoop) {
330 ApLoopMode = ApInHltLoop;
340 ApLoopMode = ApInHltLoop;
344 if (ApLoopMode != ApInMwaitLoop) {
345 *MonitorFilterSize =
sizeof (UINT32);
380 ApCount = CpuMpData->CpuCount - 1;
383 for (Index1 = 0; Index1 < ApCount; Index1++) {
388 ApicId = CpuInfoInHob[Index1].ApicId;
389 for (Index2 = Index1 + 1; Index2 <= ApCount; Index2++) {
390 if (ApicId > CpuInfoInHob[Index2].ApicId) {
392 ApicId = CpuInfoInHob[Index2].ApicId;
396 if (Index3 != Index1) {
399 &CpuInfoInHob[Index3],
400 &CpuInfoInHob[Index1],
407 &CpuMpData->CpuData[Index3],
408 &CpuMpData->CpuData[Index1],
419 for (Index1 = 0; Index1 < CpuMpData->CpuCount; Index1++) {
420 if (CpuInfoInHob[Index1].ApicId == ApicId) {
421 CpuMpData->BspNumber = (UINT32)Index1;
454 UINTN ProcessorNumber;
485 UINTN TotalProcessorNumber;
488 UINT32 CurrentApicId;
492 TotalProcessorNumber = CpuMpData->CpuCount;
494 for (Index = 0; Index < TotalProcessorNumber; Index++) {
495 if (CpuInfoInHob[Index].ApicId == CurrentApicId) {
496 *ProcessorNumber = Index;
501 return EFI_NOT_FOUND;
526 if (CpuMpData->CpuCount > 255) {
533 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
534 if (CpuInfoInHob[Index].InitialApicId >= 0xFF) {
542 DEBUG ((DEBUG_INFO,
"Force x2APIC mode!\n"));
550 while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) {
561 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
562 SetApState (&CpuMpData->CpuData[Index], CpuStateIdle);
584 CpuMpData->InitFlag = ApInitConfig;
586 CpuMpData->InitFlag = ApInitDone;
591 CpuMpData->CpuCount = CpuMpData->FinishedCount + 1;
592 ASSERT (CpuMpData->CpuCount <=
PcdGet32 (PcdCpuMaxLogicalProcessorNumber));
594 return CpuMpData->CpuCount;
611 IN UINT64 ApTopOfStack
620 CpuInfoInHob[ProcessorNumber].ApicId =
GetApicId ();
621 CpuInfoInHob[ProcessorNumber].Health = BistData;
622 CpuInfoInHob[ProcessorNumber].ApTopOfStack = ApTopOfStack;
628 ApStackData->MpData = CpuMpData;
630 CpuMpData->CpuData[ProcessorNumber].Waiting =
FALSE;
631 CpuMpData->CpuData[ProcessorNumber].CpuHealthy = (BistData == 0) ?
TRUE :
FALSE;
638 CpuMpData->CpuData[ProcessorNumber].PlatformId = (UINT8)PlatformIdMsr.
Bits.
PlatformId;
643 &CpuMpData->CpuData[ProcessorNumber].ProcessorSignature,
650 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle);
665 if (CpuMpData->UseSevEsAPMethod) {
685 IN volatile UINT32 *ApStartupSignalBuffer,
686 IN UINT8 ApTargetCState
691 if (ApLoopMode == ApInMwaitLoop) {
696 if ((*ApStartupSignalBuffer != WAKEUP_AP_SIGNAL) && (*ApStartupSignalBuffer != MP_HAND_OFF_SIGNAL)) {
704 }
else if (ApLoopMode == ApInRunLoop) {
717 if ((*ApStartupSignalBuffer == WAKEUP_AP_SIGNAL) || (*ApStartupSignalBuffer == MP_HAND_OFF_SIGNAL)) {
736 UINTN ProcessorNumber;
740 volatile UINT32 *ApStartupSignalBuffer;
743 UINTN CurrentApicMode;
745 UINT32 OriginalValue;
760 if (CpuMpData->InitFlag == ApInitConfig) {
765 CurrentApicMode = CpuMpData->InitialBspApicMode;
767 ProcessorNumber = ApIndex;
771 ApTopOfStack = CpuMpData->Buffer + (ProcessorNumber + 1) * CpuMpData->CpuApStackSize;
773 BistData = (UINT32)ApStackData->Bist;
782 ApStartupSignalBuffer = CpuMpData->CpuData[ProcessorNumber].StartupApSignal;
791 ApStartupSignalBuffer = CpuMpData->CpuData[ProcessorNumber].StartupApSignal;
793 (UINT32 *)ApStartupSignalBuffer,
797 if (OriginalValue == MP_HAND_OFF_SIGNAL) {
798 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateReady);
802 (UINT32 *)ApStartupSignalBuffer,
809 if (
GetApState (&CpuMpData->CpuData[ProcessorNumber]) == CpuStateReady) {
810 Procedure = (
EFI_AP_PROCEDURE)CpuMpData->CpuData[ProcessorNumber].ApFunction;
811 Parameter = (VOID *)CpuMpData->CpuData[ProcessorNumber].ApFunctionArgument;
812 if (Procedure !=
NULL) {
813 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateBusy);
821 Procedure (Parameter);
823 if (CpuMpData->SwitchBspFlag) {
828 CpuMpData->CpuData[ProcessorNumber].ApFunction = 0;
829 CpuMpData->CpuData[ProcessorNumber].ApFunctionArgument = 0;
830 ApStartupSignalBuffer = CpuMpData->CpuData[ProcessorNumber].StartupApSignal;
831 CpuInfoInHob[ProcessorNumber].ApTopOfStack = CpuInfoInHob[CpuMpData->NewBspNumber].ApTopOfStack;
833 if ((CpuInfoInHob[ProcessorNumber].ApicId !=
GetApicId ()) ||
847 CpuInfoInHob[ProcessorNumber].ApicId =
GetApicId ();
854 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateFinished);
865 if (CpuMpData->InitFlag == ApInitConfig) {
871 if (!CpuMpData->UseSevEsAPMethod) {
879 if (CpuMpData->ApLoopMode == ApInHltLoop) {
903 UINTN ProcessorNumber;
907 if (CpuMpData->EnableExecuteDisableForSwitchContext) {
916 CpuMpData->ApLoopMode,
917 CpuMpData->CpuData[ProcessorNumber].StartupApSignal,
918 CpuMpData->ApTargetCState
930 IN volatile UINT32 *ApStartupSignalBuffer
938 (UINT32 *)ApStartupSignalBuffer,
962 if (SizeBelow1Mb !=
NULL) {
966 if (SizeAbove1Mb !=
NULL) {
967 *SizeAbove1Mb = AddressMap->RendezvousFunnelSize - AddressMap->ModeTransitionOffset;
984 IA32_SEGMENT_DESCRIPTOR *Selector;
987 ExchangeInfo = CpuMpData->MpCpuExchangeInfo;
988 ExchangeInfo->StackStart = CpuMpData->Buffer;
989 ExchangeInfo->StackSize = CpuMpData->CpuApStackSize;
990 ExchangeInfo->BufferStart = CpuMpData->WakeupBuffer;
991 ExchangeInfo->ModeOffset = CpuMpData->AddressMap.ModeEntryOffset;
993 ExchangeInfo->CodeSegment =
AsmReadCs ();
994 ExchangeInfo->DataSegment =
AsmReadDs ();
999 ExchangeInfo->ApIndex = 0;
1000 ExchangeInfo->NumApsExecuting = 0;
1001 ExchangeInfo->InitFlag = (
UINTN)CpuMpData->InitFlag;
1003 ExchangeInfo->CpuMpData = CpuMpData;
1018 ExchangeInfo->Enable5LevelPaging = (BOOLEAN)(Cr4.Bits.LA57 == 1);
1019 DEBUG ((DEBUG_INFO,
"%a: 5-Level Paging = %d\n", gEfiCallerBaseName, ExchangeInfo->Enable5LevelPaging));
1021 ExchangeInfo->SevEsIsEnabled = CpuMpData->SevEsIsEnabled;
1022 ExchangeInfo->SevSnpIsEnabled = CpuMpData->SevSnpIsEnabled;
1023 ExchangeInfo->GhcbBase = (
UINTN)CpuMpData->GhcbBase;
1028 if (ExchangeInfo->SevSnpIsEnabled) {
1035 AsmReadGdtr ((IA32_DESCRIPTOR *)&ExchangeInfo->GdtrProfile);
1036 AsmReadIdtr ((IA32_DESCRIPTOR *)&ExchangeInfo->IdtrProfile);
1041 Selector = (IA32_SEGMENT_DESCRIPTOR *)ExchangeInfo->GdtrProfile.Base;
1042 Size = ExchangeInfo->GdtrProfile.Limit + 1;
1044 if ((Selector->Bits.L == 0) && (Selector->Bits.Type >= 8)) {
1045 ExchangeInfo->ModeTransitionSegment =
1046 (UINT16)((
UINTN)Selector - ExchangeInfo->GdtrProfile.Base);
1051 Size -=
sizeof (IA32_SEGMENT_DESCRIPTOR);
1054 ExchangeInfo->ModeTransitionMemory = (UINT32)CpuMpData->WakeupBufferHigh;
1056 ExchangeInfo->ModeHighMemory = ExchangeInfo->ModeTransitionMemory +
1057 (UINT32)ExchangeInfo->ModeOffset -
1058 (UINT32)CpuMpData->AddressMap.ModeTransitionOffset;
1059 ExchangeInfo->ModeHighSegment = (UINT16)ExchangeInfo->CodeSegment;
1073 IN UINT32 FinishedApLimit,
1088 (VOID *)CpuMpData->BackupBuffer,
1089 (VOID *)CpuMpData->WakeupBuffer,
1090 CpuMpData->BackupBufferSize
1093 (VOID *)CpuMpData->WakeupBuffer,
1094 (VOID *)CpuMpData->AddressMap.RendezvousFunnelAddress,
1110 (VOID *)CpuMpData->WakeupBuffer,
1111 (VOID *)CpuMpData->BackupBuffer,
1112 CpuMpData->BackupBufferSize
1126 UINTN ApResetStackSize;
1128 if (CpuMpData->WakeupBuffer == (
UINTN)-1) {
1129 CpuMpData->WakeupBuffer =
GetWakeupBuffer (CpuMpData->BackupBufferSize);
1134 "AP Vector: 16-bit = %p/%x, ExchangeInfo = %p/%x\n",
1135 CpuMpData->WakeupBuffer,
1137 CpuMpData->MpCpuExchangeInfo,
1153 ApResetStackSize = (AP_RESET_STACK_SIZE *
1154 PcdGet32 (PcdCpuMaxLogicalProcessorNumber));
1161 CpuMpData->SevEsAPResetStackStart =
GetWakeupBuffer (ApResetStackSize);
1168 if (CpuMpData->SevEsAPResetStackStart >= CpuMpData->WakeupBuffer) {
1171 "SEV-ES AP reset stack is not below wakeup buffer\n"
1199 if (!CpuMpData->UseSevEsAPMethod) {
1218 IN BOOLEAN Broadcast,
1221 IN VOID *ProcedureArgument OPTIONAL,
1222 IN BOOLEAN WakeUpDisabledAps
1228 BOOLEAN ResetVectorRequired;
1231 CpuMpData->FinishedCount = 0;
1232 ResetVectorRequired =
FALSE;
1234 if (CpuMpData->WakeUpByInitSipiSipi ||
1235 (CpuMpData->InitFlag == ApInitConfig))
1237 ResetVectorRequired =
TRUE;
1243 if (CpuMpData->ApLoopMode == ApInMwaitLoop) {
1248 CpuMpData->ApTargetCState =
PcdGet8 (PcdCpuApTargetCstate);
1251 ExchangeInfo = CpuMpData->MpCpuExchangeInfo;
1254 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
1255 if (Index != CpuMpData->BspNumber) {
1256 CpuData = &CpuMpData->CpuData[Index];
1262 if ((
GetApState (CpuData) == CpuStateDisabled) && !WakeUpDisabledAps) {
1266 CpuData->ApFunction = (
UINTN)Procedure;
1267 CpuData->ApFunctionArgument = (
UINTN)ProcedureArgument;
1269 if (CpuMpData->InitFlag == ApInitDone) {
1270 *(UINT32 *)CpuData->StartupApSignal = WAKEUP_AP_SIGNAL;
1275 if (ResetVectorRequired) {
1281 if (CpuMpData->SevEsIsEnabled) {
1294 if ((CpuMpData->InitFlag == ApInitConfig) &&
FixedPcdGetBool (PcdFirstTimeWakeUpAPsBySipi)) {
1305 if (CpuMpData->InitFlag == ApInitConfig) {
1306 if (
PcdGet32 (PcdCpuBootLogicalProcessorNumber) > 0) {
1322 PcdGet32 (PcdCpuBootLogicalProcessorNumber) - 1,
1360 PcdGet32 (PcdCpuMaxLogicalProcessorNumber) - 1,
1361 PcdGet32 (PcdCpuApInitTimeOutInMicroSeconds)
1364 while (CpuMpData->MpCpuExchangeInfo->NumApsExecuting != 0) {
1372 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
1373 CpuData = &CpuMpData->CpuData[Index];
1374 if (Index != CpuMpData->BspNumber) {
1380 CpuData = &CpuMpData->CpuData[ProcessorNumber];
1381 CpuData->ApFunction = (
UINTN)Procedure;
1382 CpuData->ApFunctionArgument = (
UINTN)ProcedureArgument;
1387 ASSERT (CpuMpData->InitFlag == ApInitDone);
1388 *(UINT32 *)CpuData->StartupApSignal = WAKEUP_AP_SIGNAL;
1389 if (ResetVectorRequired) {
1397 if (CpuMpData->SevEsIsEnabled) {
1405 CpuInfoInHob[ProcessorNumber].ApicId,
1406 (UINT32)ExchangeInfo->BufferStart
1417 if (ResetVectorRequired) {
1426 CpuMpData->WakeUpByInitSipiSipi = (CpuMpData->ApLoopMode == ApInHltLoop);
1446 IN UINTN TimeoutInMicroseconds,
1447 OUT UINT64 *CurrentTime
1450 UINT64 TimeoutInSeconds;
1451 UINT64 TimestampCounterFreq;
1462 if (TimeoutInMicroseconds == 0) {
1479 TimeoutInSeconds =
DivU64x32 (TimeoutInMicroseconds, 1000000);
1484 return MultU64x64 (TimestampCounterFreq, TimeoutInSeconds);
1492 TimestampCounterFreq,
1493 TimeoutInMicroseconds
1510 UINTN ProcessorNumber;
1520 (VOID *)(
UINTN)CpuMpData,
1522 (VOID *)((
UINTN)CpuInfoInHob[ProcessorNumber].ApTopOfStack)
1548 IN OUT UINT64 *PreviousTime,
1549 IN UINT64 *TotalTime,
1564 Cycle = End - Start;
1571 Delta = (INT64)(CurrentTime - *PreviousTime);
1580 *TotalTime += Delta;
1581 *PreviousTime = CurrentTime;
1582 if (*TotalTime > Timeout) {
1600 IN UINT32 FinishedApLimit,
1608 if (TimeLimit == 0) {
1612 CpuMpData->TotalTime = 0;
1615 &CpuMpData->CurrentTime
1617 while (CpuMpData->FinishedCount < FinishedApLimit &&
1619 &CpuMpData->CurrentTime,
1620 &CpuMpData->TotalTime,
1621 CpuMpData->ExpectedTime
1627 if (CpuMpData->FinishedCount >= FinishedApLimit) {
1630 "%a: reached FinishedApLimit=%u in %Lu microseconds\n",
1659 CpuMpData->WakeUpByInitSipiSipi =
TRUE;
1660 if (CpuMpData ==
NULL) {
1661 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get CpuMpData. Aborting the AP reset to idle.\n", __func__));
1666 while (CpuMpData->FinishedCount < 1) {
1670 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle);
1689 UINTN ProcessorNumber;
1694 if (CpuMpData ==
NULL) {
1695 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get CpuMpData.\n", __func__));
1696 return EFI_LOAD_ERROR;
1699 for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {
1700 if (CpuMpData->CpuData[ProcessorNumber].Waiting) {
1701 *NextProcessorNumber = ProcessorNumber;
1706 return EFI_NOT_FOUND;
1730 if (CpuMpData ==
NULL) {
1731 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get CpuMpData.\n", __func__));
1732 return EFI_LOAD_ERROR;
1735 CpuData = &CpuMpData->CpuData[ProcessorNumber];
1745 if (
GetApState (CpuData) == CpuStateFinished) {
1746 if (CpuData->Finished !=
NULL) {
1747 *(CpuData->Finished) =
TRUE;
1756 if (
CheckTimeout (&CpuData->CurrentTime, &CpuData->TotalTime, CpuData->ExpectedTime)) {
1757 if (CpuData->Finished !=
NULL) {
1758 *(CpuData->Finished) =
FALSE;
1770 return EFI_NOT_READY;
1788 UINTN ProcessorNumber;
1789 UINTN NextProcessorNumber;
1797 if (CpuMpData ==
NULL) {
1798 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get CpuMpData.\n", __func__));
1799 return EFI_LOAD_ERROR;
1802 NextProcessorNumber = 0;
1807 for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {
1808 if (!CpuMpData->CpuData[ProcessorNumber].Waiting) {
1812 CpuData = &CpuMpData->CpuData[ProcessorNumber];
1818 if (
GetApState (CpuData) == CpuStateFinished) {
1819 CpuMpData->RunningCount--;
1820 CpuMpData->CpuData[ProcessorNumber].Waiting =
FALSE;
1826 if (CpuMpData->SingleThread) {
1829 if (!EFI_ERROR (Status)) {
1833 (UINT32)NextProcessorNumber,
1834 CpuMpData->Procedure,
1835 CpuMpData->ProcArguments,
1846 if (CpuMpData->RunningCount == 0) {
1854 &CpuMpData->CurrentTime,
1855 &CpuMpData->TotalTime,
1856 CpuMpData->ExpectedTime
1863 if (CpuMpData->FailedCpuList !=
NULL) {
1864 *CpuMpData->FailedCpuList =
1866 ASSERT (*CpuMpData->FailedCpuList !=
NULL);
1871 for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {
1875 if (CpuMpData->CpuData[ProcessorNumber].Waiting) {
1880 CpuMpData->CpuData[ProcessorNumber].Waiting =
FALSE;
1881 if (CpuMpData->FailedCpuList !=
NULL) {
1882 (*CpuMpData->FailedCpuList)[ListIndex++] = ProcessorNumber;
1887 if (CpuMpData->FailedCpuList !=
NULL) {
1894 return EFI_NOT_READY;
1917 for (MpHandOff = FirstMpHandOff;
1921 for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
1922 if (MpHandOff->Info[Index].ApicId == ApicId) {
1923 return MpHandOff->ProcessorIndex + Index;
1956 for (MpHandOff = FirstMpHandOff;
1960 for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
1961 if (MpHandOff->ProcessorIndex + Index != BspNumber) {
1963 *(UINT32 *)(
UINTN)MpHandOff->Info[Index].StartupSignalAddress = MpHandOffConfig->StartupSignalValue;
1971 for (MpHandOff = FirstMpHandOff;
1975 for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
1976 if (MpHandOff->ProcessorIndex + Index != BspNumber) {
1996 if (GuidHob ==
NULL) {
2017 if (MpHandOff ==
NULL) {
2021 GuidHob =
GetNextGuidHob (&mMpHandOffGuid, GET_NEXT_HOB (GuidHob));
2024 if (GuidHob ==
NULL) {
2028 return (
MP_HAND_OFF *)GET_GUID_HOB_DATA (GuidHob);
2054 UINT32 MaxLogicalProcessorNumber;
2059 UINT32 MonitorFilterSize;
2064 UINT8 *MonitorBuffer;
2065 UINT32 Index, HobIndex;
2066 UINTN ApResetVectorSizeBelow1Mb;
2067 UINTN ApResetVectorSizeAbove1Mb;
2068 UINTN BackupBufferAddr;
2072 if (FirstMpHandOff !=
NULL) {
2073 MaxLogicalProcessorNumber = 0;
2074 for (MpHandOff = FirstMpHandOff;
2080 "%a: ProcessorIndex=%u CpuCount=%u\n",
2082 MpHandOff->ProcessorIndex,
2085 ASSERT (MaxLogicalProcessorNumber == MpHandOff->ProcessorIndex);
2086 MaxLogicalProcessorNumber += MpHandOff->CpuCount;
2089 MaxLogicalProcessorNumber =
PcdGet32 (PcdCpuMaxLogicalProcessorNumber);
2092 ASSERT (MaxLogicalProcessorNumber != 0);
2096 ApStackSize =
PcdGet32 (PcdCpuApStackSize);
2100 ASSERT ((ApStackSize & (ApStackSize - 1)) == 0);
2108 BufferSize = ApStackSize * MaxLogicalProcessorNumber;
2112 BufferSize += ApStackSize;
2113 BufferSize += MonitorFilterSize * MaxLogicalProcessorNumber;
2114 BufferSize += ApResetVectorSizeBelow1Mb;
2116 BufferSize += VolatileRegisters.Idtr.Limit + 1;
2120 ASSERT (MpBuffer !=
NULL);
2121 if (MpBuffer ==
NULL) {
2122 return EFI_OUT_OF_RESOURCES;
2125 ZeroMem (MpBuffer, BufferSize);
2149 MonitorBuffer = (UINT8 *)(Buffer + ApStackSize * MaxLogicalProcessorNumber);
2150 BackupBufferAddr = (
UINTN)MonitorBuffer + MonitorFilterSize * MaxLogicalProcessorNumber;
2151 ApIdtBase =
ALIGN_VALUE (BackupBufferAddr + ApResetVectorSizeBelow1Mb, 8);
2152 CpuMpData = (
CPU_MP_DATA *)(ApIdtBase + VolatileRegisters.Idtr.Limit + 1);
2153 CpuMpData->Buffer = Buffer;
2154 CpuMpData->CpuApStackSize = ApStackSize;
2155 CpuMpData->BackupBuffer = BackupBufferAddr;
2156 CpuMpData->BackupBufferSize = ApResetVectorSizeBelow1Mb;
2157 CpuMpData->WakeupBuffer = (
UINTN)-1;
2158 CpuMpData->CpuCount = 1;
2159 if (FirstMpHandOff ==
NULL) {
2160 CpuMpData->BspNumber = 0;
2165 CpuMpData->WaitEvent =
NULL;
2166 CpuMpData->SwitchBspFlag =
FALSE;
2167 CpuMpData->CpuData = (
CPU_AP_DATA *)(CpuMpData + 1);
2168 CpuMpData->CpuInfoInHob = (UINT64)(
UINTN)(CpuMpData->CpuData + MaxLogicalProcessorNumber);
2172 CpuMpData->SevEsAPBuffer = (
UINTN)-1;
2173 CpuMpData->GhcbBase =
PcdGet64 (PcdGhcbBase);
2174 CpuMpData->UseSevEsAPMethod = CpuMpData->SevEsIsEnabled && !CpuMpData->SevSnpIsEnabled;
2176 if (CpuMpData->SevSnpIsEnabled) {
2177 ASSERT ((
PcdGet64 (PcdGhcbHypervisorFeatures) & GHCB_HV_FEATURES_SNP_AP_CREATE) == GHCB_HV_FEATURES_SNP_AP_CREATE);
2185 (CpuMpData->CpuInfoInHob + sizeof (
CPU_INFO_IN_HOB) * MaxLogicalProcessorNumber) ==
2186 (
UINTN)MpBuffer + BufferSize - (ApStackSize - Buffer + (
UINTN)MpBuffer)
2193 CopyMem ((VOID *)ApIdtBase, (VOID *)VolatileRegisters.Idtr.Base, VolatileRegisters.Idtr.Limit + 1);
2194 VolatileRegisters.Idtr.Base = ApIdtBase;
2198 VolatileRegisters.Tr = 0;
2202 VolatileRegisters.Dr0 = 0;
2203 VolatileRegisters.Dr1 = 0;
2204 VolatileRegisters.Dr2 = 0;
2205 VolatileRegisters.Dr3 = 0;
2206 VolatileRegisters.Dr6 = 0;
2207 VolatileRegisters.Dr7 = 0;
2214 for (Index = 0; Index < MaxLogicalProcessorNumber; Index++) {
2215 CopyMem (&CpuMpData->CpuData[Index].VolatileRegisters, &VolatileRegisters, sizeof (VolatileRegisters));
2221 InitializeApData (CpuMpData, CpuMpData->BspNumber, 0, CpuMpData->Buffer + ApStackSize * (CpuMpData->BspNumber + 1));
2229 CpuMpData->ApLoopMode = ApLoopMode;
2230 DEBUG ((DEBUG_INFO,
"AP Loop Mode is %d\n", CpuMpData->ApLoopMode));
2232 CpuMpData->WakeUpByInitSipiSipi = (CpuMpData->ApLoopMode == ApInHltLoop);
2237 for (Index = 0; Index < MaxLogicalProcessorNumber; Index++) {
2238 CpuMpData->CpuData[Index].StartupApSignal =
2239 (UINT32 *)(MonitorBuffer + MonitorFilterSize * Index);
2248 (VOID *)CpuMpData->WakeupBufferHigh,
2249 CpuMpData->AddressMap.RendezvousFunnelAddress +
2250 CpuMpData->AddressMap.ModeTransitionOffset,
2251 ApResetVectorSizeAbove1Mb
2253 DEBUG ((DEBUG_INFO,
"AP Vector: non-16-bit = %p/%x\n", CpuMpData->WakeupBufferHigh, ApResetVectorSizeAbove1Mb));
2266 if (FirstMpHandOff ==
NULL) {
2267 if (MaxLogicalProcessorNumber > 1) {
2285 DEBUG ((DEBUG_INFO,
"MpInitLib: Find %d processors in system.\n", CpuMpData->CpuCount));
2292 CpuMpData->InitFlag = ApInitDone;
2293 if (CpuMpData->UseSevEsAPMethod) {
2297 CpuMpData->CpuCount = MaxLogicalProcessorNumber;
2299 for (MpHandOff = FirstMpHandOff;
2303 for (HobIndex = 0; HobIndex < MpHandOff->CpuCount; HobIndex++) {
2304 Index = MpHandOff->ProcessorIndex + HobIndex;
2306 CpuMpData->CpuData[Index].CpuHealthy = (MpHandOff->Info[HobIndex].Health == 0) ?
TRUE :
FALSE;
2307 CpuMpData->CpuData[Index].ApFunction = 0;
2308 CpuInfoInHob[Index].InitialApicId = MpHandOff->Info[HobIndex].ApicId;
2309 CpuInfoInHob[Index].ApTopOfStack = CpuMpData->Buffer + (Index + 1) * CpuMpData->CpuApStackSize;
2310 CpuInfoInHob[Index].ApicId = MpHandOff->Info[HobIndex].ApicId;
2311 CpuInfoInHob[Index].Health = MpHandOff->Info[HobIndex].Health;
2316 if (MpHandOffConfig ==
NULL) {
2319 "%a: at least one MpHandOff HOB, but no MpHandOffConfig HOB\n",
2322 ASSERT (MpHandOffConfig !=
NULL);
2328 "FirstMpHandOff->WaitLoopExecutionMode: %04d, sizeof (VOID *): %04d\n",
2329 MpHandOffConfig->WaitLoopExecutionMode,
2332 if (MpHandOffConfig->WaitLoopExecutionMode == sizeof (VOID *)) {
2333 ASSERT (CpuMpData->ApLoopMode != ApInHltLoop);
2335 CpuMpData->FinishedCount = 0;
2351 while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) {
2359 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
2360 SetApState (&CpuMpData->CpuData[Index], CpuStateIdle);
2373 CpuMpData->WakeUpByInitSipiSipi =
TRUE;
2378 &CpuMpData->MicrocodePatchAddress,
2379 &CpuMpData->MicrocodePatchRegionSize
2401 if (CpuMpData->CpuCount > 1) {
2406 while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) {
2410 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
2411 SetApState (&CpuMpData->CpuData[Index], CpuStateIdle);
2420 UINT32 ExpectedMicrocodeRevision;
2423 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
2425 if (ThreadId == 0) {
2430 ExpectedMicrocodeRevision = 0;
2431 if (CpuMpData->CpuData[Index].MicrocodeEntryAddr != 0) {
2432 ExpectedMicrocodeRevision = ((
CPU_MICROCODE_HEADER *)(
UINTN)CpuMpData->CpuData[Index].MicrocodeEntryAddr)->UpdateRevision;
2437 "CPU[%04d]: Microcode revision = %08x, expected = %08x\n",
2439 CpuMpData->CpuData[Index].MicrocodeRevision,
2440 ExpectedMicrocodeRevision
2484 UINTN OriginalProcessorNumber;
2489 if (CpuMpData ==
NULL) {
2490 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get CpuMpData.\n", __func__));
2491 return EFI_LOAD_ERROR;
2499 OriginalProcessorNumber = ProcessorNumber;
2500 ProcessorNumber &= BIT24 - 1;
2507 if (EFI_ERROR (Status)) {
2508 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get processor number. Failed to get MpInit Processor info.\n", __func__));
2512 if (CallerNumber != CpuMpData->BspNumber) {
2513 return EFI_DEVICE_ERROR;
2516 if (ProcessorInfoBuffer ==
NULL) {
2517 return EFI_INVALID_PARAMETER;
2520 if (ProcessorNumber >= CpuMpData->CpuCount) {
2521 return EFI_NOT_FOUND;
2524 ProcessorInfoBuffer->ProcessorId = (UINT64)CpuInfoInHob[ProcessorNumber].ApicId;
2525 ProcessorInfoBuffer->StatusFlag = 0;
2526 if (ProcessorNumber == CpuMpData->BspNumber) {
2530 if (CpuMpData->CpuData[ProcessorNumber].CpuHealthy) {
2534 if (
GetApState (&CpuMpData->CpuData[ProcessorNumber]) == CpuStateDisabled) {
2535 ProcessorInfoBuffer->StatusFlag &= ~PROCESSOR_ENABLED_BIT;
2544 CpuInfoInHob[ProcessorNumber].ApicId,
2545 &ProcessorInfoBuffer->Location.Package,
2546 &ProcessorInfoBuffer->Location.Core,
2547 &ProcessorInfoBuffer->Location.Thread
2552 CpuInfoInHob[ProcessorNumber].ApicId,
2553 &ProcessorInfoBuffer->ExtendedInformation.Location2.Package,
2554 &ProcessorInfoBuffer->ExtendedInformation.Location2.Die,
2555 &ProcessorInfoBuffer->ExtendedInformation.Location2.Tile,
2556 &ProcessorInfoBuffer->ExtendedInformation.Location2.Module,
2557 &ProcessorInfoBuffer->ExtendedInformation.Location2.Core,
2558 &ProcessorInfoBuffer->ExtendedInformation.Location2.Thread
2562 if (HealthData !=
NULL) {
2563 HealthData->Uint32 = CpuInfoInHob[ProcessorNumber].Health;
2583 IN BOOLEAN EnableOldBSP
2590 BOOLEAN OldInterruptState;
2591 BOOLEAN OldTimerInterruptState;
2615 if (CpuMpData ==
NULL) {
2616 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get CpuMpData.\n", __func__));
2617 return EFI_LOAD_ERROR;
2625 if (EFI_ERROR (Status)) {
2626 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get processor number. Failed to get MpInit Processor info.\n", __func__));
2630 if (CallerNumber != CpuMpData->BspNumber) {
2631 return EFI_DEVICE_ERROR;
2634 if (ProcessorNumber >= CpuMpData->CpuCount) {
2635 return EFI_NOT_FOUND;
2641 State =
GetApState (&CpuMpData->CpuData[ProcessorNumber]);
2642 if (State == CpuStateDisabled) {
2643 return EFI_INVALID_PARAMETER;
2649 if (ProcessorNumber == CpuMpData->BspNumber) {
2650 return EFI_INVALID_PARAMETER;
2656 if (State == CpuStateBusy) {
2657 return EFI_NOT_READY;
2660 CpuMpData->BSPInfo.State = CPU_SWITCH_STATE_IDLE;
2661 CpuMpData->APInfo.State = CPU_SWITCH_STATE_IDLE;
2662 CpuMpData->SwitchBspFlag =
TRUE;
2663 CpuMpData->NewBspNumber = ProcessorNumber;
2699 while (
GetApState (&CpuMpData->CpuData[CallerNumber]) != CpuStateFinished) {
2703 CpuMpData->SwitchBspFlag =
FALSE;
2707 if (!EnableOldBSP) {
2708 SetApState (&CpuMpData->CpuData[CallerNumber], CpuStateDisabled);
2710 SetApState (&CpuMpData->CpuData[CallerNumber], CpuStateIdle);
2716 CpuMpData->BspNumber = (UINT32)ProcessorNumber;
2723 if (OldTimerInterruptState) {
2747 IN BOOLEAN EnableAP,
2748 IN UINT32 *HealthFlag OPTIONAL
2757 if (CpuMpData ==
NULL) {
2758 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get CpuMpData.\n", __func__));
2759 return EFI_LOAD_ERROR;
2767 if (EFI_ERROR (Status)) {
2768 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get processor number. Failed to get MpInit Processor info.\n", __func__));
2772 if (CallerNumber != CpuMpData->BspNumber) {
2773 return EFI_DEVICE_ERROR;
2776 if (ProcessorNumber == CpuMpData->BspNumber) {
2777 return EFI_INVALID_PARAMETER;
2780 if (ProcessorNumber >= CpuMpData->CpuCount) {
2781 return EFI_NOT_FOUND;
2785 SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateDisabled);
2790 if (HealthFlag !=
NULL) {
2791 CpuMpData->CpuData[ProcessorNumber].CpuHealthy =
2822 if (ProcessorNumber ==
NULL) {
2823 return EFI_INVALID_PARAMETER;
2828 if (CpuMpData ==
NULL) {
2829 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get CpuMpData.\n", __func__));
2830 return EFI_LOAD_ERROR;
2859 OUT UINTN *NumberOfProcessors OPTIONAL,
2860 OUT UINTN *NumberOfEnabledProcessors OPTIONAL
2865 UINTN ProcessorNumber;
2866 UINTN EnabledProcessorNumber;
2872 if (CpuMpData ==
NULL) {
2873 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get CpuMpData.\n", __func__));
2874 return EFI_LOAD_ERROR;
2877 if ((NumberOfProcessors ==
NULL) && (NumberOfEnabledProcessors ==
NULL)) {
2878 return EFI_INVALID_PARAMETER;
2886 if (EFI_ERROR (Status)) {
2887 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get processor number. Failed to get MpInit Processor info.\n", __func__));
2891 if (CallerNumber != CpuMpData->BspNumber) {
2892 return EFI_DEVICE_ERROR;
2895 ProcessorNumber = CpuMpData->CpuCount;
2896 EnabledProcessorNumber = 0;
2897 for (Index = 0; Index < ProcessorNumber; Index++) {
2898 if (
GetApState (&CpuMpData->CpuData[Index]) != CpuStateDisabled) {
2899 EnabledProcessorNumber++;
2903 if (NumberOfProcessors !=
NULL) {
2904 *NumberOfProcessors = ProcessorNumber;
2907 if (NumberOfEnabledProcessors !=
NULL) {
2908 *NumberOfEnabledProcessors = EnabledProcessorNumber;
2949 IN BOOLEAN SingleThread,
2950 IN BOOLEAN ExcludeBsp,
2952 IN UINTN TimeoutInMicroseconds,
2953 IN VOID *ProcedureArgument OPTIONAL,
2959 UINTN ProcessorCount;
2960 UINTN ProcessorNumber;
2963 BOOLEAN HasEnabledAp;
2968 if (FailedCpuList !=
NULL) {
2969 *FailedCpuList =
NULL;
2972 if (CpuMpData ==
NULL) {
2973 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get CpuMpData.\n", __func__));
2974 return EFI_LOAD_ERROR;
2977 if ((CpuMpData->CpuCount == 1) && ExcludeBsp) {
2978 return EFI_NOT_STARTED;
2981 if (Procedure ==
NULL) {
2982 return EFI_INVALID_PARAMETER;
2990 if (EFI_ERROR (Status)) {
2991 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get processor number. Failed to get MpInit Processor info.\n", __func__));
2995 if (CallerNumber != CpuMpData->BspNumber) {
2996 return EFI_DEVICE_ERROR;
3004 ProcessorCount = CpuMpData->CpuCount;
3005 HasEnabledAp =
FALSE;
3010 for (ProcessorNumber = 0; ProcessorNumber < ProcessorCount; ProcessorNumber++) {
3011 CpuData = &CpuMpData->CpuData[ProcessorNumber];
3012 if (ProcessorNumber != CpuMpData->BspNumber) {
3014 if (ApState != CpuStateDisabled) {
3015 HasEnabledAp =
TRUE;
3016 if (ApState != CpuStateIdle) {
3020 return EFI_NOT_READY;
3026 if (!HasEnabledAp && ExcludeBsp) {
3030 return EFI_NOT_STARTED;
3033 CpuMpData->RunningCount = 0;
3034 for (ProcessorNumber = 0; ProcessorNumber < ProcessorCount; ProcessorNumber++) {
3035 CpuData = &CpuMpData->CpuData[ProcessorNumber];
3036 CpuData->Waiting =
FALSE;
3037 if (ProcessorNumber != CpuMpData->BspNumber) {
3038 if (CpuData->State == CpuStateIdle) {
3042 CpuData->Waiting =
TRUE;
3043 CpuMpData->RunningCount++;
3048 CpuMpData->Procedure = Procedure;
3049 CpuMpData->ProcArguments = ProcedureArgument;
3050 CpuMpData->SingleThread = SingleThread;
3051 CpuMpData->FinishedCount = 0;
3052 CpuMpData->FailedCpuList = FailedCpuList;
3054 TimeoutInMicroseconds,
3055 &CpuMpData->CurrentTime
3057 CpuMpData->TotalTime = 0;
3058 CpuMpData->WaitEvent = WaitEvent;
3060 if (!SingleThread) {
3063 for (ProcessorNumber = 0; ProcessorNumber < ProcessorCount; ProcessorNumber++) {
3064 if (ProcessorNumber == CallerNumber) {
3068 if (CpuMpData->CpuData[ProcessorNumber].Waiting) {
3069 WakeUpAP (CpuMpData,
FALSE, ProcessorNumber, Procedure, ProcedureArgument,
TRUE);
3079 Procedure (ProcedureArgument);
3083 if (WaitEvent ==
NULL) {
3086 }
while (Status == EFI_NOT_READY);
3120 IN UINTN TimeoutInMicroseconds,
3121 IN VOID *ProcedureArgument OPTIONAL,
3122 OUT BOOLEAN *Finished OPTIONAL
3132 if (Finished !=
NULL) {
3136 if (CpuMpData ==
NULL) {
3137 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get CpuMpData.\n", __func__));
3138 return EFI_LOAD_ERROR;
3146 if (EFI_ERROR (Status)) {
3147 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get processor number. Failed to get MpInit Processor info.\n", __func__));
3151 if (CallerNumber != CpuMpData->BspNumber) {
3152 return EFI_DEVICE_ERROR;
3158 if (ProcessorNumber >= CpuMpData->CpuCount) {
3159 return EFI_NOT_FOUND;
3165 if (ProcessorNumber == CpuMpData->BspNumber) {
3166 return EFI_INVALID_PARAMETER;
3172 if (Procedure ==
NULL) {
3173 return EFI_INVALID_PARAMETER;
3184 if (
GetApState (&CpuMpData->CpuData[ProcessorNumber]) == CpuStateDisabled) {
3185 return EFI_INVALID_PARAMETER;
3193 CpuData = &CpuMpData->CpuData[ProcessorNumber];
3194 CpuData->WaitEvent = WaitEvent;
3195 CpuData->Finished = Finished;
3196 CpuData->ExpectedTime =
CalculateTimeout (TimeoutInMicroseconds, &CpuData->CurrentTime);
3197 CpuData->TotalTime = 0;
3199 WakeUpAP (CpuMpData,
FALSE, ProcessorNumber, Procedure, ProcedureArgument,
TRUE);
3206 if (WaitEvent ==
NULL) {
3209 }
while (Status == EFI_NOT_READY);
3231 if (GuidHob !=
NULL) {
3232 DataInHob = GET_GUID_HOB_DATA (GuidHob);
3269 IN UINTN TimeoutInMicroseconds,
3270 IN VOID *ProcedureArgument OPTIONAL
3278 TimeoutInMicroseconds,
3297 IN UINT64 CurrentAttr,
3298 IN CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr
3301 UINT64 CurrentLevel;
3303 CurrentLevel = CurrentAttr & CCAttrTypeMask;
3310 return CurrentLevel >= CCAttrAmdSev;
3311 case CCAttrAmdSevEs:
3315 return CurrentLevel >= CCAttrAmdSevEs;
3316 case CCAttrAmdSevSnp:
3317 return CurrentLevel == CCAttrAmdSevSnp;
3318 case CCAttrFeatureAmdSevEsDebugVirtualization:
3319 return !!(CurrentAttr & CCAttrFeatureAmdSevEsDebugVirtualization);
3337 IN CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr
3345 CurrentAttr =
PcdGet64 (PcdConfidentialComputingGuestAttr);
3350 if (((
RShiftU64 (CurrentAttr, 8)) & 0xff) == 1) {
3354 return (CurrentAttr == Attr);
3369 BOOLEAN MwaitSupport;
3370 UINTN ProcessorNumber;
3376 if (EFI_ERROR (Status)) {
3377 DEBUG ((DEBUG_ERROR,
"[%a] - Failed to get processor number. Aborting AP sync.\n", __func__));
3383 if (CpuMpData->UseSevEsAPMethod) {
3387 StackStart = CpuMpData->SevEsAPResetStackStart;
3388 mReservedApLoop.AmdSevEntry (
3390 CpuMpData->ApTargetCState,
3391 CpuMpData->PmCodeSegment,
3392 StackStart - ProcessorNumber * AP_SAFE_STACK_SIZE,
3393 (
UINTN)&mNumberToFinish,
3394 CpuMpData->Pm16CodeSegment,
3395 CpuMpData->SevEsAPBuffer,
3396 CpuMpData->WakeupBuffer
3402 StackStart = mReservedTopOfApStack;
3403 mReservedApLoop.GenericEntry (
3405 CpuMpData->ApTargetCState,
3406 StackStart - ProcessorNumber * AP_SAFE_STACK_SIZE,
3407 (
UINTN)&mNumberToFinish,
3431 UINTN ApLoopFuncSize;
3436 AddressMap = &CpuMpData->AddressMap;
3437 if (CpuMpData->UseSevEsAPMethod) {
3441 Address = BASE_4GB - 1;
3442 ApLoopFunc = AddressMap->RelocateApLoopFuncAddressAmdSev;
3443 ApLoopFuncSize = AddressMap->RelocateApLoopFuncSizeAmdSev;
3449 ApLoopFunc = AddressMap->RelocateApLoopFuncAddressGeneric;
3450 ApLoopFuncSize = AddressMap->RelocateApLoopFuncSizeGeneric;
3474 ASSERT (Address != 0);
3477 if (Cr0.Bits.PG != 0) {
3487 mReservedApLoop.Data = (VOID *)(
UINTN)Address;
3488 ASSERT (mReservedApLoop.Data !=
NULL);
3489 CopyMem (mReservedApLoop.Data, ApLoopFunc, ApLoopFuncSize);
3490 if (!CpuMpData->UseSevEsAPMethod) {
#define CPU_STACK_ALIGNMENT
UINT64 EFIAPI GetPerformanceCounterProperties(OUT UINT64 *StartValue OPTIONAL, OUT UINT64 *EndValue OPTIONAL)
UINT64 EFIAPI GetPerformanceCounter(VOID)
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
VOID *EFIAPI GetNextGuidHob(IN CONST EFI_GUID *Guid, IN CONST VOID *HobStart)
BOOLEAN EFIAPI SetInterruptState(IN BOOLEAN InterruptState)
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
UINT64 EFIAPI MultU64x64(IN UINT64 Multiplicand, IN UINT64 Multiplier)
BOOLEAN EFIAPI SaveAndDisableInterrupts(VOID)
VOID EFIAPI SwitchStack(IN SWITCH_STACK_ENTRY_POINT EntryPoint, IN VOID *Context1 OPTIONAL, IN VOID *Context2 OPTIONAL, IN VOID *NewStack,...)
VOID EFIAPI CpuDeadLoop(VOID)
VOID EFIAPI CpuPause(VOID)
VOID EFIAPI DisableInterrupts(VOID)
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
UINT64 EFIAPI DivU64x64Remainder(IN UINT64 Dividend, IN UINT64 Divisor, OUT UINT64 *Remainder OPTIONAL)
VOID(EFIAPI * SWITCH_STACK_ENTRY_POINT)(IN VOID *Context1 OPTIONAL, IN VOID *Context2 OPTIONAL)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI CpuSleep(VOID)
VOID CheckAndUpdateApsStatus(VOID)
VOID RemoveNxprotection(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINTN Length)
UINTN GetWakeupBuffer(IN UINTN WakeupBufferSize)
VOID AllocateApLoopCodeBuffer(IN UINTN Pages, IN OUT EFI_PHYSICAL_ADDRESS *Address)
UINTN AllocateCodeBuffer(IN UINTN BufferSize)
CPU_MP_DATA * GetCpuMpData(VOID)
VOID InitMpGlobalData(IN CPU_MP_DATA *CpuMpData)
VOID EnableDebugAgent(VOID)
VOID SaveCpuMpData(IN CPU_MP_DATA *CpuMpData)
UINTN CreatePageTable(IN UINTN Address, IN UINTN Length)
UINTN EFIAPI AsmWriteDr1(UINTN Dr1)
UINT16 EFIAPI AsmReadTr(VOID)
UINTN EFIAPI AsmReadDr1(VOID)
UINTN EFIAPI AsmReadDr0(VOID)
UINTN EFIAPI AsmWriteDr7(UINTN Dr7)
UINTN EFIAPI AsmWriteDr3(UINTN Dr3)
UINTN EFIAPI AsmReadCr3(VOID)
UINTN EFIAPI AsmReadDr2(VOID)
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
UINTN EFIAPI AsmWriteCr3(UINTN Cr3)
UINTN EFIAPI AsmWriteCr4(UINTN Cr4)
UINTN EFIAPI AsmReadCr0(VOID)
UINTN EFIAPI AsmWriteDr2(UINTN Dr2)
UINTN EFIAPI AsmWriteDr0(UINTN Dr0)
UINTN EFIAPI AsmWriteCr0(UINTN Cr0)
UINT16 EFIAPI AsmReadCs(VOID)
UINT64 EFIAPI AsmWriteMsr64(IN UINT32 Index, IN UINT64 Value)
UINTN EFIAPI AsmReadDr3(VOID)
UINTN EFIAPI AsmReadCr4(VOID)
UINTN EFIAPI AsmReadDr6(VOID)
UINTN EFIAPI AsmWriteDr6(UINTN Dr6)
UINT16 EFIAPI AsmReadDs(VOID)
UINTN EFIAPI AsmReadDr7(VOID)
VOID EFIAPI SendInitSipiSipiAllExcludingSelf(IN UINT32 StartupRoutine)
BOOLEAN EFIAPI GetApicTimerInterruptState(VOID)
VOID EFIAPI DisableLvtInterrupts(VOID)
VOID EFIAPI GetApicTimerState(OUT UINTN *DivideValue OPTIONAL, OUT BOOLEAN *PeriodicMode OPTIONAL, OUT UINT8 *Vector OPTIONAL)
UINT32 EFIAPI GetInitialApicId(VOID)
#define LOCAL_APIC_MODE_X2APIC
x2APIC mode.
UINTN EFIAPI GetApicMode(VOID)
VOID EFIAPI ProgramVirtualWireMode(VOID)
VOID EFIAPI EnableApicTimerInterrupt(VOID)
#define LOCAL_APIC_MODE_XAPIC
xAPIC mode.
VOID EFIAPI SendStartupIpiAllExcludingSelf(IN UINT32 StartupRoutine)
VOID EFIAPI SetApicMode(IN UINTN ApicMode)
UINT32 EFIAPI GetApicTimerInitCount(VOID)
VOID EFIAPI GetProcessorLocation2ByApicId(IN UINT32 InitialApicId, OUT UINT32 *Package OPTIONAL, OUT UINT32 *Die OPTIONAL, OUT UINT32 *Tile OPTIONAL, OUT UINT32 *Module OPTIONAL, OUT UINT32 *Core OPTIONAL, OUT UINT32 *Thread OPTIONAL)
VOID EFIAPI GetProcessorLocationByApicId(IN UINT32 InitialApicId, OUT UINT32 *Package OPTIONAL, OUT UINT32 *Core OPTIONAL, OUT UINT32 *Thread OPTIONAL)
VOID EFIAPI InitializeApicTimer(IN UINTN DivideValue, IN UINT32 InitCount, IN BOOLEAN PeriodicMode, IN UINT8 Vector)
VOID EFIAPI SendInitSipiSipi(IN UINT32 ApicId, IN UINT32 StartupRoutine)
VOID EFIAPI DisableApicTimerInterrupt(VOID)
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)
CPU_STATE GetApState(IN CPU_AP_DATA *CpuData)
CPU_MP_DATA * GetCpuMpDataFromGuidedHob(VOID)
VOID EFIAPI ApWakeupFunction(IN UINTN ApIndex, IN MP_CPU_EXCHANGE_INFO *ExchangeInfo)
EFI_STATUS EFIAPI MpInitLibWhoAmI(OUT UINTN *ProcessorNumber)
EFI_STATUS EFIAPI MpInitLibGetNumberOfProcessors(OUT UINTN *NumberOfProcessors OPTIONAL, OUT UINTN *NumberOfEnabledProcessors OPTIONAL)
VOID SortApicId(IN CPU_MP_DATA *CpuMpData)
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)
UINT64 CalculateTimeout(IN UINTN TimeoutInMicroseconds, OUT UINT64 *CurrentTime)
EFI_STATUS EFIAPI MpInitLibStartupAllCPUs(IN EFI_AP_PROCEDURE Procedure, IN UINTN TimeoutInMicroseconds, IN VOID *ProcedureArgument OPTIONAL)
VOID TimedWaitForApFinish(IN CPU_MP_DATA *CpuMpData, IN UINT32 FinishedApLimit, IN UINT32 TimeLimit)
VOID WaitApWakeup(IN volatile UINT32 *ApStartupSignalBuffer)
EFI_STATUS EFIAPI MpInitLibGetProcessorInfo(IN UINTN ProcessorNumber, OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer, OUT EFI_HEALTH_FLAGS *HealthData OPTIONAL)
EFI_STATUS GetProcessorNumber(IN CPU_MP_DATA *CpuMpData, OUT UINTN *ProcessorNumber)
BOOLEAN CheckTimeout(IN OUT UINT64 *PreviousTime, IN UINT64 *TotalTime, IN UINT64 Timeout)
UINTN CollectProcessorCount(IN CPU_MP_DATA *CpuMpData)
VOID FillExchangeInfoData(IN CPU_MP_DATA *CpuMpData)
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)
VOID InitializeApData(IN OUT CPU_MP_DATA *CpuMpData, IN UINTN ProcessorNumber, IN UINT32 BistData)
VOID SetApState(IN CPU_AP_DATA *CpuData, IN CPU_STATE State)
EFI_STATUS EFIAPI MpInitLibInitialize(VOID)
EFI_STATUS CheckAllAPs(VOID)
EFI_STATUS GetNextWaitingProcessorNumber(OUT UINTN *NextProcessorNumber)
#define ALIGN_VALUE(Value, Alignment)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG_CODE_BEGIN()
#define DEBUG(Expression)
#define MSR_IA32_PLATFORM_ID
#define MSR_IA32_APIC_BASE
#define CPUID_VERSION_INFO
#define CPUID_MONITOR_MWAIT
#define CPUID_EXTENDED_CPU_SIG
UINT32 EFIAPI AsmCpuid(IN UINT32 Index, OUT UINT32 *RegisterEax OPTIONAL, OUT UINT32 *RegisterEbx OPTIONAL, OUT UINT32 *RegisterEcx OPTIONAL, OUT UINT32 *RegisterEdx OPTIONAL)
VOID ShadowMicrocodeUpdatePatch(IN OUT CPU_MP_DATA *CpuMpData)
VOID MicrocodeDetect(IN CPU_MP_DATA *CpuMpData, IN UINTN ProcessorNumber)
BOOLEAN GetMicrocodePatchInfoFromHob(UINT64 *Address, UINT64 *RegionSize)
UINTN EFIAPI AsmMonitor(IN UINTN RegisterEax, IN UINTN RegisterEcx, IN UINTN RegisterEdx)
VOID RestoreVolatileRegisters(IN CPU_VOLATILE_REGISTERS *VolatileRegisters)
VOID EFIAPI RelocateApLoop(IN OUT VOID *Buffer)
VOID BackupAndPrepareWakeupBuffer(IN CPU_MP_DATA *CpuMpData)
VOID SaveLocalApicTimerSetting(IN CPU_MP_DATA *CpuMpData)
VOID EFIAPI DxeApEntryPoint(CPU_MP_DATA *CpuMpData)
EFI_STATUS EnableDisableApWorker(IN UINTN ProcessorNumber, IN BOOLEAN EnableAP, IN UINT32 *HealthFlag OPTIONAL)
VOID EFIAPI ApFuncEnableX2Apic(IN OUT VOID *Buffer)
VOID EFIAPI FutureBSPProc(IN VOID *Buffer)
VOID SwitchApContext(IN CONST MP_HAND_OFF_CONFIG *MpHandOffConfig, IN CONST MP_HAND_OFF *FirstMpHandOff)
VOID AllocateResetVectorBelow1Mb(IN OUT CPU_MP_DATA *CpuMpData)
VOID SaveVolatileRegisters(OUT CPU_VOLATILE_REGISTERS *VolatileRegisters)
BOOLEAN IsBspExecuteDisableEnabled(VOID)
BOOLEAN EFIAPI ConfidentialComputingGuestHas(IN CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr)
VOID PlaceAPInHltLoop(IN CPU_MP_DATA *CpuMpData)
MP_HAND_OFF * GetNextMpHandOffHob(IN CONST MP_HAND_OFF *MpHandOff)
STATIC VOID GetApResetVectorSize(IN MP_ASSEMBLY_ADDRESS_MAP *AddressMap, OUT UINTN *SizeBelow1Mb OPTIONAL, OUT UINTN *SizeAbove1Mb OPTIONAL)
VOID AutoEnableX2Apic(IN CPU_MP_DATA *CpuMpData)
VOID PrepareApLoopCode(IN CPU_MP_DATA *CpuMpData)
VOID PlaceAPInMwaitLoopOrRunLoop(IN UINT8 ApLoopMode, IN volatile UINT32 *ApStartupSignalBuffer, IN UINT8 ApTargetCState)
UINT32 GetBspNumber(IN CONST MP_HAND_OFF *FirstMpHandOff)
VOID SyncLocalApicTimerSetting(IN CPU_MP_DATA *CpuMpData)
VOID EFIAPI ApInitializeSync(IN OUT VOID *Buffer)
BOOLEAN IsMwaitSupport(VOID)
VOID ResetProcessorToIdleState(IN UINTN ProcessorNumber)
STATIC BOOLEAN AmdMemEncryptionAttrCheck(IN UINT64 CurrentAttr, IN CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr)
EFI_STATUS SwitchBSPWorker(IN UINTN ProcessorNumber, IN BOOLEAN EnableOldBSP)
MP_HAND_OFF_CONFIG * GetMpHandOffConfigHob(VOID)
UINT8 GetApLoopMode(OUT UINT32 *MonitorFilterSize)
VOID RestoreWakeupBuffer(IN CPU_MP_DATA *CpuMpData)
VOID EFIAPI SwitchContextPerAp(VOID)
VOID FreeResetVector(IN CPU_MP_DATA *CpuMpData)
VOID EFIAPI AsmExchangeRole(IN CPU_EXCHANGE_ROLE_INFO *MyInfo, IN CPU_EXCHANGE_ROLE_INFO *OthersInfo)
VOID EFIAPI AsmGetAddressMap(OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap)
#define PROCESSOR_HEALTH_STATUS_BIT
#define PROCESSOR_AS_BSP_BIT
#define CPU_V2_EXTENDED_TOPOLOGY
#define PROCESSOR_ENABLED_BIT
MTRR_SETTINGS *EFIAPI MtrrSetAllMtrrs(IN MTRR_SETTINGS *MtrrSetting)
MTRR_SETTINGS *EFIAPI MtrrGetAllMtrrs(OUT MTRR_SETTINGS *MtrrSetting)
UINTN EFIAPI AsmMwait(IN UINTN RegisterEax, IN UINTN RegisterEcx)
#define PcdGet64(TokenName)
#define PcdGet8(TokenName)
#define FixedPcdGetBool(TokenName)
#define PcdGet32(TokenName)
VOID(EFIAPI * EFI_AP_PROCEDURE)(IN OUT VOID *Buffer)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
VOID *EFIAPI AllocatePages(IN UINTN Pages)
UINT32 EFIAPI InterlockedIncrement(IN volatile UINT32 *Value)
SPIN_LOCK *EFIAPI AcquireSpinLock(IN OUT SPIN_LOCK *SpinLock)
UINT32 EFIAPI InterlockedCompareExchange32(IN OUT volatile UINT32 *Value, IN UINT32 CompareValue, IN UINT32 ExchangeValue)
UINT32 EFIAPI InterlockedDecrement(IN volatile UINT32 *Value)
SPIN_LOCK *EFIAPI InitializeSpinLock(OUT SPIN_LOCK *SpinLock)
SPIN_LOCK *EFIAPI ReleaseSpinLock(IN OUT SPIN_LOCK *SpinLock)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)
#define EFI_SIZE_TO_PAGES(Size)
VOID AllocateSevEsAPMemory(IN OUT CPU_MP_DATA *CpuMpData)
VOID AmdSevUpdateCpuMpData(IN CPU_MP_DATA *CpuMpData)
VOID SetSevEsJumpTable(IN UINTN SipiVector)
VOID SevEsPlaceApHlt(CPU_MP_DATA *CpuMpData)
VOID FillExchangeInfoDataSevEs(IN volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo)
VOID SevSnpCreateAP(IN CPU_MP_DATA *CpuMpData, IN INTN ProcessorNumber)
BOOLEAN CanUseSevSnpCreateAP(IN CPU_MP_DATA *CpuMpData)
BOOLEAN EFIAPI StandardSignatureIsAuthenticAMD(VOID)
VOID EFIAPI InitializeFloatingPointUnits(VOID)
VOID EFIAPI AsmReadGdtr(OUT IA32_DESCRIPTOR *Gdtr)
VOID EFIAPI AsmReadIdtr(OUT IA32_DESCRIPTOR *Idtr)
VOID EFIAPI AsmWriteTr(IN UINT16 Selector)
VOID EFIAPI AsmWriteGdtr(IN CONST IA32_DESCRIPTOR *Gdtr)
VOID EFIAPI AsmWriteIdtr(IN CONST IA32_DESCRIPTOR *Idtr)
struct CPUID_MONITOR_MWAIT_EBX::@702 Bits
UINT32 LargestMonitorLineSize
struct CPUID_VERSION_INFO_ECX::@695 Bits
struct CPUID_VERSION_INFO_EDX::@696 Bits
struct MSR_IA32_APIC_BASE_REGISTER::@627 Bits
struct MSR_IA32_EFER_REGISTER::@691 Bits
struct MSR_IA32_PLATFORM_ID_REGISTER::@626 Bits