From patchwork Thu Jan 15 13:18:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 43180 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E057F20D60 for ; Thu, 15 Jan 2015 13:18:58 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id b6sf1903514lbj.2 for ; Thu, 15 Jan 2015 05:18:57 -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=VUZln8ic27YXHjD45hZHDkrtjmzUMux/M205DgwqUlFa0UqY3Fd+/fsgt+VphOcxOi LacZiBzVdWAdgh4XJCrqDv1BcAX4aRQUfGpn/gyMVhIK0qSn2OecQvOjJIgH/JfRH3yT NFuCl+NszCQtdEbu0pjRz7ERc75XQPCbPm/h7MnEwNsueQ4DQPH5a1sJM4hkaN8bgkUM qrqaCT67gfax+xKjLzRDIengkZ2bq162THln7Kh0+hWWxavfm0+SGaM3Bbfz6S2BojYx Gi7mRbMlieOeobzt+Wo7tvWLpIee0yMKA5/0YaL37+FQ8L1PSAPbmox5GROprP0yd3qU IhZw== X-Gm-Message-State: ALoCoQk0F+P+FPTRgIINXDdPII/X4JV29wyk79rz/NUxCaVlftu+BXKyPTG1kEKmJKMruXpEh2/e X-Received: by 10.112.42.104 with SMTP id n8mr242112lbl.19.1421327937814; Thu, 15 Jan 2015 05:18:57 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.104 with SMTP id kx8ls232673lac.82.gmail; Thu, 15 Jan 2015 05:18:57 -0800 (PST) X-Received: by 10.112.167.136 with SMTP id zo8mr7375851lbb.17.1421327937674; Thu, 15 Jan 2015 05:18:57 -0800 (PST) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id oq1si1371483lbb.98.2015.01.15.05.18.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 15 Jan 2015 05:18:57 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by mail-la0-f50.google.com with SMTP id pn19so13460063lab.9 for ; Thu, 15 Jan 2015 05:18:57 -0800 (PST) X-Received: by 10.112.173.202 with SMTP id bm10mr1196727lbc.24.1421327937600; Thu, 15 Jan 2015 05:18:57 -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.9.200 with SMTP id c8csp2030751lbb; Thu, 15 Jan 2015 05:18:56 -0800 (PST) X-Received: by 10.180.81.169 with SMTP id b9mr18931809wiy.41.1421327932154; Thu, 15 Jan 2015 05:18:52 -0800 (PST) Received: from mail-wg0-f46.google.com (mail-wg0-f46.google.com. [74.125.82.46]) by mx.google.com with ESMTPS id eu9si6088844wid.82.2015.01.15.05.18.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 15 Jan 2015 05:18:52 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.46 as permitted sender) client-ip=74.125.82.46; Received: by mail-wg0-f46.google.com with SMTP id x13so14841567wgg.5 for ; Thu, 15 Jan 2015 05:18:51 -0800 (PST) X-Received: by 10.194.89.39 with SMTP id bl7mr17895946wjb.76.1421327931581; Thu, 15 Jan 2015 05:18:51 -0800 (PST) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id o2sm7456332wiy.11.2015.01.15.05.18.50 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 15 Jan 2015 05:18:50 -0800 (PST) From: Eric Auger To: eric.auger@st.com, christoffer.dall@linaro.org, qemu-devel@nongnu.org, kim.phillips@freescale.com, alex.williamson@redhat.com, agraf@suse.de, peter.maydell@linaro.org Cc: eric.auger@linaro.org, kvmarm@lists.cs.columbia.edu, patches@linaro.org, Bharat.Bhushan@freescale.com, b.reynal@virtualopensystems.com, a.rigo@virtualopensystems.com, a.motakis@virtualopensystems.com, pbonzini@redhat.com, afaerber@suse.de Subject: [PATCH v9 6/7] hw/arm/sysbus-fdt: enable vfio-calxeda-xgmac dynamic instantiation Date: Thu, 15 Jan 2015 13:18:16 +0000 Message-Id: <1421327897-1698-7-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1421327897-1698-1-git-send-email-eric.auger@linaro.org> References: <1421327897-1698-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.50 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 *