diff mbox

[kvm-unit-tests,2/2] arm/arm64: uart0_init: check /chosen/stdout-path

Message ID 1438090020-32388-3-git-send-email-drjones@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrew Jones July 28, 2015, 1:27 p.m. UTC
Arguably all of uart0_init() is unnecessary, as we're pretty sure
that the address we initialize uart0_base to is correct. We go
through the motions of finding the uart anyway though, because it's
easy. It's also easy to check chosen/stdout-path first, so let's do
that too. But, just to make all this stuff is a little less unnecessary,
let's add a warning when we do actually find an address that doesn't
match our initializer.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm/io.c | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)
diff mbox

Patch

diff --git a/lib/arm/io.c b/lib/arm/io.c
index 8b1501886736a..db5fb5e0ce50b 100644
--- a/lib/arm/io.c
+++ b/lib/arm/io.c
@@ -21,10 +21,10 @@  extern void halt(int code);
  * having earlier printf support. We'll overwrite it with the real
  * base address that we read from the device tree later.
  */
-#define QEMU_MACH_VIRT_PL011_BASE 0x09000000UL
+#define QEMU_MACH_VIRT_PL011_EARLY_BASE 0x09000000UL
 
 static struct spinlock uart_lock;
-static volatile u8 *uart0_base = (u8 *)QEMU_MACH_VIRT_PL011_BASE;
+static volatile u8 *uart0_base = (u8 *)QEMU_MACH_VIRT_PL011_EARLY_BASE;
 
 static void uart0_init(void)
 {
@@ -32,16 +32,32 @@  static void uart0_init(void)
 	struct dt_pbus_reg base;
 	int ret;
 
-	ret = dt_pbus_get_base_compatible(compatible, &base);
-	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
+	ret = dt_get_default_console_node();
+	assert(ret >= 0 || ret == -FDT_ERR_NOTFOUND);
 
-	if (ret) {
-		printf("%s: %s not found in the device tree, aborting...\n",
-			__func__, compatible);
-		abort();
+	if (ret == -FDT_ERR_NOTFOUND) {
+
+		ret = dt_pbus_get_base_compatible(compatible, &base);
+		assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
+
+		if (ret) {
+			printf("%s: %s not found in the device tree, "
+				"aborting...\n",
+				__func__, compatible);
+			abort();
+		}
+
+	} else {
+		assert(dt_pbus_translate_node(ret, 0, &base) == 0);
 	}
 
 	uart0_base = ioremap(base.addr, base.size);
+
+	if (uart0_base != (u8 *)QEMU_MACH_VIRT_PL011_EARLY_BASE) {
+		printf("WARNING: early print support may not work. "
+		       "Found uart at %p, but early base is %p.\n",
+			uart0_base, (u8 *)QEMU_MACH_VIRT_PL011_EARLY_BASE);
+	}
 }
 
 void io_init(void)