]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
MdeModulePkg/PiSmmIpl: Check order of EndOfDxe and DxeSmmReadyToLock
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / PiSmmIpl.c
index 50c3b34dfd34d65819ea6a5e6eaf47b55ace8784..acfcc83e4f56b1e8499337d154a2aa7896d49f02 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SMM IPL that produces SMM related runtime protocols and load the SMM Core into SMRAM\r
 \r
-  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2016, 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
@@ -38,6 +38,7 @@
 #include <Library/UefiLib.h>\r
 #include <Library/UefiRuntimeLib.h>\r
 #include <Library/PcdLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
 \r
 #include "PiSmmCorePrivateData.h"\r
 \r
@@ -162,6 +163,20 @@ SmmIplGuidedEventNotify (
   IN VOID       *Context\r
   );\r
 \r
+/**\r
+  Event notification that is fired when EndOfDxe Event Group is signaled.\r
+\r
+  @param  Event                 The Event that is being processed, not used.\r
+  @param  Context               Event Context, not used.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+SmmIplEndOfDxeEventNotify (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  );\r
+\r
 /**\r
   Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r
 \r
@@ -243,6 +258,7 @@ EFI_SMM_CONTROL2_PROTOCOL  *mSmmControl2;
 EFI_SMM_ACCESS2_PROTOCOL   *mSmmAccess;\r
 EFI_SMRAM_DESCRIPTOR       *mCurrentSmramRange;\r
 BOOLEAN                    mSmmLocked = FALSE;\r
+BOOLEAN                    mEndOfDxe  = FALSE;\r
 EFI_PHYSICAL_ADDRESS       mSmramCacheBase;\r
 UINT64                     mSmramCacheSize;\r
 \r
@@ -271,6 +287,10 @@ SMM_IPL_EVENT_NOTIFICATION  mSmmIplEvents[] = {
   //\r
   { FALSE, TRUE,  &gEfiEndOfDxeEventGroupGuid,        SmmIplGuidedEventNotify,           &gEfiEndOfDxeEventGroupGuid,        TPL_CALLBACK, NULL },\r
   //\r
+  // Declare event notification on EndOfDxe event.  This is used to set EndOfDxe event signaled flag.\r
+  //\r
+  { FALSE, TRUE,  &gEfiEndOfDxeEventGroupGuid,        SmmIplEndOfDxeEventNotify,         &gEfiEndOfDxeEventGroupGuid,        TPL_CALLBACK, NULL },\r
+  //\r
   // Declare event notification on the DXE Dispatch Event Group.  This event is signaled by the DXE Core\r
   // each time the DXE Core dispatcher has completed its work.  When this event is signalled, the SMM Core\r
   // if notified, so the SMM Core can dispatch SMM drivers.\r
@@ -556,6 +576,23 @@ SmmIplGuidedEventNotify (
   SmmCommunicationCommunicate (&mSmmCommunication, &mCommunicateHeader, &Size);\r
 }\r
 \r
+/**\r
+  Event notification that is fired when EndOfDxe Event Group is signaled.\r
+\r
+  @param  Event                 The Event that is being processed, not used.\r
+  @param  Context               Event Context, not used.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+SmmIplEndOfDxeEventNotify (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  mEndOfDxe = TRUE;\r
+}\r
+\r
 /**\r
   Event notification that is fired when DxeDispatch Event Group is signaled.\r
 \r
@@ -711,6 +748,15 @@ SmmIplReadyToLockEventNotify (
     DEBUG ((DEBUG_WARN, "SMM IPL!  DXE SMM Ready To Lock Protocol not installed before Ready To Boot signal\n"));\r
   }\r
 \r
+  if (!mEndOfDxe) {\r
+    DEBUG ((DEBUG_ERROR, "EndOfDxe Event must be signaled before DxeSmmReadyToLock Protocol installation!\n"));\r
+    REPORT_STATUS_CODE (\r
+      EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED,\r
+      (EFI_SOFTWARE_SMM_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE)\r
+      );\r
+    ASSERT (FALSE);\r
+  }\r
+\r
   //\r
   // Lock the SMRAM (Note: Locking SMRAM may not be supported on all platforms)\r
   //\r