From patchwork Wed Jul 29 07:39:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 6890141 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4FDDFC05AC for ; Wed, 29 Jul 2015 07:39:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 71530207CE for ; Wed, 29 Jul 2015 07:39:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 79FCC207D1 for ; Wed, 29 Jul 2015 07:39:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752807AbbG2HjS (ORCPT ); Wed, 29 Jul 2015 03:39:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37169 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752062AbbG2HjR (ORCPT ); Wed, 29 Jul 2015 03:39:17 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 83784350119 for ; Wed, 29 Jul 2015 07:39:17 +0000 (UTC) Received: from hawk.localdomain.com (ovpn-204-38.brq.redhat.com [10.40.204.38]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6T7dCJu012468; Wed, 29 Jul 2015 03:39:16 -0400 From: Andrew Jones To: kvm@vger.kernel.org Cc: pbonzini@redhat.com Subject: [kvm-unit-tests PATCH v2 2/2] arm/arm64: uart0_init: check /chosen/stdout-path Date: Wed, 29 Jul 2015 09:39:10 +0200 Message-Id: <1438155550-6676-3-git-send-email-drjones@redhat.com> In-Reply-To: <1438155550-6676-1-git-send-email-drjones@redhat.com> References: <1438155550-6676-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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 --- lib/arm/io.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/arm/io.c b/lib/arm/io.c index 8b1501886736a..a08d394e4aa1c 100644 --- a/lib/arm/io.c +++ b/lib/arm/io.c @@ -19,12 +19,14 @@ extern void halt(int code); /* * Use this guess for the pl011 base in order to make an attempt at * having earlier printf support. We'll overwrite it with the real - * base address that we read from the device tree later. + * base address that we read from the device tree later. This is + * the address we expect QEMU's mach-virt machine type to put in + * its generated device tree. */ -#define QEMU_MACH_VIRT_PL011_BASE 0x09000000UL +#define UART_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 *)UART_EARLY_BASE; static void uart0_init(void) { @@ -32,16 +34,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 *)UART_EARLY_BASE) { + printf("WARNING: early print support may not work. " + "Found uart at %p, but early base is %p.\n", + uart0_base, (u8 *)UART_EARLY_BASE); + } } void io_init(void)