]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c
MdeModulePkg/Core/PiSmmCore: Fix various typos
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / SmramProfileRecord.c
index ac832ce38c740c096459f6914f9a35a760088d24..1b302c810cc927d6757a088ef7ac98896d9190d2 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   Support routines for SMRAM profile.\r
 \r
-  Copyright (c) 2014 - 2016, 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
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -77,14 +71,14 @@ 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
+  Dump SMRAM information.\r
 \r
 **/\r
 VOID\r
@@ -99,10 +93,10 @@ DumpSmramInfo (
   @param[in, out] ProfileSize       On entry, points to the size in bytes of the ProfileBuffer.\r
                                     On return, points to the size of the data returned in ProfileBuffer.\r
   @param[out]     ProfileBuffer     Profile buffer.\r
-                      \r
+\r
   @return EFI_SUCCESS               Get the memory profile data successfully.\r
   @return EFI_UNSUPPORTED           Memory profile is unsupported.\r
-  @return EFI_BUFFER_TO_SMALL       The ProfileSize is too small for the resulting data. \r
+  @return EFI_BUFFER_TO_SMALL       The ProfileSize is too small for the resulting data.\r
                                     ProfileSize is updated with the size required.\r
 \r
 **/\r
@@ -232,7 +226,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
@@ -255,35 +249,6 @@ GetSmramProfileContext (
   return mSmramProfileContextPtr;\r
 }\r
 \r
-/**\r
-  Retrieves the magic value from the PE/COFF header.\r
-\r
-  @param Hdr    The buffer in which to return the PE32, PE32+, or TE header.\r
-\r
-  @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32\r
-  @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+\r
-\r
-**/\r
-UINT16\r
-InternalPeCoffGetPeHeaderMagicValue (\r
-  IN  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr\r
-  )\r
-{\r
-  //\r
-  // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value\r
-  //       in the PE/COFF Header.  If the MachineType is Itanium(IA64) and the\r
-  //       Magic value in the OptionalHeader is  EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC\r
-  //       then override the returned value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC\r
-  //\r
-  if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
-    return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;\r
-  }\r
-  //\r
-  // Return the magic value from the PC/COFF Optional Header\r
-  //\r
-  return Hdr.Pe32->OptionalHeader.Magic;\r
-}\r
-\r
 /**\r
   Retrieves and returns the Subsystem of a PE/COFF image that has been loaded into system memory.\r
   If Pe32Data is NULL, then ASSERT().\r
@@ -320,7 +285,7 @@ InternalPeCoffGetSubsystem (
   if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
     return Hdr.Te->Subsystem;\r
   } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)  {\r
-    Magic = InternalPeCoffGetPeHeaderMagicValue (Hdr);\r
+    Magic = Hdr.Pe32->OptionalHeader.Magic;\r
     if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
       return Hdr.Pe32->OptionalHeader.Subsystem;\r
     } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
@@ -443,6 +408,7 @@ BuildDriverInfo (
   if (EFI_ERROR (Status)) {\r
     return NULL;\r
   }\r
+  ASSERT (DriverInfoData != NULL);\r
 \r
   ZeroMem (DriverInfoData, sizeof (*DriverInfoData));\r
 \r
@@ -593,7 +559,7 @@ NeedRecordThisDriver (
     //\r
     return TRUE;\r
   }\r
-  \r
+\r
   //\r
   // Record FilePath without end node.\r
   //\r
@@ -1595,6 +1561,7 @@ SmramProfileGetDataSize (
   FREE_POOL_HEADER                  *Pool;\r
   UINTN                             PoolListIndex;\r
   UINTN                             Index;\r
+  UINTN                             SmmPoolTypeIndex;\r
 \r
   ContextData = GetSmramProfileContext ();\r
   if (ContextData == NULL) {\r
@@ -1637,19 +1604,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
@@ -1697,6 +1665,7 @@ SmramProfileCopyData (
   UINT64                          RemainingSize;\r
   UINTN                           PdbSize;\r
   UINTN                           ActionStringSize;\r
+  UINTN                           SmmPoolTypeIndex;\r
 \r
   ContextData = GetSmramProfileContext ();\r
   if (ContextData == NULL) {\r
@@ -1784,14 +1753,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
@@ -1826,29 +1797,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
@@ -1905,10 +1878,10 @@ Done:
   @param[in, out] ProfileSize       On entry, points to the size in bytes of the ProfileBuffer.\r
                                     On return, points to the size of the data returned in ProfileBuffer.\r
   @param[out]     ProfileBuffer     Profile buffer.\r
-                      \r
+\r
   @return EFI_SUCCESS               Get the memory profile data successfully.\r
   @return EFI_UNSUPPORTED           Memory profile is unsupported.\r
-  @return EFI_BUFFER_TO_SMALL       The ProfileSize is too small for the resulting data. \r
+  @return EFI_BUFFER_TO_SMALL       The ProfileSize is too small for the resulting data.\r
                                     ProfileSize is updated with the size required.\r
 \r
 **/\r
@@ -1978,7 +1951,7 @@ SmramProfileProtocolRegisterImage (
   EFI_SMM_DRIVER_ENTRY              DriverEntry;\r
   VOID                              *EntryPointInImage;\r
   EFI_GUID                          *Name;\r
-  \r
+\r
   ZeroMem (&DriverEntry, sizeof (DriverEntry));\r
   Name = GetFileNameFromFilePath (FilePath);\r
   if (Name != NULL) {\r
@@ -2576,6 +2549,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
@@ -2585,23 +2559,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
@@ -2619,7 +2595,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
@@ -2643,8 +2619,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
@@ -2669,7 +2643,7 @@ ProfileMemoryTypeToStr (
   )\r
 {\r
   UINTN     Index;\r
-  for (Index = 0; Index < sizeof (mMemoryTypeString) / sizeof (mMemoryTypeString[0]); Index++) {\r
+  for (Index = 0; Index < ARRAY_SIZE (mMemoryTypeString); Index++) {\r
     if (mMemoryTypeString[Index].MemoryType == MemoryType) {\r
       return mMemoryTypeString[Index].MemoryTypeStr;\r
     }\r
@@ -2696,12 +2670,12 @@ ProfileActionToStr (
   CHAR8     **ActionString;\r
 \r
   ActionString = mSmmActionString;\r
-  ActionStringCount = sizeof (mSmmActionString) / sizeof (mSmmActionString[0]);\r
+  ActionStringCount = ARRAY_SIZE (mSmmActionString);\r
 \r
   if ((UINTN) (UINT32) Action < ActionStringCount) {\r
     return ActionString[Action];\r
   }\r
-  for (Index = 0; Index < sizeof (mExtActionString) / sizeof (mExtActionString[0]); Index++) {\r
+  for (Index = 0; Index < ARRAY_SIZE (mExtActionString); Index++) {\r
     if (mExtActionString[Index].Action == Action) {\r
       return mExtActionString[Index].String;\r
     }\r
@@ -2823,7 +2797,7 @@ DumpSmramProfile (
 }\r
 \r
 /**\r
-  Dump SMRAM infromation.\r
+  Dump SMRAM information.\r
 \r
 **/\r
 VOID\r