From nobody Wed May 1 01:14:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1529077312407187.8557131782179; Fri, 15 Jun 2018 08:41:52 -0700 (PDT) Received: from localhost ([::1]:47636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTqrF-000090-Tc for importer@patchew.org; Fri, 15 Jun 2018 11:41:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTpuy-0007Wh-WC for qemu-devel@nongnu.org; Fri, 15 Jun 2018 10:41:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fTpux-0004tO-NO for qemu-devel@nongnu.org; Fri, 15 Jun 2018 10:41:37 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:43468) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fTpur-0004kG-Nu; Fri, 15 Jun 2018 10:41:29 -0400 Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E976D1A9A; Fri, 15 Jun 2018 16:41:26 +0200 (CEST) From: Kieran Bingham To: linux-renesas-soc@vger.kernel.org, qemu-devel@nongnu.org Date: Fri, 15 Jun 2018 15:41:23 +0100 Message-Id: <20180615144123.20844-1-kieran@bingham.xyz> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 213.167.242.64 X-Mailman-Approved-At: Fri, 15 Jun 2018 11:25:56 -0400 Subject: [Qemu-devel] [PATCH] [QEMU][RFC] hw/arm/sysbus-fdt: Enable rcar-gen3-scif dynamic instantiation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kieran Bingham , qemu-arm@nongnu.org, geert@glider.be, Laurent Pinchart Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Allow the provision of a Renesas R-Car Gen3 (H)SCIF controller device from the Qemu command line: -device vfio-platform,host=3De6e68000.serial,manufacturer=3Drenesas,model= =3Drcar-gen3-scif To support this, the serial device must be unbound from the host, and rebound to the vfio-platform driver: echo 1 > /sys/module/vfio/parameters/enable_unsafe_noiommu_mode echo e6e68000.serial > /sys/bus/platform/drivers/sh-sci/unbind echo vfio-platform > /sys/bus/platform/devices/e6e68000.serial/driver_ove= rride echo e6e68000.serial > /sys/bus/platform/drivers/vfio-platform/bind Ideally, this patch should be unnecessary and the FDT should be generated automatically from the host, or perhaps with the provision of a DTO, allowing the configuration to be provided externally from Q-Emu. The functionality of this patch mostly duplicates the add_rcar_gpio_fdt_node() with the exception of the gpio-controller node, and #gpio-cells. Not-Signed-off-by: Kieran Bingham --- This patch supports testing of serial device passthrough on R-Car Gen3, and is not meant to be upstreamed as is. This serves as a purpose for ongoing development and investigation into para-virtualisation of the R-Car Gen3 platforms, and highlights the extensions needed to support passing through a basic serial device to a guest. This patch and its dependencies is available at the following branch: https://github.com/kbingham/qemu.git rcar3/serial/passthrough This builds upon existing work [0] done by Geert Uytterhoeven [0] https://www.spinics.net/lists/kvm/msg163975.html --- hw/arm/sysbus-fdt.c | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c index a04e5b384c29..ec755e0f4652 100644 --- a/hw/arm/sysbus-fdt.c +++ b/hw/arm/sysbus-fdt.c @@ -477,6 +477,66 @@ static int add_rcar_gpio_fdt_node(SysBusDevice *sbdev,= void *opaque) return 0; } =20 +/** + * add_rcar_scif_fdt_node + * + * Generates a simple node with following properties: + * compatible string, regs, #gpio-cells, gpio-controller + */ +static int add_rcar_scif_fdt_node(SysBusDevice *sbdev, void *opaque) +{ + PlatformBusFDTData *data =3D opaque; + VFIOPlatformDevice *vdev =3D VFIO_PLATFORM_DEVICE(sbdev); + const char *parent_node =3D data->pbus_node_name; + VFIODevice *vbasedev =3D &vdev->vbasedev; + PlatformBusDevice *pbus =3D data->pbus; + int compat_str_len, i, irq_number; + uint32_t *reg_attr, *irq_attr; + void *fdt =3D data->fdt; + uint64_t mmio_base; + char *nodename; + + mmio_base =3D platform_bus_get_mmio_addr(pbus, sbdev, 0); + nodename =3D g_strdup_printf("%s/%s@%" PRIx64, parent_node, + vbasedev->name, mmio_base); + qemu_fdt_add_subnode(fdt, nodename); + + printf("%s - using nodename :%s\n", __func__, nodename); + + /* Add compatible */ + compat_str_len =3D strlen(vdev->compat) + 1; + qemu_fdt_setprop(fdt, nodename, "compatible", + vdev->compat, compat_str_len); + + /* Copy reg */ + reg_attr =3D g_new(uint32_t, vbasedev->num_regions * 2); + for (i =3D 0; i < vbasedev->num_regions; i++) { + mmio_base =3D platform_bus_get_mmio_addr(pbus, sbdev, i); + reg_attr[2 * i] =3D cpu_to_be32(mmio_base); + reg_attr[2 * i + 1] =3D cpu_to_be32( + memory_region_size(vdev->regions[i]->mem)); + } + qemu_fdt_setprop(fdt, nodename, "reg", reg_attr, + vbasedev->num_regions * 2 * sizeof(uint32_t)); + + /* Copy interrupts */ + irq_attr =3D g_new(uint32_t, vbasedev->num_irqs * 3); + for (i =3D 0; i < vbasedev->num_irqs; i++) { + irq_number =3D platform_bus_get_irqn(pbus, sbdev , i) + + data->irq_start; + irq_attr[3 * i] =3D cpu_to_be32(GIC_FDT_IRQ_TYPE_SPI); + irq_attr[3 * i + 1] =3D cpu_to_be32(irq_number); + irq_attr[3 * i + 2] =3D cpu_to_be32(GIC_FDT_IRQ_FLAGS_LEVEL_HI); + } + qemu_fdt_setprop(fdt, nodename, "interrupts", + irq_attr, vbasedev->num_irqs * 3 * sizeof(uint32_t)); + + g_free(irq_attr); + g_free(reg_attr); + g_free(nodename); + return 0; +} + /* manufacturer/model matching */ static bool vfio_platform_match(SysBusDevice *sbdev, const BindingEntry *entry) @@ -516,6 +576,7 @@ static const BindingEntry bindings[] =3D { TYPE_BINDING(TYPE_VFIO_AMD_XGBE, add_amd_xgbe_fdt_node), VFIO_PLATFORM_BINDING("amd", "xgbe-seattle-v1a", add_amd_xgbe_fdt_node= ), VFIO_PLATFORM_BINDING("renesas", "rcar-gen3-gpio", add_rcar_gpio_fdt_n= ode), + VFIO_PLATFORM_BINDING("renesas", "rcar-gen3-scif", add_rcar_scif_fdt_n= ode), #endif TYPE_BINDING("", NULL), /* last element */ }; --=20 2.17.1