From patchwork Thu Jun 22 07:38:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupinder Thakur X-Patchwork-Id: 106166 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp2327122qgd; Thu, 22 Jun 2017 00:41:18 -0700 (PDT) X-Received: by 10.36.112.208 with SMTP id f199mr683157itc.67.1498117278453; Thu, 22 Jun 2017 00:41:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498117278; cv=none; d=google.com; s=arc-20160816; b=ExH3V9kDKGSDF7A60ShmufZ8cv+342Ank+5GLIPkSYN4Zca+TCj1oKdZ0w0aqd9TL6 wcvX6Z1MYpj73+Mt4w2yBIT5udw8KE7+rlBguyy/5QiVd6EYPazWc9HYxkkP03ozDQXF OmqejACYVHPt/JGz9HpxzDGqejQrjvMTp0//5A4CBvV0w8zjyFbB03H52OIHXXHmP55m dvD39MwWAhzeFF2sxS7gSX9NWNa/Vlplv7l/u1Ytp2ZVSQo5HQpBJ4y2pcmiU3Qma2Uu uXesFwxvLqe/+6vdu+MMxEiShuiOwWVZJ6f0iY3RyK9k7mX2UWf3qN1Pr+raNM+fgtrF ighQ== 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=dqMPI4GPZxDy4nj7Hl7PfeF9H2Esh9xW0Cn1YEu5+xw=; b=Nbc/xCEZpo3GlolPZH6pKY1gI3VfbUcVy03M2pryQBR9IO/B5Bm/i7VYOyXJWuQvZG UALuew7z2XfMRGJh/EqNK9orNSZPAQBJrnD1AJOIVUJ2KoN9kb8bNjEsTSHjn9HruZfc haJowovWbim01jSoT+OvK9aeSOURs0aV80qzNJyeHZIzessCnebElmpJ1t3O8YlT6DL7 a/PGppSkNT4xbrmRIjG+BHQbcSR/dGToJAm4zWMXCgk5scdFkVWa/QOXwqO9oJDayX5+ 4D0HXhSvyioQHNZj2R6J2w/gR7SG7rhkINlLieYOQAHuXVKzGYg6eA9QxY/UT53kSByi KWjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=g+DDqVGM; 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 k66si739363iod.85.2017.06.22.00.41.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Jun 2017 00:41:18 -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 header.b=g+DDqVGM; 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 1dNwhj-0005Lm-QK; Thu, 22 Jun 2017 07:39:03 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNwhi-0005Lg-Eh for xen-devel@lists.xenproject.org; Thu, 22 Jun 2017 07:39:02 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 2F/3A-26749-5147B495; Thu, 22 Jun 2017 07:39:01 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprGIsWRWlGSWpSXmKPExsXiVRtspCtS4h1 pcKHZxuL7lslMDowehz9cYQlgjGLNzEvKr0hgzVjSepu54IJrxcaml2wNjOtNuxg5OYQEpjNK TD+eAGKzCLQzS/z7YQJiSwi8Y5G499sXwk6T2LviMCOEXSHx/M0JRoheLYmjp2azdjFyAdn7m CR6zq1l72Lk4GATMJGY1SEBUiMioCRxb9VkJpAaZoELjBI/zj9nA6kRFrCV2L1JDWKvqsTtxn tMIGFeAW+Jg5M5IFbJSdw818k8gZFvASPDKkaN4tSistQiXSNjvaSizPSMktzEzBxdQwNjvdz U4uLE9NScxKRiveT83E2MwBCpZ2Bg3MHYt9fvEKMkB5OSKO//PO9IIb6k/JTKjMTijPii0pzU 4kOMMhwcShK884qAcoJFqempFWmZOcBghUlLcPAoifC2gLTyFhck5hZnpkOkTjHac2xYvf4LE 8edvg1ActKB7UDywNcdX5iEWPLy81KlxHlFi4HaBEDaMkrz4IbCousSo6yUMC8jAwODEE9Bal FuZgmq/CtGcQ5GJWFefZDbeDLzSuB2vwI6iwnorBdHPEDOKklESEk1MFap3ftskaTXxOcQmGR SsvrymqMcL5O2K56aeW9N43V3/W2Fd1Vs7Ba5TjLhlFw6NZd9R7nfinPVPfsa3aXcJ4V42JvF JnClR6/K/d0lwTaPafPX3t0PlEPc3wYfj5B+teL2+6h+mS8BH6R5FA6oSmzLV963I0fHrCVD9 N3ZeqmNPzu8eoo7lFiKMxINtZiLihMBiLeYX6kCAAA= X-Env-Sender: bhupinder.thakur@linaro.org X-Msg-Ref: server-2.tower-31.messagelabs.com!1498117139!95151069!1 X-Originating-IP: [74.125.83.50] X-SpamReason: No, hits=1.3 required=7.0 tests=BODY_RANDOM_LONG,USERPASS X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 58659 invoked from network); 22 Jun 2017 07:39:00 -0000 Received: from mail-pg0-f50.google.com (HELO mail-pg0-f50.google.com) (74.125.83.50) by server-2.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 22 Jun 2017 07:39:00 -0000 Received: by mail-pg0-f50.google.com with SMTP id 132so4594778pgb.2 for ; Thu, 22 Jun 2017 00:39:00 -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=n5S1uGJf8kD9sXHQxcy7pEiiuniCKv0UVk0ypn44vik=; b=g+DDqVGMR6sksOA4kz3m5kfFkOdFRkgv2tHcXW01BSDkXtYKjzcKCUCuiwMtTUFZiQ +R3/+hFJQcPBc9/qQcmRDwujsmH1uaY0MpZHfoJ+DhyiSgj5CJYUKYZhFVwXm9zrXuJF lda+JdBAeBkavYDCoAsEyUz9S27VnXDv+DVus= 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=n5S1uGJf8kD9sXHQxcy7pEiiuniCKv0UVk0ypn44vik=; b=muBN/Endt90zfcTbobiv2BSfhfQit//J3dFEiovdRdnZKka6g13fuf71mWsAG+jJ/q rXnfmIN+wSXuy6hbyV+gaD/VidGy+JNk3/nwv//HqpS+qwl3mxznPDgXK1w3fQCL2A63 sYLD9fX+KmVFgAvxlcBIfeZaueOGd12Ub5gg/iWOZA0M9kK0oh1ndqH1xdCiID0+29NY LXXq/A8rCCXIy52edFKL1cl56JLa5uImf6SdN2Ogcq9uFK+QJmSj4k91ffhebvWJK6MT 6zjZi9NQhn55boYJu/UT7Y8k4yHn15ie3bZHNfqN0rpwb5wgnHDY6E9SPEZwdoU0AlL7 NOVw== X-Gm-Message-State: AKS2vOzjoLQkCf8oQUUWNb6X9s2use8m5aTsRr0lLmwSR1t8enXpnYCO wm9SSSIgMIqTb7wNwFtZSw== X-Received: by 10.84.132.74 with SMTP id 68mr1435111ple.190.1498117138843; Thu, 22 Jun 2017 00:38:58 -0700 (PDT) Received: from blr-ubuntu-linaro.wlan.qualcomm.com (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id w69sm1883591pfk.107.2017.06.22.00.38.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Jun 2017 00:38:58 -0700 (PDT) From: Bhupinder Thakur To: xen-devel@lists.xenproject.org Date: Thu, 22 Jun 2017 13:08:35 +0530 Message-Id: <1498117132-27139-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/17 v5] SBSA UART 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" SBSA UART 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 SBSA 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: https://git@git.linaro.org:/people/bhupinder.thakur/xen.git branch: vpl011_v5 Kindly wait for one day to checkout the code from the above URL as I am not able to push my changes from my office network. I will push the changes once I am at home. 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: Ian Jackson CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Konrad Rzeszutek Wilk Bhupinder Thakur (17): xen/arm: vpl011: Move vgic register access functions to vreg.h xen/arm: vpl011: Rename vgic_reg* functions definitions and calls to vreg_reg* xen/arm: vpl011: Define common ring buffer helper functions in console.h xen/arm: vpl011: Add SBSA UART emulation in Xen xen/arm: vpl011: Allocate a new GFN in the toolstack for vuart xen/arm: vpl011: Add support for vuart in libxl xen/arm: vpl011: Rearrange xen header includes in alphabetical order in domctl.c 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: Rename the console structure field conspath to xspath 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 | 3 +- tools/console/client/main.c | 13 +- tools/console/daemon/io.c | 658 +++++++++++++++++++++++------------ tools/libxc/include/xc_dom.h | 2 + tools/libxc/include/xenctrl.h | 20 ++ tools/libxc/xc_dom_arm.c | 5 +- tools/libxc/xc_dom_boot.c | 2 + tools/libxc/xc_domain.c | 25 ++ tools/libxl/libxl.h | 6 + tools/libxl/libxl_arch.h | 6 + tools/libxl/libxl_arm.c | 74 +++- tools/libxl/libxl_console.c | 47 +++ tools/libxl/libxl_create.c | 10 +- tools/libxl/libxl_device.c | 9 +- tools/libxl/libxl_dom.c | 5 + tools/libxl/libxl_internal.h | 6 + tools/libxl/libxl_types.idl | 7 + tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/libxl_x86.c | 8 + tools/xl/xl_cmdtable.c | 2 +- tools/xl/xl_console.c | 5 +- tools/xl/xl_parse.c | 8 + xen/arch/arm/Kconfig | 7 + xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 5 + xen/arch/arm/domctl.c | 41 ++- xen/arch/arm/vgic-v2.c | 28 +- xen/arch/arm/vgic-v3-its.c | 28 +- xen/arch/arm/vgic-v3.c | 50 +-- xen/arch/arm/vpl011.c | 449 ++++++++++++++++++++++++ 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 | 73 ++++ xen/include/asm-arm/vreg.h | 110 ++++++ xen/include/public/arch-arm.h | 6 + xen/include/public/domctl.h | 12 + xen/include/public/io/console.h | 4 + 42 files changed, 1507 insertions(+), 403 deletions(-) create mode 100644 xen/arch/arm/vpl011.c create mode 100644 xen/include/asm-arm/vpl011.h