]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[memmap] Rename addr/last fields to min/max for clarity
authorMichael Brown <mcb30@ipxe.org>
Fri, 23 May 2025 15:55:42 +0000 (16:55 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 23 May 2025 15:55:42 +0000 (16:55 +0100)
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>
12 files changed:
src/arch/x86/core/relocate.c
src/arch/x86/image/bzimage.c
src/arch/x86/image/multiboot.c
src/arch/x86/interface/pcbios/int15.c
src/core/fdtmem.c
src/core/memmap.c
src/core/memmap_settings.c
src/image/initrd.c
src/image/lkrn.c
src/image/segment.c
src/include/ipxe/memmap.h
src/include/ipxe/null_memmap.h

index 0d0c5b4092b725a4f287b84c820a46e6051e4f1b..0a8f0b8dc3e4286584331ad1a675bc044ca4c4dd 100644 (file)
@@ -81,11 +81,11 @@ __asmcall void relocate ( struct i386_all_regs *ix86 ) {
                 * stage.
                 */
                memmap_dump ( &region );
-               if ( region.addr > max ) {
+               if ( region.min > max ) {
                        DBGC ( &region, "...starts after max=%#08lx\n", max );
                        break;
                }
-               r_start = region.addr;
+               r_start = region.min;
                if ( ! memmap_is_usable ( &region ) ) {
                        DBGC ( &region, "...not usable\n" );
                        continue;
index 764f37bbc57523ade146d549e504e0169b00d7af..16a47fc57c8bbf64155abd2d5f0312eb3ccba4ee 100644 (file)
@@ -347,11 +347,11 @@ static int bzimage_check_initrds ( struct image *image,
 
        /* Limit region to avoiding kernel itself */
        min = virt_to_phys ( bzimg->pm_kernel + bzimg->pm_sz );
-       if ( min < region.addr )
-               min = region.addr;
+       if ( min < region.min )
+               min = region.min;
 
        /* Limit region to kernel's memory limit */
-       max = region.last;
+       max = region.max;
        if ( max > bzimg->mem_limit )
                max = bzimg->mem_limit;
 
index 3d679aed9cbfcfca9ca2a6a5ba100b2f6973b80a..c6bc01d4c0848bb61b9d4e728f1b82898941a1a1 100644 (file)
@@ -132,7 +132,7 @@ static void multiboot_build_memmap ( struct image *image,
                /* Populate Multiboot memory map entry */
                mbmemmap->size = ( sizeof ( *mbmemmap ) -
                                   sizeof ( mbmemmap->size ) );
-               mbmemmap->base_addr = region.addr;
+               mbmemmap->base_addr = region.min;
                mbmemmap->length = memmap_size ( &region );
                mbmemmap->type = MBMEM_RAM;
 
index ff90f551c85578bb618c520b14492b8683d8fd2a..73bdbbe4a06a59422cccfddc5821cb63349f9e66 100644 (file)
@@ -305,11 +305,11 @@ static int meme820 ( struct memmap_region *region ) {
 /**
  * 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 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 ) {
        unsigned int basemem;
        unsigned int extmem;
@@ -317,7 +317,7 @@ static void int15_describe ( uint64_t addr, int hide,
        int rc;
 
        /* Initialise region */
-       memmap_init ( addr, region );
+       memmap_init ( min, region );
 
        /* 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
index ef1ceb59df30be0caaca04af5bcbb456dc2cdf10..bb8786d3ce1d6ba7f357c45610ceec94998bdadc 100644 (file)
@@ -196,22 +196,23 @@ static int fdtmem_update_tree ( struct memmap_region *region,
 /**
  * Describe memory region
  *
- * @v addr             Address within region
- * @v fdt              Device tree
+ * @v min              Minimum address
  * @v max              Maximum accessible physical address
+ * @v fdt              Device tree
  * @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 ) {
-       uint64_t inaccessible = ( ( ( uint64_t ) max ) + 1 );
+       uint64_t inaccessible;
 
        /* Initialise region */
-       memmap_init ( addr, region );
+       memmap_init ( min, region );
 
        /* Update region based on device tree */
        fdtmem_update_tree ( region, fdt );
 
        /* Treat inaccessible physical memory as such */
+       inaccessible = ( max + 1 );
        memmap_update ( region, inaccessible, -inaccessible,
                        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 ) {
 
                /* 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, virt_to_phys ( hdr ), fdt.len,
                                MEMMAP_FL_RESERVED, "FDT" );
-               next = ( region.last + 1 );
+               next = ( region.max + 1 );
 
                /* Dump region descriptor (for debugging) */
                memmap_dump ( &region );
-               assert ( region.last >= region.addr );
+               assert ( region.max >= region.min );
 
                /* Use highest possible 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
  *
- * @v addr             Address within region
+ * @v min              Minimum address
  * @v hide             Hide in-use regions from the memory map
  * @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 ) {
 
        /* 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 */
        if ( hide )
index 6c814a9ed3114cbbe7125075c9529823b260a117..2939e855b5160d76fc6fd880a6723ab9e9b42677 100644 (file)
@@ -46,54 +46,54 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  */
 void memmap_update ( struct memmap_region *region, uint64_t start,
                     uint64_t size, unsigned int flags, const char *name ) {
-       uint64_t last;
+       uint64_t max;
 
        /* Sanity check */
-       assert ( region->last >= region->addr );
+       assert ( region->max >= region->min );
 
        /* Ignore empty regions */
        if ( ! size )
                return;
 
-       /* Calculate last addresses (and truncate if necessary) */
-       last = ( start + size - 1 );
-       if ( last < start ) {
-               last = ~( ( uint64_t ) 0 );
+       /* Calculate max addresses (and truncate if necessary) */
+       max = ( start + size - 1 );
+       if ( max < start ) {
+               max = ~( ( uint64_t ) 0 );
                DBGC ( region, "MEMMAP [%#08llx,%#08llx] %s truncated "
                       "(invalid size %#08llx)\n",
                       ( ( unsigned long long ) start ),
-                      ( ( unsigned long long ) last ), name,
+                      ( ( unsigned long long ) max ), name,
                       ( ( unsigned long long ) size ) );
        }
 
        /* Ignore regions entirely below the region of interest */
-       if ( last < region->addr )
+       if ( max < region->min )
                return;
 
        /* Ignore regions entirely above the region of interest */
-       if ( start > region->last )
+       if ( start > region->max )
                return;
 
        /* Update region of interest as applicable */
-       if ( start <= region->addr ) {
+       if ( start <= region->min ) {
 
                /* Record this region as covering the region of interest */
                region->flags |= flags;
                if ( name )
                        region->name = name;
 
-               /* Update last address if no closer boundary exists */
-               if ( last < region->last )
-                       region->last = last;
+               /* Update max address if no closer boundary exists */
+               if ( max < region->max )
+                       region->max = max;
 
-       } else if ( start < region->last ) {
+       } else if ( start < region->max ) {
 
-               /* Update last address if no closer boundary exists */
-               region->last = ( start - 1 );
+               /* Update max address if no closer boundary exists */
+               region->max = ( start - 1 );
        }
 
        /* 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 ) {
                        DBGC ( &region, "...new largest region found\n" );
                        largest = size;
-                       *start = region.addr;
+                       *start = region.min;
                }
        }
        return largest;
index 430065dc99ea879796164f89393cda4275f12b2d..d07e9747e140dbebdb66c18493b18ecaeea16f3b 100644 (file)
@@ -175,9 +175,9 @@ static int memmap_settings_fetch ( struct settings *settings,
 
                /* Extract results from this region */
                if ( include_start ) {
-                       result += region.addr;
+                       result += region.min;
                        DBGC ( settings, "MEMMAP %d start %#08llx\n", index,
-                              ( ( unsigned long long ) region.addr ) );
+                              ( ( unsigned long long ) region.min ) );
                }
                if ( include_length ) {
                        result += memmap_size ( &region );
index fec799ce70421c7691754ad4c6cbecb8b4594342..ba550a8f22eb69430af91948264965e866cee520 100644 (file)
@@ -364,8 +364,8 @@ int initrd_region ( size_t len, struct memmap_region *region ) {
               min, ( min + available ) );
 
        /* Populate region descriptor */
-       region->addr = min;
-       region->last = ( min + available - 1 );
+       region->min = min;
+       region->max = ( min + available - 1 );
        region->flags = MEMMAP_FL_MEMORY;
        region->name = "initrd";
 
index 7110a95efd4b27cd320cfd88132844e82180d48d..8a7c577cdd563c15d28b636dcc2343677cd0f6d6 100644 (file)
@@ -105,7 +105,7 @@ static int lkrn_ram ( struct image *image, struct lkrn_context *ctx ) {
                memmap_dump ( &region );
                if ( ! ( region.flags & MEMMAP_FL_MEMORY ) )
                        continue;
-               ctx->ram = region.addr;
+               ctx->ram = region.min;
                DBGC ( image, "LKRN %s RAM starts at %#08lx\n",
                       image->name, ctx->ram );
                return 0;
@@ -181,7 +181,7 @@ static int lkrn_exec ( struct image *image ) {
 
        /* Check that everything can be placed at its target addresses */
        totalsz = ( ctx.fdt + fdtimg.len - ctx.ram );
-       if ( ( ctx.entry >= region.addr ) &&
+       if ( ( ctx.entry >= region.min ) &&
             ( ( ctx.offset + totalsz ) <= memmap_size ( &region ) ) ) {
                /* Target addresses are within the reshuffle region */
                DBGC ( image, "LKRN %s fits within reshuffle region\n",
index 848831acea9401af6b9a073c8a885d59c44d0637..469a66321f5319dba24f3806da088f0b7f9b34e8 100644 (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 mid = ( start + filesz );
        physaddr_t end = ( start + memsz );
-       physaddr_t last;
+       physaddr_t max;
 
        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 */
        if ( memsz == 0 )
                return 0;
-       last = ( end - 1 );
+       max = ( end - 1 );
 
        /* Check for address space overflow */
-       if ( last < start ) {
+       if ( max < start ) {
                DBGC ( &region, "SEGMENT [%#08lx,%#08lx,%#08lx) wraps "
                       "around\n", start, mid, end );
                return -EINVAL;
@@ -91,7 +91,7 @@ int prep_segment ( void *segment, size_t filesz, size_t memsz ) {
        memmap_dump ( &region );
 
        /* 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 "
                       "into available memory\n", start, mid, end );
                return -ERANGE_SEGMENT;
index 0175be11afc1cc2c0bc4b0b83af4a54b594ebe75..405a74bafb7b100fc2c9823c5de52eff01fdcf46 100644 (file)
@@ -46,15 +46,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 /** A memory region descriptor */
 struct memmap_region {
-       /** The address being described */
-       uint64_t addr;
-       /** Last address with the same description
-        *
-        * 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;
+       /** Minimum address in region */
+       uint64_t min;
+       /** Maximum address in region */
+       uint64_t max;
        /** Region flags */
        unsigned int flags;
        /** Region name (for debug messages) */
@@ -69,14 +64,14 @@ struct memmap_region {
 /**
  * Initialise memory region descriptor
  *
- * @v addr             Address within region
+ * @v min              Minimum address
  * @v region           Region descriptor to fill in
  */
 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->last = ~( ( uint64_t ) 0 );
+       region->min = min;
+       region->max = ~( ( uint64_t ) 0 );
        region->flags = 0;
        region->name = NULL;
 }
@@ -103,7 +98,7 @@ static inline __attribute__ (( always_inline )) uint64_t
 memmap_size ( const struct memmap_region *region ) {
 
        /* 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 */
@@ -132,11 +127,11 @@ struct used_region {
 /**
  * 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 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
@@ -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
  */
 #define for_each_memmap_from( region, start, hide )                    \
-       for ( (region)->addr = (start), (region)->last = 0 ;            \
-             ( ( ( (region)->last + 1 ) != 0 ) &&                      \
-               ( memmap_describe ( (region)->addr, (hide),             \
+       for ( (region)->min = (start), (region)->max = 0 ;              \
+             ( ( ( (region)->max + 1 ) != 0 ) &&                       \
+               ( memmap_describe ( (region)->min, (hide),              \
                                    (region) ), 1 ) ) ;                 \
-             (region)->addr = ( (region)->last + 1 ) )
+             (region)->min = ( (region)->max + 1 ) )
 
 /**
  * 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_USED ) ? "U" : "-" ),
               ( ( flags & MEMMAP_FL_INACCESSIBLE ) ? "X" : "-" ),
-              ( ( unsigned long long ) region->addr ),
-              ( ( unsigned long long ) region->last ),
+              ( ( unsigned long long ) region->min ),
+              ( ( unsigned long long ) region->max ),
               ( name ? " " : "" ), ( name ? name : "" ) );
 }
 
index 43c0f2a2937815f678ed2afdab47139799100a68..0933d45befb67fc3271568d3169909e312b8dc63 100644 (file)
@@ -20,16 +20,16 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 /**
  * 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 region           Region descriptor to fill in
  */
 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 ) {
 
        /* Initialise region as empty */
-       memmap_init ( addr, region );
+       memmap_init ( min, region );
 }
 
 /**