]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/MpInitLib/MpLib.h
UefiCpuPkg/MpInitLib: Remove Executable attribute from MpLib.h
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / MpLib.h
index 84ae24f88d774537b930a5e54dcaa6e1decbdf67..a8ca03efb8e3d8e75363dd66ad77fcb740b1c8ed 100644 (file)
@@ -1,14 +1,10 @@
 /** @file\r
   Common header file for MP Initialize Library.\r
 \r
-  Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
+  Copyright (c) 2016 - 2020, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2020, AMD Inc. All rights reserved.<BR>\r
 \r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 \r
 #include <PiPei.h>\r
 \r
-#include <Register/Cpuid.h>\r
-#include <Register/Msr.h>\r
-#include <Register/LocalApic.h>\r
-#include <Register/Microcode.h>\r
+#include <Register/Intel/Cpuid.h>\r
+#include <Register/Amd/Cpuid.h>\r
+#include <Register/Intel/Msr.h>\r
+#include <Register/Intel/LocalApic.h>\r
+#include <Register/Intel/Microcode.h>\r
 \r
 #include <Library/MpInitLib.h>\r
 #include <Library/BaseLib.h>\r
@@ -34,6 +31,9 @@
 #include <Library/SynchronizationLib.h>\r
 #include <Library/MtrrLib.h>\r
 #include <Library/HobLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+#include <Guid/MicrocodePatchHob.h>\r
 \r
 #define WAKEUP_AP_SIGNAL SIGNATURE_32 ('S', 'T', 'A', 'P')\r
 \r
 #define CPU_SWITCH_STATE_STORED 1\r
 #define CPU_SWITCH_STATE_LOADED 2\r
 \r
+//\r
+// Default maximum number of entries to store the microcode patches information\r
+//\r
+#define DEFAULT_MAX_MICROCODE_PATCH_NUM 8\r
+\r
+//\r
+// Data structure for microcode patch information\r
+//\r
+typedef struct {\r
+  UINTN    Address;\r
+  UINTN    Size;\r
+} MICROCODE_PATCH_INFO;\r
+\r
 //\r
 // CPU exchange information for switch BSP\r
 //\r
@@ -81,6 +94,10 @@ typedef enum {
 //\r
 // AP state\r
 //\r
+// The state transitions for an AP when it process a procedure are:\r
+//  Idle ----> Ready ----> Busy ----> Idle\r
+//       [BSP]       [AP]       [AP]\r
+//\r
 typedef enum {\r
   CpuStateIdle,\r
   CpuStateReady,\r
@@ -102,6 +119,9 @@ typedef struct {
   UINTN                          Dr3;\r
   UINTN                          Dr6;\r
   UINTN                          Dr7;\r
+  IA32_DESCRIPTOR                Gdtr;\r
+  IA32_DESCRIPTOR                Idtr;\r
+  UINT16                         Tr;\r
 } CPU_VOLATILE_REGISTERS;\r
 \r
 //\r
@@ -121,6 +141,9 @@ typedef struct {
   UINT64                         CurrentTime;\r
   UINT64                         TotalTime;\r
   EFI_EVENT                      WaitEvent;\r
+  UINT32                         ProcessorSignature;\r
+  UINT8                          PlatformId;\r
+  UINT64                         MicrocodeEntryAddr;\r
 } CPU_AP_DATA;\r
 \r
 //\r
@@ -149,6 +172,7 @@ typedef struct {
   UINTN             RendezvousFunnelSize;\r
   UINT8             *RelocateApLoopFuncAddress;\r
   UINTN             RelocateApLoopFuncSize;\r
+  UINTN             ModeTransitionOffset;\r
 } MP_ASSEMBLY_ADDRESS_MAP;\r
 \r
 typedef struct _CPU_MP_DATA  CPU_MP_DATA;\r
@@ -169,15 +193,24 @@ typedef struct {
   IA32_DESCRIPTOR       IdtrProfile;\r
   UINTN                 BufferStart;\r
   UINTN                 ModeOffset;\r
-  UINTN                 NumApsExecuting;\r
+  UINTN                 ApIndex;\r
   UINTN                 CodeSegment;\r
   UINTN                 DataSegment;\r
   UINTN                 EnableExecuteDisable;\r
   UINTN                 Cr3;\r
   UINTN                 InitFlag;\r
   CPU_INFO_IN_HOB       *CpuInfo;\r
+  UINTN                 NumApsExecuting;\r
   CPU_MP_DATA           *CpuMpData;\r
   UINTN                 InitializeFloatingPointUnitsAddress;\r
+  UINT32                ModeTransitionMemory;\r
+  UINT16                ModeTransitionSegment;\r
+  UINT32                ModeHighMemory;\r
+  UINT16                ModeHighSegment;\r
+  //\r
+  // Enable5LevelPaging indicates whether 5-level paging is enabled in long mode.\r
+  //\r
+  BOOLEAN               Enable5LevelPaging;\r
 } MP_CPU_EXCHANGE_INFO;\r
 \r
 #pragma pack()\r
@@ -199,12 +232,12 @@ struct _CPU_MP_DATA {
   UINTN                          CpuApStackSize;\r
   MP_ASSEMBLY_ADDRESS_MAP        AddressMap;\r
   UINTN                          WakeupBuffer;\r
+  UINTN                          WakeupBufferHigh;\r
   UINTN                          BackupBuffer;\r
   UINTN                          BackupBufferSize;\r
 \r
-  volatile UINT32                StartCount;\r
   volatile UINT32                FinishedCount;\r
-  volatile UINT32                RunningCount;\r
+  UINT32                         RunningCount;\r
   BOOLEAN                        SingleThread;\r
   EFI_AP_PROCEDURE               Procedure;\r
   VOID                           *ProcArguments;\r
@@ -216,7 +249,6 @@ struct _CPU_MP_DATA {
   UINTN                          **FailedCpuList;\r
 \r
   AP_INIT_STATE                  InitFlag;\r
-  BOOLEAN                        X2ApicEnable;\r
   BOOLEAN                        SwitchBspFlag;\r
   UINTN                          NewBspNumber;\r
   CPU_EXCHANGE_ROLE_INFO         BSPInfo;\r
@@ -235,6 +267,15 @@ struct _CPU_MP_DATA {
   BOOLEAN                        TimerInterruptState;\r
   UINT64                         MicrocodePatchAddress;\r
   UINT64                         MicrocodePatchRegionSize;\r
+\r
+  //\r
+  // Whether need to use Init-Sipi-Sipi to wake up the APs.\r
+  // Two cases need to set this value to TRUE. One is in HLT\r
+  // loop mode, the other is resume from S3 which loop mode\r
+  // will be hardcode change to HLT mode by PiSmmCpuDxeSmm\r
+  // driver.\r
+  //\r
+  BOOLEAN                        WakeUpByInitSipiSipi;\r
 };\r
 \r
 extern EFI_GUID mCpuInitMpLibHobGuid;\r
@@ -325,6 +366,23 @@ GetWakeupBuffer (
   IN UINTN                WakeupBufferSize\r
   );\r
 \r
+/**\r
+  Get available EfiBootServicesCode memory below 4GB by specified size.\r
+\r
+  This buffer is required to safely transfer AP from real address mode to\r
+  protected mode or long mode, due to the fact that the buffer returned by\r
+  GetWakeupBuffer() may be marked as non-executable.\r
+\r
+  @param[in] BufferSize   Wakeup transition buffer size.\r
+\r
+  @retval other   Return wakeup transition buffer address below 4GB.\r
+  @retval 0       Cannot find free memory below 4GB.\r
+**/\r
+UINTN\r
+GetModeTransitionBuffer (\r
+  IN UINTN                BufferSize\r
+  );\r
+\r
 /**\r
   This function will be called by BSP to wakeup AP.\r
 \r
@@ -334,6 +392,7 @@ GetWakeupBuffer (
   @param[in] ProcessorNumber    The handle number of specified processor\r
   @param[in] Procedure          The function to be invoked by AP\r
   @param[in] ProcedureArgument  The argument to be passed into AP function\r
+  @param[in] WakeUpDisabledAps  Whether need to wake up disabled APs in broadcast mode.\r
 **/\r
 VOID\r
 WakeUpAP (\r
@@ -341,7 +400,8 @@ WakeUpAP (
   IN BOOLEAN                   Broadcast,\r
   IN UINTN                     ProcessorNumber,\r
   IN EFI_AP_PROCEDURE          Procedure,              OPTIONAL\r
-  IN VOID                      *ProcedureArgument      OPTIONAL\r
+  IN VOID                      *ProcedureArgument,     OPTIONAL\r
+  IN BOOLEAN                   WakeUpDisabledAps       OPTIONAL\r
   );\r
 \r
 /**\r
@@ -365,6 +425,7 @@ InitMpGlobalData (
                                       number.  If FALSE, then all the enabled APs\r
                                       execute the function specified by Procedure\r
                                       simultaneously.\r
+  @param[in]  ExcludeBsp              Whether let BSP also trig this task.\r
   @param[in]  WaitEvent               The event created by the caller with CreateEvent()\r
                                       service.\r
   @param[in]  TimeoutInMicroseconds   Indicates the time limit in microseconds for\r
@@ -386,9 +447,10 @@ InitMpGlobalData (
 \r
 **/\r
 EFI_STATUS\r
-StartupAllAPsWorker (\r
+StartupAllCPUsWorker (\r
   IN  EFI_AP_PROCEDURE          Procedure,\r
   IN  BOOLEAN                   SingleThread,\r
+  IN  BOOLEAN                   ExcludeBsp,\r
   IN  EFI_EVENT                 WaitEvent               OPTIONAL,\r
   IN  UINTN                     TimeoutInMicroseconds,\r
   IN  VOID                      *ProcedureArgument      OPTIONAL,\r
@@ -436,7 +498,7 @@ StartupThisAPWorker (
                                enabled AP. Otherwise, it will be disabled.\r
 \r
   @retval EFI_SUCCESS          BSP successfully switched.\r
-  @retval others               Failed to switch BSP. \r
+  @retval others               Failed to switch BSP.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -519,11 +581,46 @@ CheckAndUpdateApsStatus (
 /**\r
   Detect whether specified processor can find matching microcode patch and load it.\r
 \r
-  @param[in]  CpuMpData  The pointer to CPU MP Data structure.\r
+  @param[in]  CpuMpData        The pointer to CPU MP Data structure.\r
+  @param[in]  ProcessorNumber  The handle number of the processor. The range is\r
+                               from 0 to the total number of logical processors\r
+                               minus 1.\r
 **/\r
 VOID\r
 MicrocodeDetect (\r
-  IN CPU_MP_DATA             *CpuMpData\r
+  IN CPU_MP_DATA             *CpuMpData,\r
+  IN UINTN                   ProcessorNumber\r
+  );\r
+\r
+/**\r
+  Shadow the required microcode patches data into memory.\r
+\r
+  @param[in, out]  CpuMpData    The pointer to CPU MP Data structure.\r
+**/\r
+VOID\r
+ShadowMicrocodeUpdatePatch (\r
+  IN OUT CPU_MP_DATA             *CpuMpData\r
+  );\r
+\r
+/**\r
+  Get the cached microcode patch base address and size from the microcode patch\r
+  information cache HOB.\r
+\r
+  @param[out] Address       Base address of the microcode patches data.\r
+                            It will be updated if the microcode patch\r
+                            information cache HOB is found.\r
+  @param[out] RegionSize    Size of the microcode patches data.\r
+                            It will be updated if the microcode patch\r
+                            information cache HOB is found.\r
+\r
+  @retval  TRUE     The microcode patch information cache HOB is found.\r
+  @retval  FALSE    The microcode patch information cache HOB is not found.\r
+\r
+**/\r
+BOOLEAN\r
+GetMicrocodePatchInfoFromHob (\r
+  UINT64                         *Address,\r
+  UINT64                         *RegionSize\r
   );\r
 \r
 /**\r
@@ -546,5 +643,36 @@ EnableDebugAgent (
   VOID\r
   );\r
 \r
+/**\r
+  Find the current Processor number by APIC ID.\r
+\r
+  @param[in]  CpuMpData         Pointer to PEI CPU MP Data\r
+  @param[out] ProcessorNumber   Return the pocessor number found\r
+\r
+  @retval EFI_SUCCESS          ProcessorNumber is found and returned.\r
+  @retval EFI_NOT_FOUND        ProcessorNumber is not found.\r
+**/\r
+EFI_STATUS\r
+GetProcessorNumber (\r
+  IN CPU_MP_DATA               *CpuMpData,\r
+  OUT UINTN                    *ProcessorNumber\r
+  );\r
+\r
+/**\r
+  This funtion will try to invoke platform specific microcode shadow logic to\r
+  relocate microcode update patches into memory.\r
+\r
+  @param[in, out] CpuMpData  The pointer to CPU MP Data structure.\r
+\r
+  @retval EFI_SUCCESS              Shadow microcode success.\r
+  @retval EFI_OUT_OF_RESOURCES     No enough resource to complete the operation.\r
+  @retval EFI_UNSUPPORTED          Can't find platform specific microcode shadow\r
+                                   PPI/Protocol.\r
+**/\r
+EFI_STATUS\r
+PlatformShadowMicrocode (\r
+  IN OUT CPU_MP_DATA             *CpuMpData\r
+  );\r
+\r
 #endif\r
 \r