Skip to content

Commit

Permalink
inmates: arm: make uart drivers runtime selectable
Browse files Browse the repository at this point in the history
Without additional cmdline arguments, inmates will use an empty debug
output driver. Following cmdline arguments can be used to select a
specific driver:

con-type
  "8250" or "PL011"

con-base
  UART-MMIO base address

con-divider
  Optional: UART divider. Zero value means to skip initialisation.
            Defaults to 0.

con-clock_reg
con-gate_nr
  Optional: Clock Register and Gate Nr

Signed-off-by: Ralf Ramsauer <ralf.ramsauer@oth-regensburg.de>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
  • Loading branch information
rralf authored and jan-kiszka committed Dec 2, 2016
1 parent d18fe64 commit d8178f3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
5 changes: 2 additions & 3 deletions inmates/lib/arm/Makefile
Expand Up @@ -16,9 +16,8 @@ always := lib.a

ccflags-y := -ffunction-sections

lib-y := header.o gic.o printk.o timer.o
lib-y := header.o gic.o printk.o timer.o \
uart-pl011.o uart-8250.o
lib-y += ../string.o ../cmdline.o
lib-$(CONFIG_ARM_GIC_V2) += gic-v2.o
lib-$(CONFIG_ARM_GIC_V3) += gic-v3.o
lib-$(CONFIG_SERIAL_AMBA_PL011) += uart-pl011.o
lib-$(CONFIG_SERIAL_8250) += uart-8250.o
37 changes: 32 additions & 5 deletions inmates/lib/arm/printk.c
Expand Up @@ -15,7 +15,9 @@
#include <uart.h>
#include <mach/uart.h>

extern struct uart_chip uart_ops;
static struct uart_chip *chip = NULL;

extern struct uart_chip uart_8250_ops, uart_pl011_ops;

static void console_write(const char *msg)
{
Expand All @@ -29,11 +31,34 @@ static void console_write(const char *msg)
if (!c)
break;

uart_ops.wait(&uart_ops);
uart_ops.write(&uart_ops, c);
chip->wait(chip);
chip->write(chip, c);
}
}

static void console_init(void)
{
char buf[32];
const char *type;

type = cmdline_parse_str("con-type", buf, sizeof(buf), "none");
if (!strncmp(type, "8250", 4))
chip = &uart_8250_ops;
else if (!strncmp(type, "PL011", 5))
chip = &uart_pl011_ops;

if (!chip)
return;

chip->base = (void *)(unsigned long) cmdline_parse_int("con-base", 0);
chip->divider = cmdline_parse_int("con-divider", 0);
chip->gate_nr = cmdline_parse_int("con-gate_nr", 0);
chip->clock_reg = (void *)(unsigned long)
cmdline_parse_int("con-clock_reg", 0);

chip->init(chip);
}

#include "../../../hypervisor/printk-core.c"

void printk(const char *fmt, ...)
Expand All @@ -42,11 +67,13 @@ void printk(const char *fmt, ...)
va_list ap;

if (!inited) {
uart_ops.base = UART_BASE;
uart_ops.init(&uart_ops);
console_init();
inited = true;
}

if (!chip)
return;

va_start(ap, fmt);

__vprintk(fmt, ap);
Expand Down
2 changes: 1 addition & 1 deletion inmates/lib/arm/uart-8250.c
Expand Up @@ -51,7 +51,7 @@ static void uart_write(struct uart_chip *chip, char c)
mmio_write32(chip->base + UART_TX, c);
}

struct uart_chip uart_ops = {
struct uart_chip uart_8250_ops = {
.init = uart_init,
.wait = uart_wait,
.write = uart_write,
Expand Down
2 changes: 1 addition & 1 deletion inmates/lib/arm/uart-pl011.c
Expand Up @@ -66,7 +66,7 @@ static void uart_write(struct uart_chip *chip, char c)
mmio_write32(chip->base + UARTDR, c);
}

struct uart_chip uart_ops = {
struct uart_chip uart_pl011_ops = {
.init = uart_init,
.wait = uart_wait,
.write = uart_write,
Expand Down
3 changes: 1 addition & 2 deletions inmates/lib/arm64/Makefile
Expand Up @@ -17,6 +17,5 @@ always := lib.a
lib-y := header.o
lib-y += ../arm/gic.o ../arm/printk.o ../arm/timer.o
lib-y += ../string.o ../cmdline.o
lib-y += ../arm/uart-pl011.o ../arm/uart-8250.o
lib-$(CONFIG_ARM_GIC_V2) += ../arm/gic-v2.o
lib-$(CONFIG_SERIAL_AMBA_PL011) += ../arm/uart-pl011.o
lib-$(CONFIG_SERIAL_8250) += ../arm/uart-8250.o

0 comments on commit d8178f3

Please sign in to comment.