summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brown2025-05-23 17:55:42 +0200
committerMichael Brown2025-05-23 17:55:42 +0200
commit036e43334ad94125dfe212480957fd397e51a053 (patch)
treea2d1e35fdbe58ce9e67ccea1279f2fa9ecc0e0a6 /src
parent[lkrn] Support initrd construction for RISC-V bare-metal kernels (diff)
downloadipxe-036e43334ad94125dfe212480957fd397e51a053.tar.gz
ipxe-036e43334ad94125dfe212480957fd397e51a053.tar.xz
ipxe-036e43334ad94125dfe212480957fd397e51a053.zip
[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>
Diffstat (limited to 'src')
-rw-r--r--src/arch/x86/core/relocate.c4
-rw-r--r--src/arch/x86/image/bzimage.c6
-rw-r--r--src/arch/x86/image/multiboot.c2
-rw-r--r--src/arch/x86/interface/pcbios/int15.c6
-rw-r--r--src/core/fdtmem.c23
-rw-r--r--src/core/memmap.c36
-rw-r--r--src/core/memmap_settings.c4
-rw-r--r--src/image/initrd.c4
-rw-r--r--src/image/lkrn.c4
-rw-r--r--src/image/segment.c8
-rw-r--r--src/include/ipxe/memmap.h39
-rw-r--r--src/include/ipxe/null_memmap.h6
12 files changed, 69 insertions, 73 deletions
diff --git a/src/arch/x86/core/relocate.c b/src/arch/x86/core/relocate.c
index 0d0c5b409..0a8f0b8dc 100644
--- a/src/arch/x86/core/relocate.c
+++ b/src/arch/x86/core/relocate.c
@@ -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;
diff --git a/src/arch/x86/image/bzimage.c b/src/arch/x86/image/bzimage.c
index 764f37bbc..16a47fc57 100644
--- a/src/arch/x86/image/bzimage.c
+++ b/src/arch/x86/image/bzimage.c
@@ -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;
diff --git a/src/arch/x86/image/multiboot.c b/src/arch/x86/image/multiboot.c
index 3d679aed9..c6bc01d4c 100644
--- a/src/arch/x86/image/multiboot.c
+++ b/src/arch/x86/image/multiboot.c
@@ -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;
diff --git a/src/arch/x86/interface/pcbios/int15.c b/src/arch/x86/interface/pcbios/int15.c
index ff90f551c..73bdbbe4a 100644
--- a/src/arch/x86/interface/pcbios/int15.c
+++ b/src/arch/x86/interface/pcbios/int15.c
@@ -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
diff --git a/src/core/fdtmem.c b/src/core/fdtmem.c
index ef1ceb59d..bb8786d3c 100644
--- a/src/core/fdtmem.c
+++ b/src/core/fdtmem.c
@@ -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 )
diff --git a/src/core/memmap.c b/src/core/memmap.c
index 6c814a9ed..2939e855b 100644
--- a/src/core/memmap.c
+++ b/src/core/memmap.c
@@ -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;
diff --git a/src/core/memmap_settings.c b/src/core/memmap_settings.c
index 430065dc9..d07e9747e 100644
--- a/src/core/memmap_settings.c
+++ b/src/core/memmap_settings.c
@@ -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 );
diff --git a/src/image/initrd.c b/src/image/initrd.c
index fec799ce7..ba550a8f2 100644
--- a/src/image/initrd.c
+++ b/src/image/initrd.c
@@ -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";
diff --git a/src/image/lkrn.c b/src/image/lkrn.c
index 7110a95ef..8a7c577cd 100644
--- a/src/image/lkrn.c
+++ b/src/image/lkrn.c
@@ -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",
diff --git a/src/image/segment.c b/src/image/segment.c
index 848831ace..469a66321 100644
--- a/src/image/segment.c
+++ b/src/image/segment.c
@@ -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;
diff --git a/src/include/ipxe/memmap.h b/src/include/ipxe/memmap.h
index 0175be11a..405a74baf 100644
--- a/src/include/ipxe/memmap.h
+++ b/src/include/ipxe/memmap.h
@@ -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 : "" ) );
}
diff --git a/src/include/ipxe/null_memmap.h b/src/include/ipxe/null_memmap.h
index 43c0f2a29..0933d45be 100644
--- a/src/include/ipxe/null_memmap.h
+++ b/src/include/ipxe/null_memmap.h
@@ -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 );
}
/**