- if (mMemoryTypeStatistics[Type].MaximumAddress == EFI_MAX_ADDRESS) {\r
- mMemoryTypeStatistics[Type].MaximumAddress = mDefaultMaximumAddress;\r
- }\r
- }\r
-\r
- mMemoryTypeInformationInitialized = TRUE;\r
-}\r
-\r
-\r
-STATIC\r
-VOID\r
-CoreAddRange (\r
- IN EFI_MEMORY_TYPE Type,\r
- IN EFI_PHYSICAL_ADDRESS Start,\r
- IN EFI_PHYSICAL_ADDRESS End,\r
- IN UINT64 Attribute\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Internal function. Adds a ranges to the memory map.\r
- The range must not already exist in the map.\r
-\r
-Arguments:\r
-\r
- Type - The type of memory range to add\r
-\r
- Start - The starting address in the memory range\r
- Must be paged aligned\r
-\r
- End - The last address in the range\r
- Must be the last byte of a page\r
-\r
- Attribute - The attributes of the memory range to add\r
-\r
-Returns:\r
-\r
- None. The range is added to the memory map\r
-\r
---*/\r
-{\r
- LIST_ENTRY *Link;\r
- MEMORY_MAP *Entry;\r
-\r
- ASSERT ((Start & EFI_PAGE_MASK) == 0);\r
- ASSERT (End > Start) ;\r
-\r
- ASSERT_LOCKED (&gMemoryLock);\r
- \r
- DEBUG ((EFI_D_PAGE, "AddRange: %lx-%lx to %d\n", Start, End, Type));\r
-\r
- //\r
- // Memory map being altered so updated key\r
- //\r
- mMemoryMapKey += 1;\r
-\r
- //\r
- // UEFI 2.0 added an event group for notificaiton on memory map changes.\r
- // So we need to signal this Event Group every time the memory map changes.\r
- // If we are in EFI 1.10 compatability mode no event groups will be \r
- // found and nothing will happen we we call this function. These events\r
- // will get signaled but since a lock is held around the call to this \r
- // function the notificaiton events will only be called after this funciton\r
- // returns and the lock is released.\r
- //\r
- CoreNotifySignalList (&gEfiEventMemoryMapChangeGuid);\r
-\r
- //\r
- // Look for adjoining memory descriptor\r
- //\r
- \r
- // Two memory descriptors can only be merged if they have the same Type\r
- // and the same Attribute\r
- //\r
-\r
- Link = gMemoryMap.ForwardLink;\r
- while (Link != &gMemoryMap) {\r
- Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);\r
- Link = Link->ForwardLink;\r
-\r
- if (Entry->Type != Type) {\r
- continue;\r
- }\r
-\r
- if (Entry->Attribute != Attribute) {\r
- continue;\r
- }\r
-\r
- if (Entry->End + 1 == Start) {\r
- \r
- Start = Entry->Start;\r
- RemoveMemoryMapEntry (Entry);\r
-\r
- } else if (Entry->Start == End + 1) {\r
- \r
- End = Entry->End;\r
- RemoveMemoryMapEntry (Entry);\r
- }\r
- }\r
-\r
- //\r
- // Add descriptor \r
- //\r
-\r
- mMapStack[mMapDepth].Signature = MEMORY_MAP_SIGNATURE;\r
- mMapStack[mMapDepth].FromPages = FALSE;\r
- mMapStack[mMapDepth].Type = Type;\r
- mMapStack[mMapDepth].Start = Start;\r
- mMapStack[mMapDepth].End = End;\r
- mMapStack[mMapDepth].VirtualStart = 0;\r
- mMapStack[mMapDepth].Attribute = Attribute;\r
- InsertTailList (&gMemoryMap, &mMapStack[mMapDepth].Link);\r
-\r
- mMapDepth += 1;\r
- ASSERT (mMapDepth < MAX_MAP_DEPTH);\r
-\r
- return ;\r
-}\r
-\r
-STATIC\r
-VOID\r
-CoreFreeMemoryMapStack (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Internal function. Moves any memory descriptors that are on the\r
- temporary descriptor stack to heap.\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
-{\r
- MEMORY_MAP *Entry;\r
- MEMORY_MAP *Entry2;\r
- LIST_ENTRY *Link2;\r
-\r
- ASSERT_LOCKED (&gMemoryLock);\r
-\r
- //\r
- // If already freeing the map stack, then return\r
- //\r
- if (mFreeMapStack) {\r
- return ;\r
- }\r
-\r
- //\r
- // Move the temporary memory descriptor stack into pool\r
- //\r
- mFreeMapStack += 1;\r
-\r
- while (mMapDepth) {\r
- //\r
- // Deque an memory map entry from mFreeMemoryMapEntryList \r
- //\r
- Entry = AllocateMemoryMapEntry ();\r
- \r
- ASSERT (Entry);\r
-\r
- //\r
- // Update to proper entry\r
- //\r
- mMapDepth -= 1;\r
-\r
- if (mMapStack[mMapDepth].Link.ForwardLink != NULL) {\r
-\r
- //\r
- // Move this entry to general memory\r
- //\r
- RemoveEntryList (&mMapStack[mMapDepth].Link);\r
- mMapStack[mMapDepth].Link.ForwardLink = NULL;\r
-\r
- CopyMem (Entry , &mMapStack[mMapDepth], sizeof (MEMORY_MAP));\r
- Entry->FromPages = TRUE;\r
-\r
- //\r
- // Find insertion location\r
- //\r
- for (Link2 = gMemoryMap.ForwardLink; Link2 != &gMemoryMap; Link2 = Link2->ForwardLink) {\r
- Entry2 = CR (Link2, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);\r
- if (Entry2->FromPages && Entry2->Start > Entry->Start) {\r
- break;\r
- }\r
- }\r
-\r
- InsertTailList (Link2, &Entry->Link);\r
-\r
- } else {\r
- // \r
- // This item of mMapStack[mMapDepth] has already been dequeued from gMemoryMap list,\r
- // so here no need to move it to memory.\r
- //\r
- InsertTailList (&mFreeMemoryMapEntryList, &Entry->Link);\r