X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FMem%2FPool.c;h=6ef5fba395f5805794d3972746f61fb365e66c45;hp=23409d35c4284e92e7ffab5d2451ae949e924a57;hb=1d60fe96422206d37e1d74198bb11b2cf6195157;hpb=f8aabf6e4c199e92498512e1d0cf9a347b62e491 diff --git a/MdeModulePkg/Core/Dxe/Mem/Pool.c b/MdeModulePkg/Core/Dxe/Mem/Pool.c index 23409d35c4..6ef5fba395 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Pool.c +++ b/MdeModulePkg/Core/Dxe/Mem/Pool.c @@ -1,7 +1,7 @@ /** @file UEFI Memory pool management functions. -Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -52,7 +52,7 @@ typedef struct { // as we would in a strict power-of-2 sequence // STATIC CONST UINT16 mPoolSizeTable[] = { - 64, 128, 192, 320, 512, 832, 1344, 2176, 3520, 5696, 9216, 14912, 24128 + 128, 256, 384, 640, 1024, 1664, 2688, 4352, 7040, 11392, 18432, 29824 }; #define SIZE_TO_LIST(a) (GetPoolIndexFromSize (a)) @@ -85,6 +85,14 @@ POOL mPoolHead[EfiMaxMemoryType]; // LIST_ENTRY mPoolHeadList = INITIALIZE_LIST_HEAD_VARIABLE (mPoolHeadList); +/** + Get pool size table index from the specified size. + + @param Size The specified size to get index from pool table. + + @return The index of pool size table. + +**/ STATIC UINTN GetPoolIndexFromSize ( @@ -146,10 +154,11 @@ LookupPoolHead ( } // - // MemoryType values in the range 0x80000000..0xFFFFFFFF are reserved for use by UEFI - // OS loaders that are provided by operating system vendors + // MemoryType values in the range 0x80000000..0xFFFFFFFF are reserved for use by UEFI + // OS loaders that are provided by operating system vendors. + // MemoryType values in the range 0x70000000..0x7FFFFFFF are reserved for OEM use. // - if ((INT32)MemoryType < 0) { + if ((UINT32) MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) { for (Link = mPoolHeadList.ForwardLink; Link != &mPoolHeadList; Link = Link->ForwardLink) { Pool = CR(Link, POOL, Link, POOL_SIGNATURE); @@ -188,7 +197,9 @@ LookupPoolHead ( @param Buffer The address to return a pointer to the allocated pool - @retval EFI_INVALID_PARAMETER PoolType not valid or Buffer is NULL. + @retval EFI_INVALID_PARAMETER Buffer is NULL. + PoolType is in the range EfiMaxMemoryType..0x6FFFFFFF. + PoolType is EfiPersistentMemory. @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed. @retval EFI_SUCCESS Pool successfully allocated. @@ -206,8 +217,8 @@ CoreInternalAllocatePool ( // // If it's not a valid type, fail it // - if ((PoolType >= EfiMaxMemoryType && PoolType <= 0x7fffffff) || - PoolType == EfiConventionalMemory) { + if ((PoolType >= EfiMaxMemoryType && PoolType < MEMORY_TYPE_OEM_RESERVED_MIN) || + (PoolType == EfiConventionalMemory) || (PoolType == EfiPersistentMemory)) { return EFI_INVALID_PARAMETER; } @@ -246,7 +257,9 @@ CoreInternalAllocatePool ( @param Buffer The address to return a pointer to the allocated pool - @retval EFI_INVALID_PARAMETER PoolType not valid or Buffer is NULL. + @retval EFI_INVALID_PARAMETER Buffer is NULL. + PoolType is in the range EfiMaxMemoryType..0x6FFFFFFF. + PoolType is EfiPersistentMemory. @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed. @retval EFI_SUCCESS Pool successfully allocated. @@ -263,7 +276,15 @@ CoreAllocatePool ( Status = CoreInternalAllocatePool (PoolType, Size, Buffer); if (!EFI_ERROR (Status)) { - CoreUpdateProfile ((EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), MemoryProfileActionAllocatePool, PoolType, Size, *Buffer); + CoreUpdateProfile ( + (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), + MemoryProfileActionAllocatePool, + PoolType, + Size, + *Buffer, + NULL + ); + InstallMemoryAttributesTableOnMemoryAllocation (PoolType); } return Status; } @@ -292,7 +313,7 @@ CoreAllocatePoolI ( VOID *Buffer; UINTN Index; UINTN FSize; - UINTN Offset; + UINTN Offset, MaxOffset; UINTN NoPages; UINTN Granularity; @@ -343,6 +364,22 @@ CoreAllocatePoolI ( // if (IsListEmpty (&Pool->FreeList[Index])) { + Offset = LIST_TO_SIZE (Index); + MaxOffset = Granularity; + + // + // Check the bins holding larger blocks, and carve one up if needed + // + while (++Index < SIZE_TO_LIST (Granularity)) { + if (!IsListEmpty (&Pool->FreeList[Index])) { + Free = CR (Pool->FreeList[Index].ForwardLink, POOL_FREE, Link, POOL_FREE_SIGNATURE); + RemoveEntryList (&Free->Link); + NewPage = (VOID *) Free; + MaxOffset = LIST_TO_SIZE (Index); + goto Carve; + } + } + // // Get another page // @@ -354,29 +391,28 @@ CoreAllocatePoolI ( // // Serve the allocation request from the head of the allocated block // +Carve: Head = (POOL_HEAD *) NewPage; - Offset = LIST_TO_SIZE (Index); // // Carve up remaining space into free pool blocks // - Index = SIZE_TO_LIST (Granularity) - 1; - while (Offset < Granularity) { + Index--; + while (Offset < MaxOffset) { ASSERT (Index < MAX_POOL_LIST); FSize = LIST_TO_SIZE(Index); - while (Offset + FSize <= Granularity) { + while (Offset + FSize <= MaxOffset) { Free = (POOL_FREE *) &NewPage[Offset]; Free->Signature = POOL_FREE_SIGNATURE; Free->Index = (UINT32)Index; InsertHeadList (&Pool->FreeList[Index], &Free->Link); Offset += FSize; } - Index -= 1; } - ASSERT (Offset == Granularity); + ASSERT (Offset == MaxOffset); goto Done; } @@ -431,6 +467,7 @@ Done: Frees pool. @param Buffer The allocated pool entry to free + @param PoolType Pointer to pool type @retval EFI_INVALID_PARAMETER Buffer is not a valid value. @retval EFI_SUCCESS Pool successfully freed. @@ -439,7 +476,8 @@ Done: EFI_STATUS EFIAPI CoreInternalFreePool ( - IN VOID *Buffer + IN VOID *Buffer, + OUT EFI_MEMORY_TYPE *PoolType OPTIONAL ) { EFI_STATUS Status; @@ -449,7 +487,7 @@ CoreInternalFreePool ( } CoreAcquireMemoryLock (); - Status = CoreFreePoolI (Buffer); + Status = CoreFreePoolI (Buffer, PoolType); CoreReleaseMemoryLock (); return Status; } @@ -469,11 +507,20 @@ CoreFreePool ( IN VOID *Buffer ) { - EFI_STATUS Status; + EFI_STATUS Status; + EFI_MEMORY_TYPE PoolType; - Status = CoreInternalFreePool (Buffer); + Status = CoreInternalFreePool (Buffer, &PoolType); if (!EFI_ERROR (Status)) { - CoreUpdateProfile ((EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), MemoryProfileActionFreePool, (EFI_MEMORY_TYPE) 0, 0, Buffer); + CoreUpdateProfile ( + (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), + MemoryProfileActionFreePool, + PoolType, + 0, + Buffer, + NULL + ); + InstallMemoryAttributesTableOnMemoryAllocation (PoolType); } return Status; } @@ -483,6 +530,7 @@ CoreFreePool ( Caller must have the memory lock held @param Buffer The allocated pool entry to free + @param PoolType Pointer to pool type @retval EFI_INVALID_PARAMETER Buffer not valid @retval EFI_SUCCESS Buffer successfully freed. @@ -490,7 +538,8 @@ CoreFreePool ( **/ EFI_STATUS CoreFreePoolI ( - IN VOID *Buffer + IN VOID *Buffer, + OUT EFI_MEMORY_TYPE *PoolType OPTIONAL ) { POOL *Pool; @@ -555,6 +604,10 @@ CoreFreePoolI ( Granularity = DEFAULT_PAGE_ALLOCATION; } + if (PoolType != NULL) { + *PoolType = Head->Type; + } + // // Determine the pool list // @@ -633,13 +686,13 @@ CoreFreePoolI ( } // - // If this is an OS specific memory type, then check to see if the last + // If this is an OS/OEM specific memory type, then check to see if the last // portion of that memory type has been freed. If it has, then free the // list entry for that memory type // - if ((INT32)Pool->MemoryType < 0 && Pool->Used == 0) { + if (((UINT32) Pool->MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) && Pool->Used == 0) { RemoveEntryList (&Pool->Link); - CoreFreePoolI (Pool); + CoreFreePoolI (Pool, NULL); } return EFI_SUCCESS;