]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
MdeModulePkg PiSmmCore: Introduce SMM Exit Boot Services and Legacy Boot.
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / PiSmmCore.c
index 187cb8e68e4870322c22cff6e3c6f127424f20e1..852f8b90f687d0426a870daa96929a92d2cc68cb 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SMM Core Main Entry Point\r
 \r
-  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2015, 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
@@ -66,7 +66,7 @@ EFI_SMM_SYSTEM_TABLE2  gSmmCoreSmst = {
 //\r
 // Flag to determine if the platform has performed a legacy boot.\r
 // If this flag is TRUE, then the runtime code and runtime data associated with the \r
-// SMM IPL are converted to free memory, so the SMM COre must guarantee that is\r
+// SMM IPL are converted to free memory, so the SMM Core must guarantee that is\r
 // does not touch of the code/data associated with the SMM IPL if this flag is TRUE.\r
 //\r
 BOOLEAN  mInLegacyBoot = FALSE;\r
@@ -75,11 +75,13 @@ BOOLEAN  mInLegacyBoot = FALSE;
 // Table of SMI Handlers that are registered by the SMM Core when it is initialized\r
 //\r
 SMM_CORE_SMI_HANDLERS  mSmmCoreSmiHandlers[] = {\r
-  { SmmDriverDispatchHandler, &gEfiEventDxeDispatchGuid,          NULL, TRUE  },\r
-  { SmmReadyToLockHandler,    &gEfiDxeSmmReadyToLockProtocolGuid, NULL, TRUE }, \r
-  { SmmLegacyBootHandler,     &gEfiEventLegacyBootGuid,           NULL, FALSE },\r
-  { SmmEndOfDxeHandler,       &gEfiEndOfDxeEventGroupGuid,        NULL, FALSE },\r
-  { NULL,                     NULL,                               NULL, FALSE }\r
+  { SmmDriverDispatchHandler,   &gEfiEventDxeDispatchGuid,          NULL, TRUE  },\r
+  { SmmReadyToLockHandler,      &gEfiDxeSmmReadyToLockProtocolGuid, NULL, TRUE }, \r
+  { SmmLegacyBootHandler,       &gEfiEventLegacyBootGuid,           NULL, FALSE },\r
+  { SmmExitBootServicesHandler, &gEfiEventExitBootServicesGuid,     NULL, FALSE },\r
+  { SmmReadyToBootHandler,      &gEfiEventReadyToBootGuid,          NULL, FALSE },\r
+  { SmmEndOfDxeHandler,         &gEfiEndOfDxeEventGroupGuid,        NULL, FALSE },\r
+  { NULL,                       NULL,                               NULL, FALSE }\r
 };\r
 \r
 UINTN                           mFullSmramRangeCount;\r
@@ -121,7 +123,8 @@ SmmEfiNotAvailableYetArg5 (
   Core uses this signal to know that a Legacy Boot has been performed and that \r
   gSmmCorePrivate that is shared between the UEFI and SMM execution environments can\r
   not be accessed from SMM anymore since that structure is considered free memory by\r
-  a legacy OS.\r
+  a legacy OS. Then the SMM Core also install SMM Legacy Boot protocol to notify SMM\r
+  driver that system enter legacy boot.\r
 \r
   @param  DispatchHandle  The unique handle assigned to this handler by SmiHandlerRegister().\r
   @param  Context         Points to an optional handler context which was specified when the handler was registered.\r
@@ -141,8 +144,109 @@ SmmLegacyBootHandler (
   IN OUT UINTN       *CommBufferSize  OPTIONAL\r
   )\r
 {\r
+  EFI_STATUS    Status;\r
+  EFI_HANDLE    SmmHandle;\r
+\r
+  //\r
+  // Install SMM Legacy Boot protocol.\r
+  //\r
+  SmmHandle = NULL;\r
+  Status = SmmInstallProtocolInterface (\r
+             &SmmHandle,\r
+             &gEdkiiSmmLegacyBootProtocolGuid,\r
+             EFI_NATIVE_INTERFACE,\r
+             NULL\r
+             );\r
+\r
   mInLegacyBoot = TRUE;\r
-  return EFI_SUCCESS;\r
+\r
+  SmiHandlerUnRegister (DispatchHandle);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Software SMI handler that is called when an Exit Boot Services event is signalled.\r
+  Then the SMM Core also install SMM Exit Boot Services protocol to notify SMM driver\r
+  that system enter exit boot services.\r
+\r
+  @param  DispatchHandle  The unique handle assigned to this handler by SmiHandlerRegister().\r
+  @param  Context         Points to an optional handler context which was specified when the handler was registered.\r
+  @param  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  CommBufferSize  The size of the CommBuffer.\r
+\r
+  @return Status Code\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmExitBootServicesHandler (\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
+  EFI_STATUS    Status;\r
+  EFI_HANDLE    SmmHandle;\r
+\r
+  //\r
+  // Install SMM Exit Boot Services protocol.\r
+  //\r
+  SmmHandle = NULL;\r
+  Status = SmmInstallProtocolInterface (\r
+             &SmmHandle,\r
+             &gEdkiiSmmExitBootServicesProtocolGuid,\r
+             EFI_NATIVE_INTERFACE,\r
+             NULL\r
+             );\r
+\r
+  SmiHandlerUnRegister (DispatchHandle);\r
+\r
+  return Status;\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
+  that system enter ready to boot.\r
+\r
+  @param  DispatchHandle  The unique handle assigned to this handler by SmiHandlerRegister().\r
+  @param  Context         Points to an optional handler context which was specified when the handler was registered.\r
+  @param  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  CommBufferSize  The size of the CommBuffer.\r
+\r
+  @return Status Code\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmReadyToBootHandler (\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
+  EFI_STATUS    Status;\r
+  EFI_HANDLE    SmmHandle;\r
+\r
+  //\r
+  // Install SMM Ready To Boot protocol.\r
+  //\r
+  SmmHandle = NULL;\r
+  Status = SmmInstallProtocolInterface (\r
+             &SmmHandle,\r
+             &gEdkiiSmmReadyToBootProtocolGuid,\r
+             EFI_NATIVE_INTERFACE,\r
+             NULL\r
+             );\r
+\r
+  SmiHandlerUnRegister (DispatchHandle);\r
+\r
+  return Status;\r
 }\r
 \r
 /**\r