]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/PiSmmCore/Smi.c
MdeModulePkg/PiSmmCore: Add SmiHandlerProfile support.
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / Smi.c
index 1111959c3a40f34332caddc30e7e59ed93508612..ad483a1877ce129d71d3440a73bfb75841a32727 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SMI management.\r
 \r
-  Copyright (c) 2009 - 2012, 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
 \r
 #include "PiSmmCore.h"\r
 \r
-//\r
-// SMM_HANDLER - used for each SMM handler\r
-//\r
-\r
-#define SMI_ENTRY_SIGNATURE  SIGNATURE_32('s','m','i','e')\r
-\r
- typedef struct {\r
-  UINTN       Signature;\r
-  LIST_ENTRY  AllEntries;  // All entries\r
-\r
-  EFI_GUID    HandlerType; // Type of interrupt\r
-  LIST_ENTRY  SmiHandlers; // All handlers\r
-} SMI_ENTRY;\r
-\r
-#define SMI_HANDLER_SIGNATURE  SIGNATURE_32('s','m','i','h')\r
-\r
- typedef struct {\r
-  UINTN                         Signature;\r
-  LIST_ENTRY                    Link;        // Link on SMI_ENTRY.SmiHandlers\r
-  EFI_SMM_HANDLER_ENTRY_POINT2  Handler;     // The smm handler's entry point\r
-  SMI_ENTRY                     *SmiEntry;\r
-} SMI_HANDLER;\r
-\r
-LIST_ENTRY  mRootSmiHandlerList = INITIALIZE_LIST_HEAD_VARIABLE (mRootSmiHandlerList);\r
 LIST_ENTRY  mSmiEntryList       = INITIALIZE_LIST_HEAD_VARIABLE (mSmiEntryList);\r
 \r
+SMI_ENTRY   mRootSmiEntry = {\r
+  SMI_ENTRY_SIGNATURE,\r
+  INITIALIZE_LIST_HEAD_VARIABLE (mRootSmiEntry.AllEntries),\r
+  {0},\r
+  INITIALIZE_LIST_HEAD_VARIABLE (mRootSmiEntry.SmiHandlers),\r
+};\r
+\r
 /**\r
   Finds the SMI entry for the requested handler type.\r
 \r
@@ -128,17 +111,16 @@ SmiManage (
   LIST_ENTRY   *Head;\r
   SMI_ENTRY    *SmiEntry;\r
   SMI_HANDLER  *SmiHandler;\r
-  BOOLEAN      InterruptQuiesced;\r
+  BOOLEAN      SuccessReturn;\r
   EFI_STATUS   Status;\r
   \r
   Status = EFI_NOT_FOUND;\r
-  InterruptQuiesced = FALSE;\r
+  SuccessReturn = FALSE;\r
   if (HandlerType == NULL) {\r
     //\r
     // Root SMI handler\r
     //\r
-\r
-    Head = &mRootSmiHandlerList;\r
+    SmiEntry = &mRootSmiEntry;\r
   } else {\r
     //\r
     // Non-root SMI handler\r
@@ -150,9 +132,8 @@ SmiManage (
       //\r
       return Status;\r
     }\r
-\r
-    Head = &SmiEntry->SmiHandlers;\r
   }\r
+  Head = &SmiEntry->SmiHandlers;\r
 \r
   for (Link = Head->ForwardLink; Link != Head; Link = Link->ForwardLink) {\r
     SmiHandler = CR (Link, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);\r
@@ -167,8 +148,8 @@ SmiManage (
     switch (Status) {\r
     case EFI_INTERRUPT_PENDING:\r
       //\r
-      // If a handler returns EFI_INTERRUPT_PENDING then no additional handlers \r
-      // will be processed and EFI_INTERRUPT_PENDING will be returned.\r
+      // If a handler returns EFI_INTERRUPT_PENDING and HandlerType is not NULL then\r
+      // no additional handlers will be processed and EFI_INTERRUPT_PENDING will be returned.\r
       //\r
       if (HandlerType != NULL) {\r
         return EFI_INTERRUPT_PENDING;\r
@@ -177,12 +158,14 @@ SmiManage (
 \r
     case EFI_SUCCESS:\r
       //\r
-      // If a handler returns EFI_SUCCESS then no additional handlers will be processed.\r
-      // then the function will return EFI_SUCCESS.\r
+      // If at least one of the handlers returns EFI_SUCCESS then the function will return\r
+      // EFI_SUCCESS. If a handler returns EFI_SUCCESS and HandlerType is not NULL then no\r
+      // additional handlers will be processed.\r
       //\r
       if (HandlerType != NULL) {\r
         return EFI_SUCCESS;\r
       }\r
+      SuccessReturn = TRUE;\r
       break;\r
 \r
     case EFI_WARN_INTERRUPT_SOURCE_QUIESCED:\r
@@ -190,7 +173,7 @@ SmiManage (
       // If at least one of the handlers returns EFI_WARN_INTERRUPT_SOURCE_QUIESCED\r
       // then the function will return EFI_SUCCESS. \r
       //\r
-      InterruptQuiesced = TRUE;\r
+      SuccessReturn = TRUE;\r
       break;\r
 \r
     case EFI_WARN_INTERRUPT_SOURCE_PENDING:\r
@@ -209,7 +192,7 @@ SmiManage (
     }\r
   }\r
 \r
-  if (InterruptQuiesced) {\r
+  if (SuccessReturn) {\r
     Status = EFI_SUCCESS;\r
   }\r
 \r
@@ -250,13 +233,13 @@ SmiHandlerRegister (
 \r
   SmiHandler->Signature = SMI_HANDLER_SIGNATURE;\r
   SmiHandler->Handler = Handler;\r
+  SmiHandler->CallerAddr = (UINTN)RETURN_ADDRESS (0);\r
 \r
   if (HandlerType == NULL) {\r
     //\r
     // This is root SMI handler\r
     //\r
-    SmiEntry = NULL;\r
-    List = &mRootSmiHandlerList;\r
+    SmiEntry = &mRootSmiEntry;\r
   } else {\r
     //\r
     // None root SMI handler\r
@@ -265,9 +248,8 @@ SmiHandlerRegister (
     if (SmiEntry == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
-\r
-    List = &SmiEntry->SmiHandlers;\r
   }\r
+  List = &SmiEntry->SmiHandlers;\r
 \r
   SmiHandler->SmiEntry = SmiEntry;\r
   InsertTailList (List, &SmiHandler->Link);\r