arm: add early_printk()
authorDavid Vrabel <david.vrabel@citrix.com>
Mon, 13 Feb 2012 14:24:49 +0000 (14:24 +0000)
committerDavid Vrabel <david.vrabel@citrix.com>
Mon, 13 Feb 2012 14:24:49 +0000 (14:24 +0000)
Add early_printk() which can be used before setup_pagetables().  This
will be used when doing the early parsing of the DTB.

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Acked-by: Tim Deegan <tim@xen.org>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
xen/arch/arm/Makefile
xen/arch/arm/early_printk.c [new file with mode: 0644]
xen/include/asm-arm/early_printk.h [new file with mode: 0644]

index b4dd3b1268935ecbc83b889c5f9b224ec404c21f..168716e16a72b7a2304a38444af6ee16f71be2a1 100644 (file)
@@ -1,6 +1,7 @@
 subdir-y += lib
 
 obj-y += dummy.o
+obj-y += early_printk.o
 obj-y += entry.o
 obj-y += domain.o
 obj-y += domain_build.o
diff --git a/xen/arch/arm/early_printk.c b/xen/arch/arm/early_printk.c
new file mode 100644 (file)
index 0000000..3e51252
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * printk() for use before the final page tables are setup.
+ *
+ * Copyright (C) 2012 Citrix Systems, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <xen/config.h>
+#include <xen/init.h>
+#include <xen/lib.h>
+#include <xen/stdarg.h>
+#include <xen/string.h>
+#include <asm/early_printk.h>
+
+#ifdef EARLY_UART_ADDRESS
+
+static void __init early_putch(char c)
+{
+    volatile uint32_t *r;
+
+    r = (uint32_t *)((EARLY_UART_ADDRESS & 0x001fffff)
+                     + XEN_VIRT_START + (1 << 21));
+
+    /* XXX: assuming a PL011 UART. */
+    while(*(r + 0x6) & 0x8)
+        ;
+    *r = c;
+}
+
+static void __init early_puts(const char *s)
+{
+    while (*s != '\0') {
+        if (*s == '\n')
+            early_putch('\r');
+        early_putch(*s);
+        s++;
+    }
+}
+
+static void __init early_vprintk(const char *fmt, va_list args)
+{
+    char buf[80];
+
+    vsnprintf(buf, sizeof(buf), fmt, args);
+    early_puts(buf);
+}
+
+void __init early_printk(const char *fmt, ...)
+{
+    va_list args;
+
+    va_start(args, fmt);
+    early_vprintk(fmt, args);
+    va_end(args);
+}
+
+void __attribute__((noreturn)) __init
+early_panic(const char *fmt, ...)
+{
+    va_list args;
+
+    va_start(args, fmt);
+    early_vprintk(fmt, args);
+    va_end(args);
+
+    while(1);
+}
+
+#endif /* #ifdef EARLY_UART_ADDRESS */
diff --git a/xen/include/asm-arm/early_printk.h b/xen/include/asm-arm/early_printk.h
new file mode 100644 (file)
index 0000000..f45f21e
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * printk() for use before the final page tables are setup.
+ *
+ * Copyright (C) 2012 Citrix Systems, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef __ARM_EARLY_PRINTK_H__
+#define __ARM_EARLY_PRINTK_H__
+
+#include <xen/config.h>
+
+#ifdef EARLY_UART_ADDRESS
+
+void early_printk(const char *fmt, ...);
+void early_panic(const char *fmt, ...);
+
+#else
+
+static inline void early_printk(const char *fmt, ...) {}
+static inline void early_panic(const char *fmt, ...) {}
+
+#endif
+
+#endif