public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] UefiCpuPkg/UefiCpuLib: Add GetCpuFamilyModel and GetCpuSteppingId
@ 2021-10-19  6:42 Ni, Ray
  2021-11-09 12:14 ` Dong, Eric
  0 siblings, 1 reply; 2+ messages in thread
From: Ni, Ray @ 2021-10-19  6:42 UTC (permalink / raw)
  To: devel; +Cc: Eric Dong, Rahul Kumar

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>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
---
 UefiCpuPkg/Include/Library/UefiCpuLib.h       | 23 +++++++++-
 .../Library/BaseUefiCpuLib/BaseUefiCpuLib.c   | 43 +++++++++++++++++++
 2 files changed, 65 insertions(+), 1 deletion(-)

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] UefiCpuPkg/UefiCpuLib: Add GetCpuFamilyModel and GetCpuSteppingId
  2021-10-19  6:42 [PATCH] UefiCpuPkg/UefiCpuLib: Add GetCpuFamilyModel and GetCpuSteppingId Ni, Ray
@ 2021-11-09 12:14 ` Dong, Eric
  0 siblings, 0 replies; 2+ messages in thread
From: Dong, Eric @ 2021-11-09 12:14 UTC (permalink / raw)
  To: Ni, Ray, devel@edk2.groups.io; +Cc: Kumar, Rahul1

Reviewed-by: Eric Dong <eric.dong@intel.com>

-----Original Message-----
From: Ni, Ray <ray.ni@intel.com> 
Sent: Tuesday, October 19, 2021 2:42 PM
To: devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@intel.com>; Kumar, Rahul1 <rahul1.kumar@intel.com>
Subject: [PATCH] UefiCpuPkg/UefiCpuLib: Add GetCpuFamilyModel and GetCpuSteppingId

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>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
---
 UefiCpuPkg/Include/Library/UefiCpuLib.h       | 23 +++++++++-
 .../Library/BaseUefiCpuLib/BaseUefiCpuLib.c   | 43 +++++++++++++++++++
 2 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Include/Library/UefiCpuLib.h b/UefiCpuPkg/Include/Library/UefiCpuLib.h
index 5326e72463..092c1d2116 100644
--- a/UefiCpuPkg/Include/Library/UefiCpuLib.h
+++ b/UefiCpuPkg/Include/Library/UefiCpuLib.h
@@ -4,7 +4,7 @@
   This library class defines some routines that are generic for IA32 family CPU

   to be UEFI specification compliant.

 

-  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>

+  Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.<BR>

   Copyright (c) 2020, AMD Inc. All rights reserved.<BR>

   SPDX-License-Identifier: BSD-2-Clause-Patent

 

@@ -43,4 +43,25 @@ StandardSignatureIsAuthenticAMD (
   VOID

   );

 

+/**

+  Return the 32bit CPU family and model value.

+

+  @return CPUID[01h].EAX with Processor Type and Stepping ID cleared.

+**/

+UINT32

+EFIAPI

+GetCpuFamilyModel (

+  VOID

+  );

+

+/**

+  Return the CPU stepping ID.

+  @return CPU stepping ID value in CPUID[01h].EAX.

+**/

+UINT8

+EFIAPI

+GetCpuSteppingId (

+  VOID

+  );

+

 #endif

diff --git a/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c b/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c
index c2cc3ff9a7..50891618c4 100644
--- a/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c
+++ b/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c
@@ -4,6 +4,7 @@
   The library routines are UEFI specification compliant.

 

   Copyright (c) 2020, AMD Inc. All rights reserved.<BR>

+  Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>

   SPDX-License-Identifier: BSD-2-Clause-Patent

 

 **/

@@ -36,3 +37,45 @@ StandardSignatureIsAuthenticAMD (
           RegEcx == CPUID_SIGNATURE_AUTHENTIC_AMD_ECX &&

           RegEdx == CPUID_SIGNATURE_AUTHENTIC_AMD_EDX);

 }

+

+/**

+  Return the 32bit CPU family and model value.

+

+  @return CPUID[01h].EAX with Processor Type and Stepping ID cleared.

+**/

+UINT32

+EFIAPI

+GetCpuFamilyModel (

+  VOID

+  )

+{

+  CPUID_VERSION_INFO_EAX  Eax;

+

+  AsmCpuid (CPUID_VERSION_INFO, &Eax.Uint32, NULL, NULL, NULL);

+

+  //

+  // Mask other fields than Family and Model.

+  //

+  Eax.Bits.SteppingId    = 0;

+  Eax.Bits.ProcessorType = 0;

+  Eax.Bits.Reserved1     = 0;

+  Eax.Bits.Reserved2     = 0;

+  return Eax.Uint32;

+}

+

+/**

+  Return the CPU stepping ID.

+  @return CPU stepping ID value in CPUID[01h].EAX.

+**/

+UINT8

+EFIAPI

+GetCpuSteppingId (

+  VOID

+  )

+{

+  CPUID_VERSION_INFO_EAX  Eax;

+

+  AsmCpuid (CPUID_VERSION_INFO, &Eax.Uint32, NULL, NULL, NULL);

+

+  return (UINT8) Eax.Bits.SteppingId;

+}

-- 
2.32.0.windows.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-09 12:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-19  6:42 [PATCH] UefiCpuPkg/UefiCpuLib: Add GetCpuFamilyModel and GetCpuSteppingId Ni, Ray
2021-11-09 12:14 ` Dong, Eric

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox