]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/MpInitLib: Sync BSP's local APIC timer settings to APs
authorJeff Fan <jeff.fan@intel.com>
Mon, 26 Dec 2016 08:44:24 +0000 (16:44 +0800)
committerJeff Fan <jeff.fan@intel.com>
Wed, 28 Dec 2016 07:38:02 +0000 (15:38 +0800)
If APs are waken up by INIT-SIPI-SIPI command, they will lose original local
APIC timer setting. As a result, the timer library instance based on local APIC
timer cannot work on APs function.

This fix is to save BSP's local APIC timer settings before waking up APs and
to sync to APs when APs wakeup by INIT-SIPI-SIPI command.

Setting BSP's current counter to AP's initial counter could make sure BSP and
APs have same counter value across BSP switching.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Kinney Michael D <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
UefiCpuPkg/Library/MpInitLib/MpLib.c
UefiCpuPkg/Library/MpInitLib/MpLib.h

index a21a980b58b1f48f5642608237c32fceb1f936c5..e5842ef505dc7864cc08c81f04f44b571de48d86 100644 (file)
@@ -109,6 +109,53 @@ SetApState (
   ReleaseSpinLock (&CpuData->ApLock);\r
 }\r
 \r
+/**\r
+  Save BSP's local APIC timer setting\r
+\r
+  @param[in] CpuMpData          Pointer to CPU MP Data\r
+**/\r
+VOID\r
+SaveLocalApicTimerSetting (\r
+  IN CPU_MP_DATA   *CpuMpData\r
+  )\r
+{\r
+  //\r
+  // Record the current local APIC timer setting of BSP\r
+  //\r
+  GetApicTimerState (\r
+    &CpuMpData->DivideValue,\r
+    &CpuMpData->PeriodicMode,\r
+    &CpuMpData->Vector\r
+    );\r
+  CpuMpData->CurrentTimerCount   = GetApicTimerCurrentCount ();\r
+  CpuMpData->TimerInterruptState = GetApicTimerInterruptState ();\r
+}\r
+\r
+/**\r
+  Sync local APIC timer setting from BSP to AP.\r
+\r
+  @param[in] CpuMpData          Pointer to CPU MP Data\r
+**/\r
+VOID\r
+SyncLocalApicTimerSetting (\r
+  IN CPU_MP_DATA   *CpuMpData\r
+  )\r
+{\r
+  //\r
+  // Sync local APIC timer setting from BSP to AP\r
+  //\r
+  InitializeApicTimer (\r
+    CpuMpData->DivideValue,\r
+    CpuMpData->CurrentTimerCount,\r
+    CpuMpData->PeriodicMode,\r
+    CpuMpData->Vector\r
+    );\r
+  //\r
+  // Disable AP's local APIC timer interrupt\r
+  //\r
+  DisableApicTimerInterrupt ();\r
+}\r
+\r
 /**\r
   Save the volatile registers required to be restored following INIT IPI.\r
 \r
@@ -488,7 +535,12 @@ ApWakeupFunction (
   //\r
   CpuMpData = ExchangeInfo->CpuMpData;\r
 \r
-  ProgramVirtualWireMode (); \r
+  //\r
+  // AP's local APIC settings will be lost after received INIT IPI\r
+  // We need to re-initialize them at here\r
+  //\r
+  ProgramVirtualWireMode ();\r
+  SyncLocalApicTimerSetting (CpuMpData);\r
 \r
   while (TRUE) {\r
     if (CpuMpData->InitFlag == ApInitConfig) {\r
@@ -736,6 +788,7 @@ WakeUpAP (
     ResetVectorRequired = TRUE;\r
     AllocateResetVector (CpuMpData);\r
     FillExchangeInfoData (CpuMpData);\r
+    SaveLocalApicTimerSetting (CpuMpData);\r
   } else if (CpuMpData->ApLoopMode == ApInMwaitLoop) {\r
     //\r
     // Get AP target C-state each time when waking up AP,\r
index b67ea9d11ff3cbac8f349942778f87c034a77826..7a272d78ec3376ae9157d499099753eb690bd055 100644 (file)
@@ -227,6 +227,12 @@ struct _CPU_MP_DATA {
   UINT16                         PmCodeSegment;\r
   CPU_AP_DATA                    *CpuData;\r
   volatile MP_CPU_EXCHANGE_INFO  *MpCpuExchangeInfo;\r
+\r
+  UINT32                         CurrentTimerCount;\r
+  UINTN                          DivideValue;\r
+  UINT8                          Vector;\r
+  BOOLEAN                        PeriodicMode;\r
+  BOOLEAN                        TimerInterruptState;\r
 };\r
 \r
 extern EFI_GUID mCpuInitMpLibHobGuid;\r