Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[settings] Extend numerical setting tags to 64 bits
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed May 22, 2017
1 parent 2f12690 commit ee9897f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
38 changes: 23 additions & 15 deletions src/core/memmap_settings.c
Expand Up @@ -142,28 +142,36 @@ static int memmap_settings_fetch ( struct settings *settings,
struct memory_map memmap;
struct memory_region *region;
uint64_t result = 0;
unsigned int i;
unsigned int start;
unsigned int count;
unsigned int scale;
int include_start;
int include_length;
int ignore_nonexistent;
unsigned int i;

DBGC ( settings, "MEMMAP start %ld count %ld %s%s%s%s scale %ld\n",
MEMMAP_START ( setting->tag ), MEMMAP_COUNT ( setting->tag ),
( MEMMAP_INCLUDE_START ( setting->tag ) ? "start" : "" ),
( ( MEMMAP_INCLUDE_START ( setting->tag ) &&
MEMMAP_INCLUDE_LENGTH ( setting->tag ) ) ? "+" : "" ),
( MEMMAP_INCLUDE_LENGTH ( setting->tag ) ? "length" : "" ),
( MEMMAP_IGNORE_NONEXISTENT ( setting->tag ) ? " ignore" : "" ),
MEMMAP_SCALE ( setting->tag ) );
/* 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 */
count = MEMMAP_COUNT ( setting->tag );
for ( i = MEMMAP_START ( setting->tag ) ; count-- ; i++ ) {
for ( i = start ; count-- ; i++ ) {

/* Check that region exists */
if ( i >= memmap.count ) {
if ( MEMMAP_IGNORE_NONEXISTENT ( setting->tag ) ) {
if ( ignore_nonexistent ) {
continue;
} else {
DBGC ( settings, "MEMMAP region %d does not "
Expand All @@ -174,20 +182,20 @@ static int memmap_settings_fetch ( struct settings *settings,

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

/* Scale result */
result >>= MEMMAP_SCALE ( setting->tag );
result >>= scale;

/* Return result */
result = cpu_to_be64 ( result );
Expand Down
4 changes: 2 additions & 2 deletions src/core/settings.c
Expand Up @@ -1478,9 +1478,9 @@ struct setting * find_setting ( const char *name ) {
* @v name Name
* @ret tag Tag number, or 0 if not a valid number
*/
static unsigned long parse_setting_tag ( const char *name ) {
static uint64_t parse_setting_tag ( const char *name ) {
char *tmp = ( ( char * ) name );
unsigned long tag = 0;
uint64_t tag = 0;

while ( 1 ) {
tag = ( ( tag << 8 ) | strtoul ( tmp, &tmp, 0 ) );
Expand Down
2 changes: 1 addition & 1 deletion src/include/ipxe/settings.h
Expand Up @@ -40,7 +40,7 @@ struct setting {
* (such as a DHCP option number, or an SMBIOS structure and
* field number).
*/
unsigned long tag;
uint64_t tag;
/** Setting scope (or NULL)
*
* For historic reasons, a NULL scope with a non-zero tag
Expand Down

0 comments on commit ee9897f

Please sign in to comment.