From patchwork Sun Apr 28 23:02:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 16484 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f72.google.com (mail-qe0-f72.google.com [209.85.128.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 11E8B2395E for ; Sun, 28 Apr 2013 23:03:45 +0000 (UTC) Received: by mail-qe0-f72.google.com with SMTP id 9sf6859685qea.11 for ; Sun, 28 Apr 2013 16:02:44 -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=HNKVuv2c1jvGwnQJKitjfBMFupCzCzLPWt7rjKjwKIU=; b=GY0IjxHigKFjaiwqE2J5HdJmWYqWYAXjs3f12PFr8xtAwSd6JAJPP85e0gq/IJQixF hKKkg2U1PPIrm1QJkOdXkQ/rgzdW0qB5oP2JZxJKVv5O80aqZmGmXYaXfYlSe9K0NvmV vQuDU6Okdn9jc5+CFfRVOaZU3DSULvM9Z+YrWDJWpbtYyJL6/mnDdSp0sLOoe0kK+eaK DeQuCYOeAmhsIFCvTmPOmwKVxhzdOJTp//NEeUxWMrO7eaD02b5Sm75BcrinOTuUMaeu sW7V1yPx0dtQN/pPdtZIQM4q4hVejRdyHbzUyafHaNrf150Lyp0qri1xLmfFxXQcqr/P Stjw== X-Received: by 10.224.18.133 with SMTP id w5mr8498912qaa.1.1367190163974; Sun, 28 Apr 2013 16:02:43 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.119.129 with SMTP id ku1ls901053qeb.49.gmail; Sun, 28 Apr 2013 16:02:43 -0700 (PDT) X-Received: by 10.58.164.131 with SMTP id yq3mr32441117veb.31.1367190163793; Sun, 28 Apr 2013 16:02:43 -0700 (PDT) Received: from mail-ve0-x234.google.com (mail-ve0-x234.google.com [2607:f8b0:400c:c01::234]) by mx.google.com with ESMTPS id u8si8976962vck.29.2013.04.28.16.02.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 28 Apr 2013 16:02:43 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::234 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::234; Received: by mail-ve0-f180.google.com with SMTP id pb11so2663557veb.39 for ; Sun, 28 Apr 2013 16:02:43 -0700 (PDT) X-Received: by 10.52.228.71 with SMTP id sg7mr26627590vdc.51.1367190163637; Sun, 28 Apr 2013 16:02:43 -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 nf2csp33801veb; Sun, 28 Apr 2013 16:02:42 -0700 (PDT) X-Received: by 10.180.210.225 with SMTP id mx1mr14236829wic.15.1367190161381; Sun, 28 Apr 2013 16:02:41 -0700 (PDT) Received: from mail-we0-x232.google.com (mail-we0-x232.google.com [2a00:1450:400c:c03::232]) by mx.google.com with ESMTPS id n6si2003533wjw.242.2013.04.28.16.02.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 28 Apr 2013 16:02:41 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c03::232 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=2a00:1450:400c:c03::232; Received: by mail-we0-f178.google.com with SMTP id t11so1685959wey.37 for ; Sun, 28 Apr 2013 16:02:41 -0700 (PDT) X-Received: by 10.180.205.226 with SMTP id lj2mr14170998wic.5.1367190160990; Sun, 28 Apr 2013 16:02:40 -0700 (PDT) Received: from belegaer.uk.xensource.com. (firewall.ctxuk.citrix.com. [46.33.159.2]) by mx.google.com with ESMTPSA id k5sm18711393wiy.5.2013.04.28.16.02.39 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 28 Apr 2013 16:02:40 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Cc: ian.campbell@citrix.com, patches@linaro.org, anthony.perard@citrix.com, stefano.stabellini@eu.citrix.com, Julien Grall Subject: [RFC 18/29] xen/arm: add generic UART to get the device in the device tree Date: Mon, 29 Apr 2013 00:02:01 +0100 Message-Id: X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: X-Gm-Message-State: ALoCoQm9GlyWSj0G2G/X9GD3vuP+XQ+hNRXwBEFHF8Mt7jaKIc2uG3Pb8SGwRe/XZ0RvifXTVxvQ X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::234 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 com1=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 --- xen/arch/arm/setup.c | 3 +- xen/drivers/char/Makefile | 1 + xen/drivers/char/arm-uart.c | 76 +++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/serial.h | 8 +++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 xen/drivers/char/arm-uart.c diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 51f4bba..e5d8724 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -434,8 +434,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..e242ae2 --- /dev/null +++ b/xen/drivers/char/arm-uart.c @@ -0,0 +1,76 @@ +/* + * 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 serial port with string: devname + * Where devname is the alias of the device in the device tree + */ +static char __initdata opt_com1[30] = ""; +string_param("com1", opt_com1); + +void __init arm_uart_init(void) +{ + struct dt_device_node *dev; + int ret; + u64 addr, size; + struct serial_arm_defaults defaults; + + if ( !console_has("com1") || !strcmp(opt_com1, "") ) + { + early_printk("No console\n"); + return; + } + + early_printk("Looking for serial console %s\n", opt_com1); + dev = dt_find_node_by_alias(opt_com1); + + if ( !dev ) + { + early_printk("Unable to find device \"%s\"\n", opt_com1); + return; + } + + 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/include/xen/serial.h b/xen/include/xen/serial.h index 5de5171..2579ce8 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,13 @@ 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 *);