Attention is currently required from: Jakub Czapiga. Jianjun Wang has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/63494 )
Change subject: coreboot_tables: Convert 'struct lb_uint64' to lb_uint64_t ......................................................................
coreboot_tables: Convert 'struct lb_uint64' to lb_uint64_t
Convert 'struct lb_uint64' to 'typedef __aligned(4) uint64_t lb_uint64_t', and remove unpack_lb64/pack_lb64 functions since it's no longer needed.
Signed-off-by: Jianjun Wang jianjun.wang@mediatek.com Change-Id: If6b037e4403a8000625f4a5fb8d20311fe76200a --- M src/commonlib/include/commonlib/coreboot_tables.h M src/lib/bootmem.c M src/lib/coreboot_table.c M tests/lib/bootmem-test.c M tests/lib/coreboot_table-test.c M util/cbmem/cbmem.c M util/nvramtool/coreboot_tables.h M util/nvramtool/lbtable.c 8 files changed, 27 insertions(+), 89 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/94/63494/1
diff --git a/src/commonlib/include/commonlib/coreboot_tables.h b/src/commonlib/include/commonlib/coreboot_tables.h index 01b12f3..4b3a1f8 100644 --- a/src/commonlib/include/commonlib/coreboot_tables.h +++ b/src/commonlib/include/commonlib/coreboot_tables.h @@ -94,38 +94,7 @@ LB_TAG_OPTION_CHECKSUM = 0x00cc, };
-/* Since coreboot is usually compiled 32bit, gcc will align 64bit - * types to 32bit boundaries. If the coreboot table is dumped on a - * 64bit system, a uint64_t would be aligned to 64bit boundaries, - * breaking the table format. - * - * lb_uint64 will keep 64bit coreboot table values aligned to 32bit - * to ensure compatibility. They can be accessed with the two functions - * below: unpack_lb64() and pack_lb64() - * - * See also: util/lbtdump/lbtdump.c - */ - -struct lb_uint64 { - uint32_t lo; - uint32_t hi; -}; - -static inline uint64_t unpack_lb64(struct lb_uint64 value) -{ - uint64_t result; - result = value.hi; - result = (result << 32) + value.lo; - return result; -} - -static inline struct lb_uint64 pack_lb64(uint64_t value) -{ - struct lb_uint64 result; - result.lo = (value >> 0) & 0xffffffff; - result.hi = (value >> 32) & 0xffffffff; - return result; -} +typedef __aligned(4) uint64_t lb_uint64_t;
struct lb_header { uint8_t signature[4]; /* LBIO */ @@ -148,8 +117,8 @@ };
struct lb_memory_range { - struct lb_uint64 start; - struct lb_uint64 size; + lb_uint64_t start; + lb_uint64_t size; uint32_t type; #define LB_MEM_RAM 1 /* Memory anyone can use */ #define LB_MEM_RESERVED 2 /* Don't use this memory region */ @@ -461,7 +430,7 @@ uint32_t tag; uint32_t size;
- struct lb_uint64 fw_config; + lb_uint64_t fw_config; uint32_t board_id; uint32_t ram_code; uint32_t sku_id; @@ -583,7 +552,7 @@ struct lb_acpi_rsdp { uint32_t tag; uint32_t size; - struct lb_uint64 rsdp_pointer; /* Address of the ACPI RSDP */ + lb_uint64_t rsdp_pointer; /* Address of the ACPI RSDP */ };
#endif diff --git a/src/lib/bootmem.c b/src/lib/bootmem.c index e9d4287..d4462d8 100644 --- a/src/lib/bootmem.c +++ b/src/lib/bootmem.c @@ -110,8 +110,8 @@ bootmem_dump_ranges();
memranges_each_entry(r, &bootmem_os) { - lb_r->start = pack_lb64(range_entry_base(r)); - lb_r->size = pack_lb64(range_entry_size(r)); + lb_r->start = range_entry_base(r); + lb_r->size = range_entry_size(r); lb_r->type = bootmem_to_lb_tag(range_entry_tag(r));
lb_r++; diff --git a/src/lib/coreboot_table.c b/src/lib/coreboot_table.c index 3ceab37..c29d308 100644 --- a/src/lib/coreboot_table.c +++ b/src/lib/coreboot_table.c @@ -313,7 +313,7 @@ config->board_id = board_id(); config->ram_code = ram_code(); config->sku_id = sku_id(); - config->fw_config = pack_lb64(fw_config); + config->fw_config = fw_config;
if (config->board_id != UNDEFINED_STRAPPING_ID) printk(BIOS_INFO, "Board ID: %d\n", config->board_id); @@ -428,7 +428,7 @@ acpi_rsdp = (struct lb_acpi_rsdp *)rec; acpi_rsdp->tag = LB_TAG_ACPI_RSDP; acpi_rsdp->size = sizeof(*acpi_rsdp); - acpi_rsdp->rsdp_pointer = pack_lb64(get_coreboot_rsdp()); + acpi_rsdp->rsdp_pointer = get_coreboot_rsdp(); }
size_t write_coreboot_forwarding_table(uintptr_t entry, uintptr_t target) diff --git a/tests/lib/bootmem-test.c b/tests/lib/bootmem-test.c index ddd62ae..7bdbf0d 100644 --- a/tests/lib/bootmem-test.c +++ b/tests/lib/bootmem-test.c @@ -177,8 +177,8 @@ required_unused_space_size);
for (i = 0; i < lb_mem->size / sizeof(struct lb_memory_range); i++) { - assert_int_equal(unpack_lb64(lb_mem->map[i].start), os_ranges[i].start); - assert_int_equal(unpack_lb64(lb_mem->map[i].size), os_ranges[i].size); + assert_int_equal(lb_mem->map[i].start, os_ranges[i].start); + assert_int_equal(lb_mem->map[i].size, os_ranges[i].size); assert_int_equal(lb_mem->map[i].type, bootmem_to_lb_tag(os_ranges[i].type)); }
diff --git a/tests/lib/coreboot_table-test.c b/tests/lib/coreboot_table-test.c index a50dd15..2bf1f61 100644 --- a/tests/lib/coreboot_table-test.c +++ b/tests/lib/coreboot_table-test.c @@ -229,8 +229,8 @@ /* Insert entries for testing */ for (i = 0; i < ARRAY_SIZE(mock_bootmem_ranges); ++i) { struct resource *res = &mock_bootmem_ranges[i]; - lb_r->start = pack_lb64(res->base); - lb_r->size = pack_lb64(res->size); + lb_r->start = res->base; + lb_r->size = res->size; lb_r->type = res->flags; lb_r++; mem->size += sizeof(struct lb_memory_range); @@ -362,18 +362,18 @@ const struct lb_memory *memory = (struct lb_memory *)record; const struct lb_memory_range *range; const struct resource *res; - struct lb_uint64 value; + lb_uint64_t value;
for (int i = 0; i < ARRAY_SIZE(mock_bootmem_ranges); ++i) { res = &mock_bootmem_ranges[i]; range = &memory->map[i];
- value = pack_lb64(res->base); + value = res->base; assert_memory_equal(&value, &range->start, - sizeof(struct lb_uint64)); - value = pack_lb64(res->size); + sizeof(lb_uint64_t)); + value = res->size; assert_memory_equal(&value, &range->size, - sizeof(struct lb_uint64)); + sizeof(lb_uint64_t)); assert_int_equal(range->type, res->flags); } break; @@ -475,9 +475,9 @@
const struct lb_board_config *board_config = (struct lb_board_config *)record; - const struct lb_uint64 expected_fw_version = pack_lb64(fw_config_get()); + const lb_uint64_t expected_fw_version = fw_config_get(); assert_memory_equal(&expected_fw_version, &board_config->fw_config, - sizeof(struct lb_uint64)); + sizeof(lb_uint64_t)); assert_int_equal(board_id(), board_config->board_id); assert_int_equal(ram_code(), board_config->ram_code); assert_int_equal(sku_id(), board_config->sku_id); @@ -486,7 +486,7 @@ assert_int_equal(sizeof(struct lb_acpi_rsdp), record->size);
const struct lb_acpi_rsdp *acpi_rsdp = (struct lb_acpi_rsdp *)record; - assert_int_equal(ebda_base, unpack_lb64(acpi_rsdp->rsdp_pointer)); + assert_int_equal(ebda_base, acpi_rsdp->rsdp_pointer); break; default: fail_msg("Unexpected tag found in record. Tag ID: 0x%x", record->tag); diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c index 0fd69d6..c9b46a8 100644 --- a/util/cbmem/cbmem.c +++ b/util/cbmem/cbmem.c @@ -927,7 +927,7 @@ return; }
- hexdump(unpack_lb64(cbmem.start), unpack_lb64(cbmem.size)); + hexdump(cbmem.start, cbmem.size); }
static void rawdump(uint64_t base, uint64_t size) diff --git a/util/nvramtool/coreboot_tables.h b/util/nvramtool/coreboot_tables.h index 1417c19..aa0ee97 100644 --- a/util/nvramtool/coreboot_tables.h +++ b/util/nvramtool/coreboot_tables.h @@ -40,38 +40,7 @@ * table entries and be backwards compatible, but it is not required. */
-/* Since coreboot is usually compiled 32bit, gcc will align 64bit - * types to 32bit boundaries. If the coreboot table is dumped on a - * 64bit system, a uint64_t would be aligned to 64bit boundaries, - * breaking the table format. - * - * lb_uint64 will keep 64bit coreboot table values aligned to 32bit - * to ensure compatibility. They can be accessed with the two functions - * below: unpack_lb64() and pack_lb64() - * - * See also: util/lbtdump/lbtdump.c - */ - -struct lb_uint64 { - uint32_t lo; - uint32_t hi; -}; - -static inline uint64_t unpack_lb64(struct lb_uint64 value) -{ - uint64_t result; - result = value.hi; - result = (result << 32) + value.lo; - return result; -} - -static inline struct lb_uint64 pack_lb64(uint64_t value) -{ - struct lb_uint64 result; - result.lo = (value >> 0) & 0xffffffff; - result.hi = (value >> 32) & 0xffffffff; - return result; -} +typedef __aligned(4) uint64_t lb_uint64_t;
struct lb_header { union { @@ -101,8 +70,8 @@ #define LB_TAG_MEMORY 0x0001
struct lb_memory_range { - struct lb_uint64 start; - struct lb_uint64 size; + lb_uint64_t start; + lb_uint64_t size; uint32_t type; #define LB_MEM_RAM 1 /* Memory anyone can use */ #define LB_MEM_RESERVED 2 /* Don't use this memory region */ diff --git a/util/nvramtool/lbtable.c b/util/nvramtool/lbtable.c index fd6c9ec..6993cc0 100644 --- a/util/nvramtool/lbtable.c +++ b/util/nvramtool/lbtable.c @@ -632,8 +632,8 @@ break; }
- size = unpack_lb64(ranges[i].size); - start = unpack_lb64(ranges[i].start); + size = ranges[i].size; + start = ranges[i].start; end = start + size - 1; printf("%s memory:\n" " from physical addresses 0x%016" PRIx64