]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/CpuMpPei: Fix potential AP mwait wakeup issue
authorJeff Fan <jeff.fan@intel.com>
Thu, 31 Mar 2016 11:15:05 +0000 (19:15 +0800)
committerJeff Fan <jeff.fan@intel.com>
Mon, 11 Apr 2016 06:15:45 +0000 (14:15 +0800)
If ApLoopMode is set to ApInMwaitLoop, AP will be placed into C-State by mwait
instruction. BSP will wakeup AP by write start-up signal in monitor address.
However, AP maybe waken by SMI/NMI/MCE and other condition. On this case, AP
will check if BSP wants to wakeup itself really. If not, AP will continue to
execute mwait to C-State.

One potential issue: BSP may not recognize AP was wakeup from C-State by other
event and BSP still writes start-up signal to wakeup AP. But AP does not aware
it and still execute mwait instruction to C-State. So, AP cannot be wakeup on
this case.

This fix is let AP to clear start-up signal when it really is wakeup to execute
AP function. And BSP will write start-up signal till AP clears it.

Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Feng Tian <feng.tian@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/CpuMpPei/CpuMpPei.c

index f38b3961961c3a2288b3b08354610e0cba05aef2..ef1c2812e2bf7f0ca620ecde61102bdd0e9592ad 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   CPU PEI Module installs CPU Multiple Processor PPI.\r
 \r
-  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2015 - 2016, 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
@@ -355,10 +355,6 @@ ApCFunction (
       }\r
     }\r
     ApStartupSignalBuffer = PeiCpuMpData->CpuData[ProcessorNumber].StartupApSignal;\r
-    //\r
-    // Clear AP start-up signal\r
-    //\r
-    *ApStartupSignalBuffer = 0;\r
     while (TRUE) {\r
       DisableInterrupts ();\r
       if (PeiCpuMpData->ApLoopMode == ApInMwaitLoop) {\r
@@ -387,12 +383,44 @@ ApCFunction (
       // otherwise place AP in loop again\r
       //\r
       if (*ApStartupSignalBuffer == WAKEUP_AP_SIGNAL) {\r
+        //\r
+        // Clear AP start-up signal when AP waken up\r
+        //\r
+        InterlockedCompareExchange32 (\r
+          (UINT32 *)ApStartupSignalBuffer,\r
+          WAKEUP_AP_SIGNAL,\r
+          0\r
+        );\r
         break;\r
       }\r
     }\r
   }\r
 }\r
 \r
+/**\r
+  Write AP start-up signal to wakeup AP.\r
+\r
+  @param ApStartupSignalBuffer  Pointer to AP wakeup signal\r
+**/\r
+VOID\r
+WriteStartupSignal (\r
+  IN volatile UINT32        *ApStartupSignalBuffer\r
+  )\r
+{\r
+  *ApStartupSignalBuffer = WAKEUP_AP_SIGNAL;\r
+  //\r
+  // If AP is waken up, StartupApSignal should be cleared.\r
+  // Otherwise, write StartupApSignal again till AP waken up.\r
+  //\r
+  while (InterlockedCompareExchange32 (\r
+          (UINT32 *)ApStartupSignalBuffer,\r
+          WAKEUP_AP_SIGNAL,\r
+          WAKEUP_AP_SIGNAL\r
+          ) != 0) {\r
+    CpuPause ();\r
+  }\r
+}\r
+\r
 /**\r
   This function will be called by BSP to wakeup AP.\r
 \r
@@ -462,11 +490,11 @@ WakeUpAP (
     if (Broadcast) {\r
       for (Index = 0; Index < PeiCpuMpData->CpuCount; Index++) {\r
         if (Index != PeiCpuMpData->BspNumber) {\r
-          *(PeiCpuMpData->CpuData[Index].StartupApSignal) = WAKEUP_AP_SIGNAL;\r
+          WriteStartupSignal (PeiCpuMpData->CpuData[Index].StartupApSignal);\r
         }\r
       }\r
     } else {\r
-      *(PeiCpuMpData->CpuData[ProcessorNumber].StartupApSignal) = WAKEUP_AP_SIGNAL;\r
+      WriteStartupSignal (PeiCpuMpData->CpuData[ProcessorNumber].StartupApSignal);\r
     }\r
   } else {\r
     ASSERT (FALSE);\r