]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/PiSmmCore/Page.c
MdeModulePkg DxeCore/PiSmmCore: Add UEFI memory and SMRAM profile support.
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / Page.c
index 5b6e849a2d924b6ed4b036bfaaaea39588ba81ae..9cc2a4cabc6efd265872d7f52614caf9d30ffc75 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SMM Memory page management functions.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials are licensed and made available \r
   under the terms and conditions of the BSD License which accompanies this \r
   distribution.  The full text of the license may be found at        \r
 \r
 #define TRUNCATE_TO_PAGES(a)  ((a) >> EFI_PAGE_SHIFT)\r
 \r
-typedef struct {\r
-  LIST_ENTRY  Link;\r
-  UINTN       NumberOfPages;\r
-} FREE_PAGE_LIST;\r
-\r
 LIST_ENTRY  mSmmMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (mSmmMemoryMap);\r
 \r
 /**\r
@@ -151,7 +146,7 @@ InternalAllocAddress (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-SmmAllocatePages (\r
+SmmInternalAllocatePages (\r
   IN  EFI_ALLOCATE_TYPE     Type,\r
   IN  EFI_MEMORY_TYPE       MemoryType,\r
   IN  UINTN                 NumberOfPages,\r
@@ -202,6 +197,40 @@ SmmAllocatePages (
   return EFI_SUCCESS;\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
+  @retval EFI_INVALID_PARAMETER  Parameters violate checking rules defined in 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
+SmmAllocatePages (\r
+  IN  EFI_ALLOCATE_TYPE     Type,\r
+  IN  EFI_MEMORY_TYPE       MemoryType,\r
+  IN  UINTN                 NumberOfPages,\r
+  OUT EFI_PHYSICAL_ADDRESS  *Memory\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Status = SmmInternalAllocatePages (Type, MemoryType, NumberOfPages, Memory);\r
+  if (!EFI_ERROR (Status)) {\r
+    SmmCoreUpdateProfile ((EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), MemoryProfileActionAllocatePages, MemoryType, EFI_PAGES_TO_SIZE (NumberOfPages), (VOID *) (UINTN) *Memory);\r
+  }\r
+  return Status;\r
+}\r
+\r
 /**\r
   Internal Function. Merge two adjacent nodes.\r
 \r
@@ -242,7 +271,7 @@ InternalMergeNodes (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-SmmFreePages (\r
+SmmInternalFreePages (\r
   IN EFI_PHYSICAL_ADDRESS  Memory,\r
   IN UINTN                 NumberOfPages\r
   )\r
@@ -293,6 +322,33 @@ SmmFreePages (
   return EFI_SUCCESS;\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
+SmmFreePages (\r
+  IN EFI_PHYSICAL_ADDRESS  Memory,\r
+  IN UINTN                 NumberOfPages\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Status = SmmInternalFreePages (Memory, NumberOfPages);\r
+  if (!EFI_ERROR (Status)) {\r
+    SmmCoreUpdateProfile ((EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), MemoryProfileActionFreePages, 0, EFI_PAGES_TO_SIZE (NumberOfPages), (VOID *) (UINTN) Memory);\r
+  }\r
+  return Status;\r
+}\r
+\r
 /**\r
   Add free SMRAM region for use by memory service.\r
 \r