From be842cb72d83b347bbc1c3308909f4eac286b47a Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Sat, 18 Jul 2020 14:54:47 +0200 Subject: libpayload: Cache physical location of serial-console struct In the presence of self-relocating payloads, it's safer to keep physical addresses in `libsysinfo`. Change-Id: Icd30e95c6b8115d16dd793914fb01a1a9da1854f Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/c/coreboot/+/43577 Tested-by: build bot (Jenkins) Reviewed-by: Angel Pons Reviewed-by: Julius Werner --- payloads/libpayload/drivers/serial/8250.c | 4 ++-- payloads/libpayload/drivers/serial/ipq40xx.c | 4 +--- payloads/libpayload/drivers/serial/ipq806x.c | 4 ++-- payloads/libpayload/drivers/serial/qcom_qupv3_serial.c | 5 +++-- payloads/libpayload/drivers/serial/qcs405.c | 4 ++-- payloads/libpayload/drivers/serial/s5p.c | 6 ++++-- 6 files changed, 14 insertions(+), 13 deletions(-) (limited to 'payloads/libpayload/drivers/serial') diff --git a/payloads/libpayload/drivers/serial/8250.c b/payloads/libpayload/drivers/serial/8250.c index b0e9d03c20..1df34c41ea 100644 --- a/payloads/libpayload/drivers/serial/8250.c +++ b/payloads/libpayload/drivers/serial/8250.c @@ -132,9 +132,9 @@ void serial_init(void) void serial_console_init(void) { - if (!lib_sysinfo.serial) + if (!lib_sysinfo.cb_serial) return; - cb_serial = *lib_sysinfo.serial; + cb_serial = *(struct cb_serial *)phys_to_virt(lib_sysinfo.cb_serial); serial_init(); diff --git a/payloads/libpayload/drivers/serial/ipq40xx.c b/payloads/libpayload/drivers/serial/ipq40xx.c index 5a9079b46b..bc5ebbbc1b 100644 --- a/payloads/libpayload/drivers/serial/ipq40xx.c +++ b/payloads/libpayload/drivers/serial/ipq40xx.c @@ -553,9 +553,7 @@ static struct console_output_driver consout = {}; /* For simplicity's sake, let's rely on coreboot initializing the UART. */ void serial_console_init(void) { - struct cb_serial *sc_ptr = lib_sysinfo.serial; - - if (!sc_ptr) + if (!lib_sysinfo.cb_serial) return; consin.havekey = serial_havechar; diff --git a/payloads/libpayload/drivers/serial/ipq806x.c b/payloads/libpayload/drivers/serial/ipq806x.c index ef4ce80849..93e2129185 100644 --- a/payloads/libpayload/drivers/serial/ipq806x.c +++ b/payloads/libpayload/drivers/serial/ipq806x.c @@ -343,9 +343,9 @@ int serial_getchar(void) /* For simplicity's sake, let's rely on coreboot initializing the UART. */ void serial_console_init(void) { - struct cb_serial *sc_ptr = lib_sysinfo.serial; + struct cb_serial *sc_ptr = phys_to_virt(lib_sysinfo.cb_serial); - if (!sc_ptr) + if (!lib_sysinfo.cb_serial) return; base_uart_addr = (void *) sc_ptr->baseaddr; diff --git a/payloads/libpayload/drivers/serial/qcom_qupv3_serial.c b/payloads/libpayload/drivers/serial/qcom_qupv3_serial.c index 3d0e6de335..321ff46b42 100644 --- a/payloads/libpayload/drivers/serial/qcom_qupv3_serial.c +++ b/payloads/libpayload/drivers/serial/qcom_qupv3_serial.c @@ -275,7 +275,8 @@ static struct console_output_driver consout = { static struct qup_regs *uart_base_address(void) { - return (void *)(uintptr_t)lib_sysinfo.serial->baseaddr; + const struct cb_serial *const serial = phys_to_virt(lib_sysinfo.cb_serial); + return phys_to_virt(serial->baseaddr); } static void uart_qupv3_tx_flush(void) @@ -332,7 +333,7 @@ int serial_getchar(void) void serial_console_init(void) { - if (!lib_sysinfo.serial) + if (!lib_sysinfo.cb_serial) return; console_add_output_driver(&consout); diff --git a/payloads/libpayload/drivers/serial/qcs405.c b/payloads/libpayload/drivers/serial/qcs405.c index 1a7b9e901b..2ed6af1749 100644 --- a/payloads/libpayload/drivers/serial/qcs405.c +++ b/payloads/libpayload/drivers/serial/qcs405.c @@ -541,9 +541,9 @@ int serial_getchar(void) /* For simplicity's sake, let's rely on coreboot initializing the UART. */ void serial_console_init(void) { - struct cb_serial *sc_ptr = lib_sysinfo.serial; + struct cb_serial *sc_ptr = phys_to_virt(lib_sysinfo.cb_serial); - if (!sc_ptr) + if (!lib_sysinfo.cb_serial) return; uart_board_param.uart_dm_base = (void *)(uintptr_t)sc_ptr->baseaddr; diff --git a/payloads/libpayload/drivers/serial/s5p.c b/payloads/libpayload/drivers/serial/s5p.c index 6ca5dc4717..7a6f0e1c39 100644 --- a/payloads/libpayload/drivers/serial/s5p.c +++ b/payloads/libpayload/drivers/serial/s5p.c @@ -90,10 +90,12 @@ static struct console_input_driver s5p_serial_input = void serial_init(void) { - if (!lib_sysinfo.serial || !lib_sysinfo.serial->baseaddr) + const struct cb_serial *const serial = phys_to_virt(lib_sysinfo.cb_serial); + + if (!lib_sysinfo.cb_serial || !serial->baseaddr) return; - uart_regs = (struct s5p_uart *)lib_sysinfo.serial->baseaddr; + uart_regs = (struct s5p_uart *)serial->baseaddr; } void serial_console_init(void) -- cgit v1.2.3