Skip to contentSkip to conversation

VFIO support for AMBA devices

RFC PATCH Superseded Baptiste Reynal 2 participants 9 messages Dec 17, 2014

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover VFIO support for AMBA devices

The following series add VFIO support for AMBA devices.

It introduces multiple compatible string support to deal with arm,primecell compatible string.

The VFIOPlatformDevice now checks for this string and performs amba specific operations if it is present (change path of the device, add clock in the fd).

This patch applies on top of http://git.linaro.org/people/eric.auger/qemu.git
on branch vfio_integ_v9_rc6_official_dynsysbus_v6 for irqfd support.

TODO: The IRQ forwarding doesn't work.

The series has been tested using PL330 device, irq forwarding doesn't work. (The test hangs on the first IRQ).
The test performed relies on a special guest kernel, which can be found here
http://github.com/virtualopensystems/linux-kvm-arm.git on branch vfio-platform-v6-guide, with CONFIG_KVM, CONFIG_ARM_SMMU, CONFIG_PL330_DMA and CONFIG_VOSYS_DMATEST enabled.

Run qemu using this command:

./qemu-system-arm -M virt -m 512M -enable-kvm \
        -device vfio-pl330,host="2c0a0000.dma",id=dma,x-irqfd=false,x-forward=false \
        -append "earlyprintk console=ttyAMA0" \
        -kernel zImage -nographic

Then run DMA test:
mount -t debugfs none /sys/kernel/debug
echo 1 > /sys/kernel/debug/vosys_dmatest/start

Results can be checked using dmesg.

Baptiste Reynal (3):
hw/vfio/sysbus-fdt: generic add_generic_fdt_node hw/vfio: amba device support
hw/vfio: add pl330 device support

 hw/arm/sysbus-fdt.c           | 34 +++++++++++++++++++++++++++++-----
 hw/vfio/Makefile.objs         |  1 +
 hw/vfio/pl330.c               | 41 +++++++++++++++++++++++++++++++++++++++++
 hw/vfio/platform.c            | 15 ++++++++++++---
 include/hw/vfio/vfio-common.h |  1 +
 include/hw/vfio/vfio-pl330.h  | 26 ++++++++++++++++++++++++++
 6 files changed, 110 insertions(+), 8 deletions(-)
 create mode 100644 hw/vfio/pl330.c
 create mode 100644 include/hw/vfio/vfio-pl330.h
Signature · 1 line
2.1.3
#1 lore raw

RFC PATCH 1/3 hw/vfio/sysbus-fdt: generic add_generic_fdt_node

Modify add_calxeda_midway_xgmac_fdt_node to make it more generic. Add multiple compatible strings support.

---
 hw/arm/sysbus-fdt.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
hw/arm/sysbus-fdt.c +16 -5
index 15bb50c..125ba37 100644
@@ -58,12 +58,12 @@ typedef struct NodeCreationPair {
 /* Device Specific Code */
 
 /**
- * add_calxeda_midway_xgmac_fdt_node
+ * add_device_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)
+static int add_generic_fdt_node(SysBusDevice *sbdev, void *opaque)
 {
     PlatformBusFdtData *data = opaque;
     PlatformBusDevice *pbus = data->pbus;
@@ -80,6 +80,18 @@ static int add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void *opaque)
     VFIODevice *vbasedev = &vdev->vbasedev;
     Object *obj = OBJECT(sbdev);
 
+    /*
+     * Process compatible string to deal with multiple strings
+     * (; is replaced by \0)
+     */
+    char *compat = g_strdup(vdev->compat);
+    compat_str_len = strlen(compat) + 1;
+
+    char *semicolon = compat;
+    while ((semicolon = strchr(semicolon, ';')) != NULL) {
+        *semicolon = '\0';
+    }
+
     mmio_base = object_property_get_int(obj, "mmio[0]", NULL);
 
     nodename = g_strdup_printf("%s/%s@%" PRIx64, parent_node,
@@ -88,9 +100,8 @@ static int add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void *opaque)
 
     qemu_fdt_add_subnode(fdt, nodename);
 
-    compat_str_len = strlen(vdev->compat) + 1;
     qemu_fdt_setprop(fdt, nodename, "compatible",
-                          vdev->compat, compat_str_len);
+                          compat, compat_str_len);
 
     reg_attr = g_new(uint64_t, vbasedev->num_regions*4);
 
@@ -140,7 +151,7 @@ fail:
 
 /* list of supported dynamic sysbus devices */
 static const NodeCreationPair add_fdt_node_functions[] = {
-{TYPE_VFIO_CALXEDA_XGMAC, add_calxeda_midway_xgmac_fdt_node},
+{TYPE_VFIO_CALXEDA_XGMAC, add_generic_fdt_node},
 {"", NULL}, /*last element*/
 };
 
Signature · 1 line
2.1.3
#5 lore raw

RFC PATCH 2/3 hw/vfio: amba device support

In reply to Baptiste Reynal

Add VFIO_DEVICE_TYPE_AMBA.
Differentiate amba and platform devices according to compatible string. If the device is amba, clocks description is added in the fd.

---
 hw/arm/sysbus-fdt.c           | 11 +++++++++++
 hw/vfio/platform.c            | 15 ++++++++++++---
 include/hw/vfio/vfio-common.h |  1 +
 3 files changed, 24 insertions(+), 3 deletions(-)
hw/arm/sysbus-fdt.c +11 -0
index 125ba37..41b4c87 100644
@@ -62,6 +62,8 @@ typedef struct NodeCreationPair {
  *
  * Generates a very simple node with following properties:
  * compatible string, regs, interrupts
+ * And the following properties if it is on an AMBA bus :
+ * clocks, clock-names
  */
 static int add_generic_fdt_node(SysBusDevice *sbdev, void *opaque)
 {
@@ -103,6 +105,15 @@ static int add_generic_fdt_node(SysBusDevice *sbdev, void *opaque)
     qemu_fdt_setprop(fdt, nodename, "compatible",
                           compat, compat_str_len);
 
+    if (vbasedev->type == VFIO_DEVICE_TYPE_AMBA) {
+        /* Setup clocks for AMBA device */
+        qemu_fdt_setprop_cells(fdt, nodename, "clocks",
+                qemu_fdt_getprop_cell(fdt, "/apb-pclk", "phandle"));
+        char clock_names[] = "apb_pclk";
+        qemu_fdt_setprop(fdt, nodename, "clock-names", clock_names,
+                sizeof(clock_names));
+    }
+
     reg_attr = g_new(uint64_t, vbasedev->num_regions*4);
 
     for (i = 0; i < vbasedev->num_regions; i++) {
hw/vfio/platform.c +12 -3
index 39eef08..0a96178 100644
@@ -563,8 +563,13 @@ static int vfio_base_device_init(VFIODevice *vbasedev)
     }
 
     /* Check that the host device exists */
-    snprintf(path, sizeof(path), "/sys/bus/platform/devices/%s/",
-             vbasedev->name);
+    if (vbasedev->type == VFIO_DEVICE_TYPE_AMBA) {
+        snprintf(path, sizeof(path), "/sys/bus/amba/devices/%s/",
+                vbasedev->name);
+    } else {
+        snprintf(path, sizeof(path), "/sys/bus/platform/devices/%s/",
+                vbasedev->name);
+    }
 
     if (stat(path, &st) < 0) {
         error_report("vfio: error: no such host device: %s", path);
@@ -661,7 +666,11 @@ static void vfio_platform_realize(DeviceState *dev, Error **errp)
     VFIODevice *vbasedev = &vdev->vbasedev;
     int i, ret;
 
-    vbasedev->type = VFIO_DEVICE_TYPE_PLATFORM;
+    if (strstr(vdev->compat, "arm,primecell")) {
+        vbasedev->type = VFIO_DEVICE_TYPE_AMBA;
+    } else {
+        vbasedev->type = VFIO_DEVICE_TYPE_PLATFORM;
+    }
     vbasedev->ops = &vfio_platform_ops;
 
 #ifdef CONFIG_KVM
include/hw/vfio/vfio-common.h +1 -0
index 58fd786..2f1b09c 100644
@@ -49,6 +49,7 @@ extern int vfio_kvm_device_fd;
 enum {
     VFIO_DEVICE_TYPE_PCI = 0,
     VFIO_DEVICE_TYPE_PLATFORM = 1,
+    VFIO_DEVICE_TYPE_AMBA = 2,
 };
 
 typedef struct VFIORegion {
Signature · 1 line
2.1.3
#7 lore raw

RFC PATCH 3/3 hw/vfio: add pl330 device support

In reply to Baptiste Reynal

Create a meta-device for PL330 DMA.

---
 hw/arm/sysbus-fdt.c          |  2 ++
 hw/vfio/Makefile.objs        |  1 +
 hw/vfio/pl330.c              | 41 +++++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio-pl330.h | 26 ++++++++++++++++++++++++++
 4 files changed, 70 insertions(+)
 create mode 100644 hw/vfio/pl330.c
 create mode 100644 include/hw/vfio/vfio-pl330.h
hw/arm/sysbus-fdt.c +2 -0
index 41b4c87..1141185 100644
@@ -28,6 +28,7 @@
 #include "sysemu/sysemu.h"
 #include "hw/vfio/vfio-platform.h"
 #include "hw/vfio/vfio-calxeda-xgmac.h"
+#include "hw/vfio/vfio-pl330.h"
 
 /*
  * internal struct that contains the information to create dynamic
@@ -163,6 +164,7 @@ fail:
 /* list of supported dynamic sysbus devices */
 static const NodeCreationPair add_fdt_node_functions[] = {
 {TYPE_VFIO_CALXEDA_XGMAC, add_generic_fdt_node},
+{TYPE_VFIO_PL330, add_generic_fdt_node},
 {"", NULL}, /*last element*/
 };
 
hw/vfio/Makefile.objs +1 -0
index 913ab14..be3023b 100644
@@ -3,4 +3,5 @@ obj-$(CONFIG_SOFTMMU) += common.o
 obj-$(CONFIG_PCI) += pci.o
 obj-$(CONFIG_SOFTMMU) += platform.o
 obj-$(CONFIG_SOFTMMU) += calxeda_xgmac.o
+obj-$(CONFIG_SOFTMMU) += pl330.o
 endif
hw/vfio/pl330.c new file +41 -0

41 lines not on this page · raw message

include/hw/vfio/vfio-pl330.h new file +26 -0
new file mode 100644
index 0000000..1cdf039
@@ -0,0 +1,26 @@
+#ifndef HW_VFIO_VFIO_PL330
+#define HW_VFIO_VFIO_PL330
+
+#include "hw/vfio/vfio-platform.h"
+
+#define TYPE_VFIO_PL330 "vfio-pl330"
+
+typedef struct VFIOPl330Device {
+    VFIOPlatformDevice vdev;
+} VFIOPl330Device;
+
+typedef struct VFIOPl330DeviceClass {
+    VFIOPlatformDeviceClass parent_class;
+    DeviceRealize parent_realize;
+} VFIOPl330DeviceClass;
+
+#define VFIO_PL330_DEVICE(obj) \
+     OBJECT_CHECK(VFIOPl330Device, (obj), TYPE_VFIO_PL330)
+#define VFIO_PL330_DEVICE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(VFIOPl330DeviceClass, (klass), \
+                        TYPE_VFIO_PL330)
+#define VFIO_PL330_DEVICE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(VFIOPl330DeviceClass, (obj), \
+                        TYPE_VFIO_PL330)
+
+#endif
Signature · 1 line
2.1.3
#8 lore raw
In reply to Baptiste Reynal
Quoted 8 lines · Baptiste Reynal

The following series add VFIO support for AMBA devices.

It introduces multiple compatible string support to deal with arm,primecell compatible string.

The VFIOPlatformDevice now checks for this string and performs amba specific operations if it is present (change path of the device, add clock in the fd).

Quoted 7 lines

This patch applies on top of http://git.linaro.org/people/eric.auger/qemu.git
on branch vfio_integ_v9_rc6_official_dynsysbus_v6 for irqfd support.

TODO: The IRQ forwarding doesn't work.

The series has been tested using PL330 device, irq forwarding doesn't work. (The test hangs on the first IRQ).

Hi Baptiste,

If am not wrong your branch below does not contain the requested kernel patches for both irqfd and forwarding. Please take the requested pieces on my linux git:
last official one can be taken at
http://git.linaro.org/people/eric.auger/linux.git (branch 3.18-rc6-v10) All the requested kernel dependencies are quoted in
http://lists.gnu.org/archive/html/qemu-devel/2014-11/msg04372.html. That should help ;-)

Best Regards

Eric

Quoted 32 lines

The test performed relies on a special guest kernel, which can be found here
http://github.com/virtualopensystems/linux-kvm-arm.git on branch vfio-platform-v6-guide, with CONFIG_KVM, CONFIG_ARM_SMMU, CONFIG_PL330_DMA and CONFIG_VOSYS_DMATEST enabled.

Run qemu using this command:

./qemu-system-arm -M virt -m 512M -enable-kvm \
        -device vfio-pl330,host="2c0a0000.dma",id=dma,x-irqfd=false,x-forward=false \
        -append "earlyprintk console=ttyAMA0" \
        -kernel zImage -nographic

Then run DMA test:
mount -t debugfs none /sys/kernel/debug
echo 1 > /sys/kernel/debug/vosys_dmatest/start

Results can be checked using dmesg.

Baptiste Reynal (3):
hw/vfio/sysbus-fdt: generic add_generic_fdt_node hw/vfio: amba device support
hw/vfio: add pl330 device support

 hw/arm/sysbus-fdt.c           | 34 +++++++++++++++++++++++++++++-----
 hw/vfio/Makefile.objs         |  1 +
 hw/vfio/pl330.c               | 41 +++++++++++++++++++++++++++++++++++++++++
 hw/vfio/platform.c            | 15 ++++++++++++---
 include/hw/vfio/vfio-common.h |  1 +
 include/hw/vfio/vfio-pl330.h  | 26 ++++++++++++++++++++++++++
 6 files changed, 110 insertions(+), 8 deletions(-)
 create mode 100644 hw/vfio/pl330.c
 create mode 100644 include/hw/vfio/vfio-pl330.h
#2 lore raw

Re: [Qemu-devel] [RFC PATCH 1/3] hw/vfio/sysbus-fdt: generic add_generic_fdt_node

In reply to Baptiste Reynal
Quoted 2 lines · Baptiste Reynal

Modify add_calxeda_midway_xgmac_fdt_node to make it more generic. Add multiple compatible strings support.

Hi Baptiste,

Although I understand you may be tempted to transform the Calxeda basic node creation function into something more generic, we came to the current result after long discussions with Alex Graf. This generic function was something released in the past but transformed into something specific at the end.

Typically the fact the IRQ is edge sensitive or level sensitive may depend on the device and it would be arbitrary here to choose either in a "generic" node creation.

So the current trend for new devices is to add another entry in the add_fdt_node_functions array; genericity target was argued in the past and rejected.

If you want to do something going in the direction of genericity I would advise you to investigate using Antonios API ([RFC 0/4] VFIO: PLATFORM:
Return device tree info for a platform device node). This could typically enable to get the egde/level sensitive characteritics.

Quoted 30 lines
---
 hw/arm/sysbus-fdt.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
hw/arm/sysbus-fdt.c +3 -2
index 15bb50c..125ba37 100644
@@ -58,12 +58,12 @@ typedef struct NodeCreationPair {
 /* Device Specific Code */
 
 /**
- * add_calxeda_midway_xgmac_fdt_node
+ * add_device_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)
+static int add_generic_fdt_node(SysBusDevice *sbdev, void *opaque)
 {
     PlatformBusFdtData *data = opaque;
     PlatformBusDevice *pbus = data->pbus;
@@ -80,6 +80,18 @@ static int add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void *opaque)
     VFIODevice *vbasedev = &vdev->vbasedev;
     Object *obj = OBJECT(sbdev);
 
+    /*

hw/arm/sysbus-fdt.c static int add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void *opaque) · line 93

Quoted 10 lines
hw/arm/sysbus-fdt.c +10 -0
+     * Process compatible string to deal with multiple strings
+     * (; is replaced by \0)
+     */
+    char *compat = g_strdup(vdev->compat);
+    compat_str_len = strlen(compat) + 1;
+
+    char *semicolon = compat;
+    while ((semicolon = strchr(semicolon, ';')) != NULL) {
+        *semicolon = '\0';
+    }

why can't you format the string directly in the corresponding VFIO AMBA device? Formerly we had this problem of conversion since we passed the format string in qemu command line.

Best Regards

Eric

Quoted 25 lines
hw/arm/sysbus-fdt.c +3 -3
+
     mmio_base = object_property_get_int(obj, "mmio[0]", NULL);
 
     nodename = g_strdup_printf("%s/%s@%" PRIx64, parent_node,
@@ -88,9 +100,8 @@ static int add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void *opaque)
 
     qemu_fdt_add_subnode(fdt, nodename);
 
-    compat_str_len = strlen(vdev->compat) + 1;
     qemu_fdt_setprop(fdt, nodename, "compatible",
-                          vdev->compat, compat_str_len);
+                          compat, compat_str_len);
 
     reg_attr = g_new(uint64_t, vbasedev->num_regions*4);
 
@@ -140,7 +151,7 @@ fail:
 
 /* list of supported dynamic sysbus devices */
 static const NodeCreationPair add_fdt_node_functions[] = {
-{TYPE_VFIO_CALXEDA_XGMAC, add_calxeda_midway_xgmac_fdt_node},
+{TYPE_VFIO_CALXEDA_XGMAC, add_generic_fdt_node},
 {"", NULL}, /*last element*/
 };
 
#6 lore raw

Re: [Qemu-devel] [RFC PATCH 2/3] hw/vfio: amba device support

In reply to Baptiste Reynal
Quoted 25 lines · Baptiste Reynal

Add VFIO_DEVICE_TYPE_AMBA.
Differentiate amba and platform devices according to compatible string. If the device is amba, clocks description is added in the fd.

---
 hw/arm/sysbus-fdt.c           | 11 +++++++++++
 hw/vfio/platform.c            | 15 ++++++++++++---
 include/hw/vfio/vfio-common.h |  1 +
 3 files changed, 24 insertions(+), 3 deletions(-)
hw/arm/sysbus-fdt.c +2 -0
index 125ba37..41b4c87 100644
@@ -62,6 +62,8 @@ typedef struct NodeCreationPair {
  *
  * Generates a very simple node with following properties:
  * compatible string, regs, interrupts
+ * And the following properties if it is on an AMBA bus :
+ * clocks, clock-names
  */
 static int add_generic_fdt_node(SysBusDevice *sbdev, void *opaque)
 {

hw/arm/sysbus-fdt.c static int add_generic_fdt_node(SysBusDevice *sbdev, void *opaque) · line 111

Quoted 7 lines
hw/arm/sysbus-fdt.c +4 -0
@@ -103,6 +105,15 @@ static int add_generic_fdt_node(SysBusDevice *sbdev, void *opaque)
     qemu_fdt_setprop(fdt, nodename, "compatible",
                           compat, compat_str_len);
 
+    if (vbasedev->type == VFIO_DEVICE_TYPE_AMBA) {
+        /* Setup clocks for AMBA device */
+        qemu_fdt_setprop_cells(fdt, nodename, "clocks",
+                qemu_fdt_getprop_cell(fdt, "/apb-pclk", "phandle"));

Shouldn't you test if this clock node exists in the guest device tree?

Quoted 29 lines
hw/arm/sysbus-fdt.c +5 -0
+        char clock_names[] = "apb_pclk";
+        qemu_fdt_setprop(fdt, nodename, "clock-names", clock_names,
+                sizeof(clock_names));
+    }
+
     reg_attr = g_new(uint64_t, vbasedev->num_regions*4);
 
     for (i = 0; i < vbasedev->num_regions; i++) {
hw/vfio/platform.c +7 -2
index 39eef08..0a96178 100644
@@ -563,8 +563,13 @@ static int vfio_base_device_init(VFIODevice *vbasedev)
     }
 
     /* Check that the host device exists */
-    snprintf(path, sizeof(path), "/sys/bus/platform/devices/%s/",
-             vbasedev->name);
+    if (vbasedev->type == VFIO_DEVICE_TYPE_AMBA) {
+        snprintf(path, sizeof(path), "/sys/bus/amba/devices/%s/",
+                vbasedev->name);
+    } else {
+        snprintf(path, sizeof(path), "/sys/bus/platform/devices/%s/",
+                vbasedev->name);
+    }
 
     if (stat(path, &st) < 0) {
         error_report("vfio: error: no such host device: %s", path);

hw/vfio/platform.c static void vfio_platform_realize(DeviceState *dev, Error **errp) · line 674

Quoted 10 lines
hw/vfio/platform.c +5 -1
@@ -661,7 +666,11 @@ static void vfio_platform_realize(DeviceState *dev, Error **errp)
     VFIODevice *vbasedev = &vdev->vbasedev;
     int i, ret;
 
-    vbasedev->type = VFIO_DEVICE_TYPE_PLATFORM;
+    if (strstr(vdev->compat, "arm,primecell")) {
+        vbasedev->type = VFIO_DEVICE_TYPE_AMBA;
+    } else {
+        vbasedev->type = VFIO_DEVICE_TYPE_PLATFORM;
+    }
     vbasedev->ops = &vfio_platform_ops;

The plan is to use VFIO_DEVICE_GET_INFO instead. Alex recently requested we test the flags. We need a header sync for that.

Best Regards

Eric

Quoted 15 lines
hw/vfio/platform.c +0 -0
 #ifdef CONFIG_KVM
include/hw/vfio/vfio-common.h +1 -0
index 58fd786..2f1b09c 100644
@@ -49,6 +49,7 @@ extern int vfio_kvm_device_fd;
 enum {
     VFIO_DEVICE_TYPE_PCI = 0,
     VFIO_DEVICE_TYPE_PLATFORM = 1,
+    VFIO_DEVICE_TYPE_AMBA = 2,
 };
 
 typedef struct VFIORegion {
#3 lore raw

Re: [Qemu-devel] [RFC PATCH 1/3] hw/vfio/sysbus-fdt: generic add_generic_fdt_node

In reply to Eric Auger
Quoted 16 lines · Eric Auger
Quoted 2 lines · Baptiste Reynal

Modify add_calxeda_midway_xgmac_fdt_node to make it more generic. Add multiple compatible strings support.

Hi Baptiste,

Although I understand you may be tempted to transform the Calxeda basic node creation function into something more generic, we came to the current result after long discussions with Alex Graf. This generic function was something released in the past but transformed into something specific at the end.

Typically the fact the IRQ is edge sensitive or level sensitive may depend on the device and it would be arbitrary here to choose either in a "generic" node creation.

Quoted 9 lines

So the current trend for new devices is to add another entry in the add_fdt_node_functions array; genericity target was argued in the past and rejected.

If you want to do something going in the direction of genericity I would advise you to investigate using Antonios API ([RFC 0/4] VFIO: PLATFORM:
Return device tree info for a platform device node). This could typically enable to get the egde/level sensitive characteritics.

I'm not sure I totally understand your point, but creating a new add_pl330_fdt_node function which will call to add_calxeda_midway_xgmac_fdt_node and perform amba specific process (multiple compatible string and clocks) seems to be a good solution for you ?

Quoted 47 lines
Quoted 12 lines
---
 hw/arm/sysbus-fdt.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
hw/arm/sysbus-fdt.c +0 -0
index 15bb50c..125ba37 100644

hw/arm/sysbus-fdt.c typedef struct NodeCreationPair { · line 66

Quoted 10 lines
hw/arm/sysbus-fdt.c +1 -2
@@ -58,12 +58,12 @@ typedef struct NodeCreationPair {
 /* Device Specific Code */
 
 /**
- * add_calxeda_midway_xgmac_fdt_node
+ * add_device_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)

hw/arm/sysbus-fdt.c static int

Quoted 5 lines
hw/arm/sysbus-fdt.c +1 -0
+static int add_generic_fdt_node(SysBusDevice *sbdev, void *opaque)
 {
     PlatformBusFdtData *data = opaque;
     PlatformBusDevice *pbus = data->pbus;
@@ -80,6 +80,18 @@ static int

add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void *opaque)

Quoted 4 lines
hw/arm/sysbus-fdt.c +1 -0
     VFIODevice *vbasedev = &vdev->vbasedev;
     Object *obj = OBJECT(sbdev);
 
+    /*

hw/arm/sysbus-fdt.c static int add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void *opaque) · line 93

Quoted 10 lines
hw/arm/sysbus-fdt.c +10 -0
+     * Process compatible string to deal with multiple strings
+     * (; is replaced by \0)
+     */
+    char *compat = g_strdup(vdev->compat);
+    compat_str_len = strlen(compat) + 1;
+
+    char *semicolon = compat;
+    while ((semicolon = strchr(semicolon, ';')) != NULL) {
+        *semicolon = '\0';
+    }

why can't you format the string directly in the corresponding VFIO AMBA device? Formerly we had this problem of conversion since we passed the format string in qemu command line.

Quoted 6 lines

Best Regards

Eric

From my point of view, formatting the string directly in VFIO AMBA device

will mess a lot with string function, but I can use an array of string in VFIOPlatformDevice to avoid it.

Best Regards,

Baptiste

Quoted 28 lines

+

hw/arm/sysbus-fdt.c static int

Quoted 4 lines
hw/arm/sysbus-fdt.c +0 -0
     mmio_base = object_property_get_int(obj, "mmio[0]", NULL);
 
     nodename = g_strdup_printf("%s/%s@%" PRIx64, parent_node,
@@ -88,9 +100,8 @@ static int

add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void *opaque)

Quoted 20 lines
hw/arm/sysbus-fdt.c +2 -3
     qemu_fdt_add_subnode(fdt, nodename);
 
-    compat_str_len = strlen(vdev->compat) + 1;
     qemu_fdt_setprop(fdt, nodename, "compatible",
-                          vdev->compat, compat_str_len);
+                          compat, compat_str_len);
 
     reg_attr = g_new(uint64_t, vbasedev->num_regions*4);
 
@@ -140,7 +151,7 @@ fail:
 
 /* list of supported dynamic sysbus devices */
 static const NodeCreationPair add_fdt_node_functions[] = {
-{TYPE_VFIO_CALXEDA_XGMAC, add_calxeda_midway_xgmac_fdt_node},
+{TYPE_VFIO_CALXEDA_XGMAC, add_generic_fdt_node},
 {"", NULL}, /*last element*/
 };
 
#4 lore raw

Re: [Qemu-devel] [RFC PATCH 1/3] hw/vfio/sysbus-fdt: generic add_generic_fdt_node

Quoted 30 lines · Baptiste Reynal

On Wed, Dec 17, 2014 at 2:32 PM, Eric Auger <[email protected] <mailto:[email protected]>> wrote:

On 12/17/2014 11:09 AM, Baptiste Reynal wrote:
> Modify add_calxeda_midway_xgmac_fdt_node to make it more generic. > Add multiple compatible strings support.
Hi Baptiste,

Although I understand you may be tempted to transform the Calxeda basic node creation function into something more generic, we came to the current result after long discussions with Alex Graf. This generic function was something released in the past but transformed into something specific at the end.

Typically the fact the IRQ is edge sensitive or level sensitive may depend on the device and it would be arbitrary here to choose either in a "generic" node creation.

So the current trend for new devices is to add another entry in the add_fdt_node_functions array; genericity target was argued in the past and rejected.

If you want to do something going in the direction of genericity I would advise you to investigate using Antonios API ([RFC 0/4] VFIO: PLATFORM:
Return device tree info for a platform device node). This could typically enable to get the egde/level sensitive characteritics.

Quoted 6 lines

I'm not sure I totally understand your point, but creating a new add_pl330_fdt_node function which will call to add_calxeda_midway_xgmac_fdt_node and perform amba specific process (multiple compatible string and clocks) seems to be a good solution for you ?

No I had in mind the amba node creation function should duplicate the code, have its own compat string manipulation if needed, add its own clock properties ...

Maybe we could devise some helper function for building the reg property and interrupt property?

BR

Eric

Quoted 88 lines
Quoted 3 lines
    <mailto:[email protected]>>
    > ---
    >  hw/arm/sysbus-fdt.c | 21 ++++++++++++++++-----
    >  1 file changed, 16 insertions(+), 5 deletions(-)
    >
    > diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c
    > index 15bb50c..125ba37 100644
    > --- a/hw/arm/sysbus-fdt.c
    > +++ b/hw/arm/sysbus-fdt.c
    > @@ -58,12 +58,12 @@ typedef struct NodeCreationPair {
    >  /* Device Specific Code */
    >
    >  /**
    > - * add_calxeda_midway_xgmac_fdt_node
    > + * add_device_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)
    > +static int add_generic_fdt_node(SysBusDevice *sbdev, void *opaque)
    >  {
    >      PlatformBusFdtData *data = opaque;
    >      PlatformBusDevice *pbus = data->pbus;
    > @@ -80,6 +80,18 @@ static int
    add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void *opaque)
    >      VFIODevice *vbasedev = &vdev->vbasedev;
    >      Object *obj = OBJECT(sbdev);
    >
    > +    /*
    > +     * Process compatible string to deal with multiple strings
    > +     * (; is replaced by \0)
    > +     */
    > +    char *compat = g_strdup(vdev->compat);
    > +    compat_str_len = strlen(compat) + 1;
    > +
    > +    char *semicolon = compat;
    > +    while ((semicolon = strchr(semicolon, ';')) != NULL) {
    > +        *semicolon = '\0';
    > +    }
    why can't you format the string directly in the corresponding VFIO AMBA
    device? Formerly we had this problem of conversion since we passed the
    format string in qemu command line.

    Best Regards

    Eric

From my point of view, formatting the string directly in VFIO AMBA device will mess a lot with string function, but I can use an array of string in VFIOPlatformDevice to avoid it.

Best Regards,

Baptiste

hw/arm/sysbus-fdt.c static int

Quoted 5 lines
hw/arm/sysbus-fdt.c +1 -0
+
     mmio_base = object_property_get_int(obj, "mmio[0]", NULL);
 
     nodename = g_strdup_printf("%s/%s@%" PRIx64, parent_node,
@@ -88,9 +100,8 @@ static int
    add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void *opaque)
    >
    >      qemu_fdt_add_subnode(fdt, nodename);
    >
    > -    compat_str_len = strlen(vdev->compat) + 1;
    >      qemu_fdt_setprop(fdt, nodename, "compatible",
    > -                          vdev->compat, compat_str_len);
    > +                          compat, compat_str_len);
    >
    >      reg_attr = g_new(uint64_t, vbasedev->num_regions*4);
    >
    > @@ -140,7 +151,7 @@ fail:
    >
    >  /* list of supported dynamic sysbus devices */
    >  static const NodeCreationPair add_fdt_node_functions[] = {
    > -{TYPE_VFIO_CALXEDA_XGMAC, add_calxeda_midway_xgmac_fdt_node},
    > +{TYPE_VFIO_CALXEDA_XGMAC, add_generic_fdt_node},
    >  {"", NULL}, /*last element*/
    >  };
    >
    >