]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg PiSmmCore: Only install EndOfS3Resume during S3 resume
authorStar Zeng <star.zeng@intel.com>
Fri, 8 Dec 2017 10:44:40 +0000 (18:44 +0800)
committerStar Zeng <star.zeng@intel.com>
Tue, 12 Dec 2017 10:30:06 +0000 (18:30 +0800)
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>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf

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