X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FMem%2FPage.c;h=1f9e659753af2ceec5ff7ecf0bfc6321154338a9;hp=b09f2f1304e1d562e2bbe490b2726aec2820db00;hb=a1b749d074ef44e758458cf16e460dd74e3df123;hpb=9c4ac31cca01b4a503c36616770ea3157bf3bb9e diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index b09f2f1304..1f9e659753 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -13,11 +13,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ #include "DxeMain.h" +#include "Imem.h" #define EFI_DEFAULT_PAGE_ALLOCATION_ALIGNMENT (EFI_PAGE_SIZE) // -// Entry for tracking the memory regions for each memory type to help cooalese like memory types +// Entry for tracking the memory regions for each memory type to coalesce similar memory types // typedef struct { EFI_PHYSICAL_ADDRESS BaseAddress; @@ -34,40 +35,42 @@ typedef struct { // UINTN mMemoryMapKey = 0; -// -// mMapStack - space to use as temp storage to build new map descriptors -// mMapDepth - depth of new descriptor stack -// - #define MAX_MAP_DEPTH 6 + +/// +/// mMapDepth - depth of new descriptor stack +/// UINTN mMapDepth = 0; +/// +/// mMapStack - space to use as temp storage to build new map descriptors +/// MEMORY_MAP mMapStack[MAX_MAP_DEPTH]; UINTN mFreeMapStack = 0; -// -// This list maintain the free memory map list -// +/// +/// This list maintain the free memory map list +/// LIST_ENTRY mFreeMemoryMapEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mFreeMemoryMapEntryList); BOOLEAN mMemoryTypeInformationInitialized = FALSE; EFI_MEMORY_TYPE_STAISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1] = { - { 0, EFI_MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiReservedMemoryType - { 0, EFI_MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiLoaderCode - { 0, EFI_MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiLoaderData - { 0, EFI_MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiBootServicesCode - { 0, EFI_MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiBootServicesData - { 0, EFI_MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, TRUE }, // EfiRuntimeServicesCode - { 0, EFI_MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, TRUE }, // EfiRuntimeServicesData - { 0, EFI_MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiConventionalMemory - { 0, EFI_MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiUnusableMemory - { 0, EFI_MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiACPIReclaimMemory - { 0, EFI_MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiACPIMemoryNVS - { 0, EFI_MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiMemoryMappedIO - { 0, EFI_MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiMemoryMappedIOPortSpace - { 0, EFI_MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, TRUE }, // EfiPalCode - { 0, EFI_MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE } // EfiMaxMemoryType + { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiReservedMemoryType + { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiLoaderCode + { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiLoaderData + { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiBootServicesCode + { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiBootServicesData + { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, TRUE }, // EfiRuntimeServicesCode + { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, TRUE }, // EfiRuntimeServicesData + { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiConventionalMemory + { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiUnusableMemory + { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiACPIReclaimMemory + { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiACPIMemoryNVS + { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiMemoryMappedIO + { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiMemoryMappedIOPortSpace + { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, TRUE }, // EfiPalCode + { 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE } // EfiMaxMemoryType }; -EFI_PHYSICAL_ADDRESS mDefaultMaximumAddress = EFI_MAX_ADDRESS; +EFI_PHYSICAL_ADDRESS mDefaultMaximumAddress = MAX_ADDRESS; EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = { { EfiReservedMemoryType, 0 }, @@ -87,17 +90,57 @@ EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = { { EfiMaxMemoryType, 0 } }; -// -// Internal prototypes -// + /** - Find untested but initialized memory regions in GCD map and convert them to be DXE allocatable. + Enter critical section by gaining lock on gMemoryLock. **/ VOID -PromoteMemoryResource ( +CoreAcquireMemoryLock ( VOID - ); + ) +{ + CoreAcquireLock (&gMemoryLock); +} + + + +/** + Exit critical section by releasing lock on gMemoryLock. + +**/ +VOID +CoreReleaseMemoryLock ( + VOID + ) +{ + CoreReleaseLock (&gMemoryLock); +} + + + + +/** + Internal function. Removes a descriptor entry. + + @param Entry The entry to remove + +**/ +VOID +RemoveMemoryMapEntry ( + IN OUT MEMORY_MAP *Entry + ) +{ + RemoveEntryList (&Entry->Link); + Entry->Link.ForwardLink = NULL; + + if (Entry->FromPages) { + // + // Insert the free memory map descriptor to the end of mFreeMemoryMapEntryList + // + InsertTailList (&mFreeMemoryMapEntryList, &Entry->Link); + } +} /** Internal function. Adds a ranges to the memory map. @@ -117,51 +160,85 @@ CoreAddRange ( IN EFI_PHYSICAL_ADDRESS Start, IN EFI_PHYSICAL_ADDRESS End, IN UINT64 Attribute - ); + ) +{ + LIST_ENTRY *Link; + MEMORY_MAP *Entry; -/** - Internal function. Moves any memory descriptors that are on the - temporary descriptor stack to heap. + ASSERT ((Start & EFI_PAGE_MASK) == 0); + ASSERT (End > Start) ; -**/ -VOID -CoreFreeMemoryMapStack ( - VOID - ); + ASSERT_LOCKED (&gMemoryLock); -/** - Internal function. Converts a memory range to the specified type. - The range must exist in the memory map. + DEBUG ((DEBUG_PAGE, "AddRange: %lx-%lx to %d\n", Start, End, Type)); - @param Start The first address of the range Must be page - aligned - @param NumberOfPages The number of pages to convert - @param NewType The new type for the memory range + // + // Memory map being altered so updated key + // + mMemoryMapKey += 1; - @retval EFI_INVALID_PARAMETER Invalid parameter - @retval EFI_NOT_FOUND Could not find a descriptor cover the specified - range or convertion not allowed. - @retval EFI_SUCCESS Successfully converts the memory range to the - specified type. + // + // UEFI 2.0 added an event group for notificaiton on memory map changes. + // So we need to signal this Event Group every time the memory map changes. + // If we are in EFI 1.10 compatability mode no event groups will be + // found and nothing will happen we we call this function. These events + // will get signaled but since a lock is held around the call to this + // function the notificaiton events will only be called after this funciton + // returns and the lock is released. + // + CoreNotifySignalList (&gEfiEventMemoryMapChangeGuid); -**/ -EFI_STATUS -CoreConvertPages ( - IN UINT64 Start, - IN UINT64 NumberOfPages, - IN EFI_MEMORY_TYPE NewType - ); + // + // Look for adjoining memory descriptor + // -/** - Internal function. Removes a descriptor entry. + // Two memory descriptors can only be merged if they have the same Type + // and the same Attribute + // - @param Entry The entry to remove + Link = gMemoryMap.ForwardLink; + while (Link != &gMemoryMap) { + Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE); + Link = Link->ForwardLink; -**/ -VOID -RemoveMemoryMapEntry ( - IN OUT MEMORY_MAP *Entry - ); + if (Entry->Type != Type) { + continue; + } + + if (Entry->Attribute != Attribute) { + continue; + } + + if (Entry->End + 1 == Start) { + + Start = Entry->Start; + RemoveMemoryMapEntry (Entry); + + } else if (Entry->Start == End + 1) { + + End = Entry->End; + RemoveMemoryMapEntry (Entry); + } + } + + // + // 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; + InsertTailList (&gMemoryMap, &mMapStack[mMapDepth].Link); + + mMapDepth += 1; + ASSERT (mMapDepth < MAX_MAP_DEPTH); + + return ; +} /** Internal function. Deque a descriptor entry from the mFreeMemoryMapEntryList. @@ -179,35 +256,114 @@ RemoveMemoryMapEntry ( MEMORY_MAP * AllocateMemoryMapEntry ( VOID - ); + ) +{ + MEMORY_MAP* FreeDescriptorEntries; + MEMORY_MAP* Entry; + UINTN Index; + + if (IsListEmpty (&mFreeMemoryMapEntryList)) { + // + // The list is empty, to allocate one page to refuel the list + // + FreeDescriptorEntries = CoreAllocatePoolPages (EfiBootServicesData, EFI_SIZE_TO_PAGES(DEFAULT_PAGE_ALLOCATION), DEFAULT_PAGE_ALLOCATION); + if(FreeDescriptorEntries != NULL) { + // + // Enque the free memmory map entries into the list + // + for (Index = 0; Index< DEFAULT_PAGE_ALLOCATION / sizeof(MEMORY_MAP); Index++) { + FreeDescriptorEntries[Index].Signature = MEMORY_MAP_SIGNATURE; + InsertTailList (&mFreeMemoryMapEntryList, &FreeDescriptorEntries[Index].Link); + } + } else { + return NULL; + } + } + // + // dequeue the first descriptor from the list + // + Entry = CR (mFreeMemoryMapEntryList.ForwardLink, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE); + RemoveEntryList (&Entry->Link); + + return Entry; +} /** - Enter critical section by gaining lock on gMemoryLock. + Internal function. Moves any memory descriptors that are on the + temporary descriptor stack to heap. **/ VOID -CoreAcquireMemoryLock ( +CoreFreeMemoryMapStack ( VOID ) { - CoreAcquireLock (&gMemoryLock); -} + MEMORY_MAP *Entry; + MEMORY_MAP *Entry2; + LIST_ENTRY *Link2; + ASSERT_LOCKED (&gMemoryLock); + // + // If already freeing the map stack, then return + // + if (mFreeMapStack != 0) { + return ; + } -/** - Exit critical section by releasing lock on gMemoryLock. + // + // Move the temporary memory descriptor stack into pool + // + mFreeMapStack += 1; -**/ -VOID -CoreReleaseMemoryLock ( - VOID - ) -{ - CoreReleaseLock (&gMemoryLock); -} + while (mMapDepth != 0) { + // + // Deque an memory map entry from mFreeMemoryMapEntryList + // + Entry = AllocateMemoryMapEntry (); + + ASSERT (Entry); + + // + // Update to proper entry + // + 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)); + Entry->FromPages = TRUE; + + // + // Find insertion location + // + 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) { + break; + } + } + + InsertTailList (Link2, &Entry->Link); + + } else { + // + // This item of mMapStack[mMapDepth] has already been dequeued from gMemoryMap list, + // so here no need to move it to memory. + // + InsertTailList (&mFreeMemoryMapEntryList, &Entry->Link); + } + } + mFreeMapStack -= 1; +} /** Find untested but initialized memory regions in GCD map and convert them to be DXE allocatable. @@ -221,7 +377,7 @@ PromoteMemoryResource ( LIST_ENTRY *Link; EFI_GCD_MAP_ENTRY *Entry; - DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "Promote the memory resource\n")); + DEBUG ((DEBUG_PAGE, "Promote the memory resource\n")); CoreAcquireGcdMemoryLock (); @@ -231,7 +387,7 @@ PromoteMemoryResource ( Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE); if (Entry->GcdMemoryType == EfiGcdMemoryTypeReserved && - Entry->EndAddress < EFI_MAX_ADDRESS && + Entry->EndAddress < MAX_ADDRESS && (Entry->Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) == (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)) { // @@ -357,7 +513,7 @@ CoreAddMemoryDescriptor ( gMemoryTypeInformation[FreeIndex].NumberOfPages ); mMemoryTypeStatistics[Type].BaseAddress = 0; - mMemoryTypeStatistics[Type].MaximumAddress = EFI_MAX_ADDRESS; + mMemoryTypeStatistics[Type].MaximumAddress = MAX_ADDRESS; } } return; @@ -415,7 +571,7 @@ CoreAddMemoryDescriptor ( } } mMemoryTypeStatistics[Type].CurrentNumberOfPages = 0; - if (mMemoryTypeStatistics[Type].MaximumAddress == EFI_MAX_ADDRESS) { + if (mMemoryTypeStatistics[Type].MaximumAddress == MAX_ADDRESS) { mMemoryTypeStatistics[Type].MaximumAddress = mDefaultMaximumAddress; } } @@ -424,255 +580,6 @@ CoreAddMemoryDescriptor ( } - -/** - Internal function. Adds a ranges to the memory map. - The range must not already exist in the map. - - @param Type The type of memory range to add - @param Start The starting address in the memory range Must be - paged aligned - @param End The last address in the range Must be the last - byte of a page - @param Attribute The attributes of the memory range to add - -**/ -VOID -CoreAddRange ( - IN EFI_MEMORY_TYPE Type, - IN EFI_PHYSICAL_ADDRESS Start, - IN EFI_PHYSICAL_ADDRESS End, - IN UINT64 Attribute - ) -{ - LIST_ENTRY *Link; - MEMORY_MAP *Entry; - - ASSERT ((Start & EFI_PAGE_MASK) == 0); - ASSERT (End > Start) ; - - ASSERT_LOCKED (&gMemoryLock); - - DEBUG ((DEBUG_PAGE, "AddRange: %lx-%lx to %d\n", Start, End, Type)); - - // - // Memory map being altered so updated key - // - mMemoryMapKey += 1; - - // - // UEFI 2.0 added an event group for notificaiton on memory map changes. - // So we need to signal this Event Group every time the memory map changes. - // If we are in EFI 1.10 compatability mode no event groups will be - // found and nothing will happen we we call this function. These events - // will get signaled but since a lock is held around the call to this - // function the notificaiton events will only be called after this funciton - // returns and the lock is released. - // - CoreNotifySignalList (&gEfiEventMemoryMapChangeGuid); - - // - // Look for adjoining memory descriptor - // - - // Two memory descriptors can only be merged if they have the same Type - // and the same Attribute - // - - Link = gMemoryMap.ForwardLink; - while (Link != &gMemoryMap) { - Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE); - Link = Link->ForwardLink; - - if (Entry->Type != Type) { - continue; - } - - if (Entry->Attribute != Attribute) { - continue; - } - - if (Entry->End + 1 == Start) { - - Start = Entry->Start; - RemoveMemoryMapEntry (Entry); - - } else if (Entry->Start == End + 1) { - - End = Entry->End; - RemoveMemoryMapEntry (Entry); - } - } - - // - // 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; - InsertTailList (&gMemoryMap, &mMapStack[mMapDepth].Link); - - mMapDepth += 1; - ASSERT (mMapDepth < MAX_MAP_DEPTH); - - return ; -} - - -/** - Internal function. Moves any memory descriptors that are on the - temporary descriptor stack to heap. - -**/ -VOID -CoreFreeMemoryMapStack ( - VOID - ) -{ - MEMORY_MAP *Entry; - MEMORY_MAP *Entry2; - LIST_ENTRY *Link2; - - ASSERT_LOCKED (&gMemoryLock); - - // - // If already freeing the map stack, then return - // - if (mFreeMapStack != 0) { - return ; - } - - // - // Move the temporary memory descriptor stack into pool - // - mFreeMapStack += 1; - - while (mMapDepth != 0) { - // - // Deque an memory map entry from mFreeMemoryMapEntryList - // - Entry = AllocateMemoryMapEntry (); - - ASSERT (Entry); - - // - // Update to proper entry - // - 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)); - Entry->FromPages = TRUE; - - // - // Find insertion location - // - 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) { - break; - } - } - - InsertTailList (Link2, &Entry->Link); - - } else { - // - // This item of mMapStack[mMapDepth] has already been dequeued from gMemoryMap list, - // so here no need to move it to memory. - // - InsertTailList (&mFreeMemoryMapEntryList, &Entry->Link); - } - } - - mFreeMapStack -= 1; -} - - -/** - Internal function. Removes a descriptor entry. - - @param Entry The entry to remove - -**/ -VOID -RemoveMemoryMapEntry ( - IN OUT MEMORY_MAP *Entry - ) -{ - RemoveEntryList (&Entry->Link); - Entry->Link.ForwardLink = NULL; - - if (Entry->FromPages) { - // - // Insert the free memory map descriptor to the end of mFreeMemoryMapEntryList - // - InsertTailList (&mFreeMemoryMapEntryList, &Entry->Link); - } -} - - -/** - Internal function. Deque a descriptor entry from the mFreeMemoryMapEntryList. - If the list is emtry, then allocate a new page to refuel the list. - Please Note this algorithm to allocate the memory map descriptor has a property - that the memory allocated for memory entries always grows, and will never really be freed - For example, if the current boot uses 2000 memory map entries at the maximum point, but - ends up with only 50 at the time the OS is booted, then the memory associated with the 1950 - memory map entries is still allocated from EfiBootServicesMemory. - - - @return The Memory map descriptor dequed from the mFreeMemoryMapEntryList - -**/ -MEMORY_MAP * -AllocateMemoryMapEntry ( - VOID - ) -{ - MEMORY_MAP* FreeDescriptorEntries; - MEMORY_MAP* Entry; - UINTN Index; - - if (IsListEmpty (&mFreeMemoryMapEntryList)) { - // - // The list is empty, to allocate one page to refuel the list - // - FreeDescriptorEntries = CoreAllocatePoolPages (EfiBootServicesData, EFI_SIZE_TO_PAGES(DEFAULT_PAGE_ALLOCATION), DEFAULT_PAGE_ALLOCATION); - if(FreeDescriptorEntries != NULL) { - // - // Enque the free memmory map entries into the list - // - for (Index = 0; Index< DEFAULT_PAGE_ALLOCATION / sizeof(MEMORY_MAP); Index++) { - FreeDescriptorEntries[Index].Signature = MEMORY_MAP_SIGNATURE; - InsertTailList (&mFreeMemoryMapEntryList, &FreeDescriptorEntries[Index].Link); - } - } else { - return NULL; - } - } - // - // dequeue the first descriptor from the list - // - Entry = CR (mFreeMemoryMapEntryList.ForwardLink, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE); - RemoveEntryList (&Entry->Link); - - return Entry; -} - - /** Internal function. Converts a memory range to the specified type. The range must exist in the memory map. @@ -754,7 +661,7 @@ CoreConvertPages ( // Debug code - verify conversion is allowed // if (!(NewType == EfiConventionalMemory ? 1 : 0) ^ (Entry->Type == EfiConventionalMemory ? 1 : 0)) { - DEBUG ((DEBUG_ERROR , "ConvertPages: Incompatible memory types\n")); + DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "ConvertPages: Incompatible memory types\n")); return EFI_NOT_FOUND; } @@ -1112,7 +1019,7 @@ CoreAllocatePages ( // // The max address is the max natively addressable address for the processor // - MaxAddress = EFI_MAX_ADDRESS; + MaxAddress = MAX_ADDRESS; if (Type == AllocateMaxAddress) { MaxAddress = Start; @@ -1220,7 +1127,7 @@ CoreFreePages ( // // Destroy the contents // - if (Memory < EFI_MAX_ADDRESS) { + if (Memory < MAX_ADDRESS) { DEBUG_CLEAR_MEMORY ((VOID *)(UINTN)Memory, NumberOfPages << EFI_PAGE_SHIFT); } @@ -1374,7 +1281,7 @@ CoreGetMemoryMap ( MemoryMap->Attribute |= EFI_MEMORY_RUNTIME; } - MemoryMap = NextMemoryDescriptor (MemoryMap, Size); + MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, Size); } for (Link = mGcdMemorySpaceMap.ForwardLink; Link != &mGcdMemorySpaceMap; Link = Link->ForwardLink) { @@ -1382,7 +1289,10 @@ CoreGetMemoryMap ( if ((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) || (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo)) { if ((GcdMapEntry->Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) { - + // + // Create EFI_MEMORY_DESCRIPTOR for every Reserved and MMIO GCD entries + // that are marked for runtime use + // MemoryMap->PhysicalStart = GcdMapEntry->BaseAddress; MemoryMap->VirtualStart = 0; MemoryMap->NumberOfPages = RShiftU64 ((GcdMapEntry->EndAddress - GcdMapEntry->BaseAddress + 1), EFI_PAGE_SHIFT); @@ -1398,7 +1308,7 @@ CoreGetMemoryMap ( } } - MemoryMap = NextMemoryDescriptor (MemoryMap, Size); + MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, Size); } } } @@ -1447,13 +1357,13 @@ CoreAllocatePoolPages ( // // Find the pages to convert // - Start = FindFreePages (EFI_MAX_ADDRESS, NumberOfPages, PoolType, Alignment); + Start = FindFreePages (MAX_ADDRESS, NumberOfPages, PoolType, Alignment); // // Convert it to boot services data // if (Start == 0) { - DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "AllocatePoolPages: failed to allocate %d pages\n", NumberOfPages)); + DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "AllocatePoolPages: failed to allocate %d pages\n", (UINT32)NumberOfPages)); } else { CoreConvertPages (Start, NumberOfPages, PoolType); } @@ -1514,21 +1424,21 @@ CoreTerminateMemoryMap ( for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) { Entry = CR(Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE); - if (Entry->Attribute & EFI_MEMORY_RUNTIME) { + if ((Entry->Attribute & EFI_MEMORY_RUNTIME) != 0) { if (Entry->Type == EfiACPIReclaimMemory || Entry->Type == EfiACPIMemoryNVS) { - DEBUG((DEBUG_ERROR, "ExitBootServices: ACPI memory entry has RUNTIME attribute set.\n")); - CoreReleaseMemoryLock (); - return EFI_INVALID_PARAMETER; + DEBUG((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: ACPI memory entry has RUNTIME attribute set.\n")); + Status = EFI_INVALID_PARAMETER; + goto Done; } - if (Entry->Start & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) { - DEBUG((DEBUG_ERROR, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n")); - CoreReleaseMemoryLock (); - return EFI_INVALID_PARAMETER; + if ((Entry->Start & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) { + 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) & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) { - DEBUG((DEBUG_ERROR, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n")); - CoreReleaseMemoryLock (); - return EFI_INVALID_PARAMETER; + if (((Entry->End + 1) & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) { + DEBUG((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n")); + Status = EFI_INVALID_PARAMETER; + goto Done; } } } @@ -1544,6 +1454,7 @@ CoreTerminateMemoryMap ( Status = EFI_INVALID_PARAMETER; } +Done: CoreReleaseMemoryLock (); return Status;