From patchwork Wed Apr 29 14:52:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 466117 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 B68851402BC for ; Thu, 30 Apr 2015 00:54:59 +1000 (AEST) Received: from localhost ([::1]:39455 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnTO5-0000Rw-M9 for incoming@patchwork.ozlabs.org; Wed, 29 Apr 2015 10:54:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnTLe-0003nN-Bm for qemu-devel@nongnu.org; Wed, 29 Apr 2015 10:52:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnTLZ-0001dj-OO for qemu-devel@nongnu.org; Wed, 29 Apr 2015 10:52:26 -0400 Received: from mail-wg0-f48.google.com ([74.125.82.48]:34846) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnTLZ-0001da-G4 for qemu-devel@nongnu.org; Wed, 29 Apr 2015 10:52:21 -0400 Received: by wgyo15 with SMTP id o15so31175303wgy.2 for ; Wed, 29 Apr 2015 07:52:21 -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=25GXLBdUmsz1JcYs2F2ocDQU/2JpSNMnSUukGQTAurw=; b=ay2coccm8osgmIgfQhkWQGTHMyB0nNG07rWUdKEZklO0zjY9E2inYzzmlsN5GRJBcB /zoUAlSDkAG0KRpmDm5snXxRcpixNQdNVEG8DdlzW/LRY598QEP8lIuixgm6+K3Q+Rhc Oyb5+XcDz9gHPK7eHKtYerbLzQLDKwywcsTgkQSqAO3exwOAVq8BXhSGhzuvaTJgYyNv PjgjZErX+XedXFusiqV6e6iqLx5Ma8PfezMgzddBjDxGnShMn4xdabUshfs8CIMLXzZu dWF+QYVnDi+GO1UEEykxQzkv518GP8Glmsmo6hEyva1/luLFU+cX2SiOIN+5+Ms+VNNR KyYQ== X-Gm-Message-State: ALoCoQlHtv5sDGZpWTqm8DkQMVnZOaXkanmAn2GIorKMKjIR39WAB4WzUyuoXSEF/Dv+Rf7R3hsW X-Received: by 10.181.13.113 with SMTP id ex17mr6761407wid.12.1430319140931; Wed, 29 Apr 2015 07:52:20 -0700 (PDT) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id it5sm21555782wid.3.2015.04.29.07.52.19 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 29 Apr 2015 07:52:19 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, alex.williamson@redhat.com, agraf@suse.de, pbonzini@redhat.com, peter.crosthwaite@xilinx.com Date: Wed, 29 Apr 2015 15:52:02 +0100 Message-Id: <1430319127-25907-6-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1430319127-25907-1-git-send-email-eric.auger@linaro.org> References: <1430319127-25907-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: 74.125.82.48 Cc: peter.maydell@linaro.org, b.reynal@virtualopensystems.com, vikrams@codeaurora.org, patches@linaro.org, Bharat.Bhushan@freescale.com, borntraeger@de.ibm.com, cornelia.huck@de.ibm.com, alex.bennee@linaro.org, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org Subject: [Qemu-devel] [PATCH v14 05/10] 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 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 --- v12 -> v13: - use platform_bus_get_mmio_addr instead of deprecated mmio[0] property. Thanks to Bharat who pointed this issue out. - use cpu_to_be32 to mmio_base & size (Vikram report) 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..3d67acf 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; + + 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, "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] = cpu_to_be32(mmio_base); + reg_attr[2*i+1] = cpu_to_be32( + 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 *