Hello Julius Werner, Reto Buerki,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/37513
to review the following change.
Change subject: libpayload: Make 8250 UART driver relocation safe ......................................................................
libpayload: Make 8250 UART driver relocation safe
`lib_sysinfo->serial` is a virtual pointer into coreboot tables. It's not valid across relocation. Work around that by caching the whole table entry locally.
The better alternative would be to revise `sysinfo`, to contain no virtual pointers to anything outside the payload.
Change-Id: I03adaf57b83a177316d7778f7e06df8eb6f9158e Signed-off-by: Nico Huber nico.huber@secunet.com --- M payloads/libpayload/drivers/serial/8250.c 1 file changed, 10 insertions(+), 11 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/13/37513/1
diff --git a/payloads/libpayload/drivers/serial/8250.c b/payloads/libpayload/drivers/serial/8250.c index 9502d4b..4a7cc01 100644 --- a/payloads/libpayload/drivers/serial/8250.c +++ b/payloads/libpayload/drivers/serial/8250.c @@ -31,7 +31,9 @@ #include <libpayload-config.h> #include <libpayload.h>
-#define IOBASE lib_sysinfo.serial->baseaddr +static struct cb_serial cb_serial; + +#define IOBASE cb_serial.baseaddr #define MEMBASE (phys_to_virt(IOBASE))
static int serial_hardware_is_present = 0; @@ -39,14 +41,14 @@
static uint8_t serial_read_reg(int offset) { - offset *= lib_sysinfo.serial->regwidth; + offset *= cb_serial.regwidth;
#if CONFIG(LP_IO_ADDRESS_SPACE) if (!serial_is_mem_mapped) return inb(IOBASE + offset); else #endif - if (lib_sysinfo.serial->regwidth == 4) + if (cb_serial.regwidth == 4) return readl(MEMBASE + offset) & 0xff; else return readb(MEMBASE + offset); @@ -54,14 +56,14 @@
static void serial_write_reg(uint8_t val, int offset) { - offset *= lib_sysinfo.serial->regwidth; + offset *= cb_serial.regwidth;
#if CONFIG(LP_IO_ADDRESS_SPACE) if (!serial_is_mem_mapped) outb(val, IOBASE + offset); else #endif - if (lib_sysinfo.serial->regwidth == 4) + if (cb_serial.regwidth == 4) writel(val & 0xff, MEMBASE + offset); else writeb(val, MEMBASE + offset); @@ -108,11 +110,7 @@
void serial_init(void) { - if (!lib_sysinfo.serial) - return; - - serial_is_mem_mapped = - (lib_sysinfo.serial->type == CB_SERIAL_TYPE_MEMORY_MAPPED); + serial_is_mem_mapped = (cb_serial.type == CB_SERIAL_TYPE_MEMORY_MAPPED);
if (!serial_is_mem_mapped) { #if CONFIG(LP_IO_ADDRESS_SPACE) @@ -130,15 +128,16 @@ #if CONFIG(LP_SERIAL_SET_SPEED) serial_hardware_init(CONFIG_LP_SERIAL_BAUD_RATE, 8, 0, 1); #endif + serial_hardware_is_present = 1; }
void serial_console_init(void) { if (!lib_sysinfo.serial) return; + cb_serial = *lib_sysinfo.serial;
serial_init(); - serial_hardware_is_present = 1;
console_add_input_driver(&consin); console_add_output_driver(&consout);
Reto Buerki has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/37513 )
Change subject: libpayload: Make 8250 UART driver relocation safe ......................................................................
Patch Set 1: Code-Review+1
This fixes the FILO relocation issue with DEBUG_ALL. Thanks!
Paul Menzel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/37513 )
Change subject: libpayload: Make 8250 UART driver relocation safe ......................................................................
Patch Set 1:
(1 comment)
https://review.coreboot.org/c/coreboot/+/37513/1//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/37513/1//COMMIT_MSG@15 PS1, Line 15: Describe a problem this fixes?
FILO hangs with DEBUG_ALL enabled.
Hello build bot (Jenkins), Reto Buerki, Angel Pons, Julius Werner,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/37513
to look at the new patch set (#2).
Change subject: libpayload: Make 8250 UART driver relocation safe ......................................................................
libpayload: Make 8250 UART driver relocation safe
`lib_sysinfo->serial` is a virtual pointer into coreboot tables. It's not valid across relocation. Accessing the wrong value during relocation of FILO resulted in a hang with DEBUG_SEGMENT and UART console enabled. Work around that by caching the whole table entry locally.
An alternative would be to revise `sysinfo`, to contain no virtual pointers to anything outside the payload.
Change-Id: I03adaf57b83a177316d7778f7e06df8eb6f9158e Signed-off-by: Nico Huber nico.huber@secunet.com --- M payloads/libpayload/drivers/serial/8250.c 1 file changed, 10 insertions(+), 11 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/13/37513/2
Nico Huber has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/37513 )
Change subject: libpayload: Make 8250 UART driver relocation safe ......................................................................
Patch Set 2:
(1 comment)
https://review.coreboot.org/c/coreboot/+/37513/1//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/37513/1//COMMIT_MSG@15 PS1, Line 15:
Describe a problem this fixes? […]
Done
Nico Huber has submitted this change. ( https://review.coreboot.org/c/coreboot/+/37513 )
Change subject: libpayload: Make 8250 UART driver relocation safe ......................................................................
libpayload: Make 8250 UART driver relocation safe
`lib_sysinfo->serial` is a virtual pointer into coreboot tables. It's not valid across relocation. Accessing the wrong value during relocation of FILO resulted in a hang with DEBUG_SEGMENT and UART console enabled. Work around that by caching the whole table entry locally.
An alternative would be to revise `sysinfo`, to contain no virtual pointers to anything outside the payload.
Change-Id: I03adaf57b83a177316d7778f7e06df8eb6f9158e Signed-off-by: Nico Huber nico.huber@secunet.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/37513 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Reto Buerki reet@codelabs.ch Reviewed-by: Angel Pons th3fanbus@gmail.com --- M payloads/libpayload/drivers/serial/8250.c 1 file changed, 10 insertions(+), 11 deletions(-)
Approvals: build bot (Jenkins): Verified Reto Buerki: Looks good to me, but someone else must approve Angel Pons: Looks good to me, approved
diff --git a/payloads/libpayload/drivers/serial/8250.c b/payloads/libpayload/drivers/serial/8250.c index 9502d4b..4a7cc01 100644 --- a/payloads/libpayload/drivers/serial/8250.c +++ b/payloads/libpayload/drivers/serial/8250.c @@ -31,7 +31,9 @@ #include <libpayload-config.h> #include <libpayload.h>
-#define IOBASE lib_sysinfo.serial->baseaddr +static struct cb_serial cb_serial; + +#define IOBASE cb_serial.baseaddr #define MEMBASE (phys_to_virt(IOBASE))
static int serial_hardware_is_present = 0; @@ -39,14 +41,14 @@
static uint8_t serial_read_reg(int offset) { - offset *= lib_sysinfo.serial->regwidth; + offset *= cb_serial.regwidth;
#if CONFIG(LP_IO_ADDRESS_SPACE) if (!serial_is_mem_mapped) return inb(IOBASE + offset); else #endif - if (lib_sysinfo.serial->regwidth == 4) + if (cb_serial.regwidth == 4) return readl(MEMBASE + offset) & 0xff; else return readb(MEMBASE + offset); @@ -54,14 +56,14 @@
static void serial_write_reg(uint8_t val, int offset) { - offset *= lib_sysinfo.serial->regwidth; + offset *= cb_serial.regwidth;
#if CONFIG(LP_IO_ADDRESS_SPACE) if (!serial_is_mem_mapped) outb(val, IOBASE + offset); else #endif - if (lib_sysinfo.serial->regwidth == 4) + if (cb_serial.regwidth == 4) writel(val & 0xff, MEMBASE + offset); else writeb(val, MEMBASE + offset); @@ -108,11 +110,7 @@
void serial_init(void) { - if (!lib_sysinfo.serial) - return; - - serial_is_mem_mapped = - (lib_sysinfo.serial->type == CB_SERIAL_TYPE_MEMORY_MAPPED); + serial_is_mem_mapped = (cb_serial.type == CB_SERIAL_TYPE_MEMORY_MAPPED);
if (!serial_is_mem_mapped) { #if CONFIG(LP_IO_ADDRESS_SPACE) @@ -130,15 +128,16 @@ #if CONFIG(LP_SERIAL_SET_SPEED) serial_hardware_init(CONFIG_LP_SERIAL_BAUD_RATE, 8, 0, 1); #endif + serial_hardware_is_present = 1; }
void serial_console_init(void) { if (!lib_sysinfo.serial) return; + cb_serial = *lib_sysinfo.serial;
serial_init(); - serial_hardware_is_present = 1;
console_add_input_driver(&consin); console_add_output_driver(&consout);
9elements QA has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/37513 )
Change subject: libpayload: Make 8250 UART driver relocation safe ......................................................................
Patch Set 3:
Automatic boot test returned (PASS/FAIL/TOTAL): 4/0/4 Emulation targets: "QEMU x86 q35/ich9" using payload TianoCore : SUCCESS : https://lava.9esec.io/r/2487 "QEMU x86 q35/ich9" using payload SeaBIOS : SUCCESS : https://lava.9esec.io/r/2486 "QEMU x86 i440fx/piix4" using payload SeaBIOS : SUCCESS : https://lava.9esec.io/r/2485 "QEMU AArch64" using payload LinuxBoot_u-root_kexec : SUCCESS : https://lava.9esec.io/r/2484
Please note: This test is under development and might not be accurate at all!