[settings] Use memmap_describe() to construct memory map settings

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-05-16 15:47:51 +01:00
parent c8d64ecd87
commit 79c30b92a3

View File

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