[coreboot-gerrit] Patch set updated for coreboot: riscv: fix up issues related to lb_tables

Ronald G. Minnich (rminnich@gmail.com) gerrit at coreboot.org
Mon Jan 16 07:43:14 CET 2017


Ronald G. Minnich (rminnich at gmail.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/18139

-gerrit

commit 2c06cf846747207d631d3571659014c85242bf35
Author: Ronald G. Minnich <rminnich at gmail.com>
Date:   Fri Jan 13 18:27:34 2017 -0800

    riscv: fix up issues related to lb_tables
    
    In the lb_tables code, some functions made a reasonable
    effort to align structs on reasonable boundaries,
    and others did not. Even the ones that did did not
    get it quite right, setting alignments to 32 bits, not
    64, such that riscv will still take alignment traps in
    a mode (M-mode) in which such traps are fatal.
    
    Change lb_new_record to take a tag and size parameter.
    This further removes the need for each function to assign
    tag and size to the record. And, it lets the allocator
    (lb_new_record) get some idea of the final size. Most
    importantly, it lets the allocator ensure that entities
    are 128-bit aligned, and hence future proof for
    128-bit processors (and note that the rv128 qemu
    implementation is already available).
    
    This gets me back up to a shell prompt on harvey on the
    lowriscv, where before we would fail with an alignment trap in
    coreboot.
    
    Change-Id: Id683fe2baa8cbea9abfccab72cf66a44fc04429e
    Signed-off-by: Ronald G. Minnich <rminnich at gmail.com>
---
 src/arch/x86/cpu.c                             |   5 +-
 src/drivers/intel/fsp1_1/fsp_gop.c             |   8 +-
 src/drivers/intel/fsp2_0/graphics.c            |   7 +-
 src/drivers/spi/spi_flash.c                    |   7 +-
 src/include/boot/coreboot_tables.h             |   4 +-
 src/lib/coreboot_table.c                       | 119 ++++++++++++-------------
 src/lib/imd_cbmem.c                            |   6 +-
 src/mainboard/google/daisy/mainboard.c         |   5 +-
 src/mainboard/google/gale/mainboard.c          |   5 +-
 src/mainboard/google/nyan/mainboard.c          |   5 +-
 src/mainboard/google/nyan_big/mainboard.c      |   5 +-
 src/mainboard/google/nyan_blaze/mainboard.c    |   5 +-
 src/mainboard/google/peach_pit/mainboard.c     |   5 +-
 src/mainboard/google/purin/mainboard.c         |   6 +-
 src/mainboard/google/storm/mainboard.c         |   5 +-
 src/mainboard/google/urara/mainboard.c         |   6 +-
 src/mainboard/google/veyron/mainboard.c        |   5 +-
 src/mainboard/google/veyron_mickey/mainboard.c |   6 +-
 src/mainboard/google/veyron_rialto/mainboard.c |   5 +-
 src/soc/nvidia/tegra210/mtc.c                  |   6 +-
 src/vendorcode/google/chromeos/ramoops.c       |   6 +-
 src/vendorcode/google/chromeos/vpd_mac.c       |   8 +-
 src/vendorcode/google/chromeos/vpd_serialno.c  |   6 +-
 23 files changed, 120 insertions(+), 125 deletions(-)

diff --git a/src/arch/x86/cpu.c b/src/arch/x86/cpu.c
index 1e74d0c..0bcc3a4 100644
--- a/src/arch/x86/cpu.c
+++ b/src/arch/x86/cpu.c
@@ -307,9 +307,8 @@ void lb_arch_add_records(struct lb_header *header)
 	if (freq_khz == 0)
 		return;
 
-	tsc_info = (void *)lb_new_record(header);
-	tsc_info->tag = LB_TAG_TSC_INFO;
-	tsc_info->size = sizeof(*tsc_info);
+	tsc_info = (void *)
+		lb_new_record(header, LB_TAG_TSC_INFO, sizeof(*tsc_info));
 	tsc_info->freq_khz = freq_khz;
 }
 
diff --git a/src/drivers/intel/fsp1_1/fsp_gop.c b/src/drivers/intel/fsp1_1/fsp_gop.c
index 6d905b2..754b94b 100644
--- a/src/drivers/intel/fsp1_1/fsp_gop.c
+++ b/src/drivers/intel/fsp1_1/fsp_gop.c
@@ -60,7 +60,11 @@ const optionrom_vbt_t *fsp_get_vbt(uint32_t *vbt_len)
 void lb_framebuffer(struct lb_header *header)
 {
 	struct lb_framebuffer *framebuffer;
-	framebuffer = (struct lb_framebuffer *)lb_new_record(header);
+
+	framebuffer = (struct lb_framebuffer *)
+		lb_new_record(header,
+			      LB_TAG_FRAMEBUFFER,
+			      sizeof(*framebuffer));
 
 	VOID *hob_list_ptr;
 	hob_list_ptr = get_hob_list();
@@ -90,6 +94,4 @@ void lb_framebuffer(struct lb_header *header)
 	framebuffer->blue_mask_size = 8;
 	framebuffer->reserved_mask_pos = 24;
 	framebuffer->reserved_mask_size = 8;
-	framebuffer->tag = LB_TAG_FRAMEBUFFER;
-	framebuffer->size = sizeof(*framebuffer);
 }
diff --git a/src/drivers/intel/fsp2_0/graphics.c b/src/drivers/intel/fsp2_0/graphics.c
index 97fffdc..45a6ddd 100644
--- a/src/drivers/intel/fsp2_0/graphics.c
+++ b/src/drivers/intel/fsp2_0/graphics.c
@@ -88,8 +88,6 @@ enum cb_err fsp_fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
 	framebuffer->blue_mask_size = fbinfo->blue.size;
 	framebuffer->reserved_mask_pos = fbinfo->rsvd.pos;
 	framebuffer->reserved_mask_size = fbinfo->rsvd.pos;
-	framebuffer->tag = LB_TAG_FRAMEBUFFER;
-	framebuffer->size = sizeof(*framebuffer);
 	return CB_SUCCESS;
 }
 
@@ -121,7 +119,10 @@ void lb_framebuffer(struct lb_header *header)
 		return;
 	}
 
-	framebuffer = (void *)lb_new_record(header);
+	framebuffer = (void *)lb_new_record(header,
+					    LB_TAG_FRAMEBUFFER,
+					    sizeof(*framebuffer));
+
 	ret = fsp_fill_lb_framebuffer(framebuffer);
 	if (ret != CB_SUCCESS) {
 		printk(BIOS_ALERT, "FSP did not return a valid framebuffer\n");
diff --git a/src/drivers/spi/spi_flash.c b/src/drivers/spi/spi_flash.c
index 95362f2..1ae1a87 100644
--- a/src/drivers/spi/spi_flash.c
+++ b/src/drivers/spi/spi_flash.c
@@ -455,10 +455,9 @@ void lb_spi_flash(struct lb_header *header)
 	if (!IS_ENABLED(CONFIG_BOOT_DEVICE_SPI_FLASH))
 		return;
 
-	flash = (struct lb_spi_flash *)lb_new_record(header);
-
-	flash->tag = LB_TAG_SPI_FLASH;
-	flash->size = sizeof(*flash);
+	flash = (struct lb_spi_flash *)lb_new_record(header,
+						     LB_TAG_SPI_FLASH,
+						     sizeof(*flash));
 
 	/* Try to get the flash device if not loaded yet */
 	if (!spi_flash_dev)
diff --git a/src/include/boot/coreboot_tables.h b/src/include/boot/coreboot_tables.h
index 5647629..f7e76dd 100644
--- a/src/include/boot/coreboot_tables.h
+++ b/src/include/boot/coreboot_tables.h
@@ -36,6 +36,8 @@ void lb_table_add_macs_from_vpd(struct lb_header *header);
 
 void lb_table_add_serialno_from_vpd(struct lb_header *header);
 
-struct lb_record *lb_new_record(struct lb_header *header);
+struct lb_record *lb_new_record(struct lb_header *header,
+				uint32_t tag,
+				uint32_t size);
 
 #endif /* COREBOOT_TABLES_H */
diff --git a/src/lib/coreboot_table.c b/src/lib/coreboot_table.c
index f8da658..d49b9c9 100644
--- a/src/lib/coreboot_table.c
+++ b/src/lib/coreboot_table.c
@@ -82,7 +82,8 @@ static struct lb_record *lb_last_record(struct lb_header *header)
 	return rec;
 }
 
-struct lb_record *lb_new_record(struct lb_header *header)
+struct lb_record *lb_new_record(struct lb_header *header,
+				uint32_t tag, uint32_t size)
 {
 	struct lb_record *rec;
 	rec = lb_last_record(header);
@@ -91,8 +92,17 @@ struct lb_record *lb_new_record(struct lb_header *header)
 	}
 	rec = lb_last_record(header);
 	header->table_entries++;
-	rec->tag = LB_TAG_UNUSED;
-	rec->size = sizeof(*rec);
+	rec->tag = tag;
+	// If the rec->size is not aligned to something reasonable,
+	// some architectures can take alignment traps.
+	// Round up table_bytes to something that is future-proof,
+	// namely 128 bits (16 bytes). This will ensure that even
+	// the 128-bit RISCV won't get traps.
+	// We have roundup macros all over the tree; we need to
+	// clean that up at some point.
+	// Note that all table types include an lb_record, so we
+	// need only use the passed-in size.
+	rec->size = (size + 0xf) & ~0xf;
 	return rec;
 }
 
@@ -100,10 +110,8 @@ static struct lb_memory *lb_memory(struct lb_header *header)
 {
 	struct lb_record *rec;
 	struct lb_memory *mem;
-	rec = lb_new_record(header);
+	rec = lb_new_record(header, LB_TAG_MEMORY, sizeof(*mem));
 	mem = (struct lb_memory *)rec;
-	mem->tag = LB_TAG_MEMORY;
-	mem->size = sizeof(*mem);
 	return mem;
 }
 
@@ -112,9 +120,9 @@ void lb_add_serial(struct lb_serial *new_serial, void *data)
 	struct lb_header *header = (struct lb_header *)data;
 	struct lb_serial *serial;
 
-	serial = (struct lb_serial *)lb_new_record(header);
-	serial->tag = LB_TAG_SERIAL;
-	serial->size = sizeof(*serial);
+	serial = (struct lb_serial *)lb_new_record(header,
+						   LB_TAG_SERIAL,
+						   sizeof(*serial));
 	serial->type = new_serial->type;
 	serial->baseaddr = new_serial->baseaddr;
 	serial->baud = new_serial->baud;
@@ -128,9 +136,9 @@ void lb_add_console(uint16_t consoletype, void *data)
 	struct lb_header *header = (struct lb_header *)data;
 	struct lb_console *console;
 
-	console = (struct lb_console *)lb_new_record(header);
-	console->tag = LB_TAG_CONSOLE;
-	console->size = sizeof(*console);
+	console = (struct lb_console *)lb_new_record(header,
+						     LB_TAG_CONSOLE,
+						     sizeof(*console));
 	console->type = consoletype;
 }
 
@@ -145,10 +153,9 @@ void __attribute__((weak)) lb_framebuffer(struct lb_header *header)
 	if (!vbe_mode_info_valid())
 		return;
 	struct lb_framebuffer *framebuffer;
-	framebuffer = (struct lb_framebuffer *)lb_new_record(header);
+	framebuffer = (struct lb_framebuffer *)
+		lb_new_record(header, LB_TAG_FRAMEBUFFER, sizeof(*framebuffer));
 	fill_lb_framebuffer(framebuffer);
-	framebuffer->tag = LB_TAG_FRAMEBUFFER;
-	framebuffer->size = sizeof(*framebuffer);
 #endif
 }
 
@@ -168,9 +175,9 @@ static void lb_gpios(struct lb_header *header)
 	struct lb_gpios *gpios;
 	struct lb_gpio *g;
 
-	gpios = (struct lb_gpios *)lb_new_record(header);
-	gpios->tag = LB_TAG_GPIO;
-	gpios->size = sizeof(*gpios);
+	gpios = (struct lb_gpios *)lb_new_record(header,
+						 LB_TAG_GPIO;
+						 sizeof(*gpios));
 	gpios->count = 0;
 	fill_lb_gpios(gpios);
 
@@ -206,9 +213,8 @@ static void lb_vdat(struct lb_header *header)
 #if CONFIG_HAVE_ACPI_TABLES
 	struct lb_range *vdat;
 
-	vdat = (struct lb_range *)lb_new_record(header);
-	vdat->tag = LB_TAG_VDAT;
-	vdat->size = sizeof(*vdat);
+	vdat = (struct lb_range *)
+		lb_new_record(header, LB_TAG_VDAT, sizeof(*vdat));
 	acpi_get_vdat_info(&vdat->range_start, &vdat->range_size);
 #endif
 }
@@ -218,9 +224,8 @@ static void lb_vbnv(struct lb_header *header)
 #if CONFIG_PC80_SYSTEM
 	struct lb_range *vbnv;
 
-	vbnv = (struct lb_range *)lb_new_record(header);
-	vbnv->tag = LB_TAG_VBNV;
-	vbnv->size = sizeof(*vbnv);
+	vbnv = (struct lb_range *)
+		lb_new_record(header, LB_TAG_VBNV, sizeof(*vbnv));
 	vbnv->range_start = CONFIG_VBOOT_VBNV_OFFSET + 14;
 	vbnv->range_size = VBOOT_VBNV_BLOCK_SIZE;
 #endif
@@ -236,9 +241,8 @@ static void lb_vboot_handoff(struct lb_header *header)
 	if (vboot_get_handoff_info(&addr, &size))
 		return;
 
-	vbho = (struct lb_range *)lb_new_record(header);
-	vbho->tag = LB_TAB_VBOOT_HANDOFF;
-	vbho->size = sizeof(*vbho);
+	vbho = (struct lb_range *)
+		lb_new_record(header, LB_TAB_VBOOT_HANDOFF, sizeof(*vbho));
 	vbho->range_start = (intptr_t)addr;
 	vbho->range_size = size;
 }
@@ -252,10 +256,8 @@ static void lb_board_id(struct lb_header *header)
 #if CONFIG_BOARD_ID_AUTO || CONFIG_BOARD_ID_MANUAL
 	struct lb_board_id  *bid;
 
-	bid = (struct lb_board_id *)lb_new_record(header);
-
-	bid->tag = LB_TAG_BOARD_ID;
-	bid->size = sizeof(*bid);
+	bid = (struct lb_board_id *)
+		lb_new_record(header, LB_TAG_BOARD_ID, sizeof(*bid));
 	bid->board_id = board_id();
 #endif
 }
@@ -276,9 +278,8 @@ static void lb_boot_media_params(struct lb_header *header)
 	if (boot_dev == NULL)
 		return;
 
-	bmp = (struct lb_boot_media_params *)lb_new_record(header);
-	bmp->tag = LB_TAG_BOOT_MEDIA_PARAMS;
-	bmp->size = sizeof(*bmp);
+	bmp = (struct lb_boot_media_params *)
+		lb_new_record(header, LB_TAG_BOOT_MEDIA_PARAMS, sizeof(*bmp));
 
 	bmp->cbfs_offset = props.offset;
 	bmp->cbfs_size = props.size;
@@ -295,10 +296,8 @@ static void lb_ram_code(struct lb_header *header)
 #if IS_ENABLED(CONFIG_RAM_CODE_SUPPORT)
 	struct lb_ram_code *code;
 
-	code = (struct lb_ram_code *)lb_new_record(header);
-
-	code->tag = LB_TAG_RAM_CODE;
-	code->size = sizeof(*code);
+	code = (struct lb_ram_code *)
+		lb_new_record(header, LB_TAG_RAM_CODE, sizeof(*code));
 	code->ram_code = ram_code();
 #endif
 }
@@ -329,7 +328,9 @@ static void add_cbmem_pointers(struct lb_header *header)
 		if (!cbmem_addr)
 			continue;  /* This section is not present */
 
-		cbmem_ref = (struct lb_cbmem_ref *)lb_new_record(header);
+		cbmem_ref = (struct lb_cbmem_ref *)
+			lb_new_record(header, sid->table_tag,
+				      sizeof(*cbmem_ref));
 		if (!cbmem_ref) {
 			printk(BIOS_ERR, "No more room in coreboot table!\n");
 			break;
@@ -344,14 +345,13 @@ static struct lb_mainboard *lb_mainboard(struct lb_header *header)
 {
 	struct lb_record *rec;
 	struct lb_mainboard *mainboard;
-	rec = lb_new_record(header);
-	mainboard = (struct lb_mainboard *)rec;
-	mainboard->tag = LB_TAG_MAINBOARD;
+	rec = lb_new_record(header, LB_TAG_MAINBOARD,
+			    sizeof(*mainboard) +
+			    strlen(mainboard_vendor) + 1 +
+			    strlen(mainboard_part_number) + 1);
 
-	mainboard->size = (sizeof(*mainboard) +
-		strlen(mainboard_vendor) + 1 +
-		strlen(mainboard_part_number) + 1 +
-		3) & ~3;
+
+	mainboard = (struct lb_mainboard *)rec;
 
 	mainboard->vendor_idx = 0;
 	mainboard->part_number_idx = strlen(mainboard_vendor) + 1;
@@ -369,11 +369,9 @@ static struct cmos_checksum *lb_cmos_checksum(struct lb_header *header)
 {
 	struct lb_record *rec;
 	struct cmos_checksum *cmos_checksum;
-	rec = lb_new_record(header);
+	rec = lb_new_record(header, LB_TAG_OPTION_CHECKSUM,
+			    sizeof(*cmos_checksum));
 	cmos_checksum = (struct cmos_checksum *)rec;
-	cmos_checksum->tag = LB_TAG_OPTION_CHECKSUM;
-
-	cmos_checksum->size = (sizeof(*cmos_checksum));
 
 	cmos_checksum->range_start = LB_CKS_RANGE_START * 8;
 	cmos_checksum->range_end = ( LB_CKS_RANGE_END * 8 ) + 7;
@@ -399,10 +397,10 @@ static void lb_strings(struct lb_header *header)
 	for(i = 0; i < ARRAY_SIZE(strings); i++) {
 		struct lb_string *rec;
 		size_t len;
-		rec = (struct lb_string *)lb_new_record(header);
 		len = strlen(strings[i].string);
-		rec->tag = strings[i].tag;
-		rec->size = (sizeof(*rec) + len + 1 + 3) & ~3;
+		rec = (struct lb_string *)lb_new_record(header,
+							strings[i].tag,
+							sizeof(*rec) + len + 1);
 		memcpy(rec->string, strings[i].string, len+1);
 	}
 
@@ -411,9 +409,8 @@ static void lb_strings(struct lb_header *header)
 static void lb_record_version_timestamp(struct lb_header *header)
 {
 	struct lb_timestamp *rec;
-	rec = (struct lb_timestamp *)lb_new_record(header);
-	rec->tag = LB_TAG_VERSION_TIMESTAMP;
-	rec->size = sizeof(*rec);
+	rec = (struct lb_timestamp *)
+		lb_new_record(header, LB_TAG_VERSION_TIMESTAMP, sizeof(*rec));
 	rec->timestamp = coreboot_version_timestamp;
 }
 
@@ -431,10 +428,8 @@ static struct lb_forward *lb_forward(struct lb_header *header, struct lb_header
 {
 	struct lb_record *rec;
 	struct lb_forward *forward;
-	rec = lb_new_record(header);
+	rec = lb_new_record(header, LB_TAG_FORWARD, sizeof(*forward));
 	forward = (struct lb_forward *)rec;
-	forward->tag = LB_TAG_FORWARD;
-	forward->size = sizeof(*forward);
 	forward->forward = (uint64_t)(unsigned long)next_header;
 	return forward;
 }
@@ -485,7 +480,11 @@ static uintptr_t write_coreboot_table(uintptr_t rom_table_end)
 			cbfs_boot_map_with_leak("cmos_layout.bin",
 				CBFS_COMPONENT_CMOS_LAYOUT, NULL);
 		if (option_table) {
-			struct lb_record *rec_dest = lb_new_record(head);
+			struct lb_record *rec_dest;
+
+			rec_dest = lb_new_record(head,
+						 option_table->tag,
+						 option_table->size);
 			/* Copy the option config table, it's already a lb_record... */
 			memcpy(rec_dest,  option_table, option_table->size);
 			/* Create cmos checksum entry in coreboot table */
diff --git a/src/lib/imd_cbmem.c b/src/lib/imd_cbmem.c
index b0273f4..8187ffa 100644
--- a/src/lib/imd_cbmem.c
+++ b/src/lib/imd_cbmem.c
@@ -335,9 +335,9 @@ void cbmem_add_records_to_cbtable(struct lb_header *header)
 		if (id == CBMEM_ID_IMD_ROOT || id == CBMEM_ID_IMD_SMALL)
 			continue;
 
-		lbe = (struct lb_cbmem_entry *)lb_new_record(header);
-		lbe->tag = LB_TAG_CBMEM_ENTRY;
-		lbe->size = sizeof(*lbe);
+		lbe = (struct lb_cbmem_entry *)lb_new_record(header,
+							     LB_TAG_CBMEM_ENTRY,
+							     sizeof(*lbe));
 		lbe->address = (uintptr_t)imd_entry_at(imd, e);
 		lbe->entry_size = imd_entry_size(imd, e);
 		lbe->id = id;
diff --git a/src/mainboard/google/daisy/mainboard.c b/src/mainboard/google/daisy/mainboard.c
index e67bdcf..a5e11c6 100644
--- a/src/mainboard/google/daisy/mainboard.c
+++ b/src/mainboard/google/daisy/mainboard.c
@@ -350,9 +350,8 @@ void lb_board(struct lb_header *header)
 {
 	struct lb_range *dma;
 
-	dma = (struct lb_range *)lb_new_record(header);
-	dma->tag = LB_TAB_DMA;
-	dma->size = sizeof(*dma);
+	dma = (struct lb_range *)
+		lb_new_record(header, LB_TAB_DMA, sizeof(*dma));
 	dma->range_start = (uintptr_t)_dma_coherent;
 	dma->range_size = _dma_coherent_size;
 }
diff --git a/src/mainboard/google/gale/mainboard.c b/src/mainboard/google/gale/mainboard.c
index f27421b..e7199b4 100644
--- a/src/mainboard/google/gale/mainboard.c
+++ b/src/mainboard/google/gale/mainboard.c
@@ -74,9 +74,8 @@ void lb_board(struct lb_header *header)
 {
 	struct lb_range *dma;
 
-	dma = (struct lb_range *)lb_new_record(header);
-	dma->tag = LB_TAB_DMA;
-	dma->size = sizeof(*dma);
+	dma = (struct lb_range *)lb_new_record(header,
+					       LB_TAB_DMA, sizeof(*dma));
 	dma->range_start = (uintptr_t)_dma_coherent;
 	dma->range_size = _dma_coherent_size;
 
diff --git a/src/mainboard/google/nyan/mainboard.c b/src/mainboard/google/nyan/mainboard.c
index 92bb3e3..429aba8 100644
--- a/src/mainboard/google/nyan/mainboard.c
+++ b/src/mainboard/google/nyan/mainboard.c
@@ -258,9 +258,8 @@ void lb_board(struct lb_header *header)
 {
 	struct lb_range *dma;
 
-	dma = (struct lb_range *)lb_new_record(header);
-	dma->tag = LB_TAB_DMA;
-	dma->size = sizeof(*dma);
+	dma = (struct lb_range *)lb_new_record(header,
+					       LB_TAB_DMA, sizeof(*dma));
 	dma->range_start = (uintptr_t)_dma_coherent;
 	dma->range_size = _dma_coherent_size;
 }
diff --git a/src/mainboard/google/nyan_big/mainboard.c b/src/mainboard/google/nyan_big/mainboard.c
index 0c0fe5e..35d4d7e 100644
--- a/src/mainboard/google/nyan_big/mainboard.c
+++ b/src/mainboard/google/nyan_big/mainboard.c
@@ -256,9 +256,8 @@ void lb_board(struct lb_header *header)
 {
 	struct lb_range *dma;
 
-	dma = (struct lb_range *)lb_new_record(header);
-	dma->tag = LB_TAB_DMA;
-	dma->size = sizeof(*dma);
+	dma = (struct lb_range *)lb_new_record(header,
+					       LB_TAB_DMA, sizeof(*dma));
 	dma->range_start = (uintptr_t)_dma_coherent;
 	dma->range_size = _dma_coherent_size;
 }
diff --git a/src/mainboard/google/nyan_blaze/mainboard.c b/src/mainboard/google/nyan_blaze/mainboard.c
index c3b936c..9bfd54f 100644
--- a/src/mainboard/google/nyan_blaze/mainboard.c
+++ b/src/mainboard/google/nyan_blaze/mainboard.c
@@ -256,9 +256,8 @@ void lb_board(struct lb_header *header)
 {
 	struct lb_range *dma;
 
-	dma = (struct lb_range *)lb_new_record(header);
-	dma->tag = LB_TAB_DMA;
-	dma->size = sizeof(*dma);
+	dma = (struct lb_range *)lb_new_record(header,
+					       LB_TAB_DMA, sizeof(*dma));
 	dma->range_start = (uintptr_t)_dma_coherent;
 	dma->range_size = _dma_coherent_size;
 }
diff --git a/src/mainboard/google/peach_pit/mainboard.c b/src/mainboard/google/peach_pit/mainboard.c
index 4cc72f1..b86502b 100644
--- a/src/mainboard/google/peach_pit/mainboard.c
+++ b/src/mainboard/google/peach_pit/mainboard.c
@@ -484,9 +484,8 @@ void lb_board(struct lb_header *header)
 {
 	struct lb_range *dma;
 
-	dma = (struct lb_range *)lb_new_record(header);
-	dma->tag = LB_TAB_DMA;
-	dma->size = sizeof(*dma);
+	dma = (struct lb_range *)
+		lb_new_record(header, LB_TAB_DMA, sizeof(*dma));
 	dma->range_start = (uintptr_t)_dma_coherent;
 	dma->range_size = _dma_coherent_size;
 }
diff --git a/src/mainboard/google/purin/mainboard.c b/src/mainboard/google/purin/mainboard.c
index c238442..36f8c30 100644
--- a/src/mainboard/google/purin/mainboard.c
+++ b/src/mainboard/google/purin/mainboard.c
@@ -34,9 +34,9 @@ void lb_board(struct lb_header *header)
 {
 	struct lb_range *dma;
 
-	dma = (struct lb_range *)lb_new_record(header);
-	dma->tag = LB_TAB_DMA;
-	dma->size = sizeof(*dma);
+	dma = (struct lb_range *)lb_new_record(header,
+					       LB_TAB_DMA,
+					       sizeof(*dma));
 	dma->range_start = (uintptr_t)_dma_coherent;
 	dma->range_size = _dma_coherent_size;
 }
diff --git a/src/mainboard/google/storm/mainboard.c b/src/mainboard/google/storm/mainboard.c
index e3e7b68..54a3f9f 100644
--- a/src/mainboard/google/storm/mainboard.c
+++ b/src/mainboard/google/storm/mainboard.c
@@ -118,9 +118,8 @@ void lb_board(struct lb_header *header)
 {
 	struct lb_range *dma;
 
-	dma = (struct lb_range *)lb_new_record(header);
-	dma->tag = LB_TAB_DMA;
-	dma->size = sizeof(*dma);
+	dma = (struct lb_range *)lb_new_record(header,
+					       LB_TAB_DMA, sizeof(*dma));
 	dma->range_start = (uintptr_t)_dma_coherent;
 	dma->range_size = _dma_coherent_size;
 
diff --git a/src/mainboard/google/urara/mainboard.c b/src/mainboard/google/urara/mainboard.c
index f68bb0b..06f821f 100644
--- a/src/mainboard/google/urara/mainboard.c
+++ b/src/mainboard/google/urara/mainboard.c
@@ -43,9 +43,9 @@ void lb_board(struct lb_header *header)
 {
 	struct lb_range *dma;
 
-	dma = (struct lb_range *)lb_new_record(header);
-	dma->tag = LB_TAB_DMA;
-	dma->size = sizeof(*dma);
+	dma = (struct lb_range *)lb_new_record(header,
+					       LB_TAB_DMA,
+					       sizeof(*dma));
 	dma->range_start = (uintptr_t)_dma_coherent;
 	dma->range_size = _dma_coherent_size;
 
diff --git a/src/mainboard/google/veyron/mainboard.c b/src/mainboard/google/veyron/mainboard.c
index a6bbf88..a3290e9 100644
--- a/src/mainboard/google/veyron/mainboard.c
+++ b/src/mainboard/google/veyron/mainboard.c
@@ -123,9 +123,8 @@ void lb_board(struct lb_header *header)
 {
 	struct lb_range *dma;
 
-	dma = (struct lb_range *)lb_new_record(header);
-	dma->tag = LB_TAB_DMA;
-	dma->size = sizeof(*dma);
+	dma = (struct lb_range *)
+		lb_new_record(header, LB_TAB_DMA, sizeof(*dma));
 	dma->range_start = (uintptr_t)_dma_coherent;
 	dma->range_size = _dma_coherent_size;
 }
diff --git a/src/mainboard/google/veyron_mickey/mainboard.c b/src/mainboard/google/veyron_mickey/mainboard.c
index ef085b2..0d37807 100644
--- a/src/mainboard/google/veyron_mickey/mainboard.c
+++ b/src/mainboard/google/veyron_mickey/mainboard.c
@@ -102,9 +102,9 @@ void lb_board(struct lb_header *header)
 {
 	struct lb_range *dma;
 
-	dma = (struct lb_range *)lb_new_record(header);
-	dma->tag = LB_TAB_DMA;
-	dma->size = sizeof(*dma);
+	dma = (struct lb_range *)lb_new_record(header,
+					       LB_TAB_DMA,
+					       sizeof(*dma));
 	dma->range_start = (uintptr_t)_dma_coherent;
 	dma->range_size = _dma_coherent_size;
 }
diff --git a/src/mainboard/google/veyron_rialto/mainboard.c b/src/mainboard/google/veyron_rialto/mainboard.c
index b9b6a22..28791c1 100644
--- a/src/mainboard/google/veyron_rialto/mainboard.c
+++ b/src/mainboard/google/veyron_rialto/mainboard.c
@@ -107,9 +107,8 @@ void lb_board(struct lb_header *header)
 {
 	struct lb_range *dma;
 
-	dma = (struct lb_range *)lb_new_record(header);
-	dma->tag = LB_TAB_DMA;
-	dma->size = sizeof(*dma);
+	dma = (struct lb_range *)lb_new_record(header,
+					       LB_TAB_DMA, sizeof(*dma));
 	dma->range_start = (uintptr_t)_dma_coherent;
 	dma->range_size = _dma_coherent_size;
 }
diff --git a/src/soc/nvidia/tegra210/mtc.c b/src/soc/nvidia/tegra210/mtc.c
index f71e5e8..13d7b51 100644
--- a/src/soc/nvidia/tegra210/mtc.c
+++ b/src/soc/nvidia/tegra210/mtc.c
@@ -79,9 +79,9 @@ int tegra210_run_mtc(void)
 void soc_add_mtc(struct lb_header *header)
 {
 	struct lb_range *mtc;
-	mtc = (struct lb_range *)lb_new_record(header);
-	mtc->tag = LB_TAG_MTC;
-	mtc->size = sizeof(*mtc);
+	mtc = (struct lb_range *)lb_new_record(header,
+					       LB_TAG_MTC,
+					       sizeof(*mtc));
 
 	mtc->range_start = (uintptr_t)cbmem_find(CBMEM_ID_MTC);
 	mtc->range_size = mtc_table_size;
diff --git a/src/vendorcode/google/chromeos/ramoops.c b/src/vendorcode/google/chromeos/ramoops.c
index 313025d..8776192 100644
--- a/src/vendorcode/google/chromeos/ramoops.c
+++ b/src/vendorcode/google/chromeos/ramoops.c
@@ -121,9 +121,9 @@ void lb_ramoops(struct lb_header *header)
 		return;
 
 	struct lb_range *ramoops;
-	ramoops = (struct lb_range *)lb_new_record(header);
-	ramoops->tag = LB_TAG_RAM_OOPS;
-	ramoops->size = sizeof(*ramoops);
+	ramoops = (struct lb_range *)lb_new_record(header,
+						   LB_TAG_RAM_OOPS,
+						   sizeof(*ramoops));
 	ramoops->range_start = (uintptr_t)buffer;
 	ramoops->range_size = CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE;
 }
diff --git a/src/vendorcode/google/chromeos/vpd_mac.c b/src/vendorcode/google/chromeos/vpd_mac.c
index 0619974..f647fc0 100644
--- a/src/vendorcode/google/chromeos/vpd_mac.c
+++ b/src/vendorcode/google/chromeos/vpd_mac.c
@@ -89,8 +89,10 @@ void lb_table_add_macs_from_vpd(struct lb_header *header)
 				break;
 
 			if (!macs) {
-				macs = (struct lb_macs *)lb_new_record(header);
-				macs->tag = LB_TAG_MAC_ADDRS;
+				macs = (struct lb_macs *)
+					lb_new_record(header,
+						      LB_TAG_MAC_ADDRS,
+						      sizeof(*macs));
 			}
 
 			decode_mac(macs->mac_addrs + count,
@@ -105,5 +107,5 @@ void lb_table_add_macs_from_vpd(struct lb_header *header)
 		return; /* No MAC addresses in the VPD. */
 
 	macs->count = count;
-	macs->size = sizeof(*macs) + count * sizeof(struct mac_address);
+	macs->size += count * sizeof(struct mac_address);
 }
diff --git a/src/vendorcode/google/chromeos/vpd_serialno.c b/src/vendorcode/google/chromeos/vpd_serialno.c
index e9a771e..c3d5ab5 100644
--- a/src/vendorcode/google/chromeos/vpd_serialno.c
+++ b/src/vendorcode/google/chromeos/vpd_serialno.c
@@ -36,9 +36,9 @@ void lb_table_add_serialno_from_vpd(struct lb_header *header)
 	len = strlen(serialno) + 1;
 	ASSERT(len <= 32);
 
-	serialno_rec = (struct lb_string *)lb_new_record(header);
-	serialno_rec->tag = LB_TAG_SERIALNO;
+	serialno_rec = (struct lb_string *)
+		lb_new_record(header, LB_TAG_SERIALNO,
+			      ALIGN_UP(sizeof(*serialno_rec) + len, 8));
 
-	serialno_rec->size = ALIGN_UP(sizeof(*serialno_rec) + len, 8);
 	memcpy(&serialno_rec->string, serialno, len);
 }



More information about the coreboot-gerrit mailing list