]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c
MdeModulePkg DxeCore: Return memory type from internal free pool/pages
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Mem / MemoryProfileRecord.c
index 60971ba9f9be14801943575b4f507e8886dc9670..158803746126890ba7e3633de902cd9398f407ec 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Support routines for UEFI memory profile.\r
 \r
-  Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\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
@@ -13,6 +13,7 @@
 **/\r
 \r
 #include "DxeMain.h"\r
+#include "Imem.h"\r
 \r
 #define IS_UEFI_MEMORY_PROFILE_ENABLED ((PcdGet8 (PcdMemoryProfilePropertyMask) & BIT0) != 0)\r
 \r
@@ -483,13 +484,15 @@ GetFileNameFromFilePath (
   EFI_GUID                              *FileName;\r
 \r
   FileName = NULL;\r
-  ThisFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) FilePath;\r
-  while (!IsDevicePathEnd (ThisFilePath)) {\r
-    FileName = EfiGetNameGuidFromFwVolDevicePathNode (ThisFilePath);\r
-    if (FileName != NULL) {\r
-      break;\r
+  if (FilePath != NULL) {\r
+    ThisFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) FilePath;\r
+    while (!IsDevicePathEnd (ThisFilePath)) {\r
+      FileName = EfiGetNameGuidFromFwVolDevicePathNode (ThisFilePath);\r
+      if (FileName != NULL) {\r
+        break;\r
+      }\r
+      ThisFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) NextDevicePathNode (ThisFilePath);\r
     }\r
-    ThisFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) NextDevicePathNode (ThisFilePath);\r
   }\r
 \r
   return FileName;\r
@@ -727,7 +730,7 @@ UnregisterMemoryProfileImage (
     //\r
     // Use CoreInternalFreePool() that will not update profile for this FreePool action.\r
     //\r
-    CoreInternalFreePool (DriverInfoData);\r
+    CoreInternalFreePool (DriverInfoData, NULL);\r
   }\r
 \r
   return TRUE;\r
@@ -735,8 +738,9 @@ UnregisterMemoryProfileImage (
 \r
 /**\r
   Return if this memory type needs to be recorded into memory profile.\r
-  If BIOS memory type (0 ~ EfiMaxMemoryType), it checks bit (1 << MemoryType).\r
+  If BIOS memory type (0 ~ EfiMaxMemoryType - 1), it checks bit (1 << MemoryType).\r
   If OS memory type (0x80000000 ~ 0xFFFFFFFF), it checks bit63 - 0x8000000000000000.\r
+  If OEM memory type (0x70000000 ~ 0x7FFFFFFF), it checks bit62 - 0x4000000000000000.\r
 \r
   @param MemoryType     Memory type.\r
 \r
@@ -751,8 +755,10 @@ CoreNeedRecordProfile (
 {\r
   UINT64 TestBit;\r
 \r
-  if ((UINT32) MemoryType >= 0x80000000) {\r
+  if ((UINT32) MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {\r
     TestBit = BIT63;\r
+  } else if ((UINT32) MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {\r
+    TestBit = BIT62;\r
   } else {\r
     TestBit = LShiftU64 (1, MemoryType);\r
   }\r
@@ -766,21 +772,24 @@ CoreNeedRecordProfile (
 \r
 /**\r
   Convert EFI memory type to profile memory index. The rule is:\r
-  If BIOS memory type (0 ~ EfiMaxMemoryType), ProfileMemoryIndex = MemoryType.\r
+  If BIOS memory type (0 ~ EfiMaxMemoryType - 1), ProfileMemoryIndex = MemoryType.\r
   If OS memory type (0x80000000 ~ 0xFFFFFFFF), ProfileMemoryIndex = EfiMaxMemoryType.\r
+  If OEM memory type (0x70000000 ~ 0x7FFFFFFF), ProfileMemoryIndex = EfiMaxMemoryType + 1.\r
 \r
   @param MemoryType     Memory type.\r
 \r
-  @return EFI memory type as profile memory index.\r
+  @return Profile memory index.\r
 \r
 **/\r
-EFI_MEMORY_TYPE\r
+UINTN\r
 GetProfileMemoryIndex (\r
   IN EFI_MEMORY_TYPE    MemoryType\r
   )\r
 {\r
-  if ((UINT32) MemoryType >= 0x80000000) {\r
+  if ((UINT32) MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {\r
     return EfiMaxMemoryType;\r
+  } else if ((UINT32) MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {\r
+    return EfiMaxMemoryType + 1;\r
   } else {\r
     return MemoryType;\r
   }\r
@@ -815,7 +824,7 @@ CoreUpdateProfileAllocate (
   MEMORY_PROFILE_CONTEXT_DATA       *ContextData;\r
   MEMORY_PROFILE_DRIVER_INFO_DATA   *DriverInfoData;\r
   MEMORY_PROFILE_ALLOC_INFO_DATA    *AllocInfoData;\r
-  EFI_MEMORY_TYPE                   ProfileMemoryIndex;\r
+  UINTN                             ProfileMemoryIndex;\r
 \r
   AllocInfoData = NULL;\r
 \r
@@ -968,7 +977,7 @@ CoreUpdateProfileFree (
   LIST_ENTRY                       *DriverInfoList;\r
   MEMORY_PROFILE_DRIVER_INFO_DATA  *ThisDriverInfoData;\r
   MEMORY_PROFILE_ALLOC_INFO_DATA   *AllocInfoData;\r
-  EFI_MEMORY_TYPE                  ProfileMemoryIndex;\r
+  UINTN                            ProfileMemoryIndex;\r
 \r
   ContextData = GetMemoryProfileContext ();\r
   if (ContextData == NULL) {\r
@@ -1074,7 +1083,7 @@ CoreUpdateProfileFree (
   //\r
   // Use CoreInternalFreePool() that will not update profile for this FreePool action.\r
   //\r
-  CoreInternalFreePool (AllocInfoData);\r
+  CoreInternalFreePool (AllocInfoData, NULL);\r
 \r
   return TRUE;\r
 }\r