From 9948c521a63148e49d850d2ac760f245007908a3 Mon Sep 17 00:00:00 2001 From: Arthur Heymans Date: Mon, 24 Oct 2022 14:37:40 +0200 Subject: lib/coreboot_table: Simplify API to set up lb_serial Instead of having callbacks into serial console code to set up the coreboot table have the coreboot table code call IP specific code to get serial information. This makes it easier to reuse the information as the return value can be used in a different context (e.g. when filling in a FDT). This also removes boilerplate code to set up lb_console entries by setting entry based on the type in struct lb_uart. Change-Id: I6c08a88fb5fc035eb28d0becf19471c709c8043d Signed-off-by: Arthur Heymans Reviewed-on: https://review.coreboot.org/c/coreboot/+/68768 Tested-by: build bot (Jenkins) Reviewed-by: Hung-Te Lin --- src/lib/coreboot_table.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/lib') diff --git a/src/lib/coreboot_table.c b/src/lib/coreboot_table.c index 4df703958f..6c09cb13c4 100644 --- a/src/lib/coreboot_table.c +++ b/src/lib/coreboot_table.c @@ -96,19 +96,22 @@ static struct lb_memory *lb_memory(struct lb_header *header) return mem; } -void lb_add_serial(struct lb_serial *new_serial, void *data) +static void lb_add_serial(struct lb_header *header) { - 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->type = new_serial->type; - serial->baseaddr = new_serial->baseaddr; - serial->baud = new_serial->baud; - serial->regwidth = new_serial->regwidth; - serial->input_hertz = new_serial->input_hertz; + struct lb_serial new_serial = { .tag = LB_TAG_SERIAL, + .size = sizeof(struct lb_serial), + }; + if (fill_lb_serial(&new_serial) != CB_SUCCESS) + return; + + struct lb_serial *serial = (struct lb_serial *)lb_new_record(header); + memcpy(serial, &new_serial, sizeof(*serial)); + assert(serial->type == LB_SERIAL_TYPE_IO_MAPPED + || serial->type == LB_SERIAL_TYPE_MEMORY_MAPPED) + if (serial->type == LB_SERIAL_TYPE_IO_MAPPED) + lb_add_console(LB_TAG_CONSOLE_SERIAL8250, header); + else + lb_add_console(LB_TAG_CONSOLE_SERIAL8250MEM, header); } void lb_add_console(uint16_t consoletype, void *data) @@ -492,7 +495,7 @@ static uintptr_t write_coreboot_table(uintptr_t rom_table_end) /* Record the serial ports and consoles */ if (CONFIG(CONSOLE_SERIAL)) - uart_fill_lb(head); + lb_add_serial(head); if (CONFIG(CONSOLE_USB)) lb_add_console(LB_TAG_CONSOLE_EHCI, head); -- cgit v1.2.3