* stage.
*/
memmap_dump ( ®ion );
- if ( region.addr > max ) {
+ if ( region.min > max ) {
DBGC ( ®ion, "...starts after max=%#08lx\n", max );
break;
}
- r_start = region.addr;
+ r_start = region.min;
if ( ! memmap_is_usable ( ®ion ) ) {
DBGC ( ®ion, "...not usable\n" );
continue;
/* 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;
/* 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 ( ®ion );
mbmemmap->type = MBMEM_RAM;
/**
* 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;
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
/**
* 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 );
}
for ( addr = 0, next = 1 ; next ; addr = next ) {
/* Describe region and in-use memory */
- fdtmem_describe ( addr, &fdt, max, ®ion );
+ fdtmem_describe ( addr, max, &fdt, ®ion );
memmap_update ( ®ion, old, memsz, MEMMAP_FL_USED, "iPXE" );
memmap_update ( ®ion, 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 ( ®ion );
- assert ( region.last >= region.addr );
+ assert ( region.max >= region.min );
/* Use highest possible region */
if ( memmap_is_usable ( ®ion ) &&
/**
* 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 )
*/
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 );
}
/**
if ( size > largest ) {
DBGC ( ®ion, "...new largest region found\n" );
largest = size;
- *start = region.addr;
+ *start = region.min;
}
}
return largest;
/* 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 ( ®ion );
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";
memmap_dump ( ®ion );
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;
/* 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 ( ®ion ) ) ) {
/* Target addresses are within the reshuffle region */
DBGC ( image, "LKRN %s fits within reshuffle region\n",
physaddr_t start = virt_to_phys ( segment );
physaddr_t mid = ( start + filesz );
physaddr_t end = ( start + memsz );
- physaddr_t last;
+ physaddr_t max;
DBGC ( ®ion, "SEGMENT [%#08lx,%#08lx,%#08lx)\n", start, mid, end );
/* 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 ( ®ion, "SEGMENT [%#08lx,%#08lx,%#08lx) wraps "
"around\n", start, mid, end );
return -EINVAL;
memmap_dump ( ®ion );
/* Fail unless region is usable and sufficiently large */
- if ( ( ! memmap_is_usable ( ®ion ) ) || ( region.last < last ) ) {
+ if ( ( ! memmap_is_usable ( ®ion ) ) || ( region.max < max ) ) {
DBGC ( ®ion, "SEGMENT [%#08lx,%#08lx,%#08lx) does not fit "
"into available memory\n", start, mid, end );
return -ERANGE_SEGMENT;
/** 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) */
/**
* 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;
}
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 */
/**
* 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
* @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
( ( 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 : "" ) );
}
/**
* 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 );
}
/**