Revision: 19360
          http://sourceforge.net/p/edk2/code/19360
Author:   vanjeff
Date:     2015-12-18 05:48:45 +0000 (Fri, 18 Dec 2015)
Log Message:
-----------
UefiCpuPkg/CpuMpPei: Add GetApLoopMode() to get AP loop mode

Add GetApLoopMode() that will get PCD PcdCpuApLoopMode firstly. If it is
ApInMwaitLoop, we will check if MONITOR/MWAIT feature supported by CPUID. If
MONITOR/MWAIT feature is not supported, force AP loop mode to ApInHltLoop.

GetApLoopMode() also return the largest line size required.

(Sync patch r19343 from main trunk.)

Contributed-under: TianoCore Contribution Agreement 1.0
Cc: Feng Tian <[email protected]>
Cc: Michael Kinney <[email protected]>
Cc: Jordan Justen <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <[email protected]>
Signed-off-by: Michael Kinney <[email protected]>
Tested-by: Michael Kinney <[email protected]>
Reviewed-by: Michael Kinney <[email protected]>

Revision Links:
--------------
    http://sourceforge.net/p/edk2/code/19343

Modified Paths:
--------------
    branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.c
    branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.h
    branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.inf
    branches/UDK2015/UefiCpuPkg/Include/Register/Cpuid.h

Modified: branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.c
===================================================================
--- branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.c     2015-12-18 05:47:48 UTC 
(rev 19359)
+++ branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.c     2015-12-18 05:48:45 UTC 
(rev 19360)
@@ -118,6 +118,54 @@
 }
 
 /**
+  Get AP loop mode.
+
+  @param MonitorFilterSize  Returns the largest monitor-line size in bytes.
+
+  @return The AP loop mode.
+**/
+UINT8
+GetApLoopMode (
+  OUT UINT16     *MonitorFilterSize
+  )
+{
+  UINT8          ApLoopMode;
+  UINT32         RegEbx;
+  UINT32         RegEcx;
+  UINT32         RegEdx;
+
+  ASSERT (MonitorFilterSize != NULL);
+
+  ApLoopMode = PcdGet8 (PcdCpuApLoopMode);
+  ASSERT (ApLoopMode >= ApInHltLoop && ApLoopMode <= ApInRunLoop);
+  if (ApLoopMode == ApInMwaitLoop) {
+    AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, &RegEcx, NULL);
+    if ((RegEcx & BIT3) == 0) {
+      //
+      // If processor does not support MONITOR/MWAIT feature
+      // by CPUID.[EAX=01H]:ECX.BIT3, force AP in Hlt-loop mode
+      //
+      ApLoopMode = ApInHltLoop;
+    }
+  }
+
+  if (ApLoopMode == ApInHltLoop) {
+    *MonitorFilterSize = 0;
+  } else if (ApLoopMode == ApInRunLoop) {
+    *MonitorFilterSize = sizeof (UINT32);
+  } else if (ApLoopMode == ApInMwaitLoop) {
+    //
+    // CPUID.[EAX=05H]:EBX.BIT0-15: Largest monitor-line size in bytes
+    // CPUID.[EAX=05H].EDX: C-states supported using MWAIT
+    //
+    AsmCpuid (CPUID_MONITOR_MWAIT, NULL, &RegEbx, NULL, &RegEdx);
+    *MonitorFilterSize = RegEbx & 0xFFFF;
+  }
+
+  return ApLoopMode;
+}
+
+/**
   Get CPU MP Data pointer from the Guided HOB.
 
   @return  Pointer to Pointer to PEI CPU MP Data

Modified: branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.h
===================================================================
--- branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.h     2015-12-18 05:47:48 UTC 
(rev 19359)
+++ branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.h     2015-12-18 05:48:45 UTC 
(rev 19360)
@@ -50,6 +50,12 @@
   CpuStateDisabled
 } CPU_STATE;
 
+typedef enum {
+  ApInHltLoop   = 1,
+  ApInMwaitLoop = 2,
+  ApInRunLoop   = 3
+} AP_LOOP_MODE;
+
 //
 // AP reset code information
 //

Modified: branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.inf
===================================================================
--- branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.inf   2015-12-18 05:47:48 UTC 
(rev 19359)
+++ branches/UDK2015/UefiCpuPkg/CpuMpPei/CpuMpPei.inf   2015-12-18 05:48:45 UTC 
(rev 19360)
@@ -81,6 +81,7 @@
   gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize                      ## CONSUMES
   gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress            ## CONSUMES
   gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize         ## CONSUMES
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode                       ## CONSUMES
 
 [Depex]
   gEfiPeiMemoryDiscoveredPpiGuid

Modified: branches/UDK2015/UefiCpuPkg/Include/Register/Cpuid.h
===================================================================
--- branches/UDK2015/UefiCpuPkg/Include/Register/Cpuid.h        2015-12-18 
05:47:48 UTC (rev 19359)
+++ branches/UDK2015/UefiCpuPkg/Include/Register/Cpuid.h        2015-12-18 
05:48:45 UTC (rev 19360)
@@ -31,6 +31,8 @@
 
 #define CPUID_CACHE_PARAMS                      0x4
 
+#define CPUID_MONITOR_MWAIT                     0x5
+
 #define CPUID_EXTENDED_TOPOLOGY                 0xB
 #define   CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID  0x0
 #define   CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT      0x1


------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to