]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg CpuCommonFeaturesLib: Enable Ppin feature.
authorEric Dong <eric.dong@intel.com>
Fri, 14 Jul 2017 02:22:04 +0000 (10:22 +0800)
committerEric Dong <eric.dong@intel.com>
Thu, 20 Jul 2017 06:11:15 +0000 (14:11 +0800)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Jeff Fan <jeff.fan@intel.com>
UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h
UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c
UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf
UefiCpuPkg/Library/CpuCommonFeaturesLib/Ppin.c [new file with mode: 0644]

index 9c6e0b4e674165e3afb98b8286b4013292d011ee..c03e5ab0183f93ec6e5ae0f3fe4a38a64245f5d0 100644 (file)
@@ -854,4 +854,59 @@ FeatureControlGetConfigData (
   IN UINTN               NumberOfProcessors\r
   );\r
 \r
+/**\r
+  Detects if Protected Processor Inventory Number feature supported on current \r
+  processor.\r
+\r
+  @param[in]  ProcessorNumber  The index of the CPU executing this function.\r
+  @param[in]  CpuInfo          A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
+                               structure for the CPU executing this function.\r
+  @param[in]  ConfigData       A pointer to the configuration buffer returned\r
+                               by CPU_FEATURE_GET_CONFIG_DATA.  NULL if\r
+                               CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
+                               RegisterCpuFeature().\r
+\r
+  @retval TRUE     Enhanced Intel SpeedStep feature is supported.\r
+  @retval FALSE    Enhanced Intel SpeedStep feature is not supported.\r
+\r
+  @note This service could be called by BSP/APs.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+PpinSupport (\r
+  IN UINTN                             ProcessorNumber,\r
+  IN REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo,\r
+  IN VOID                              *ConfigData  OPTIONAL\r
+  );\r
+\r
+/**\r
+  Initializes Protected Processor Inventory Number feature to specific state.\r
+\r
+  @param[in]  ProcessorNumber  The index of the CPU executing this function.\r
+  @param[in]  CpuInfo          A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
+                               structure for the CPU executing this function.\r
+  @param[in]  ConfigData       A pointer to the configuration buffer returned\r
+                               by CPU_FEATURE_GET_CONFIG_DATA.  NULL if\r
+                               CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
+                               RegisterCpuFeature().\r
+  @param[in]  State            If TRUE, then the Protected Processor Inventory \r
+                               Number feature must be enabled.\r
+                               If FALSE, then the Protected Processor Inventory \r
+                               Number feature must be disabled.\r
+\r
+  @retval RETURN_SUCCESS       Protected Processor Inventory Number feature is \r
+                               initialized.\r
+  @retval RETURN_DEVICE_ERROR  Device can't change state because it has been \r
+                               locked.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PpinInitialize (\r
+  IN UINTN                             ProcessorNumber,\r
+  IN REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo,\r
+  IN VOID                              *ConfigData,  OPTIONAL\r
+  IN BOOLEAN                           State\r
+  );\r
+\r
 #endif\r
index 2bd32ab8a6bbb6e17d02405607bfe7e6a13624c0..b88b7d1e6d008813ed73c5f188edfd68c3e03151 100644 (file)
@@ -206,6 +206,17 @@ CpuCommonFeaturesLibConstructor (
                );\r
     ASSERT_EFI_ERROR (Status);\r
   }\r
+  if (IsCpuFeatureSupported (CPU_FEATURE_PPIN)) {\r
+    Status = RegisterCpuFeature (\r
+               "PPIN",\r
+               NULL,\r
+               PpinSupport,\r
+               PpinInitialize,\r
+               CPU_FEATURE_PPIN,\r
+               CPU_FEATURE_END\r
+               );\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
 \r
   return RETURN_SUCCESS;\r
 }\r
index e68936be25b7ea39c989eae886d5764875b9a8fb..202d5608b867096883723ae64b1a3623afdb79d3 100644 (file)
@@ -47,6 +47,7 @@
   MonitorMwait.c\r
   PendingBreak.c\r
   X2Apic.c\r
+  Ppin.c\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/Ppin.c b/UefiCpuPkg/Library/CpuCommonFeaturesLib/Ppin.c
new file mode 100644 (file)
index 0000000..146c4cf
--- /dev/null
@@ -0,0 +1,114 @@
+/** @file\r
+  Protected Processor Inventory Number(PPIN) feature.\r
+\r
+  Copyright (c) 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
+\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
+\r
+**/\r
+\r
+#include "CpuCommonFeatures.h"\r
+\r
+/**\r
+  Detects if Protected Processor Inventory Number feature supported on current \r
+  processor.\r
+\r
+  @param[in]  ProcessorNumber  The index of the CPU executing this function.\r
+  @param[in]  CpuInfo          A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
+                               structure for the CPU executing this function.\r
+  @param[in]  ConfigData       A pointer to the configuration buffer returned\r
+                               by CPU_FEATURE_GET_CONFIG_DATA.  NULL if\r
+                               CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
+                               RegisterCpuFeature().\r
+\r
+  @retval TRUE     Enhanced Intel SpeedStep feature is supported.\r
+  @retval FALSE    Enhanced Intel SpeedStep feature is not supported.\r
+\r
+  @note This service could be called by BSP/APs.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+PpinSupport (\r
+  IN UINTN                             ProcessorNumber,\r
+  IN REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo,\r
+  IN VOID                              *ConfigData  OPTIONAL\r
+  )\r
+{\r
+  MSR_IVY_BRIDGE_PLATFORM_INFO_1_REGISTER    PlatformInfo;\r
+\r
+  if ((CpuInfo->DisplayFamily == 0x06) && \r
+      ((CpuInfo->DisplayModel == 0x3E) ||      // Xeon E5 V2\r
+       (CpuInfo->DisplayModel == 0x56) ||      // Xeon Processor D Product\r
+       (CpuInfo->DisplayModel == 0x4F) ||      // Xeon E5 v4, E7 v4\r
+       (CpuInfo->DisplayModel == 0x55) ||      // Xeon Processor Scalable\r
+       (CpuInfo->DisplayModel == 0x57) ||      // Xeon Phi processor 3200, 5200, 7200 series.\r
+       (CpuInfo->DisplayModel == 0x85)         // Future Xeon phi processor \r
+     )) {\r
+    //\r
+    // Check whether platform support this feature.\r
+    //\r
+    PlatformInfo.Uint64 = AsmReadMsr64 (MSR_IVY_BRIDGE_PLATFORM_INFO_1);\r
+    return (PlatformInfo.Bits.PPIN_CAP != 0);\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Initializes Protected Processor Inventory Number feature to specific state.\r
+\r
+  @param[in]  ProcessorNumber  The index of the CPU executing this function.\r
+  @param[in]  CpuInfo          A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
+                               structure for the CPU executing this function.\r
+  @param[in]  ConfigData       A pointer to the configuration buffer returned\r
+                               by CPU_FEATURE_GET_CONFIG_DATA.  NULL if\r
+                               CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
+                               RegisterCpuFeature().\r
+  @param[in]  State            If TRUE, then the Protected Processor Inventory \r
+                               Number feature must be enabled.\r
+                               If FALSE, then the Protected Processor Inventory \r
+                               Number feature must be disabled.\r
+\r
+  @retval RETURN_SUCCESS       Protected Processor Inventory Number feature is \r
+                               initialized.\r
+  @retval RETURN_DEVICE_ERROR  Device can't change state because it has been \r
+                               locked.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PpinInitialize (\r
+  IN UINTN                             ProcessorNumber,\r
+  IN REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo,\r
+  IN VOID                              *ConfigData,  OPTIONAL\r
+  IN BOOLEAN                           State\r
+  )\r
+{\r
+  MSR_IVY_BRIDGE_PPIN_CTL_REGISTER     MsrPpinCtrl;\r
+\r
+  //\r
+  // Check whether device already lock this register.\r
+  // If already locked, just base on the request state and\r
+  // the current state to return the status.\r
+  //\r
+  MsrPpinCtrl.Uint64 = AsmReadMsr64 (MSR_IVY_BRIDGE_PPIN_CTL);\r
+  if (MsrPpinCtrl.Bits.LockOut != 0) {\r
+    return MsrPpinCtrl.Bits.Enable_PPIN == State ? RETURN_SUCCESS : RETURN_DEVICE_ERROR;\r
+  }\r
+\r
+  CPU_REGISTER_TABLE_WRITE_FIELD (\r
+    ProcessorNumber,\r
+    Msr,\r
+    MSR_IVY_BRIDGE_PPIN_CTL,\r
+    MSR_IVY_BRIDGE_PPIN_CTL_REGISTER,\r
+    Bits.Enable_PPIN,\r
+    (State) ? 1 : 0\r
+    );\r
+\r
+  return RETURN_SUCCESS;\r
+}\r