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 <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/43577
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
Nico Huber 2020-07-18 14:54:47 +02:00 committed by Patrick Georgi
parent b2eafa666c
commit be842cb72d
8 changed files with 16 additions and 17 deletions

View File

@ -132,9 +132,9 @@ void serial_init(void)
void serial_console_init(void) void serial_console_init(void)
{ {
if (!lib_sysinfo.serial) if (!lib_sysinfo.cb_serial)
return; return;
cb_serial = *lib_sysinfo.serial; cb_serial = *(struct cb_serial *)phys_to_virt(lib_sysinfo.cb_serial);
serial_init(); serial_init();

View File

@ -553,9 +553,7 @@ static struct console_output_driver consout = {};
/* For simplicity's sake, let's rely on coreboot initializing the UART. */ /* For simplicity's sake, let's rely on coreboot initializing the UART. */
void serial_console_init(void) void serial_console_init(void)
{ {
struct cb_serial *sc_ptr = lib_sysinfo.serial; if (!lib_sysinfo.cb_serial)
if (!sc_ptr)
return; return;
consin.havekey = serial_havechar; consin.havekey = serial_havechar;

View File

@ -343,9 +343,9 @@ int serial_getchar(void)
/* For simplicity's sake, let's rely on coreboot initializing the UART. */ /* For simplicity's sake, let's rely on coreboot initializing the UART. */
void serial_console_init(void) 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; return;
base_uart_addr = (void *) sc_ptr->baseaddr; base_uart_addr = (void *) sc_ptr->baseaddr;

View File

@ -275,7 +275,8 @@ static struct console_output_driver consout = {
static struct qup_regs *uart_base_address(void) 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) static void uart_qupv3_tx_flush(void)
@ -332,7 +333,7 @@ int serial_getchar(void)
void serial_console_init(void) void serial_console_init(void)
{ {
if (!lib_sysinfo.serial) if (!lib_sysinfo.cb_serial)
return; return;
console_add_output_driver(&consout); console_add_output_driver(&consout);

View File

@ -541,9 +541,9 @@ int serial_getchar(void)
/* For simplicity's sake, let's rely on coreboot initializing the UART. */ /* For simplicity's sake, let's rely on coreboot initializing the UART. */
void serial_console_init(void) 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; return;
uart_board_param.uart_dm_base = (void *)(uintptr_t)sc_ptr->baseaddr; uart_board_param.uart_dm_base = (void *)(uintptr_t)sc_ptr->baseaddr;

View File

@ -90,10 +90,12 @@ static struct console_input_driver s5p_serial_input =
void serial_init(void) 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; return;
uart_regs = (struct s5p_uart *)lib_sysinfo.serial->baseaddr; uart_regs = (struct s5p_uart *)serial->baseaddr;
} }
void serial_console_init(void) void serial_console_init(void)

View File

@ -41,8 +41,6 @@
#include <coreboot_tables.h> #include <coreboot_tables.h>
struct cb_serial;
/* /*
* All pointers in here shall be virtual. * All pointers in here shall be virtual.
* *
@ -51,7 +49,7 @@ struct cb_serial;
*/ */
struct sysinfo_t { struct sysinfo_t {
unsigned int cpu_khz; unsigned int cpu_khz;
struct cb_serial *serial; uintptr_t cb_serial;
unsigned short ser_ioport; unsigned short ser_ioport;
unsigned long ser_base; // for mmapped serial unsigned long ser_base; // for mmapped serial

View File

@ -86,7 +86,7 @@ static void cb_parse_memory(void *ptr, struct sysinfo_t *info)
static void cb_parse_serial(void *ptr, struct sysinfo_t *info) static void cb_parse_serial(void *ptr, struct sysinfo_t *info)
{ {
info->serial = ((struct cb_serial *)ptr); info->cb_serial = virt_to_phys(ptr);
} }
static void cb_parse_vboot_workbuf(unsigned char *ptr, struct sysinfo_t *info) static void cb_parse_vboot_workbuf(unsigned char *ptr, struct sysinfo_t *info)