iPXE
Functions
memblock.h File Reference

Largest memory block. More...

#include <stdint.h>
#include <ipxe/uaccess.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
size_t largest_memblock (userptr_t *start)
 Find largest usable memory region. More...
 

Detailed Description

Largest memory block.

Definition in file memblock.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ largest_memblock()

size_t largest_memblock ( userptr_t start)

Find largest usable memory region.

Return values
startStart of region
lenLength of region

Definition at line 73 of file memtop_umalloc.c.

73  {
74  struct memory_map memmap;
75  struct memory_region *region;
77  physaddr_t region_start;
78  physaddr_t region_end;
79  size_t region_len;
80  unsigned int i;
81  size_t len = 0;
82 
83  /* Avoid returning uninitialised data on error */
84  *start = UNULL;
85 
86  /* Scan through all memory regions */
87  get_memmap ( &memmap );
88  for ( i = 0 ; i < memmap.count ; i++ ) {
89  region = &memmap.regions[i];
90  DBG ( "Considering [%llx,%llx)\n", region->start, region->end );
91 
92  /* Truncate block to maximum physical address */
93  if ( region->start > max ) {
94  DBG ( "...starts after maximum address %lx\n", max );
95  continue;
96  }
97  region_start = region->start;
98  if ( region->end > max ) {
99  DBG ( "...end truncated to maximum address %lx\n", max);
100  region_end = 0; /* =max, given the wraparound */
101  } else {
102  region_end = region->end;
103  }
104  region_len = ( region_end - region_start );
105 
106  /* Use largest block */
107  if ( region_len > len ) {
108  DBG ( "...new best block found\n" );
109  *start = phys_to_user ( region_start );
110  len = region_len;
111  }
112  }
113 
114  return len;
115 }
void get_memmap(struct memory_map *memmap)
Get memory map.
#define max(x, y)
Definition: ath.h:39
userptr_t phys_to_user(unsigned long phys_addr)
Convert physical address to user pointer.
A memory map.
Definition: io.h:499
uint32_t start
Starting offset.
Definition: netvsc.h:12
#define EM_MAX_ADDRESS
Maximum usable address for external allocated memory.
A usable memory region.
Definition: io.h:488
unsigned long physaddr_t
Definition: stdint.h:20
#define UNULL
Equivalent of NULL for user pointers.
Definition: uaccess.h:36
uint32_t len
Length.
Definition: ena.h:14
uint64_t start
Physical start address.
Definition: io.h:490
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
uint64_t end
Physical end address.
Definition: io.h:492

References memory_map::count, DBG, EM_MAX_ADDRESS, memory_region::end, get_memmap(), len, max, phys_to_user(), memory_map::regions, start, memory_region::start, and UNULL.

Referenced by init_eheap(), and initrd_startup().