Skip to content

Commit

Permalink
coreboot_tables: Replace 'struct lb_uint64' with lb_uint64_t
Browse files Browse the repository at this point in the history
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 <jianjun.wang@mediatek.com>
Change-Id: If6b037e4403a8000625f4a5fb8d20311fe76200a
Reviewed-on: https://review.coreboot.org/c/coreboot/+/63494
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
  • Loading branch information
wang-jianjun authored and felixheld committed Apr 14, 2022
1 parent 6f023ec commit b2537bd
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 117 deletions.
6 changes: 2 additions & 4 deletions payloads/coreinfo/coreboot_module.c
Expand Up @@ -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;
Expand Down
32 changes: 12 additions & 20 deletions payloads/libpayload/include/coreboot_tables.h
Expand Up @@ -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];
Expand All @@ -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;
};

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -316,18 +313,18 @@ 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;
};


struct cb_cbmem_entry {
uint32_t tag;
uint32_t size;

uint64_t address;
cb_uint64_t address;
uint32_t entry_size;
uint32_t id;
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 4 additions & 8 deletions payloads/libpayload/libc/coreboot.c
Expand Up @@ -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++;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
56 changes: 17 additions & 39 deletions src/commonlib/include/commonlib/coreboot_tables.h
Expand Up @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 {
Expand Down Expand Up @@ -237,7 +215,7 @@ struct lb_console {
struct lb_forward {
uint32_t tag;
uint32_t size;
uint64_t forward;
lb_uint64_t forward;
};

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};

Expand All @@ -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 {
Expand Down Expand Up @@ -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;
};

/*
Expand All @@ -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;
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/lib/bootmem.c
Expand Up @@ -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++;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/coreboot_table.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/bootmem-test.c
Expand Up @@ -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));
}

Expand Down
20 changes: 10 additions & 10 deletions tests/lib/coreboot_table-test.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion util/cbmem/cbmem.c
Expand Up @@ -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)
Expand Down

0 comments on commit b2537bd

Please sign in to comment.