# HG changeset patch # User Alex Williamson # Date 1192041966 21600 # Node ID 2eefc9fdd17c00d52e03e6319a5b990a2e51e580 # Parent 5b9238742219d655e32b26c137d011fd7869ad42 Sort the memmory map provided to the guest A sorted memory map seems to be the defacto standard. This is just a trivial bubble sort, but this doesn't seem to be called often enough or take any noticable time for something more complicated. Signed-off-by: Alex Williamson diff -r 5b9238742219 -r 2eefc9fdd17c edk2-patches/patches_list --- a/edk2-patches/patches_list Wed Oct 10 12:43:12 2007 -0600 +++ b/edk2-patches/patches_list Wed Oct 10 12:46:06 2007 -0600 @@ -1,2 +1,3 @@ NVRAM_for_open_GFW.patch NVRAM_for_open_GFW.patch load_fpswa.patch +sort_memmap.patch diff -r 5b9238742219 -r 2eefc9fdd17c edk2-patches/sort_memmap.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/edk2-patches/sort_memmap.patch Wed Oct 10 12:46:06 2007 -0600 @@ -0,0 +1,51 @@ +Sort the memmory map provided to the guest + +A sorted memory map seems to be the defacto standard. This is just +a trivial bubble sort, but this doesn't seem to be called often enough +or take any noticable time for something more complicated. + +Signed-off-by: Alex Williamson +--- + +diff -r df27743a1e0a edk2-sparse/EdkModulePkg/Core/Dxe/Mem/Page.c +--- a/EdkModulePkg/Core/Dxe/Mem/Page.c Wed Oct 10 11:59:15 2007 -0600 ++++ b/EdkModulePkg/Core/Dxe/Mem/Page.c Wed Oct 10 11:59:28 2007 -0600 +@@ -1363,6 +1363,10 @@ Returns: + LIST_ENTRY *Link; + MEMORY_MAP *Entry; + EFI_GCD_MAP_ENTRY *GcdMapEntry; ++ EFI_MEMORY_DESCRIPTOR *MemoryMapBase = MemoryMap; ++ EFI_MEMORY_DESCRIPTOR *MemoryMapA, *MemoryMapB; ++ EFI_MEMORY_DESCRIPTOR MemoryMapSpare; ++ BOOLEAN Sorted; + + // + // Make sure the parameters are valid +@@ -1477,7 +1481,26 @@ Returns: + } + } + } +- ++ ++ // ++ // Simple bubble sort ++ // ++ do { ++ Sorted = TRUE; ++ MemoryMapA = MemoryMapBase; ++ MemoryMapB = NextMemoryDescriptor(MemoryMapA, Size); ++ while (MemoryMapB < MemoryMap) { ++ if (MemoryMapA->PhysicalStart > MemoryMapB->PhysicalStart) { ++ CopyMem(&MemoryMapSpare, MemoryMapA, sizeof (EFI_MEMORY_DESCRIPTOR)); ++ CopyMem(MemoryMapA, MemoryMapB, sizeof (EFI_MEMORY_DESCRIPTOR)); ++ CopyMem(MemoryMapB, &MemoryMapSpare, sizeof (EFI_MEMORY_DESCRIPTOR)); ++ Sorted = FALSE; ++ } ++ MemoryMapA = MemoryMapB; ++ MemoryMapB = NextMemoryDescriptor(MemoryMapB, Size); ++ } ++ } while (Sorted == FALSE); ++ + Status = EFI_SUCCESS; + + Done: