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 <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>
This commit is contained in:
		@@ -94,10 +94,8 @@ static int coreboot_module_redraw(WINDOW *win)
 | 
				
			|||||||
			mvwprintw(win, row++, 3, "   Table: ");
 | 
								mvwprintw(win, row++, 3, "   Table: ");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		wprintw(win, "%16.16llx - %16.16llx",
 | 
							wprintw(win, "%16.16llx - %16.16llx", cb_info.range[i].start,
 | 
				
			||||||
			cb_unpack64(cb_info.range[i].start),
 | 
								cb_info.range[i].start + cb_info.range[i].size - 1);
 | 
				
			||||||
			cb_unpack64(cb_info.range[i].start) +
 | 
					 | 
				
			||||||
			cb_unpack64(cb_info.range[i].size) - 1);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -91,10 +91,7 @@ enum {
 | 
				
			|||||||
	CB_TAG_OPTION_CHECKSUM		= 0x00cc,
 | 
						CB_TAG_OPTION_CHECKSUM		= 0x00cc,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cbuint64 {
 | 
					typedef __aligned(4) uint64_t cb_uint64_t;
 | 
				
			||||||
	u32 lo;
 | 
					 | 
				
			||||||
	u32 hi;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cb_header {
 | 
					struct cb_header {
 | 
				
			||||||
	u8 signature[4];
 | 
						u8 signature[4];
 | 
				
			||||||
@@ -111,8 +108,8 @@ struct cb_record {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cb_memory_range {
 | 
					struct cb_memory_range {
 | 
				
			||||||
	struct cbuint64 start;
 | 
						cb_uint64_t start;
 | 
				
			||||||
	struct cbuint64 size;
 | 
						cb_uint64_t size;
 | 
				
			||||||
	u32 type;
 | 
						u32 type;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -271,14 +268,14 @@ struct cb_gpios {
 | 
				
			|||||||
struct lb_range {
 | 
					struct lb_range {
 | 
				
			||||||
	uint32_t tag;
 | 
						uint32_t tag;
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
	uint64_t range_start;
 | 
						cb_uint64_t range_start;
 | 
				
			||||||
	uint32_t range_size;
 | 
						uint32_t range_size;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cb_cbmem_tab {
 | 
					struct cb_cbmem_tab {
 | 
				
			||||||
	uint32_t tag;
 | 
						uint32_t tag;
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
	uint64_t cbmem_tab;
 | 
						cb_uint64_t cbmem_tab;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cb_x86_rom_mtrr {
 | 
					struct cb_x86_rom_mtrr {
 | 
				
			||||||
@@ -316,10 +313,10 @@ struct cb_boot_media_params {
 | 
				
			|||||||
	uint32_t tag;
 | 
						uint32_t tag;
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
	/* offsets are relative to start of boot media */
 | 
						/* offsets are relative to start of boot media */
 | 
				
			||||||
	uint64_t fmap_offset;
 | 
						cb_uint64_t fmap_offset;
 | 
				
			||||||
	uint64_t cbfs_offset;
 | 
						cb_uint64_t cbfs_offset;
 | 
				
			||||||
	uint64_t cbfs_size;
 | 
						cb_uint64_t cbfs_size;
 | 
				
			||||||
	uint64_t boot_media_size;
 | 
						cb_uint64_t boot_media_size;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -327,7 +324,7 @@ struct cb_cbmem_entry {
 | 
				
			|||||||
	uint32_t tag;
 | 
						uint32_t tag;
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint64_t address;
 | 
						cb_uint64_t address;
 | 
				
			||||||
	uint32_t entry_size;
 | 
						uint32_t entry_size;
 | 
				
			||||||
	uint32_t id;
 | 
						uint32_t id;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@@ -369,7 +366,7 @@ struct cb_board_config {
 | 
				
			|||||||
	uint32_t tag;
 | 
						uint32_t tag;
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct cbuint64 fw_config;
 | 
						cb_uint64_t fw_config;
 | 
				
			||||||
	uint32_t board_id;
 | 
						uint32_t board_id;
 | 
				
			||||||
	uint32_t ram_code;
 | 
						uint32_t ram_code;
 | 
				
			||||||
	uint32_t sku_id;
 | 
						uint32_t sku_id;
 | 
				
			||||||
@@ -429,17 +426,12 @@ struct	cb_cmos_checksum {
 | 
				
			|||||||
struct cb_acpi_rsdp {
 | 
					struct cb_acpi_rsdp {
 | 
				
			||||||
	uint32_t tag;
 | 
						uint32_t tag;
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
	struct cbuint64 rsdp_pointer; /* Address of the ACPI RSDP */
 | 
						cb_uint64_t rsdp_pointer; /* Address of the ACPI RSDP */
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Helpful inlines */
 | 
					/* 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)
 | 
					static inline u16 cb_checksum(const void *ptr, unsigned len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return ipchksum(ptr, len);
 | 
						return ipchksum(ptr, len);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -61,12 +61,8 @@ static void cb_parse_memory(void *ptr, struct sysinfo_t *info)
 | 
				
			|||||||
			continue;
 | 
								continue;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		info->memrange[info->n_memranges].base =
 | 
							info->memrange[info->n_memranges].base = range->start;
 | 
				
			||||||
		    cb_unpack64(range->start);
 | 
							info->memrange[info->n_memranges].size = range->size;
 | 
				
			||||||
 | 
					 | 
				
			||||||
		info->memrange[info->n_memranges].size =
 | 
					 | 
				
			||||||
		    cb_unpack64(range->size);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		info->memrange[info->n_memranges].type = range->type;
 | 
							info->memrange[info->n_memranges].type = range->type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		info->n_memranges++;
 | 
							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)
 | 
					static void cb_parse_board_config(unsigned char *ptr, struct sysinfo_t *info)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct cb_board_config *const config = (struct cb_board_config *)ptr;
 | 
						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->board_id = config->board_id;
 | 
				
			||||||
	info->ram_code = config->ram_code;
 | 
						info->ram_code = config->ram_code;
 | 
				
			||||||
	info->sku_id = config->sku_id;
 | 
						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)
 | 
					static void cb_parse_rsdp(void *ptr, struct sysinfo_t *info)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const struct cb_acpi_rsdp *cb_acpi_rsdp = ptr;
 | 
						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)
 | 
					int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -99,33 +99,11 @@ enum {
 | 
				
			|||||||
 * 64bit system, a uint64_t would be aligned to 64bit boundaries,
 | 
					 * 64bit system, a uint64_t would be aligned to 64bit boundaries,
 | 
				
			||||||
 * breaking the table format.
 | 
					 * breaking the table format.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * lb_uint64 will keep 64bit coreboot table values aligned to 32bit
 | 
					 * lb_uint64_t will keep 64bit coreboot table values aligned to 32bit
 | 
				
			||||||
 * to ensure compatibility. They can be accessed with the two functions
 | 
					 * to ensure compatibility.
 | 
				
			||||||
 * below: unpack_lb64() and pack_lb64()
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * See also: util/lbtdump/lbtdump.c
 | 
					 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct lb_uint64 {
 | 
					typedef __aligned(4) uint64_t lb_uint64_t;
 | 
				
			||||||
	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;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct lb_header {
 | 
					struct lb_header {
 | 
				
			||||||
	uint8_t  signature[4]; /* LBIO */
 | 
						uint8_t  signature[4]; /* LBIO */
 | 
				
			||||||
@@ -148,8 +126,8 @@ struct lb_record {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct lb_memory_range {
 | 
					struct lb_memory_range {
 | 
				
			||||||
	struct lb_uint64 start;
 | 
						lb_uint64_t start;
 | 
				
			||||||
	struct lb_uint64 size;
 | 
						lb_uint64_t size;
 | 
				
			||||||
	uint32_t type;
 | 
						uint32_t type;
 | 
				
			||||||
#define LB_MEM_RAM		 1	/* Memory anyone can use */
 | 
					#define LB_MEM_RAM		 1	/* Memory anyone can use */
 | 
				
			||||||
#define LB_MEM_RESERVED		 2	/* Don't use this memory region */
 | 
					#define LB_MEM_RESERVED		 2	/* Don't use this memory region */
 | 
				
			||||||
@@ -169,7 +147,7 @@ struct lb_memory {
 | 
				
			|||||||
struct lb_hwrpb {
 | 
					struct lb_hwrpb {
 | 
				
			||||||
	uint32_t tag;
 | 
						uint32_t tag;
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
	uint64_t hwrpb;
 | 
						lb_uint64_t hwrpb;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct lb_mainboard {
 | 
					struct lb_mainboard {
 | 
				
			||||||
@@ -237,7 +215,7 @@ struct lb_console {
 | 
				
			|||||||
struct lb_forward {
 | 
					struct lb_forward {
 | 
				
			||||||
	uint32_t tag;
 | 
						uint32_t tag;
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
	uint64_t forward;
 | 
						lb_uint64_t forward;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@@ -295,7 +273,7 @@ struct lb_framebuffer {
 | 
				
			|||||||
	uint32_t tag;
 | 
						uint32_t tag;
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint64_t physical_address;
 | 
						lb_uint64_t physical_address;
 | 
				
			||||||
	uint32_t x_resolution;
 | 
						uint32_t x_resolution;
 | 
				
			||||||
	uint32_t y_resolution;
 | 
						uint32_t y_resolution;
 | 
				
			||||||
	uint32_t bytes_per_line;
 | 
						uint32_t bytes_per_line;
 | 
				
			||||||
@@ -333,7 +311,7 @@ struct lb_range {
 | 
				
			|||||||
	uint32_t tag;
 | 
						uint32_t tag;
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint64_t range_start;
 | 
						lb_uint64_t range_start;
 | 
				
			||||||
	uint32_t range_size;
 | 
						uint32_t range_size;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -343,7 +321,7 @@ struct lb_cbmem_ref {
 | 
				
			|||||||
	uint32_t tag;
 | 
						uint32_t tag;
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint64_t cbmem_addr;
 | 
						lb_uint64_t cbmem_addr;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct lb_x86_rom_mtrr {
 | 
					struct lb_x86_rom_mtrr {
 | 
				
			||||||
@@ -379,10 +357,10 @@ struct lb_boot_media_params {
 | 
				
			|||||||
	uint32_t tag;
 | 
						uint32_t tag;
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
	/* offsets are relative to start of boot media */
 | 
						/* offsets are relative to start of boot media */
 | 
				
			||||||
	uint64_t fmap_offset;
 | 
						lb_uint64_t fmap_offset;
 | 
				
			||||||
	uint64_t cbfs_offset;
 | 
						lb_uint64_t cbfs_offset;
 | 
				
			||||||
	uint64_t cbfs_size;
 | 
						lb_uint64_t cbfs_size;
 | 
				
			||||||
	uint64_t boot_media_size;
 | 
						lb_uint64_t boot_media_size;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@@ -392,7 +370,7 @@ struct lb_cbmem_entry {
 | 
				
			|||||||
	uint32_t tag;
 | 
						uint32_t tag;
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint64_t address;
 | 
						lb_uint64_t address;
 | 
				
			||||||
	uint32_t entry_size;
 | 
						uint32_t entry_size;
 | 
				
			||||||
	uint32_t id;
 | 
						uint32_t id;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@@ -461,7 +439,7 @@ struct lb_board_config {
 | 
				
			|||||||
	uint32_t tag;
 | 
						uint32_t tag;
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct lb_uint64 fw_config;
 | 
						lb_uint64_t fw_config;
 | 
				
			||||||
	uint32_t board_id;
 | 
						uint32_t board_id;
 | 
				
			||||||
	uint32_t ram_code;
 | 
						uint32_t ram_code;
 | 
				
			||||||
	uint32_t sku_id;
 | 
						uint32_t sku_id;
 | 
				
			||||||
@@ -583,7 +561,7 @@ struct lb_tpm_physical_presence {
 | 
				
			|||||||
struct lb_acpi_rsdp {
 | 
					struct lb_acpi_rsdp {
 | 
				
			||||||
	uint32_t tag;
 | 
						uint32_t tag;
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
	struct lb_uint64 rsdp_pointer; /* Address of the ACPI RSDP */
 | 
						lb_uint64_t rsdp_pointer; /* Address of the ACPI RSDP */
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -110,8 +110,8 @@ void bootmem_write_memory_table(struct lb_memory *mem)
 | 
				
			|||||||
	bootmem_dump_ranges();
 | 
						bootmem_dump_ranges();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memranges_each_entry(r, &bootmem_os) {
 | 
						memranges_each_entry(r, &bootmem_os) {
 | 
				
			||||||
		lb_r->start = pack_lb64(range_entry_base(r));
 | 
							lb_r->start = range_entry_base(r);
 | 
				
			||||||
		lb_r->size = pack_lb64(range_entry_size(r));
 | 
							lb_r->size = range_entry_size(r);
 | 
				
			||||||
		lb_r->type = bootmem_to_lb_tag(range_entry_tag(r));
 | 
							lb_r->type = bootmem_to_lb_tag(range_entry_tag(r));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		lb_r++;
 | 
							lb_r++;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -313,7 +313,7 @@ static struct lb_board_config *lb_board_config(struct lb_header *header)
 | 
				
			|||||||
	config->board_id = board_id();
 | 
						config->board_id = board_id();
 | 
				
			||||||
	config->ram_code = ram_code();
 | 
						config->ram_code = ram_code();
 | 
				
			||||||
	config->sku_id = sku_id();
 | 
						config->sku_id = sku_id();
 | 
				
			||||||
	config->fw_config = pack_lb64(fw_config);
 | 
						config->fw_config = fw_config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (config->board_id != UNDEFINED_STRAPPING_ID)
 | 
						if (config->board_id != UNDEFINED_STRAPPING_ID)
 | 
				
			||||||
		printk(BIOS_INFO, "Board ID: %d\n", config->board_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 = (struct lb_acpi_rsdp *)rec;
 | 
				
			||||||
	acpi_rsdp->tag = LB_TAG_ACPI_RSDP;
 | 
						acpi_rsdp->tag = LB_TAG_ACPI_RSDP;
 | 
				
			||||||
	acpi_rsdp->size = sizeof(*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)
 | 
					size_t write_coreboot_forwarding_table(uintptr_t entry, uintptr_t target)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -177,8 +177,8 @@ static void test_bootmem_write_mem_table(void **state)
 | 
				
			|||||||
			required_unused_space_size);
 | 
								required_unused_space_size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < lb_mem->size / sizeof(struct lb_memory_range); i++) {
 | 
						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(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].size, os_ranges[i].size);
 | 
				
			||||||
		assert_int_equal(lb_mem->map[i].type, bootmem_to_lb_tag(os_ranges[i].type));
 | 
							assert_int_equal(lb_mem->map[i].type, bootmem_to_lb_tag(os_ranges[i].type));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -229,8 +229,8 @@ void bootmem_write_memory_table(struct lb_memory *mem)
 | 
				
			|||||||
	/* Insert entries for testing */
 | 
						/* Insert entries for testing */
 | 
				
			||||||
	for (i = 0; i < ARRAY_SIZE(mock_bootmem_ranges); ++i) {
 | 
						for (i = 0; i < ARRAY_SIZE(mock_bootmem_ranges); ++i) {
 | 
				
			||||||
		struct resource *res = &mock_bootmem_ranges[i];
 | 
							struct resource *res = &mock_bootmem_ranges[i];
 | 
				
			||||||
		lb_r->start = pack_lb64(res->base);
 | 
							lb_r->start = res->base;
 | 
				
			||||||
		lb_r->size = pack_lb64(res->size);
 | 
							lb_r->size = res->size;
 | 
				
			||||||
		lb_r->type = res->flags;
 | 
							lb_r->type = res->flags;
 | 
				
			||||||
		lb_r++;
 | 
							lb_r++;
 | 
				
			||||||
		mem->size += sizeof(struct lb_memory_range);
 | 
							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 *memory = (struct lb_memory *)record;
 | 
				
			||||||
			const struct lb_memory_range *range;
 | 
								const struct lb_memory_range *range;
 | 
				
			||||||
			const struct resource *res;
 | 
								const struct resource *res;
 | 
				
			||||||
			struct lb_uint64 value;
 | 
								lb_uint64_t value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			for (int i = 0; i < ARRAY_SIZE(mock_bootmem_ranges); ++i) {
 | 
								for (int i = 0; i < ARRAY_SIZE(mock_bootmem_ranges); ++i) {
 | 
				
			||||||
				res = &mock_bootmem_ranges[i];
 | 
									res = &mock_bootmem_ranges[i];
 | 
				
			||||||
				range = &memory->map[i];
 | 
									range = &memory->map[i];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				value = pack_lb64(res->base);
 | 
									value = res->base;
 | 
				
			||||||
				assert_memory_equal(&value, &range->start,
 | 
									assert_memory_equal(&value, &range->start,
 | 
				
			||||||
						    sizeof(struct lb_uint64));
 | 
											    sizeof(lb_uint64_t));
 | 
				
			||||||
				value = pack_lb64(res->size);
 | 
									value = res->size;
 | 
				
			||||||
				assert_memory_equal(&value, &range->size,
 | 
									assert_memory_equal(&value, &range->size,
 | 
				
			||||||
						    sizeof(struct lb_uint64));
 | 
											    sizeof(lb_uint64_t));
 | 
				
			||||||
				assert_int_equal(range->type, res->flags);
 | 
									assert_int_equal(range->type, res->flags);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
@@ -475,9 +475,9 @@ static void test_write_tables(void **state)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			const struct lb_board_config *board_config =
 | 
								const struct lb_board_config *board_config =
 | 
				
			||||||
				(struct lb_board_config *)record;
 | 
									(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,
 | 
								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(board_id(), board_config->board_id);
 | 
				
			||||||
			assert_int_equal(ram_code(), board_config->ram_code);
 | 
								assert_int_equal(ram_code(), board_config->ram_code);
 | 
				
			||||||
			assert_int_equal(sku_id(), board_config->sku_id);
 | 
								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);
 | 
								assert_int_equal(sizeof(struct lb_acpi_rsdp), record->size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			const struct lb_acpi_rsdp *acpi_rsdp = (struct lb_acpi_rsdp *)record;
 | 
								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;
 | 
								break;
 | 
				
			||||||
		default:
 | 
							default:
 | 
				
			||||||
			fail_msg("Unexpected tag found in record. Tag ID: 0x%x", record->tag);
 | 
								fail_msg("Unexpected tag found in record. Tag ID: 0x%x", record->tag);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1016,7 +1016,7 @@ static void dump_cbmem_hex(void)
 | 
				
			|||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	hexdump(unpack_lb64(cbmem.start), unpack_lb64(cbmem.size));
 | 
						hexdump(cbmem.start, cbmem.size);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void rawdump(uint64_t base, uint64_t size)
 | 
					static void rawdump(uint64_t base, uint64_t size)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -45,33 +45,11 @@
 | 
				
			|||||||
 * 64bit system, a uint64_t would be aligned to 64bit boundaries,
 | 
					 * 64bit system, a uint64_t would be aligned to 64bit boundaries,
 | 
				
			||||||
 * breaking the table format.
 | 
					 * breaking the table format.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * lb_uint64 will keep 64bit coreboot table values aligned to 32bit
 | 
					 * lb_uint64_t will keep 64bit coreboot table values aligned to 32bit
 | 
				
			||||||
 * to ensure compatibility. They can be accessed with the two functions
 | 
					 * to ensure compatibility.
 | 
				
			||||||
 * below: unpack_lb64() and pack_lb64()
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * See also: util/lbtdump/lbtdump.c
 | 
					 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct lb_uint64 {
 | 
					typedef __attribute__((aligned(4))) uint64_t lb_uint64_t;
 | 
				
			||||||
	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;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct lb_header {
 | 
					struct lb_header {
 | 
				
			||||||
	union {
 | 
						union {
 | 
				
			||||||
@@ -101,8 +79,8 @@ struct lb_record {
 | 
				
			|||||||
#define LB_TAG_MEMORY		0x0001
 | 
					#define LB_TAG_MEMORY		0x0001
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct lb_memory_range {
 | 
					struct lb_memory_range {
 | 
				
			||||||
	struct lb_uint64 start;
 | 
						lb_uint64_t start;
 | 
				
			||||||
	struct lb_uint64 size;
 | 
						lb_uint64_t size;
 | 
				
			||||||
	uint32_t type;
 | 
						uint32_t type;
 | 
				
			||||||
#define LB_MEM_RAM	1	/* Memory anyone can use */
 | 
					#define LB_MEM_RAM	1	/* Memory anyone can use */
 | 
				
			||||||
#define LB_MEM_RESERVED	2	/* Don't use this memory region */
 | 
					#define LB_MEM_RESERVED	2	/* Don't use this memory region */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -632,8 +632,8 @@ static void memory_print_fn(const struct lb_record *rec)
 | 
				
			|||||||
			break;
 | 
								break;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		size = unpack_lb64(ranges[i].size);
 | 
							size = ranges[i].size;
 | 
				
			||||||
		start = unpack_lb64(ranges[i].start);
 | 
							start = ranges[i].start;
 | 
				
			||||||
		end = start + size - 1;
 | 
							end = start + size - 1;
 | 
				
			||||||
		printf("%s memory:\n"
 | 
							printf("%s memory:\n"
 | 
				
			||||||
		       "    from physical addresses 0x%016" PRIx64
 | 
							       "    from physical addresses 0x%016" PRIx64
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user