From: Eric Auger <eric.auger@linaro.org> To: "Alex Bennée" <alex.bennee@linaro.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, b.reynal@virtualopensystems.com, feng.wu@intel.com, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org Subject: Re: [Qemu-devel] [PATCH v10 6/7] hw/arm/sysbus-fdt: enable vfio-calxeda-xgmac dynamic instantiation Date: Fri, 13 Mar 2015 10:33:57 +0100 [thread overview] Message-ID: <5502AF05.9000504@linaro.org> (raw) In-Reply-To: <87bnkszs4u.fsf@linaro.org> Alex, On 02/17/2015 12:36 PM, Alex Bennée wrote: > > Eric Auger <eric.auger@linaro.org> writes: > >> 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 <eric.auger@linaro.org> >> >> --- >> 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); > > Could we use qemu_fdt_setprop_sized_cells() like everyone else to hide > the uglyness of the _from_array? Due to the fact I need to handle 'num_regions' regions, I need to setup the array programmatically. I could use qemu_fdt_setprop instead since the cell size always is 1 but I currently do not see how I could easily take benefit from qemu_fdt_setprop_sized_cells. > >> + 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)); > > Ditto. Here also I need to handle num_irqs. But maybe I misunderstand your comment here. Best Regards Eric > >> + 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: "Alex Bennée" <alex.bennee@linaro.org> Cc: eric.auger@st.com, patches@linaro.org, qemu-devel@nongnu.org, alex.williamson@redhat.com, pbonzini@redhat.com, feng.wu@intel.com, kvmarm@lists.cs.columbia.edu Subject: Re: [PATCH v10 6/7] hw/arm/sysbus-fdt: enable vfio-calxeda-xgmac dynamic instantiation Date: Fri, 13 Mar 2015 10:33:57 +0100 [thread overview] Message-ID: <5502AF05.9000504@linaro.org> (raw) In-Reply-To: <87bnkszs4u.fsf@linaro.org> Alex, On 02/17/2015 12:36 PM, Alex Bennée wrote: > > Eric Auger <eric.auger@linaro.org> writes: > >> 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 <eric.auger@linaro.org> >> >> --- >> 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); > > Could we use qemu_fdt_setprop_sized_cells() like everyone else to hide > the uglyness of the _from_array? Due to the fact I need to handle 'num_regions' regions, I need to setup the array programmatically. I could use qemu_fdt_setprop instead since the cell size always is 1 but I currently do not see how I could easily take benefit from qemu_fdt_setprop_sized_cells. > >> + 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)); > > Ditto. Here also I need to handle num_irqs. But maybe I misunderstand your comment here. Best Regards Eric > >> + 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 >> * > _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
next prev parent reply other threads:[~2015-03-13 9:36 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-02-13 3:47 [Qemu-devel] [PATCH v10 0/7] KVM platform device passthrough Eric Auger 2015-02-13 3:47 ` [Qemu-devel] [PATCH v10 1/7] linux-headers: update VFIO header for VFIO platform drivers Eric Auger 2015-02-13 3:47 ` [Qemu-devel] [PATCH v10 2/7] hw/vfio/platform: vfio-platform skeleton Eric Auger 2015-02-17 10:56 ` Alex Bennée 2015-02-17 10:56 ` Alex Bennée 2015-03-13 9:28 ` [Qemu-devel] " Eric Auger 2015-03-13 9:28 ` Eric Auger 2015-02-13 3:47 ` [Qemu-devel] [PATCH v10 3/7] hw/vfio/platform: add irq assignment Eric Auger 2015-02-17 11:24 ` Alex Bennée 2015-02-17 11:24 ` Alex Bennée 2015-03-19 10:18 ` [Qemu-devel] " Eric Auger 2015-03-19 10:18 ` Eric Auger 2015-02-13 3:47 ` [Qemu-devel] [PATCH v10 4/7] hw/vfio/platform: add capability to start IRQ propagation Eric Auger 2015-02-13 3:47 ` [Qemu-devel] [PATCH v10 5/7] hw/vfio: calxeda xgmac device Eric Auger 2015-02-17 11:29 ` Alex Bennée 2015-02-17 11:29 ` Alex Bennée 2015-02-13 3:47 ` [Qemu-devel] [PATCH v10 6/7] hw/arm/sysbus-fdt: enable vfio-calxeda-xgmac dynamic instantiation Eric Auger 2015-02-17 11:36 ` Alex Bennée 2015-02-17 11:36 ` Alex Bennée 2015-03-13 9:33 ` Eric Auger [this message] 2015-03-13 9:33 ` Eric Auger 2015-02-13 3:47 ` [Qemu-devel] [PATCH v10 7/7] hw/vfio/platform: add irqfd support Eric Auger 2015-02-17 11:41 ` Alex Bennée 2015-02-17 11:41 ` Alex Bennée
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=5502AF05.9000504@linaro.org \ --to=eric.auger@linaro.org \ --cc=agraf@suse.de \ --cc=alex.bennee@linaro.org \ --cc=alex.williamson@redhat.com \ --cc=b.reynal@virtualopensystems.com \ --cc=christoffer.dall@linaro.org \ --cc=eric.auger@st.com \ --cc=feng.wu@intel.com \ --cc=kvmarm@lists.cs.columbia.edu \ --cc=patches@linaro.org \ --cc=pbonzini@redhat.com \ --cc=peter.maydell@linaro.org \ --cc=qemu-devel@nongnu.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: linkBe 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.