]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[bios] Use memmap_describe() to find an external heap location
authorMichael Brown <mcb30@ipxe.org>
Fri, 16 May 2025 17:04:27 +0000 (18:04 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 16 May 2025 17:04:27 +0000 (18:04 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/interface/pcbios/memtop_umalloc.c

index 99d8f146078b4f0484691a6dc07264db4ad0bd90..3348263a54d79819346772b13d6aa18c621e599c 100644 (file)
@@ -34,7 +34,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <string.h>
 #include <errno.h>
 #include <ipxe/uaccess.h>
-#include <ipxe/io.h>
 #include <ipxe/memblock.h>
 #include <ipxe/memmap.h>
 #include <ipxe/umalloc.h>
@@ -85,35 +84,34 @@ static void hide_umalloc ( physaddr_t start, physaddr_t end ) {
  * @ret len            Length of region
  */
 size_t largest_memblock ( void **start ) {
-       struct memory_map memmap;
-       struct memory_region *region;
+       struct memmap_region region;
        physaddr_t max = EM_MAX_ADDRESS;
        physaddr_t region_start;
        physaddr_t region_end;
        size_t region_len;
-       unsigned int i;
        size_t len = 0;
 
        /* Avoid returning uninitialised data on error */
        *start = NULL;
 
        /* Scan through all memory regions */
-       get_memmap ( &memmap );
-       for ( i = 0 ; i < memmap.count ; i++ ) {
-               region = &memmap.regions[i];
-               DBG ( "Considering [%llx,%llx)\n", region->start, region->end );
+       for_each_memmap ( &region, 1 ) {
 
                /* Truncate block to maximum physical address */
-               if ( region->start > max ) {
-                       DBG ( "...starts after maximum address %lx\n", max );
-                       continue;
+               memmap_dump ( &region );
+               if ( region.addr > max ) {
+                       DBGC ( &region, "...starts after maximum address "
+                              "%lx\n", max );
+                       break;
                }
-               region_start = region->start;
-               if ( region->end > max ) {
-                       DBG ( "...end truncated to maximum address %lx\n", max);
+               region_start = region.addr;
+               if ( ! memmap_is_usable ( &region ) )
+                       continue;
+               region_end = ( region_start + memmap_size ( &region ) );
+               if ( region_end > max ) {
+                       DBGC ( &region, "...end truncated to maximum address "
+                              "%lx\n", max);
                        region_end = 0; /* =max, given the wraparound */
-               } else {
-                       region_end = region->end;
                }
                region_len = ( region_end - region_start );