[memmap] Rename addr/last fields to min/max for clarity

Use the terminology "min" and "max" for addresses covered by a memory
region descriptor, since this is sufficiently intuitive to generally
not require further explanation.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-05-23 16:55:42 +01:00
parent cd38ed4fab
commit 036e43334a
12 changed files with 69 additions and 73 deletions

View File

@@ -81,11 +81,11 @@ __asmcall void relocate ( struct i386_all_regs *ix86 ) {
* stage. * stage.
*/ */
memmap_dump ( &region ); memmap_dump ( &region );
if ( region.addr > max ) { if ( region.min > max ) {
DBGC ( &region, "...starts after max=%#08lx\n", max ); DBGC ( &region, "...starts after max=%#08lx\n", max );
break; break;
} }
r_start = region.addr; r_start = region.min;
if ( ! memmap_is_usable ( &region ) ) { if ( ! memmap_is_usable ( &region ) ) {
DBGC ( &region, "...not usable\n" ); DBGC ( &region, "...not usable\n" );
continue; continue;

View File

@@ -347,11 +347,11 @@ static int bzimage_check_initrds ( struct image *image,
/* Limit region to avoiding kernel itself */ /* Limit region to avoiding kernel itself */
min = virt_to_phys ( bzimg->pm_kernel + bzimg->pm_sz ); min = virt_to_phys ( bzimg->pm_kernel + bzimg->pm_sz );
if ( min < region.addr ) if ( min < region.min )
min = region.addr; min = region.min;
/* Limit region to kernel's memory limit */ /* Limit region to kernel's memory limit */
max = region.last; max = region.max;
if ( max > bzimg->mem_limit ) if ( max > bzimg->mem_limit )
max = bzimg->mem_limit; max = bzimg->mem_limit;

View File

@@ -132,7 +132,7 @@ static void multiboot_build_memmap ( struct image *image,
/* Populate Multiboot memory map entry */ /* Populate Multiboot memory map entry */
mbmemmap->size = ( sizeof ( *mbmemmap ) - mbmemmap->size = ( sizeof ( *mbmemmap ) -
sizeof ( mbmemmap->size ) ); sizeof ( mbmemmap->size ) );
mbmemmap->base_addr = region.addr; mbmemmap->base_addr = region.min;
mbmemmap->length = memmap_size ( &region ); mbmemmap->length = memmap_size ( &region );
mbmemmap->type = MBMEM_RAM; mbmemmap->type = MBMEM_RAM;

View File

@@ -305,11 +305,11 @@ static int meme820 ( struct memmap_region *region ) {
/** /**
* Describe memory region from system memory map * Describe memory region from system memory map
* *
* @v addr Address within region * @v min Minimum address
* @v hide Hide in-use regions from the memory map * @v hide Hide in-use regions from the memory map
* @v region Region descriptor to fill in * @v region Region descriptor to fill in
*/ */
static void int15_describe ( uint64_t addr, int hide, static void int15_describe ( uint64_t min, int hide,
struct memmap_region *region ) { struct memmap_region *region ) {
unsigned int basemem; unsigned int basemem;
unsigned int extmem; unsigned int extmem;
@@ -317,7 +317,7 @@ static void int15_describe ( uint64_t addr, int hide,
int rc; int rc;
/* Initialise region */ /* Initialise region */
memmap_init ( addr, region ); memmap_init ( min, region );
/* Mark addresses above 4GB as inaccessible: we have no way to /* Mark addresses above 4GB as inaccessible: we have no way to
* access them either in a 32-bit build or in a 64-bit build * access them either in a 32-bit build or in a 64-bit build

View File

@@ -196,22 +196,23 @@ static int fdtmem_update_tree ( struct memmap_region *region,
/** /**
* Describe memory region * Describe memory region
* *
* @v addr Address within region * @v min Minimum address
* @v fdt Device tree
* @v max Maximum accessible physical address * @v max Maximum accessible physical address
* @v fdt Device tree
* @v region Region descriptor to fill in * @v region Region descriptor to fill in
*/ */
static void fdtmem_describe ( uint64_t addr, struct fdt *fdt, physaddr_t max, static void fdtmem_describe ( uint64_t min, uint64_t max, struct fdt *fdt,
struct memmap_region *region ) { struct memmap_region *region ) {
uint64_t inaccessible = ( ( ( uint64_t ) max ) + 1 ); uint64_t inaccessible;
/* Initialise region */ /* Initialise region */
memmap_init ( addr, region ); memmap_init ( min, region );
/* Update region based on device tree */ /* Update region based on device tree */
fdtmem_update_tree ( region, fdt ); fdtmem_update_tree ( region, fdt );
/* Treat inaccessible physical memory as such */ /* Treat inaccessible physical memory as such */
inaccessible = ( max + 1 );
memmap_update ( region, inaccessible, -inaccessible, memmap_update ( region, inaccessible, -inaccessible,
MEMMAP_FL_INACCESSIBLE, NULL ); MEMMAP_FL_INACCESSIBLE, NULL );
} }
@@ -289,15 +290,15 @@ physaddr_t fdtmem_relocate ( struct fdt_header *hdr, physaddr_t max ) {
for ( addr = 0, next = 1 ; next ; addr = next ) { for ( addr = 0, next = 1 ; next ; addr = next ) {
/* Describe region and in-use memory */ /* Describe region and in-use memory */
fdtmem_describe ( addr, &fdt, max, &region ); fdtmem_describe ( addr, max, &fdt, &region );
memmap_update ( &region, old, memsz, MEMMAP_FL_USED, "iPXE" ); memmap_update ( &region, old, memsz, MEMMAP_FL_USED, "iPXE" );
memmap_update ( &region, virt_to_phys ( hdr ), fdt.len, memmap_update ( &region, virt_to_phys ( hdr ), fdt.len,
MEMMAP_FL_RESERVED, "FDT" ); MEMMAP_FL_RESERVED, "FDT" );
next = ( region.last + 1 ); next = ( region.max + 1 );
/* Dump region descriptor (for debugging) */ /* Dump region descriptor (for debugging) */
memmap_dump ( &region ); memmap_dump ( &region );
assert ( region.last >= region.addr ); assert ( region.max >= region.min );
/* Use highest possible region */ /* Use highest possible region */
if ( memmap_is_usable ( &region ) && if ( memmap_is_usable ( &region ) &&
@@ -364,15 +365,15 @@ int fdtmem_register ( struct fdt_header *hdr, physaddr_t max ) {
/** /**
* Describe memory region from system memory map * Describe memory region from system memory map
* *
* @v addr Address within region * @v min Minimum address
* @v hide Hide in-use regions from the memory map * @v hide Hide in-use regions from the memory map
* @v region Region descriptor to fill in * @v region Region descriptor to fill in
*/ */
static void fdtmem_describe_region ( uint64_t addr, int hide, static void fdtmem_describe_region ( uint64_t min, int hide,
struct memmap_region *region ) { struct memmap_region *region ) {
/* Describe memory region based on device tree */ /* Describe memory region based on device tree */
fdtmem_describe ( addr, &sysfdt, fdtmem_max, region ); fdtmem_describe ( min, fdtmem_max, &sysfdt, region );
/* Update memory region based on in-use regions, if applicable */ /* Update memory region based on in-use regions, if applicable */
if ( hide ) if ( hide )

View File

@@ -46,54 +46,54 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
*/ */
void memmap_update ( struct memmap_region *region, uint64_t start, void memmap_update ( struct memmap_region *region, uint64_t start,
uint64_t size, unsigned int flags, const char *name ) { uint64_t size, unsigned int flags, const char *name ) {
uint64_t last; uint64_t max;
/* Sanity check */ /* Sanity check */
assert ( region->last >= region->addr ); assert ( region->max >= region->min );
/* Ignore empty regions */ /* Ignore empty regions */
if ( ! size ) if ( ! size )
return; return;
/* Calculate last addresses (and truncate if necessary) */ /* Calculate max addresses (and truncate if necessary) */
last = ( start + size - 1 ); max = ( start + size - 1 );
if ( last < start ) { if ( max < start ) {
last = ~( ( uint64_t ) 0 ); max = ~( ( uint64_t ) 0 );
DBGC ( region, "MEMMAP [%#08llx,%#08llx] %s truncated " DBGC ( region, "MEMMAP [%#08llx,%#08llx] %s truncated "
"(invalid size %#08llx)\n", "(invalid size %#08llx)\n",
( ( unsigned long long ) start ), ( ( unsigned long long ) start ),
( ( unsigned long long ) last ), name, ( ( unsigned long long ) max ), name,
( ( unsigned long long ) size ) ); ( ( unsigned long long ) size ) );
} }
/* Ignore regions entirely below the region of interest */ /* Ignore regions entirely below the region of interest */
if ( last < region->addr ) if ( max < region->min )
return; return;
/* Ignore regions entirely above the region of interest */ /* Ignore regions entirely above the region of interest */
if ( start > region->last ) if ( start > region->max )
return; return;
/* Update region of interest as applicable */ /* Update region of interest as applicable */
if ( start <= region->addr ) { if ( start <= region->min ) {
/* Record this region as covering the region of interest */ /* Record this region as covering the region of interest */
region->flags |= flags; region->flags |= flags;
if ( name ) if ( name )
region->name = name; region->name = name;
/* Update last address if no closer boundary exists */ /* Update max address if no closer boundary exists */
if ( last < region->last ) if ( max < region->max )
region->last = last; region->max = max;
} else if ( start < region->last ) { } else if ( start < region->max ) {
/* Update last address if no closer boundary exists */ /* Update max address if no closer boundary exists */
region->last = ( start - 1 ); region->max = ( start - 1 );
} }
/* Sanity check */ /* Sanity check */
assert ( region->last >= region->addr ); assert ( region->max >= region->min );
} }
/** /**
@@ -134,7 +134,7 @@ size_t memmap_largest ( physaddr_t *start ) {
if ( size > largest ) { if ( size > largest ) {
DBGC ( &region, "...new largest region found\n" ); DBGC ( &region, "...new largest region found\n" );
largest = size; largest = size;
*start = region.addr; *start = region.min;
} }
} }
return largest; return largest;

View File

@@ -175,9 +175,9 @@ static int memmap_settings_fetch ( struct settings *settings,
/* Extract results from this region */ /* Extract results from this region */
if ( include_start ) { if ( include_start ) {
result += region.addr; result += region.min;
DBGC ( settings, "MEMMAP %d start %#08llx\n", index, DBGC ( settings, "MEMMAP %d start %#08llx\n", index,
( ( unsigned long long ) region.addr ) ); ( ( unsigned long long ) region.min ) );
} }
if ( include_length ) { if ( include_length ) {
result += memmap_size ( &region ); result += memmap_size ( &region );

View File

@@ -364,8 +364,8 @@ int initrd_region ( size_t len, struct memmap_region *region ) {
min, ( min + available ) ); min, ( min + available ) );
/* Populate region descriptor */ /* Populate region descriptor */
region->addr = min; region->min = min;
region->last = ( min + available - 1 ); region->max = ( min + available - 1 );
region->flags = MEMMAP_FL_MEMORY; region->flags = MEMMAP_FL_MEMORY;
region->name = "initrd"; region->name = "initrd";

View File

@@ -105,7 +105,7 @@ static int lkrn_ram ( struct image *image, struct lkrn_context *ctx ) {
memmap_dump ( &region ); memmap_dump ( &region );
if ( ! ( region.flags & MEMMAP_FL_MEMORY ) ) if ( ! ( region.flags & MEMMAP_FL_MEMORY ) )
continue; continue;
ctx->ram = region.addr; ctx->ram = region.min;
DBGC ( image, "LKRN %s RAM starts at %#08lx\n", DBGC ( image, "LKRN %s RAM starts at %#08lx\n",
image->name, ctx->ram ); image->name, ctx->ram );
return 0; return 0;
@@ -181,7 +181,7 @@ static int lkrn_exec ( struct image *image ) {
/* Check that everything can be placed at its target addresses */ /* Check that everything can be placed at its target addresses */
totalsz = ( ctx.fdt + fdtimg.len - ctx.ram ); totalsz = ( ctx.fdt + fdtimg.len - ctx.ram );
if ( ( ctx.entry >= region.addr ) && if ( ( ctx.entry >= region.min ) &&
( ( ctx.offset + totalsz ) <= memmap_size ( &region ) ) ) { ( ( ctx.offset + totalsz ) <= memmap_size ( &region ) ) ) {
/* Target addresses are within the reshuffle region */ /* Target addresses are within the reshuffle region */
DBGC ( image, "LKRN %s fits within reshuffle region\n", DBGC ( image, "LKRN %s fits within reshuffle region\n",

View File

@@ -63,7 +63,7 @@ int prep_segment ( void *segment, size_t filesz, size_t memsz ) {
physaddr_t start = virt_to_phys ( segment ); physaddr_t start = virt_to_phys ( segment );
physaddr_t mid = ( start + filesz ); physaddr_t mid = ( start + filesz );
physaddr_t end = ( start + memsz ); physaddr_t end = ( start + memsz );
physaddr_t last; physaddr_t max;
DBGC ( &region, "SEGMENT [%#08lx,%#08lx,%#08lx)\n", start, mid, end ); DBGC ( &region, "SEGMENT [%#08lx,%#08lx,%#08lx)\n", start, mid, end );
@@ -77,10 +77,10 @@ int prep_segment ( void *segment, size_t filesz, size_t memsz ) {
/* Zero-length segments do not need a memory region */ /* Zero-length segments do not need a memory region */
if ( memsz == 0 ) if ( memsz == 0 )
return 0; return 0;
last = ( end - 1 ); max = ( end - 1 );
/* Check for address space overflow */ /* Check for address space overflow */
if ( last < start ) { if ( max < start ) {
DBGC ( &region, "SEGMENT [%#08lx,%#08lx,%#08lx) wraps " DBGC ( &region, "SEGMENT [%#08lx,%#08lx,%#08lx) wraps "
"around\n", start, mid, end ); "around\n", start, mid, end );
return -EINVAL; return -EINVAL;
@@ -91,7 +91,7 @@ int prep_segment ( void *segment, size_t filesz, size_t memsz ) {
memmap_dump ( &region ); memmap_dump ( &region );
/* Fail unless region is usable and sufficiently large */ /* Fail unless region is usable and sufficiently large */
if ( ( ! memmap_is_usable ( &region ) ) || ( region.last < last ) ) { if ( ( ! memmap_is_usable ( &region ) ) || ( region.max < max ) ) {
DBGC ( &region, "SEGMENT [%#08lx,%#08lx,%#08lx) does not fit " DBGC ( &region, "SEGMENT [%#08lx,%#08lx,%#08lx) does not fit "
"into available memory\n", start, mid, end ); "into available memory\n", start, mid, end );
return -ERANGE_SEGMENT; return -ERANGE_SEGMENT;

View File

@@ -46,15 +46,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** A memory region descriptor */ /** A memory region descriptor */
struct memmap_region { struct memmap_region {
/** The address being described */ /** Minimum address in region */
uint64_t addr; uint64_t min;
/** Last address with the same description /** Maximum address in region */
* uint64_t max;
* Note that this is the last address with the same
* description as the address being described, not the first
* address with a different description.
*/
uint64_t last;
/** Region flags */ /** Region flags */
unsigned int flags; unsigned int flags;
/** Region name (for debug messages) */ /** Region name (for debug messages) */
@@ -69,14 +64,14 @@ struct memmap_region {
/** /**
* Initialise memory region descriptor * Initialise memory region descriptor
* *
* @v addr Address within region * @v min Minimum address
* @v region Region descriptor to fill in * @v region Region descriptor to fill in
*/ */
static inline __attribute__ (( always_inline )) void static inline __attribute__ (( always_inline )) void
memmap_init ( uint64_t addr, struct memmap_region *region ) { memmap_init ( uint64_t min, struct memmap_region *region ) {
region->addr = addr; region->min = min;
region->last = ~( ( uint64_t ) 0 ); region->max = ~( ( uint64_t ) 0 );
region->flags = 0; region->flags = 0;
region->name = NULL; region->name = NULL;
} }
@@ -103,7 +98,7 @@ static inline __attribute__ (( always_inline )) uint64_t
memmap_size ( const struct memmap_region *region ) { memmap_size ( const struct memmap_region *region ) {
/* Calculate size, assuming overflow is known to be impossible */ /* Calculate size, assuming overflow is known to be impossible */
return ( ( region->last + 1 ) - region->addr ); return ( region->max - region->min + 1 );
} }
/** An in-use memory region */ /** An in-use memory region */
@@ -132,11 +127,11 @@ struct used_region {
/** /**
* Describe memory region from system memory map * Describe memory region from system memory map
* *
* @v addr Address within region * @v min Minimum address
* @v hide Hide in-use regions from the memory map * @v hide Hide in-use regions from the memory map
* @v region Region descriptor to fill in * @v region Region descriptor to fill in
*/ */
void memmap_describe ( uint64_t addr, int hide, struct memmap_region *region ); void memmap_describe ( uint64_t min, int hide, struct memmap_region *region );
/** /**
* Synchronise in-use regions with the externally visible system memory map * Synchronise in-use regions with the externally visible system memory map
@@ -173,11 +168,11 @@ memmap_use ( struct used_region *used, physaddr_t start, size_t size ) {
* @v hide Hide in-use regions from the memory map * @v hide Hide in-use regions from the memory map
*/ */
#define for_each_memmap_from( region, start, hide ) \ #define for_each_memmap_from( region, start, hide ) \
for ( (region)->addr = (start), (region)->last = 0 ; \ for ( (region)->min = (start), (region)->max = 0 ; \
( ( ( (region)->last + 1 ) != 0 ) && \ ( ( ( (region)->max + 1 ) != 0 ) && \
( memmap_describe ( (region)->addr, (hide), \ ( memmap_describe ( (region)->min, (hide), \
(region) ), 1 ) ) ; \ (region) ), 1 ) ) ; \
(region)->addr = ( (region)->last + 1 ) ) (region)->min = ( (region)->max + 1 ) )
/** /**
* Iterate over memory regions * Iterate over memory regions
@@ -204,8 +199,8 @@ static inline void memmap_dump ( const struct memmap_region *region ) {
( ( flags & MEMMAP_FL_RESERVED ) ? "R" : "-" ), ( ( flags & MEMMAP_FL_RESERVED ) ? "R" : "-" ),
( ( flags & MEMMAP_FL_USED ) ? "U" : "-" ), ( ( flags & MEMMAP_FL_USED ) ? "U" : "-" ),
( ( flags & MEMMAP_FL_INACCESSIBLE ) ? "X" : "-" ), ( ( flags & MEMMAP_FL_INACCESSIBLE ) ? "X" : "-" ),
( ( unsigned long long ) region->addr ), ( ( unsigned long long ) region->min ),
( ( unsigned long long ) region->last ), ( ( unsigned long long ) region->max ),
( name ? " " : "" ), ( name ? name : "" ) ); ( name ? " " : "" ), ( name ? name : "" ) );
} }

View File

@@ -20,16 +20,16 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** /**
* Describe memory region from system memory map * Describe memory region from system memory map
* *
* @v addr Address within region * @v min Minimum address
* @v hide Hide in-use regions from the memory map * @v hide Hide in-use regions from the memory map
* @v region Region descriptor to fill in * @v region Region descriptor to fill in
*/ */
static inline __attribute__ (( always_inline )) void static inline __attribute__ (( always_inline )) void
MEMMAP_INLINE ( null, memmap_describe ) ( uint64_t addr, int hide __unused, MEMMAP_INLINE ( null, memmap_describe ) ( uint64_t min, int hide __unused,
struct memmap_region *region ) { struct memmap_region *region ) {
/* Initialise region as empty */ /* Initialise region as empty */
memmap_init ( addr, region ); memmap_init ( min, region );
} }
/** /**