Place uart device structures in their own section. Analogously to the recently introduced units structure, this helps us to ease the initialisation process and lets us drop out those ugly if-strcmp patterns.
Signed-off-by: Ralf Ramsauer <[email protected]> --- inmates/lib/arm-common/include/uart.h | 13 ++----------- inmates/lib/arm-common/printk.c | 25 +++++++------------------ inmates/lib/arm/inmate.lds.S | 7 +++++++ inmates/lib/arm64/inmate.lds.S | 7 +++++++ 4 files changed, 23 insertions(+), 29 deletions(-) diff --git a/inmates/lib/arm-common/include/uart.h b/inmates/lib/arm-common/include/uart.h index b55f83ea..cd9bda8a 100644 --- a/inmates/lib/arm-common/include/uart.h +++ b/inmates/lib/arm-common/include/uart.h @@ -52,19 +52,10 @@ struct uart_chip { }; #define DEFINE_UART(__name, __description) \ - struct uart_chip uart_##__name##_ops = { \ + struct uart_chip uart_##__name##_ops \ + __attribute__((section(".uarts"), used)) = { \ .name = __description, \ .init = uart_##__name##_init, \ .is_busy = uart_##__name##_is_busy, \ .write = uart_##__name##_write, \ } - -extern struct uart_chip uart_jailhouse_ops; -extern struct uart_chip uart_8250_ops; -extern struct uart_chip uart_8250_8_ops; -extern struct uart_chip uart_pl011_ops; -extern struct uart_chip uart_xuartps_ops; -extern struct uart_chip uart_mvebu_ops; -extern struct uart_chip uart_hscif_ops; -extern struct uart_chip uart_scifa_ops; -extern struct uart_chip uart_imx_ops; diff --git a/inmates/lib/arm-common/printk.c b/inmates/lib/arm-common/printk.c index 73091c36..d8312476 100644 --- a/inmates/lib/arm-common/printk.c +++ b/inmates/lib/arm-common/printk.c @@ -55,6 +55,7 @@ #define UART_IDLE_LOOPS 100 +extern struct uart_chip __uarts_array_start[0], __uarts_array_end[0]; static struct uart_chip *chip = NULL; static void console_write(const char *msg) @@ -77,29 +78,17 @@ static void console_write(const char *msg) static void console_init(void) { + struct uart_chip *c; char buf[32]; const char *type; unsigned int n; type = cmdline_parse_str("con-type", buf, sizeof(buf), CON_TYPE); - if (!strcmp(type, "JAILHOUSE")) - chip = &uart_jailhouse_ops; - else if (!strcmp(type, "8250")) - chip = &uart_8250_ops; - else if (!strcmp(type, "8250-8")) - chip = &uart_8250_8_ops; - else if (!strcmp(type, "PL011")) - chip = &uart_pl011_ops; - else if (!strcmp(type, "XUARTPS")) - chip = &uart_xuartps_ops; - else if (!strcmp(type, "MVEBU")) - chip = &uart_mvebu_ops; - else if (!strcmp(type, "HSCIF")) - chip = &uart_hscif_ops; - else if (!strcmp(type, "SCIFA")) - chip = &uart_scifa_ops; - else if (!strcmp(type, "IMX-UART")) - chip = &uart_imx_ops; + for (c = __uarts_array_start; c < __uarts_array_end; c++) + if (!strcmp(type, c->name)) { + chip = c; + break; + } if (!chip) return; diff --git a/inmates/lib/arm/inmate.lds.S b/inmates/lib/arm/inmate.lds.S index 6f64b5ed..bfb570d8 100644 --- a/inmates/lib/arm/inmate.lds.S +++ b/inmates/lib/arm/inmate.lds.S @@ -59,6 +59,13 @@ SECTIONS { *(.text) } + . = ALIGN(8); + .uarts : { + __uarts_array_start = .; + *(.uarts); + __uarts_array_end = .; + } + .rodata : { *(.rodata) } diff --git a/inmates/lib/arm64/inmate.lds.S b/inmates/lib/arm64/inmate.lds.S index a2db6ac3..dad64bc5 100644 --- a/inmates/lib/arm64/inmate.lds.S +++ b/inmates/lib/arm64/inmate.lds.S @@ -62,6 +62,13 @@ SECTIONS { *(.text) } + . = ALIGN(8); + .uarts : { + __uarts_array_start = .; + *(.uarts); + __uarts_array_end = .; + } + .rodata : { *(.rodata) } -- 2.17.0 -- You received this message because you are subscribed to the Google Groups "Jailhouse" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
