public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdeModulePkg PiSmmCore: Only install EndOfS3Resume during S3 resume
@ 2017-12-11  8:36 Star Zeng
  2017-12-11 13:23 ` Yao, Jiewen
  0 siblings, 1 reply; 2+ messages in thread
From: Star Zeng @ 2017-12-11  8:36 UTC (permalink / raw)
  To: edk2-devel; +Cc: Star Zeng, Jiewen Yao, Eric Dong

Otherwise, it may be triggered wrongly by other code in OS.

This patch is to use S3 entry callback to determine if it will be
during S3 resume, and check it in SmmReadyToBootHandler().

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.c   | 79 +++++++++++++++++++++++++++++--
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.h   |  1 +
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf |  1 +
 3 files changed, 77 insertions(+), 4 deletions(-)

diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
index 0b9c7958c75c..6d266933868d 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
@@ -72,6 +72,12 @@ EFI_SMM_SYSTEM_TABLE2  gSmmCoreSmst = {
 BOOLEAN  mInLegacyBoot = FALSE;
 
 //
+// Flag to determine if it is during S3 resume.
+// It will be set in S3 entry callback and cleared at EndOfS3Resume.
+//
+BOOLEAN  mDuringS3Resume = FALSE;
+
+//
 // Table of SMI Handlers that are registered by the SMM Core when it is initialized
 //
 SMM_CORE_SMI_HANDLERS  mSmmCoreSmiHandlers[] = {
@@ -213,6 +219,37 @@ SmmExitBootServicesHandler (
 }
 
 /**
+  Main entry point for an SMM handler dispatch or communicate-based callback.
+
+  @param[in]     DispatchHandle  The unique handle assigned to this handler by SmiHandlerRegister().
+  @param[in]     Context         Points to an optional handler context which was specified when the
+                                 handler was registered.
+  @param[in,out] CommBuffer      A pointer to a collection of data in memory that will
+                                 be conveyed from a non-SMM environment into an SMM environment.
+  @param[in,out] CommBufferSize  The size of the CommBuffer.
+
+  @retval EFI_SUCCESS                         The interrupt was handled and quiesced. No other handlers
+                                              should still be called.
+  @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED  The interrupt has been quiesced but other handlers should
+                                              still be called.
+  @retval EFI_WARN_INTERRUPT_SOURCE_PENDING   The interrupt is still pending and other handlers should still
+                                              be called.
+  @retval EFI_INTERRUPT_PENDING               The interrupt could not be quiesced.
+**/
+EFI_STATUS
+EFIAPI
+SmmS3EntryCallBack (
+  IN           EFI_HANDLE           DispatchHandle,
+  IN     CONST VOID                 *Context         OPTIONAL,
+  IN OUT       VOID                 *CommBuffer      OPTIONAL,
+  IN OUT       UINTN                *CommBufferSize  OPTIONAL
+  )
+{
+  mDuringS3Resume = TRUE;
+  return EFI_SUCCESS;
+}
+
+/**
   Software SMI handler that is called when an Ready To Boot event is signalled.
   Then the SMM Core also install SMM Ready To Boot protocol to notify SMM driver
   that system enter ready to boot.
@@ -235,8 +272,11 @@ SmmReadyToBootHandler (
   IN OUT UINTN       *CommBufferSize  OPTIONAL
   )
 {
-  EFI_STATUS    Status;
-  EFI_HANDLE    SmmHandle;
+  EFI_STATUS                        Status;
+  EFI_HANDLE                        SmmHandle;
+  EFI_SMM_SX_DISPATCH2_PROTOCOL     *SxDispatch;
+  EFI_SMM_SX_REGISTER_CONTEXT       EntryRegisterContext;
+  EFI_HANDLE                        S3SleepEntryHandle;
 
   //
   // Install SMM Ready To Boot protocol.
@@ -251,7 +291,31 @@ SmmReadyToBootHandler (
 
   SmiHandlerUnRegister (DispatchHandle);
 
-  return Status;
+  //
+  // Locate SmmSxDispatch2 protocol.
+  //
+  Status = SmmLocateProtocol (
+             &gEfiSmmSxDispatch2ProtocolGuid,
+             NULL,
+             &SxDispatch
+             );
+  if (!EFI_ERROR (Status)) {
+    //
+    // Register a S3 entry callback function to
+    // determine if it will be during S3 resume.
+    //
+    EntryRegisterContext.Type  = SxS3;
+    EntryRegisterContext.Phase = SxEntry;
+    Status = SxDispatch->Register (
+                           SxDispatch,
+                           SmmS3EntryCallBack,
+                           &EntryRegisterContext,
+                           &S3SleepEntryHandle
+                           );
+    ASSERT_EFI_ERROR (Status);
+  }
+
+  return EFI_SUCCESS;
 }
 
 /**
@@ -409,7 +473,12 @@ SmmEndOfS3ResumeHandler (
   EFI_STATUS  Status;
   EFI_HANDLE  SmmHandle;
 
-  DEBUG ((EFI_D_INFO, "SmmEndOfS3ResumeHandler\n"));
+  DEBUG ((DEBUG_INFO, "SmmEndOfS3ResumeHandler\n"));
+
+  if (!mDuringS3Resume) {
+    DEBUG ((DEBUG_ERROR, "It is not during S3 resume\n"));
+    return EFI_ACCESS_DENIED;
+  }
 
   //
   // Install SMM EndOfS3Resume protocol
@@ -434,6 +503,8 @@ SmmEndOfS3ResumeHandler (
            );
   ASSERT_EFI_ERROR (Status);
 
+  mDuringS3Resume = FALSE;
+
   return Status;
 }
 
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
index 2729a434d8f8..8c10d833e2ae 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
@@ -33,6 +33,7 @@
 #include <Protocol/SmmLegacyBoot.h>
 #include <Protocol/SmmReadyToBoot.h>
 #include <Protocol/SmmMemoryAttribute.h>
+#include <Protocol/SmmSxDispatch2.h>
 
 #include <Guid/Apriori.h>
 #include <Guid/EventGroup.h>
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf
index de0037fe4a99..5c04e851f94b 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf
@@ -92,6 +92,7 @@ [Protocols]
   gEfiSmmUsbDispatch2ProtocolGuid               ## SOMETIMES_CONSUMES
   gEfiSmmCpuProtocolGuid                        ## SOMETIMES_CONSUMES
   gEdkiiSmmMemoryAttributeProtocolGuid          ## CONSUMES
+  gEfiSmmSxDispatch2ProtocolGuid                ## SOMETIMES_CONSUMES
 
 [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressSmmCodePageNumber     ## SOMETIMES_CONSUMES
-- 
2.7.0.windows.1



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

* Re: [PATCH] MdeModulePkg PiSmmCore: Only install EndOfS3Resume during S3 resume
  2017-12-11  8:36 [PATCH] MdeModulePkg PiSmmCore: Only install EndOfS3Resume during S3 resume Star Zeng
@ 2017-12-11 13:23 ` Yao, Jiewen
  0 siblings, 0 replies; 2+ messages in thread
From: Yao, Jiewen @ 2017-12-11 13:23 UTC (permalink / raw)
  To: Zeng, Star, edk2-devel@lists.01.org; +Cc: Dong, Eric

Reviewed-by: Jiewen.yao@intel.com

> -----Original Message-----
> From: Zeng, Star
> Sent: Monday, December 11, 2017 4:36 PM
> To: edk2-devel@lists.01.org
> Cc: Zeng, Star <star.zeng@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>;
> Dong, Eric <eric.dong@intel.com>
> Subject: [PATCH] MdeModulePkg PiSmmCore: Only install EndOfS3Resume
> during S3 resume
> 
> Otherwise, it may be triggered wrongly by other code in OS.
> 
> This patch is to use S3 entry callback to determine if it will be
> during S3 resume, and check it in SmmReadyToBootHandler().
> 
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Star Zeng <star.zeng@intel.com>
> ---
>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.c   | 79
> +++++++++++++++++++++++++++++--
>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.h   |  1 +
>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf |  1 +
>  3 files changed, 77 insertions(+), 4 deletions(-)
> 
> diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> index 0b9c7958c75c..6d266933868d 100644
> --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> @@ -72,6 +72,12 @@ EFI_SMM_SYSTEM_TABLE2  gSmmCoreSmst = {
>  BOOLEAN  mInLegacyBoot = FALSE;
> 
>  //
> +// Flag to determine if it is during S3 resume.
> +// It will be set in S3 entry callback and cleared at EndOfS3Resume.
> +//
> +BOOLEAN  mDuringS3Resume = FALSE;
> +
> +//
>  // Table of SMI Handlers that are registered by the SMM Core when it is
> initialized
>  //
>  SMM_CORE_SMI_HANDLERS  mSmmCoreSmiHandlers[] = {
> @@ -213,6 +219,37 @@ SmmExitBootServicesHandler (
>  }
> 
>  /**
> +  Main entry point for an SMM handler dispatch or communicate-based
> callback.
> +
> +  @param[in]     DispatchHandle  The unique handle assigned to this
> handler by SmiHandlerRegister().
> +  @param[in]     Context         Points to an optional handler context
> which was specified when the
> +                                 handler was registered.
> +  @param[in,out] CommBuffer      A pointer to a collection of data in
> memory that will
> +                                 be conveyed from a non-SMM
> environment into an SMM environment.
> +  @param[in,out] CommBufferSize  The size of the CommBuffer.
> +
> +  @retval EFI_SUCCESS                         The interrupt was
> handled and quiesced. No other handlers
> +                                              should still be called.
> +  @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED  The interrupt has
> been quiesced but other handlers should
> +                                              still be called.
> +  @retval EFI_WARN_INTERRUPT_SOURCE_PENDING   The interrupt is still
> pending and other handlers should still
> +                                              be called.
> +  @retval EFI_INTERRUPT_PENDING               The interrupt could not
> be quiesced.
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmS3EntryCallBack (
> +  IN           EFI_HANDLE           DispatchHandle,
> +  IN     CONST VOID                 *Context         OPTIONAL,
> +  IN OUT       VOID                 *CommBuffer      OPTIONAL,
> +  IN OUT       UINTN                *CommBufferSize  OPTIONAL
> +  )
> +{
> +  mDuringS3Resume = TRUE;
> +  return EFI_SUCCESS;
> +}
> +
> +/**
>    Software SMI handler that is called when an Ready To Boot event is signalled.
>    Then the SMM Core also install SMM Ready To Boot protocol to notify SMM
> driver
>    that system enter ready to boot.
> @@ -235,8 +272,11 @@ SmmReadyToBootHandler (
>    IN OUT UINTN       *CommBufferSize  OPTIONAL
>    )
>  {
> -  EFI_STATUS    Status;
> -  EFI_HANDLE    SmmHandle;
> +  EFI_STATUS                        Status;
> +  EFI_HANDLE                        SmmHandle;
> +  EFI_SMM_SX_DISPATCH2_PROTOCOL     *SxDispatch;
> +  EFI_SMM_SX_REGISTER_CONTEXT       EntryRegisterContext;
> +  EFI_HANDLE                        S3SleepEntryHandle;
> 
>    //
>    // Install SMM Ready To Boot protocol.
> @@ -251,7 +291,31 @@ SmmReadyToBootHandler (
> 
>    SmiHandlerUnRegister (DispatchHandle);
> 
> -  return Status;
> +  //
> +  // Locate SmmSxDispatch2 protocol.
> +  //
> +  Status = SmmLocateProtocol (
> +             &gEfiSmmSxDispatch2ProtocolGuid,
> +             NULL,
> +             &SxDispatch
> +             );
> +  if (!EFI_ERROR (Status)) {
> +    //
> +    // Register a S3 entry callback function to
> +    // determine if it will be during S3 resume.
> +    //
> +    EntryRegisterContext.Type  = SxS3;
> +    EntryRegisterContext.Phase = SxEntry;
> +    Status = SxDispatch->Register (
> +                           SxDispatch,
> +                           SmmS3EntryCallBack,
> +                           &EntryRegisterContext,
> +                           &S3SleepEntryHandle
> +                           );
> +    ASSERT_EFI_ERROR (Status);
> +  }
> +
> +  return EFI_SUCCESS;
>  }
> 
>  /**
> @@ -409,7 +473,12 @@ SmmEndOfS3ResumeHandler (
>    EFI_STATUS  Status;
>    EFI_HANDLE  SmmHandle;
> 
> -  DEBUG ((EFI_D_INFO, "SmmEndOfS3ResumeHandler\n"));
> +  DEBUG ((DEBUG_INFO, "SmmEndOfS3ResumeHandler\n"));
> +
> +  if (!mDuringS3Resume) {
> +    DEBUG ((DEBUG_ERROR, "It is not during S3 resume\n"));
> +    return EFI_ACCESS_DENIED;
> +  }
> 
>    //
>    // Install SMM EndOfS3Resume protocol
> @@ -434,6 +503,8 @@ SmmEndOfS3ResumeHandler (
>             );
>    ASSERT_EFI_ERROR (Status);
> 
> +  mDuringS3Resume = FALSE;
> +
>    return Status;
>  }
> 
> diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
> b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
> index 2729a434d8f8..8c10d833e2ae 100644
> --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
> +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
> @@ -33,6 +33,7 @@
>  #include <Protocol/SmmLegacyBoot.h>
>  #include <Protocol/SmmReadyToBoot.h>
>  #include <Protocol/SmmMemoryAttribute.h>
> +#include <Protocol/SmmSxDispatch2.h>
> 
>  #include <Guid/Apriori.h>
>  #include <Guid/EventGroup.h>
> diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf
> b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf
> index de0037fe4a99..5c04e851f94b 100644
> --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf
> +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf
> @@ -92,6 +92,7 @@ [Protocols]
>    gEfiSmmUsbDispatch2ProtocolGuid               ##
> SOMETIMES_CONSUMES
>    gEfiSmmCpuProtocolGuid                        ##
> SOMETIMES_CONSUMES
>    gEdkiiSmmMemoryAttributeProtocolGuid          ## CONSUMES
> +  gEfiSmmSxDispatch2ProtocolGuid                ##
> SOMETIMES_CONSUMES
> 
>  [Pcd]
> 
> gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressSmmCodePageNumber
> ## SOMETIMES_CONSUMES
> --
> 2.7.0.windows.1



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

end of thread, other threads:[~2017-12-11 13:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-11  8:36 [PATCH] MdeModulePkg PiSmmCore: Only install EndOfS3Resume during S3 resume Star Zeng
2017-12-11 13:23 ` Yao, Jiewen

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