From patchwork Mon Jul 29 16:40:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 18647 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id ABA462395F for ; Mon, 29 Jul 2013 16:40:36 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id n1sf3494569qcx.11 for ; Mon, 29 Jul 2013 09:40:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-beenthere:x-forwarded-to:x-forwarded-for:delivered-to:message-id :date:from:user-agent:mime-version:to:cc:subject:references :in-reply-to: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 :content-type:content-transfer-encoding; bh=eH0ZZfcFhxR4mpGEvjhJLjk3bfWqCvYRyWBD1bcw+ec=; b=eauzRoeh6yHQkOJ3mpgiCC98kM9IeP/evmdCsFh5VcjAbbEFCU9i9O4KvA4WAA8USU Yv1l6XDwO8UJgP1wBvh9e84SNLdTXTtTKGPt3WdNnOIrvMjBkzzGIuNtCt8y9AhAjXnM B+vqSEuic0wo8qafvqSkvJnb8/C4nwprtN1Hu71YvggL5i2Ge/QVIAyOwsIMJ/KQiYdZ 5YVu+00xpSOqUyht63199n9Cxs/swBcXRg1TxozyfFVoqZgJBMVJ3U5x20M8b3e97tiI 98Cc5eFcR1BXSd+UK7EKspEw2IzTw4KXJsgpNGmZvreEVt54xopIZjl9mjKJy6JG60Ak Q5bQ== X-Received: by 10.236.194.33 with SMTP id l21mr30349315yhn.42.1375116036065; Mon, 29 Jul 2013 09:40:36 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.72.233 with SMTP id g9ls2115554qev.84.gmail; Mon, 29 Jul 2013 09:40:36 -0700 (PDT) X-Received: by 10.220.104.74 with SMTP id n10mr8766086vco.74.1375116035974; Mon, 29 Jul 2013 09:40:35 -0700 (PDT) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id ta3si5759140vcb.71.2013.07.29.09.40.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 29 Jul 2013 09:40:35 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.179; Received: by mail-ve0-f179.google.com with SMTP id c13so586340vea.24 for ; Mon, 29 Jul 2013 09:40:35 -0700 (PDT) X-Received: by 10.220.173.195 with SMTP id q3mr8560246vcz.86.1375116035816; Mon, 29 Jul 2013 09:40:35 -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.221.11.8 with SMTP id pc8csp125382vcb; Mon, 29 Jul 2013 09:40:34 -0700 (PDT) X-Received: by 10.15.44.203 with SMTP id z51mr60334356eev.106.1375116034424; Mon, 29 Jul 2013 09:40:34 -0700 (PDT) Received: from mail-ee0-f44.google.com (mail-ee0-f44.google.com [74.125.83.44]) by mx.google.com with ESMTPS id a48si53905578eep.143.2013.07.29.09.40.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 29 Jul 2013 09:40:34 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.83.44 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=74.125.83.44; Received: by mail-ee0-f44.google.com with SMTP id b47so683186eek.31 for ; Mon, 29 Jul 2013 09:40:33 -0700 (PDT) X-Received: by 10.15.32.67 with SMTP id z43mr61123790eeu.24.1375116033755; Mon, 29 Jul 2013 09:40:33 -0700 (PDT) Received: from [10.80.2.139] (firewall.ctxuk.citrix.com. [46.33.159.2]) by mx.google.com with ESMTPSA id n45sm103347745eew.1.2013.07.29.09.40.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 29 Jul 2013 09:40:32 -0700 (PDT) Message-ID: <51F69AFF.5060104@linaro.org> Date: Mon, 29 Jul 2013 17:40:31 +0100 From: Julien Grall User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130704 Icedove/17.0.7 MIME-Version: 1.0 To: Ian Campbell CC: xen-devel@lists.xen.org, Stefano.Stabellini@eu.citrix.com, patches@linaro.org Subject: Re: [PATCH 5/8] xen/arm: Implement a virtual UART References: <1374771574-7848-1-git-send-email-julien.grall@linaro.org> <1374771574-7848-6-git-send-email-julien.grall@linaro.org> <1375115181.11701.29.camel@kazak.uk.xensource.com> In-Reply-To: <1375115181.11701.29.camel@kazak.uk.xensource.com> X-Gm-Message-State: ALoCoQnmltXmv7Yuklf6XNQTPlF9o2zCswYY6Ndr1AKuaYxc1yWCf+0kgMj0PqrLja167sFnMe+F X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.179 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: , On 07/29/2013 05:26 PM, Ian Campbell wrote: > On Thu, 2013-07-25 at 17:59 +0100, Julien Grall wrote: >> This code is based on the previous vuart0 implementation. Unlike the latter, >> it's intend to replace UART stolen by XEN to DOM0 via dtuart=... on its >> command line. >> >> It's useful when the kernel is compiled with early printk enabled or for a >> single platform. Most of the time, the hardcoded code to handle the UART >> will need 2 registers: status and data, the others registers can be >> implemented as RAZ/WI. >> >> Signed-off-by: Julien Grall >> --- >> xen/arch/arm/Makefile | 2 +- >> xen/arch/arm/domain.c | 12 ++-- >> xen/arch/arm/io.c | 2 +- >> xen/arch/arm/io.h | 2 +- >> xen/arch/arm/vpl011.c | 152 ------------------------------------------ >> xen/arch/arm/vpl011.h | 35 ---------- >> xen/arch/arm/vuart.c | 150 +++++++++++++++++++++++++++++++++++++++++ >> xen/arch/arm/vuart.h | 35 ++++++++++ > > Please can you use the -M option to format-patch/send-email so that the > rename is handled in a way which lets us review the actual diff between > the old and new files. below the patch generated with -M option. commit d5be5261c93abac0a9c50e4bdb69883e469fd49f Author: Julien Grall Date: Thu Jul 25 17:11:59 2013 +0100 xen/arm: Implement a virtual UART This code is based on the previous vuart0 implementation. Unlike the latter, it's intend to replace UART stolen by XEN to DOM0 via dtuart=... on its command line. It's useful when the kernel is compiled with early printk enabled or for a single platform. Most of the time, the hardcoded code to handle the UART will need 2 registers: status and data, the others registers can be implemented as RAZ/WI. Signed-off-by: Julien Grall diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 5ae5831..6e1208f 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -27,7 +27,7 @@ obj-y += shutdown.o obj-y += traps.o obj-y += vgic.o obj-y += vtimer.o -obj-y += vpl011.o +obj-y += vuart.o obj-y += hvm.o obj-y += device.o diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 4e9cece..cb0424d 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -32,7 +32,7 @@ #include #include "vtimer.h" -#include "vpl011.h" +#include "vuart.h" DEFINE_PER_CPU(struct vcpu *, curr_vcpu); @@ -525,8 +525,12 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags) if ( (rc = vcpu_domain_init(d)) != 0 ) goto fail; - /* Domain 0 gets a real UART not an emulated one */ - if ( d->domain_id && (rc = domain_uart0_init(d)) != 0 ) + /* + * Virtual UART is only used by linux early printk and decompress code. + * Only use it for dom0 because the linux kernel may not support + * multi-platform. + */ + if ( (d->domain_id == 0) && (rc = domain_vuart_init(d)) ) goto fail; return 0; @@ -542,7 +546,7 @@ void arch_domain_destroy(struct domain *d) { p2m_teardown(d); domain_vgic_free(d); - domain_uart0_free(d); + domain_vuart_free(d); free_xenheap_page(d->shared_info); } diff --git a/xen/arch/arm/io.c b/xen/arch/arm/io.c index ad28c26..a6db00b 100644 --- a/xen/arch/arm/io.c +++ b/xen/arch/arm/io.c @@ -25,7 +25,7 @@ static const struct mmio_handler *const mmio_handlers[] = { &vgic_distr_mmio_handler, - &uart0_mmio_handler, + &vuart_mmio_handler, }; #define MMIO_HANDLER_NR ARRAY_SIZE(mmio_handlers) diff --git a/xen/arch/arm/io.h b/xen/arch/arm/io.h index 661dce1..8d252c0 100644 --- a/xen/arch/arm/io.h +++ b/xen/arch/arm/io.h @@ -41,7 +41,7 @@ struct mmio_handler { }; extern const struct mmio_handler vgic_distr_mmio_handler; -extern const struct mmio_handler uart0_mmio_handler; +extern const struct mmio_handler vuart_mmio_handler; extern int handle_mmio(mmio_info_t *info); diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vuart.c similarity index 51% rename from xen/arch/arm/vpl011.c rename to xen/arch/arm/vuart.c index 13ba623..5c3a84c 100644 --- a/xen/arch/arm/vpl011.c +++ b/xen/arch/arm/vuart.c @@ -1,8 +1,13 @@ /* - * xen/arch/arm/vpl011.c + * xen/arch/arm/vuart.c * - * ARM PL011 UART Emulator (DEBUG) + * Virtual UART Emulator. * + * The emulator uses the information from dtuart. It will expose a basic + * UART which will allow the guest to log with an hardcode UART (early printk + + * decompressor). + * + * Julien Grall * Ian Campbell * Copyright (c) 2012 Citrix Systems. * @@ -32,38 +37,42 @@ #include #include #include +#include +#include "vuart.h" #include "io.h" -#define UART0_START 0x1c090000 -#define UART0_END (UART0_START+65536) - -#define UARTDR 0x000 -#define UARTFR 0x018 +#define domain_has_vuart(d) ((d)->arch.vuart.info != NULL) -int domain_uart0_init(struct domain *d) +int domain_vuart_init(struct domain *d) { - ASSERT( d->domain_id ); + ASSERT( !d->domain_id ); - spin_lock_init(&d->arch.uart0.lock); - d->arch.uart0.idx = 0; + d->arch.vuart.info = serial_info(SERHND_DTUART); + if ( !d->arch.vuart.info ) + return 0; - d->arch.uart0.buf = xzalloc_array(char, VPL011_BUF_SIZE); - if ( !d->arch.uart0.buf ) + spin_lock_init(&d->arch.vuart.lock); + d->arch.vuart.idx = 0; + + d->arch.vuart.buf = xzalloc_array(char, VUART_BUF_SIZE); + if ( !d->arch.vuart.buf ) return -ENOMEM; return 0; - } -void domain_uart0_free(struct domain *d) +void domain_vuart_free(struct domain *d) { - xfree(d->arch.uart0.buf); + if ( !domain_has_vuart(d) ) + return; + + xfree(d->arch.vuart.buf); } -static void uart0_print_char(char c) +static void vuart_print_char(char c) { - struct vpl011 *uart = ¤t->domain->arch.uart0; + struct vuart *uart = ¤t->domain->arch.vuart; /* Accept only printable characters, newline, and horizontal tab. */ if ( !isprint(c) && (c != '\n') && (c != '\t') ) @@ -71,7 +80,7 @@ static void uart0_print_char(char c) spin_lock(&uart->lock); uart->buf[uart->idx++] = c; - if ( (uart->idx == (VPL011_BUF_SIZE - 2)) || (c == '\n') ) + if ( (uart->idx == (VUART_BUF_SIZE - 2)) || (c == '\n') ) { if ( c != '\n' ) uart->buf[uart->idx++] = '\n'; @@ -83,62 +92,51 @@ static void uart0_print_char(char c) spin_unlock(&uart->lock); } -static int uart0_mmio_check(struct vcpu *v, paddr_t addr) +static int vuart_mmio_check(struct vcpu *v, paddr_t addr) { - struct domain *d = v->domain; + const struct serial_info *info = v->domain->arch.vuart.info; - return d->domain_id != 0 && addr >= UART0_START && addr < UART0_END; + return (domain_has_vuart(v->domain) && addr >= info->base_addr && + addr <= (info->base_addr + info->size)); } -static int uart0_mmio_read(struct vcpu *v, mmio_info_t *info) +static int vuart_mmio_read(struct vcpu *v, mmio_info_t *info) { + struct domain *d = v->domain; struct hsr_dabt dabt = info->dabt; struct cpu_user_regs *regs = guest_cpu_user_regs(); register_t *r = select_user_reg(regs, dabt.reg); - int offset = (int)(info->gpa - UART0_START); + paddr_t offset = info->gpa - d->arch.vuart.info->base_addr; - switch ( offset ) - { - case UARTDR: - *r = 0; - return 1; - case UARTFR: - *r = 0x87; /* All holding registers empty, ready to send etc */ - return 1; - default: - printk("VPL011: unhandled read r%d offset %#08x\n", - dabt.reg, offset); - domain_crash_synchronous(); - } + /* By default zeroed the register */ + *r = 0; + + if ( offset == d->arch.vuart.info->status_off ) + /* All holding registers empty, ready to send etc */ + *r = d->arch.vuart.info->status; + + return 1; } -static int uart0_mmio_write(struct vcpu *v, mmio_info_t *info) +static int vuart_mmio_write(struct vcpu *v, mmio_info_t *info) { + struct domain *d = v->domain; struct hsr_dabt dabt = info->dabt; struct cpu_user_regs *regs = guest_cpu_user_regs(); register_t *r = select_user_reg(regs, dabt.reg); - int offset = (int)(info->gpa - UART0_START); + paddr_t offset = (int)(info->gpa - d->arch.vuart.info->base_addr); - switch ( offset ) - { - case UARTDR: + if ( offset == d->arch.vuart.info->data_off ) /* ignore any status bits */ - uart0_print_char((int)((*r) & 0xFF)); - return 1; - case UARTFR: - /* Silently ignore */ - return 1; - default: - printk("VPL011: unhandled write r%d=%"PRIregister" offset %#08x\n", - dabt.reg, *r, offset); - domain_crash_synchronous(); - } + vuart_print_char((int)((*r) & 0xFF)); + + return 1; } -const struct mmio_handler uart0_mmio_handler = { - .check_handler = uart0_mmio_check, - .read_handler = uart0_mmio_read, - .write_handler = uart0_mmio_write, +const struct mmio_handler vuart_mmio_handler = { + .check_handler = vuart_mmio_check, + .read_handler = vuart_mmio_read, + .write_handler = vuart_mmio_write, }; /* diff --git a/xen/arch/arm/vpl011.h b/xen/arch/arm/vuart.h similarity index 75% rename from xen/arch/arm/vpl011.h rename to xen/arch/arm/vuart.h index f0d0a82..9445e50 100644 --- a/xen/arch/arm/vpl011.h +++ b/xen/arch/arm/vuart.h @@ -1,7 +1,7 @@ -/* - * xen/arch/arm/vpl011.h +/* + * xen/arch/arm/vuart.h * - * ARM PL011 Emulation Support + * Virtual UART Emulation Support * * Ian Campbell * Copyright (c) 2012 Citrix Systems. @@ -17,13 +17,13 @@ * GNU General Public License for more details. */ -#ifndef __ARCH_ARM_VPL011_H__ -#define __ARCH_ARM_VPL011_H__ +#ifndef __ARCH_ARM_VUART_H__ +#define __ARCH_ARM_VUART_H__ -extern int domain_uart0_init(struct domain *d); -extern void domain_uart0_free(struct domain *d); +int domain_vuart_init(struct domain *d); +void domain_vuart_free(struct domain *d); -#endif +#endif /* __ARCH_ARM_VUART_H__ */ /* * Local variables: diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index 89f88f6..394e574 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -8,6 +8,7 @@ #include #include #include +#include /* Represents state corresponding to a block of 32 interrupts */ struct vgic_irq_rank { @@ -103,12 +104,13 @@ struct arch_domain paddr_t cbase; /* CPU base address */ } vgic; - struct vpl011 { -#define VPL011_BUF_SIZE 128 - char *buf; - int idx; - spinlock_t lock; - } uart0; + struct vuart { +#define VUART_BUF_SIZE 128 + char *buf; + int idx; + const struct serial_info *info; + spinlock_t lock; + } vuart; } __cacheline_aligned;