]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/UefiCpuLib: Add GetCpuFamilyModel and GetCpuSteppingId
authorNi, Ray <ray.ni@intel.com>
Tue, 19 Oct 2021 06:42:21 +0000 (14:42 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 10 Nov 2021 04:28:08 +0000 (04:28 +0000)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3698

Lots of code relies on CPU Family/Model/Stepping for different logics.

The change adds two APIs for such needs.

Signed-off-by: Ray Ni <ray.ni@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
UefiCpuPkg/Include/Library/UefiCpuLib.h
UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c

index 5326e7246301c2da4914b03647e5b353d734da8f..092c1d2116c3bbf54c88447d016acc37d543b449 100644 (file)
@@ -4,7 +4,7 @@
   This library class defines some routines that are generic for IA32 family CPU\r
   to be UEFI specification compliant.\r
 \r
   This library class defines some routines that are generic for IA32 family CPU\r
   to be UEFI specification compliant.\r
 \r
-  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.<BR>\r
   Copyright (c) 2020, AMD Inc. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
   Copyright (c) 2020, AMD Inc. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -43,4 +43,25 @@ StandardSignatureIsAuthenticAMD (
   VOID\r
   );\r
 \r
   VOID\r
   );\r
 \r
+/**\r
+  Return the 32bit CPU family and model value.\r
+\r
+  @return CPUID[01h].EAX with Processor Type and Stepping ID cleared.\r
+**/\r
+UINT32\r
+EFIAPI\r
+GetCpuFamilyModel (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Return the CPU stepping ID.\r
+  @return CPU stepping ID value in CPUID[01h].EAX.\r
+**/\r
+UINT8\r
+EFIAPI\r
+GetCpuSteppingId (\r
+  VOID\r
+  );\r
+\r
 #endif\r
 #endif\r
index c2cc3ff9a7091f1469c0b96a9c530af179e08fb2..50891618c458b3ca8c651577e817ac89aa3fcbb9 100644 (file)
@@ -4,6 +4,7 @@
   The library routines are UEFI specification compliant.\r
 \r
   Copyright (c) 2020, AMD Inc. All rights reserved.<BR>\r
   The library routines are UEFI specification compliant.\r
 \r
   Copyright (c) 2020, AMD Inc. All rights reserved.<BR>\r
+  Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -36,3 +37,45 @@ StandardSignatureIsAuthenticAMD (
           RegEcx == CPUID_SIGNATURE_AUTHENTIC_AMD_ECX &&\r
           RegEdx == CPUID_SIGNATURE_AUTHENTIC_AMD_EDX);\r
 }\r
           RegEcx == CPUID_SIGNATURE_AUTHENTIC_AMD_ECX &&\r
           RegEdx == CPUID_SIGNATURE_AUTHENTIC_AMD_EDX);\r
 }\r
+\r
+/**\r
+  Return the 32bit CPU family and model value.\r
+\r
+  @return CPUID[01h].EAX with Processor Type and Stepping ID cleared.\r
+**/\r
+UINT32\r
+EFIAPI\r
+GetCpuFamilyModel (\r
+  VOID\r
+  )\r
+{\r
+  CPUID_VERSION_INFO_EAX  Eax;\r
+\r
+  AsmCpuid (CPUID_VERSION_INFO, &Eax.Uint32, NULL, NULL, NULL);\r
+\r
+  //\r
+  // Mask other fields than Family and Model.\r
+  //\r
+  Eax.Bits.SteppingId    = 0;\r
+  Eax.Bits.ProcessorType = 0;\r
+  Eax.Bits.Reserved1     = 0;\r
+  Eax.Bits.Reserved2     = 0;\r
+  return Eax.Uint32;\r
+}\r
+\r
+/**\r
+  Return the CPU stepping ID.\r
+  @return CPU stepping ID value in CPUID[01h].EAX.\r
+**/\r
+UINT8\r
+EFIAPI\r
+GetCpuSteppingId (\r
+  VOID\r
+  )\r
+{\r
+  CPUID_VERSION_INFO_EAX  Eax;\r
+\r
+  AsmCpuid (CPUID_VERSION_INFO, &Eax.Uint32, NULL, NULL, NULL);\r
+\r
+  return (UINT8) Eax.Bits.SteppingId;\r
+}\r