#include <string.h>
#include <errno.h>
#include <ipxe/uaccess.h>
-#include <ipxe/io.h>
#include <ipxe/memblock.h>
#include <ipxe/memmap.h>
#include <ipxe/umalloc.h>
* @ret len Length of region
*/
size_t largest_memblock ( void **start ) {
- struct memory_map memmap;
- struct memory_region *region;
+ struct memmap_region region;
physaddr_t max = EM_MAX_ADDRESS;
physaddr_t region_start;
physaddr_t region_end;
size_t region_len;
- unsigned int i;
size_t len = 0;
/* Avoid returning uninitialised data on error */
*start = NULL;
/* Scan through all memory regions */
- get_memmap ( &memmap );
- for ( i = 0 ; i < memmap.count ; i++ ) {
- region = &memmap.regions[i];
- DBG ( "Considering [%llx,%llx)\n", region->start, region->end );
+ for_each_memmap ( ®ion, 1 ) {
/* Truncate block to maximum physical address */
- if ( region->start > max ) {
- DBG ( "...starts after maximum address %lx\n", max );
- continue;
+ memmap_dump ( ®ion );
+ if ( region.addr > max ) {
+ DBGC ( ®ion, "...starts after maximum address "
+ "%lx\n", max );
+ break;
}
- region_start = region->start;
- if ( region->end > max ) {
- DBG ( "...end truncated to maximum address %lx\n", max);
+ region_start = region.addr;
+ if ( ! memmap_is_usable ( ®ion ) )
+ continue;
+ region_end = ( region_start + memmap_size ( ®ion ) );
+ if ( region_end > max ) {
+ DBGC ( ®ion, "...end truncated to maximum address "
+ "%lx\n", max);
region_end = 0; /* =max, given the wraparound */
- } else {
- region_end = region->end;
}
region_len = ( region_end - region_start );