iPXE
Functions
memmap.c File Reference

System memory map. More...

#include <assert.h>
#include <ipxe/io.h>
#include <ipxe/memmap.h>

Go to the source code of this file.

Functions

 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)
 Update memory region descriptor. More...
 
void memmap_update_used (struct memmap_region *region)
 Update memory region descriptor based on all in-use memory regions. More...
 
size_t memmap_largest (physaddr_t *start)
 Find largest usable memory region. More...
 
 PROVIDE_MEMMAP_INLINE (null, memmap_describe)
 
 PROVIDE_MEMMAP_INLINE (null, memmap_sync)
 

Detailed Description

System memory map.

Definition in file memmap.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ memmap_update()

void memmap_update ( struct memmap_region region,
uint64_t  start,
uint64_t  size,
unsigned int  flags,
const char *  name 
)

Update memory region descriptor.

Parameters
regionMemory region of interest to be updated
startStart address of known region
sizeSize of known region
flagsFlags for known region
nameName of known region (for debugging)

Update a memory region descriptor based on a known existent region.

Definition at line 47 of file memmap.c.

48  {
49  uint64_t max;
50 
51  /* Sanity check */
52  assert ( region->max >= region->min );
53 
54  /* Ignore empty regions */
55  if ( ! size )
56  return;
57 
58  /* Calculate max addresses (and truncate if necessary) */
59  max = ( start + size - 1 );
60  if ( max < start ) {
61  max = ~( ( uint64_t ) 0 );
62  DBGC ( region, "MEMMAP [%#08llx,%#08llx] %s truncated "
63  "(invalid size %#08llx)\n",
64  ( ( unsigned long long ) start ),
65  ( ( unsigned long long ) max ), name,
66  ( ( unsigned long long ) size ) );
67  }
68 
69  /* Ignore regions entirely below the region of interest */
70  if ( max < region->min )
71  return;
72 
73  /* Ignore regions entirely above the region of interest */
74  if ( start > region->max )
75  return;
76 
77  /* Update region of interest as applicable */
78  if ( start <= region->min ) {
79 
80  /* Record this region as covering the region of interest */
81  region->flags |= flags;
82  if ( name )
83  region->name = name;
84 
85  /* Update max address if no closer boundary exists */
86  if ( max < region->max )
87  region->max = max;
88 
89  } else if ( start < region->max ) {
90 
91  /* Update max address if no closer boundary exists */
92  region->max = ( start - 1 );
93  }
94 
95  /* Sanity check */
96  assert ( region->max >= region->min );
97 }
const char * name
Definition: ath9k_hw.c:1984
#define max(x, y)
Definition: ath.h:40
uint64_t max
Maximum address in region.
Definition: memmap.h:52
uint16_t size
Buffer size.
Definition: dwmac.h:14
#define DBGC(...)
Definition: compiler.h:505
#define min(x, y)
Definition: ath.h:35
unsigned long long uint64_t
Definition: stdint.h:13
uint32_t start
Starting offset.
Definition: netvsc.h:12
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint8_t flags
Flags.
Definition: ena.h:18
unsigned int flags
Region flags.
Definition: memmap.h:54
const char * name
Region name (for debug messages)
Definition: memmap.h:56
uint64_t min
Minimum address in region.
Definition: memmap.h:50

References assert(), DBGC, flags, memmap_region::flags, max, memmap_region::max, min, memmap_region::min, memmap_region::name, name, size, and start.

Referenced by fdtmem_describe(), fdtmem_relocate(), fdtmem_update_node(), fdtmem_update_tree(), int15_describe(), meme820(), and memmap_update_used().

◆ memmap_update_used()

void memmap_update_used ( struct memmap_region region)

Update memory region descriptor based on all in-use memory regions.

Parameters
regionMemory region of interest to be updated

Definition at line 104 of file memmap.c.

104  {
105  struct used_region *used;
106 
107  /* Update descriptor to hide all in-use regions */
109  memmap_update ( region, used->start, used->size,
110  MEMMAP_FL_USED, used->name );
111  }
112 }
size_t size
Length of region.
Definition: memmap.h:111
void memmap_update(struct memmap_region *region, uint64_t start, uint64_t size, unsigned int flags, const char *name)
Update memory region descriptor.
Definition: memmap.c:47
#define USED_REGIONS
In-use memory region table.
Definition: memmap.h:115
#define MEMMAP_FL_USED
Is in use by iPXE.
Definition: memmap.h:61
physaddr_t start
Start address.
Definition: memmap.h:109
An in-use memory region.
Definition: memmap.h:105
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
const char * name
Region name.
Definition: memmap.h:107

References for_each_table_entry, MEMMAP_FL_USED, memmap_update(), used_region::name, used_region::size, used_region::start, and USED_REGIONS.

Referenced by fdtmem_describe_region().

◆ memmap_largest()

size_t memmap_largest ( physaddr_t start)

Find largest usable memory region.

Parameters
startStart address to fill in
Return values
lenLength of region

Definition at line 120 of file memmap.c.

120  {
121  struct memmap_region region;
122  size_t largest;
123  size_t size;
124 
125  /* Find largest usable region */
126  DBGC ( &region, "MEMMAP finding largest usable region\n" );
127  *start = 0;
128  largest = 0;
129  for_each_memmap ( &region, 1 ) {
130  DBGC_MEMMAP ( &region, &region );
131  if ( ! memmap_is_usable ( &region ) )
132  continue;
133  size = memmap_size ( &region );
134  if ( size > largest ) {
135  DBGC ( &region, "...new largest region found\n" );
136  largest = size;
137  *start = region.min;
138  }
139  }
140  return largest;
141 }
static int memmap_is_usable(const struct memmap_region *region)
Check if memory region is usable.
Definition: memmap.h:86
uint16_t size
Buffer size.
Definition: dwmac.h:14
#define DBGC(...)
Definition: compiler.h:505
#define DBGC_MEMMAP(...)
Definition: memmap.h:206
uint32_t start
Starting offset.
Definition: netvsc.h:12
#define for_each_memmap(region, hide)
Iterate over memory regions.
Definition: memmap.h:183
static uint64_t memmap_size(const struct memmap_region *region)
Get remaining size of memory region (from the described address upwards)
Definition: memmap.h:98
A memory region descriptor.
Definition: memmap.h:48

References DBGC, DBGC_MEMMAP, for_each_memmap, memmap_is_usable(), memmap_size(), memmap_region::min, size, and start.

Referenced by uheap_find().

◆ PROVIDE_MEMMAP_INLINE() [1/2]

PROVIDE_MEMMAP_INLINE ( null  ,
memmap_describe   
)

◆ PROVIDE_MEMMAP_INLINE() [2/2]

PROVIDE_MEMMAP_INLINE ( null  ,
memmap_sync   
)