From patchwork Tue Feb 21 11:25:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupinder Thakur X-Patchwork-Id: 94256 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp396467qgi; Tue, 21 Feb 2017 03:28:15 -0800 (PST) X-Received: by 10.107.19.40 with SMTP id b40mr19872790ioj.66.1487676495462; Tue, 21 Feb 2017 03:28:15 -0800 (PST) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id c74si10995015itb.125.2017.02.21.03.28.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Feb 2017 03:28:15 -0800 (PST) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cg8aL-0002gD-FG; Tue, 21 Feb 2017 11:26:21 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cg8aJ-0002g3-JG for xen-devel@lists.xenproject.org; Tue, 21 Feb 2017 11:26:19 +0000 Received: from [85.158.137.68] by server-4.bemta-3.messagelabs.com id 3E/F5-01392-AD32CA85; Tue, 21 Feb 2017 11:26:18 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprMIsWRWlGSWpSXmKPExsXiVRusqXtLeU2 EwdxP/Bbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8alh/PZC/rNK1r/zWFuYLyj1cXIxSEkMJNR YvePpWwgDotAO7PErklLmUEcCYF3LBKfz0xg7GLkBHJiJKYuPQ5lV0qc+XaBDcQWEtCSOHpqN ivEqFYmiaub9wMlODjYBEwkZnVIgNSICChJ3Fs1mQnEZhYIlfj3rI0dxBYWMJVYtrWRHaScRU BV4t0dXZAwr4C3xJ8d86BWyUncPNfJPIGRbwEjwypGjeLUorLUIl1DQ72kosz0jJLcxMwcXUM DY73c1OLixPTUnMSkYr3k/NxNjMBAYQCCHYyrfzsdYpTkYFIS5c2WWhMhxJeUn1KZkVicEV9U mpNafIhRhoNDSYJ3jhJQTrAoNT21Ii0zBxiyMGkJDh4lEV5TYNgK8RYXJOYWZ6ZDpE4xWnJ82 XnmJRPHrl2XgeSdl1deMgmx5OXnpUqJ85aBzBMAacgozYMbB4urS4yyUsK8jEAHCvEUpBblZp agyr9iFOdgVBLm3Q8yhSczrwRu6yugg5iADrrpsRLkoJJEhJRUA2PElVk3ri30YXIw4clZ++r EqU9hsgKs6zuCk39aXr99LeLCHtVNBe/mM4v3vrndaiS99Ll4xfRdMnmuDfxrv2/Nm35P8rbC 95ZVW8OVS9WD1nRba894lNeW1RBkf3j1x83VSiX2AvsrODc7xx+ZeUFvskh92p6Ve1prXgkce Hnf7YxbH2uUh6kSS3FGoqEWc1FxIgD3GEKspgIAAA== X-Env-Sender: bhupinder.thakur@linaro.org X-Msg-Ref: server-11.tower-31.messagelabs.com!1487676376!55779506!1 X-Originating-IP: [74.125.83.41] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 357 invoked from network); 21 Feb 2017 11:26:17 -0000 Received: from mail-pg0-f41.google.com (HELO mail-pg0-f41.google.com) (74.125.83.41) by server-11.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 21 Feb 2017 11:26:17 -0000 Received: by mail-pg0-f41.google.com with SMTP id b129so34935803pgc.2 for ; Tue, 21 Feb 2017 03:26:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=F4NBTYFg0LLQPAPkoxqymhzJBaCzHRl4tyAaIMw7LfA=; b=MBiHxbnX711Q5KkN5utvoc5GOT1h1Ejg2gI1dOWQl7GM8rJoxfhjVl8LI7DD2lXSsy BLtwKxvoakoIyWVonZD09nDTPJ6TwpWhvX1N4Bxr3gVlgkVw5o3xJZFskTtF9aiGxCg7 szk36TYhUVxWkZHI1RiDHuUnfSY44Z/7yUP9E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=F4NBTYFg0LLQPAPkoxqymhzJBaCzHRl4tyAaIMw7LfA=; b=cIvSIswGmziIgYXMyvXF3FWbbiTeWkssoGRr2ewyYaFDxs4FcdRWgJQdawXEGnK9dm 3rIYANBgs8LwfWT/fG5enksZDaNWEbN8w66sjqchM5jgZpavslmeE6/1YLn8x80025Ay cuHv/pFycXfW/6UP0kz2qVezH6fxyCrGYKfN3khfxuEd99BWleDQ5cicO7hjU75ayxXg 1HHXH9LYDk/SNSNNYVM+YeoHvlbdSbmyICsdD/T2Kok8iex9xHmJ5ih6tQlIJs3LXV2C q+YIgyP15xePXZ3dHU12uN2oK9YWt0EFN25KA4dnWCllTuaCz4YG2sChFd0Vivp7GWKf bkkA== X-Gm-Message-State: AMke39lYGdGwB11iXfr+l95+6UZQHa7vxZNNI656ddF9pNzdvTC1ywsy+uQWAeipf9oaymAz X-Received: by 10.84.193.101 with SMTP id e92mr34019724pld.4.1487676376153; Tue, 21 Feb 2017 03:26:16 -0800 (PST) Received: from blr-ubuntu-linaro.wlan.qualcomm.com ([103.5.19.18]) by smtp.gmail.com with ESMTPSA id p66sm40508627pfb.88.2017.02.21.03.26.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Feb 2017 03:26:15 -0800 (PST) From: Bhupinder Thakur To: xen-devel@lists.xenproject.org Date: Tue, 21 Feb 2017 16:55:57 +0530 Message-Id: <1487676368-22356-1-git-send-email-bhupinder.thakur@linaro.org> X-Mailer: git-send-email 2.7.4 Cc: Julien Grall , Stefano Stabellini Subject: [Xen-devel] [PATCH 00/11] pl011 emulation support in Xen X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" PL011 emulation for guests in Xen ===================================== This feature allows the Xen guests to map their console to a SBSA compliant pl011 UART as specified in ARM Service Base System architecture, Appendix B. Currently, Xen supports paravirtualized (aka PV) and an emulated serial consoles. This feature will allow an emulated SBSA pl011 UART console, which a user can access using xenconsoled running on dom0. The device tree passed to the guest VM will contain the pl011 MMIO address range and an irq for receiving rx/tx pl011 interrupts. The device tree format is specified in Documentation/devicetree/bindings/serial/arm_sbsa_uart.txt. The Xen hypervisor will expose two types of interfaces to dom0 and domU. The interface exposed to domU will be an emulated pl011 UART by emulating the access to the following pl011 registers by the guest. - Data register (DR) - RW - Control register (CR) - RW - Raw interrupt status register (RIS) - RO - Masked interrupt status register (MIS)- RO - Interrupt Mask (IMSC) - RW - Interrupt Clear (ICR) - WO It will also inject the pl011 interrupts to the guest in the following conditions: - incoming data in the rx buffer for the guest - there is space in the tx buffer for the guest to write more data The interface exposed to dom0 will be the same PV console interface, which minimizes the changes required in xenconsole to support a new pl011 console. This interface has rx and tx ring buffers and an event channel for sending/receiving events from dom0. So essentially Xen handles the data on behalf of domU and dom0. Any data written by domU is captured by Xen and written to the TX (OUT) ring buffer and a pl011 event is raised to dom0 to read the TX ring buffer. Similarly on reciving a pl011 event, Xen injects an interrupt to guest to indicate there is data available in the RX (IN) ring buffer. Note that the pl011 UART state is completely captured in the set of registers mentioned above and this state is updated everytime there is an event from dom0 or there is register read/write access from domU. For example, if domU has masked the rx interrupt in the IMSC register, then Xen will not inject an interrupt to guest and will just update the RIS register. Once the interrupt is unmasked by guest, the interrupt will be delivered to the guest. The following changes were done: Xen Hypervisor =============== 1. Add emulation code to emulate read/write access to pl011 registers and pl011 interrupts - It emulates DR read/write by reading and writing from/to the IN and OUT ring buffers and raising an event to dom0 when there is data in the OUT ring buffer and injecting an interrupt to the guest when there is data in the IN ring buffer - Other registers are related to interrupt management and essentially control when interrupts are delivered to the guest 2. Add three new HVM param handlers for - allocating a new VIRQ and return to the toolstack - allocating a new event channel for sending/receiving events from Xen and return to the toolstack - mapping the PFN allocted by the toolstack to be used as IN/OUT ring buffers 3. Breakup evtchn_send() to allow sending events for a Xen bound channel (Currently, there is a check which disallows generating events for a Xen bound channel) 4. Enable vpl011 emulation for a domain when it is created 5. Ensuring that nr_spis is atleast 1 to allow allocation of vpl011 spi virq Toolstack ========== 1. Reading a VIRQ from Xen using a hvm call and using it for adding new device tree node in the guest DT for SBSA pl011 uart containing the IRQ and the MMIO address range to be used by the guest 2. Allocating a new PFN and passing it on to Xen though a hvm call to be used as the IN/OUT ring buffers 3. Add two new parameters to the xen store - newly allocated PFN to be used as IN/OUT ring buffer by xenconsoled - a new event channel read from Xen using a hvm call to be used by xenconsoled for eventing Xenconsoled ============ 1. Modfication in domain_create_ring() - Bind to the vpl011 event channel obtained from the xen store as a new parameter - Map the PFN to its address space to be used as IN/OUT ring buffers. It obtains the PFN from the xen store as a new parameter 2. Modificaton to handle_ring_read() and buffer_append () to allow reading data from both PV or vpl011 OUT ring buffers and add to the output buffer 3. Modification in handle_tty_read to write the user data to the vpl011 IN ring buffer There are still some items which are pending: 1. Adding dynamic enable/disable of pl011 emulation for a guest 2. Add a new console type "pl011" in xenconsoled to allow the user to connect to either PV/serial/pl011 console. 3. Add checks to ensure that the new hvm params read/written by the guest Bhupinder Thakur (11): xen/arm: vpl011: Add pl011 uart emulation in Xen xen/arm: vpl011: Add new hvm params in Xen for ring buffer/event setup xen/arm: vpl011: Refactor evtchn_send in Xen to allow sending events from a xen bound channel xen/arm: vpl011: Enable vpl011 emulation for a domain in Xen xen/arm: vpl011: Initialize nr_spis in vgic_init in Xen to atleast 1 xen/arm: vpl011: Add a new pl011 uart node in the guest DT in the toolstack xen/arm: vpl011: Add two new vpl011 parameters to xenstore xen/arm: vpl011: Allocate a new PFN in the toolstack and pass to Xen using a hvm call xen/arm: vpl011: Modify domain_create_ring in xenconsole to map the ring buffer and event channel xen/arm: vpl011: Modify handle_ring_read and buffer_append to read/append vpl011 data xen/arm: vpl011: Modify handle_tty_read in xenconsole to redirect user data to vpl011 IN ring buffer tools/console/daemon/io.c | 168 +++++++++++++++--- tools/libxc/include/xc_dom.h | 5 + tools/libxc/xc_dom_arm.c | 7 +- tools/libxc/xc_dom_boot.c | 5 + tools/libxc/xc_domain.c | 3 + tools/libxl/libxl.c | 6 + tools/libxl/libxl_arm.c | 47 +++++- tools/libxl/libxl_dom.c | 18 +- tools/libxl/libxl_internal.h | 4 + xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 8 + xen/arch/arm/hvm.c | 39 +++++ xen/arch/arm/vgic.c | 5 + xen/arch/arm/vpl011.c | 366 ++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/vpl011.h | 208 +++++++++++++++++++++++ xen/common/Kconfig | 6 + xen/common/domctl.c | 2 + xen/common/event_channel.c | 49 ++++-- xen/include/asm-arm/domain.h | 15 ++ xen/include/public/arch-arm.h | 5 + xen/include/public/hvm/params.h | 10 +- xen/include/xen/event.h | 6 + xen/include/xen/sched.h | 4 + 23 files changed, 944 insertions(+), 43 deletions(-) create mode 100644 xen/arch/arm/vpl011.c create mode 100644 xen/arch/arm/vpl011.h