qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Baptiste Reynal <b.reynal@virtualopensystems.com>
To: kvmarm@lists.cs.columbia.edu, qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	tech@virtualopensystems.com,
	Baptiste Reynal <b.reynal@virtualopensystems.com>
Subject: [Qemu-devel] [RFC PATCH v3 1/3] hw/vfio/sysbus-fdt: helper routines to create fdt nodes
Date: Wed, 11 Feb 2015 17:22:01 +0100	[thread overview]
Message-ID: <1423671724-13167-2-git-send-email-b.reynal@virtualopensystems.com> (raw)
In-Reply-To: <1423671724-13167-1-git-send-email-b.reynal@virtualopensystems.com>

Creates set_interrupts_fdt_node and set_regions_fdt_node
for code reusability.

Signed-off-by: Baptiste Reynal <b.reynal@virtualopensystems.com>

---
v2 -> v3:
handle intermediate ret values in set_regions_fdt_node and
set_interrupts_fdt_node
---
 hw/arm/sysbus-fdt.c | 129 ++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 91 insertions(+), 38 deletions(-)

diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c
index d4f97f5..bc0944c 100644
--- a/hw/arm/sysbus-fdt.c
+++ b/hw/arm/sysbus-fdt.c
@@ -58,39 +58,59 @@ typedef struct NodeCreationPair {
 /* Device Specific Code */
 
 /**
- * add_calxeda_midway_xgmac_fdt_node
+ * set_interrupts_fdt_node
  *
- * Generates a very simple node with following properties:
- * compatible string, regs, interrupts
+ * Helper function, generate interrupts property for a given node
  */
-static int add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void *opaque)
+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;
-    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;
+    int i, ret;
     VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev);
     VFIODevice *vbasedev = &vdev->vbasedev;
-    Object *obj = OBJECT(sbdev);
 
-    mmio_base = object_property_get_int(obj, "mmio[0]", NULL);
+    irq_attr = g_new(uint32_t, vbasedev->num_irqs*3);
 
-    nodename = g_strdup_printf("%s/%s@%" PRIx64, parent_node,
-                               vbasedev->name,
-                               mmio_base);
+    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);
+    }
 
-    qemu_fdt_add_subnode(fdt, nodename);
+    ret = qemu_fdt_setprop(fdt, nodename, "interrupts",
+            irq_attr, vbasedev->num_irqs*3*sizeof(uint32_t));
 
-    compat_str_len = strlen(vdev->compat) + 1;
-    qemu_fdt_setprop(fdt, nodename, "compatible",
-                          vdev->compat, compat_str_len);
+    if (ret < 0) {
+        error_report("could not set interrupts property of node %s", nodename);
+    }
+    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);
 
@@ -103,34 +123,67 @@ static int add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void *opaque)
     }
 
     ret = qemu_fdt_setprop_sized_cells_from_array(fdt, nodename, "reg",
-                     vbasedev->num_regions*2, reg_attr);
-    if (ret) {
+            vbasedev->num_regions*2, reg_attr);
+
+    if (ret < 0) {
         error_report("could not set reg property of node %s", nodename);
-        goto fail_reg;
     }
+    g_free(reg_attr);
 
-    irq_attr = g_new(uint32_t, vbasedev->num_irqs*3);
+    return ret;
+}
 
-    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);
+/**
+ * add_calxeda_midway_xgmac_fdt_node
+ *
+ * Generates a very simple node with the following properties:
+ * compatible string, regs, interrupts
+ */
+static int add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void *opaque)
+{
+    PlatformBusFDTData *data = opaque;
+    void *fdt = data->fdt;
+    const char *parent_node = data->pbus_node_name;
+    int compat_str_len;
+    char *nodename;
+    int ret;
+    uint64_t mmio_base;
+    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);
+
+    ret = set_regions_fdt_node(nodename, sbdev, opaque);
+
+    if (ret < 0) {
+        goto fail;
     }
 
-   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);
+    ret = set_interrupts_fdt_node(nodename, sbdev, opaque, 0, 0x4);
+
+    if (ret < 0) {
+        goto fail;
     }
 
-    g_free(irq_attr);
-fail_reg:
-    g_free(reg_attr);
     g_free(nodename);
-    return ret;
+
+    return 0;
+
+fail:
+    error_report("could not initialize node %s", nodename);
+    g_free(nodename);
+    return -1;
 }
 
 /* list of supported dynamic sysbus devices */
-- 
2.3.0

  reply	other threads:[~2015-02-11 16:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-11 16:22 [Qemu-devel] [RFC PATCH v3 0/3] VFIO support for AMBA devices Baptiste Reynal
2015-02-11 16:22 ` Baptiste Reynal [this message]
2015-02-11 16:22 ` [Qemu-devel] [RFC PATCH v3 2/3] hw/vfio: amba device support Baptiste Reynal
2015-02-11 16:22 ` [Qemu-devel] [RFC PATCH v3 3/3] hw/vfio: add pl330 " Baptiste Reynal

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=1423671724-13167-2-git-send-email-b.reynal@virtualopensystems.com \
    --to=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).