From: Eric Auger <eric.auger@linaro.org>
To: Baptiste Reynal <b.reynal@virtualopensystems.com>,
kvmarm@lists.cs.columbia.edu, qemu-devel@nongnu.org
Cc: a.motakis@virtualopensystems.com, tech@virtualopensystems.com,
Peter Maydell <peter.maydell@linaro.org>
Subject: Re: [Qemu-devel] [RFC PATCH v2 1/3] hw/vfio/sysbus-fdt: refactoring
Date: Thu, 15 Jan 2015 16:03:50 +0100 [thread overview]
Message-ID: <54B7D6D6.3030301@linaro.org> (raw)
In-Reply-To: <1419265427-24238-2-git-send-email-b.reynal@virtualopensystems.com>
Hi Baptiste,
On 12/22/2014 05:23 PM, Baptiste Reynal wrote:
> Creates set_interrupts_fdt_node and set_regions_fdt_node
> for code reusability.
>
> Signed-off-by: Baptiste Reynal <b.reynal@virtualopensystems.com>
> ---
> hw/arm/sysbus-fdt.c | 102 +++++++++++++++++++++++++++++++++++++---------------
> 1 file changed, 73 insertions(+), 29 deletions(-)
>
> diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c
> index 15bb50c..f6ff8a7 100644
> --- a/hw/arm/sysbus-fdt.c
> +++ b/hw/arm/sysbus-fdt.c
> @@ -58,6 +58,76 @@ typedef struct NodeCreationPair {
> /* Device Specific Code */
>
> /**
> + * set_interrupts_fdt_node
> + *
> + * Helper function, generate interrupts property for a given node
> + */
> +static int set_interrupts_fdt_node(char *nodename, SysBusDevice *sbdev,
> + void *opaque, int type, int flags)
> +{
> + PlatformBusFdtData *data = opaque;
> + PlatformBusDevice *pbus = data->pbus;
> + void *fdt = data->fdt;
> + uint32_t *irq_attr;
> + uint64_t irq_number;
> + int i, ret;
> + VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev);
> + VFIODevice *vbasedev = &vdev->vbasedev;
> +
> + 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(type);
> + irq_attr[3*i+1] = cpu_to_be32(irq_number);
> + irq_attr[3*i+2] = cpu_to_be32(flags);
> + }
> +
> + ret = qemu_fdt_setprop(fdt, nodename, "interrupts",
> + irq_attr, vbasedev->num_irqs*3*sizeof(uint32_t));
> +
> + g_free(irq_attr);
> +
> + return ret;
> +}
> +
> +/**
> + * set_regions_fdt_node
> + *
> + * Helper function, generate reg property for a given node
> + */
> +static int set_regions_fdt_node(char *nodename, SysBusDevice *sbdev,
> + void *opaque)
> +{
> + PlatformBusFdtData *data = opaque;
> + PlatformBusDevice *pbus = data->pbus;
> + void *fdt = data->fdt;
> + uint64_t *reg_attr;
> + uint64_t mmio_base;
> + int i, ret;
> + VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev);
> + VFIODevice *vbasedev = &vdev->vbasedev;
> +
> + 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);
> +
> + g_free(reg_attr);
> +
> + return ret;
> +}
> +
> +/**
> * add_calxeda_midway_xgmac_fdt_node
> *
> * Generates a very simple node with following properties:
> @@ -66,16 +136,12 @@ typedef struct NodeCreationPair {
> 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;
> + int ret;
> uint64_t mmio_base;
> - uint64_t irq_number;
> VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev);
> VFIODevice *vbasedev = &vdev->vbasedev;
> Object *obj = OBJECT(sbdev);
> @@ -92,35 +158,15 @@ static int add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void *opaque)
> 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 = set_regions_fdt_node(nodename, sbdev, opaque);
>
> - 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);
> + ret = set_interrupts_fdt_node(nodename, sbdev, opaque, 0, 0x4);
>
> - 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);
> @@ -128,8 +174,6 @@ static int add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void *opaque)
> }
>
> g_free(nodename);
> - g_free(irq_attr);
> - g_free(reg_attr);
>
> return 0;
I think we should also take into account intermediate ret values.
Otherwise looks sensible to me.
Also you properly handled irq_attr and reg_attr dealloc here as opposed
to what I did in that version ;-)
maybe the title of your commit may be more explicit?
Best Regards
Eric
>
>
next prev parent reply other threads:[~2015-01-15 15:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-22 16:23 [Qemu-devel] [RFC PATCH v2 0/3] [RFC PATCH 0/3] VFIO support for AMBA devices Baptiste Reynal
2014-12-22 16:23 ` [Qemu-devel] [RFC PATCH v2 1/3] hw/vfio/sysbus-fdt: refactoring Baptiste Reynal
2015-01-15 15:03 ` Eric Auger [this message]
2014-12-22 16:23 ` [Qemu-devel] [RFC PATCH v2 2/3] hw/vfio: amba device support Baptiste Reynal
2015-01-15 15:08 ` Eric Auger
2014-12-22 16:23 ` [Qemu-devel] [RFC PATCH v2 3/3] hw/vfio: add pl330 " Baptiste Reynal
2015-01-15 15:38 ` 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=54B7D6D6.3030301@linaro.org \
--to=eric.auger@linaro.org \
--cc=a.motakis@virtualopensystems.com \
--cc=b.reynal@virtualopensystems.com \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=tech@virtualopensystems.com \
/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.