]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Mem/Pool.c
MdeModulePkg DxeCore/PiSmmCore: Add UEFI memory and SMRAM profile support.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Mem / Pool.c
index bc785a8b9c85cd624b51152acf768f10e303ead8..1891bb73876aa94029e8455c1c1c7c57b89d3675 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   UEFI Memory pool management functions.\r
 \r
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, 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
@@ -175,7 +175,7 @@ LookupPoolHead (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-CoreAllocatePool (\r
+CoreInternalAllocatePool (\r
   IN EFI_MEMORY_TYPE  PoolType,\r
   IN UINTN            Size,\r
   OUT VOID            **Buffer\r
@@ -218,7 +218,35 @@ CoreAllocatePool (
   return (*Buffer != NULL) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;\r
 }\r
 \r
+/**\r
+  Allocate pool of a particular type.\r
+\r
+  @param  PoolType               Type of pool to allocate\r
+  @param  Size                   The amount of pool to allocate\r
+  @param  Buffer                 The address to return a pointer to the allocated\r
+                                 pool\r
+\r
+  @retval EFI_INVALID_PARAMETER  PoolType not valid or Buffer is NULL. \r
+  @retval EFI_OUT_OF_RESOURCES   Size exceeds max pool size or allocation failed.\r
+  @retval EFI_SUCCESS            Pool successfully allocated.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CoreAllocatePool (\r
+  IN EFI_MEMORY_TYPE  PoolType,\r
+  IN UINTN            Size,\r
+  OUT VOID            **Buffer\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
 \r
+  Status = CoreInternalAllocatePool (PoolType, Size, Buffer);\r
+  if (!EFI_ERROR (Status)) {\r
+    CoreUpdateProfile ((EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), MemoryProfileActionAllocatePool, PoolType, Size, *Buffer);\r
+  }\r
+  return Status;\r
+}\r
 \r
 /**\r
   Internal function to allocate pool of a particular type.\r
@@ -274,7 +302,7 @@ CoreAllocatePoolI (
   //\r
   if (Index >= MAX_POOL_LIST) {\r
     NoPages = EFI_SIZE_TO_PAGES(Size) + EFI_SIZE_TO_PAGES (DEFAULT_PAGE_ALLOCATION) - 1;\r
-    NoPages &= ~(EFI_SIZE_TO_PAGES (DEFAULT_PAGE_ALLOCATION) - 1);\r
+    NoPages &= ~(UINTN)(EFI_SIZE_TO_PAGES (DEFAULT_PAGE_ALLOCATION) - 1);\r
     Head = CoreAllocatePoolPages (PoolType, NoPages, DEFAULT_PAGE_ALLOCATION);\r
     goto Done;\r
   }\r
@@ -373,7 +401,7 @@ Done:
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-CoreFreePool (\r
+CoreInternalFreePool (\r
   IN VOID        *Buffer\r
   )\r
 {\r
@@ -389,7 +417,29 @@ CoreFreePool (
   return Status;\r
 }\r
 \r
+/**\r
+  Frees pool.\r
+\r
+  @param  Buffer                 The allocated pool entry to free\r
+\r
+  @retval EFI_INVALID_PARAMETER  Buffer is not a valid value.\r
+  @retval EFI_SUCCESS            Pool successfully freed.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CoreFreePool (\r
+  IN VOID  *Buffer\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
 \r
+  Status = CoreInternalFreePool (Buffer);\r
+  if (!EFI_ERROR (Status)) {\r
+    CoreUpdateProfile ((EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), MemoryProfileActionFreePool, 0, 0, Buffer);\r
+  }\r
+  return Status;\r
+}\r
 \r
 /**\r
   Internal function to free a pool entry.\r
@@ -473,7 +523,7 @@ CoreFreePoolI (
     // Return the memory pages back to free memory\r
     //\r
     NoPages = EFI_SIZE_TO_PAGES(Size) + EFI_SIZE_TO_PAGES (DEFAULT_PAGE_ALLOCATION) - 1;\r
-    NoPages &= ~(EFI_SIZE_TO_PAGES (DEFAULT_PAGE_ALLOCATION) - 1);\r
+    NoPages &= ~(UINTN)(EFI_SIZE_TO_PAGES (DEFAULT_PAGE_ALLOCATION) - 1);\r
     CoreFreePoolPages ((EFI_PHYSICAL_ADDRESS) (UINTN) Head, NoPages);\r
 \r
   } else {\r
@@ -558,3 +608,4 @@ CoreFreePoolI (
 \r
   return EFI_SUCCESS;\r
 }\r
+\r