]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
MdeModulePkg: Fix unix style of EOL
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / PiSmmCore.c
index b877a3325f69bd4ab0d1f028109ce895cc68634d..a7467aca201229dfb9511540ec7f02641e285945 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SMM Core Main Entry Point\r
 \r
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2017, 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
@@ -75,13 +75,14 @@ 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
-  { SmmExitBootServicesHandler, &gEfiEventExitBootServicesGuid,     NULL, FALSE },\r
-  { SmmReadyToBootHandler,      &gEfiEventReadyToBootGuid,          NULL, FALSE },\r
-  { SmmEndOfDxeHandler,         &gEfiEndOfDxeEventGroupGuid,        NULL, TRUE },\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, TRUE },\r
+  { SmmEndOfS3ResumeHandler,    &gEdkiiSmmEndOfS3ResumeProtocolGuid, NULL, FALSE },\r
+  { NULL,                       NULL,                                NULL, FALSE }\r
 };\r
 \r
 UINTN                           mFullSmramRangeCount;\r
@@ -382,6 +383,60 @@ SmmEndOfDxeHandler (
   return Status;\r
 }\r
 \r
+/**\r
+  Software SMI handler that is called when the EndOfS3Resume event is trigged.\r
+  This function installs the SMM EndOfS3Resume Protocol so SMM Drivers are informed that\r
+  S3 resume has finished.\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
+SmmEndOfS3ResumeHandler (\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
+  DEBUG ((EFI_D_INFO, "SmmEndOfS3ResumeHandler\n"));\r
+\r
+  //\r
+  // Install SMM EndOfS3Resume protocol\r
+  //\r
+  SmmHandle = NULL;\r
+  Status = SmmInstallProtocolInterface (\r
+             &SmmHandle,\r
+             &gEdkiiSmmEndOfS3ResumeProtocolGuid,\r
+             EFI_NATIVE_INTERFACE,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Uninstall the protocol here because the comsume just hook the\r
+  // installation event.\r
+  //\r
+  Status = SmmUninstallProtocolInterface (\r
+           SmmHandle,\r
+           &gEdkiiSmmEndOfS3ResumeProtocolGuid,\r
+           NULL\r
+           );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
+\r
 /**\r
   Determine if two buffers overlap in memory.\r
 \r
@@ -432,6 +487,8 @@ SmmEntryPoint (
   EFI_SMM_COMMUNICATE_HEADER  *CommunicateHeader;\r
   BOOLEAN                     InLegacyBoot;\r
   BOOLEAN                     IsOverlapped;\r
+  VOID                        *CommunicationBuffer;\r
+  UINTN                       BufferSize;\r
 \r
   PERF_START (NULL, "SMM", NULL, 0) ;\r
 \r
@@ -449,6 +506,11 @@ SmmEntryPoint (
   //\r
   PlatformHookBeforeSmmDispatch ();\r
 \r
+  //\r
+  // Call memory management hook function\r
+  //\r
+  SmmEntryPointMemoryManagementHook ();\r
+\r
   //\r
   // If a legacy boot has occured, then make sure gSmmCorePrivate is not accessed\r
   //\r
@@ -463,17 +525,19 @@ SmmEntryPoint (
     // Check to see if this is a Synchronous SMI sent through the SMM Communication \r
     // Protocol or an Asynchronous SMI\r
     //\r
-    if (gSmmCorePrivate->CommunicationBuffer != NULL) {\r
+    CommunicationBuffer = gSmmCorePrivate->CommunicationBuffer;\r
+    BufferSize          = gSmmCorePrivate->BufferSize;\r
+    if (CommunicationBuffer != NULL) {\r
       //\r
       // Synchronous SMI for SMM Core or request from Communicate protocol\r
       //\r
       IsOverlapped = InternalIsBufferOverlapped (\r
-                       (UINT8 *) gSmmCorePrivate->CommunicationBuffer,\r
-                       gSmmCorePrivate->BufferSize,\r
+                       (UINT8 *) CommunicationBuffer,\r
+                       BufferSize,\r
                        (UINT8 *) gSmmCorePrivate,\r
                        sizeof (*gSmmCorePrivate)\r
                        );\r
-      if (!SmmIsBufferOutsideSmmValid ((UINTN)gSmmCorePrivate->CommunicationBuffer, gSmmCorePrivate->BufferSize) || IsOverlapped) {\r
+      if (!SmmIsBufferOutsideSmmValid ((UINTN)CommunicationBuffer, BufferSize) || IsOverlapped) {\r
         //\r
         // If CommunicationBuffer is not in valid address scope,\r
         // or there is overlap between gSmmCorePrivate and CommunicationBuffer,\r
@@ -482,19 +546,19 @@ SmmEntryPoint (
         gSmmCorePrivate->CommunicationBuffer = NULL;\r
         gSmmCorePrivate->ReturnStatus = EFI_INVALID_PARAMETER;\r
       } else {\r
-        CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)gSmmCorePrivate->CommunicationBuffer;\r
-        gSmmCorePrivate->BufferSize -= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);\r
+        CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)CommunicationBuffer;\r
+        BufferSize -= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);\r
         Status = SmiManage (\r
                    &CommunicateHeader->HeaderGuid, \r
                    NULL, \r
                    CommunicateHeader->Data, \r
-                   &gSmmCorePrivate->BufferSize\r
+                   &BufferSize\r
                    );\r
         //\r
         // Update CommunicationBuffer, BufferSize and ReturnStatus\r
         // Communicate service finished, reset the pointer to CommBuffer to NULL\r
         //\r
-        gSmmCorePrivate->BufferSize += OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);\r
+        gSmmCorePrivate->BufferSize = BufferSize + OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);\r
         gSmmCorePrivate->CommunicationBuffer = NULL;\r
         gSmmCorePrivate->ReturnStatus = (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND;\r
       }\r
@@ -640,7 +704,7 @@ SmmMain (
   //\r
   gSmmCorePrivate->Smst          = &gSmmCoreSmst;\r
   gSmmCorePrivate->SmmEntryPoint = SmmEntryPoint;\r
-  \r
+\r
   //\r
   // No need to initialize memory service.\r
   // It is done in constructor of PiSmmCoreMemoryAllocationLib(),\r
@@ -676,5 +740,7 @@ SmmMain (
 \r
   SmmCoreInitializeMemoryAttributesTable ();\r
 \r
+  SmmCoreInitializeSmiHandlerProfile ();\r
+\r
   return EFI_SUCCESS;\r
 }\r