Pool.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/** @file
UEFI Memory pool management functions.
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "DxeMain.h"
#include "Imem.h"
typedef struct {
} POOL_FREE;
typedef struct {
} POOL_HEAD;
typedef struct {
} POOL_TAIL;
#define POOL_SHIFT 7
#define HEAD_TO_TAIL(a) \
#define SIZE_TO_LIST(a) ((a) >> POOL_SHIFT)
//
// Globals
//
typedef struct {
} POOL;
//
// Pool header for each memory type.
//
//
// List of pool header to search for the appropriate memory type.
//
/**
Called to initialize the pool.
**/
)
{
}
}
}
/**
Look up pool head for specified memory type.
@param MemoryType Memory type of which pool head is looked for
@return Pointer of Corresponding pool head.
**/
POOL *
)
{
return &mPoolHead[MemoryType];
}
//
// MemoryType values in the range 0x80000000..0xFFFFFFFF are reserved for use by UEFI
// OS loaders that are provided by operating system vendors
//
return Pool;
}
}
return NULL;
}
}
return Pool;
}
return NULL;
}
/**
Allocate pool of a particular type.
@param PoolType Type of pool to allocate
@param Size The amount of pool to allocate
@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_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
@retval EFI_SUCCESS Pool successfully allocated.
**/
)
{
//
// If it's not a valid type, fail it
//
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
//
// If size is too large, fail it
// Base on the EFI spec, return status of EFI_OUT_OF_RESOURCES
//
if (Size > MAX_POOL_SIZE) {
return EFI_OUT_OF_RESOURCES;
}
//
// Acquire the memory lock and make the allocation
//
return EFI_OUT_OF_RESOURCES;
}
}
/**
Internal function to allocate pool of a particular type.
Caller must have the memory lock held
@param PoolType Type of pool to allocate
@param Size The amount of pool to allocate
@return The allocate pool, or NULL
**/
VOID *
)
{
//
// Adjust the size by the pool header & tail overhead
//
//
// Adjusting the Size to be of proper alignment so that
// we don't get an unaligned access fault later when
// pool_Tail is being initialized
//
Size += POOL_OVERHEAD;
return NULL;
}
//
// If allocation is over max size, just allocate pages for the request
// (slow)
//
if (Index >= MAX_POOL_LIST) {
goto Done;
}
//
// If there's no free pool in the proper list size, go get some more pages
//
//
// Get another page
//
NewPage = CoreAllocatePoolPages(PoolType, EFI_SIZE_TO_PAGES (DEFAULT_PAGE_ALLOCATION), DEFAULT_PAGE_ALLOCATION);
goto Done;
}
//
// Carve up new page into free pool blocks
//
Offset = 0;
while (Offset < DEFAULT_PAGE_ALLOCATION) {
}
Index -= 1;
}
}
//
// Remove entry from free pool list
//
Done:
//
// If we have a pool buffer, fill in the header & tail info
//
DEBUG ((
"AllocatePoolI: Type %x, Addr %p (len %lx) %,ld\n", PoolType,
));
//
// Account the allocation
//
} else {
}
return Buffer;
}
/**
Frees pool.
@param Buffer The allocated pool entry to free
@retval EFI_INVALID_PARAMETER Buffer is not a valid value.
@retval EFI_SUCCESS Pool successfully freed.
**/
)
{
return EFI_INVALID_PARAMETER;
}
return Status;
}
/**
Internal function to free a pool entry.
Caller must have the memory lock held
@param Buffer The allocated pool entry to free
@retval EFI_INVALID_PARAMETER Buffer not valid
@retval EFI_SUCCESS Buffer successfully freed.
**/
)
{
//
// Get the head & tail of the pool entry
//
return EFI_INVALID_PARAMETER;
}
//
// Debug
//
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
//
// Determine the pool type and account for it
//
return EFI_INVALID_PARAMETER;
}
DEBUG ((DEBUG_POOL, "FreePool: %p (len %lx) %,ld\n", Head->Data, (UINT64)(Head->Size - POOL_OVERHEAD), (UINT64) Pool->Used));
//
// Determine the pool list
//
//
// If it's not on the list, it must be pool pages
//
if (Index >= MAX_POOL_LIST) {
//
// Return the memory pages back to free memory
//
} else {
//
// Put the pool entry onto the free pool list
//
//
// See if all the pool entries in the same page as Free are freed pool
// entries
//
Offset = 0;
}
}
Index -= 1;
}
if (AllFree) {
//
// All of the pool entries in the same page as Free are free pool
// entries
// Remove all of these pool entries from the free loop lists.
//
Offset = 0;
while (Offset < DEFAULT_PAGE_ALLOCATION) {
}
Index -= 1;
}
//
// Free the page
//
CoreFreePoolPages ((EFI_PHYSICAL_ADDRESS) (UINTN)NewPage, EFI_SIZE_TO_PAGES (DEFAULT_PAGE_ALLOCATION));
}
}
}
//
// If this is an OS 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
//
}
return EFI_SUCCESS;
}