iPXE
Defines | 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.

Defines

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

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.
static int memmap_settings_fetch (struct settings *settings, struct setting *setting, void *data, size_t len)
 Fetch value of memory map setting.
static void memmap_settings_init (void)
 Initialise memory map settings.
struct init_fn
memmap_settings_init_fn 
__init_fn (INIT_NORMAL)
 Memory map settings initialiser.
struct setting memsize_setting __setting (SETTING_MISC, memsize)
 Memory map predefined settings.

Variables

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

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.


Define Documentation

#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) )

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.

#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.

Referenced by memmap_settings_fetch().

#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.

Referenced by memmap_settings_fetch().

#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.

Referenced by memmap_settings_fetch().

#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.

Referenced by memmap_settings_fetch().

#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.

Referenced by memmap_settings_fetch().

#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.

Referenced by memmap_settings_fetch().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
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.

References memmap_settings_scope, and setting::scope.

                                                                     {

        return ( setting->scope == &memmap_settings_scope );
}
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.

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

                                                            {
        struct memory_map memmap;
        struct memory_region *region;
        uint64_t result = 0;
        unsigned int start;
        unsigned int count;
        unsigned int scale;
        int include_start;
        int include_length;
        int ignore_nonexistent;
        unsigned int i;

        /* Parse settings tag */
        start = MEMMAP_START ( setting->tag );
        count = MEMMAP_COUNT ( setting->tag );
        scale = MEMMAP_SCALE ( setting->tag );
        include_start = MEMMAP_INCLUDE_START ( setting->tag );
        include_length = MEMMAP_INCLUDE_LENGTH ( setting->tag );
        ignore_nonexistent = MEMMAP_IGNORE_NONEXISTENT ( setting->tag );
        DBGC ( settings, "MEMMAP start %d count %d %s%s%s%s scale %d\n",
               start, count, ( include_start ? "start" : "" ),
               ( ( include_start && include_length ) ? "+" : "" ),
               ( include_length ? "length" : "" ),
               ( ignore_nonexistent ? " ignore" : "" ), scale );

        /* Fetch memory map */
        get_memmap ( &memmap );

        /* Extract results from memory map */
        for ( i = start ; count-- ; i++ ) {

                /* Check that region exists */
                if ( i >= memmap.count ) {
                        if ( ignore_nonexistent ) {
                                continue;
                        } else {
                                DBGC ( settings, "MEMMAP region %d does not "
                                       "exist\n", i );
                                return -ENOENT;
                        }
                }

                /* Extract results from this region */
                region = &memmap.regions[i];
                if ( include_start ) {
                        result += region->start;
                        DBGC ( settings, "MEMMAP %d start %08llx\n",
                               i, region->start );
                }
                if ( include_length ) {
                        result += ( region->end - region->start );
                        DBGC ( settings, "MEMMAP %d length %08llx\n",
                               i, ( region->end - region->start ) );
                }
        }

        /* Scale result */
        result >>= scale;

        /* Return result */
        result = cpu_to_be64 ( result );
        if ( len > sizeof ( result ) )
                len = sizeof ( result );
        memcpy ( data, &result, len );

        /* Set type if not already specified */
        if ( ! setting->type )
                setting->type = &setting_type_hexraw;

        return sizeof ( result );
}
static void memmap_settings_init ( void  ) [static]

Initialise memory map settings.

Definition at line 229 of file memmap_settings.c.

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

                                          {
        int rc;

        if ( ( rc = register_settings ( &memmap_settings, NULL,
                                        "memmap" ) ) != 0 ) {
                DBG ( "MEMMAP could not register settings: %s\n",
                      strerror ( rc ) );
                return;
        }
}
struct init_fn memmap_settings_init_fn __init_fn ( INIT_NORMAL  ) [read]

Memory map settings initialiser.

struct setting memsize_setting __setting ( SETTING_MISC  ,
memsize   
) [read]

Memory map predefined settings.


Variable Documentation

Memory map settings scope.

Definition at line 115 of file memmap_settings.c.

Referenced by memmap_settings_applies().

Initial value:

Memory map settings operations.

Definition at line 214 of file memmap_settings.c.

struct settings memmap_settings [static]
Initial value:
 {
        .refcnt = NULL,
        .siblings = LIST_HEAD_INIT ( memmap_settings.siblings ),
        .children = LIST_HEAD_INIT ( memmap_settings.children ),
        .op = &memmap_settings_operations,
        .default_scope = &memmap_settings_scope,
}

Memory map settings.

Definition at line 220 of file memmap_settings.c.