From: Eric Auger <eric.auger@linaro.org>
To: Vikram Sethi <vikrams@codeaurora.org>
Cc: eric.auger@st.com, patches@linaro.org, qemu-devel@nongnu.org,
alex.williamson@redhat.com, pbonzini@redhat.com,
kvmarm@lists.cs.columbia.edu
Subject: Re: [PATCH v12 7/9] hw/arm/sysbus-fdt: enable vfio-calxeda-xgmac dynamic instantiation
Date: Mon, 27 Apr 2015 11:19:12 +0200 [thread overview]
Message-ID: <553DFF10.4070704@linaro.org> (raw)
In-Reply-To: <553AC529.7040009@codeaurora.org>
Hi Vikram,
On 04/25/2015 12:35 AM, Vikram Sethi wrote:
> Hi Eric,
>
> On 03/19/15 12:16, Eric Auger wrote:
>> This patch allows the instantiation of the vfio-calxeda-xgmac device
>> from the QEMU command line (-device vfio-calxeda-xgmac,host="<device>").
>>
>> A specialized device tree node is created for the guest, containing
>> compat, dma-coherent, reg and interrupts properties.
>>
>> Signed-off-by: Eric Auger <eric.auger@linaro.org>
>>
>> ---
>> 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
>> + */
> Since this function is applicable to any dma-coherent device with
> only mmio and irq properties to be exposed, should it be named
> something more generic so that it can be reused for other devices?
Hi Vikram,
well this is a discussion started a while ago. Alex requested the entry
point not to be generic. I think when adding new entries in this lookup
table we will bring helpers that can be used by several entries to
generate most common props (irq, regions, ...).
see [RFC PATCH v3 1/3] hw/vfio/sysbus-fdt: helper routines to create fdt
nodes (https://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02063.html)
>> +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);
> You are missing the cpu_to_be32 for mmio_base and size.
> As a result, a 0x1000 size really gets encoded as 0x100000.
> If you have a device with 2 MMIO regions, this results
> in the second region getting a wrong starting address in
> the guest kernel, which also doesn't match the 2nd stage
> mapping done by KVM. With that fix, able to test this function
> with a device with 2 regions as well.
Thanks for reporting this.
This will be corrected in v13 early this week.
Best Regards
Eric
>> + 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
>> *
>
WARNING: multiple messages have this Message-ID (diff)
From: Eric Auger <eric.auger@linaro.org>
To: Vikram Sethi <vikrams@codeaurora.org>
Cc: peter.maydell@linaro.org, eric.auger@st.com, patches@linaro.org,
qemu-devel@nongnu.org, agraf@suse.de, alex.williamson@redhat.com,
pbonzini@redhat.com, kvmarm@lists.cs.columbia.edu
Subject: Re: [Qemu-devel] [PATCH v12 7/9] hw/arm/sysbus-fdt: enable vfio-calxeda-xgmac dynamic instantiation
Date: Mon, 27 Apr 2015 11:19:12 +0200 [thread overview]
Message-ID: <553DFF10.4070704@linaro.org> (raw)
In-Reply-To: <553AC529.7040009@codeaurora.org>
Hi Vikram,
On 04/25/2015 12:35 AM, Vikram Sethi wrote:
> Hi Eric,
>
> On 03/19/15 12:16, Eric Auger wrote:
>> This patch allows the instantiation of the vfio-calxeda-xgmac device
>> from the QEMU command line (-device vfio-calxeda-xgmac,host="<device>").
>>
>> A specialized device tree node is created for the guest, containing
>> compat, dma-coherent, reg and interrupts properties.
>>
>> Signed-off-by: Eric Auger <eric.auger@linaro.org>
>>
>> ---
>> 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
>> + */
> Since this function is applicable to any dma-coherent device with
> only mmio and irq properties to be exposed, should it be named
> something more generic so that it can be reused for other devices?
Hi Vikram,
well this is a discussion started a while ago. Alex requested the entry
point not to be generic. I think when adding new entries in this lookup
table we will bring helpers that can be used by several entries to
generate most common props (irq, regions, ...).
see [RFC PATCH v3 1/3] hw/vfio/sysbus-fdt: helper routines to create fdt
nodes (https://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02063.html)
>> +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);
> You are missing the cpu_to_be32 for mmio_base and size.
> As a result, a 0x1000 size really gets encoded as 0x100000.
> If you have a device with 2 MMIO regions, this results
> in the second region getting a wrong starting address in
> the guest kernel, which also doesn't match the 2nd stage
> mapping done by KVM. With that fix, able to test this function
> with a device with 2 regions as well.
Thanks for reporting this.
This will be corrected in v13 early this week.
Best Regards
Eric
>> + 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
>> *
>
next prev parent reply other threads:[~2015-04-27 9:13 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-19 17:16 [PATCH v12 0/9] KVM platform device passthrough Eric Auger
2015-03-19 17:16 ` [Qemu-devel] " Eric Auger
2015-03-19 17:16 ` [PATCH v12 1/9] linux-headers: update VFIO header for VFIO platform/amba drivers Eric Auger
2015-03-19 17:16 ` [Qemu-devel] " Eric Auger
2015-04-16 22:03 ` Alex Williamson
2015-04-16 22:03 ` [Qemu-devel] " Alex Williamson
2015-03-19 17:16 ` [PATCH v12 2/9] hw/vfio/platform: vfio-platform skeleton Eric Auger
2015-03-19 17:16 ` [Qemu-devel] " Eric Auger
2015-04-16 22:04 ` Alex Williamson
2015-04-16 22:04 ` [Qemu-devel] " Alex Williamson
2015-03-19 17:16 ` [PATCH v12 3/9] hw/vfio/platform: add irq assignment Eric Auger
2015-03-19 17:16 ` [Qemu-devel] " Eric Auger
2015-03-19 17:16 ` [PATCH v12 4/9] hw/vfio/platform: add capability to start IRQ propagation Eric Auger
2015-03-19 17:16 ` [Qemu-devel] " Eric Auger
2015-04-16 22:04 ` Alex Williamson
2015-04-16 22:04 ` [Qemu-devel] " Alex Williamson
2015-04-17 15:31 ` Eric Auger
2015-04-17 15:31 ` [Qemu-devel] " Eric Auger
2015-04-17 19:41 ` Alex Williamson
2015-04-17 19:41 ` [Qemu-devel] " Alex Williamson
2015-04-21 8:42 ` [Qemu-devel] [question] Clean way to retrieve the gsi of a sysbus device qemu_irq? Eric Auger
2015-04-21 11:54 ` [PATCH v12 4/9] hw/vfio/platform: add capability to start IRQ propagation Eric Auger
2015-04-21 11:54 ` [Qemu-devel] " Eric Auger
2015-03-19 17:16 ` [PATCH v12 5/9] hw/arm/virt: start VFIO " Eric Auger
2015-03-19 17:16 ` [Qemu-devel] " Eric Auger
2015-04-16 22:05 ` Alex Williamson
2015-04-16 22:05 ` [Qemu-devel] " Alex Williamson
2015-03-19 17:16 ` [PATCH v12 6/9] hw/vfio/platform: calxeda xgmac device Eric Auger
2015-03-19 17:16 ` [Qemu-devel] " Eric Auger
2015-03-19 17:16 ` [PATCH v12 7/9] hw/arm/sysbus-fdt: enable vfio-calxeda-xgmac dynamic instantiation Eric Auger
2015-03-19 17:16 ` [Qemu-devel] " Eric Auger
2015-04-24 22:35 ` Vikram Sethi
2015-04-24 22:35 ` [Qemu-devel] " Vikram Sethi
2015-04-27 9:19 ` Eric Auger [this message]
2015-04-27 9:19 ` Eric Auger
2015-03-19 17:16 ` [PATCH v12 8/9] linux-headers: update arm/arm64 KVM headers for irqfd Eric Auger
2015-03-19 17:16 ` [Qemu-devel] " Eric Auger
2015-03-19 17:16 ` [PATCH v12 9/9] hw/vfio/platform: add irqfd support Eric Auger
2015-03-19 17:16 ` [Qemu-devel] " Eric Auger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=553DFF10.4070704@linaro.org \
--to=eric.auger@linaro.org \
--cc=alex.williamson@redhat.com \
--cc=eric.auger@st.com \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=patches@linaro.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=vikrams@codeaurora.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.