From patchwork Thu Aug 1 16:09:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 18726 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ye0-f198.google.com (mail-ye0-f198.google.com [209.85.213.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 81435246CC for ; Thu, 1 Aug 2013 16:09:53 +0000 (UTC) Received: by mail-ye0-f198.google.com with SMTP id m12sf2409275yen.5 for ; Thu, 01 Aug 2013 09:09:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-removed-original-auth :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=86tYE16jvR1ScnTb5QIUI+/xbt63AOcicgfacOCCqa8=; b=Xb+QG4gY7xd/BVAy2OfCKSCkpi/thglxqgykOTq+LrTF05pVIfzN06zDZdaGAQ0gpw 5367+JUMF3WABMJiIcn5Fkx+iqfgAwL5Qa4hMlmF80DlZhE4d1WXGB3ToBC1oA2K53FH W9FR1muqeJPCPAzp1Q+EdmYG+3OJ0ptLn9AHmGxljOlE8WHCczojScY1xott0kM3Mezq MRYdCpJp8JxVJ5IOU3/S8j3UdMPPz/DiMTXcZDsWiF4JhQC/HJjZCY9KapCUTDhjNHmT TqGkbqwlCJI2U3ZqPX3IRNgQelsRBWbFKkqH7CHlsWKWmhSp6rq3lxAUzlTFcuUTjtxl QbLw== X-Received: by 10.236.112.33 with SMTP id x21mr804241yhg.57.1375373393282; Thu, 01 Aug 2013 09:09:53 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.39.230 with SMTP id s6ls1298956qek.53.gmail; Thu, 01 Aug 2013 09:09:53 -0700 (PDT) X-Received: by 10.52.160.197 with SMTP id xm5mr605012vdb.48.1375373393102; Thu, 01 Aug 2013 09:09:53 -0700 (PDT) Received: from mail-vb0-f53.google.com (mail-vb0-f53.google.com [209.85.212.53]) by mx.google.com with ESMTPS id xb6si773656vdb.94.2013.08.01.09.09.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 Aug 2013 09:09:53 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.53 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.53; Received: by mail-vb0-f53.google.com with SMTP id i3so2250171vbh.26 for ; Thu, 01 Aug 2013 09:09:53 -0700 (PDT) X-Received: by 10.58.6.210 with SMTP id d18mr643866vea.96.1375373392739; Thu, 01 Aug 2013 09:09:52 -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 pc8csp307260vcb; Thu, 1 Aug 2013 09:09:51 -0700 (PDT) X-Received: by 10.194.248.130 with SMTP id ym2mr1826292wjc.61.1375373391303; Thu, 01 Aug 2013 09:09:51 -0700 (PDT) Received: from mail-we0-f175.google.com (mail-we0-f175.google.com [74.125.82.175]) by mx.google.com with ESMTPS id q20si1872373wik.49.2013.08.01.09.09.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 Aug 2013 09:09:51 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.175 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=74.125.82.175; Received: by mail-we0-f175.google.com with SMTP id q58so1836444wes.6 for ; Thu, 01 Aug 2013 09:09:50 -0700 (PDT) X-Received: by 10.194.216.99 with SMTP id op3mr1896143wjc.52.1375373390544; Thu, 01 Aug 2013 09:09:50 -0700 (PDT) Received: from belegaer.uk.xensource.com. (firewall.ctxuk.citrix.com. [46.33.159.2]) by mx.google.com with ESMTPSA id a8sm4594556wie.6.2013.08.01.09.09.49 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 Aug 2013 09:09:49 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Cc: stefano.stabellini@eu.citrix.com, ian.campbell@citrix.com, patches@linaro.org, tim@xen.org, Julien Grall Subject: [PATCH v3 4/7] xen/arm: Implement a virtual UART Date: Thu, 1 Aug 2013 17:09:29 +0100 Message-Id: <1375373372-15009-5-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1375373372-15009-1-git-send-email-julien.grall@linaro.org> References: <1375373372-15009-1-git-send-email-julien.grall@linaro.org> X-Gm-Message-State: ALoCoQmG8d/SgB9VGYPSXgRB+OQSBlf52kHK6ICHonwIY2jn+L2B581da1oZbZVCWDTF2C29J2e3 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.53 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 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. This commit will also drop support of early printk (based on vexpress pl011) in the guest. Signed-off-by: Julien Grall Reviewed-by: Tim Deegan --- Changes in v3: - Fix typo - Don't use "current" in vuart_print_char - Remove unnecessary cast - Update changeset Changes in v2: - Merge and update comments - Use the renamed callback --- 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 ++++++++++ xen/include/asm-arm/domain.h | 14 ++-- 9 files changed, 204 insertions(+), 200 deletions(-) delete mode 100644 xen/arch/arm/vpl011.c delete mode 100644 xen/arch/arm/vpl011.h create mode 100644 xen/arch/arm/vuart.c create mode 100644 xen/arch/arm/vuart.h diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 5c13a65..003ac84 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 obj-y += decode.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/vpl011.c deleted file mode 100644 index 13ba623..0000000 --- a/xen/arch/arm/vpl011.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - * xen/arch/arm/vpl011.c - * - * ARM PL011 UART Emulator (DEBUG) - * - * Ian Campbell - * Copyright (c) 2012 Citrix Systems. - * - * 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. - */ - -/* - * This is not intended to be a full emulation of a PL011 - * device. Rather it is intended to provide a sufficient veneer of one - * that early code (such as Linux's boot time decompressor) which - * hardcodes output directly to such a device are able to make progress. - * - * This device is not intended to be enumerable or exposed to the OS - * (e.g. via Device Tree). - */ - -#include -#include -#include -#include -#include - -#include "io.h" - -#define UART0_START 0x1c090000 -#define UART0_END (UART0_START+65536) - -#define UARTDR 0x000 -#define UARTFR 0x018 - -int domain_uart0_init(struct domain *d) -{ - ASSERT( d->domain_id ); - - spin_lock_init(&d->arch.uart0.lock); - d->arch.uart0.idx = 0; - - d->arch.uart0.buf = xzalloc_array(char, VPL011_BUF_SIZE); - if ( !d->arch.uart0.buf ) - return -ENOMEM; - - return 0; - -} - -void domain_uart0_free(struct domain *d) -{ - xfree(d->arch.uart0.buf); -} - -static void uart0_print_char(char c) -{ - struct vpl011 *uart = ¤t->domain->arch.uart0; - - /* Accept only printable characters, newline, and horizontal tab. */ - if ( !isprint(c) && (c != '\n') && (c != '\t') ) - return ; - - spin_lock(&uart->lock); - uart->buf[uart->idx++] = c; - if ( (uart->idx == (VPL011_BUF_SIZE - 2)) || (c == '\n') ) - { - if ( c != '\n' ) - uart->buf[uart->idx++] = '\n'; - uart->buf[uart->idx] = '\0'; - printk(XENLOG_G_DEBUG "DOM%u: %s", - current->domain->domain_id, uart->buf); - uart->idx = 0; - } - spin_unlock(&uart->lock); -} - -static int uart0_mmio_check(struct vcpu *v, paddr_t addr) -{ - struct domain *d = v->domain; - - return d->domain_id != 0 && addr >= UART0_START && addr < UART0_END; -} - -static int uart0_mmio_read(struct vcpu *v, mmio_info_t *info) -{ - 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); - - 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(); - } -} - -static int uart0_mmio_write(struct vcpu *v, mmio_info_t *info) -{ - 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); - - switch ( offset ) - { - case UARTDR: - /* 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(); - } -} - -const struct mmio_handler uart0_mmio_handler = { - .check_handler = uart0_mmio_check, - .read_handler = uart0_mmio_read, - .write_handler = uart0_mmio_write, -}; - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - */ - diff --git a/xen/arch/arm/vpl011.h b/xen/arch/arm/vpl011.h deleted file mode 100644 index f0d0a82..0000000 --- a/xen/arch/arm/vpl011.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * xen/arch/arm/vpl011.h - * - * ARM PL011 Emulation Support - * - * Ian Campbell - * Copyright (c) 2012 Citrix Systems. - * - * 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. - */ - -#ifndef __ARCH_ARM_VPL011_H__ -#define __ARCH_ARM_VPL011_H__ - -extern int domain_uart0_init(struct domain *d); -extern void domain_uart0_free(struct domain *d); - -#endif - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/xen/arch/arm/vuart.c b/xen/arch/arm/vuart.c new file mode 100644 index 0000000..b9d3ced --- /dev/null +++ b/xen/arch/arm/vuart.c @@ -0,0 +1,150 @@ +/* + * xen/arch/arm/vuart.c + * + * Virtual UART Emulator. + * + * This emulator uses the information from dtuart. This is not intended to be + * a full emulation of an UART device. Rather it is intended to provide a + * sufficient veneer of one that early code (such as Linux's boot time + * decompressor) which hardcodes output directly to such a device are able to + * make progress. + * + * The minimal register set to emulate an UART are: + * - Single byte transmit register + * - Single status register + * + * /!\ This device is not intended to be enumerable or exposed to the OS + * (e.g. via Device Tree). + * + * Julien Grall + * Ian Campbell + * Copyright (c) 2012 Citrix Systems. + * + * 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 "vuart.h" +#include "io.h" + +#define domain_has_vuart(d) ((d)->arch.vuart.info != NULL) + +int domain_vuart_init(struct domain *d) +{ + ASSERT( !d->domain_id ); + + d->arch.vuart.info = serial_vuart_info(SERHND_DTUART); + if ( !d->arch.vuart.info ) + return 0; + + 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_vuart_free(struct domain *d) +{ + if ( !domain_has_vuart(d) ) + return; + + xfree(d->arch.vuart.buf); +} + +static void vuart_print_char(struct vcpu *v, char c) +{ + struct domain *d = v->domain; + struct vuart *uart = &d->arch.vuart; + + /* Accept only printable characters, newline, and horizontal tab. */ + if ( !isprint(c) && (c != '\n') && (c != '\t') ) + return ; + + spin_lock(&uart->lock); + uart->buf[uart->idx++] = c; + if ( (uart->idx == (VUART_BUF_SIZE - 2)) || (c == '\n') ) + { + if ( c != '\n' ) + uart->buf[uart->idx++] = '\n'; + uart->buf[uart->idx] = '\0'; + printk(XENLOG_G_DEBUG "DOM%u: %s", d->domain_id, uart->buf); + uart->idx = 0; + } + spin_unlock(&uart->lock); +} + +static int vuart_mmio_check(struct vcpu *v, paddr_t addr) +{ + const struct vuart_info *info = v->domain->arch.vuart.info; + + return (domain_has_vuart(v->domain) && addr >= info->base_addr && + addr <= (info->base_addr + info->size)); +} + +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); + paddr_t offset = info->gpa - d->arch.vuart.info->base_addr; + + /* 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 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); + paddr_t offset = info->gpa - d->arch.vuart.info->base_addr; + + if ( offset == d->arch.vuart.info->data_off ) + /* ignore any status bits */ + vuart_print_char(v, *r & 0xFF); + + return 1; +} + +const struct mmio_handler vuart_mmio_handler = { + .check_handler = vuart_mmio_check, + .read_handler = vuart_mmio_read, + .write_handler = vuart_mmio_write, +}; + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ + diff --git a/xen/arch/arm/vuart.h b/xen/arch/arm/vuart.h new file mode 100644 index 0000000..9445e50 --- /dev/null +++ b/xen/arch/arm/vuart.h @@ -0,0 +1,35 @@ +/* + * xen/arch/arm/vuart.h + * + * Virtual UART Emulation Support + * + * Ian Campbell + * Copyright (c) 2012 Citrix Systems. + * + * 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. + */ + +#ifndef __ARCH_ARM_VUART_H__ +#define __ARCH_ARM_VUART_H__ + +int domain_vuart_init(struct domain *d); +void domain_vuart_free(struct domain *d); + +#endif /* __ARCH_ARM_VUART_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index 89f88f6..67bfbbc 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 vuart_info *info; + spinlock_t lock; + } vuart; } __cacheline_aligned;