]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c
MdeModulePkg PiSmmCore: Set ForwardLink to NULL in RemoveOldEntry()
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / SmramProfileRecord.c
index d983cefbb3dc18b97db0084a3c8981717efa41f3..410e0836fd1641c59cfd83905f32f5a58be4e09d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Support routines for SMRAM profile.\r
 \r
-  Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -77,11 +77,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mSmramProfileContext =
 };\r
 GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA *mSmramProfileContextPtr = NULL;\r
 \r
-BOOLEAN mSmramReadyToLock;\r
-BOOLEAN mSmramProfileGettingStatus = FALSE;\r
-BOOLEAN mSmramProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE;\r
-EFI_DEVICE_PATH_PROTOCOL *mSmramProfileDriverPath;\r
-UINTN                    mSmramProfileDriverPathSize;\r
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSmramReadyToLock;\r
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSmramProfileGettingStatus = FALSE;\r
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSmramProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE;\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_PROTOCOL *mSmramProfileDriverPath;\r
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN                    mSmramProfileDriverPathSize;\r
 \r
 /**\r
   Dump SMRAM infromation.\r
@@ -232,7 +232,7 @@ SmramProfileProtocolRecord (
   IN CHAR8                              *ActionString OPTIONAL\r
   );\r
 \r
-EDKII_SMM_MEMORY_PROFILE_PROTOCOL mSmmProfileProtocol = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED EDKII_SMM_MEMORY_PROFILE_PROTOCOL mSmmProfileProtocol = {\r
   SmramProfileProtocolGetData,\r
   SmramProfileProtocolRegisterImage,\r
   SmramProfileProtocolUnregisterImage,\r
@@ -1596,6 +1596,7 @@ SmramProfileGetDataSize (
   FREE_POOL_HEADER                  *Pool;\r
   UINTN                             PoolListIndex;\r
   UINTN                             Index;\r
+  UINTN                             SmmPoolTypeIndex;\r
 \r
   ContextData = GetSmramProfileContext ();\r
   if (ContextData == NULL) {\r
@@ -1638,19 +1639,20 @@ SmramProfileGetDataSize (
        Node = Node->BackLink) {\r
     Index++;\r
   }\r
-  for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {\r
-    FreePoolList = &mSmmPoolLists[PoolListIndex];\r
-    for (Node = FreePoolList->BackLink;\r
-         Node != FreePoolList;\r
-         Node = Node->BackLink) {\r
-      Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);\r
-      if (Pool->Header.Available) {\r
-        Index++;\r
+  for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {\r
+    for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {\r
+      FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][PoolListIndex];\r
+      for (Node = FreePoolList->BackLink;\r
+           Node != FreePoolList;\r
+           Node = Node->BackLink) {\r
+        Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);\r
+        if (Pool->Header.Available) {\r
+          Index++;\r
+        }\r
       }\r
     }\r
   }\r
 \r
-\r
   TotalSize += (sizeof (MEMORY_PROFILE_FREE_MEMORY) + Index * sizeof (MEMORY_PROFILE_DESCRIPTOR));\r
   TotalSize += (sizeof (MEMORY_PROFILE_MEMORY_RANGE) + mFullSmramRangeCount * sizeof (MEMORY_PROFILE_DESCRIPTOR));\r
 \r
@@ -1698,6 +1700,7 @@ SmramProfileCopyData (
   UINT64                          RemainingSize;\r
   UINTN                           PdbSize;\r
   UINTN                           ActionStringSize;\r
+  UINTN                           SmmPoolTypeIndex;\r
 \r
   ContextData = GetSmramProfileContext ();\r
   if (ContextData == NULL) {\r
@@ -1785,14 +1788,16 @@ SmramProfileCopyData (
            Node = Node->BackLink) {\r
         Index++;\r
       }\r
-      for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {\r
-        FreePoolList = &mSmmPoolLists[MAX_POOL_INDEX - PoolListIndex - 1];\r
-        for (Node = FreePoolList->BackLink;\r
-             Node != FreePoolList;\r
-             Node = Node->BackLink) {\r
-          Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);\r
-          if (Pool->Header.Available) {\r
-            Index++;\r
+      for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {\r
+        for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {\r
+          FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][MAX_POOL_INDEX - PoolListIndex - 1];\r
+          for (Node = FreePoolList->BackLink;\r
+               Node != FreePoolList;\r
+               Node = Node->BackLink) {\r
+            Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);\r
+            if (Pool->Header.Available) {\r
+              Index++;\r
+            }\r
           }\r
         }\r
       }\r
@@ -1827,29 +1832,31 @@ SmramProfileCopyData (
     }\r
     Offset += sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
   }\r
-  for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {\r
-    FreePoolList = &mSmmPoolLists[MAX_POOL_INDEX - PoolListIndex - 1];\r
-    for (Node = FreePoolList->BackLink;\r
-         Node != FreePoolList;\r
-         Node = Node->BackLink) {\r
-      Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);\r
-      if (Pool->Header.Available) {\r
-        if (*ProfileOffset < (Offset + sizeof (MEMORY_PROFILE_DESCRIPTOR))) {\r
-          if (RemainingSize >= sizeof (MEMORY_PROFILE_DESCRIPTOR)) {\r
-            MemoryProfileDescriptor = ProfileBuffer;\r
-            MemoryProfileDescriptor->Header.Signature = MEMORY_PROFILE_DESCRIPTOR_SIGNATURE;\r
-            MemoryProfileDescriptor->Header.Length = sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
-            MemoryProfileDescriptor->Header.Revision = MEMORY_PROFILE_DESCRIPTOR_REVISION;\r
-            MemoryProfileDescriptor->Address = (PHYSICAL_ADDRESS) (UINTN) Pool;\r
-            MemoryProfileDescriptor->Size = Pool->Header.Size;\r
-\r
-            RemainingSize -= sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
-            ProfileBuffer = (UINT8 *) ProfileBuffer + sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
-          } else {\r
-            goto Done;\r
+  for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {\r
+    for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {\r
+      FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][MAX_POOL_INDEX - PoolListIndex - 1];\r
+      for (Node = FreePoolList->BackLink;\r
+           Node != FreePoolList;\r
+           Node = Node->BackLink) {\r
+        Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);\r
+        if (Pool->Header.Available) {\r
+          if (*ProfileOffset < (Offset + sizeof (MEMORY_PROFILE_DESCRIPTOR))) {\r
+            if (RemainingSize >= sizeof (MEMORY_PROFILE_DESCRIPTOR)) {\r
+              MemoryProfileDescriptor = ProfileBuffer;\r
+              MemoryProfileDescriptor->Header.Signature = MEMORY_PROFILE_DESCRIPTOR_SIGNATURE;\r
+              MemoryProfileDescriptor->Header.Length = sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
+              MemoryProfileDescriptor->Header.Revision = MEMORY_PROFILE_DESCRIPTOR_REVISION;\r
+              MemoryProfileDescriptor->Address = (PHYSICAL_ADDRESS) (UINTN) Pool;\r
+              MemoryProfileDescriptor->Size = Pool->Header.Size;\r
+\r
+              RemainingSize -= sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
+              ProfileBuffer = (UINT8 *) ProfileBuffer + sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
+            } else {\r
+              goto Done;\r
+            }\r
           }\r
+          Offset += sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
         }\r
-        Offset += sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
       }\r
     }\r
   }\r
@@ -2577,6 +2584,7 @@ DumpFreePoolList (
   UINTN                         PoolListIndex;\r
   MEMORY_PROFILE_CONTEXT_DATA   *ContextData;\r
   BOOLEAN                       SmramProfileGettingStatus;\r
+  UINTN                         SmmPoolTypeIndex;\r
 \r
   ContextData = GetSmramProfileContext ();\r
   if (ContextData == NULL) {\r
@@ -2586,23 +2594,25 @@ DumpFreePoolList (
   SmramProfileGettingStatus = mSmramProfileGettingStatus;\r
   mSmramProfileGettingStatus = TRUE;\r
 \r
-  DEBUG ((EFI_D_INFO, "======= SmramProfile begin =======\n"));\r
-\r
-  for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {\r
-    DEBUG ((EFI_D_INFO, "FreePoolList (%d):\n", PoolListIndex));\r
-    FreePoolList = &mSmmPoolLists[PoolListIndex];\r
-    for (Node = FreePoolList->BackLink, Index = 0;\r
-         Node != FreePoolList;\r
-         Node = Node->BackLink, Index++) {\r
-      Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);\r
-      DEBUG ((EFI_D_INFO, "  Index - 0x%x\n", Index));\r
-      DEBUG ((EFI_D_INFO, "    PhysicalStart - 0x%016lx\n", (PHYSICAL_ADDRESS) (UINTN) Pool));\r
-      DEBUG ((EFI_D_INFO, "    Size          - 0x%08x\n", Pool->Header.Size));\r
-      DEBUG ((EFI_D_INFO, "    Available     - 0x%02x\n", Pool->Header.Available));\r
+  DEBUG ((DEBUG_INFO, "======= SmramProfile begin =======\n"));\r
+\r
+  for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {\r
+    for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {\r
+      DEBUG ((DEBUG_INFO, "FreePoolList(%d)(%d):\n", SmmPoolTypeIndex, PoolListIndex));\r
+      FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][PoolListIndex];\r
+      for (Node = FreePoolList->BackLink, Index = 0;\r
+           Node != FreePoolList;\r
+           Node = Node->BackLink, Index++) {\r
+        Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);\r
+        DEBUG ((DEBUG_INFO, "  Index - 0x%x\n", Index));\r
+        DEBUG ((DEBUG_INFO, "    PhysicalStart - 0x%016lx\n", (PHYSICAL_ADDRESS) (UINTN) Pool));\r
+        DEBUG ((DEBUG_INFO, "    Size          - 0x%08x\n", Pool->Header.Size));\r
+        DEBUG ((DEBUG_INFO, "    Available     - 0x%02x\n", Pool->Header.Available));\r
+      }\r
     }\r
   }\r
 \r
-  DEBUG ((EFI_D_INFO, "======= SmramProfile end =======\n"));\r
+  DEBUG ((DEBUG_INFO, "======= SmramProfile end =======\n"));\r
 \r
   mSmramProfileGettingStatus = SmramProfileGettingStatus;\r
 }\r
@@ -2620,7 +2630,7 @@ typedef struct {
   CHAR8                 *String;\r
 } ACTION_STRING;\r
 \r
-ACTION_STRING mExtActionString[] = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED ACTION_STRING mExtActionString[] = {\r
   {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_PAGES,                    "Lib:AllocatePages"},\r
   {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_PAGES,            "Lib:AllocateRuntimePages"},\r
   {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_PAGES,           "Lib:AllocateReservedPages"},\r
@@ -2644,8 +2654,6 @@ ACTION_STRING mExtActionString[] = {
   {MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RESERVED_POOL,          "Lib:ReallocateReservedPool"},\r
 };\r
 \r
-GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mUserDefinedActionString[] = {"UserDefined-0x80000000"};\r
-\r
 typedef struct {\r
   EFI_MEMORY_TYPE   MemoryType;\r
   CHAR8             *MemoryTypeStr;\r