Received: from eggs.gnu.org ([2001:4830:134:3::10]:48541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6zEM-0001Rh-6E for qemu-devel@nongnu.org; Wed, 16 Nov 2016 07:22:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c6zEI-00027R-Ve for qemu-devel@nongnu.org; Wed, 16 Nov 2016 07:22:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36424) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c6zEI-00027D-O4 for qemu-devel@nongnu.org; Wed, 16 Nov 2016 07:22:18 -0500 References: <1477012975-12181-1-git-send-email-songwenjun@huawei.com> <1477012975-12181-2-git-send-email-songwenjun@huawei.com> From: Auger Eric Message-ID: <75f53080-aeb4-2270-2288-b0a91695e50f@redhat.com> Date: Wed, 16 Nov 2016 13:21:30 +0100 MIME-Version: 1.0 In-Reply-To: <1477012975-12181-2-git-send-email-songwenjun@huawei.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC, v1, 2/2] hw/arm/sysbus-fdt: enable vfio-hisi-hnsvf dynamic instantiation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Rick Song , qemu-devel@nongnu.org, alex.williamson@redhat.com Hi, On 21/10/2016 03:22, Rick Song wrote: > This patch allows the instantiation of the vfio-hisi-hnsvf device > from the QEMU command line (-device vfio-hisi-hnsvf,host=""). > A specialized device tree node is created for the guest, containing > compat, dma-coherent, reg and interrupts properties. For additional devices, Peter requested we re-structured the sysbus-fdt.c file to avoid it gets too large. We need to define relevant helpers and put node creation function elsewhere. Similarly I can propose something next week except if you want to do it. Thanks Eric > > Signed-off-by: Rick Song > --- > hw/arm/sysbus-fdt.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 71 insertions(+) > > diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c > index d68e3dc..207586f 100644 > --- a/hw/arm/sysbus-fdt.c > +++ b/hw/arm/sysbus-fdt.c > @@ -36,6 +36,7 @@ > #include "hw/vfio/vfio-platform.h" > #include "hw/vfio/vfio-calxeda-xgmac.h" > #include "hw/vfio/vfio-amd-xgbe.h" > +#include "hw/vfio/vfio-hisi-hnsvf.h" > #include "hw/arm/fdt.h" > > /* > @@ -413,6 +414,75 @@ static int add_amd_xgbe_fdt_node(SysBusDevice *sbdev, void *opaque) > return 0; > } > > +/** > + * add_hisi_hnsvf_fdt_node > + * > + * Generates a simple node with following properties: > + * compatible string, regs, interrupts, dma-coherent > + */ > +static int add_hisi_hnsvf_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, i; > + char *nodename; > + uint32_t *irq_attr, *reg_attr; > + uint64_t mmio_base, irq_number; > + VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev); > + VFIODevice *vbasedev = &vdev->vbasedev; > + VFIOINTp *intp; > + > + mmio_base = platform_bus_get_mmio_addr(pbus, sbdev, 0); > + 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); > + > + qemu_fdt_setprop(fdt, nodename, "dma-coherent", "", 0); > + > + reg_attr = g_new(uint32_t, vbasedev->num_regions * 2); > + for (i = 0; i < vbasedev->num_regions; i++) { > + mmio_base = platform_bus_get_mmio_addr(pbus, sbdev, i); > + reg_attr[2 * i] = cpu_to_be32(mmio_base); > + reg_attr[2 * i + 1] = cpu_to_be32( > + memory_region_size(vdev->regions[i]->mem)); > + } > + qemu_fdt_setprop(fdt, nodename, "reg", reg_attr, > + vbasedev->num_regions * 2 * sizeof(uint32_t)); > + > + 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(GIC_FDT_IRQ_TYPE_SPI); > + irq_attr[3 * i + 1] = cpu_to_be32(irq_number); > + > + QLIST_FOREACH(intp, &vdev->intp_list, next) { > + if (intp->pin == i) { > + break; > + } > + } > + > + if (intp->flags & VFIO_IRQ_INFO_AUTOMASKED) { > + irq_attr[3 * i + 2] = cpu_to_be32(GIC_FDT_IRQ_FLAGS_LEVEL_HI); > + } else { > + irq_attr[3 * i + 2] = cpu_to_be32(GIC_FDT_IRQ_FLAGS_EDGE_LO_HI); > + } > + } > + qemu_fdt_setprop(fdt, nodename, "interrupts", > + irq_attr, vbasedev->num_irqs * 3 * sizeof(uint32_t)); > + g_free(irq_attr); > + g_free(reg_attr); > + g_free(nodename); > + return 0; > + > +} > + > #endif /* CONFIG_LINUX */ > > /* list of supported dynamic sysbus devices */ > @@ -420,6 +490,7 @@ static const NodeCreationPair add_fdt_node_functions[] = { > #ifdef CONFIG_LINUX > {TYPE_VFIO_CALXEDA_XGMAC, add_calxeda_midway_xgmac_fdt_node}, > {TYPE_VFIO_AMD_XGBE, add_amd_xgbe_fdt_node}, > + {TYPE_VFIO_HISI_HNSVF, add_hisi_hnsvf_fdt_node}, > #endif > {"", NULL}, /* last element */ > }; >