From patchwork Thu Mar 19 10:05:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 46025 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f197.google.com (mail-we0-f197.google.com [74.125.82.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C04A12153C for ; Thu, 19 Mar 2015 10:06:02 +0000 (UTC) Received: by wevm14 with SMTP id m14sf4384188wev.0 for ; Thu, 19 Mar 2015 03:06:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=Hpl4iQbnFpMgebJHezY09nPxHNlRctPzdJA2xhMiK6A=; b=MokKqhxhU/g+hMOO4WjGr7/T+c7t6dygKEZOU8gPtQrrTwJck8ZcRKpkSCRS4nykDI Iv/cnKSmKcySxMNmxGi2S4S6mlD9bVoZ+O+RFAFyFGd7UtxGtQ8BhpRRQKZLmcFU5Y8U 2Vq0MPfTv1eOomdo2eJd9gEqEEClvBnknn+Ir+WF0QMU5EvoQd5TdQ5/nuZhd7zKmK0H MwoxBytbUdyGMVlct1ShGwValyWsuV6xhAaAe9krnR9odDRB/lQBNtVsEWq9WTSgCFum l6fGjOtrwqjNBMyuXrmfcqowTZE7PiZRVOpJ3HgqDRmdeiXJ9fxSjxRbIBqmT2fx775M iBLw== X-Gm-Message-State: ALoCoQmf9lrq2+SLAHk7fpc0TbYrMZ5YHjxMj7G8k4xX6aA7zuYkWECe+Y9pgol6Uxhlcj1807Mp X-Received: by 10.152.164.171 with SMTP id yr11mr8971003lab.4.1426759562064; Thu, 19 Mar 2015 03:06:02 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.164.193 with SMTP id ys1ls295096lab.39.gmail; Thu, 19 Mar 2015 03:06:01 -0700 (PDT) X-Received: by 10.152.27.39 with SMTP id q7mr66371904lag.49.1426759561856; Thu, 19 Mar 2015 03:06:01 -0700 (PDT) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id pu6si584710lbb.145.2015.03.19.03.06.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 03:06:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by lamx15 with SMTP id x15so57942558lam.3 for ; Thu, 19 Mar 2015 03:06:01 -0700 (PDT) X-Received: by 10.152.28.5 with SMTP id x5mr66949961lag.112.1426759561738; Thu, 19 Mar 2015 03:06:01 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.35.133 with SMTP id h5csp277057lbj; Thu, 19 Mar 2015 03:06:00 -0700 (PDT) X-Received: by 10.112.171.65 with SMTP id as1mr68369210lbc.45.1426759553711; Thu, 19 Mar 2015 03:05:53 -0700 (PDT) Received: from mail-we0-f177.google.com (mail-we0-f177.google.com. [74.125.82.177]) by mx.google.com with ESMTPS id ei5si2142593wib.117.2015.03.19.03.05.53 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 03:05:53 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.177 as permitted sender) client-ip=74.125.82.177; Received: by wegp1 with SMTP id p1so52993305weg.1 for ; Thu, 19 Mar 2015 03:05:53 -0700 (PDT) X-Received: by 10.194.6.228 with SMTP id e4mr148467951wja.63.1426759553446; Thu, 19 Mar 2015 03:05:53 -0700 (PDT) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id y14sm1257677wjr.39.2015.03.19.03.05.52 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Mar 2015 03:05:52 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, alex.williamson@redhat.com, peter.maydell@linaro.org, agraf@suse.de, b.reynal@virtualopensystems.com Cc: christoffer.dall@linaro.org, kvmarm@lists.cs.columbia.edu, patches@linaro.org, pbonzini@redhat.com, kim.phillips@freescale.com, a.rigo@virtualopensystems.com Subject: [PATCH v11 7/9] hw/arm/sysbus-fdt: enable vfio-calxeda-xgmac dynamic instantiation Date: Thu, 19 Mar 2015 10:05:36 +0000 Message-Id: <1426759538-18030-8-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1426759538-18030-1-git-send-email-eric.auger@linaro.org> References: <1426759538-18030-1-git-send-email-eric.auger@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch allows the instantiation of the vfio-calxeda-xgmac device from the QEMU command line (-device vfio-calxeda-xgmac,host=""). A specialized device tree node is created for the guest, containing compat, dma-coherent, reg and interrupts properties. Signed-off-by: Eric Auger --- v10 -> v11: - add dma-coherent property to calxeda midway xgmac node (fix) - use qemu_fdt_setprop to add reg property instead of qemu_fdt_setprop_sized_cells_from_array - commit message rewording v8 -> v9: - properly free resources in case of errors in add_calxeda_midway_xgmac_fdt_node v7 -> v8: - move the add_fdt_node_functions array declaration between the device specific code and the generic code to avoid forward declarations of decice specific functions - rename add_basic_vfio_fdt_node into add_calxeda_midway_xgmac_fdt_node 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 | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c index 3038b94..6e465b2 100644 --- a/hw/arm/sysbus-fdt.c +++ b/hw/arm/sysbus-fdt.c @@ -26,6 +26,8 @@ #include "sysemu/device_tree.h" #include "hw/platform-bus.h" #include "sysemu/sysemu.h" +#include "hw/vfio/vfio-platform.h" +#include "hw/vfio/vfio-calxeda-xgmac.h" /* * internal struct that contains the information to create dynamic @@ -53,11 +55,81 @@ typedef struct NodeCreationPair { int (*add_fdt_node_fn)(SysBusDevice *sbdev, void *opaque); } NodeCreationPair; +/* Device Specific Code */ + +/** + * add_calxeda_midway_xgmac_fdt_node + * + * Generates a simple node with following properties: + * compatible string, regs, interrupts, dma-coherent + */ +static int add_calxeda_midway_xgmac_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, ret = -1; + char *nodename; + uint32_t *irq_attr, *reg_attr; + uint64_t mmio_base, 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); + + qemu_fdt_setprop(fdt, nodename, "dma-coherent", "", 0); + + 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] = (uint32_t)mmio_base; + reg_attr[2*i+1] = (uint32_t)memory_region_size(&vdev->regions[i]->mem); + } + ret = qemu_fdt_setprop(fdt, nodename, "reg", reg_attr, + vbasedev->num_regions*2*sizeof(uint32_t)); + if (ret) { + error_report("could not set reg property of node %s", nodename); + goto fail_reg; + } + + 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) { + error_report("could not set interrupts property of node %s", + nodename); + } + g_free(irq_attr); +fail_reg: + g_free(reg_attr); + g_free(nodename); + return ret; +} + /* list of supported dynamic sysbus devices */ static const NodeCreationPair add_fdt_node_functions[] = { + {TYPE_VFIO_CALXEDA_XGMAC, add_calxeda_midway_xgmac_fdt_node}, {"", NULL}, /* last element */ }; +/* Generic Code */ + /** * add_fdt_node - add the device tree node of a dynamic sysbus device *