]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[settings] Use memmap_describe() to construct memory map settings
authorMichael Brown <mcb30@ipxe.org>
Fri, 16 May 2025 14:47:51 +0000 (15:47 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 16 May 2025 16:39:36 +0000 (17:39 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/memmap_settings.c

index c620a0343e7c1a0b5454dcd24a64d0c6fa5de91b..430065dc99ea879796164f89393cda4275f12b2d 100644 (file)
@@ -28,7 +28,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <byteswap.h>
 #include <ipxe/init.h>
 #include <ipxe/settings.h>
-#include <ipxe/io.h>
+#include <ipxe/memmap.h>
 
 /** @file
  *
@@ -139,16 +139,15 @@ static int memmap_settings_applies ( struct settings *settings __unused,
 static int memmap_settings_fetch ( struct settings *settings,
                                   struct setting *setting,
                                   void *data, size_t len ) {
-       struct memory_map memmap;
-       struct memory_region *region;
+       struct memmap_region region;
        uint64_t result = 0;
+       unsigned int index = 0;
        unsigned int start;
        unsigned int count;
        unsigned int scale;
        int include_start;
        int include_length;
        int ignore_nonexistent;
-       unsigned int i;
 
        /* Parse settings tag */
        start = MEMMAP_START ( setting->tag );
@@ -163,35 +162,40 @@ static int memmap_settings_fetch ( struct settings *settings,
               ( include_length ? "length" : "" ),
               ( ignore_nonexistent ? " ignore" : "" ), scale );
 
-       /* Fetch memory map */
-       get_memmap ( &memmap );
-
        /* Extract results from memory map */
-       for ( i = start ; count-- ; i++ ) {
-
-               /* Check that region exists */
-               if ( i >= memmap.count ) {
-                       if ( ignore_nonexistent ) {
-                               continue;
-                       } else {
-                               DBGC ( settings, "MEMMAP region %d does not "
-                                      "exist\n", i );
-                               return -ENOENT;
-                       }
-               }
+       for_each_memmap ( &region, 0 ) {
+
+               /* Skip non-memory regions */
+               if ( ! ( region.flags & MEMMAP_FL_MEMORY ) )
+                       continue;
+
+               /* Ignore unwanted regions */
+               if ( index++ < start )
+                       continue;
 
                /* Extract results from this region */
-               region = &memmap.regions[i];
                if ( include_start ) {
-                       result += region->start;
-                       DBGC ( settings, "MEMMAP %d start %08llx\n",
-                              i, region->start );
+                       result += region.addr;
+                       DBGC ( settings, "MEMMAP %d start %#08llx\n", index,
+                              ( ( unsigned long long ) region.addr ) );
                }
                if ( include_length ) {
-                       result += ( region->end - region->start );
-                       DBGC ( settings, "MEMMAP %d length %08llx\n",
-                              i, ( region->end - region->start ) );
+                       result += memmap_size ( &region );
+                       DBGC ( settings, "MEMMAP %d length %#08llx\n", index,
+                              ( ( unsigned long long )
+                                memmap_size ( &region ) ) );
                }
+
+               /* Stop when we have accumulated sufficient regions */
+               if ( --count == 0 )
+                       break;
+       }
+
+       /* Check for nonexistent regions */
+       if ( count && ( ! ignore_nonexistent ) ) {
+               DBGC ( settings, "MEMMAP regions %d-%d do not exist\n",
+                      index, ( index + count - 1 ) );
+               return -ENOENT;
        }
 
        /* Scale result */