Adapt arm,pl330 function to use the vfio device property API. Clock apb-pclk is the default if a clock is needed by the device. Three optional parameters are taken into account : - #dma-cells - #dma-channels - #dma-requests Signed-off-by: Baptiste Reynal <b.reynal@xxxxxxxxxxxxxxxxxxxxxx> --- v1 -> v2: add some comments free pointers (property) --- hw/arm/sysbus-fdt.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c index c3b3d97..d507daa 100644 --- a/hw/arm/sysbus-fdt.c +++ b/hw/arm/sysbus-fdt.c @@ -148,6 +148,60 @@ static int set_regions_fdt_node(char *nodename, SysBusDevice *sbdev, } /** + * set_arm_primecell_node + * + * Set node properties for an arm primecell device + * see Documentation/devicetree/bindings/arm/primecell.txt + */ +static int set_arm_primecell_node(char *nodename, SysBusDevice *sbdev, void + *opaque) +{ + PlatformBusFDTData *data = opaque; + void *fdt = data->fdt; + int ret; + VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev); + VFIODevice *vbasedev = &vdev->vbasedev; + struct vfio_dev_property *property; + + /* Optional properties */ + property = vfio_get_dev_property(vbasedev->fd, "interrupts", + VFIO_DEV_PROPERTY_TYPE_U32); + if (property != NULL) { + ret = set_interrupts_fdt_node(nodename, sbdev, opaque); + if (ret < 0) { + error_report("could not set interrupts property of node %s", + nodename); + goto fail; + } + g_free(property); + } + + property = vfio_get_dev_property(vbasedev->fd, "clock-names", + VFIO_DEV_PROPERTY_TYPE_STRINGS); + if (property != NULL) { + /* If a clock is attached, we rely on apb-pclk */ + /* Check clock existence */ + ret = fdt_path_offset(fdt, "/apb-pclk"); + + if (ret < 0) { + error_report("could not set clocks property of node %s", nodename); + goto fail; + } else { + 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)); + } + g_free(property); + } + + return 0; + +fail: + return -1; +} +/** * add_calxeda_midway_xgmac_fdt_node * * Generates a very simple node with following properties: @@ -205,6 +259,8 @@ fail: * * Generates a very simple node with following properties: * compatible string, regs, interrupts, clocks, clock-names + * + * See Documentation/devicetree/bindings/dma/arm-pl330.txt */ static int add_arm_pl330_fdt_node(SysBusDevice *sbdev, void *opaque) { @@ -218,6 +274,8 @@ static int add_arm_pl330_fdt_node(SysBusDevice *sbdev, void *opaque) VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev); VFIODevice *vbasedev = &vdev->vbasedev; Object *obj = OBJECT(sbdev); + struct vfio_dev_property *property; + int propint; mmio_base = object_property_get_int(obj, "mmio[0]", NULL); @@ -227,6 +285,13 @@ static int add_arm_pl330_fdt_node(SysBusDevice *sbdev, void *opaque) qemu_fdt_add_subnode(fdt, nodename); + ret = set_arm_primecell_node(nodename, sbdev, opaque); + if (ret < 0) { + error_report("could not set arm,primecell properties of node %s", + nodename); + goto fail; + } + /* * Process compatible string to deal with multiple strings * (; is replaced by \0) @@ -272,6 +337,52 @@ static int add_arm_pl330_fdt_node(SysBusDevice *sbdev, void *opaque) goto fail; } + /* Optional properties */ + property = vfio_get_dev_property(vbasedev->fd, "#dma-cells", + VFIO_DEV_PROPERTY_TYPE_U32); + if (property != NULL) { + propint = cpu_to_be32(((__u32 *) property->data)[0]); + ret = qemu_fdt_setprop(fdt, nodename, "#dma-cells", &propint, + sizeof(int)); + if (ret < 0) { + error_report("could not set #dma-cells property of node %s", + nodename); + g_free(property); + goto fail; + } + g_free(property); + } + + property = vfio_get_dev_property(vbasedev->fd, "#dma-channels", + VFIO_DEV_PROPERTY_TYPE_U32); + if (property != NULL) { + propint = cpu_to_be32(((__u32 *) property->data)[0]); + ret = qemu_fdt_setprop(fdt, nodename, "#dma-cells", &propint, + sizeof(int)); + if (ret < 0) { + error_report("could not set #dma-cells property of node %s", + nodename); + g_free(property); + goto fail; + } + g_free(property); + } + + property = vfio_get_dev_property(vbasedev->fd, "#dma-requests", + VFIO_DEV_PROPERTY_TYPE_U32); + if (property != NULL) { + propint = cpu_to_be32(((__u32 *) property->data)[0]); + ret = qemu_fdt_setprop(fdt, nodename, "#dma-cells", &propint, + sizeof(int)); + if (ret < 0) { + error_report("could not set #dma-cells property of node %s", + nodename); + g_free(property); + goto fail; + } + g_free(property); + } + g_free(nodename); return 0; -- 2.3.0 _______________________________________________ kvmarm mailing list kvmarm@xxxxxxxxxxxxxxxxxxxxx https://lists.cs.columbia.edu/mailman/listinfo/kvmarm