15STATIC UINT64 mSevEsPeiWakeupBuffer = BASE_1MB;
46 if (ApicBaseMsr.
Bits.
BSP == 1) {
48 ASSERT (CpuMpData !=
NULL);
86 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
87 if (Index % MaxCpusPerHob == 0) {
89 CpusInHob =
MIN (CpuMpData->CpuCount - HobBase, MaxCpusPerHob);
93 ASSERT (MpHandOff !=
NULL);
94 ZeroMem (MpHandOff, MpHandOffSize);
96 MpHandOff->ProcessorIndex = HobBase;
97 MpHandOff->CpuCount = CpusInHob;
100 MpHandOff->Info[Index-HobBase].ApicId = CpuInfoInHob[Index].ApicId;
101 MpHandOff->Info[Index-HobBase].Health = CpuInfoInHob[Index].Health;
102 if (CpuMpData->ApLoopMode != ApInHltLoop) {
103 MpHandOff->Info[Index-HobBase].StartupSignalAddress = (UINT64)(
UINTN)CpuMpData->CpuData[Index].StartupApSignal;
104 MpHandOff->Info[Index-HobBase].StartupProcedureAddress = (UINT64)(
UINTN)&CpuMpData->CpuData[Index].ApFunction;
108 ZeroMem (&MpHandOffConfig,
sizeof (MpHandOffConfig));
109 if (CpuMpData->ApLoopMode != ApInHltLoop) {
110 MpHandOffConfig.StartupSignalValue = MP_HAND_OFF_SIGNAL;
111 MpHandOffConfig.WaitLoopExecutionMode =
sizeof (VOID *);
115 &mMpHandOffConfigGuid,
116 (VOID *)&MpHandOffConfig,
117 sizeof (MpHandOffConfig)
123 Data64 = (UINT64)(
UINTN)CpuMpData;
125 &mCpuInitMpLibHobGuid,
142 IN UINT64 WakeupBufferStart,
143 IN UINT64 WakeupBufferEnd
160 while (!END_OF_HOB_LIST (Hob)) {
161 if (Hob.Header->
HobType == EFI_HOB_TYPE_MEMORY_ALLOCATION) {
162 MemoryHob = Hob.MemoryAllocation;
165 if (!((WakeupBufferStart >= MemoryEnd) || (WakeupBufferEnd <= MemoryStart))) {
171 Hob.Raw = GET_NEXT_HOB (Hob);
191 UINT64 WakeupBufferStart;
192 UINT64 WakeupBufferEnd;
194 WakeupBufferSize = (WakeupBufferSize + SIZE_4KB - 1) & ~(SIZE_4KB - 1);
204 while (!END_OF_HOB_LIST (Hob)) {
205 if (Hob.Header->
HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
207 (Hob.ResourceDescriptor->
ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) &&
209 (EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED |
210 EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED |
211 EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED
220 (WakeupBufferEnd > mSevEsPeiWakeupBuffer))
225 WakeupBufferEnd = mSevEsPeiWakeupBuffer;
226 }
else if (WakeupBufferEnd > BASE_1MB) {
230 WakeupBufferEnd = BASE_1MB;
233 while (WakeupBufferEnd > (UINT64)WakeupBufferSize) {
237 WakeupBufferStart = (WakeupBufferEnd - WakeupBufferSize) & ~(SIZE_4KB - 1);
238 if (WakeupBufferStart < Hob.ResourceDescriptor->PhysicalStart) {
247 WakeupBufferEnd -= WakeupBufferSize;
253 "WakeupBufferStart = %x, WakeupBufferSize = %x\n",
263 mSevEsPeiWakeupBuffer = WakeupBufferStart;
266 return (
UINTN)WakeupBufferStart;
274 Hob.Raw = GET_NEXT_HOB (Hob);
301 if (EFI_ERROR (Status)) {
305 return (
UINTN)Address;
355 sizeof (UINT64) * CpuMpData->CpuCount;
358 if (MicrocodeHob ==
NULL) {
366 MicrocodeHob->MicrocodePatchAddress = CpuMpData->MicrocodePatchAddress;
367 MicrocodeHob->MicrocodePatchRegionSize = CpuMpData->MicrocodePatchRegionSize;
372 MicrocodeHob->ProcessorCount = CpuMpData->CpuCount;
373 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
374 if (CpuMpData->CpuData[Index].MicrocodeEntryAddr != 0) {
375 MicrocodeHob->ProcessorSpecificPatchOffset[Index] =
376 CpuMpData->CpuData[Index].MicrocodeEntryAddr - CpuMpData->MicrocodePatchAddress;
378 MicrocodeHob->ProcessorSpecificPatchOffset[Index] = MAX_UINT64;
383 &gEdkiiMicrocodePatchHobGuid,
412 mNumberToFinish = CpuMpData->CpuCount - 1;
414 while (mNumberToFinish > 0) {
418 DEBUG ((DEBUG_INFO,
"%a() done!\n", __func__));
427 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
428 &gEdkiiEndOfS3ResumeGuid,
535 IN BOOLEAN SingleThread,
537 IN UINTN TimeoutInMicroseconds,
538 IN VOID *ProcedureArgument OPTIONAL,
542 if (WaitEvent !=
NULL) {
543 return EFI_UNSUPPORTED;
551 TimeoutInMicroseconds,
634 IN UINTN TimeoutInMicroseconds,
635 IN VOID *ProcedureArgument OPTIONAL,
636 OUT BOOLEAN *Finished OPTIONAL
639 if (WaitEvent !=
NULL) {
640 return EFI_UNSUPPORTED;
647 TimeoutInMicroseconds,
683 IN BOOLEAN EnableOldBSP
724 IN UINT32 *HealthFlag OPTIONAL
755 &gEdkiiPeiShadowMicrocodePpiGuid,
758 (VOID **)&ShadowMicrocodePpi
760 if (EFI_ERROR (Status)) {
761 return EFI_UNSUPPORTED;
764 CpuCount = CpuMpData->CpuCount;
766 if (MicrocodeCpuId ==
NULL) {
767 return EFI_OUT_OF_RESOURCES;
770 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
771 MicrocodeCpuId[Index].ProcessorSignature = CpuMpData->CpuData[Index].ProcessorSignature;
772 MicrocodeCpuId[Index].PlatformId = CpuMpData->CpuData[Index].PlatformId;
775 Status = ShadowMicrocodePpi->ShadowMicrocode (
783 if (EFI_ERROR (Status)) {
784 return EFI_NOT_FOUND;
787 CpuMpData->MicrocodePatchAddress = (
UINTN)Buffer;
788 CpuMpData->MicrocodePatchRegionSize = BufferSize;
792 "%a: Required microcode patches have been loaded at 0x%lx, with size 0x%lx.\n",
794 CpuMpData->MicrocodePatchAddress,
795 CpuMpData->MicrocodePatchRegionSize
816 if (EFI_ERROR (Status)) {
842 PAGING_MODE PagingMode;
844 BOOLEAN Page5LevelSupport;
846 BOOLEAN Page1GSupport;
849 if (
sizeof (
UINTN) ==
sizeof (UINT64)) {
854 Page5LevelSupport = (Cr4.Bits.LA57 ?
TRUE :
FALSE);
859 Page1GSupport =
FALSE;
864 Page1GSupport =
TRUE;
871 if (Page5LevelSupport) {
872 PagingMode = Page1GSupport ? Paging5Level1GB : Paging5Level;
874 PagingMode = Page1GSupport ? Paging4Level1GB : Paging4Level;
877 PagingMode = PagingPae;
880 MapAttribute.Uint64 = 0;
883 PageTable =
AsmReadCr3 () & PAGING_4K_ADDRESS_MASK_64;
889 Status =
PageTableMap (&PageTable, PagingMode, 0, &BufferSize, BaseAddress, Length, &MapAttribute, &MapMask,
NULL);
890 if (Status == EFI_BUFFER_TOO_SMALL) {
900 Status =
PageTableMap (&PageTable, PagingMode, (VOID *)(
UINTN)Buffer, &BufferSize, BaseAddress, Length, &MapAttribute, &MapMask,
NULL);
VOID *EFIAPI BuildGuidDataHob(IN CONST EFI_GUID *Guid, IN VOID *Data, IN UINTN DataLength)
VOID *EFIAPI BuildGuidHob(IN CONST EFI_GUID *Guid, IN UINTN DataLength)
VOID *EFIAPI GetHobList(VOID)
VOID EFIAPI CpuPause(VOID)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
RETURN_STATUS EFIAPI PageTableMap(IN OUT UINTN *PageTable OPTIONAL, IN PAGING_MODE PagingMode, IN VOID *Buffer, IN OUT UINTN *BufferSize, IN UINT64 LinearAddress, IN UINT64 Length, IN IA32_MAP_ATTRIBUTE *Attribute, IN IA32_MAP_ATTRIBUTE *Mask, OUT BOOLEAN *IsModified OPTIONAL)
STATIC BOOLEAN EFIAPI ConfidentialComputingGuestHas(IN CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
EFI_STATUS EFIAPI PeiServicesNotifyPpi(IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList)
EFI_STATUS EFIAPI PeiServicesAllocatePages(IN EFI_MEMORY_TYPE MemoryType, IN UINTN Pages, OUT EFI_PHYSICAL_ADDRESS *Memory)
UINTN EFIAPI AsmReadCr3(VOID)
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
UINTN EFIAPI AsmWriteCr3(UINTN Cr3)
UINTN EFIAPI AsmReadCr4(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_MP_DATA * GetCpuMpDataFromGuidedHob(VOID)
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 EnableDisableApWorker(IN UINTN ProcessorNumber, IN BOOLEAN EnableAP, IN UINT32 *HealthFlag OPTIONAL)
EFI_STATUS EFIAPI MpInitLibEnableDisableAP(IN UINTN ProcessorNumber, IN BOOLEAN EnableAP, IN UINT32 *HealthFlag OPTIONAL)
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 CheckAndUpdateApsStatus(VOID)
EFI_STATUS EFIAPI MpInitLibSwitchBSP(IN UINTN ProcessorNumber, IN BOOLEAN EnableOldBSP)
CPU_MP_DATA * GetCpuMpData(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)
#define ALIGN_VALUE(Value, Alignment)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define MSR_IA32_APIC_BASE
#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 EFIAPI RelocateApLoop(IN OUT VOID *Buffer)
VOID PrepareApLoopCode(IN CPU_MP_DATA *CpuMpData)
EFI_STATUS SwitchBSPWorker(IN UINTN ProcessorNumber, IN BOOLEAN EnableOldBSP)
#define PcdGet32(TokenName)
EFI_STATUS EFIAPI NotifyOnEndOfS3Resume(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc, IN VOID *InvokePpi)
VOID RemoveNxprotection(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINTN Length)
UINTN GetWakeupBuffer(IN UINTN WakeupBufferSize)
VOID BuildMicrocodeCacheHob(IN CPU_MP_DATA *CpuMpData)
BOOLEAN CheckOverlapWithAllocatedBuffer(IN UINT64 WakeupBufferStart, IN UINT64 WakeupBufferEnd)
VOID AllocateApLoopCodeBuffer(IN UINTN Pages, IN OUT EFI_PHYSICAL_ADDRESS *Address)
UINTN AllocateCodeBuffer(IN UINTN BufferSize)
EFI_STATUS PlatformShadowMicrocode(IN OUT CPU_MP_DATA *CpuMpData)
UINTN GetSevEsAPMemory(VOID)
VOID(EFIAPI * EFI_AP_PROCEDURE)(IN OUT VOID *Buffer)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_SIZE_TO_PAGES(Size)
EFI_PHYSICAL_ADDRESS MemoryBaseAddress
EFI_HOB_MEMORY_ALLOCATION_HEADER AllocDescriptor
EFI_PHYSICAL_ADDRESS PhysicalStart
EFI_RESOURCE_TYPE ResourceType
EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
struct CPUID_EXTENDED_CPU_SIG_EDX::@750 Bits
struct MSR_IA32_APIC_BASE_REGISTER::@627 Bits