From patchwork Sun Nov 30 18:35:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 41738 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7374524001 for ; Sun, 30 Nov 2014 18:36:07 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id c13sf5852331eek.6 for ; Sun, 30 Nov 2014 10:36:06 -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=Ori8yViab83FyEf5PgM1i7D/UTIrVkag0GbcPnpztLM=; b=ZShiDPI5xaoSvWZOjmlPKCXGbpLMCizQgMrfIO0aKzm4f6CyUkbMQG9Fe5oCxks0dS rOQsO2fVgVUN+J+5toTEHZ9jFp4Qt3LdCry3ajkWqfGYkpjpBrvCVC4yHYpzWSvvBnMv znhE8yFq7gLH03pve72yEaalIraPzJB34tD+4mKx6DUDZKdlr4ccQLeF8xCVBWzOiBkj ncjrZ21wlgoJEtnqy7oDi9r6zjVR8DOUjg0GvQcAkRIJJ4LZhdGuB4TMwMUe4vv927+4 jK6OEubJ2l0PpbqgrIOJVUoKRMMXsQgGBFYL34N4a922tkWWYMUvX/eq1NcjP+BYGo5Q V3bg== X-Gm-Message-State: ALoCoQnxwfIawS65bMk7an7P4LolFKjmmomgclG9xq+/n5pUl0IZWLGFubQ5llEzP+JUs9kRTDVI X-Received: by 10.152.44.195 with SMTP id g3mr2973538lam.2.1417372566635; Sun, 30 Nov 2014 10:36:06 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.116.48 with SMTP id jt16ls938827lab.44.gmail; Sun, 30 Nov 2014 10:36:06 -0800 (PST) X-Received: by 10.152.5.6 with SMTP id o6mr53868257lao.8.1417372566364; Sun, 30 Nov 2014 10:36:06 -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 i7si15612687lbs.116.2014.11.30.10.36.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 30 Nov 2014 10:36:06 -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 l4so7350251lbv.25 for ; Sun, 30 Nov 2014 10:36:06 -0800 (PST) X-Received: by 10.112.52.37 with SMTP id q5mr52495850lbo.32.1417372566277; Sun, 30 Nov 2014 10:36:06 -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.184.201 with SMTP id ew9csp172725lbc; Sun, 30 Nov 2014 10:36:05 -0800 (PST) X-Received: by 10.180.107.198 with SMTP id he6mr78816107wib.44.1417372565568; Sun, 30 Nov 2014 10:36:05 -0800 (PST) Received: from mail-wg0-f54.google.com (mail-wg0-f54.google.com. [74.125.82.54]) by mx.google.com with ESMTPS id ps5si26736961wjc.85.2014.11.30.10.36.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 30 Nov 2014 10:36:05 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.54 as permitted sender) client-ip=74.125.82.54; Received: by mail-wg0-f54.google.com with SMTP id l2so12457680wgh.27 for ; Sun, 30 Nov 2014 10:36:05 -0800 (PST) X-Received: by 10.180.37.142 with SMTP id y14mr41997776wij.47.1417372565363; Sun, 30 Nov 2014 10:36:05 -0800 (PST) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id z7sm38794058wia.22.2014.11.30.10.36.03 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 30 Nov 2014 10:36:04 -0800 (PST) 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, zhaoshenglong@huawei.com, ard.biesheuvel@linaro.org Cc: eric.auger@linaro.org, kvmarm@lists.cs.columbia.edu, patches@linaro.org, alex.williamson@redhat.com, peter.maydell@linaro.org, will.deacon@arm.com, Bharat.Bhushan@freescale.com, stuart.yoder@freescale.com, a.motakis@virtualopensystems.com Subject: [PATCH v8 15/19] hw/arm/sysbus-fdt: enable vfio-calxeda-xgmac dynamic instantiation Date: Sun, 30 Nov 2014 18:35:20 +0000 Message-Id: <1417372524-12936-16-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1417372524-12936-1-git-send-email-eric.auger@linaro.org> References: <1417372524-12936-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 --- 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 | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c index 7537267..86bbd06 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,97 @@ 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; + 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; +} + /* 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 *