X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=UefiCpuPkg%2FLibrary%2FMpInitLib%2FPeiMpLib.c;h=e6e1b7c57d3d93b2b59d577ee46f0f2e66ed7136;hp=a7e1cdeac11ec4d3649663a0115e9c0aecd4d87f;hb=a234383c5bc28c5545b2988edc59f0cbdb123afd;hpb=ed66e0e3f48db7a97ca82b8b630b0cf83b1283fb diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c index a7e1cdeac1..e6e1b7c57d 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c @@ -1,7 +1,7 @@ /** @file MP initialize support functions for PEI phase. - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -13,20 +13,88 @@ **/ #include "MpLib.h" -#include #include +#include + +/** + S3 SMM Init Done notification function. + + @param PeiServices Indirect reference to the PEI Services Table. + @param NotifyDesc Address of the notification descriptor data structure. + @param InvokePpi Address of the PPI that was invoked. + + @retval EFI_SUCCESS The function completes successfully. + +**/ +EFI_STATUS +EFIAPI +NotifyOnS3SmmInitDonePpi ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc, + IN VOID *InvokePpi + ); + // -// Global PEI notify function descriptor on EndofPei event +// Global function // -GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mMpInitLibNotifyList = { - (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), - &gEfiEndOfPeiSignalPpiGuid, - CpuMpEndOfPeiCallback +EFI_PEI_NOTIFY_DESCRIPTOR mS3SmmInitDoneNotifyDesc = { + EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, + &gEdkiiS3SmmInitDoneGuid, + NotifyOnS3SmmInitDonePpi }; +/** + S3 SMM Init Done notification function. + + @param PeiServices Indirect reference to the PEI Services Table. + @param NotifyDesc Address of the notification descriptor data structure. + @param InvokePpi Address of the PPI that was invoked. + + @retval EFI_SUCCESS The function completes successfully. + +**/ +EFI_STATUS +EFIAPI +NotifyOnS3SmmInitDonePpi ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc, + IN VOID *InvokePpi + ) +{ + CPU_MP_DATA *CpuMpData; + + CpuMpData = GetCpuMpData (); + + // + // PiSmmCpuDxeSmm driver hardcode change the loop mode to HLT mode. + // So in this notify function, code need to check the current loop + // mode, if it is not HLT mode, code need to change loop mode back + // to the original mode. + // + if (CpuMpData->ApLoopMode != ApInHltLoop) { + CpuMpData->WakeUpByInitSipiSipi = TRUE; + } + + return EFI_SUCCESS; +} + + +/** + Enable Debug Agent to support source debugging on AP function. + +**/ +VOID +EnableDebugAgent ( + VOID + ) +{ +} + /** Get pointer to CPU MP Data structure. + For BSP, the pointer is retrieved from HOB. + For AP, the structure is just after IDT. @return The pointer to CPU MP Data structure. **/ @@ -35,10 +103,18 @@ GetCpuMpData ( VOID ) { - CPU_MP_DATA *CpuMpData; - - CpuMpData = GetCpuMpDataFromGuidedHob (); - ASSERT (CpuMpData != NULL); + CPU_MP_DATA *CpuMpData; + MSR_IA32_APIC_BASE_REGISTER ApicBaseMsr; + IA32_DESCRIPTOR Idtr; + + ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE); + if (ApicBaseMsr.Bits.BSP == 1) { + CpuMpData = GetCpuMpDataFromGuidedHob (); + ASSERT (CpuMpData != NULL); + } else { + AsmReadIdtr (&Idtr); + CpuMpData = (CPU_MP_DATA *) (Idtr.Base + Idtr.Limit + 1); + } return CpuMpData; } @@ -64,105 +140,6 @@ SaveCpuMpData ( ); } -/** - Get available system memory below 1MB by specified size. - - @param[in] PeiCpuMpData Pointer to PEI CPU MP Data -**/ -VOID -BackupAndPrepareWakeupBuffer( - IN CPU_MP_DATA *CpuMpData - ) -{ - CopyMem ( - (VOID *) CpuMpData->BackupBuffer, - (VOID *) CpuMpData->WakeupBuffer, - CpuMpData->BackupBufferSize - ); - CopyMem ( - (VOID *) CpuMpData->WakeupBuffer, - (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress, - CpuMpData->AddressMap.RendezvousFunnelSize - ); -} - -/** - Restore wakeup buffer data. - - @param[in] PeiCpuMpData Pointer to PEI CPU MP Data -**/ -VOID -RestoreWakeupBuffer( - IN CPU_MP_DATA *CpuMpData - ) -{ - CopyMem ( - (VOID *) CpuMpData->WakeupBuffer, - (VOID *) CpuMpData->BackupBuffer, - CpuMpData->BackupBufferSize - ); -} - -/** - Notify function on End Of PEI PPI. - - On S3 boot, this function will restore wakeup buffer data. - On normal boot, this function will flag wakeup buffer to be un-used type. - - @param[in] PeiServices The pointer to the PEI Services Table. - @param[in] NotifyDescriptor Address of the notification descriptor data structure. - @param[in] Ppi Address of the PPI that was installed. - - @retval EFI_SUCCESS When everything is OK. -**/ -EFI_STATUS -EFIAPI -CpuMpEndOfPeiCallback ( - IN EFI_PEI_SERVICES **PeiServices, - IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, - IN VOID *Ppi - ) -{ - EFI_STATUS Status; - EFI_BOOT_MODE BootMode; - CPU_MP_DATA *CpuMpData; - EFI_PEI_HOB_POINTERS Hob; - EFI_HOB_MEMORY_ALLOCATION *MemoryHob; - - DEBUG ((DEBUG_INFO, "PeiMpInitLib: CpuMpEndOfPeiCallback () invoked\n")); - - Status = PeiServicesGetBootMode (&BootMode); - ASSERT_EFI_ERROR (Status); - - CpuMpData = GetCpuMpData (); - if (BootMode != BOOT_ON_S3_RESUME) { - // - // Get the HOB list for processing - // - Hob.Raw = GetHobList (); - // - // Collect memory ranges - // - while (!END_OF_HOB_LIST (Hob)) { - if (Hob.Header->HobType == EFI_HOB_TYPE_MEMORY_ALLOCATION) { - MemoryHob = Hob.MemoryAllocation; - if (MemoryHob->AllocDescriptor.MemoryBaseAddress == CpuMpData->WakeupBuffer) { - // - // Flag this HOB type to un-used - // - GET_HOB_TYPE (Hob) = EFI_HOB_TYPE_UNUSED; - break; - } - } - Hob.Raw = GET_NEXT_HOB (Hob); - } - } else { - CpuMpData->EndOfPeiFlag = TRUE; - RestoreWakeupBuffer (CpuMpData); - } - return EFI_SUCCESS; -} - /** Check if AP wakeup buffer is overlapped with existing allocated buffer. @@ -174,15 +151,15 @@ CpuMpEndOfPeiCallback ( **/ BOOLEAN CheckOverlapWithAllocatedBuffer ( - IN UINTN WakeupBufferStart, - IN UINTN WakeupBufferEnd + IN UINT64 WakeupBufferStart, + IN UINT64 WakeupBufferEnd ) { EFI_PEI_HOB_POINTERS Hob; EFI_HOB_MEMORY_ALLOCATION *MemoryHob; BOOLEAN Overlapped; - UINTN MemoryStart; - UINTN MemoryEnd; + UINT64 MemoryStart; + UINT64 MemoryEnd; Overlapped = FALSE; // @@ -195,9 +172,8 @@ CheckOverlapWithAllocatedBuffer ( while (!END_OF_HOB_LIST (Hob)) { if (Hob.Header->HobType == EFI_HOB_TYPE_MEMORY_ALLOCATION) { MemoryHob = Hob.MemoryAllocation; - MemoryStart = (UINTN) MemoryHob->AllocDescriptor.MemoryBaseAddress; - MemoryEnd = (UINTN) (MemoryHob->AllocDescriptor.MemoryBaseAddress + - MemoryHob->AllocDescriptor.MemoryLength); + MemoryStart = MemoryHob->AllocDescriptor.MemoryBaseAddress; + MemoryEnd = MemoryHob->AllocDescriptor.MemoryBaseAddress + MemoryHob->AllocDescriptor.MemoryLength; if (!((WakeupBufferStart >= MemoryEnd) || (WakeupBufferEnd <= MemoryStart))) { Overlapped = TRUE; break; @@ -222,8 +198,8 @@ GetWakeupBuffer ( ) { EFI_PEI_HOB_POINTERS Hob; - UINTN WakeupBufferStart; - UINTN WakeupBufferEnd; + UINT64 WakeupBufferStart; + UINT64 WakeupBufferEnd; WakeupBufferSize = (WakeupBufferSize + SIZE_4KB - 1) & ~(SIZE_4KB - 1); @@ -248,7 +224,7 @@ GetWakeupBuffer ( // // Need memory under 1MB to be collected here // - WakeupBufferEnd = (UINTN) (Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength); + WakeupBufferEnd = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength; if (WakeupBufferEnd > BASE_1MB) { // // Wakeup buffer should be under 1MB @@ -273,15 +249,7 @@ GetWakeupBuffer ( } DEBUG ((DEBUG_INFO, "WakeupBufferStart = %x, WakeupBufferSize = %x\n", WakeupBufferStart, WakeupBufferSize)); - // - // Create a memory allocation HOB. - // - BuildMemoryAllocationHob ( - WakeupBufferStart, - WakeupBufferSize, - EfiBootServicesData - ); - return WakeupBufferStart; + return (UINTN)WakeupBufferStart; } } } @@ -295,45 +263,37 @@ GetWakeupBuffer ( } /** - Allocate reset vector buffer. + Get available EfiBootServicesCode memory below 4GB by specified size. + + This buffer is required to safely transfer AP from real address mode to + protected mode or long mode, due to the fact that the buffer returned by + GetWakeupBuffer() may be marked as non-executable. - @param[in, out] CpuMpData The pointer to CPU MP Data structure. + @param[in] BufferSize Wakeup transition buffer size. + + @retval other Return wakeup transition buffer address below 4GB. + @retval 0 Cannot find free memory below 4GB. **/ -VOID -AllocateResetVector ( - IN OUT CPU_MP_DATA *CpuMpData +UINTN +GetModeTransitionBuffer ( + IN UINTN BufferSize ) { - UINTN ApResetVectorSize; - - if (CpuMpData->WakeupBuffer == (UINTN) -1) { - ApResetVectorSize = CpuMpData->AddressMap.RendezvousFunnelSize + - sizeof (MP_CPU_EXCHANGE_INFO); - - CpuMpData->WakeupBuffer = GetWakeupBuffer (ApResetVectorSize); - CpuMpData->MpCpuExchangeInfo = (MP_CPU_EXCHANGE_INFO *) (UINTN) - (CpuMpData->WakeupBuffer + CpuMpData->AddressMap.RendezvousFunnelSize); - BackupAndPrepareWakeupBuffer (CpuMpData); - } - - if (CpuMpData->EndOfPeiFlag) { - BackupAndPrepareWakeupBuffer (CpuMpData); - } + // + // PEI phase doesn't need to do such transition. So simply return 0. + // + return 0; } /** - Free AP reset vector buffer. + Checks APs status and updates APs status if needed. - @param[in] CpuMpData The pointer to CPU MP Data structure. **/ VOID -FreeResetVector ( - IN CPU_MP_DATA *CpuMpData +CheckAndUpdateApsStatus ( + VOID ) { - if (CpuMpData->EndOfPeiFlag) { - RestoreWakeupBuffer (CpuMpData); - } } /** @@ -346,13 +306,14 @@ InitMpGlobalData ( IN CPU_MP_DATA *CpuMpData ) { - EFI_STATUS Status; + EFI_STATUS Status; SaveCpuMpData (CpuMpData); - // - // Register an event for EndOfPei - // - Status = PeiServicesNotifyPpi (&mMpInitLibNotifyList); + + /// + /// Install Notify + /// + Status = PeiServicesNotifyPpi (&mS3SmmInitDoneNotifyDesc); ASSERT_EFI_ERROR (Status); } @@ -383,7 +344,7 @@ InitMpGlobalData ( EFI_EVENT is defined in CreateEvent() in the Unified Extensible Firmware Interface Specification. - @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for + @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for APs to return from Procedure, either for blocking or non-blocking mode. Zero means infinity. If the timeout expires before @@ -442,7 +403,18 @@ MpInitLibStartupAllAPs ( OUT UINTN **FailedCpuList OPTIONAL ) { - return EFI_UNSUPPORTED; + if (WaitEvent != NULL) { + return EFI_UNSUPPORTED; + } + + return StartupAllAPsWorker ( + Procedure, + SingleThread, + NULL, + TimeoutInMicroseconds, + ProcedureArgument, + FailedCpuList + ); } /** @@ -472,7 +444,7 @@ MpInitLibStartupAllAPs ( EFI_EVENT is defined in CreateEvent() in the Unified Extensible Firmware Interface Specification. - @param[in] TimeoutInMicrosecsond Indicates the time limit in microseconds for + @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for this AP to finish this Procedure, either for blocking or non-blocking mode. Zero means infinity. If the timeout expires before @@ -527,7 +499,18 @@ MpInitLibStartupThisAP ( OUT BOOLEAN *Finished OPTIONAL ) { - return EFI_UNSUPPORTED; + if (WaitEvent != NULL) { + return EFI_UNSUPPORTED; + } + + return StartupThisAPWorker ( + Procedure, + ProcessorNumber, + NULL, + TimeoutInMicroseconds, + ProcedureArgument, + Finished + ); } /** @@ -563,7 +546,7 @@ MpInitLibSwitchBSP ( IN BOOLEAN EnableOldBSP ) { - return EFI_UNSUPPORTED; + return SwitchBSPWorker (ProcessorNumber, EnableOldBSP); } /** @@ -604,7 +587,7 @@ MpInitLibEnableDisableAP ( IN UINT32 *HealthFlag OPTIONAL ) { - return EFI_UNSUPPORTED; + return EnableDisableApWorker (ProcessorNumber, EnableAP, HealthFlag); }