Register all uarts in an array. When initialising the console, console_init() will iterate over that array to find the appropriate driver.
Signed-off-by: Ralf Ramsauer <[email protected]> --- inmates/lib/arm-common/Makefile.lib | 2 +- inmates/lib/arm-common/include/uart.h | 15 +++---- inmates/lib/arm-common/printk.c | 24 +++------- inmates/lib/arm-common/uart.c | 63 +++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 29 deletions(-) create mode 100644 inmates/lib/arm-common/uart.c diff --git a/inmates/lib/arm-common/Makefile.lib b/inmates/lib/arm-common/Makefile.lib index 9edb2d9f..cb5a8031 100644 --- a/inmates/lib/arm-common/Makefile.lib +++ b/inmates/lib/arm-common/Makefile.lib @@ -37,7 +37,7 @@ # objs-y := ../string.o ../cmdline.o ../setup.o -objs-y += printk.o gic.o timer.o +objs-y += printk.o gic.o timer.o uart.o objs-y += uart-jailhouse.o uart-pl011.o uart-8250.o uart-8250-8.o objs-y += uart-xuartps.o uart-mvebu.o uart-hscif.o uart-scifa.o uart-imx.o objs-y += gic-v2.o gic-v3.o diff --git a/inmates/lib/arm-common/include/uart.h b/inmates/lib/arm-common/include/uart.h index bf0b6dba..25eaef5a 100644 --- a/inmates/lib/arm-common/include/uart.h +++ b/inmates/lib/arm-common/include/uart.h @@ -51,9 +51,14 @@ struct uart_chip { void (*write)(struct uart_chip*, char c); }; +extern struct uart_chip *uart_array[]; + #define UART_OPS_NAME(__name) \ uart_##__name##_ops +#define DECLARE_UART(__name) \ + extern struct uart_chip UART_OPS_NAME(__name) + #define DEFINE_UART(__name, __description) \ struct uart_chip UART_OPS_NAME(__name) = { \ .name = __description, \ @@ -61,13 +66,3 @@ struct uart_chip { .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..3c4d6211 100644 --- a/inmates/lib/arm-common/printk.c +++ b/inmates/lib/arm-common/printk.c @@ -77,29 +77,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 = uart_array; *c; c++) + if (!strcmp(type, (*c)->name)) { + chip = *c; + break; + } if (!chip) return; diff --git a/inmates/lib/arm-common/uart.c b/inmates/lib/arm-common/uart.c new file mode 100644 index 00000000..8b16e630 --- /dev/null +++ b/inmates/lib/arm-common/uart.c @@ -0,0 +1,63 @@ +/* + * Jailhouse, a Linux-based partitioning hypervisor + * + * Copyright (c) OTH Regensburg, 2018 + * + * Authors: + * Ralf Ramsauer <[email protected]> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Alternatively, you can use or redistribute this file under the following + * BSD license: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <inmate.h> +#include <uart.h> + +DECLARE_UART(8250); +DECLARE_UART(8250_8); +DECLARE_UART(hscif); +DECLARE_UART(imx); +DECLARE_UART(jailhouse); +DECLARE_UART(mvebu); +DECLARE_UART(pl011); +DECLARE_UART(scifa); +DECLARE_UART(xuartps); + +struct uart_chip *uart_array[] = { + &UART_OPS_NAME(8250), + &UART_OPS_NAME(8250_8), + &UART_OPS_NAME(hscif), + &UART_OPS_NAME(imx), + &UART_OPS_NAME(jailhouse), + &UART_OPS_NAME(mvebu), + &UART_OPS_NAME(pl011), + &UART_OPS_NAME(scifa), + &UART_OPS_NAME(xuartps), + NULL +}; -- 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.
