]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
MdeModulePkg/PiSmmCore: Control S3 related functionality through flag.
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / PiSmmCore.c
index d0bc65b5644e35b18c1793ca31e83910f2659ec8..0d57b7bed5fdf30d11fcef05bd4b52377f1633ee 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SMM Core Main Entry Point\r
 \r
-  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials are licensed and made available\r
   under the terms and conditions of the BSD License which accompanies this\r
   distribution.  The full text of the license may be found at\r
@@ -77,6 +77,12 @@ BOOLEAN  mInLegacyBoot = FALSE;
 //\r
 BOOLEAN  mDuringS3Resume = FALSE;\r
 \r
+//\r
+// Flag to determine if platform enabled S3.\r
+// Get the value from PcdAcpiS3Enable.\r
+//\r
+BOOLEAN  mAcpiS3Enable = FALSE;\r
+\r
 //\r
 // Table of SMI Handlers that are registered by the SMM Core when it is initialized\r
 //\r
@@ -87,6 +93,13 @@ SMM_CORE_SMI_HANDLERS  mSmmCoreSmiHandlers[] = {
   { SmmExitBootServicesHandler, &gEfiEventExitBootServicesGuid,      NULL, FALSE },\r
   { SmmReadyToBootHandler,      &gEfiEventReadyToBootGuid,           NULL, FALSE },\r
   { SmmEndOfDxeHandler,         &gEfiEndOfDxeEventGroupGuid,         NULL, TRUE },\r
+  { NULL,                       NULL,                                NULL, FALSE }\r
+};\r
+\r
+//\r
+// Table of SMI Handlers that are registered by the SMM Core when it is initialized\r
+//\r
+SMM_CORE_SMI_HANDLERS  mSmmCoreS3SmiHandlers[] = {\r
   { SmmS3SmmInitDoneHandler,    &gEdkiiS3SmmInitDoneGuid,            NULL, FALSE },\r
   { SmmEndOfS3ResumeHandler,    &gEdkiiEndOfS3ResumeGuid,            NULL, FALSE },\r
   { NULL,                       NULL,                                NULL, FALSE }\r
@@ -445,28 +458,30 @@ SmmEndOfDxeHandler (
              NULL\r
              );\r
 \r
-  //\r
-  // Locate SmmSxDispatch2 protocol.\r
-  //\r
-  Status = SmmLocateProtocol (\r
-             &gEfiSmmSxDispatch2ProtocolGuid,\r
-             NULL,\r
-             (VOID **)&SxDispatch\r
-             );\r
-  if (!EFI_ERROR (Status) && (SxDispatch != NULL)) {\r
+  if (mAcpiS3Enable) {\r
     //\r
-    // Register a S3 entry callback function to\r
-    // determine if it will be during S3 resume.\r
+    // Locate SmmSxDispatch2 protocol.\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
+    Status = SmmLocateProtocol (\r
+               &gEfiSmmSxDispatch2ProtocolGuid,\r
+               NULL,\r
+               (VOID **)&SxDispatch\r
+               );\r
+    if (!EFI_ERROR (Status) && (SxDispatch != NULL)) {\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
 \r
   return EFI_SUCCESS;\r
@@ -883,6 +898,21 @@ SmmMain (
     ASSERT_EFI_ERROR (Status);\r
   }\r
 \r
+  mAcpiS3Enable = PcdGetBool (PcdAcpiS3Enable);\r
+  if (mAcpiS3Enable) {\r
+    //\r
+    // Register all S3 related SMI Handlers required by the SMM Core\r
+    //\r
+    for (Index = 0; mSmmCoreS3SmiHandlers[Index].HandlerType != NULL; Index++) {\r
+      Status = SmiHandlerRegister (\r
+                 mSmmCoreS3SmiHandlers[Index].Handler,\r
+                 mSmmCoreS3SmiHandlers[Index].HandlerType,\r
+                 &mSmmCoreS3SmiHandlers[Index].DispatchHandle\r
+                 );\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+  }\r
+\r
   RegisterSmramProfileHandler ();\r
   SmramProfileInstallProtocol ();\r
 \r