From patchwork Fri Feb 9 15:17:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 871504 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zdMrx56VHz9s7M for ; Sat, 10 Feb 2018 04:44:48 +1100 (AEDT) Received: from localhost ([::1]:49535 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekCj8-0006k9-DV for incoming@patchwork.ozlabs.org; Fri, 09 Feb 2018 12:44:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48367) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekAyP-0001XO-7m for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:52:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ekAyM-0007hj-6B for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:52:25 -0500 Received: from newton.telenet-ops.be ([195.130.132.45]:48758) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ekAyL-0007gv-Tl for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:52:22 -0500 Received: from xavier.telenet-ops.be (xavier.telenet-ops.be [IPv6:2a02:1800:120:4::f00:14]) by newton.telenet-ops.be (Postfix) with ESMTPS id 3zdJwg1xhkzMqtr2 for ; Fri, 9 Feb 2018 16:32:51 +0100 (CET) Received: from ayla.of.borg ([84.194.111.163]) by xavier.telenet-ops.be with bizsmtp id 8fHm1x03N3XaVaC01fHmhP; Fri, 09 Feb 2018 16:17:50 +0100 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1ekAQs-0003SB-Qm; Fri, 09 Feb 2018 16:17:46 +0100 Received: from geert by ramsan with local (Exim 4.86_2) (envelope-from ) id 1ekAQs-0000lY-PH; Fri, 09 Feb 2018 16:17:46 +0100 From: Geert Uytterhoeven To: Peter Maydell , Alex Williamson Date: Fri, 9 Feb 2018 16:17:36 +0100 Message-Id: <1518189456-2873-6-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518189456-2873-1-git-send-email-geert+renesas@glider.be> References: <1518189456-2873-1-git-send-email-geert+renesas@glider.be> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.130.132.45 X-Mailman-Approved-At: Fri, 09 Feb 2018 12:38:16 -0500 Subject: [Qemu-devel] [PATCH/RFC 5/5] hw/arm/sysbus-fdt: Enable rcar-gen3-gpio 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: Geert Uytterhoeven , Arnd Bergmann , Wolfram Sang , Magnus Damm , Alexander Graf , qemu-devel@nongnu.org, linux-renesas-soc@vger.kernel.org, Auger Eric , qemu-arm@nongnu.org, Laurent Pinchart , Xiao Feng Ren Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Allow the instantiation of a Renesas R-Car Gen3 GPIO controller device from the QEMU command line: -device vfio-platform,host=,manufacturer=renesas,model=rcar-gen3-gpio -device vfio-platform,sysfsdev=,manufacturer=renesas,model=rcar-gen3-gpio A specialized device tree node is created for the guest, containing compatible, reg, gpio-controller, and #gpio-cells properties. Not-Yet-Signed-off-by: Geert Uytterhoeven --- Question: - Why do we need the manufacturer=foo,model=bar syntax? Can't this just be extracted from the host DT? TODO: - Copy properties from the host DT, as add_amd_xgbe_fdt_node() does, - Make this more generic? --- hw/arm/sysbus-fdt.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c index c5d4fd5604c28118..428175f343d9f3b9 100644 --- a/hw/arm/sysbus-fdt.c +++ b/hw/arm/sysbus-fdt.c @@ -416,6 +416,52 @@ static int add_amd_xgbe_fdt_node(SysBusDevice *sbdev, void *opaque) return 0; } +/** + * add_rcar_gpio_fdt_node + * + * Generates a simple node with following properties: + * compatible string, regs, #gpio-cells, gpio-controller + */ +static int add_rcar_gpio_fdt_node(SysBusDevice *sbdev, void *opaque) +{ + PlatformBusFDTData *data = opaque; + PlatformBusDevice *pbus = data->pbus; + void *fdt = data->fdt; + const char *parent_node = data->pbus_node_name; + int compat_str_len, i; + char *nodename; + uint32_t *reg_attr; + uint64_t mmio_base; + VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev); + VFIODevice *vbasedev = &vdev->vbasedev; + + mmio_base = platform_bus_get_mmio_addr(pbus, sbdev, 0); + nodename = g_strdup_printf("%s/%s@%" PRIx64, parent_node, + vbasedev->name, mmio_base); + qemu_fdt_add_subnode(fdt, nodename); + + compat_str_len = strlen(vdev->compat) + 1; + qemu_fdt_setprop(fdt, nodename, "compatible", + vdev->compat, compat_str_len); + + qemu_fdt_setprop(fdt, nodename, "gpio-controller", NULL, 0); + qemu_fdt_setprop_cells(fdt, nodename, "#gpio-cells", 2); + + reg_attr = g_new(uint32_t, vbasedev->num_regions * 2); + for (i = 0; i < vbasedev->num_regions; i++) { + mmio_base = platform_bus_get_mmio_addr(pbus, sbdev, i); + reg_attr[2 * i] = cpu_to_be32(mmio_base); + reg_attr[2 * i + 1] = 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)); + + g_free(reg_attr); + g_free(nodename); + return 0; +} + /* manufacturer/model matching */ static bool vfio_platform_match(SysBusDevice *sbdev, const BindingEntry *entry) @@ -454,6 +500,7 @@ static const BindingEntry bindings[] = { TYPE_BINDING(TYPE_VFIO_CALXEDA_XGMAC, add_calxeda_midway_xgmac_fdt_node), 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_node), #endif TYPE_BINDING("", NULL), /* last element */ };