]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg DxeCore: Return memory type from internal free pool/pages
authorStar Zeng <star.zeng@intel.com>
Mon, 11 Apr 2016 03:00:47 +0000 (11:00 +0800)
committerStar Zeng <star.zeng@intel.com>
Fri, 22 Apr 2016 05:39:56 +0000 (13:39 +0800)
The following patch for MemoryAttributesTable will need the memory type.
And CoreUpdateProfile() can also use the memory type for check.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
MdeModulePkg/Core/Dxe/DxeMain.h
MdeModulePkg/Core/Dxe/Mem/Imem.h
MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c
MdeModulePkg/Core/Dxe/Mem/Page.c
MdeModulePkg/Core/Dxe/Mem/Pool.c

index fefe5bec19d36f09e2cb49e9daae4e691022b689..edb7ff5b9fa53c91d0bae017fca73426e8d59d6a 100644 (file)
@@ -1269,33 +1269,6 @@ CoreAllocatePages (
   IN OUT EFI_PHYSICAL_ADDRESS  *Memory\r
   );\r
 \r
-/**\r
-  Allocates pages from the memory map.\r
-\r
-  @param  Type                   The type of allocation to perform\r
-  @param  MemoryType             The type of memory to turn the allocated pages\r
-                                 into\r
-  @param  NumberOfPages          The number of pages to allocate\r
-  @param  Memory                 A pointer to receive the base allocated memory\r
-                                 address\r
-\r
-  @return Status. On success, Memory is filled in with the base address allocated\r
-  @retval EFI_INVALID_PARAMETER  Parameters violate checking rules defined in\r
-                                 spec.\r
-  @retval EFI_NOT_FOUND          Could not allocate pages match the requirement.\r
-  @retval EFI_OUT_OF_RESOURCES   No enough pages to allocate.\r
-  @retval EFI_SUCCESS            Pages successfully allocated.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-CoreInternalAllocatePages (\r
-  IN EFI_ALLOCATE_TYPE      Type,\r
-  IN EFI_MEMORY_TYPE        MemoryType,\r
-  IN UINTN                  NumberOfPages,\r
-  IN OUT EFI_PHYSICAL_ADDRESS  *Memory\r
-  );\r
-\r
 /**\r
   Frees previous allocated pages.\r
 \r
@@ -1314,24 +1287,6 @@ CoreFreePages (
   IN UINTN                  NumberOfPages\r
   );\r
 \r
-/**\r
-  Frees previous allocated pages.\r
-\r
-  @param  Memory                 Base address of memory being freed\r
-  @param  NumberOfPages          The number of pages to free\r
-\r
-  @retval EFI_NOT_FOUND          Could not find the entry that covers the range\r
-  @retval EFI_INVALID_PARAMETER  Address not aligned\r
-  @return EFI_SUCCESS         -Pages successfully freed.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-CoreInternalFreePages (\r
-  IN EFI_PHYSICAL_ADDRESS   Memory,\r
-  IN UINTN                  NumberOfPages\r
-  );\r
-\r
 /**\r
   This function returns a copy of the current memory map. The map is an array of\r
   memory descriptors, each of which describes a contiguous block of memory.\r
@@ -1435,6 +1390,7 @@ CoreFreePool (
   Frees pool.\r
 \r
   @param  Buffer                 The allocated pool entry to free\r
+  @param  PoolType               Pointer to pool type\r
 \r
   @retval EFI_INVALID_PARAMETER  Buffer is not a valid value.\r
   @retval EFI_SUCCESS            Pool successfully freed.\r
@@ -1443,7 +1399,8 @@ CoreFreePool (
 EFI_STATUS\r
 EFIAPI\r
 CoreInternalFreePool (\r
-  IN VOID        *Buffer\r
+  IN VOID               *Buffer,\r
+  OUT EFI_MEMORY_TYPE   *PoolType OPTIONAL\r
   );\r
 \r
 /**\r
index 6f4065e3b89b4ba2da7464f8929fd0de827a7489..fb53f95575f07b5109f2a6ead9ec330b4c62109a 100644 (file)
@@ -112,6 +112,7 @@ CoreAllocatePoolI (
   Caller must have the memory lock held\r
 \r
   @param  Buffer                 The allocated pool entry to free\r
+  @param  PoolType               Pointer to pool type\r
 \r
   @retval EFI_INVALID_PARAMETER  Buffer not valid\r
   @retval EFI_SUCCESS            Buffer successfully freed.\r
@@ -119,7 +120,8 @@ CoreAllocatePoolI (
 **/\r
 EFI_STATUS\r
 CoreFreePoolI (\r
-  IN VOID       *Buffer\r
+  IN VOID               *Buffer,\r
+  OUT EFI_MEMORY_TYPE   *PoolType OPTIONAL\r
   );\r
 \r
 \r
index 1f17947808e92972aca50f6f2d0ad06449337e50..158803746126890ba7e3633de902cd9398f407ec 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Support routines for UEFI memory profile.\r
 \r
-  Copyright (c) 2014 - 2015, 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
@@ -730,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
@@ -1083,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
index 2f4ff8ecfdab6fe22ed2baa8b1060bd31a1c8830..fa71bd87dfdc6313dcb73f828460456d99dd5d61 100644 (file)
@@ -1345,6 +1345,7 @@ CoreAllocatePages (
 \r
   @param  Memory                 Base address of memory being freed\r
   @param  NumberOfPages          The number of pages to free\r
+  @param  MemoryType             Pointer to memory type\r
 \r
   @retval EFI_NOT_FOUND          Could not find the entry that covers the range\r
   @retval EFI_INVALID_PARAMETER  Address not aligned\r
@@ -1355,7 +1356,8 @@ EFI_STATUS
 EFIAPI\r
 CoreInternalFreePages (\r
   IN EFI_PHYSICAL_ADDRESS   Memory,\r
-  IN UINTN                  NumberOfPages\r
+  IN UINTN                  NumberOfPages,\r
+  OUT EFI_MEMORY_TYPE       *MemoryType OPTIONAL\r
   )\r
 {\r
   EFI_STATUS      Status;\r
@@ -1403,6 +1405,10 @@ CoreInternalFreePages (
   NumberOfPages += EFI_SIZE_TO_PAGES (Alignment) - 1;\r
   NumberOfPages &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);\r
 \r
+  if (MemoryType != NULL) {\r
+    *MemoryType = Entry->Type;\r
+  }\r
+\r
   Status = CoreConvertPages (Memory, NumberOfPages, EfiConventionalMemory);\r
 \r
   if (EFI_ERROR (Status)) {\r
@@ -1432,9 +1438,10 @@ CoreFreePages (
   IN UINTN                 NumberOfPages\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
+  EFI_STATUS        Status;\r
+  EFI_MEMORY_TYPE   MemoryType;\r
 \r
-  Status = CoreInternalFreePages (Memory, NumberOfPages);\r
+  Status = CoreInternalFreePages (Memory, NumberOfPages, &MemoryType);\r
   if (!EFI_ERROR (Status)) {\r
     CoreUpdateProfile ((EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), MemoryProfileActionFreePages, (EFI_MEMORY_TYPE) 0, EFI_PAGES_TO_SIZE (NumberOfPages), (VOID *) (UINTN) Memory);\r
   }\r
index 528c8e8ce9a52326d0db5e1d6dd718e158b13475..5496a09cfa72ab9d004efe8e2c665231e7846f8f 100644 (file)
@@ -459,6 +459,7 @@ Done:
   Frees pool.\r
 \r
   @param  Buffer                 The allocated pool entry to free\r
+  @param  PoolType               Pointer to pool type\r
 \r
   @retval EFI_INVALID_PARAMETER  Buffer is not a valid value.\r
   @retval EFI_SUCCESS            Pool successfully freed.\r
@@ -467,7 +468,8 @@ Done:
 EFI_STATUS\r
 EFIAPI\r
 CoreInternalFreePool (\r
-  IN VOID        *Buffer\r
+  IN VOID               *Buffer,\r
+  OUT EFI_MEMORY_TYPE   *PoolType OPTIONAL\r
   )\r
 {\r
   EFI_STATUS Status;\r
@@ -477,7 +479,7 @@ CoreInternalFreePool (
   }\r
 \r
   CoreAcquireMemoryLock ();\r
-  Status = CoreFreePoolI (Buffer);\r
+  Status = CoreFreePoolI (Buffer, PoolType);\r
   CoreReleaseMemoryLock ();\r
   return Status;\r
 }\r
@@ -497,9 +499,10 @@ CoreFreePool (
   IN VOID  *Buffer\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
+  EFI_STATUS        Status;\r
+  EFI_MEMORY_TYPE   PoolType;\r
 \r
-  Status = CoreInternalFreePool (Buffer);\r
+  Status = CoreInternalFreePool (Buffer, &PoolType);\r
   if (!EFI_ERROR (Status)) {\r
     CoreUpdateProfile ((EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), MemoryProfileActionFreePool, (EFI_MEMORY_TYPE) 0, 0, Buffer);\r
   }\r
@@ -511,6 +514,7 @@ CoreFreePool (
   Caller must have the memory lock held\r
 \r
   @param  Buffer                 The allocated pool entry to free\r
+  @param  PoolType               Pointer to pool type\r
 \r
   @retval EFI_INVALID_PARAMETER  Buffer not valid\r
   @retval EFI_SUCCESS            Buffer successfully freed.\r
@@ -518,7 +522,8 @@ CoreFreePool (
 **/\r
 EFI_STATUS\r
 CoreFreePoolI (\r
-  IN VOID       *Buffer\r
+  IN VOID               *Buffer,\r
+  OUT EFI_MEMORY_TYPE   *PoolType OPTIONAL\r
   )\r
 {\r
   POOL        *Pool;\r
@@ -583,6 +588,10 @@ CoreFreePoolI (
     Granularity = DEFAULT_PAGE_ALLOCATION;\r
   }\r
 \r
+  if (PoolType != NULL) {\r
+    *PoolType = Head->Type;\r
+  }\r
+\r
   //\r
   // Determine the pool list\r
   //\r
@@ -667,7 +676,7 @@ CoreFreePoolI (
   //\r
   if (((UINT32) Pool->MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) && Pool->Used == 0) {\r
     RemoveEntryList (&Pool->Link);\r
-    CoreFreePoolI (Pool);\r
+    CoreFreePoolI (Pool, NULL);\r
   }\r
 \r
   return EFI_SUCCESS;\r