From b2537bdad552443aba58bda7c42af1f039a58c94 Mon Sep 17 00:00:00 2001 From: Jianjun Wang Date: Fri, 8 Apr 2022 16:57:28 +0800 Subject: coreboot_tables: Replace 'struct lb_uint64' with lb_uint64_t Replace 'struct lb_uint64' with 'typedef __aligned(4) uint64_t lb_uint64_t', and remove unpack_lb64/pack_lb64 functions since it's no longer needed. Also replace 'struct cbuint64' with 'cb_uint64_t' and remove 'cb_unpack64' in libpayload for compatible with lb_uint64_t. Signed-off-by: Jianjun Wang Change-Id: If6b037e4403a8000625f4a5fb8d20311fe76200a Reviewed-on: https://review.coreboot.org/c/coreboot/+/63494 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- payloads/coreinfo/coreboot_module.c | 6 +-- payloads/libpayload/include/coreboot_tables.h | 32 +++++-------- payloads/libpayload/libc/coreboot.c | 12 ++--- src/commonlib/include/commonlib/coreboot_tables.h | 56 +++++++---------------- src/lib/bootmem.c | 4 +- src/lib/coreboot_table.c | 4 +- tests/lib/bootmem-test.c | 4 +- tests/lib/coreboot_table-test.c | 20 ++++---- util/cbmem/cbmem.c | 2 +- util/nvramtool/coreboot_tables.h | 32 ++----------- util/nvramtool/lbtable.c | 4 +- 11 files changed, 59 insertions(+), 117 deletions(-) diff --git a/payloads/coreinfo/coreboot_module.c b/payloads/coreinfo/coreboot_module.c index 87032d599079..2c165e12c5d6 100644 --- a/payloads/coreinfo/coreboot_module.c +++ b/payloads/coreinfo/coreboot_module.c @@ -94,10 +94,8 @@ static int coreboot_module_redraw(WINDOW *win) mvwprintw(win, row++, 3, " Table: "); } - wprintw(win, "%16.16llx - %16.16llx", - cb_unpack64(cb_info.range[i].start), - cb_unpack64(cb_info.range[i].start) + - cb_unpack64(cb_info.range[i].size) - 1); + wprintw(win, "%16.16llx - %16.16llx", cb_info.range[i].start, + cb_info.range[i].start + cb_info.range[i].size - 1); } return 0; diff --git a/payloads/libpayload/include/coreboot_tables.h b/payloads/libpayload/include/coreboot_tables.h index bd23d34c837a..1d38c19a80f1 100644 --- a/payloads/libpayload/include/coreboot_tables.h +++ b/payloads/libpayload/include/coreboot_tables.h @@ -91,10 +91,7 @@ enum { CB_TAG_OPTION_CHECKSUM = 0x00cc, }; -struct cbuint64 { - u32 lo; - u32 hi; -}; +typedef __aligned(4) uint64_t cb_uint64_t; struct cb_header { u8 signature[4]; @@ -111,8 +108,8 @@ struct cb_record { }; struct cb_memory_range { - struct cbuint64 start; - struct cbuint64 size; + cb_uint64_t start; + cb_uint64_t size; u32 type; }; @@ -271,14 +268,14 @@ struct cb_gpios { struct lb_range { uint32_t tag; uint32_t size; - uint64_t range_start; + cb_uint64_t range_start; uint32_t range_size; }; struct cb_cbmem_tab { uint32_t tag; uint32_t size; - uint64_t cbmem_tab; + cb_uint64_t cbmem_tab; }; struct cb_x86_rom_mtrr { @@ -316,10 +313,10 @@ struct cb_boot_media_params { uint32_t tag; uint32_t size; /* offsets are relative to start of boot media */ - uint64_t fmap_offset; - uint64_t cbfs_offset; - uint64_t cbfs_size; - uint64_t boot_media_size; + cb_uint64_t fmap_offset; + cb_uint64_t cbfs_offset; + cb_uint64_t cbfs_size; + cb_uint64_t boot_media_size; }; @@ -327,7 +324,7 @@ struct cb_cbmem_entry { uint32_t tag; uint32_t size; - uint64_t address; + cb_uint64_t address; uint32_t entry_size; uint32_t id; }; @@ -369,7 +366,7 @@ struct cb_board_config { uint32_t tag; uint32_t size; - struct cbuint64 fw_config; + cb_uint64_t fw_config; uint32_t board_id; uint32_t ram_code; uint32_t sku_id; @@ -429,17 +426,12 @@ struct cb_cmos_checksum { struct cb_acpi_rsdp { uint32_t tag; uint32_t size; - struct cbuint64 rsdp_pointer; /* Address of the ACPI RSDP */ + cb_uint64_t rsdp_pointer; /* Address of the ACPI RSDP */ }; /* Helpful inlines */ -static inline u64 cb_unpack64(struct cbuint64 val) -{ - return (((u64) val.hi) << 32) | val.lo; -} - static inline u16 cb_checksum(const void *ptr, unsigned len) { return ipchksum(ptr, len); diff --git a/payloads/libpayload/libc/coreboot.c b/payloads/libpayload/libc/coreboot.c index 2474df96fa38..cdd6a437b683 100644 --- a/payloads/libpayload/libc/coreboot.c +++ b/payloads/libpayload/libc/coreboot.c @@ -61,12 +61,8 @@ static void cb_parse_memory(void *ptr, struct sysinfo_t *info) continue; #endif - info->memrange[info->n_memranges].base = - cb_unpack64(range->start); - - info->memrange[info->n_memranges].size = - cb_unpack64(range->size); - + info->memrange[info->n_memranges].base = range->start; + info->memrange[info->n_memranges].size = range->size; info->memrange[info->n_memranges].type = range->type; info->n_memranges++; @@ -121,7 +117,7 @@ static void cb_parse_mac_addresses(unsigned char *ptr, static void cb_parse_board_config(unsigned char *ptr, struct sysinfo_t *info) { struct cb_board_config *const config = (struct cb_board_config *)ptr; - info->fw_config = cb_unpack64(config->fw_config); + info->fw_config = config->fw_config; info->board_id = config->board_id; info->ram_code = config->ram_code; info->sku_id = config->sku_id; @@ -271,7 +267,7 @@ static void cb_parse_cbmem_entry(void *ptr, struct sysinfo_t *info) static void cb_parse_rsdp(void *ptr, struct sysinfo_t *info) { const struct cb_acpi_rsdp *cb_acpi_rsdp = ptr; - info->acpi_rsdp = cb_unpack64(cb_acpi_rsdp->rsdp_pointer); + info->acpi_rsdp = cb_acpi_rsdp->rsdp_pointer; } int cb_parse_header(void *addr, int len, struct sysinfo_t *info) diff --git a/src/commonlib/include/commonlib/coreboot_tables.h b/src/commonlib/include/commonlib/coreboot_tables.h index 01b12f3a4874..206ddb4558e1 100644 --- a/src/commonlib/include/commonlib/coreboot_tables.h +++ b/src/commonlib/include/commonlib/coreboot_tables.h @@ -99,33 +99,11 @@ enum { * 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 + * lb_uint64_t will keep 64bit coreboot table values aligned to 32bit + * to ensure compatibility. */ -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 +126,8 @@ struct lb_record { }; 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 */ @@ -169,7 +147,7 @@ struct lb_memory { struct lb_hwrpb { uint32_t tag; uint32_t size; - uint64_t hwrpb; + lb_uint64_t hwrpb; }; struct lb_mainboard { @@ -237,7 +215,7 @@ struct lb_console { struct lb_forward { uint32_t tag; uint32_t size; - uint64_t forward; + lb_uint64_t forward; }; /** @@ -295,7 +273,7 @@ struct lb_framebuffer { uint32_t tag; uint32_t size; - uint64_t physical_address; + lb_uint64_t physical_address; uint32_t x_resolution; uint32_t y_resolution; uint32_t bytes_per_line; @@ -333,7 +311,7 @@ struct lb_range { uint32_t tag; uint32_t size; - uint64_t range_start; + lb_uint64_t range_start; uint32_t range_size; }; @@ -343,7 +321,7 @@ struct lb_cbmem_ref { uint32_t tag; uint32_t size; - uint64_t cbmem_addr; + lb_uint64_t cbmem_addr; }; struct lb_x86_rom_mtrr { @@ -379,10 +357,10 @@ struct lb_boot_media_params { uint32_t tag; uint32_t size; /* offsets are relative to start of boot media */ - uint64_t fmap_offset; - uint64_t cbfs_offset; - uint64_t cbfs_size; - uint64_t boot_media_size; + lb_uint64_t fmap_offset; + lb_uint64_t cbfs_offset; + lb_uint64_t cbfs_size; + lb_uint64_t boot_media_size; }; /* @@ -392,7 +370,7 @@ struct lb_cbmem_entry { uint32_t tag; uint32_t size; - uint64_t address; + lb_uint64_t address; uint32_t entry_size; uint32_t id; }; @@ -461,7 +439,7 @@ struct lb_board_config { 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 +561,7 @@ struct lb_tpm_physical_presence { 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 e9d4287d2155..d4462d88b43f 100644 --- a/src/lib/bootmem.c +++ b/src/lib/bootmem.c @@ -110,8 +110,8 @@ void bootmem_write_memory_table(struct lb_memory *mem) 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 3ceab3746f7d..c29d3081b5e1 100644 --- a/src/lib/coreboot_table.c +++ b/src/lib/coreboot_table.c @@ -313,7 +313,7 @@ static struct lb_board_config *lb_board_config(struct lb_header *header) 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 @@ static void lb_add_acpi_rsdp(struct lb_header *head) 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 ddd62ae6ef60..7bdbf0d31093 100644 --- a/tests/lib/bootmem-test.c +++ b/tests/lib/bootmem-test.c @@ -177,8 +177,8 @@ static void test_bootmem_write_mem_table(void **state) 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 a50dd15d085b..2bf1f61da024 100644 --- a/tests/lib/coreboot_table-test.c +++ b/tests/lib/coreboot_table-test.c @@ -229,8 +229,8 @@ void bootmem_write_memory_table(struct lb_memory *mem) /* 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 @@ static void test_write_tables(void **state) 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 @@ static void test_write_tables(void **state) 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 @@ static void test_write_tables(void **state) 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 8add6ec26164..3af8a25020c2 100644 --- a/util/cbmem/cbmem.c +++ b/util/cbmem/cbmem.c @@ -1016,7 +1016,7 @@ static void dump_cbmem_hex(void) 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 1417c19ba1dc..aafeab4964f4 100644 --- a/util/nvramtool/coreboot_tables.h +++ b/util/nvramtool/coreboot_tables.h @@ -45,33 +45,11 @@ * 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 + * lb_uint64_t will keep 64bit coreboot table values aligned to 32bit + * to ensure compatibility. */ -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 __attribute__((aligned(4))) uint64_t lb_uint64_t; struct lb_header { union { @@ -101,8 +79,8 @@ struct lb_record { #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 fd6c9ec1d6d3..6993cc0ce5d2 100644 --- a/util/nvramtool/lbtable.c +++ b/util/nvramtool/lbtable.c @@ -632,8 +632,8 @@ static void memory_print_fn(const struct lb_record *rec) 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 -- cgit v1.2.3