:: commit 0c46de53d8cc0fcb98d7bf487ce5ecb6471b9589

mintsuki <mintsuki@protonmail.com> — 2021-07-07 03:37

parents: 10e802981d

Revert "pmm: Use our custom EFI memory entry type to release EFI memory back instead of relying on our memmap"

This reverts commit eadee3e6cba0885c77c1db01b0f576d727779e75.
diff --git a/stage23/mm/pmm.s2.c b/stage23/mm/pmm.s2.c
index 5bebb548..f95f0352 100644
--- a/stage23/mm/pmm.s2.c
+++ b/stage23/mm/pmm.s2.c
@@ -453,50 +453,20 @@ void pmm_reclaim_uefi_mem(void) {
 void pmm_release_uefi_mem(void) {
     EFI_STATUS status;
 
-    EFI_MEMORY_DESCRIPTOR tmp_mmap[1];
-    efi_mmap_size = sizeof(tmp_mmap);
-    UINTN mmap_key = 0;
-
-    uefi_call_wrapper(gBS->GetMemoryMap, 5,
-        &efi_mmap_size, tmp_mmap, &mmap_key, &efi_desc_size, &efi_desc_ver);
-
-    efi_mmap_size += 4096;
-
-    status = uefi_call_wrapper(gBS->FreePool, 1, efi_mmap);
-    if (status)
-        goto fail;
-
-    status = uefi_call_wrapper(gBS->AllocatePool, 3,
-        EfiLoaderData, efi_mmap_size, &efi_mmap);
-    if (status)
-        goto fail;
-
-    status = uefi_call_wrapper(gBS->GetMemoryMap, 5,
-        &efi_mmap_size, efi_mmap, &mmap_key, &efi_desc_size, &efi_desc_ver);
-    if (status)
-        goto fail;
-
-    // Go through new EFI memmap and free up bootloader held entries
-    size_t entry_count = efi_mmap_size / efi_desc_size;
-
-    for (size_t i = 0; i < entry_count; i++) {
-        EFI_MEMORY_DESCRIPTOR *entry = (void *)efi_mmap + i * efi_desc_size;
+    for (size_t i = 0; i < memmap_entries; i++) {
+        if (memmap[i].type != MEMMAP_USABLE
+         && memmap[i].type != MEMMAP_BOOTLOADER_RECLAIMABLE) {
+            continue;
+        }
 
-        if (entry->Type == 0x80000000) {
-            status = uefi_call_wrapper(gBS->FreePages, 2,
-                                       entry->PhysicalStart, entry->NumberOfPages);
+        status = uefi_call_wrapper(gBS->FreePages, 2,
+                                   memmap[i].base, memmap[i].length / 4096);
 
-            if (status)
-                panic("pmm: FreePages failure (%x)", status);
-        }
+        if (status)
+            panic("pmm: FreePages failure (%x)", status);
     }
 
     allocations_disallowed = true;
-
-    return;
-
-fail:
-    panic("pmm: Failed to release UEFI memory");
 }
 #endif
 
diff --git a/stage23/protos/chainload.c b/stage23/protos/chainload.c
index f03f2027..58bba9b3 100644
--- a/stage23/protos/chainload.c
+++ b/stage23/protos/chainload.c
@@ -9,7 +9,6 @@
 #include <lib/fb.h>
 #include <lib/uri.h>
 #include <lib/print.h>
-#include <lib/libc.h>
 #include <sys/idt.h>
 #include <drivers/vga_textmode.h>
 #include <mm/pmm.h>
@@ -120,14 +119,8 @@ void chainload(char *config) {
     if (!uri_open(image, image_path))
         panic("chainload: Failed to open image with path `%s`. Is the path correct?", image_path);
 
-    void *_ptr = freadall(image, MEMMAP_RESERVED);
+    void *ptr = freadall(image, MEMMAP_RESERVED);
     size_t image_size = image->size;
-    void *ptr;
-    status = uefi_call_wrapper(gBS->AllocatePool, 3,
-        EfiLoaderData, image_size, &ptr);
-    if (status)
-        panic("chainload: Allocation failure");
-    memcpy(ptr, _ptr, image_size);
 
     term_deinit();
 
tab: 248 wrap: offon