From patchwork Tue Jun 6 17:25:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupinder Thakur X-Patchwork-Id: 103174 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp1536675qgd; Tue, 6 Jun 2017 10:27:49 -0700 (PDT) X-Received: by 10.36.7.142 with SMTP id f136mr18788019itf.97.1496770069230; Tue, 06 Jun 2017 10:27:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496770069; cv=none; d=google.com; s=arc-20160816; b=lhFttwCVokXD/igpgfppdXwvp5rDVoWSfGn0pwqFLUzbqrYYb4L0Msnx8qDFafvfZt xCOlgSPKyq8vaVOaaHanUcYGLJqJnG08CqVKMOAUzN0AbVugK17qIZuMewzt/pZ/O2Lg 466+hutQUXxBozSJeSxCxLlS+EnYDPVj66p2/DJLz/DXxJkD+vxNBI9DvWCxVYh8yYU3 FhjUX9NsB6rrk7bMjdiAVutu4zD+cEj8bVA5w1TzwFfMWYIFpydOT6gm5q1AUx6A1+8I lAo01NX0w6hcJm+orCHu61+RWVlfjzEl6aCNv+jaFqgB/BNVKkqF0h3QX9X33HkCB0oz 6o4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:message-id:date:to:from:dkim-signature :arc-authentication-results; bh=r169Wd/uWf2dGj8onqXwmT0xWM+65IOyeaEyeqYUGxc=; b=JGHfVwzDXMIjferb/zDZre4oU5W8gCT5T7+V6yHcmiB9vMTAM7cwLQoT7VhYKNiIYX 404ZbbtbJVMb6jtKRnLeufmIyMZdbE2/eOvAygjk3dD9sBEugBYaDvBvH6QmEueIm3iE T7fn+w/p5Yyu0D9u0TFiNvoCl9YjzgeQ5gdw2b7Z7HKtFLOJEU9jjHB0An9GcjnDZDGg KaJK68I0mS5Dnedz5d55iaGyxopOd0JiCX33MdiPKQP7ZI6frJslAzAJpgjATlbesNWR aIBzPs5ulh4fiXx+l3pVx/P8yxGP6fwN5urjX0ntstOO1c2d5Mi6CPeVS+fFw6I/XPyR NbJw== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id s133si35380461iod.153.2017.06.06.10.27.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Jun 2017 10:27:49 -0700 (PDT) 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 1dIIEe-0001TG-UP; Tue, 06 Jun 2017 17:25:40 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dIIEc-0001T7-W4 for xen-devel@lists.xenproject.org; Tue, 06 Jun 2017 17:25:39 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id 58/D7-03587-295E6395; Tue, 06 Jun 2017 17:25:38 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprJIsWRWlGSWpSXmKPExsXiVRtsojvxqVm kwYPDqhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa0bL5bPsBV8cKvq/XmNvYFxn2MXIySEkMJ1R 4t4J1S5GLg4WgXZmiaffV7KBOBIC71gklreeYQapkhBIk7i96SpjFyMHkF0pcXNOCESzlsTRU 7NZQeqFBJqZJL4d2MYGUsMmYCIxq0MCpEZEQEni3qrJTCA1zAIXGCV+nH/OBpIQFrCQ2Nl9C8 xmEVCVOLvyAQuIzSvgLXHr+kOovXISN891Mk9g5FvAyLCKUaM4tagstUjX0FgvqSgzPaMkNzE zR9fQwEwvN7W4ODE9NScxqVgvOT93EyMwUBiAYAfjl2UBhxglOZiURHkjL5lFCvEl5adUZiQW Z8QXleakFh9ilOHgUJLgjXwClBMsSk1PrUjLzAGGLExagoNHSYR38gOgNG9xQWJucWY6ROoUo z3HhtXrvzBx3OnbACQnHdgOJA983fGFSYglLz8vVUqcVwFkqgBIW0ZpHtxQWIxdYpSVEuZlBD pTiKcgtSg3swRV/hWjOAejkjBvCsgUnsy8Erjdr4DOYgI6i++SCchZJYkIKakGxuzUB7M/3Jo 2bfPxfH1m+Xnhy/dNlzgyp4PtvJ/k97wvTvMq76/wFmvex5YrdiXqGcPdK3mPwm6/dF7wVe/o ZeYepskdNi5MzJUzLq/6MuH33CPxHBa5f/JrlzmI2AtYX9+3YrbRCnU5EdMnKVIrc5wecrxK7 uw7d3XKh6LA0IXBz89enHGC7bISS3FGoqEWc1FxIgAPJrfOrAIAAA== X-Env-Sender: bhupinder.thakur@linaro.org X-Msg-Ref: server-5.tower-27.messagelabs.com!1496769936!100875600!1 X-Originating-IP: [74.125.83.52] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 32328 invoked from network); 6 Jun 2017 17:25:37 -0000 Received: from mail-pg0-f52.google.com (HELO mail-pg0-f52.google.com) (74.125.83.52) by server-5.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 6 Jun 2017 17:25:37 -0000 Received: by mail-pg0-f52.google.com with SMTP id k71so4102178pgd.2 for ; Tue, 06 Jun 2017 10:25:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=7V8YlkQJba93x4NxGy508JNexkRgv67/j1ukLtA/n64=; b=btF4OIChW/cJJGFye908lWTUre8LPRm5HdlNPn7QT72WF9N38xp9/7ybrr8wuxB/AO kDkdg4KCLMuDejbNwCy1EzyhTOZQ0JUHq3pfb+MTof5MquVoHwyTOnGa4UAUQIIgM2f2 WSEvb5BNkLjHHtzOSy+wkAOXK+Kj6jfnoSyuI= 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=7V8YlkQJba93x4NxGy508JNexkRgv67/j1ukLtA/n64=; b=gP6XIz/g2KT19r3jcI16u5zF2P9O3TFJPWsGP3Mzym9umhJmv5mcFdaXVmvgeAy7qS vXyelD3aFlAUv7gkknjZVFctW2+lFmC0KKq4taCYcgboIaQzoE6YIgfGnWx7f8c4Jr4+ U7PhDXL87xX49EwRdK4ICTq+pUJR8opVb6ZHcW3H8NrgHWjKiPyt7B3js2dNqIOh1Nbh tzcGUXpkWJ57H2k+LTnZYUhetlpWeyb6eilzXwMp/u7bEz4jzEpHzzcxo9dounWXGiZs PTus2DspdUxJpSypS8lPWjmx/JNGqwDMLb+/24/t0EWOf2PEEJx/maQtaJpZSsBOAJQy m8tA== X-Gm-Message-State: AODbwcCUyZQw4LZjQ/CaOsQo5Tt/AjgdF8HAVAGd6bi77EwsDF5tjqKF 3tF1jPiExroXRUVOuIRm3w== X-Received: by 10.99.146.86 with SMTP id s22mr23197723pgn.85.1496769935599; Tue, 06 Jun 2017 10:25:35 -0700 (PDT) Received: from blr-ubuntu-linaro.wlan.qualcomm.com ([103.5.19.18]) by smtp.gmail.com with ESMTPSA id 62sm6031632pfr.90.2017.06.06.10.25.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Jun 2017 10:25:35 -0700 (PDT) From: Bhupinder Thakur To: xen-devel@lists.xenproject.org Date: Tue, 6 Jun 2017 22:55:15 +0530 Message-Id: <1496769929-23355-1-git-send-email-bhupinder.thakur@linaro.org> X-Mailer: git-send-email 2.7.4 Cc: Wei Liu , Julien Grall , Stefano Stabellini , Ian Jackson Subject: [Xen-devel] [PATCH 00/14 v4] 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 =================================== Linaro has published VM System specification for ARM Processors, which provides a set of guidelines for both guest OS and hypervisor implementations, such that building OS images according to these guidelines guarantees that those images can also run on hypervisors compliant with this specification. One of the spec requirements is that the hypervisor must provide an emulated PL011 UART as a serial console which meets the minimum requirements in SBSA UART as defined in appendix B of the following ARM Server Base Architecture Document: https://static.docs.arm.com/den0029/a/Server_Base_System_Architecture_v3_1_ARM_DEN_0029A.pdf. This feature allows the Xen guests to use SBSA compliant pl011 UART as as a console. Note that SBSA pl011 UART is a subset of full featured ARM pl011 UART and supports only a subset of registers as mentioned below. It does not support rx/tx DMA. Currently, Xen supports paravirtualized (aka PV console) and an emulated serial consoles. This feature will expose an emulated SBSA pl011 UART console to the guest, which a user can access using xenconsole. 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 the backend 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 - 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 the backend 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 the backend. So essentially Xen handles the data on behalf of domU and the backend. Any data written by domU is captured by Xen and written to the TX (OUT) ring buffer and a pl011 event is raised to the backend 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. 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 the backend 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. Changes summary: 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 a new domctl API to initialize vpl011 emulation in Xen. 3. Enable vpl011 emulation for a domain based on a libxl option passed during domain creation. Toolstack ========== 1. Add a new option "vuart" in the domU configuration file to enable/disable vuart. 2. Create a SBSA UART DT node in the guest device tree. It uses a fixed vpl011 SPI IRQ number and MMIO address. 3. Call vpl011 init DOMCTL API to enable vpl011 emulation. 5. Add a new vuart xenstore node, which contains: - ring-ref - event channel - buffer limit - type Xenconsoled ============ 1. Split the domain structure to support multiple consoles. 2. Modify different APIs such as buffer_append() etc. to operate on the console structure. 3. Add support for handling multiple consoles. 4. Add support for vuart console: The vpl011 changes available at the following repo: url: ssh://git@git.linaro.org:/people/bhupinder.thakur/xen.git branch: vpl011_v4 There are some TBD items which need to be looked at in the future: 1. Currently UEFI firmware logs the output to hvc console only. How can UEFI firmware be made aware of pl011 console and how it can use it as a console instead of hvc. 2. Linux seems to have hvc console as the default console i.e. if no console is specified then it uses hvc as the console. How can an option be provided in Linux to select either hvc or pl011 as the default console. 3. ACPI support for pl011 device. CC: ij CC: wl CC: ss CC: jg CC: kw Bhupinder Thakur (14): xen/arm: vpl011: Move vgic register access functions to vreg.h xen/arm: vpl011: Define generic vreg_reg* access functions in vreg.h xen/arm: vpl011: Add pl011 uart emulation in Xen xen/arm: vpl011: Add support for vuart in libxl xen/arm: vpl011: Allocate a new GFN in the toolstack for vuart xen/arm: vpl011: Add a new domctl API to initialize vpl011 xen/arm: vpl011: Add a new vuart node in the xenstore xen/arm: vpl011: Modify xenconsole to define and use a new console structure xen/arm: vpl011: Modify xenconsole functions to take console structure as input xen/arm: vpl011: Modify xenconsole to support multiple consoles xen/arm: vpl011: Add support for vuart console in xenconsole xen/arm: vpl011: Add a new vuart console type to xenconsole client xen/arm: vpl011: Add a pl011 uart DT node in the guest device tree xen/arm: vpl011: Update documentation for vuart console support config/arm32.mk | 1 + config/arm64.mk | 1 + docs/man/xl.cfg.pod.5.in | 9 + docs/misc/console.txt | 44 ++- tools/console/Makefile | 4 +- tools/console/client/main.c | 25 +- tools/console/daemon/io.c | 544 ++++++++++++++++++++++++----------- tools/libxc/include/xc_dom.h | 3 + tools/libxc/include/xenctrl.h | 17 ++ tools/libxc/xc_dom_arm.c | 12 +- tools/libxc/xc_dom_boot.c | 2 + tools/libxc/xc_domain.c | 23 ++ tools/libxl/libxl.h | 6 + tools/libxl/libxl_arch.h | 7 + tools/libxl/libxl_arm.c | 71 ++++- tools/libxl/libxl_console.c | 47 +++ tools/libxl/libxl_create.c | 12 +- tools/libxl/libxl_device.c | 9 +- tools/libxl/libxl_dom.c | 8 +- tools/libxl/libxl_internal.h | 7 + tools/libxl/libxl_types.idl | 7 + tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/libxl_x86.c | 8 + tools/xl/Makefile | 4 + tools/xl/xl_cmdtable.c | 4 + tools/xl/xl_console.c | 11 +- tools/xl/xl_parse.c | 8 + xen/arch/arm/Kconfig | 5 + xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 2 + xen/arch/arm/domctl.c | 44 ++- xen/arch/arm/vgic-v2.c | 28 +- xen/arch/arm/vgic-v3.c | 40 +-- xen/arch/arm/vpl011.c | 418 +++++++++++++++++++++++++++ xen/include/asm-arm/domain.h | 6 + xen/include/asm-arm/pl011-uart.h | 2 + xen/include/asm-arm/vgic.h | 111 +------ xen/include/asm-arm/vpl011.h | 74 +++++ xen/include/asm-arm/vreg.h | 109 +++++++ xen/include/public/arch-arm.h | 6 + xen/include/public/domctl.h | 12 + xen/include/public/io/console.h | 4 + 42 files changed, 1421 insertions(+), 336 deletions(-) create mode 100644 xen/arch/arm/vpl011.c create mode 100644 xen/include/asm-arm/vpl011.h