public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Abdul Lateef Attar" <abdattar@amd.com>
To: <devel@edk2.groups.io>
Cc: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>,
	Paul Grimes <paul.grimes@amd.com>,
	Garrett Kirkendall <garrett.kirkendall@amd.com>,
	"Abner Chang" <abner.chang@amd.com>,
	Eric Dong <eric.dong@intel.com>, Ray Ni <ray.ni@intel.com>,
	Rahul Kumar <rahul1.kumar@intel.com>
Subject: [PATCH v1 5/5] UefiCpuPkg/AmdSmmCpuFeaturesLib: Handles S3 save state
Date: Tue, 6 Dec 2022 18:53:18 +0530	[thread overview]
Message-ID: <a6d478ef1633d716d7396672a70e877591169bf8.1670332633.git.abdattar@amd.com> (raw)
In-Reply-To: <cover.1670332633.git.abdattar@amd.com>

From: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4182

Handles S3 save state restore condition.
Implements SmmCpuFeaturesCompleteSmmReadyToLock() to
sync all processor and update S3 resume entry point.

Cc: Paul Grimes <paul.grimes@amd.com>
Cc: Garrett Kirkendall <garrett.kirkendall@amd.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
---
 .../AmdSmmCpuFeaturesLib.inf                  |  1 +
 .../SmmCpuFeaturesLib/Amd/SmramSaveState.h    | 19 +++++++++++
 .../SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c | 32 +++++++++++++++++++
 3 files changed, 52 insertions(+)

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf
index 95eb31d16ead..7fd559e91ad8 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf
@@ -27,6 +27,7 @@ [Sources]
 [Packages]
   MdePkg/MdePkg.dec
   UefiCpuPkg/UefiCpuPkg.dec
+  MdeModulePkg/MdeModulePkg.dec
 
 [LibraryClasses]
   BaseLib
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h
index 290ebdbc9227..474a5dbd9765 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h
@@ -17,6 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/DebugLib.h>
 #include <Library/SmmServicesTableLib.h>
 #include <Register/Amd/SmramSaveStateMap.h>
+#include <Guid/AcpiS3Context.h>
 
 // EFER register LMA bit
 #define LMA  BIT10
@@ -106,4 +107,22 @@ InternalSmmCpuFeaturesWriteSaveStateRegister (
   IN CONST VOID                   *Buffer
   );
 
+/**
+  Initialize MP synchronization data.
+**/
+VOID
+EFIAPI
+InitializeMpSyncData (
+  VOID
+  );
+
+/**
+  Perform SMM MP sync Semaphores re-initialization in the S3 boot path.
+**/
+VOID
+EFIAPI
+SmmS3MpSemaphoreInit (
+  VOID
+  );
+
 #endif
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c
index 10bed4116397..b855573d9401 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c
@@ -14,6 +14,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 // The mode of the CPU at the time an SMI occurs
 extern UINT8  mSmmSaveStateRegisterLma;
 
+// SMM S3 resume state Ptr
+extern SMM_S3_RESUME_STATE  *mSmmS3ResumeState;
+
 /**
   Read an SMM Save State register on the target processor.  If this function
   returns EFI_UNSUPPORTED, then the caller is responsible for reading the
@@ -441,4 +444,33 @@ SmmCpuFeaturesCompleteSmmReadyToLock (
   VOID
   )
 {
+  if (mSmmS3ResumeState != NULL ) {
+    mSmmS3ResumeState->SmmS3ResumeEntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)SmmS3MpSemaphoreInit;
+  }
+}
+
+/**
+  Perform SMM MP sync Semaphores re-initialization in the S3 boot path.
+**/
+VOID
+EFIAPI
+SmmS3MpSemaphoreInit (
+  VOID
+  )
+{
+  InitializeMpSyncData ();
+
+  DEBUG ((DEBUG_INFO, "SMM S3 Return CS                = %x\n", mSmmS3ResumeState->ReturnCs));
+  DEBUG ((DEBUG_INFO, "SMM S3 Return Entry Point       = %x\n", mSmmS3ResumeState->ReturnEntryPoint));
+  DEBUG ((DEBUG_INFO, "SMM S3 Return Context1          = %x\n", mSmmS3ResumeState->ReturnContext1));
+  DEBUG ((DEBUG_INFO, "SMM S3 Return Context2          = %x\n", mSmmS3ResumeState->ReturnContext2));
+  DEBUG ((DEBUG_INFO, "SMM S3 Return Stack Pointer     = %x\n", mSmmS3ResumeState->ReturnStackPointer));
+
+  AsmDisablePaging64 (
+    mSmmS3ResumeState->ReturnCs,
+    (UINT32)mSmmS3ResumeState->ReturnEntryPoint,
+    (UINT32)mSmmS3ResumeState->ReturnContext1,
+    (UINT32)mSmmS3ResumeState->ReturnContext2,
+    (UINT32)mSmmS3ResumeState->ReturnStackPointer
+    );
 }
-- 
2.25.1


  parent reply	other threads:[~2022-12-06 13:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-06 13:23 [PATCH v1 0/5] Adds AmdSmmCpuFeaturesLib Abdul Lateef Attar
2022-12-06 13:23 ` [PATCH v1 1/5] UefiCpuPkg/SmmCpuFeaturesLib: Restructure arch-dependent code Abdul Lateef Attar
2022-12-07 15:57   ` Chang, Abner
2022-12-06 13:23 ` [PATCH v1 2/5] MdePkg: Adds AMD SMRAM save state map Abdul Lateef Attar
2022-12-07 16:17   ` [edk2-devel] " Chang, Abner
2022-12-06 13:23 ` [PATCH v1 3/5] UefiCpuPkg: Initial implementation of AMD's SmmCpuFeaturesLib Abdul Lateef Attar
2022-12-08  4:06   ` [edk2-devel] " Chang, Abner
2022-12-06 13:23 ` [PATCH v1 4/5] UefiCpuPkg: Implements SmmCpuFeaturesLib for AMD Family Abdul Lateef Attar
2022-12-08  5:07   ` [edk2-devel] " Chang, Abner
2022-12-12  9:13     ` Attar, AbdulLateef (Abdul Lateef)
2022-12-06 13:23 ` Abdul Lateef Attar [this message]
2022-12-08  5:46   ` [edk2-devel] [PATCH v1 5/5] UefiCpuPkg/AmdSmmCpuFeaturesLib: Handles S3 save state Chang, Abner
2022-12-12  9:16     ` Attar, AbdulLateef (Abdul Lateef)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a6d478ef1633d716d7396672a70e877591169bf8.1670332633.git.abdattar@amd.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox