iPXE
Macros | Functions | Variables
memmap_settings.c File Reference

Memory map settings. More...

#include <string.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/init.h>
#include <ipxe/settings.h>
#include <ipxe/io.h>

Go to the source code of this file.

Macros

#define MEMMAP_TAG(start, count, include_start, include_length, ignore, scale)
 Construct memory map setting tag. More...
 
#define MEMMAP_COUNT(tag)   ( ( ( (tag) >> 24 ) & 0xff ) + 1 )
 Extract number of regions from setting tag. More...
 
#define MEMMAP_START(tag)   ( ( (tag) >> 16 ) & 0xff )
 Extract starting region from setting tag. More...
 
#define MEMMAP_IGNORE_NONEXISTENT(tag)   ( (tag) & 0x00000400UL )
 Extract ignore flag from setting tag. More...
 
#define MEMMAP_INCLUDE_LENGTH(tag)   ( (tag) & 0x00000200UL )
 Extract length inclusion flag from setting tag. More...
 
#define MEMMAP_INCLUDE_START(tag)   ( (tag) & 0x00000100UL )
 Extract start address inclusion flag from setting tag. More...
 
#define MEMMAP_SCALE(tag)   ( (tag) & 0x3f )
 Extract scale factor from setting tag. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int memmap_settings_applies (struct settings *settings __unused, const struct setting *setting)
 Check applicability of memory map setting. More...
 
static int memmap_settings_fetch (struct settings *settings, struct setting *setting, void *data, size_t len)
 Fetch value of memory map setting. More...
 
static void memmap_settings_init (void)
 Initialise memory map settings. More...
 
struct init_fn memmap_settings_init_fn __init_fn (INIT_NORMAL)
 Memory map settings initialiser. More...
 
const struct setting memsize_setting __setting (SETTING_MISC, memsize)
 Memory map predefined settings. More...
 

Variables

static const struct settings_scope memmap_settings_scope
 Memory map settings scope. More...
 
static struct settings_operations memmap_settings_operations
 Memory map settings operations. More...
 
static struct settings memmap_settings
 Memory map settings. More...
 

Detailed Description

Memory map settings.

Memory map settings are numerically encoded as:

Bits 31-24 Number of regions, minus one Bits 23-16 Starting region Bits 15-11 Unused Bit 10 Ignore non-existent regions (rather than generating an error) Bit 9 Include length Bit 8 Include start address Bits 7-6 Unused Bits 5-0 Scale factor (i.e. right shift count)

Definition in file memmap_settings.c.

Macro Definition Documentation

◆ MEMMAP_TAG

#define MEMMAP_TAG (   start,
  count,
  include_start,
  include_length,
  ignore,
  scale 
)
Value:
( ( (start) << 16 ) | ( ( (count) - 1 ) << 24 ) | \
( (ignore) << 10 ) | ( (include_length) << 9 ) | \
( (include_start) << 8 ) | (scale) )
uint32_t start
Starting offset.
Definition: netvsc.h:12
uint16_t count
Number of entries.
Definition: ena.h:22

Construct memory map setting tag.

Parameters
startStarting region
countNumber of regions
include_startInclude start address
include_lengthInclude length
ignoreIgnore non-existent regions
scaleScale factor
Return values
tagSetting tag

Definition at line 60 of file memmap_settings.c.

◆ MEMMAP_COUNT

#define MEMMAP_COUNT (   tag)    ( ( ( (tag) >> 24 ) & 0xff ) + 1 )

Extract number of regions from setting tag.

Parameters
tagSetting tag
Return values
countNumber of regions

Definition at line 72 of file memmap_settings.c.

◆ MEMMAP_START

#define MEMMAP_START (   tag)    ( ( (tag) >> 16 ) & 0xff )

Extract starting region from setting tag.

Parameters
tagSetting tag
Return values
startStarting region

Definition at line 80 of file memmap_settings.c.

◆ MEMMAP_IGNORE_NONEXISTENT

#define MEMMAP_IGNORE_NONEXISTENT (   tag)    ( (tag) & 0x00000400UL )

Extract ignore flag from setting tag.

Parameters
tagSetting tag
Return values
ignoreIgnore non-existent regions

Definition at line 88 of file memmap_settings.c.

◆ MEMMAP_INCLUDE_LENGTH

#define MEMMAP_INCLUDE_LENGTH (   tag)    ( (tag) & 0x00000200UL )

Extract length inclusion flag from setting tag.

Parameters
tagSetting tag
Return values
include_lengthInclude length

Definition at line 96 of file memmap_settings.c.

◆ MEMMAP_INCLUDE_START

#define MEMMAP_INCLUDE_START (   tag)    ( (tag) & 0x00000100UL )

Extract start address inclusion flag from setting tag.

Parameters
tagSetting tag
Return values
include_startInclude start address

Definition at line 104 of file memmap_settings.c.

◆ MEMMAP_SCALE

#define MEMMAP_SCALE (   tag)    ( (tag) & 0x3f )

Extract scale factor from setting tag.

Parameters
tagSetting tag
scaleScale factor

Definition at line 112 of file memmap_settings.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ memmap_settings_applies()

static int memmap_settings_applies ( struct settings *settings  __unused,
const struct setting setting 
)
static

Check applicability of memory map setting.

Parameters
settingsSettings block
settingSetting
Return values
appliesSetting applies within this settings block

Definition at line 124 of file memmap_settings.c.

125  {
126 
127  return ( setting->scope == &memmap_settings_scope );
128 }
static const struct settings_scope memmap_settings_scope
Memory map settings scope.
A setting.
Definition: settings.h:23
const struct settings_scope * scope
Setting scope (or NULL)
Definition: settings.h:49

References memmap_settings_scope, and setting::scope.

◆ memmap_settings_fetch()

static int memmap_settings_fetch ( struct settings settings,
struct setting setting,
void *  data,
size_t  len 
)
static

Fetch value of memory map setting.

Parameters
settingsSettings block
settingSetting to fetch
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 139 of file memmap_settings.c.

141  {
142  struct memory_map memmap;
143  struct memory_region *region;
144  uint64_t result = 0;
145  unsigned int start;
146  unsigned int count;
147  unsigned int scale;
148  int include_start;
149  int include_length;
150  int ignore_nonexistent;
151  unsigned int i;
152 
153  /* Parse settings tag */
154  start = MEMMAP_START ( setting->tag );
155  count = MEMMAP_COUNT ( setting->tag );
156  scale = MEMMAP_SCALE ( setting->tag );
157  include_start = MEMMAP_INCLUDE_START ( setting->tag );
158  include_length = MEMMAP_INCLUDE_LENGTH ( setting->tag );
159  ignore_nonexistent = MEMMAP_IGNORE_NONEXISTENT ( setting->tag );
160  DBGC ( settings, "MEMMAP start %d count %d %s%s%s%s scale %d\n",
161  start, count, ( include_start ? "start" : "" ),
162  ( ( include_start && include_length ) ? "+" : "" ),
163  ( include_length ? "length" : "" ),
164  ( ignore_nonexistent ? " ignore" : "" ), scale );
165 
166  /* Fetch memory map */
167  get_memmap ( &memmap );
168 
169  /* Extract results from memory map */
170  for ( i = start ; count-- ; i++ ) {
171 
172  /* Check that region exists */
173  if ( i >= memmap.count ) {
174  if ( ignore_nonexistent ) {
175  continue;
176  } else {
177  DBGC ( settings, "MEMMAP region %d does not "
178  "exist\n", i );
179  return -ENOENT;
180  }
181  }
182 
183  /* Extract results from this region */
184  region = &memmap.regions[i];
185  if ( include_start ) {
186  result += region->start;
187  DBGC ( settings, "MEMMAP %d start %08llx\n",
188  i, region->start );
189  }
190  if ( include_length ) {
191  result += ( region->end - region->start );
192  DBGC ( settings, "MEMMAP %d length %08llx\n",
193  i, ( region->end - region->start ) );
194  }
195  }
196 
197  /* Scale result */
198  result >>= scale;
199 
200  /* Return result */
201  result = cpu_to_be64 ( result );
202  if ( len > sizeof ( result ) )
203  len = sizeof ( result );
204  memcpy ( data, &result, len );
205 
206  /* Set type if not already specified */
207  if ( ! setting->type )
208  setting->type = &setting_type_hexraw;
209 
210  return sizeof ( result );
211 }
void get_memmap(struct memory_map *memmap)
Get memory map.
#define MEMMAP_COUNT(tag)
Extract number of regions from setting tag.
#define DBGC(...)
Definition: compiler.h:505
#define MEMMAP_INCLUDE_LENGTH(tag)
Extract length inclusion flag from setting tag.
#define ENOENT
No such file or directory.
Definition: errno.h:514
unsigned long long uint64_t
Definition: stdint.h:13
#define MEMMAP_SCALE(tag)
Extract scale factor from setting tag.
A memory map.
Definition: io.h:499
uint32_t start
Starting offset.
Definition: netvsc.h:12
uint64_t tag
Setting tag, if applicable.
Definition: settings.h:43
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int result
Definition: bigint.h:148
const struct setting_type * type
Setting type.
Definition: settings.h:36
#define MEMMAP_START(tag)
Extract starting region from setting tag.
A settings block.
Definition: settings.h:132
A usable memory region.
Definition: io.h:488
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14
uint64_t start
Physical start address.
Definition: io.h:490
uint16_t count
Number of entries.
Definition: ena.h:22
#define cpu_to_be64(value)
Definition: byteswap.h:111
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define MEMMAP_IGNORE_NONEXISTENT(tag)
Extract ignore flag from setting tag.
uint64_t end
Physical end address.
Definition: io.h:492
#define MEMMAP_INCLUDE_START(tag)
Extract start address inclusion flag from setting tag.

References count, memory_map::count, cpu_to_be64, data, DBGC, memory_region::end, ENOENT, get_memmap(), len, memcpy(), MEMMAP_COUNT, MEMMAP_IGNORE_NONEXISTENT, MEMMAP_INCLUDE_LENGTH, MEMMAP_INCLUDE_START, MEMMAP_SCALE, MEMMAP_START, memory_map::regions, result, start, memory_region::start, setting::tag, and setting::type.

◆ memmap_settings_init()

static void memmap_settings_init ( void  )
static

Initialise memory map settings.

Definition at line 229 of file memmap_settings.c.

229  {
230  int rc;
231 
233  "memmap" ) ) != 0 ) {
234  DBG ( "MEMMAP could not register settings: %s\n",
235  strerror ( rc ) );
236  return;
237  }
238 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static struct settings memmap_settings
Memory map settings.
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
Definition: settings.c:478
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References DBG, memmap_settings, NULL, rc, register_settings(), and strerror().

◆ __init_fn()

struct init_fn memmap_settings_init_fn __init_fn ( INIT_NORMAL  )

Memory map settings initialiser.

◆ __setting()

const struct setting memsize_setting __setting ( SETTING_MISC  ,
memsize   
)

Memory map predefined settings.

Variable Documentation

◆ memmap_settings_scope

const struct settings_scope memmap_settings_scope
static

Memory map settings scope.

Definition at line 115 of file memmap_settings.c.

Referenced by memmap_settings_applies().

◆ memmap_settings_operations

struct settings_operations memmap_settings_operations
static
Initial value:
= {
}
static int memmap_settings_applies(struct settings *settings __unused, const struct setting *setting)
Check applicability of memory map setting.
static int memmap_settings_fetch(struct settings *settings, struct setting *setting, void *data, size_t len)
Fetch value of memory map setting.

Memory map settings operations.

Definition at line 214 of file memmap_settings.c.

◆ memmap_settings

struct settings memmap_settings
static
Initial value:
= {
.refcnt = NULL,
.default_scope = &memmap_settings_scope,
}
static struct settings_operations memmap_settings_operations
Memory map settings operations.
static const struct settings_scope memmap_settings_scope
Memory map settings scope.
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:140
static struct settings memmap_settings
Memory map settings.
struct list_head children
Child settings blocks.
Definition: settings.h:142
#define LIST_HEAD_INIT(list)
Initialise a static list head.
Definition: list.h:30
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

Memory map settings.

Definition at line 220 of file memmap_settings.c.

Referenced by memmap_settings_init().