From patchwork Fri May 10 15:11:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 16864 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-fa0-f72.google.com (mail-fa0-f72.google.com [209.85.161.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EAD8F238F6 for ; Fri, 10 May 2013 15:13:15 +0000 (UTC) Received: by mail-fa0-f72.google.com with SMTP id v9sf4347364fav.11 for ; Fri, 10 May 2013 08:12:49 -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=RxjndyfrgFZq92IMselaBTs2T0bxDZrwkueqZQcDaF8=; b=CpRfsig3TtKAtdAPRveAJBEGFslGfpDPjWdPIR0EpvqpkrSB+8UO5gjesCTBnfNEHD bKDx4IP2+sxXmYv6BuZPkiuSp3B1bQsVVQ3rTfzWpzfkVTo6lI+7bXF190ErVxrUkAhU SZMX8rSLNyeXNyZyfgnbma7d9uNW3mO9CuQXHKh30TQctcQqPrNjaqVxuaqqSzWU9GCU NmIC1FC+MY0eCGoCVGzHKodMgYAK6dGMtWjtwkbjfDMAlt+WEY80S3yy+qc6g3N0uN0p p+uz8Lx/lJd9E4rUfxrJtkxdaUyO9gt0iXWb8BnOk9hsQjcBjfxJSkuz+nUTH1Mk1lvd BtTw== X-Received: by 10.180.93.42 with SMTP id cr10mr893389wib.0.1368198769497; Fri, 10 May 2013 08:12:49 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.180.183.237 with SMTP id ep13ls190047wic.2.gmail; Fri, 10 May 2013 08:12:49 -0700 (PDT) X-Received: by 10.195.13.47 with SMTP id ev15mr25474611wjd.18.1368198769384; Fri, 10 May 2013 08:12:49 -0700 (PDT) Received: from mail-ve0-x22c.google.com (mail-ve0-x22c.google.com [2607:f8b0:400c:c01::22c]) by mx.google.com with ESMTPS id cx5si772515wjc.170.2013.05.10.08.12.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 May 2013 08:12:49 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::22c is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c01::22c; Received: by mail-ve0-f172.google.com with SMTP id b10so3955571vea.31 for ; Fri, 10 May 2013 08:12:48 -0700 (PDT) X-Received: by 10.221.0.199 with SMTP id nn7mr11527729vcb.14.1368198768205; Fri, 10 May 2013 08:12:48 -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.220.217.15 with SMTP id hk15csp59270vcb; Fri, 10 May 2013 08:12:43 -0700 (PDT) X-Received: by 10.180.72.195 with SMTP id f3mr4549371wiv.32.1368198755691; Fri, 10 May 2013 08:12:35 -0700 (PDT) Received: from mail-wi0-x233.google.com (mail-wi0-x233.google.com [2a00:1450:400c:c05::233]) by mx.google.com with ESMTPS id dh6si772769wjb.165.2013.05.10.08.12.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 May 2013 08:12:35 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c05::233 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=2a00:1450:400c:c05::233; Received: by mail-wi0-f179.google.com with SMTP id hn3so739873wib.6 for ; Fri, 10 May 2013 08:12:35 -0700 (PDT) X-Received: by 10.194.178.74 with SMTP id cw10mr23128508wjc.22.1368198753038; Fri, 10 May 2013 08:12:33 -0700 (PDT) Received: from belegaer.uk.xensource.com. (firewall.ctxuk.citrix.com. [46.33.159.2]) by mx.google.com with ESMTPSA id e8sm4080359wic.5.2013.05.10.08.12.31 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 May 2013 08:12:32 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Cc: Stefano.Stabellini@eu.citrix.com, ian.campbell@citrix.com, patches@linaro.org, Julien Grall , keir@xen.org Subject: [PATCH V4 19/32] xen/arm: Add generic UART to get the device in the device tree Date: Fri, 10 May 2013 16:11:58 +0100 Message-Id: <1368198723-24639-7-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1368198723-24639-1-git-send-email-julien.grall@linaro.org> References: <1368198723-24639-1-git-send-email-julien.grall@linaro.org> X-Gm-Message-State: ALoCoQmP2SOVNunADhqcIHpBaa59Y2WIXuf/rbuLpKPov2tsNZ+JmFivX4vG9SdXqK8a6U+UoWIG X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::22c 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 Acked-by: Ian Campbell CC: keir@xen.org Changes in v3: - Rename arm-uart.c (resp. arm_uart_init) to dt-uart.c (resp. dt_uart_init) - Remove serial_arm_defaults and replace by a string options - Let the specific UART driver to get its base address in the DT - Add SERHND_DTUART. The value is stolen to SERHND_COM1. Bump the value would needs some rework... Changes in v2: - Use dtuart parameter instead of com1. The first one is more arm while the latter is more x86 Acked-by: Keir Fraser --- xen/arch/arm/setup.c | 3 +- xen/drivers/char/Makefile | 1 + xen/drivers/char/dt-uart.c | 69 ++++++++++++++++++++++++++++++++++++++++++ xen/drivers/char/serial.c | 6 ++++ xen/include/asm-arm/config.h | 2 +- xen/include/xen/serial.h | 5 ++- 6 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 xen/drivers/char/dt-uart.c diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index fc53117..2e331d3 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -436,8 +436,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 + dt_uart_init(); + console_init_preirq(); system_state = SYS_STATE_boot; diff --git a/xen/drivers/char/Makefile b/xen/drivers/char/Makefile index ab2246d..9c067f9 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) += dt-uart.o obj-y += serial.o diff --git a/xen/drivers/char/dt-uart.c b/xen/drivers/char/dt-uart.c new file mode 100644 index 0000000..93bb0f5 --- /dev/null +++ b/xen/drivers/char/dt-uart.c @@ -0,0 +1,69 @@ +/* + * xen/drivers/char/dt-uart.c + * + * Generic 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 + +/* + * Configure UART port with a string: + * alias,options + * + * @alias: alias used in the device tree for the UART + * @options: UART speficic options (see in each UART driver) + */ +static char __initdata opt_dtuart[30] = ""; +string_param("dtuart", opt_dtuart); + +void __init dt_uart_init(void) +{ + struct dt_device_node *dev; + int ret; + const char *devalias = opt_dtuart; + char *options; + + if ( !console_has("dtuart") || !strcmp(opt_dtuart, "") ) + { + early_printk("No console\n"); + return; + } + + options = strchr(opt_dtuart, ','); + if ( options != NULL ) + *(options++) = '\0'; + else + options = ""; + + 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; + } + + ret = device_init(dev, DEVICE_SERIAL, options); + + 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..e1c3f47 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_DTUART; + 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..8af3bc4 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; @@ -76,10 +77,11 @@ struct uart_driver { }; /* 'Serial handles' are composed from the following fields. */ -#define SERHND_IDX (3<<0) /* COM1, COM2, or DBGP? */ +#define SERHND_IDX (3<<0) /* COM1, COM2, DBGP, DTUART? */ # define SERHND_COM1 (0<<0) # define SERHND_COM2 (1<<0) # define SERHND_DBGP (2<<0) +# define SERHND_DTUART (0<<0) /* Steal SERHND_COM1 value */ #define SERHND_HI (1<<2) /* Mux/demux each transferred char by MSB. */ #define SERHND_LO (1<<3) /* Ditto, except that the MSB is cleared. */ #define SERHND_COOKED (1<<4) /* Newline/carriage-return translation? */ @@ -156,6 +158,7 @@ void ns16550_init(int index, struct ns16550_defaults *defaults); void ehci_dbgp_init(void); void pl011_init(int index, unsigned long register_base_address); +void __init dt_uart_init(void); struct physdev_dbgp_op; int dbgp_op(const struct physdev_dbgp_op *);