summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Core/Dxe/Mem/Page.c
diff options
context:
space:
mode:
Diffstat (limited to 'MdeModulePkg/Core/Dxe/Mem/Page.c')
-rw-r--r--MdeModulePkg/Core/Dxe/Mem/Page.c687
1 files changed, 364 insertions, 323 deletions
diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c
index 731bf08..47d4c5d 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Page.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Page.c
@@ -14,38 +14,38 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// Entry for tracking the memory regions for each memory type to coalesce similar memory types
//
typedef struct {
- EFI_PHYSICAL_ADDRESS BaseAddress;
- EFI_PHYSICAL_ADDRESS MaximumAddress;
- UINT64 CurrentNumberOfPages;
- UINT64 NumberOfPages;
- UINTN InformationIndex;
- BOOLEAN Special;
- BOOLEAN Runtime;
+ EFI_PHYSICAL_ADDRESS BaseAddress;
+ EFI_PHYSICAL_ADDRESS MaximumAddress;
+ UINT64 CurrentNumberOfPages;
+ UINT64 NumberOfPages;
+ UINTN InformationIndex;
+ BOOLEAN Special;
+ BOOLEAN Runtime;
} EFI_MEMORY_TYPE_STATISTICS;
//
// MemoryMap - The current memory map
//
-UINTN mMemoryMapKey = 0;
+UINTN mMemoryMapKey = 0;
-#define MAX_MAP_DEPTH 6
+#define MAX_MAP_DEPTH 6
///
/// mMapDepth - depth of new descriptor stack
///
-UINTN mMapDepth = 0;
+UINTN mMapDepth = 0;
///
/// mMapStack - space to use as temp storage to build new map descriptors
///
-MEMORY_MAP mMapStack[MAX_MAP_DEPTH];
-UINTN mFreeMapStack = 0;
+MEMORY_MAP mMapStack[MAX_MAP_DEPTH];
+UINTN mFreeMapStack = 0;
///
/// This list maintain the free memory map list
///
-LIST_ENTRY mFreeMemoryMapEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mFreeMemoryMapEntryList);
-BOOLEAN mMemoryTypeInformationInitialized = FALSE;
+LIST_ENTRY mFreeMemoryMapEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mFreeMemoryMapEntryList);
+BOOLEAN mMemoryTypeInformationInitialized = FALSE;
-EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1] = {
+EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1] = {
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiReservedMemoryType
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiLoaderCode
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiLoaderData
@@ -64,10 +64,10 @@ EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1] = {
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE } // EfiMaxMemoryType
};
-EFI_PHYSICAL_ADDRESS mDefaultMaximumAddress = MAX_ALLOC_ADDRESS;
-EFI_PHYSICAL_ADDRESS mDefaultBaseAddress = MAX_ALLOC_ADDRESS;
+EFI_PHYSICAL_ADDRESS mDefaultMaximumAddress = MAX_ALLOC_ADDRESS;
+EFI_PHYSICAL_ADDRESS mDefaultBaseAddress = MAX_ALLOC_ADDRESS;
-EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = {
+EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = {
{ EfiReservedMemoryType, 0 },
{ EfiLoaderCode, 0 },
{ EfiLoaderData, 0 },
@@ -90,7 +90,7 @@ EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = {
// and ready to load the module in to specified address.or else, the memory is not ready and module will be loaded at a
// address assigned by DXE core.
//
-GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN gLoadFixedAddressCodeMemoryReady = FALSE;
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN gLoadFixedAddressCodeMemoryReady = FALSE;
/**
Enter critical section by gaining lock on gMemoryLock.
@@ -104,8 +104,6 @@ CoreAcquireMemoryLock (
CoreAcquireLock (&gMemoryLock);
}
-
-
/**
Exit critical section by releasing lock on gMemoryLock.
@@ -118,9 +116,6 @@ CoreReleaseMemoryLock (
CoreReleaseLock (&gMemoryLock);
}
-
-
-
/**
Internal function. Removes a descriptor entry.
@@ -129,7 +124,7 @@ CoreReleaseMemoryLock (
**/
VOID
RemoveMemoryMapEntry (
- IN OUT MEMORY_MAP *Entry
+ IN OUT MEMORY_MAP *Entry
)
{
RemoveEntryList (&Entry->Link);
@@ -157,17 +152,17 @@ RemoveMemoryMapEntry (
**/
VOID
CoreAddRange (
- IN EFI_MEMORY_TYPE Type,
- IN EFI_PHYSICAL_ADDRESS Start,
- IN EFI_PHYSICAL_ADDRESS End,
- IN UINT64 Attribute
+ IN EFI_MEMORY_TYPE Type,
+ IN EFI_PHYSICAL_ADDRESS Start,
+ IN EFI_PHYSICAL_ADDRESS End,
+ IN UINT64 Attribute
)
{
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
ASSERT ((Start & EFI_PAGE_MASK) == 0);
- ASSERT (End > Start) ;
+ ASSERT (End > Start);
ASSERT_LOCKED (&gMemoryLock);
@@ -182,7 +177,7 @@ CoreAddRange (
// at address 0, then do not zero the page at address 0 because the page is being
// used for other purposes.
//
- if (Type == EfiConventionalMemory && Start == 0 && (End >= EFI_PAGE_SIZE - 1)) {
+ if ((Type == EfiConventionalMemory) && (Start == 0) && (End >= EFI_PAGE_SIZE - 1)) {
if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) == 0) {
SetMem ((VOID *)(UINTN)Start, EFI_PAGE_SIZE, 0);
}
@@ -226,12 +221,9 @@ CoreAddRange (
}
if (Entry->End + 1 == Start) {
-
Start = Entry->Start;
RemoveMemoryMapEntry (Entry);
-
} else if (Entry->Start == End + 1) {
-
End = Entry->End;
RemoveMemoryMapEntry (Entry);
}
@@ -241,19 +233,19 @@ CoreAddRange (
// Add descriptor
//
- mMapStack[mMapDepth].Signature = MEMORY_MAP_SIGNATURE;
- mMapStack[mMapDepth].FromPages = FALSE;
- mMapStack[mMapDepth].Type = Type;
- mMapStack[mMapDepth].Start = Start;
- mMapStack[mMapDepth].End = End;
- mMapStack[mMapDepth].VirtualStart = 0;
- mMapStack[mMapDepth].Attribute = Attribute;
+ mMapStack[mMapDepth].Signature = MEMORY_MAP_SIGNATURE;
+ mMapStack[mMapDepth].FromPages = FALSE;
+ mMapStack[mMapDepth].Type = Type;
+ mMapStack[mMapDepth].Start = Start;
+ mMapStack[mMapDepth].End = End;
+ mMapStack[mMapDepth].VirtualStart = 0;
+ mMapStack[mMapDepth].Attribute = Attribute;
InsertTailList (&gMemoryMap, &mMapStack[mMapDepth].Link);
mMapDepth += 1;
ASSERT (mMapDepth < MAX_MAP_DEPTH);
- return ;
+ return;
}
/**
@@ -274,9 +266,9 @@ AllocateMemoryMapEntry (
VOID
)
{
- MEMORY_MAP* FreeDescriptorEntries;
- MEMORY_MAP* Entry;
- UINTN Index;
+ MEMORY_MAP *FreeDescriptorEntries;
+ MEMORY_MAP *Entry;
+ UINTN Index;
if (IsListEmpty (&mFreeMemoryMapEntryList)) {
//
@@ -292,7 +284,7 @@ AllocateMemoryMapEntry (
//
// Enque the free memmory map entries into the list
//
- for (Index = 0; Index < DEFAULT_PAGE_ALLOCATION_GRANULARITY / sizeof(MEMORY_MAP); Index++) {
+ for (Index = 0; Index < DEFAULT_PAGE_ALLOCATION_GRANULARITY / sizeof (MEMORY_MAP); Index++) {
FreeDescriptorEntries[Index].Signature = MEMORY_MAP_SIGNATURE;
InsertTailList (&mFreeMemoryMapEntryList, &FreeDescriptorEntries[Index].Link);
}
@@ -300,6 +292,7 @@ AllocateMemoryMapEntry (
return NULL;
}
}
+
//
// dequeue the first descriptor from the list
//
@@ -309,7 +302,6 @@ AllocateMemoryMapEntry (
return Entry;
}
-
/**
Internal function. Moves any memory descriptors that are on the
temporary descriptor stack to heap.
@@ -320,9 +312,9 @@ CoreFreeMemoryMapStack (
VOID
)
{
- MEMORY_MAP *Entry;
- MEMORY_MAP *Entry2;
- LIST_ENTRY *Link2;
+ MEMORY_MAP *Entry;
+ MEMORY_MAP *Entry2;
+ LIST_ENTRY *Link2;
ASSERT_LOCKED (&gMemoryLock);
@@ -330,7 +322,7 @@ CoreFreeMemoryMapStack (
// If already freeing the map stack, then return
//
if (mFreeMapStack != 0) {
- return ;
+ return;
}
//
@@ -352,14 +344,13 @@ CoreFreeMemoryMapStack (
mMapDepth -= 1;
if (mMapStack[mMapDepth].Link.ForwardLink != NULL) {
-
//
// Move this entry to general memory
//
RemoveEntryList (&mMapStack[mMapDepth].Link);
mMapStack[mMapDepth].Link.ForwardLink = NULL;
- CopyMem (Entry , &mMapStack[mMapDepth], sizeof (MEMORY_MAP));
+ CopyMem (Entry, &mMapStack[mMapDepth], sizeof (MEMORY_MAP));
Entry->FromPages = TRUE;
//
@@ -367,13 +358,12 @@ CoreFreeMemoryMapStack (
//
for (Link2 = gMemoryMap.ForwardLink; Link2 != &gMemoryMap; Link2 = Link2->ForwardLink) {
Entry2 = CR (Link2, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
- if (Entry2->FromPages && Entry2->Start > Entry->Start) {
+ if (Entry2->FromPages && (Entry2->Start > Entry->Start)) {
break;
}
}
InsertTailList (Link2, &Entry->Link);
-
} else {
//
// This item of mMapStack[mMapDepth] has already been dequeued from gMemoryMap list,
@@ -395,27 +385,27 @@ PromoteMemoryResource (
VOID
)
{
- LIST_ENTRY *Link;
- EFI_GCD_MAP_ENTRY *Entry;
- BOOLEAN Promoted;
- EFI_PHYSICAL_ADDRESS StartAddress;
- EFI_PHYSICAL_ADDRESS EndAddress;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
+ LIST_ENTRY *Link;
+ EFI_GCD_MAP_ENTRY *Entry;
+ BOOLEAN Promoted;
+ EFI_PHYSICAL_ADDRESS StartAddress;
+ EFI_PHYSICAL_ADDRESS EndAddress;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
DEBUG ((DEBUG_PAGE, "Promote the memory resource\n"));
CoreAcquireGcdMemoryLock ();
Promoted = FALSE;
- Link = mGcdMemorySpaceMap.ForwardLink;
+ Link = mGcdMemorySpaceMap.ForwardLink;
while (Link != &mGcdMemorySpaceMap) {
-
Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
- if (Entry->GcdMemoryType == EfiGcdMemoryTypeReserved &&
- Entry->EndAddress < MAX_ALLOC_ADDRESS &&
- (Entry->Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
- (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)) {
+ if ((Entry->GcdMemoryType == EfiGcdMemoryTypeReserved) &&
+ (Entry->EndAddress < MAX_ALLOC_ADDRESS) &&
+ ((Entry->Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
+ (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)))
+ {
//
// Update the GCD map
//
@@ -424,9 +414,10 @@ PromoteMemoryResource (
} else {
Entry->GcdMemoryType = EfiGcdMemoryTypeSystemMemory;
}
+
Entry->Capabilities |= EFI_MEMORY_TESTED;
- Entry->ImageHandle = gDxeCoreImageHandle;
- Entry->DeviceHandle = NULL;
+ Entry->ImageHandle = gDxeCoreImageHandle;
+ Entry->DeviceHandle = NULL;
//
// Add to allocable system memory resource
@@ -468,6 +459,7 @@ PromoteMemoryResource (
return Promoted;
}
+
/**
This function try to allocate Runtime code & Boot time code memory range. If LMFA enabled, 2 patchable PCD
PcdLoadFixAddressRuntimeCodePageNumber & PcdLoadFixAddressBootTimeCodePageNumber which are set by tools will record the
@@ -479,58 +471,61 @@ CoreLoadingFixedAddressHook (
VOID
)
{
- UINT32 RuntimeCodePageNumber;
- UINT32 BootTimeCodePageNumber;
- EFI_PHYSICAL_ADDRESS RuntimeCodeBase;
- EFI_PHYSICAL_ADDRESS BootTimeCodeBase;
- EFI_STATUS Status;
-
- //
- // Make sure these 2 areas are not initialzied.
- //
- if (!gLoadFixedAddressCodeMemoryReady) {
- RuntimeCodePageNumber = PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber);
- BootTimeCodePageNumber= PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber);
- RuntimeCodeBase = (EFI_PHYSICAL_ADDRESS)(gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress - EFI_PAGES_TO_SIZE (RuntimeCodePageNumber));
- BootTimeCodeBase = (EFI_PHYSICAL_ADDRESS)(RuntimeCodeBase - EFI_PAGES_TO_SIZE (BootTimeCodePageNumber));
- //
- // Try to allocate runtime memory.
- //
- Status = CoreAllocatePages (
- AllocateAddress,
- EfiRuntimeServicesCode,
- RuntimeCodePageNumber,
- &RuntimeCodeBase
- );
- if (EFI_ERROR(Status)) {
- //
- // Runtime memory allocation failed
- //
- return;
- }
- //
- // Try to allocate boot memory.
- //
- Status = CoreAllocatePages (
- AllocateAddress,
- EfiBootServicesCode,
- BootTimeCodePageNumber,
- &BootTimeCodeBase
- );
- if (EFI_ERROR(Status)) {
- //
- // boot memory allocation failed. Free Runtime code range and will try the allocation again when
- // new memory range is installed.
- //
- CoreFreePages (
- RuntimeCodeBase,
- RuntimeCodePageNumber
- );
- return;
- }
- gLoadFixedAddressCodeMemoryReady = TRUE;
- }
- return;
+ UINT32 RuntimeCodePageNumber;
+ UINT32 BootTimeCodePageNumber;
+ EFI_PHYSICAL_ADDRESS RuntimeCodeBase;
+ EFI_PHYSICAL_ADDRESS BootTimeCodeBase;
+ EFI_STATUS Status;
+
+ //
+ // Make sure these 2 areas are not initialzied.
+ //
+ if (!gLoadFixedAddressCodeMemoryReady) {
+ RuntimeCodePageNumber = PcdGet32 (PcdLoadFixAddressRuntimeCodePageNumber);
+ BootTimeCodePageNumber = PcdGet32 (PcdLoadFixAddressBootTimeCodePageNumber);
+ RuntimeCodeBase = (EFI_PHYSICAL_ADDRESS)(gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress - EFI_PAGES_TO_SIZE (RuntimeCodePageNumber));
+ BootTimeCodeBase = (EFI_PHYSICAL_ADDRESS)(RuntimeCodeBase - EFI_PAGES_TO_SIZE (BootTimeCodePageNumber));
+ //
+ // Try to allocate runtime memory.
+ //
+ Status = CoreAllocatePages (
+ AllocateAddress,
+ EfiRuntimeServicesCode,
+ RuntimeCodePageNumber,
+ &RuntimeCodeBase
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // Runtime memory allocation failed
+ //
+ return;
+ }
+
+ //
+ // Try to allocate boot memory.
+ //
+ Status = CoreAllocatePages (
+ AllocateAddress,
+ EfiBootServicesCode,
+ BootTimeCodePageNumber,
+ &BootTimeCodeBase
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // boot memory allocation failed. Free Runtime code range and will try the allocation again when
+ // new memory range is installed.
+ //
+ CoreFreePages (
+ RuntimeCodeBase,
+ RuntimeCodePageNumber
+ );
+ return;
+ }
+
+ gLoadFixedAddressCodeMemoryReady = TRUE;
+ }
+
+ return;
}
/**
@@ -556,32 +551,37 @@ CoreAddMemoryDescriptor (
IN UINT64 Attribute
)
{
- EFI_PHYSICAL_ADDRESS End;
- EFI_STATUS Status;
- UINTN Index;
- UINTN FreeIndex;
+ EFI_PHYSICAL_ADDRESS End;
+ EFI_STATUS Status;
+ UINTN Index;
+ UINTN FreeIndex;
if ((Start & EFI_PAGE_MASK) != 0) {
return;
}
- if (Type >= EfiMaxMemoryType && Type < MEMORY_TYPE_OEM_RESERVED_MIN) {
+ if ((Type >= EfiMaxMemoryType) && (Type < MEMORY_TYPE_OEM_RESERVED_MIN)) {
return;
}
+
CoreAcquireMemoryLock ();
End = Start + LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT) - 1;
CoreAddRange (Type, Start, End, Attribute);
CoreFreeMemoryMapStack ();
CoreReleaseMemoryLock ();
- ApplyMemoryProtectionPolicy (EfiMaxMemoryType, Type, Start,
- LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT));
+ ApplyMemoryProtectionPolicy (
+ EfiMaxMemoryType,
+ Type,
+ Start,
+ LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT)
+ );
//
// If Loading Module At Fixed Address feature is enabled. try to allocate memory with Runtime code & Boot time code type
//
- if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
- CoreLoadingFixedAddressHook();
+ if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) {
+ CoreLoadingFixedAddressHook ();
}
//
@@ -591,7 +591,6 @@ CoreAddMemoryDescriptor (
return;
}
-
//
// Loop through each memory type in the order specified by the gMemoryTypeInformation[] array
//
@@ -599,10 +598,11 @@ CoreAddMemoryDescriptor (
//
// Make sure the memory type in the gMemoryTypeInformation[] array is valid
//
- Type = (EFI_MEMORY_TYPE) (gMemoryTypeInformation[Index].Type);
+ Type = (EFI_MEMORY_TYPE)(gMemoryTypeInformation[Index].Type);
if ((UINT32)Type > EfiMaxMemoryType) {
continue;
}
+
if (gMemoryTypeInformation[Index].NumberOfPages != 0) {
//
// Allocate pages for the current memory type from the top of available memory
@@ -623,7 +623,7 @@ CoreAddMemoryDescriptor (
//
// Make sure the memory type in the gMemoryTypeInformation[] array is valid
//
- Type = (EFI_MEMORY_TYPE) (gMemoryTypeInformation[FreeIndex].Type);
+ Type = (EFI_MEMORY_TYPE)(gMemoryTypeInformation[FreeIndex].Type);
if ((UINT32)Type > EfiMaxMemoryType) {
continue;
}
@@ -637,6 +637,7 @@ CoreAddMemoryDescriptor (
mMemoryTypeStatistics[Type].MaximumAddress = MAX_ALLOC_ADDRESS;
}
}
+
return;
}
@@ -666,10 +667,11 @@ CoreAddMemoryDescriptor (
//
// Make sure the memory type in the gMemoryTypeInformation[] array is valid
//
- Type = (EFI_MEMORY_TYPE) (gMemoryTypeInformation[Index].Type);
+ Type = (EFI_MEMORY_TYPE)(gMemoryTypeInformation[Index].Type);
if ((UINT32)Type > EfiMaxMemoryType) {
continue;
}
+
if (gMemoryTypeInformation[Index].NumberOfPages != 0) {
CoreFreePages (
mMemoryTypeStatistics[Type].BaseAddress,
@@ -684,12 +686,13 @@ CoreAddMemoryDescriptor (
// If the number of pages reserved for a memory type is 0, then all allocations for that type
// should be in the default range.
//
- for (Type = (EFI_MEMORY_TYPE) 0; Type < EfiMaxMemoryType; Type++) {
+ for (Type = (EFI_MEMORY_TYPE)0; Type < EfiMaxMemoryType; Type++) {
for (Index = 0; gMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) {
if (Type == (EFI_MEMORY_TYPE)gMemoryTypeInformation[Index].Type) {
mMemoryTypeStatistics[Type].InformationIndex = Index;
}
}
+
mMemoryTypeStatistics[Type].CurrentNumberOfPages = 0;
if (mMemoryTypeStatistics[Type].MaximumAddress == MAX_ALLOC_ADDRESS) {
mMemoryTypeStatistics[Type].MaximumAddress = mDefaultMaximumAddress;
@@ -699,7 +702,6 @@ CoreAddMemoryDescriptor (
mMemoryTypeInformationInitialized = TRUE;
}
-
/**
Internal function. Converts a memory range to the specified type or attributes.
The range must exist in the memory map. Either ChangingType or
@@ -730,26 +732,25 @@ CoreConvertPagesEx (
IN UINT64 NewAttributes
)
{
+ UINT64 NumberOfBytes;
+ UINT64 End;
+ UINT64 RangeEnd;
+ UINT64 Attribute;
+ EFI_MEMORY_TYPE MemType;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
- UINT64 NumberOfBytes;
- UINT64 End;
- UINT64 RangeEnd;
- UINT64 Attribute;
- EFI_MEMORY_TYPE MemType;
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
-
- Entry = NULL;
+ Entry = NULL;
NumberOfBytes = LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT);
- End = Start + NumberOfBytes - 1;
+ End = Start + NumberOfBytes - 1;
ASSERT (NumberOfPages);
ASSERT ((Start & EFI_PAGE_MASK) == 0);
- ASSERT (End > Start) ;
+ ASSERT (End > Start);
ASSERT_LOCKED (&gMemoryLock);
- ASSERT ( (ChangingType == FALSE) || (ChangingAttributes == FALSE) );
+ ASSERT ((ChangingType == FALSE) || (ChangingAttributes == FALSE));
- if (NumberOfPages == 0 || ((Start & EFI_PAGE_MASK) != 0) || (Start >= End)) {
+ if ((NumberOfPages == 0) || ((Start & EFI_PAGE_MASK) != 0) || (Start >= End)) {
return EFI_INVALID_PARAMETER;
}
@@ -758,14 +759,13 @@ CoreConvertPagesEx (
//
while (Start < End) {
-
//
// Find the entry that the covers the range
//
for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) {
Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
- if (Entry->Start <= Start && Entry->End > Start) {
+ if ((Entry->Start <= Start) && (Entry->End > Start)) {
break;
}
}
@@ -786,6 +786,7 @@ CoreConvertPagesEx (
return EFI_NOT_FOUND;
}
}
+
//
// Convert range to the end, or to the end of the descriptor
// if that's all we've got
@@ -800,6 +801,7 @@ CoreConvertPagesEx (
if (ChangingType) {
DEBUG ((DEBUG_PAGE, "ConvertRange: %lx-%lx to type %d\n", Start, RangeEnd, NewType));
}
+
if (ChangingAttributes) {
DEBUG ((DEBUG_PAGE, "ConvertRange: %lx-%lx to attr %lx\n", Start, RangeEnd, NewAttributes));
}
@@ -808,13 +810,14 @@ CoreConvertPagesEx (
//
// Debug code - verify conversion is allowed
//
- if (!(NewType == EfiConventionalMemory ? 1 : 0) ^ (Entry->Type == EfiConventionalMemory ? 1 : 0)) {
+ if (!((NewType == EfiConventionalMemory) ? 1 : 0) ^ ((Entry->Type == EfiConventionalMemory) ? 1 : 0)) {
DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "ConvertPages: Incompatible memory types, "));
if (Entry->Type == EfiConventionalMemory) {
DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "the pages to free have been freed\n"));
} else {
DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "the pages to allocate have been allocated\n"));
}
+
return EFI_NOT_FOUND;
}
@@ -822,8 +825,9 @@ CoreConvertPagesEx (
// Update counters for the number of pages allocated to each memory type
//
if ((UINT32)Entry->Type < EfiMaxMemoryType) {
- if ((Start >= mMemoryTypeStatistics[Entry->Type].BaseAddress && Start <= mMemoryTypeStatistics[Entry->Type].MaximumAddress) ||
- (Start >= mDefaultBaseAddress && Start <= mDefaultMaximumAddress) ) {
+ if (((Start >= mMemoryTypeStatistics[Entry->Type].BaseAddress) && (Start <= mMemoryTypeStatistics[Entry->Type].MaximumAddress)) ||
+ ((Start >= mDefaultBaseAddress) && (Start <= mDefaultMaximumAddress)))
+ {
if (NumberOfPages > mMemoryTypeStatistics[Entry->Type].CurrentNumberOfPages) {
mMemoryTypeStatistics[Entry->Type].CurrentNumberOfPages = 0;
} else {
@@ -833,8 +837,9 @@ CoreConvertPagesEx (
}
if ((UINT32)NewType < EfiMaxMemoryType) {
- if ((Start >= mMemoryTypeStatistics[NewType].BaseAddress && Start <= mMemoryTypeStatistics[NewType].MaximumAddress) ||
- (Start >= mDefaultBaseAddress && Start <= mDefaultMaximumAddress) ) {
+ if (((Start >= mMemoryTypeStatistics[NewType].BaseAddress) && (Start <= mMemoryTypeStatistics[NewType].MaximumAddress)) ||
+ ((Start >= mDefaultBaseAddress) && (Start <= mDefaultMaximumAddress)))
+ {
mMemoryTypeStatistics[NewType].CurrentNumberOfPages += NumberOfPages;
if (mMemoryTypeStatistics[NewType].CurrentNumberOfPages > gMemoryTypeInformation[mMemoryTypeStatistics[NewType].InformationIndex].NumberOfPages) {
gMemoryTypeInformation[mMemoryTypeStatistics[NewType].InformationIndex].NumberOfPages = (UINT32)mMemoryTypeStatistics[NewType].CurrentNumberOfPages;
@@ -847,21 +852,16 @@ CoreConvertPagesEx (
// Pull range out of descriptor
//
if (Entry->Start == Start) {
-
//
// Clip start
//
Entry->Start = RangeEnd + 1;
-
} else if (Entry->End == RangeEnd) {
-
//
// Clip end
//
Entry->End = Start - 1;
-
} else {
-
//
// Pull it out of the center, clip current
//
@@ -870,7 +870,7 @@ CoreConvertPagesEx (
// Add a new one
//
mMapStack[mMapDepth].Signature = MEMORY_MAP_SIGNATURE;
- mMapStack[mMapDepth].FromPages = FALSE;
+ mMapStack[mMapDepth].FromPages = FALSE;
mMapStack[mMapDepth].Type = Entry->Type;
mMapStack[mMapDepth].Start = RangeEnd+1;
mMapStack[mMapDepth].End = Entry->End;
@@ -896,10 +896,10 @@ CoreConvertPagesEx (
//
if (ChangingType) {
Attribute = Entry->Attribute;
- MemType = NewType;
+ MemType = NewType;
} else {
Attribute = NewAttributes;
- MemType = Entry->Type;
+ MemType = Entry->Type;
}
//
@@ -916,7 +916,8 @@ CoreConvertPagesEx (
//
if (!IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED) ||
!ChangingType ||
- MemType != EfiConventionalMemory) {
+ (MemType != EfiConventionalMemory))
+ {
CoreAddRange (MemType, Start, RangeEnd, Attribute);
}
@@ -928,10 +929,10 @@ CoreConvertPagesEx (
//
if (Start == 0) {
if (RangeEnd > EFI_PAGE_SIZE) {
- DEBUG_CLEAR_MEMORY ((VOID *)(UINTN) EFI_PAGE_SIZE, (UINTN) (RangeEnd - EFI_PAGE_SIZE + 1));
+ DEBUG_CLEAR_MEMORY ((VOID *)(UINTN)EFI_PAGE_SIZE, (UINTN)(RangeEnd - EFI_PAGE_SIZE + 1));
}
} else {
- DEBUG_CLEAR_MEMORY ((VOID *)(UINTN) Start, (UINTN) (RangeEnd - Start + 1));
+ DEBUG_CLEAR_MEMORY ((VOID *)(UINTN)Start, (UINTN)(RangeEnd - Start + 1));
}
}
@@ -953,7 +954,6 @@ CoreConvertPagesEx (
return EFI_SUCCESS;
}
-
/**
Internal function. Converts a memory range to the specified type.
The range must exist in the memory map.
@@ -977,10 +977,9 @@ CoreConvertPages (
IN EFI_MEMORY_TYPE NewType
)
{
- return CoreConvertPagesEx(Start, NumberOfPages, TRUE, NewType, FALSE, 0);
+ return CoreConvertPagesEx (Start, NumberOfPages, TRUE, NewType, FALSE, 0);
}
-
/**
Internal function. Converts a memory range to use new attributes.
@@ -1002,12 +1001,11 @@ CoreUpdateMemoryAttributes (
//
// Update the attributes to the new value
//
- CoreConvertPagesEx(Start, NumberOfPages, FALSE, (EFI_MEMORY_TYPE)0, TRUE, NewAttributes);
+ CoreConvertPagesEx (Start, NumberOfPages, FALSE, (EFI_MEMORY_TYPE)0, TRUE, NewAttributes);
CoreReleaseMemoryLock ();
}
-
/**
Internal function. Finds a consecutive free page range below
the requested address.
@@ -1033,20 +1031,19 @@ CoreFindFreePagesI (
IN BOOLEAN NeedGuard
)
{
- UINT64 NumberOfBytes;
- UINT64 Target;
- UINT64 DescStart;
- UINT64 DescEnd;
- UINT64 DescNumberOfBytes;
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
-
- if ((MaxAddress < EFI_PAGE_MASK) ||(NumberOfPages == 0)) {
+ UINT64 NumberOfBytes;
+ UINT64 Target;
+ UINT64 DescStart;
+ UINT64 DescEnd;
+ UINT64 DescNumberOfBytes;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
+
+ if ((MaxAddress < EFI_PAGE_MASK) || (NumberOfPages == 0)) {
return 0;
}
if ((MaxAddress & EFI_PAGE_MASK) != EFI_PAGE_MASK) {
-
//
// If MaxAddress is not aligned to the end of a page
//
@@ -1068,7 +1065,7 @@ CoreFindFreePagesI (
}
NumberOfBytes = LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT);
- Target = 0;
+ Target = 0;
for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) {
Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
@@ -1081,7 +1078,7 @@ CoreFindFreePagesI (
}
DescStart = Entry->Start;
- DescEnd = Entry->End;
+ DescEnd = Entry->End;
//
// If desc is past max allowed address or below min allowed address, skip it
@@ -1153,7 +1150,6 @@ CoreFindFreePagesI (
return Target;
}
-
/**
Internal function. Finds a consecutive free page range below
the requested address
@@ -1170,19 +1166,19 @@ CoreFindFreePagesI (
**/
UINT64
FindFreePages (
- IN UINT64 MaxAddress,
- IN UINT64 NoPages,
- IN EFI_MEMORY_TYPE NewType,
- IN UINTN Alignment,
- IN BOOLEAN NeedGuard
- )
+ IN UINT64 MaxAddress,
+ IN UINT64 NoPages,
+ IN EFI_MEMORY_TYPE NewType,
+ IN UINTN Alignment,
+ IN BOOLEAN NeedGuard
+ )
{
- UINT64 Start;
+ UINT64 Start;
//
// Attempt to find free pages in the preferred bin based on the requested memory type
//
- if ((UINT32)NewType < EfiMaxMemoryType && MaxAddress >= mMemoryTypeStatistics[NewType].MaximumAddress) {
+ if (((UINT32)NewType < EfiMaxMemoryType) && (MaxAddress >= mMemoryTypeStatistics[NewType].MaximumAddress)) {
Start = CoreFindFreePagesI (
mMemoryTypeStatistics[NewType].MaximumAddress,
mMemoryTypeStatistics[NewType].BaseAddress,
@@ -1200,12 +1196,19 @@ FindFreePages (
// Attempt to find free pages in the default allocation bin
//
if (MaxAddress >= mDefaultMaximumAddress) {
- Start = CoreFindFreePagesI (mDefaultMaximumAddress, 0, NoPages, NewType,
- Alignment, NeedGuard);
+ Start = CoreFindFreePagesI (
+ mDefaultMaximumAddress,
+ 0,
+ NoPages,
+ NewType,
+ Alignment,
+ NeedGuard
+ );
if (Start != 0) {
if (Start < mDefaultBaseAddress) {
mDefaultBaseAddress = Start;
}
+
return Start;
}
}
@@ -1216,8 +1219,14 @@ FindFreePages (
// address range. If this allocation fails, then there are not enough
// resources anywhere to satisfy the request.
//
- Start = CoreFindFreePagesI (MaxAddress, 0, NoPages, NewType, Alignment,
- NeedGuard);
+ Start = CoreFindFreePagesI (
+ MaxAddress,
+ 0,
+ NoPages,
+ NewType,
+ Alignment,
+ NeedGuard
+ );
if (Start != 0) {
return Start;
}
@@ -1235,7 +1244,6 @@ FindFreePages (
return FindFreePages (MaxAddress, NoPages, NewType, Alignment, NeedGuard);
}
-
/**
Allocates pages from the memory map.
@@ -1258,11 +1266,11 @@ FindFreePages (
EFI_STATUS
EFIAPI
CoreInternalAllocatePages (
- IN EFI_ALLOCATE_TYPE Type,
- IN EFI_MEMORY_TYPE MemoryType,
- IN UINTN NumberOfPages,
+ IN EFI_ALLOCATE_TYPE Type,
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN UINTN NumberOfPages,
IN OUT EFI_PHYSICAL_ADDRESS *Memory,
- IN BOOLEAN NeedGuard
+ IN BOOLEAN NeedGuard
)
{
EFI_STATUS Status;
@@ -1277,8 +1285,9 @@ CoreInternalAllocatePages (
return EFI_INVALID_PARAMETER;
}
- if ((MemoryType >= EfiMaxMemoryType && MemoryType < MEMORY_TYPE_OEM_RESERVED_MIN) ||
- (MemoryType == EfiConventionalMemory) || (MemoryType == EfiPersistentMemory)) {
+ if (((MemoryType >= EfiMaxMemoryType) && (MemoryType < MEMORY_TYPE_OEM_RESERVED_MIN)) ||
+ (MemoryType == EfiConventionalMemory) || (MemoryType == EfiPersistentMemory))
+ {
return EFI_INVALID_PARAMETER;
}
@@ -1288,11 +1297,11 @@ CoreInternalAllocatePages (
Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
- if (MemoryType == EfiACPIReclaimMemory ||
- MemoryType == EfiACPIMemoryNVS ||
- MemoryType == EfiRuntimeServicesCode ||
- MemoryType == EfiRuntimeServicesData) {
-
+ if ((MemoryType == EfiACPIReclaimMemory) ||
+ (MemoryType == EfiACPIMemoryNVS) ||
+ (MemoryType == EfiRuntimeServicesCode) ||
+ (MemoryType == EfiRuntimeServicesData))
+ {
Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
}
@@ -1327,15 +1336,18 @@ CoreInternalAllocatePages (
//
if (Type == AllocateAddress) {
if ((NumberOfPages == 0) ||
- (NumberOfPages > RShiftU64 (MaxAddress, EFI_PAGE_SHIFT))) {
+ (NumberOfPages > RShiftU64 (MaxAddress, EFI_PAGE_SHIFT)))
+ {
return EFI_NOT_FOUND;
}
+
NumberOfBytes = LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT);
- End = Start + NumberOfBytes - 1;
+ End = Start + NumberOfBytes - 1;
if ((Start >= End) ||
(Start > MaxAddress) ||
- (End > MaxAddress)) {
+ (End > MaxAddress))
+ {
return EFI_NOT_FOUND;
}
@@ -1347,20 +1359,26 @@ CoreInternalAllocatePages (
// fragmented.
//
- for (CheckType = (EFI_MEMORY_TYPE) 0; CheckType < EfiMaxMemoryType; CheckType++) {
- if (MemoryType != CheckType &&
+ for (CheckType = (EFI_MEMORY_TYPE)0; CheckType < EfiMaxMemoryType; CheckType++) {
+ if ((MemoryType != CheckType) &&
mMemoryTypeStatistics[CheckType].Special &&
- mMemoryTypeStatistics[CheckType].NumberOfPages > 0) {
- if (Start >= mMemoryTypeStatistics[CheckType].BaseAddress &&
- Start <= mMemoryTypeStatistics[CheckType].MaximumAddress) {
+ (mMemoryTypeStatistics[CheckType].NumberOfPages > 0))
+ {
+ if ((Start >= mMemoryTypeStatistics[CheckType].BaseAddress) &&
+ (Start <= mMemoryTypeStatistics[CheckType].MaximumAddress))
+ {
return EFI_NOT_FOUND;
}
- if (End >= mMemoryTypeStatistics[CheckType].BaseAddress &&
- End <= mMemoryTypeStatistics[CheckType].MaximumAddress) {
+
+ if ((End >= mMemoryTypeStatistics[CheckType].BaseAddress) &&
+ (End <= mMemoryTypeStatistics[CheckType].MaximumAddress))
+ {
return EFI_NOT_FOUND;
}
- if (Start < mMemoryTypeStatistics[CheckType].BaseAddress &&
- End > mMemoryTypeStatistics[CheckType].MaximumAddress) {
+
+ if ((Start < mMemoryTypeStatistics[CheckType].BaseAddress) &&
+ (End > mMemoryTypeStatistics[CheckType].MaximumAddress))
+ {
return EFI_NOT_FOUND;
}
}
@@ -1377,8 +1395,13 @@ CoreInternalAllocatePages (
// If not a specific address, then find an address to allocate
//
if (Type != AllocateAddress) {
- Start = FindFreePages (MaxAddress, NumberOfPages, MemoryType, Alignment,
- NeedGuard);
+ Start = FindFreePages (
+ MaxAddress,
+ NumberOfPages,
+ MemoryType,
+ Alignment,
+ NeedGuard
+ );
if (Start == 0) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
@@ -1389,9 +1412,9 @@ CoreInternalAllocatePages (
// Convert pages from FreeMemory to the requested type
//
if (NeedGuard) {
- Status = CoreConvertPagesWithGuard(Start, NumberOfPages, MemoryType);
+ Status = CoreConvertPagesWithGuard (Start, NumberOfPages, MemoryType);
} else {
- Status = CoreConvertPages(Start, NumberOfPages, MemoryType);
+ Status = CoreConvertPages (Start, NumberOfPages, MemoryType);
}
Done:
@@ -1401,6 +1424,7 @@ Done:
if (NeedGuard) {
SetGuardForMemory (Start, NumberOfPages);
}
+
*Memory = Start;
}
@@ -1438,21 +1462,31 @@ CoreAllocatePages (
BOOLEAN NeedGuard;
NeedGuard = IsPageTypeToGuard (MemoryType, Type) && !mOnGuarding;
- Status = CoreInternalAllocatePages (Type, MemoryType, NumberOfPages, Memory,
- NeedGuard);
+ Status = CoreInternalAllocatePages (
+ Type,
+ MemoryType,
+ NumberOfPages,
+ Memory,
+ NeedGuard
+ );
if (!EFI_ERROR (Status)) {
CoreUpdateProfile (
- (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
+ (EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionAllocatePages,
MemoryType,
EFI_PAGES_TO_SIZE (NumberOfPages),
- (VOID *) (UINTN) *Memory,
+ (VOID *)(UINTN)*Memory,
NULL
);
InstallMemoryAttributesTableOnMemoryAllocation (MemoryType);
- ApplyMemoryProtectionPolicy (EfiConventionalMemory, MemoryType, *Memory,
- EFI_PAGES_TO_SIZE (NumberOfPages));
+ ApplyMemoryProtectionPolicy (
+ EfiConventionalMemory,
+ MemoryType,
+ *Memory,
+ EFI_PAGES_TO_SIZE (NumberOfPages)
+ );
}
+
return Status;
}
@@ -1471,16 +1505,16 @@ CoreAllocatePages (
EFI_STATUS
EFIAPI
CoreInternalFreePages (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages,
- OUT EFI_MEMORY_TYPE *MemoryType OPTIONAL
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages,
+ OUT EFI_MEMORY_TYPE *MemoryType OPTIONAL
)
{
- EFI_STATUS Status;
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
- UINTN Alignment;
- BOOLEAN IsGuarded;
+ EFI_STATUS Status;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
+ UINTN Alignment;
+ BOOLEAN IsGuarded;
//
// Free the range
@@ -1491,13 +1525,14 @@ CoreInternalFreePages (
// Find the entry that the covers the range
//
IsGuarded = FALSE;
- Entry = NULL;
+ Entry = NULL;
for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) {
- Entry = CR(Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
- if (Entry->Start <= Memory && Entry->End > Memory) {
- break;
+ Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
+ if ((Entry->Start <= Memory) && (Entry->End > Memory)) {
+ break;
}
}
+
if (Link == &gMemoryMap) {
Status = EFI_NOT_FOUND;
goto Done;
@@ -1506,13 +1541,12 @@ CoreInternalFreePages (
Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
ASSERT (Entry != NULL);
- if (Entry->Type == EfiACPIReclaimMemory ||
- Entry->Type == EfiACPIMemoryNVS ||
- Entry->Type == EfiRuntimeServicesCode ||
- Entry->Type == EfiRuntimeServicesData) {
-
+ if ((Entry->Type == EfiACPIReclaimMemory) ||
+ (Entry->Type == EfiACPIMemoryNVS) ||
+ (Entry->Type == EfiRuntimeServicesCode) ||
+ (Entry->Type == EfiRuntimeServicesData))
+ {
Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
-
}
if ((Memory & (Alignment - 1)) != 0) {
@@ -1530,8 +1564,11 @@ CoreInternalFreePages (
IsGuarded = IsPageTypeToGuard (Entry->Type, AllocateAnyPages) &&
IsMemoryGuarded (Memory);
if (IsGuarded) {
- Status = CoreConvertPagesWithGuard (Memory, NumberOfPages,
- EfiConventionalMemory);
+ Status = CoreConvertPagesWithGuard (
+ Memory,
+ NumberOfPages,
+ EfiConventionalMemory
+ );
} else {
Status = CoreConvertPages (Memory, NumberOfPages, EfiConventionalMemory);
}
@@ -1559,24 +1596,29 @@ CoreFreePages (
IN UINTN NumberOfPages
)
{
- EFI_STATUS Status;
- EFI_MEMORY_TYPE MemoryType;
+ EFI_STATUS Status;
+ EFI_MEMORY_TYPE MemoryType;
Status = CoreInternalFreePages (Memory, NumberOfPages, &MemoryType);
if (!EFI_ERROR (Status)) {
GuardFreedPagesChecked (Memory, NumberOfPages);
CoreUpdateProfile (
- (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
+ (EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionFreePages,
MemoryType,
EFI_PAGES_TO_SIZE (NumberOfPages),
- (VOID *) (UINTN) Memory,
+ (VOID *)(UINTN)Memory,
NULL
);
InstallMemoryAttributesTableOnMemoryAllocation (MemoryType);
- ApplyMemoryProtectionPolicy (MemoryType, EfiConventionalMemory, Memory,
- EFI_PAGES_TO_SIZE (NumberOfPages));
+ ApplyMemoryProtectionPolicy (
+ MemoryType,
+ EfiConventionalMemory,
+ Memory,
+ EFI_PAGES_TO_SIZE (NumberOfPages)
+ );
}
+
return Status;
}
@@ -1604,7 +1646,7 @@ MergeMemoryMapDescriptor (
//
// Traverse the array of descriptors in MemoryMap
//
- for (; MemoryMap != MemoryMapDescriptor; MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, DescriptorSize)) {
+ for ( ; MemoryMap != MemoryMapDescriptor; MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, DescriptorSize)) {
//
// Check to see if the Type fields are identical.
//
@@ -1701,17 +1743,17 @@ CoreGetMemoryMap (
OUT UINT32 *DescriptorVersion
)
{
- EFI_STATUS Status;
- UINTN Size;
- UINTN BufferSize;
- UINTN NumberOfEntries;
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
- EFI_GCD_MAP_ENTRY *GcdMapEntry;
- EFI_GCD_MAP_ENTRY MergeGcdMapEntry;
- EFI_MEMORY_TYPE Type;
- EFI_MEMORY_DESCRIPTOR *MemoryMapStart;
- EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
+ EFI_STATUS Status;
+ UINTN Size;
+ UINTN BufferSize;
+ UINTN NumberOfEntries;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
+ EFI_GCD_MAP_ENTRY *GcdMapEntry;
+ EFI_GCD_MAP_ENTRY MergeGcdMapEntry;
+ EFI_MEMORY_TYPE Type;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapStart;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
//
// Make sure the parameters are valid
@@ -1732,8 +1774,9 @@ CoreGetMemoryMap (
if ((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypePersistent) ||
(GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) ||
((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) &&
- ((GcdMapEntry->Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME))) {
- NumberOfEntries ++;
+ ((GcdMapEntry->Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME)))
+ {
+ NumberOfEntries++;
}
}
@@ -1744,7 +1787,7 @@ CoreGetMemoryMap (
// prevent people from having pointer math bugs in their code.
// now you have to use *DescriptorSize to make things work.
//
- Size += sizeof(UINT64) - (Size % sizeof (UINT64));
+ Size += sizeof (UINT64) - (Size % sizeof (UINT64));
if (DescriptorSize != NULL) {
*DescriptorSize = Size;
@@ -1786,10 +1829,10 @@ CoreGetMemoryMap (
//
// Convert internal map into an EFI_MEMORY_DESCRIPTOR
//
- MemoryMap->Type = Entry->Type;
- MemoryMap->PhysicalStart = Entry->Start;
- MemoryMap->VirtualStart = Entry->VirtualStart;
- MemoryMap->NumberOfPages = RShiftU64 (Entry->End - Entry->Start + 1, EFI_PAGE_SHIFT);
+ MemoryMap->Type = Entry->Type;
+ MemoryMap->PhysicalStart = Entry->Start;
+ MemoryMap->VirtualStart = Entry->VirtualStart;
+ MemoryMap->NumberOfPages = RShiftU64 (Entry->End - Entry->Start + 1, EFI_PAGE_SHIFT);
//
// If the memory type is EfiConventionalMemory, then determine if the range is part of a
// memory type bin and needs to be converted to the same memory type as the rest of the
@@ -1798,15 +1841,17 @@ CoreGetMemoryMap (
// differences across reboots.
//
if (MemoryMap->Type == EfiConventionalMemory) {
- for (Type = (EFI_MEMORY_TYPE) 0; Type < EfiMaxMemoryType; Type++) {
+ for (Type = (EFI_MEMORY_TYPE)0; Type < EfiMaxMemoryType; Type++) {
if (mMemoryTypeStatistics[Type].Special &&
- mMemoryTypeStatistics[Type].NumberOfPages > 0 &&
- Entry->Start >= mMemoryTypeStatistics[Type].BaseAddress &&
- Entry->End <= mMemoryTypeStatistics[Type].MaximumAddress) {
+ (mMemoryTypeStatistics[Type].NumberOfPages > 0) &&
+ (Entry->Start >= mMemoryTypeStatistics[Type].BaseAddress) &&
+ (Entry->End <= mMemoryTypeStatistics[Type].MaximumAddress))
+ {
MemoryMap->Type = Type;
}
}
}
+
MemoryMap->Attribute = Entry->Attribute;
if (MemoryMap->Type < EfiMaxMemoryType) {
if (mMemoryTypeStatistics[MemoryMap->Type].Runtime) {
@@ -1821,7 +1866,6 @@ CoreGetMemoryMap (
MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size);
}
-
ZeroMem (&MergeGcdMapEntry, sizeof (MergeGcdMapEntry));
GcdMapEntry = NULL;
for (Link = mGcdMemorySpaceMap.ForwardLink; ; Link = Link->ForwardLink) {
@@ -1834,15 +1878,17 @@ CoreGetMemoryMap (
if ((MergeGcdMapEntry.Capabilities == GcdMapEntry->Capabilities) &&
(MergeGcdMapEntry.Attributes == GcdMapEntry->Attributes) &&
(MergeGcdMapEntry.GcdMemoryType == GcdMapEntry->GcdMemoryType) &&
- (MergeGcdMapEntry.GcdIoType == GcdMapEntry->GcdIoType)) {
- MergeGcdMapEntry.EndAddress = GcdMapEntry->EndAddress;
+ (MergeGcdMapEntry.GcdIoType == GcdMapEntry->GcdIoType))
+ {
+ MergeGcdMapEntry.EndAddress = GcdMapEntry->EndAddress;
continue;
}
}
if ((MergeGcdMapEntry.GcdMemoryType == EfiGcdMemoryTypeReserved) ||
((MergeGcdMapEntry.GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) &&
- ((MergeGcdMapEntry.Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME))) {
+ ((MergeGcdMapEntry.Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME)))
+ {
//
// Page Align GCD range is required. When it is converted to EFI_MEMORY_DESCRIPTOR,
// it will be recorded as page PhysicalStart and NumberOfPages.
@@ -1857,7 +1903,7 @@ CoreGetMemoryMap (
MemoryMap->VirtualStart = 0;
MemoryMap->NumberOfPages = RShiftU64 ((MergeGcdMapEntry.EndAddress - MergeGcdMapEntry.BaseAddress + 1), EFI_PAGE_SHIFT);
MemoryMap->Attribute = (MergeGcdMapEntry.Attributes & ~EFI_MEMORY_PORT_IO) |
- (MergeGcdMapEntry.Capabilities & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
+ (MergeGcdMapEntry.Capabilities & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
if (MergeGcdMapEntry.GcdMemoryType == EfiGcdMemoryTypeReserved) {
MemoryMap->Type = EfiReservedMemoryType;
@@ -1891,8 +1937,8 @@ CoreGetMemoryMap (
MemoryMap->VirtualStart = 0;
MemoryMap->NumberOfPages = RShiftU64 ((MergeGcdMapEntry.EndAddress - MergeGcdMapEntry.BaseAddress + 1), EFI_PAGE_SHIFT);
MemoryMap->Attribute = MergeGcdMapEntry.Attributes | EFI_MEMORY_NV |
- (MergeGcdMapEntry.Capabilities & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
- MemoryMap->Type = EfiPersistentMemory;
+ (MergeGcdMapEntry.Capabilities & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
+ MemoryMap->Type = EfiPersistentMemory;
//
// Check to see if the new Memory Map Descriptor can be merged with an
@@ -1900,12 +1946,14 @@ CoreGetMemoryMap (
//
MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size);
}
+
if (Link == &mGcdMemorySpaceMap) {
//
// break loop when arrive at head.
//
break;
}
+
if (GcdMapEntry != NULL) {
//
// Copy new GCD map entry for the following GCD range merge
@@ -1931,11 +1979,12 @@ CoreGetMemoryMap (
// all supported OSs.
//
MemoryMapEnd = MemoryMap;
- MemoryMap = MemoryMapStart;
+ MemoryMap = MemoryMapStart;
while (MemoryMap < MemoryMapEnd) {
MemoryMap->Attribute &= ~(UINT64)EFI_MEMORY_ACCESS_MASK;
- MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, Size);
+ MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, Size);
}
+
MergeMemoryMap (MemoryMapStart, &BufferSize, Size);
MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMapStart + BufferSize);
@@ -1957,12 +2006,11 @@ Done:
DEBUG_CODE (
DumpGuardedMemoryBitmap ();
- );
+ );
return Status;
}
-
/**
Internal function. Used by the pool functions to allocate pages
to back pool allocation requests.
@@ -1977,19 +2025,24 @@ Done:
**/
VOID *
CoreAllocatePoolPages (
- IN EFI_MEMORY_TYPE PoolType,
- IN UINTN NumberOfPages,
- IN UINTN Alignment,
- IN BOOLEAN NeedGuard
+ IN EFI_MEMORY_TYPE PoolType,
+ IN UINTN NumberOfPages,
+ IN UINTN Alignment,
+ IN BOOLEAN NeedGuard
)
{
- UINT64 Start;
+ UINT64 Start;
//
// Find the pages to convert
//
- Start = FindFreePages (MAX_ALLOC_ADDRESS, NumberOfPages, PoolType, Alignment,
- NeedGuard);
+ Start = FindFreePages (
+ MAX_ALLOC_ADDRESS,
+ NumberOfPages,
+ PoolType,
+ Alignment,
+ NeedGuard
+ );
//
// Convert it to boot services data
@@ -2004,10 +2057,9 @@ CoreAllocatePoolPages (
}
}
- return (VOID *)(UINTN) Start;
+ return (VOID *)(UINTN)Start;
}
-
/**
Internal function. Frees pool pages allocated via AllocatePoolPages ()
@@ -2017,15 +2069,13 @@ CoreAllocatePoolPages (
**/
VOID
CoreFreePoolPages (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
)
{
CoreConvertPages (Memory, NumberOfPages, EfiConventionalMemory);
}
-
-
/**
Make sure the memory map is following all the construction rules,
it is the last time to check memory map error before exit boot services.
@@ -2039,19 +2089,18 @@ CoreFreePoolPages (
**/
EFI_STATUS
CoreTerminateMemoryMap (
- IN UINTN MapKey
+ IN UINTN MapKey
)
{
- EFI_STATUS Status;
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
+ EFI_STATUS Status;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
Status = EFI_SUCCESS;
CoreAcquireMemoryLock ();
if (MapKey == mMemoryMapKey) {
-
//
// Make sure the memory map is following all the construction rules
// This is the last chance we will be able to display any messages on
@@ -2059,18 +2108,19 @@ CoreTerminateMemoryMap (
//
for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) {
- Entry = CR(Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
+ Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
if (Entry->Type < EfiMaxMemoryType) {
if (mMemoryTypeStatistics[Entry->Type].Runtime) {
ASSERT (Entry->Type != EfiACPIReclaimMemory);
ASSERT (Entry->Type != EfiACPIMemoryNVS);
if ((Entry->Start & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) {
- DEBUG((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));
+ DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
+
if (((Entry->End + 1) & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) {
- DEBUG((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));
+ DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
@@ -2094,12 +2144,3 @@ Done:
return Status;
}
-
-
-
-
-
-
-
-
-