/** @file\r
UEFI Memory pool management functions.\r
\r
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, 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
//\r
LIST_ENTRY mPoolHeadList = INITIALIZE_LIST_HEAD_VARIABLE (mPoolHeadList);\r
\r
+/**\r
+ Get pool size table index from the specified size.\r
+\r
+ @param Size The specified size to get index from pool table.\r
+\r
+ @return The index of pool size table.\r
+\r
+**/\r
STATIC\r
UINTN\r
GetPoolIndexFromSize (\r
}\r
\r
//\r
- // MemoryType values in the range 0x80000000..0xFFFFFFFF are reserved for use by UEFI \r
- // OS loaders that are provided by operating system vendors\r
+ // MemoryType values in the range 0x80000000..0xFFFFFFFF are reserved for use by UEFI\r
+ // OS loaders that are provided by operating system vendors.\r
+ // MemoryType values in the range 0x70000000..0x7FFFFFFF are reserved for OEM use.\r
//\r
- if ((INT32)MemoryType < 0) {\r
+ if ((UINT32) MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {\r
\r
for (Link = mPoolHeadList.ForwardLink; Link != &mPoolHeadList; Link = Link->ForwardLink) {\r
Pool = CR(Link, POOL, Link, POOL_SIGNATURE);\r
pool\r
\r
@retval EFI_INVALID_PARAMETER PoolType not valid or Buffer is NULL. \r
+ PoolType was EfiPersistentMemory.\r
@retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.\r
@retval EFI_SUCCESS Pool successfully allocated.\r
\r
//\r
// If it's not a valid type, fail it\r
//\r
- if ((PoolType >= EfiMaxMemoryType && PoolType <= 0x7fffffff) ||\r
- PoolType == EfiConventionalMemory) {\r
+ if ((PoolType >= EfiMaxMemoryType && PoolType < MEMORY_TYPE_OEM_RESERVED_MIN) ||\r
+ (PoolType == EfiConventionalMemory) || (PoolType == EfiPersistentMemory)) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
VOID *Buffer;\r
UINTN Index;\r
UINTN FSize;\r
- UINTN Offset;\r
+ UINTN Offset, MaxOffset;\r
UINTN NoPages;\r
UINTN Granularity;\r
\r
//\r
if (IsListEmpty (&Pool->FreeList[Index])) {\r
\r
+ Offset = LIST_TO_SIZE (Index);\r
+ MaxOffset = Granularity;\r
+\r
+ //\r
+ // Check the bins holding larger blocks, and carve one up if needed\r
+ //\r
+ while (++Index < SIZE_TO_LIST (Granularity)) {\r
+ if (!IsListEmpty (&Pool->FreeList[Index])) {\r
+ Free = CR (Pool->FreeList[Index].ForwardLink, POOL_FREE, Link, POOL_FREE_SIGNATURE);\r
+ RemoveEntryList (&Free->Link);\r
+ NewPage = (VOID *) Free;\r
+ MaxOffset = LIST_TO_SIZE (Index);\r
+ goto Carve;\r
+ }\r
+ }\r
+\r
//\r
// Get another page\r
//\r
}\r
\r
//\r
- // Carve up new page into free pool blocks\r
+ // Serve the allocation request from the head of the allocated block\r
+ //\r
+Carve:\r
+ Head = (POOL_HEAD *) NewPage;\r
+\r
+ //\r
+ // Carve up remaining space into free pool blocks\r
//\r
- Offset = 0;\r
- while (Offset < Granularity) {\r
+ Index--;\r
+ while (Offset < MaxOffset) {\r
ASSERT (Index < MAX_POOL_LIST);\r
FSize = LIST_TO_SIZE(Index);\r
\r
- while (Offset + FSize <= Granularity) {\r
+ while (Offset + FSize <= MaxOffset) {\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
}\r
-\r
Index -= 1;\r
}\r
\r
- ASSERT (Offset == Granularity);\r
- Index = SIZE_TO_LIST(Size);\r
+ ASSERT (Offset == MaxOffset);\r
+ goto Done;\r
}\r
\r
//\r