-/*++\r
+/** @file \r
\r
-Copyright (c) 2006, Intel Corporation \r
+ UEFI Memory pool management functions.\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation \r
All rights reserved. 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
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
\r
-Module Name:\r
-\r
- pool.c\r
-\r
-Abstract:\r
-\r
- EFI Memory pool management\r
-\r
-Revision History\r
-\r
---*/\r
+**/\r
\r
#include <DxeMain.h>\r
\r
//\r
//\r
\r
+\r
+/**\r
+ Called to initialize the pool.\r
+\r
+**/\r
VOID\r
CoreInitializePool (\r
VOID\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Called to initialize the pool.\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
{\r
UINTN Type;\r
UINTN Index;\r
InitializeListHead (&PoolHeadList);\r
}\r
\r
-STATIC\r
-POOL *\r
-LookupPoolHead (\r
- IN EFI_MEMORY_TYPE MemoryType\r
- )\r
-/*++\r
-\r
-Routine Description:\r
\r
+/**\r
Look up pool head for specified memory type.\r
\r
-Arguments:\r
+ @param MemoryType Memory type of which pool head is looked for \r
\r
- MemoryType - Memory type of which pool head is looked for\r
+ @return Pointer of Corresponding pool head.\r
\r
-Returns:\r
-\r
- Pointer of Corresponding pool head.\r
-\r
---*/\r
+**/\r
+STATIC\r
+POOL *\r
+LookupPoolHead (\r
+ IN EFI_MEMORY_TYPE MemoryType\r
+ )\r
{\r
LIST_ENTRY *Link;\r
POOL *Pool;\r
\r
\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 \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 UINTN Size,\r
OUT VOID **Buffer\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Allocate pool of a particular type.\r
-\r
-Arguments:\r
-\r
- PoolType - Type of pool to allocate\r
-\r
- Size - The amount of pool to allocate\r
-\r
- Buffer - The address to return a pointer to the allocated pool\r
-\r
-Returns:\r
-\r
- EFI_INVALID_PARAMETER - PoolType not valid\r
- \r
- EFI_OUT_OF_RESOURCES - Size exceeds max pool size or allocation failed. \r
- \r
- EFI_SUCCESS - Pool successfully allocated.\r
-\r
---*/\r
{\r
EFI_STATUS Status;\r
\r
}\r
\r
\r
-VOID *\r
-CoreAllocatePoolI (\r
- IN EFI_MEMORY_TYPE PoolType,\r
- IN UINTN Size\r
- )\r
-/*++\r
-\r
-Routine Description:\r
\r
+/**\r
Internal function to allocate pool of a particular type.\r
-\r
Caller must have the memory lock held\r
\r
+ @param PoolType Type of pool to allocate \r
+ @param Size The amount of pool to allocate \r
\r
-Arguments:\r
-\r
- PoolType - Type of pool to allocate\r
-\r
- Size - The amount of pool to allocate\r
-\r
-Returns:\r
-\r
- The allocate pool, or NULL\r
+ @return The allocate pool, or NULL\r
\r
---*/\r
+**/\r
+VOID *\r
+CoreAllocatePoolI (\r
+ IN EFI_MEMORY_TYPE PoolType,\r
+ IN UINTN Size\r
+ )\r
{\r
POOL *Pool;\r
POOL_FREE *Free;\r
VOID *Buffer;\r
UINTN Index;\r
UINTN FSize;\r
- UINTN offset;\r
+ UINTN Offset;\r
UINTN Adjustment;\r
UINTN NoPages;\r
\r
//\r
// Carve up new page into free pool blocks\r
//\r
- offset = 0;\r
- while (offset < DEFAULT_PAGE_ALLOCATION) {\r
+ Offset = 0;\r
+ while (Offset < DEFAULT_PAGE_ALLOCATION) {\r
ASSERT (Index < MAX_POOL_LIST);\r
FSize = LIST_TO_SIZE(Index);\r
\r
- while (offset + FSize <= DEFAULT_PAGE_ALLOCATION) {\r
- Free = (POOL_FREE *) &NewPage[offset]; \r
+ while (Offset + FSize <= DEFAULT_PAGE_ALLOCATION) {\r
+ Free = (POOL_FREE *) &NewPage[Offset]; \r
Free->Signature = POOL_FREE_SIGNATURE;\r
Free->Index = (UINT32)Index;\r
InsertHeadList (&Pool->FreeList[Index], &Free->Link);\r
- offset += FSize;\r
+ Offset += FSize;\r
}\r
\r
Index -= 1;\r
}\r
\r
- ASSERT (offset == DEFAULT_PAGE_ALLOCATION);\r
+ ASSERT (Offset == DEFAULT_PAGE_ALLOCATION);\r
Index = SIZE_TO_LIST(Size);\r
}\r
\r
DEBUG_CLEAR_MEMORY (Buffer, Size - POOL_OVERHEAD);\r
\r
DEBUG (\r
- (EFI_D_POOL,\r
- "AllcocatePoolI: Type %x, Addr %x (len %x) %,d\n",\r
+ (DEBUG_POOL,\r
+ "AllocatePoolI: Type %x, Addr %x (len %x) %,d\n",\r
PoolType, \r
Buffer, \r
Size - POOL_OVERHEAD, \r
Pool->Used += Size;\r
\r
} else {\r
- DEBUG ((EFI_D_ERROR | EFI_D_POOL, "AllocatePool: failed to allocate %d bytes\n", Size));\r
+ DEBUG ((DEBUG_ERROR | DEBUG_POOL, "AllocatePool: failed to allocate %d bytes\n", Size));\r
}\r
\r
return Buffer;\r
\r
\r
\r
-EFI_STATUS\r
-EFIAPI\r
-CoreFreePool (\r
- IN VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
\r
+/**\r
Frees pool.\r
\r
-Arguments:\r
+ @param Buffer The allocated pool entry to free \r
\r
- Buffer - The allocated pool entry to free\r
+ @retval EFI_INVALID_PARAMETER Buffer is not a valid value. \r
+ @retval EFI_SUCCESS Pool successfully freed.\r
\r
-Returns:\r
-\r
- EFI_INVALID_PARAMETER - Buffer is not a valid value.\r
- \r
- EFI_SUCCESS - Pool successfully freed.\r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CoreFreePool (\r
+ IN VOID *Buffer\r
+ )\r
{\r
EFI_STATUS Status;\r
\r
}\r
\r
\r
-EFI_STATUS\r
-CoreFreePoolI (\r
- IN VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
\r
+/**\r
Internal function to free a pool entry.\r
-\r
Caller must have the memory lock held\r
\r
+ @param Buffer The allocated pool entry to free \r
\r
-Arguments:\r
+ @retval EFI_INVALID_PARAMETER Buffer not valid \r
+ @retval EFI_SUCCESS Buffer successfully freed.\r
\r
- Buffer - The allocated pool entry to free\r
-\r
-Returns:\r
-\r
- EFI_INVALID_PARAMETER - Buffer not valid\r
- \r
- EFI_SUCCESS - Buffer successfully freed.\r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+CoreFreePoolI (\r
+ IN VOID *Buffer\r
+ )\r
{\r
POOL *Pool;\r
POOL_HEAD *Head;\r
UINTN Size;\r
CHAR8 *NewPage;\r
UINTN FSize;\r
- UINTN offset;\r
+ UINTN Offset;\r
BOOLEAN AllFree;\r
\r
ASSERT(NULL != Buffer);\r
return EFI_INVALID_PARAMETER;\r
}\r
Pool->Used -= Size;\r
- DEBUG ((EFI_D_POOL, "FreePool: %x (len %x) %,d\n", Head->Data, Head->Size - POOL_OVERHEAD, Pool->Used));\r
+ DEBUG ((DEBUG_POOL, "FreePool: %x (len %x) %,d\n", Head->Data, Head->Size - POOL_OVERHEAD, Pool->Used));\r
\r
//\r
// Determine the pool list \r
Index = Free->Index;\r
\r
AllFree = TRUE;\r
- offset = 0;\r
+ Offset = 0;\r
\r
- while ((offset < DEFAULT_PAGE_ALLOCATION) && (AllFree)) {\r
+ while ((Offset < DEFAULT_PAGE_ALLOCATION) && (AllFree)) {\r
FSize = LIST_TO_SIZE(Index);\r
- while (offset + FSize <= DEFAULT_PAGE_ALLOCATION) {\r
- Free = (POOL_FREE *) &NewPage[offset];\r
+ while (Offset + FSize <= DEFAULT_PAGE_ALLOCATION) {\r
+ Free = (POOL_FREE *) &NewPage[Offset];\r
ASSERT(NULL != Free);\r
if (Free->Signature != POOL_FREE_SIGNATURE) {\r
AllFree = FALSE;\r
}\r
- offset += FSize;\r
+ Offset += FSize;\r
}\r
Index -= 1;\r
}\r
Free = (POOL_FREE *) &NewPage[0];\r
ASSERT(NULL != Free);\r
Index = Free->Index;\r
- offset = 0;\r
+ Offset = 0;\r
\r
- while (offset < DEFAULT_PAGE_ALLOCATION) {\r
+ while (Offset < DEFAULT_PAGE_ALLOCATION) {\r
FSize = LIST_TO_SIZE(Index);\r
- while (offset + FSize <= DEFAULT_PAGE_ALLOCATION) {\r
- Free = (POOL_FREE *) &NewPage[offset];\r
+ while (Offset + FSize <= DEFAULT_PAGE_ALLOCATION) {\r
+ Free = (POOL_FREE *) &NewPage[Offset];\r
ASSERT(NULL != Free);\r
RemoveEntryList (&Free->Link);\r
- offset += FSize;\r
+ Offset += FSize;\r
}\r
Index -= 1;\r
}\r