From patchwork Wed May 8 02:33:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 16755 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f72.google.com (mail-vb0-f72.google.com [209.85.212.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1FD18238FD for ; Wed, 8 May 2013 02:35:19 +0000 (UTC) Received: by mail-vb0-f72.google.com with SMTP id q16sf1627575vbe.7 for ; Tue, 07 May 2013 19:34:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-beenthere:x-received:received-spf :x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=YU5oj/oB0dkU2EOaLBlNisyRCSK9o9lbbj7UxZNtKMI=; b=VeMTsIgFJeiJHa1qVi0vNmIKXQz8po4b9pdJmZS9L3JREaCZmD972k0wvqM8hRiJuW iVA4hAmDDJIQzjbcCkztxKGVKurVRFlGot8QD8Yb0Hsyr5g7nn5HhAN6NAR8LEffB19z sbPesZeEFaWZcN4nJdnVWivjMcEfgmqnIPa64L0IkrQNo4jJJjGI7opGWfff3/HzAtCt 0uiJMdqZbcU/+4LFSD6qcqxGJ67b6mzbggvJjleGXpEA4JxxWjwYwRtWfVshqU5dY5u6 AhNatGQmS2rwnnWHjC88E1R/B403sL/GtGqX8mwwKUN7K03hDtOlWV4Q4jXR48pRbHxB wX/Q== X-Received: by 10.224.10.6 with SMTP id n6mr6508672qan.4.1367980498966; Tue, 07 May 2013 19:34:58 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.25.18 with SMTP id y18ls674761qef.5.gmail; Tue, 07 May 2013 19:34:58 -0700 (PDT) X-Received: by 10.52.20.210 with SMTP id p18mr2653342vde.42.1367980498737; Tue, 07 May 2013 19:34:58 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id gr7si14133129vdc.116.2013.05.07.19.34.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 May 2013 19:34:58 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id ia10so1239247vcb.13 for ; Tue, 07 May 2013 19:34:58 -0700 (PDT) X-Received: by 10.58.144.170 with SMTP id sn10mr3154717veb.7.1367980498636; Tue, 07 May 2013 19:34:58 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.127.98 with SMTP id nf2csp131020veb; Tue, 7 May 2013 19:34:58 -0700 (PDT) X-Received: by 10.180.73.206 with SMTP id n14mr18337800wiv.27.1367980497399; Tue, 07 May 2013 19:34:57 -0700 (PDT) Received: from mail-wi0-x229.google.com (mail-wi0-x229.google.com [2a00:1450:400c:c05::229]) by mx.google.com with ESMTPS id az3si1335351wib.41.2013.05.07.19.34.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 May 2013 19:34:57 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c05::229 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=2a00:1450:400c:c05::229; Received: by mail-wi0-f169.google.com with SMTP id h11so4733384wiv.2 for ; Tue, 07 May 2013 19:34:56 -0700 (PDT) X-Received: by 10.194.5.196 with SMTP id u4mr7113882wju.54.1367980496866; Tue, 07 May 2013 19:34:56 -0700 (PDT) Received: from belegaer.uk.xensource.com. (firewall.ctxuk.citrix.com. [46.33.159.2]) by mx.google.com with ESMTPSA id v6sm6823630wiy.11.2013.05.07.19.34.55 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 May 2013 19:34:56 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Cc: Stefano.Stabellini@eu.citrix.com, patches@linaro.org, ian.campbell@citrix.com, Julien Grall Subject: [PATCH V2 20/33] xen/arm: Add generic UART to get the device in the device tree Date: Wed, 8 May 2013 03:33:40 +0100 Message-Id: <157508c210d09ae6a960e5f3bcf5e576316a1997.1367979526.git.julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: X-Gm-Message-State: ALoCoQni22y9/eIsBziNbjak2kjzesR9vVTF5/nM+DLAAWXkiz3iSPSDvO+bw8Gz2bTgM5M/ZM9j X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This generic UART will find the right UART via xen command line with dtuart=myserial. "myserial" is the alias of the UART in the device tree. Xen will retrieve the information via the device tree and call the initialization function for this specific UART thanks to the device API. Signed-off-by: Julien Grall Changes in v2: - Use dtuart parameter instead of com1. The first one is more arm while the latter is more x86 --- xen/arch/arm/setup.c | 3 +- xen/drivers/char/Makefile | 1 + xen/drivers/char/arm-uart.c | 81 ++++++++++++++++++++++++++++++++++++++++++ xen/drivers/char/serial.c | 6 ++++ xen/include/asm-arm/config.h | 2 +- xen/include/xen/serial.h | 7 ++++ 6 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 xen/drivers/char/arm-uart.c diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index e4228f7..7b2df8b 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -435,8 +435,9 @@ void __init start_xen(unsigned long boot_phys_offset, #ifdef EARLY_UART_ADDRESS /* TODO Need to get device tree or command line for UART address */ pl011_init(0, FIXMAP_ADDR(FIXMAP_CONSOLE)); - console_init_preirq(); #endif + arm_uart_init(); + console_init_preirq(); /* FIXME: Do something smarter */ dt_switch_to_printk(); diff --git a/xen/drivers/char/Makefile b/xen/drivers/char/Makefile index ab2246d..e68a54a 100644 --- a/xen/drivers/char/Makefile +++ b/xen/drivers/char/Makefile @@ -2,4 +2,5 @@ obj-y += console.o obj-$(HAS_NS16550) += ns16550.o obj-$(HAS_PL011) += pl011.o obj-$(HAS_EHCI) += ehci-dbgp.o +obj-$(CONFIG_ARM) += arm-uart.o obj-y += serial.o diff --git a/xen/drivers/char/arm-uart.c b/xen/drivers/char/arm-uart.c new file mode 100644 index 0000000..c76875e --- /dev/null +++ b/xen/drivers/char/arm-uart.c @@ -0,0 +1,81 @@ +/* + * xen/drivers/char/arm-uart.c + * + * Generic ARM uart retrieved via the device tree + * + * Julien Grall + * Copyright (c) 2013 Linaro Limited. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include + +/* + * Configure UART port with a string: + * alias + * + * @alias: alias used in the device tree for the UART + * TODO: Implement config in each UART driver. + */ +static char __initdata opt_dtuart[30] = ""; +string_param("dtuart", opt_dtuart); + +void __init arm_uart_init(void) +{ + struct dt_device_node *dev; + int ret; + u64 addr, size; + struct serial_arm_defaults defaults; + const char *devalias = opt_dtuart; + + if ( !console_has("dtuart") || !strcmp(opt_dtuart, "") ) + { + early_printk("No console\n"); + return; + } + + early_printk("Looking for UART console %s\n", devalias); + dev = dt_find_node_by_alias(devalias); + + if ( !dev ) + { + early_printk("Unable to find device \"%s\"\n", devalias); + return; + } + + /* TODO: Handle UART with 0 or multiple base address */ + ret = dt_device_get_address(dev, 0, &addr, &size); + if ( ret ) + { + early_printk("Unable to retrieve the base address of the serial\n"); + return; + } + + clear_fixmap(FIXMAP_CONSOLE); + set_fixmap(FIXMAP_CONSOLE, addr >> PAGE_SHIFT, DEV_SHARED); + + addr = FIXMAP_ADDR(FIXMAP_CONSOLE) + (addr & (PAGE_SIZE - 1)); + + defaults.index = 0; + defaults.register_base_address = addr; + + ret = device_init(dev, DEVICE_SERIAL, &defaults); + + if ( ret ) + early_printk("Unable to initialize serial: %d\n", ret); +} diff --git a/xen/drivers/char/serial.c b/xen/drivers/char/serial.c index 0ae7e4d..c4c4a84 100644 --- a/xen/drivers/char/serial.c +++ b/xen/drivers/char/serial.c @@ -271,6 +271,12 @@ int __init serial_parse_handle(char *conf) goto common; } + if ( !strncmp(conf, "dtuart", 5) ) + { + handle = SERHND_COM1; + goto common; + } + if ( strncmp(conf, "com", 3) ) goto fail; diff --git a/xen/include/asm-arm/config.h b/xen/include/asm-arm/config.h index 98a3a43..8ed72f5 100644 --- a/xen/include/asm-arm/config.h +++ b/xen/include/asm-arm/config.h @@ -39,7 +39,7 @@ #define CONFIG_VIDEO 1 -#define OPT_CONSOLE_STR "com1" +#define OPT_CONSOLE_STR "dtuart" #ifdef MAX_PHYS_CPUS #define NR_CPUS MAX_PHYS_CPUS diff --git a/xen/include/xen/serial.h b/xen/include/xen/serial.h index 5de5171..f548f8b 100644 --- a/xen/include/xen/serial.h +++ b/xen/include/xen/serial.h @@ -9,6 +9,7 @@ #ifndef __XEN_SERIAL_H__ #define __XEN_SERIAL_H__ +#include #include struct cpu_user_regs; @@ -156,6 +157,12 @@ void ns16550_init(int index, struct ns16550_defaults *defaults); void ehci_dbgp_init(void); void pl011_init(int index, unsigned long register_base_address); +/* Default value for UART on ARM boards */ +struct serial_arm_defaults { + int index; /* Serial index */ + unsigned long register_base_address; /* Virtual base address */ +}; +void __init arm_uart_init(void); struct physdev_dbgp_op; int dbgp_op(const struct physdev_dbgp_op *);