public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH V3 1/3] UefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file
@ 2022-10-31  2:49 Chang, Abner
  2022-10-31  2:49 ` [PATCH V3 2/3] UefiCpuPkg/SmmCpuFeaturesLib: Abstract arch dependent code Chang, Abner
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Chang, Abner @ 2022-10-31  2:49 UTC (permalink / raw)
  To: devel
  Cc: Abdul Lateef Attar, Garrett Kirkendall, Paul Grimes, Eric Dong,
	Ray Ni, Rahul Kumar

From: Abner Chang <abner.chang@amd.com>

BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code

Rename SmmCpuFeaturesLiCommon.c to
IntelSmmCpuFeaturesLib, because it was developed
specifically for Intel implementation. The code
that can be shared by other archs or vendors
will be stripped away and put in the common
file in the next patch.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Garrett Kirkendall <garrett.kirkendall@amd.com>
Cc: Paul Grimes <paul.grimes@amd.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
---
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf      | 2 +-
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf   | 2 +-
 .../Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf    | 2 +-
 .../{SmmCpuFeaturesLibCommon.c => IntelSmmCpuFeaturesLib.c}     | 0
 4 files changed, 3 insertions(+), 3 deletions(-)
 rename UefiCpuPkg/Library/SmmCpuFeaturesLib/{SmmCpuFeaturesLibCommon.c => IntelSmmCpuFeaturesLib.c} (100%)

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
index 7b5cef97008..6254a14698a 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
@@ -18,8 +18,8 @@
 
 [Sources]
   CpuFeaturesLib.h
+  IntelSmmCpuFeaturesLib.c
   SmmCpuFeaturesLib.c
-  SmmCpuFeaturesLibCommon.c
   SmmCpuFeaturesLibNoStm.c
   TraditionalMmCpuFeaturesLib.c
 
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
index 85214ee31cd..d64d8e66b38 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
@@ -19,7 +19,7 @@
 
 [Sources]
   CpuFeaturesLib.h
-  SmmCpuFeaturesLibCommon.c
+  IntelSmmCpuFeaturesLib.c
   SmmStm.c
   SmmStm.h
   TraditionalMmCpuFeaturesLib.c
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
index 3eacab48db3..5935b3e1fd6 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
@@ -20,8 +20,8 @@
 
 [Sources]
   CpuFeaturesLib.h
+  IntelSmmCpuFeaturesLib.c
   StandaloneMmCpuFeaturesLib.c
-  SmmCpuFeaturesLibCommon.c
   SmmCpuFeaturesLibNoStm.c
 
 [Packages]
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
similarity index 100%
rename from UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
rename to UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
-- 
2.37.1.windows.1


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

* [PATCH V3 2/3] UefiCpuPkg/SmmCpuFeaturesLib: Abstract arch dependent code
  2022-10-31  2:49 [PATCH V3 1/3] UefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file Chang, Abner
@ 2022-10-31  2:49 ` Chang, Abner
  2022-10-31  4:48   ` Ni, Ray
  2022-10-31  2:49 ` [PATCH V3 3/3] UefiCpuPkg/SmmCpuFeaturesLib: Clean up header file inclusion in SmmStm.c Chang, Abner
  2022-10-31  4:47 ` [edk2-devel] [PATCH V3 1/3] UefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file Ni, Ray
  2 siblings, 1 reply; 6+ messages in thread
From: Chang, Abner @ 2022-10-31  2:49 UTC (permalink / raw)
  To: devel
  Cc: Abdul Lateef Attar, Garrett Kirkendall, Paul Grimes, Eric Dong,
	Ray Ni, Rahul Kumar

From: Abner Chang <abner.chang@amd.com>

BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code

This change stripped away the code that can be
shared with other archs or vendors from Intel
implementation and put in to the common file,
leaves the Intel X86 implementation in the
IntelSmmCpuFeatureLib. Also updates the header
file and INF file.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Garrett Kirkendall <garrett.kirkendall@amd.com>
Cc: Paul Grimes <paul.grimes@amd.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
---
 .../SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf   |   1 +
 .../SmmCpuFeaturesLibStm.inf                  |   1 +
 .../StandaloneMmCpuFeaturesLib.inf            |   1 +
 .../SmmCpuFeaturesLib/CpuFeaturesLib.h        |   6 +
 .../IntelSmmCpuFeaturesLib.c                  | 206 +----------------
 .../SmmCpuFeaturesLibCommon.c                 | 216 ++++++++++++++++++
 6 files changed, 227 insertions(+), 204 deletions(-)
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
index 6254a14698a..9ac7dde78f8 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
@@ -20,6 +20,7 @@
   CpuFeaturesLib.h
   IntelSmmCpuFeaturesLib.c
   SmmCpuFeaturesLib.c
+  SmmCpuFeaturesLibCommon.c
   SmmCpuFeaturesLibNoStm.c
   TraditionalMmCpuFeaturesLib.c
 
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
index d64d8e66b38..86d367e0a09 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
@@ -20,6 +20,7 @@
 [Sources]
   CpuFeaturesLib.h
   IntelSmmCpuFeaturesLib.c
+  SmmCpuFeaturesLibCommon.c
   SmmStm.c
   SmmStm.h
   TraditionalMmCpuFeaturesLib.c
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
index 5935b3e1fd6..b1f60a55055 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
@@ -21,6 +21,7 @@
 [Sources]
   CpuFeaturesLib.h
   IntelSmmCpuFeaturesLib.c
+  SmmCpuFeaturesLibCommon.c
   StandaloneMmCpuFeaturesLib.c
   SmmCpuFeaturesLibNoStm.c
 
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h b/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
index 8a1c2adc5c4..fd3e902547c 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
@@ -9,6 +9,12 @@
 #ifndef CPU_FEATURES_LIB_H_
 #define CPU_FEATURES_LIB_H_
 
+#include <Library/SmmCpuFeaturesLib.h>
+#include <Library/BaseLib.h>
+#include <Library/PcdLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/DebugLib.h>
+
 /**
   Performs library initialization.
 
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
index 75a0ec8e948..cb4897b21e3 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
@@ -7,16 +7,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
 
-#include <PiMm.h>
-#include <Library/SmmCpuFeaturesLib.h>
-#include <Library/BaseLib.h>
+#include "CpuFeaturesLib.h"
+
 #include <Library/MtrrLib.h>
-#include <Library/PcdLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/DebugLib.h>
 #include <Register/Intel/Cpuid.h>
 #include <Register/Intel/SmramSaveStateMap.h>
-#include "CpuFeaturesLib.h"
 
 //
 // Machine Specific Registers (MSRs)
@@ -287,64 +282,6 @@ SmmCpuFeaturesInitializeProcessor (
   FinishSmmCpuFeaturesInitializeProcessor ();
 }
 
-/**
-  This function updates the SMRAM save state on the currently executing CPU
-  to resume execution at a specific address after an RSM instruction.  This
-  function must evaluate the SMRAM save state to determine the execution mode
-  the RSM instruction resumes and update the resume execution address with
-  either NewInstructionPointer32 or NewInstructionPoint.  The auto HALT restart
-  flag in the SMRAM save state must always be cleared.  This function returns
-  the value of the instruction pointer from the SMRAM save state that was
-  replaced.  If this function returns 0, then the SMRAM save state was not
-  modified.
-
-  This function is called during the very first SMI on each CPU after
-  SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution mode
-  to signal that the SMBASE of each CPU has been updated before the default
-  SMBASE address is used for the first SMI to the next CPU.
-
-  @param[in] CpuIndex                 The index of the CPU to hook.  The value
-                                      must be between 0 and the NumberOfCpus
-                                      field in the System Management System Table
-                                      (SMST).
-  @param[in] CpuState                 Pointer to SMRAM Save State Map for the
-                                      currently executing CPU.
-  @param[in] NewInstructionPointer32  Instruction pointer to use if resuming to
-                                      32-bit execution mode from 64-bit SMM.
-  @param[in] NewInstructionPointer    Instruction pointer to use if resuming to
-                                      same execution mode as SMM.
-
-  @retval 0    This function did modify the SMRAM save state.
-  @retval > 0  The original instruction pointer value from the SMRAM save state
-               before it was replaced.
-**/
-UINT64
-EFIAPI
-SmmCpuFeaturesHookReturnFromSmm (
-  IN UINTN                 CpuIndex,
-  IN SMRAM_SAVE_STATE_MAP  *CpuState,
-  IN UINT64                NewInstructionPointer32,
-  IN UINT64                NewInstructionPointer
-  )
-{
-  return 0;
-}
-
-/**
-  Hook point in normal execution mode that allows the one CPU that was elected
-  as monarch during System Management Mode initialization to perform additional
-  initialization actions immediately after all of the CPUs have processed their
-  first SMI and called SmmCpuFeaturesInitializeProcessor() relocating SMBASE
-  into a buffer in SMRAM and called SmmCpuFeaturesHookReturnFromSmm().
-**/
-VOID
-EFIAPI
-SmmCpuFeaturesSmmRelocationComplete (
-  VOID
-  )
-{
-}
-
 /**
   Determines if MTRR registers must be configured to set SMRAM cache-ability
   when executing in System Management Mode.
@@ -414,48 +351,6 @@ SmmCpuFeaturesRendezvousEntry (
   }
 }
 
-/**
-  Processor specific hook point each time a CPU exits System Management Mode.
-
-  @param[in] CpuIndex  The index of the CPU that is exiting SMM.  The value must
-                       be between 0 and the NumberOfCpus field in the System
-                       Management System Table (SMST).
-**/
-VOID
-EFIAPI
-SmmCpuFeaturesRendezvousExit (
-  IN UINTN  CpuIndex
-  )
-{
-}
-
-/**
-  Check to see if an SMM register is supported by a specified CPU.
-
-  @param[in] CpuIndex  The index of the CPU to check for SMM register support.
-                       The value must be between 0 and the NumberOfCpus field
-                       in the System Management System Table (SMST).
-  @param[in] RegName   Identifies the SMM register to check for support.
-
-  @retval TRUE   The SMM register specified by RegName is supported by the CPU
-                 specified by CpuIndex.
-  @retval FALSE  The SMM register specified by RegName is not supported by the
-                 CPU specified by CpuIndex.
-**/
-BOOLEAN
-EFIAPI
-SmmCpuFeaturesIsSmmRegisterSupported (
-  IN UINTN         CpuIndex,
-  IN SMM_REG_NAME  RegName
-  )
-{
-  if (FeaturePcdGet (PcdSmmFeatureControlEnable) && (RegName == SmmRegFeatureControl)) {
-    return TRUE;
-  }
-
-  return FALSE;
-}
-
 /**
   Returns the current value of the SMM register for the specified CPU.
   If the SMM register is not supported, then 0 is returned.
@@ -506,100 +401,3 @@ SmmCpuFeaturesSetSmmRegister (
   }
 }
 
-/**
-  Read an SMM Save State register on the target processor.  If this function
-  returns EFI_UNSUPPORTED, then the caller is responsible for reading the
-  SMM Save Sate register.
-
-  @param[in]  CpuIndex  The index of the CPU to read the SMM Save State.  The
-                        value must be between 0 and the NumberOfCpus field in
-                        the System Management System Table (SMST).
-  @param[in]  Register  The SMM Save State register to read.
-  @param[in]  Width     The number of bytes to read from the CPU save state.
-  @param[out] Buffer    Upon return, this holds the CPU register value read
-                        from the save state.
-
-  @retval EFI_SUCCESS           The register was read from Save State.
-  @retval EFI_INVALID_PARAMETER  Buffer is NULL.
-  @retval EFI_UNSUPPORTED       This function does not support reading Register.
-
-**/
-EFI_STATUS
-EFIAPI
-SmmCpuFeaturesReadSaveStateRegister (
-  IN  UINTN                        CpuIndex,
-  IN  EFI_SMM_SAVE_STATE_REGISTER  Register,
-  IN  UINTN                        Width,
-  OUT VOID                         *Buffer
-  )
-{
-  return EFI_UNSUPPORTED;
-}
-
-/**
-  Writes an SMM Save State register on the target processor.  If this function
-  returns EFI_UNSUPPORTED, then the caller is responsible for writing the
-  SMM Save Sate register.
-
-  @param[in] CpuIndex  The index of the CPU to write the SMM Save State.  The
-                       value must be between 0 and the NumberOfCpus field in
-                       the System Management System Table (SMST).
-  @param[in] Register  The SMM Save State register to write.
-  @param[in] Width     The number of bytes to write to the CPU save state.
-  @param[in] Buffer    Upon entry, this holds the new CPU register value.
-
-  @retval EFI_SUCCESS           The register was written to Save State.
-  @retval EFI_INVALID_PARAMETER  Buffer is NULL.
-  @retval EFI_UNSUPPORTED       This function does not support writing Register.
-**/
-EFI_STATUS
-EFIAPI
-SmmCpuFeaturesWriteSaveStateRegister (
-  IN UINTN                        CpuIndex,
-  IN EFI_SMM_SAVE_STATE_REGISTER  Register,
-  IN UINTN                        Width,
-  IN CONST VOID                   *Buffer
-  )
-{
-  return EFI_UNSUPPORTED;
-}
-
-/**
-  This function is hook point called after the gEfiSmmReadyToLockProtocolGuid
-  notification is completely processed.
-**/
-VOID
-EFIAPI
-SmmCpuFeaturesCompleteSmmReadyToLock (
-  VOID
-  )
-{
-}
-
-/**
-  This API provides a method for a CPU to allocate a specific region for storing page tables.
-
-  This API can be called more once to allocate memory for page tables.
-
-  Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
-  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL
-  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is
-  returned.
-
-  This function can also return NULL if there is no preference on where the page tables are allocated in SMRAM.
-
-  @param  Pages                 The number of 4 KB pages to allocate.
-
-  @return A pointer to the allocated buffer for page tables.
-  @retval NULL      Fail to allocate a specific region for storing page tables,
-                    Or there is no preference on where the page tables are allocated in SMRAM.
-
-**/
-VOID *
-EFIAPI
-SmmCpuFeaturesAllocatePageTableMemory (
-  IN UINTN  Pages
-  )
-{
-  return NULL;
-}
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
new file mode 100644
index 00000000000..7777e52740e
--- /dev/null
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
@@ -0,0 +1,216 @@
+/** @file
+Implementation shared across all library instances.
+
+Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+#include <Library/SmmCpuFeaturesLib.h>
+#include <Library/BaseLib.h>
+#include <Library/MtrrLib.h>
+#include <Library/PcdLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/DebugLib.h>
+
+#include "CpuFeaturesLib.h"
+
+/**
+  This function updates the SMRAM save state on the currently executing CPU
+  to resume execution at a specific address after an RSM instruction.  This
+  function must evaluate the SMRAM save state to determine the execution mode
+  the RSM instruction resumes and update the resume execution address with
+  either NewInstructionPointer32 or NewInstructionPoint.  The auto HALT restart
+  flag in the SMRAM save state must always be cleared.  This function returns
+  the value of the instruction pointer from the SMRAM save state that was
+  replaced.  If this function returns 0, then the SMRAM save state was not
+  modified.
+
+  This function is called during the very first SMI on each CPU after
+  SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution mode
+  to signal that the SMBASE of each CPU has been updated before the default
+  SMBASE address is used for the first SMI to the next CPU.
+
+  @param[in] CpuIndex                 The index of the CPU to hook.  The value
+                                      must be between 0 and the NumberOfCpus
+                                      field in the System Management System Table
+                                      (SMST).
+  @param[in] CpuState                 Pointer to SMRAM Save State Map for the
+                                      currently executing CPU.
+  @param[in] NewInstructionPointer32  Instruction pointer to use if resuming to
+                                      32-bit execution mode from 64-bit SMM.
+  @param[in] NewInstructionPointer    Instruction pointer to use if resuming to
+                                      same execution mode as SMM.
+
+  @retval 0    This function did modify the SMRAM save state.
+  @retval > 0  The original instruction pointer value from the SMRAM save state
+               before it was replaced.
+**/
+UINT64
+EFIAPI
+SmmCpuFeaturesHookReturnFromSmm (
+  IN UINTN                 CpuIndex,
+  IN SMRAM_SAVE_STATE_MAP  *CpuState,
+  IN UINT64                NewInstructionPointer32,
+  IN UINT64                NewInstructionPointer
+  )
+{
+  return 0;
+}
+
+/**
+  Hook point in normal execution mode that allows the one CPU that was elected
+  as monarch during System Management Mode initialization to perform additional
+  initialization actions immediately after all of the CPUs have processed their
+  first SMI and called SmmCpuFeaturesInitializeProcessor() relocating SMBASE
+  into a buffer in SMRAM and called SmmCpuFeaturesHookReturnFromSmm().
+**/
+VOID
+EFIAPI
+SmmCpuFeaturesSmmRelocationComplete (
+  VOID
+  )
+{
+}
+
+/**
+  Processor specific hook point each time a CPU exits System Management Mode.
+
+  @param[in] CpuIndex  The index of the CPU that is exiting SMM.  The value must
+                       be between 0 and the NumberOfCpus field in the System
+                       Management System Table (SMST).
+**/
+VOID
+EFIAPI
+SmmCpuFeaturesRendezvousExit (
+  IN UINTN  CpuIndex
+  )
+{
+}
+
+/**
+  Check to see if an SMM register is supported by a specified CPU.
+
+  @param[in] CpuIndex  The index of the CPU to check for SMM register support.
+                       The value must be between 0 and the NumberOfCpus field
+                       in the System Management System Table (SMST).
+  @param[in] RegName   Identifies the SMM register to check for support.
+
+  @retval TRUE   The SMM register specified by RegName is supported by the CPU
+                 specified by CpuIndex.
+  @retval FALSE  The SMM register specified by RegName is not supported by the
+                 CPU specified by CpuIndex.
+**/
+BOOLEAN
+EFIAPI
+SmmCpuFeaturesIsSmmRegisterSupported (
+  IN UINTN         CpuIndex,
+  IN SMM_REG_NAME  RegName
+  )
+{
+  if (FeaturePcdGet (PcdSmmFeatureControlEnable) && (RegName == SmmRegFeatureControl)) {
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+/**
+  Read an SMM Save State register on the target processor.  If this function
+  returns EFI_UNSUPPORTED, then the caller is responsible for reading the
+  SMM Save Sate register.
+
+  @param[in]  CpuIndex  The index of the CPU to read the SMM Save State.  The
+                        value must be between 0 and the NumberOfCpus field in
+                        the System Management System Table (SMST).
+  @param[in]  Register  The SMM Save State register to read.
+  @param[in]  Width     The number of bytes to read from the CPU save state.
+  @param[out] Buffer    Upon return, this holds the CPU register value read
+                        from the save state.
+
+  @retval EFI_SUCCESS           The register was read from Save State.
+  @retval EFI_INVALID_PARAMETER  Buffer is NULL.
+  @retval EFI_UNSUPPORTED       This function does not support reading Register.
+
+**/
+EFI_STATUS
+EFIAPI
+SmmCpuFeaturesReadSaveStateRegister (
+  IN  UINTN                        CpuIndex,
+  IN  EFI_SMM_SAVE_STATE_REGISTER  Register,
+  IN  UINTN                        Width,
+  OUT VOID                         *Buffer
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  Writes an SMM Save State register on the target processor.  If this function
+  returns EFI_UNSUPPORTED, then the caller is responsible for writing the
+  SMM Save Sate register.
+
+  @param[in] CpuIndex  The index of the CPU to write the SMM Save State.  The
+                       value must be between 0 and the NumberOfCpus field in
+                       the System Management System Table (SMST).
+  @param[in] Register  The SMM Save State register to write.
+  @param[in] Width     The number of bytes to write to the CPU save state.
+  @param[in] Buffer    Upon entry, this holds the new CPU register value.
+
+  @retval EFI_SUCCESS           The register was written to Save State.
+  @retval EFI_INVALID_PARAMETER  Buffer is NULL.
+  @retval EFI_UNSUPPORTED       This function does not support writing Register.
+**/
+EFI_STATUS
+EFIAPI
+SmmCpuFeaturesWriteSaveStateRegister (
+  IN UINTN                        CpuIndex,
+  IN EFI_SMM_SAVE_STATE_REGISTER  Register,
+  IN UINTN                        Width,
+  IN CONST VOID                   *Buffer
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  This function is hook point called after the gEfiSmmReadyToLockProtocolGuid
+  notification is completely processed.
+**/
+VOID
+EFIAPI
+SmmCpuFeaturesCompleteSmmReadyToLock (
+  VOID
+  )
+{
+}
+
+/**
+  This API provides a method for a CPU to allocate a specific region for storing page tables.
+
+  This API can be called more once to allocate memory for page tables.
+
+  Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
+  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL
+  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is
+  returned.
+
+  This function can also return NULL if there is no preference on where the page tables are allocated in SMRAM.
+
+  @param  Pages                 The number of 4 KB pages to allocate.
+
+  @return A pointer to the allocated buffer for page tables.
+  @retval NULL      Fail to allocate a specific region for storing page tables,
+                    Or there is no preference on where the page tables are allocated in SMRAM.
+
+**/
+VOID *
+EFIAPI
+SmmCpuFeaturesAllocatePageTableMemory (
+  IN UINTN  Pages
+  )
+{
+  return NULL;
+}
-- 
2.37.1.windows.1


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

* [PATCH V3 3/3] UefiCpuPkg/SmmCpuFeaturesLib: Clean up header file inclusion in SmmStm.c
  2022-10-31  2:49 [PATCH V3 1/3] UefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file Chang, Abner
  2022-10-31  2:49 ` [PATCH V3 2/3] UefiCpuPkg/SmmCpuFeaturesLib: Abstract arch dependent code Chang, Abner
@ 2022-10-31  2:49 ` Chang, Abner
  2022-10-31  4:48   ` Ni, Ray
  2022-10-31  4:47 ` [edk2-devel] [PATCH V3 1/3] UefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file Ni, Ray
  2 siblings, 1 reply; 6+ messages in thread
From: Chang, Abner @ 2022-10-31  2:49 UTC (permalink / raw)
  To: devel
  Cc: Abdul Lateef Attar, Garrett Kirkendall, Paul Grimes, Eric Dong,
	Ray Ni, Rahul Kumar

From: Abner Chang <abner.chang@amd.com>

BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code

Remove the header files those are already included in
CpuFeatureLib.h.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Garrett Kirkendall <garrett.kirkendall@amd.com>
Cc: Paul Grimes <paul.grimes@amd.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
---
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
index 4e8f897f5e9..3cf162ada01 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
@@ -7,11 +7,8 @@
 **/
 
 #include <PiMm.h>
-#include <Library/BaseLib.h>
 #include <Library/BaseMemoryLib.h>
-#include <Library/MemoryAllocationLib.h>
 #include <Library/HobLib.h>
-#include <Library/DebugLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 #include <Library/SmmServicesTableLib.h>
 #include <Library/TpmMeasurementLib.h>
-- 
2.37.1.windows.1


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

* Re: [edk2-devel] [PATCH V3 1/3] UefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file
  2022-10-31  2:49 [PATCH V3 1/3] UefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file Chang, Abner
  2022-10-31  2:49 ` [PATCH V3 2/3] UefiCpuPkg/SmmCpuFeaturesLib: Abstract arch dependent code Chang, Abner
  2022-10-31  2:49 ` [PATCH V3 3/3] UefiCpuPkg/SmmCpuFeaturesLib: Clean up header file inclusion in SmmStm.c Chang, Abner
@ 2022-10-31  4:47 ` Ni, Ray
  2 siblings, 0 replies; 6+ messages in thread
From: Ni, Ray @ 2022-10-31  4:47 UTC (permalink / raw)
  To: devel@edk2.groups.io, abner.chang@amd.com
  Cc: Abdul Lateef Attar, Garrett Kirkendall, Paul Grimes, Dong, Eric,
	Kumar, Rahul R

Reviewed-by: Ray Ni <ray.ni@intel.com>

________________________________________
From: devel@edk2.groups.io <devel@edk2.groups.io> on behalf of Chang, Abner via groups.io <abner.chang=amd.com@groups.io>
Sent: Monday, October 31, 2022 10:49
To: devel@edk2.groups.io
Cc: Abdul Lateef Attar; Garrett Kirkendall; Paul Grimes; Dong, Eric; Ni, Ray; Kumar, Rahul R
Subject: [edk2-devel] [PATCH V3 1/3] UefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file

From: Abner Chang <abner.chang@amd.com>

BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code

Rename SmmCpuFeaturesLiCommon.c to
IntelSmmCpuFeaturesLib, because it was developed
specifically for Intel implementation. The code
that can be shared by other archs or vendors
will be stripped away and put in the common
file in the next patch.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Garrett Kirkendall <garrett.kirkendall@amd.com>
Cc: Paul Grimes <paul.grimes@amd.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
---
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf      | 2 +-
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf   | 2 +-
 .../Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf    | 2 +-
 .../{SmmCpuFeaturesLibCommon.c => IntelSmmCpuFeaturesLib.c}     | 0
 4 files changed, 3 insertions(+), 3 deletions(-)
 rename UefiCpuPkg/Library/SmmCpuFeaturesLib/{SmmCpuFeaturesLibCommon.c => IntelSmmCpuFeaturesLib.c} (100%)

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
index 7b5cef97008..6254a14698a 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
@@ -18,8 +18,8 @@

 [Sources]
   CpuFeaturesLib.h
+  IntelSmmCpuFeaturesLib.c
   SmmCpuFeaturesLib.c
-  SmmCpuFeaturesLibCommon.c
   SmmCpuFeaturesLibNoStm.c
   TraditionalMmCpuFeaturesLib.c

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
index 85214ee31cd..d64d8e66b38 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
@@ -19,7 +19,7 @@

 [Sources]
   CpuFeaturesLib.h
-  SmmCpuFeaturesLibCommon.c
+  IntelSmmCpuFeaturesLib.c
   SmmStm.c
   SmmStm.h
   TraditionalMmCpuFeaturesLib.c
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
index 3eacab48db3..5935b3e1fd6 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
@@ -20,8 +20,8 @@

 [Sources]
   CpuFeaturesLib.h
+  IntelSmmCpuFeaturesLib.c
   StandaloneMmCpuFeaturesLib.c
-  SmmCpuFeaturesLibCommon.c
   SmmCpuFeaturesLibNoStm.c

 [Packages]
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
similarity index 100%
rename from UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
rename to UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
--
2.37.1.windows.1







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

* Re: [PATCH V3 2/3] UefiCpuPkg/SmmCpuFeaturesLib: Abstract arch dependent code
  2022-10-31  2:49 ` [PATCH V3 2/3] UefiCpuPkg/SmmCpuFeaturesLib: Abstract arch dependent code Chang, Abner
@ 2022-10-31  4:48   ` Ni, Ray
  0 siblings, 0 replies; 6+ messages in thread
From: Ni, Ray @ 2022-10-31  4:48 UTC (permalink / raw)
  To: abner.chang@amd.com, devel@edk2.groups.io
  Cc: Abdul Lateef Attar, Garrett Kirkendall, Paul Grimes, Dong, Eric,
	Kumar, Rahul R

Reviewed-by: Ray Ni <ray.ni@intel.com>

> -----Original Message-----
> From: abner.chang@amd.com <abner.chang@amd.com>
> Sent: Monday, October 31, 2022 10:49 AM
> To: devel@edk2.groups.io
> Cc: Abdul Lateef Attar <abdattar@amd.com>; Garrett Kirkendall
> <garrett.kirkendall@amd.com>; Paul Grimes <paul.grimes@amd.com>; Dong,
> Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Kumar, Rahul R
> <rahul.r.kumar@intel.com>
> Subject: [PATCH V3 2/3] UefiCpuPkg/SmmCpuFeaturesLib: Abstract arch
> dependent code
> 
> From: Abner Chang <abner.chang@amd.com>
> 
> BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code
> 
> This change stripped away the code that can be
> shared with other archs or vendors from Intel
> implementation and put in to the common file,
> leaves the Intel X86 implementation in the
> IntelSmmCpuFeatureLib. Also updates the header
> file and INF file.
> 
> Signed-off-by: Abner Chang <abner.chang@amd.com>
> Cc: Abdul Lateef Attar <abdattar@amd.com>
> Cc: Garrett Kirkendall <garrett.kirkendall@amd.com>
> Cc: Paul Grimes <paul.grimes@amd.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> ---
>  .../SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf   |   1 +
>  .../SmmCpuFeaturesLibStm.inf                  |   1 +
>  .../StandaloneMmCpuFeaturesLib.inf            |   1 +
>  .../SmmCpuFeaturesLib/CpuFeaturesLib.h        |   6 +
>  .../IntelSmmCpuFeaturesLib.c                  | 206 +----------------
>  .../SmmCpuFeaturesLibCommon.c                 | 216 ++++++++++++++++++
>  6 files changed, 227 insertions(+), 204 deletions(-)
>  create mode 100644
> UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
> 
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> index 6254a14698a..9ac7dde78f8 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> @@ -20,6 +20,7 @@
>    CpuFeaturesLib.h
>    IntelSmmCpuFeaturesLib.c
>    SmmCpuFeaturesLib.c
> +  SmmCpuFeaturesLibCommon.c
>    SmmCpuFeaturesLibNoStm.c
>    TraditionalMmCpuFeaturesLib.c
> 
> diff --git
> a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
> index d64d8e66b38..86d367e0a09 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
> @@ -20,6 +20,7 @@
>  [Sources]
>    CpuFeaturesLib.h
>    IntelSmmCpuFeaturesLib.c
> +  SmmCpuFeaturesLibCommon.c
>    SmmStm.c
>    SmmStm.h
>    TraditionalMmCpuFeaturesLib.c
> diff --git
> a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.i
> nf
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.i
> nf
> index 5935b3e1fd6..b1f60a55055 100644
> ---
> a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.i
> nf
> +++
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.i
> nf
> @@ -21,6 +21,7 @@
>  [Sources]
>    CpuFeaturesLib.h
>    IntelSmmCpuFeaturesLib.c
> +  SmmCpuFeaturesLibCommon.c
>    StandaloneMmCpuFeaturesLib.c
>    SmmCpuFeaturesLibNoStm.c
> 
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
> index 8a1c2adc5c4..fd3e902547c 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
> @@ -9,6 +9,12 @@
>  #ifndef CPU_FEATURES_LIB_H_
>  #define CPU_FEATURES_LIB_H_
> 
> +#include <Library/SmmCpuFeaturesLib.h>
> +#include <Library/BaseLib.h>
> +#include <Library/PcdLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/DebugLib.h>
> +
>  /**
>    Performs library initialization.
> 
> diff --git
> a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
> index 75a0ec8e948..cb4897b21e3 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
> @@ -7,16 +7,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> 
> -#include <PiMm.h>
> -#include <Library/SmmCpuFeaturesLib.h>
> -#include <Library/BaseLib.h>
> +#include "CpuFeaturesLib.h"
> +
>  #include <Library/MtrrLib.h>
> -#include <Library/PcdLib.h>
> -#include <Library/MemoryAllocationLib.h>
> -#include <Library/DebugLib.h>
>  #include <Register/Intel/Cpuid.h>
>  #include <Register/Intel/SmramSaveStateMap.h>
> -#include "CpuFeaturesLib.h"
> 
>  //
>  // Machine Specific Registers (MSRs)
> @@ -287,64 +282,6 @@ SmmCpuFeaturesInitializeProcessor (
>    FinishSmmCpuFeaturesInitializeProcessor ();
>  }
> 
> -/**
> -  This function updates the SMRAM save state on the currently executing
> CPU
> -  to resume execution at a specific address after an RSM instruction.  This
> -  function must evaluate the SMRAM save state to determine the execution
> mode
> -  the RSM instruction resumes and update the resume execution address
> with
> -  either NewInstructionPointer32 or NewInstructionPoint.  The auto HALT
> restart
> -  flag in the SMRAM save state must always be cleared.  This function returns
> -  the value of the instruction pointer from the SMRAM save state that was
> -  replaced.  If this function returns 0, then the SMRAM save state was not
> -  modified.
> -
> -  This function is called during the very first SMI on each CPU after
> -  SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution
> mode
> -  to signal that the SMBASE of each CPU has been updated before the
> default
> -  SMBASE address is used for the first SMI to the next CPU.
> -
> -  @param[in] CpuIndex                 The index of the CPU to hook.  The value
> -                                      must be between 0 and the NumberOfCpus
> -                                      field in the System Management System Table
> -                                      (SMST).
> -  @param[in] CpuState                 Pointer to SMRAM Save State Map for the
> -                                      currently executing CPU.
> -  @param[in] NewInstructionPointer32  Instruction pointer to use if
> resuming to
> -                                      32-bit execution mode from 64-bit SMM.
> -  @param[in] NewInstructionPointer    Instruction pointer to use if resuming
> to
> -                                      same execution mode as SMM.
> -
> -  @retval 0    This function did modify the SMRAM save state.
> -  @retval > 0  The original instruction pointer value from the SMRAM save
> state
> -               before it was replaced.
> -**/
> -UINT64
> -EFIAPI
> -SmmCpuFeaturesHookReturnFromSmm (
> -  IN UINTN                 CpuIndex,
> -  IN SMRAM_SAVE_STATE_MAP  *CpuState,
> -  IN UINT64                NewInstructionPointer32,
> -  IN UINT64                NewInstructionPointer
> -  )
> -{
> -  return 0;
> -}
> -
> -/**
> -  Hook point in normal execution mode that allows the one CPU that was
> elected
> -  as monarch during System Management Mode initialization to perform
> additional
> -  initialization actions immediately after all of the CPUs have processed their
> -  first SMI and called SmmCpuFeaturesInitializeProcessor() relocating
> SMBASE
> -  into a buffer in SMRAM and called
> SmmCpuFeaturesHookReturnFromSmm().
> -**/
> -VOID
> -EFIAPI
> -SmmCpuFeaturesSmmRelocationComplete (
> -  VOID
> -  )
> -{
> -}
> -
>  /**
>    Determines if MTRR registers must be configured to set SMRAM cache-
> ability
>    when executing in System Management Mode.
> @@ -414,48 +351,6 @@ SmmCpuFeaturesRendezvousEntry (
>    }
>  }
> 
> -/**
> -  Processor specific hook point each time a CPU exits System Management
> Mode.
> -
> -  @param[in] CpuIndex  The index of the CPU that is exiting SMM.  The value
> must
> -                       be between 0 and the NumberOfCpus field in the System
> -                       Management System Table (SMST).
> -**/
> -VOID
> -EFIAPI
> -SmmCpuFeaturesRendezvousExit (
> -  IN UINTN  CpuIndex
> -  )
> -{
> -}
> -
> -/**
> -  Check to see if an SMM register is supported by a specified CPU.
> -
> -  @param[in] CpuIndex  The index of the CPU to check for SMM register
> support.
> -                       The value must be between 0 and the NumberOfCpus field
> -                       in the System Management System Table (SMST).
> -  @param[in] RegName   Identifies the SMM register to check for support.
> -
> -  @retval TRUE   The SMM register specified by RegName is supported by
> the CPU
> -                 specified by CpuIndex.
> -  @retval FALSE  The SMM register specified by RegName is not supported
> by the
> -                 CPU specified by CpuIndex.
> -**/
> -BOOLEAN
> -EFIAPI
> -SmmCpuFeaturesIsSmmRegisterSupported (
> -  IN UINTN         CpuIndex,
> -  IN SMM_REG_NAME  RegName
> -  )
> -{
> -  if (FeaturePcdGet (PcdSmmFeatureControlEnable) && (RegName ==
> SmmRegFeatureControl)) {
> -    return TRUE;
> -  }
> -
> -  return FALSE;
> -}
> -
>  /**
>    Returns the current value of the SMM register for the specified CPU.
>    If the SMM register is not supported, then 0 is returned.
> @@ -506,100 +401,3 @@ SmmCpuFeaturesSetSmmRegister (
>    }
>  }
> 
> -/**
> -  Read an SMM Save State register on the target processor.  If this function
> -  returns EFI_UNSUPPORTED, then the caller is responsible for reading the
> -  SMM Save Sate register.
> -
> -  @param[in]  CpuIndex  The index of the CPU to read the SMM Save State.
> The
> -                        value must be between 0 and the NumberOfCpus field in
> -                        the System Management System Table (SMST).
> -  @param[in]  Register  The SMM Save State register to read.
> -  @param[in]  Width     The number of bytes to read from the CPU save state.
> -  @param[out] Buffer    Upon return, this holds the CPU register value read
> -                        from the save state.
> -
> -  @retval EFI_SUCCESS           The register was read from Save State.
> -  @retval EFI_INVALID_PARAMETER  Buffer is NULL.
> -  @retval EFI_UNSUPPORTED       This function does not support reading
> Register.
> -
> -**/
> -EFI_STATUS
> -EFIAPI
> -SmmCpuFeaturesReadSaveStateRegister (
> -  IN  UINTN                        CpuIndex,
> -  IN  EFI_SMM_SAVE_STATE_REGISTER  Register,
> -  IN  UINTN                        Width,
> -  OUT VOID                         *Buffer
> -  )
> -{
> -  return EFI_UNSUPPORTED;
> -}
> -
> -/**
> -  Writes an SMM Save State register on the target processor.  If this function
> -  returns EFI_UNSUPPORTED, then the caller is responsible for writing the
> -  SMM Save Sate register.
> -
> -  @param[in] CpuIndex  The index of the CPU to write the SMM Save State.
> The
> -                       value must be between 0 and the NumberOfCpus field in
> -                       the System Management System Table (SMST).
> -  @param[in] Register  The SMM Save State register to write.
> -  @param[in] Width     The number of bytes to write to the CPU save state.
> -  @param[in] Buffer    Upon entry, this holds the new CPU register value.
> -
> -  @retval EFI_SUCCESS           The register was written to Save State.
> -  @retval EFI_INVALID_PARAMETER  Buffer is NULL.
> -  @retval EFI_UNSUPPORTED       This function does not support writing
> Register.
> -**/
> -EFI_STATUS
> -EFIAPI
> -SmmCpuFeaturesWriteSaveStateRegister (
> -  IN UINTN                        CpuIndex,
> -  IN EFI_SMM_SAVE_STATE_REGISTER  Register,
> -  IN UINTN                        Width,
> -  IN CONST VOID                   *Buffer
> -  )
> -{
> -  return EFI_UNSUPPORTED;
> -}
> -
> -/**
> -  This function is hook point called after the
> gEfiSmmReadyToLockProtocolGuid
> -  notification is completely processed.
> -**/
> -VOID
> -EFIAPI
> -SmmCpuFeaturesCompleteSmmReadyToLock (
> -  VOID
> -  )
> -{
> -}
> -
> -/**
> -  This API provides a method for a CPU to allocate a specific region for storing
> page tables.
> -
> -  This API can be called more once to allocate memory for page tables.
> -
> -  Allocates the number of 4KB pages of type EfiRuntimeServicesData and
> returns a pointer to the
> -  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If
> Pages is 0, then NULL
> -  is returned.  If there is not enough memory remaining to satisfy the
> request, then NULL is
> -  returned.
> -
> -  This function can also return NULL if there is no preference on where the
> page tables are allocated in SMRAM.
> -
> -  @param  Pages                 The number of 4 KB pages to allocate.
> -
> -  @return A pointer to the allocated buffer for page tables.
> -  @retval NULL      Fail to allocate a specific region for storing page tables,
> -                    Or there is no preference on where the page tables are allocated
> in SMRAM.
> -
> -**/
> -VOID *
> -EFIAPI
> -SmmCpuFeaturesAllocatePageTableMemory (
> -  IN UINTN  Pages
> -  )
> -{
> -  return NULL;
> -}
> diff --git
> a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
> new file mode 100644
> index 00000000000..7777e52740e
> --- /dev/null
> +++
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
> @@ -0,0 +1,216 @@
> +/** @file
> +Implementation shared across all library instances.
> +
> +Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) Microsoft Corporation.<BR>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +#include <Library/SmmCpuFeaturesLib.h>
> +#include <Library/BaseLib.h>
> +#include <Library/MtrrLib.h>
> +#include <Library/PcdLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/DebugLib.h>
> +
> +#include "CpuFeaturesLib.h"
> +
> +/**
> +  This function updates the SMRAM save state on the currently executing
> CPU
> +  to resume execution at a specific address after an RSM instruction.  This
> +  function must evaluate the SMRAM save state to determine the execution
> mode
> +  the RSM instruction resumes and update the resume execution address
> with
> +  either NewInstructionPointer32 or NewInstructionPoint.  The auto HALT
> restart
> +  flag in the SMRAM save state must always be cleared.  This function
> returns
> +  the value of the instruction pointer from the SMRAM save state that was
> +  replaced.  If this function returns 0, then the SMRAM save state was not
> +  modified.
> +
> +  This function is called during the very first SMI on each CPU after
> +  SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution
> mode
> +  to signal that the SMBASE of each CPU has been updated before the
> default
> +  SMBASE address is used for the first SMI to the next CPU.
> +
> +  @param[in] CpuIndex                 The index of the CPU to hook.  The value
> +                                      must be between 0 and the NumberOfCpus
> +                                      field in the System Management System Table
> +                                      (SMST).
> +  @param[in] CpuState                 Pointer to SMRAM Save State Map for the
> +                                      currently executing CPU.
> +  @param[in] NewInstructionPointer32  Instruction pointer to use if
> resuming to
> +                                      32-bit execution mode from 64-bit SMM.
> +  @param[in] NewInstructionPointer    Instruction pointer to use if resuming
> to
> +                                      same execution mode as SMM.
> +
> +  @retval 0    This function did modify the SMRAM save state.
> +  @retval > 0  The original instruction pointer value from the SMRAM save
> state
> +               before it was replaced.
> +**/
> +UINT64
> +EFIAPI
> +SmmCpuFeaturesHookReturnFromSmm (
> +  IN UINTN                 CpuIndex,
> +  IN SMRAM_SAVE_STATE_MAP  *CpuState,
> +  IN UINT64                NewInstructionPointer32,
> +  IN UINT64                NewInstructionPointer
> +  )
> +{
> +  return 0;
> +}
> +
> +/**
> +  Hook point in normal execution mode that allows the one CPU that was
> elected
> +  as monarch during System Management Mode initialization to perform
> additional
> +  initialization actions immediately after all of the CPUs have processed their
> +  first SMI and called SmmCpuFeaturesInitializeProcessor() relocating
> SMBASE
> +  into a buffer in SMRAM and called
> SmmCpuFeaturesHookReturnFromSmm().
> +**/
> +VOID
> +EFIAPI
> +SmmCpuFeaturesSmmRelocationComplete (
> +  VOID
> +  )
> +{
> +}
> +
> +/**
> +  Processor specific hook point each time a CPU exits System Management
> Mode.
> +
> +  @param[in] CpuIndex  The index of the CPU that is exiting SMM.  The
> value must
> +                       be between 0 and the NumberOfCpus field in the System
> +                       Management System Table (SMST).
> +**/
> +VOID
> +EFIAPI
> +SmmCpuFeaturesRendezvousExit (
> +  IN UINTN  CpuIndex
> +  )
> +{
> +}
> +
> +/**
> +  Check to see if an SMM register is supported by a specified CPU.
> +
> +  @param[in] CpuIndex  The index of the CPU to check for SMM register
> support.
> +                       The value must be between 0 and the NumberOfCpus field
> +                       in the System Management System Table (SMST).
> +  @param[in] RegName   Identifies the SMM register to check for support.
> +
> +  @retval TRUE   The SMM register specified by RegName is supported by
> the CPU
> +                 specified by CpuIndex.
> +  @retval FALSE  The SMM register specified by RegName is not supported
> by the
> +                 CPU specified by CpuIndex.
> +**/
> +BOOLEAN
> +EFIAPI
> +SmmCpuFeaturesIsSmmRegisterSupported (
> +  IN UINTN         CpuIndex,
> +  IN SMM_REG_NAME  RegName
> +  )
> +{
> +  if (FeaturePcdGet (PcdSmmFeatureControlEnable) && (RegName ==
> SmmRegFeatureControl)) {
> +    return TRUE;
> +  }
> +
> +  return FALSE;
> +}
> +
> +/**
> +  Read an SMM Save State register on the target processor.  If this function
> +  returns EFI_UNSUPPORTED, then the caller is responsible for reading the
> +  SMM Save Sate register.
> +
> +  @param[in]  CpuIndex  The index of the CPU to read the SMM Save State.
> The
> +                        value must be between 0 and the NumberOfCpus field in
> +                        the System Management System Table (SMST).
> +  @param[in]  Register  The SMM Save State register to read.
> +  @param[in]  Width     The number of bytes to read from the CPU save
> state.
> +  @param[out] Buffer    Upon return, this holds the CPU register value read
> +                        from the save state.
> +
> +  @retval EFI_SUCCESS           The register was read from Save State.
> +  @retval EFI_INVALID_PARAMETER  Buffer is NULL.
> +  @retval EFI_UNSUPPORTED       This function does not support reading
> Register.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmCpuFeaturesReadSaveStateRegister (
> +  IN  UINTN                        CpuIndex,
> +  IN  EFI_SMM_SAVE_STATE_REGISTER  Register,
> +  IN  UINTN                        Width,
> +  OUT VOID                         *Buffer
> +  )
> +{
> +  return EFI_UNSUPPORTED;
> +}
> +
> +/**
> +  Writes an SMM Save State register on the target processor.  If this function
> +  returns EFI_UNSUPPORTED, then the caller is responsible for writing the
> +  SMM Save Sate register.
> +
> +  @param[in] CpuIndex  The index of the CPU to write the SMM Save State.
> The
> +                       value must be between 0 and the NumberOfCpus field in
> +                       the System Management System Table (SMST).
> +  @param[in] Register  The SMM Save State register to write.
> +  @param[in] Width     The number of bytes to write to the CPU save state.
> +  @param[in] Buffer    Upon entry, this holds the new CPU register value.
> +
> +  @retval EFI_SUCCESS           The register was written to Save State.
> +  @retval EFI_INVALID_PARAMETER  Buffer is NULL.
> +  @retval EFI_UNSUPPORTED       This function does not support writing
> Register.
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmCpuFeaturesWriteSaveStateRegister (
> +  IN UINTN                        CpuIndex,
> +  IN EFI_SMM_SAVE_STATE_REGISTER  Register,
> +  IN UINTN                        Width,
> +  IN CONST VOID                   *Buffer
> +  )
> +{
> +  return EFI_UNSUPPORTED;
> +}
> +
> +/**
> +  This function is hook point called after the
> gEfiSmmReadyToLockProtocolGuid
> +  notification is completely processed.
> +**/
> +VOID
> +EFIAPI
> +SmmCpuFeaturesCompleteSmmReadyToLock (
> +  VOID
> +  )
> +{
> +}
> +
> +/**
> +  This API provides a method for a CPU to allocate a specific region for
> storing page tables.
> +
> +  This API can be called more once to allocate memory for page tables.
> +
> +  Allocates the number of 4KB pages of type EfiRuntimeServicesData and
> returns a pointer to the
> +  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If
> Pages is 0, then NULL
> +  is returned.  If there is not enough memory remaining to satisfy the
> request, then NULL is
> +  returned.
> +
> +  This function can also return NULL if there is no preference on where the
> page tables are allocated in SMRAM.
> +
> +  @param  Pages                 The number of 4 KB pages to allocate.
> +
> +  @return A pointer to the allocated buffer for page tables.
> +  @retval NULL      Fail to allocate a specific region for storing page tables,
> +                    Or there is no preference on where the page tables are allocated
> in SMRAM.
> +
> +**/
> +VOID *
> +EFIAPI
> +SmmCpuFeaturesAllocatePageTableMemory (
> +  IN UINTN  Pages
> +  )
> +{
> +  return NULL;
> +}
> --
> 2.37.1.windows.1


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

* Re: [PATCH V3 3/3] UefiCpuPkg/SmmCpuFeaturesLib: Clean up header file inclusion in SmmStm.c
  2022-10-31  2:49 ` [PATCH V3 3/3] UefiCpuPkg/SmmCpuFeaturesLib: Clean up header file inclusion in SmmStm.c Chang, Abner
@ 2022-10-31  4:48   ` Ni, Ray
  0 siblings, 0 replies; 6+ messages in thread
From: Ni, Ray @ 2022-10-31  4:48 UTC (permalink / raw)
  To: abner.chang@amd.com, devel@edk2.groups.io
  Cc: Abdul Lateef Attar, Garrett Kirkendall, Paul Grimes, Dong, Eric,
	Kumar, Rahul R

Reviewed-by: Ray Ni <ray.ni@intel.com>

> -----Original Message-----
> From: abner.chang@amd.com <abner.chang@amd.com>
> Sent: Monday, October 31, 2022 10:49 AM
> To: devel@edk2.groups.io
> Cc: Abdul Lateef Attar <abdattar@amd.com>; Garrett Kirkendall
> <garrett.kirkendall@amd.com>; Paul Grimes <paul.grimes@amd.com>; Dong,
> Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Kumar, Rahul R
> <rahul.r.kumar@intel.com>
> Subject: [PATCH V3 3/3] UefiCpuPkg/SmmCpuFeaturesLib: Clean up header
> file inclusion in SmmStm.c
> 
> From: Abner Chang <abner.chang@amd.com>
> 
> BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code
> 
> Remove the header files those are already included in
> CpuFeatureLib.h.
> 
> Signed-off-by: Abner Chang <abner.chang@amd.com>
> Cc: Abdul Lateef Attar <abdattar@amd.com>
> Cc: Garrett Kirkendall <garrett.kirkendall@amd.com>
> Cc: Paul Grimes <paul.grimes@amd.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> ---
>  UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
> index 4e8f897f5e9..3cf162ada01 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
> @@ -7,11 +7,8 @@
>  **/
> 
>  #include <PiMm.h>
> -#include <Library/BaseLib.h>
>  #include <Library/BaseMemoryLib.h>
> -#include <Library/MemoryAllocationLib.h>
>  #include <Library/HobLib.h>
> -#include <Library/DebugLib.h>
>  #include <Library/UefiBootServicesTableLib.h>
>  #include <Library/SmmServicesTableLib.h>
>  #include <Library/TpmMeasurementLib.h>
> --
> 2.37.1.windows.1


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

end of thread, other threads:[~2022-10-31  4:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-31  2:49 [PATCH V3 1/3] UefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file Chang, Abner
2022-10-31  2:49 ` [PATCH V3 2/3] UefiCpuPkg/SmmCpuFeaturesLib: Abstract arch dependent code Chang, Abner
2022-10-31  4:48   ` Ni, Ray
2022-10-31  2:49 ` [PATCH V3 3/3] UefiCpuPkg/SmmCpuFeaturesLib: Clean up header file inclusion in SmmStm.c Chang, Abner
2022-10-31  4:48   ` Ni, Ray
2022-10-31  4:47 ` [edk2-devel] [PATCH V3 1/3] UefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file Ni, Ray

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