diff options
author | Tim Wawrzynczak <twawrzynczak@chromium.org> | 2020-10-01 15:41:31 -0600 |
---|---|---|
committer | Tim Wawrzynczak <twawrzynczak@chromium.org> | 2020-10-30 15:24:52 +0000 |
commit | 24b4af668b3f3995a5844560ce1885d30d8d8bfd (patch) | |
tree | a3dfb0a1e8b4d3b02c0b94b7d39e55e56c0e4961 /util/sconfig | |
parent | eafe7989ace4e5d0b4214b6b30467438da3965ff (diff) | |
download | coreboot-24b4af668b3f3995a5844560ce1885d30d8d8bfd.tar.xz |
fw_config: Convert fw_config to a 64-bit field
We all knew this was coming, 32 bits is never enough. Doing this early
so that it doesn't affect too much code yet. Take care of every usage of
fw_config throughout the codebase so the conversion is all done at once.
BUG=b:169668368
TEST=Hacked up this code to OR 0x1_000_0000 with CBI-sourced FW_CONFIG
and verify the console print contained that bit.
Signed-off-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Change-Id: I6f2065d347eafa0ef7b346caeabdc3b626402092
Reviewed-on: https://review.coreboot.org/c/coreboot/+/45939
Reviewed-by: Furquan Shaikh <furquan@google.com>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'util/sconfig')
-rw-r--r-- | util/sconfig/main.c | 31 | ||||
-rw-r--r-- | util/sconfig/sconfig.h | 5 | ||||
-rwxr-xr-x | util/sconfig/sconfig.y | 5 |
3 files changed, 23 insertions, 18 deletions
diff --git a/util/sconfig/main.c b/util/sconfig/main.c index 4f13293a98..a7b2ce676e 100644 --- a/util/sconfig/main.c +++ b/util/sconfig/main.c @@ -4,8 +4,9 @@ #include <assert.h> #include <ctype.h> #include <getopt.h> -/* stat.h needs to be included before commonlib/helpers.h to avoid errors.*/ +#include <inttypes.h> #include <libgen.h> +/* stat.h needs to be included before commonlib/helpers.h to avoid errors.*/ #include <sys/stat.h> #include <commonlib/helpers.h> #include <stdint.h> @@ -402,8 +403,8 @@ struct fw_config_field *new_fw_config_field(const char *name, { struct fw_config_field *field = find_fw_config_field(name); - /* Check that field is within 32bits. */ - if (start_bit > end_bit || end_bit > 31) { + /* Check that field is within 64 bits. */ + if (start_bit > end_bit || end_bit > 63) { printf("ERROR: fw_config field %s has invalid range %u-%u\n", name, start_bit, end_bit); exit(1); @@ -452,15 +453,16 @@ static void append_fw_config_option_to_field(struct fw_config_field *field, } } -void add_fw_config_option(struct fw_config_field *field, const char *name, unsigned int value) +void add_fw_config_option(struct fw_config_field *field, const char *name, uint64_t value) { struct fw_config_option *option; - uint32_t field_max_value; + uint64_t field_max_value; /* Check that option value fits within field mask. */ - field_max_value = (1 << (1 + field->end_bit - field->start_bit)) - 1; + field_max_value = (1ull << (1ull + field->end_bit - field->start_bit)) - 1ull; if (value > field_max_value) { - printf("ERROR: fw_config option %s:%s value %u larger than field max %u\n", + printf("ERROR: fw_config option %s:%s value %" PRIx64 " larger than field max %" + PRIx64 "\n", field->name, name, value, field_max_value); exit(1); } @@ -475,7 +477,7 @@ void add_fw_config_option(struct fw_config_field *field, const char *name, unsig } /* Compare values. */ if (value == option->value) { - printf("ERROR: fw_config option %s:%s[%u] redefined as %s\n", + printf("ERROR: fw_config option %s:%s[%" PRIx64 "] redefined as %s\n", field->name, option->name, value, name); exit(1); } @@ -532,23 +534,24 @@ static void emit_fw_config(FILE *fil) while (field) { struct fw_config_option *option = field->options; - uint32_t mask; + uint64_t mask; fprintf(fil, "#define FW_CONFIG_FIELD_%s_NAME \"%s\"\n", field->name, field->name); /* Compute mask from start and end bit. */ - mask = ((1 << (1 + field->end_bit - field->start_bit)) - 1); + mask = ((1ull << (1ull + field->end_bit - field->start_bit)) - 1ull); mask <<= field->start_bit; - fprintf(fil, "#define FW_CONFIG_FIELD_%s_MASK 0x%08x\n", + fprintf(fil, "#define FW_CONFIG_FIELD_%s_MASK 0x%" PRIx64 "\n", field->name, mask); while (option) { fprintf(fil, "#define FW_CONFIG_FIELD_%s_OPTION_%s_NAME \"%s\"\n", field->name, option->name, option->name); - fprintf(fil, "#define FW_CONFIG_FIELD_%s_OPTION_%s_VALUE 0x%08x\n", - field->name, option->name, option->value << field->start_bit); + fprintf(fil, "#define FW_CONFIG_FIELD_%s_OPTION_%s_VALUE 0x%" + PRIx64 "\n", field->name, option->name, + option->value << field->start_bit); option = option->next; } @@ -569,7 +572,7 @@ static int emit_fw_config_probe(FILE *fil, struct device *dev) /* Find matching field. */ struct fw_config_field *field; struct fw_config_option *option; - uint32_t mask, value; + uint64_t mask, value; field = find_fw_config_field(probe->field); if (!field) { diff --git a/util/sconfig/sconfig.h b/util/sconfig/sconfig.h index e2ff4c786b..0db1ce59c9 100644 --- a/util/sconfig/sconfig.h +++ b/util/sconfig/sconfig.h @@ -1,6 +1,7 @@ /* sconfig, coreboot device tree compiler */ /* SPDX-License-Identifier: GPL-2.0-only */ +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -31,7 +32,7 @@ struct pci_irq_info { struct fw_config_option; struct fw_config_option { const char *name; - unsigned int value; + uint64_t value; struct fw_config_option *next; }; struct fw_config_field; @@ -213,6 +214,6 @@ struct fw_config_field *new_fw_config_field(const char *name, unsigned int start_bit, unsigned int end_bit); void add_fw_config_option(struct fw_config_field *field, const char *name, - unsigned int value); + uint64_t value); void add_fw_config_probe(struct bus *bus, const char *field, const char *option); diff --git a/util/sconfig/sconfig.y b/util/sconfig/sconfig.y index cf71b02f3e..84dfe248fd 100755 --- a/util/sconfig/sconfig.y +++ b/util/sconfig/sconfig.y @@ -2,6 +2,7 @@ /* sconfig, coreboot device tree compiler */ /* SPDX-License-Identifier: GPL-2.0-only */ +#include <stdint.h> #include "sconfig.h" int yylex(); @@ -16,7 +17,7 @@ static struct fw_config_field *cur_field; struct device *dev; struct chip_instance *chip_instance; char *string; - int number; + uint64_t number; } %token CHIP DEVICE REGISTER ALIAS REFERENCE ASSOCIATION BOOL STATUS MANDATORY BUS RESOURCE END EQUALS HEX STRING PCI PNP I2C APIC CPU_CLUSTER CPU DOMAIN IRQ DRQ SLOT_DESC IO NUMBER SUBSYSTEMID INHERIT IOAPIC_IRQ IOAPIC PCIINT GENERIC SPI USB MMIO LPC ESPI FW_CONFIG_TABLE FW_CONFIG_FIELD FW_CONFIG_OPTION FW_CONFIG_PROBE @@ -116,7 +117,7 @@ fw_config_field: FW_CONFIG_FIELD STRING { /* option <value> */ fw_config_option: FW_CONFIG_OPTION STRING NUMBER /* == field value */ - { add_fw_config_option(cur_field, $<string>2, strtoul($<string>3, NULL, 0)); }; + { add_fw_config_option(cur_field, $<string>2, strtoull($<string>3, NULL, 0)); }; /* probe <field> <option> */ fw_config_probe: FW_CONFIG_PROBE STRING /* == field */ STRING /* == option */ |