From patchwork Fri Feb 13 03:47:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 44651 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 328F921527 for ; Fri, 13 Feb 2015 03:47:40 +0000 (UTC) Received: by lams18 with SMTP id s18sf9053978lam.1 for ; Thu, 12 Feb 2015 19:47:39 -0800 (PST) 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=/RBxa91H7LuYJTAZJM+7BiFWk41vw4RRCYH4fAGGwr4=; b=LDcdZ8DsJE+ai1NumMdBTD92F6Cmu/OY/dJnSSgA5okx7M2xYQirTUPoF9OggngT2w f5C5L7QFB4ZNHrLAfGfrzx+RBmFA+ZJ4iBNjDvbWQoZ4PVI9w6H4MQV7/KIa78VVkLNz J7NvIY+ut8elyYSCvImCM0DF/3dvDHpc0pzDvG7VMEMpY6xo5l3lQop7S9F7RK+UDuek +0M6tw+m1Bq32EBOOL6cyyxr8UhwdLy1OzHD8vgO13dM1Fy6hmI1LNAtaN+EMZ4RELIB +hemSfYIdKIRe1/HLSXoFfCS2CUQeRIA3iZFUk3yAl5clmdZL33De3wjnOZm8kaMxA5N yLmQ== X-Gm-Message-State: ALoCoQn1Fvs6UNHYIdaja+04SrEv4EKHBkmOJ/bHRgdslOZLswIkk18+oggq82lylWea01H5ru6b X-Received: by 10.180.72.44 with SMTP id a12mr50332wiv.0.1423799258973; Thu, 12 Feb 2015 19:47:38 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.170.193 with SMTP id ao1ls295421lac.20.gmail; Thu, 12 Feb 2015 19:47:37 -0800 (PST) X-Received: by 10.152.28.227 with SMTP id e3mr2153106lah.117.1423799257725; Thu, 12 Feb 2015 19:47:37 -0800 (PST) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id pr6si642053lbb.30.2015.02.12.19.47.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Feb 2015 19:47:37 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by mail-lb0-f180.google.com with SMTP id z12so13278556lbi.11 for ; Thu, 12 Feb 2015 19:47:37 -0800 (PST) X-Received: by 10.152.43.193 with SMTP id y1mr6152133lal.35.1423799257647; Thu, 12 Feb 2015 19:47:37 -0800 (PST) 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 h5csp824269lbj; Thu, 12 Feb 2015 19:47:37 -0800 (PST) X-Received: by 10.180.74.199 with SMTP id w7mr13072880wiv.1.1423799255289; Thu, 12 Feb 2015 19:47:35 -0800 (PST) Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com. [74.125.82.45]) by mx.google.com with ESMTPS id fa1si1618428wjd.150.2015.02.12.19.47.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Feb 2015 19:47:35 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.45 as permitted sender) client-ip=74.125.82.45; Received: by mail-wg0-f45.google.com with SMTP id k14so11102229wgh.4 for ; Thu, 12 Feb 2015 19:47:35 -0800 (PST) X-Received: by 10.194.6.228 with SMTP id e4mr13837003wja.63.1423799255036; Thu, 12 Feb 2015 19:47:35 -0800 (PST) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id fw5sm8222550wjb.14.2015.02.12.19.47.27 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Feb 2015 19:47:33 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, christoffer.dall@linaro.org, qemu-devel@nongnu.org, alex.williamson@redhat.com, peter.maydell@linaro.org, agraf@suse.de, b.reynal@virtualopensystems.com, feng.wu@intel.com Cc: kvmarm@lists.cs.columbia.edu, patches@linaro.org, pbonzini@redhat.com, afaerber@suse.de, kim.phillips@freescale.com, Bharat.Bhushan@freescale.com, a.rigo@virtualopensystems.com, a.motakis@virtualopensystems.com Subject: [PATCH v10 6/7] hw/arm/sysbus-fdt: enable vfio-calxeda-xgmac dynamic instantiation Date: Fri, 13 Feb 2015 03:47:11 +0000 Message-Id: <1423799232-10816-7-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1423799232-10816-1-git-send-email-eric.auger@linaro.org> References: <1423799232-10816-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.217.180 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: , 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 --- 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 | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c index 3038b94..d4f97f5 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,92 @@ typedef struct NodeCreationPair { int (*add_fdt_node_fn)(SysBusDevice *sbdev, void *opaque); } NodeCreationPair; +/* Device Specific Code */ + +/** + * add_calxeda_midway_xgmac_fdt_node + * + * Generates a very simple node with following properties: + * compatible string, regs, interrupts + */ +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; + char *nodename; + int i, ret = -1; + 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) { + 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 *