From patchwork Fri Oct 31 14:05:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 405331 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 52AC514007F for ; Sat, 1 Nov 2014 02:02:07 +1100 (AEDT) Received: from localhost ([::1]:51514 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XkDiH-0005SD-Cz for incoming@patchwork.ozlabs.org; Fri, 31 Oct 2014 11:02:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XkDgy-0000xb-SU for qemu-devel@nongnu.org; Fri, 31 Oct 2014 11:00:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XkCqS-0003Ym-5i for qemu-devel@nongnu.org; Fri, 31 Oct 2014 10:06:34 -0400 Received: from mail-wi0-f176.google.com ([209.85.212.176]:60286) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XkCqR-0003Xt-TJ for qemu-devel@nongnu.org; Fri, 31 Oct 2014 10:06:28 -0400 Received: by mail-wi0-f176.google.com with SMTP id h11so1401641wiw.15 for ; Fri, 31 Oct 2014 07:06:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YXcEtjJDEsp5t05O47Y/sn06Y48ni48+EjtuHTbe9oY=; b=kGv93e8z6xfl7J0iTXrQwlfMKXU9EYjSHsXBG+YPvh5+4dG+46myWnYiweB77tkXon TDOvJOwryvVcYRvLIoHZTIrNYV+ZA75kaIUDwuePah0w/cQuOh8+eX9Dj3uUfICMB6Ns W+nM2+4Azc1amCTewATy3yh1wua7LRcJnZFmSbp4l/p35BHqpQWuEXP5s8mZveZkmFEn Vu+rD1w3+Njb+MUBM04N8tQpmzIg16/cAoU815trM4sKQgVcLyctW4W+5u8BT/XDkoUc TW1qdDpdPFY9eunNzxUDUTCfpOOhhRnx117W8kFnpHS070TwgPLnPmM/3fCvUVNy9Mj/ akYQ== X-Gm-Message-State: ALoCoQkFO4ewdF7h0NHjF3erIAZ+ZwFjPFgsP4AHwUa4x74IX5H88y+Wr6JJKDwJ+2A1RU0p7Siw X-Received: by 10.180.218.136 with SMTP id pg8mr3990436wic.37.1414764387220; Fri, 31 Oct 2014 07:06:27 -0700 (PDT) Received: from midway01-04-00.lavalab ([88.98.47.97]) by mx.google.com with ESMTPSA id v10sm12504563wiy.23.2014.10.31.07.06.26 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 07:06:26 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, christoffer.dall@linaro.org, qemu-devel@nongnu.org, agraf@suse.de, pbonzini@redhat.com, kim.phillips@freescale.com, a.rigo@virtualopensystems.com, manish.jaggi@caviumnetworks.com, joel.schopp@amd.com Date: Fri, 31 Oct 2014 14:05:46 +0000 Message-Id: <1414764350-5140-13-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1414764350-5140-1-git-send-email-eric.auger@linaro.org> References: <1414764350-5140-1-git-send-email-eric.auger@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.212.176 Cc: peter.maydell@linaro.org, patches@linaro.org, eric.auger@linaro.org, will.deacon@arm.com, stuart.yoder@freescale.com, Bharat.Bhushan@freescale.com, alex.williamson@redhat.com, a.motakis@virtualopensystems.com, kvmarm@lists.cs.columbia.edu Subject: [Qemu-devel] [PATCH v7 12/16] hw/arm/sysbus-fdt: enable vfio-calxeda-xgmac dynamic instantiation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org vfio-calxeda-xgmac now can be instantiated using the -device option. The node creation function generates a very basic dt node composed of the compat, reg and interrupts properties Signed-off-by: Eric Auger --- v6 -> v7: - compat string re-formatting removed since compat string is not exposed anymore as a user option - VFIO IRQ kick-off removed from sysbus-fdt and moved to VFIO platform device --- hw/arm/sysbus-fdt.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c index d5476f1..f8b310b 100644 --- a/hw/arm/sysbus-fdt.c +++ b/hw/arm/sysbus-fdt.c @@ -27,6 +27,8 @@ #include "hw/platform-bus.h" #include "sysemu/sysemu.h" #include "hw/platform-bus.h" +#include "hw/vfio/vfio-platform.h" +#include "hw/vfio/vfio-calxeda-xgmac.h" /* * internal struct that contains the information to create dynamic @@ -54,8 +56,11 @@ typedef struct NodeCreationPair { int (*add_fdt_node_fn)(SysBusDevice *sbdev, void *opaque); } NodeCreationPair; +static int add_basic_vfio_fdt_node(SysBusDevice *sbdev, void *opaque); + /* list of supported dynamic sysbus devices */ NodeCreationPair add_fdt_node_functions[] = { + {TYPE_VFIO_CALXEDA_XGMAC, add_basic_vfio_fdt_node}, {"", NULL}, /*last element*/ }; @@ -86,6 +91,89 @@ static int add_fdt_node(SysBusDevice *sbdev, void *opaque) } /** + * add_basic_vfio_fdt_node - generates the most basic node for a VFIO node + * + * set properties are: + * - compatible string + * - regs + * - interrupts + */ +static int add_basic_vfio_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; + char *nodename; + int i, ret; + uint32_t *irq_attr; + uint64_t *reg_attr; + uint64_t mmio_base; + uint64_t irq_number; + VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev); + VFIODevice *vbasedev = &vdev->vbasedev; + Object *obj = OBJECT(sbdev); + + mmio_base = object_property_get_int(obj, "mmio[0]", NULL); + + 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); + + reg_attr = g_new(uint64_t, vbasedev->num_regions*4); + + for (i = 0; i < vbasedev->num_regions; i++) { + mmio_base = platform_bus_get_mmio_addr(pbus, sbdev, i); + reg_attr[4*i] = 1; + reg_attr[4*i+1] = mmio_base; + reg_attr[4*i+2] = 1; + reg_attr[4*i+3] = memory_region_size(&vdev->regions[i]->mem); + } + + ret = qemu_fdt_setprop_sized_cells_from_array(fdt, nodename, "reg", + vbasedev->num_regions*2, reg_attr); + if (ret < 0) { + error_report("could not set reg property of node %s", nodename); + goto fail; + } + + irq_attr = g_new(uint32_t, vbasedev->num_irqs*3); + + for (i = 0; i < vbasedev->num_irqs; i++) { + irq_number = platform_bus_get_irqn(pbus, sbdev , i) + + data->irq_start; + irq_attr[3*i] = cpu_to_be32(0); + irq_attr[3*i+1] = cpu_to_be32(irq_number); + irq_attr[3*i+2] = cpu_to_be32(0x4); + } + + ret = qemu_fdt_setprop(fdt, nodename, "interrupts", + irq_attr, vbasedev->num_irqs*3*sizeof(uint32_t)); + if (ret < 0) { + error_report("could not set interrupts property of node %s", + nodename); + goto fail; + } + + g_free(nodename); + g_free(irq_attr); + g_free(reg_attr); + + return 0; + +fail: + + return -1; +} + +/** * add_all_platform_bus_fdt_nodes - create all the platform bus nodes * * builds the parent platform bus node and all the nodes of dynamic