Page.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/** @file
SMM Memory page management functions.
Copyright (c) 2009 - 2010, 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 "PiSmmCore.h"
#define TRUNCATE_TO_PAGES(a) ((a) >> EFI_PAGE_SHIFT)
typedef struct {
/**
Internal Function. Allocate n pages from given free page node.
@param Pages The free page node.
@param NumberOfPages Number of pages to be allocated.
@param MaxAddress Request to allocate memory below this address.
@return Memory address of allocated pages.
**/
)
{
}
}
if (Bottom > 0) {
} else {
}
}
/**
Internal Function. Allocate n pages from free page list below MaxAddress.
@param FreePageList The free page node.
@param NumberOfPages Number of pages to be allocated.
@param MaxAddress Request to allocate memory below this address.
@return Memory address of allocated pages.
**/
)
{
}
}
return (UINTN)(-1);
}
/**
Internal Function. Allocate n pages from free page list at given address.
@param FreePageList The free page node.
@param NumberOfPages Number of pages to be allocated.
@param MaxAddress Request to allocate memory below this address.
@return Memory address of allocated pages.
**/
)
{
if ((Address & EFI_PAGE_MASK) != 0) {
return ~Address;
}
break;
}
}
}
return ~Address;
}
/**
Allocates pages from the memory map.
@param Type The type of allocation to perform.
@param MemoryType The type of memory to turn the allocated pages
into.
@param NumberOfPages The number of pages to allocate.
@param Memory A pointer to receive the base allocated memory
address.
@retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
@retval EFI_NOT_FOUND Could not allocate pages match the requirement.
@retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
@retval EFI_SUCCESS Pages successfully allocated.
**/
)
{
if (MemoryType != EfiRuntimeServicesCode &&
return EFI_INVALID_PARAMETER;
}
return EFI_OUT_OF_RESOURCES;
}
//
// We don't track memory type in SMM
//
switch (Type) {
case AllocateAnyPages:
case AllocateMaxAddress:
);
return EFI_OUT_OF_RESOURCES;
}
break;
case AllocateAddress:
);
if (*Memory != RequestedAddress) {
return EFI_NOT_FOUND;
}
break;
default:
return EFI_INVALID_PARAMETER;
}
return EFI_SUCCESS;
}
/**
Internal Function. Merge two adjacent nodes.
@param First The first of two nodes to merge.
@return Pointer to node after merge (if success) or pointer to next node (if fail).
**/
)
{
ASSERT (
}
return Next;
}
/**
Frees previous allocated pages.
@param Memory Base address of memory being freed.
@param NumberOfPages The number of pages to free.
@retval EFI_NOT_FOUND Could not find the entry that covers the range.
@retval EFI_INVALID_PARAMETER Address not aligned.
@return EFI_SUCCESS Pages successfully freed.
**/
)
{
if ((Memory & EFI_PAGE_MASK) != 0) {
return EFI_INVALID_PARAMETER;
}
while (Node != &mSmmMemoryMap) {
break;
}
}
if (Node != &mSmmMemoryMap &&
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
}
);
}
if (Node != &mSmmMemoryMap) {
}
return EFI_SUCCESS;
}
/**
Add free SMRAM region for use by memory service.
@param MemBase Base address of memory region.
@param MemLength Length of the memory region.
@param Type Memory type.
@param Attributes Memory region state.
**/
)
{
//
// Do not add memory regions that is already allocated, needs testing, or needs ECC initialization
//
return;
}
//
// Align range on an EFI_PAGE_SIZE boundary
//
}