From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUBiJ-0001TW-2d for qemu-devel@nongnu.org; Mon, 22 Apr 2013 04:03:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UUBiE-0006ik-CJ for qemu-devel@nongnu.org; Mon, 22 Apr 2013 04:03:03 -0400 Received: from mail-pd0-f177.google.com ([209.85.192.177]:61626) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUBiE-0006iM-6x for qemu-devel@nongnu.org; Mon, 22 Apr 2013 04:02:58 -0400 Received: by mail-pd0-f177.google.com with SMTP id p11so87394pdj.8 for ; Mon, 22 Apr 2013 01:02:57 -0700 (PDT) From: Alexey Kardashevskiy Date: Mon, 22 Apr 2013 18:02:35 +1000 Message-Id: <1366617757-6604-2-git-send-email-aik@ozlabs.ru> In-Reply-To: <1366617757-6604-1-git-send-email-aik@ozlabs.ru> References: <1366617757-6604-1-git-send-email-aik@ozlabs.ru> Subject: [Qemu-devel] [PATCH 1/3] vfio: make some of VFIO API public List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex Williamson Cc: Alexey Kardashevskiy , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson The patch makes vfio_dma_map/vfio_dma_unmap functions public for explicit use by VFIO clients rather that just being called from MemoryListener. The patch also adds a "connect" parameter to the vfio_get_group() function to allow control over group and container creation and connection before any device from the group is actially created in QEMU. Cc: David Gibson Signed-off-by: Alexey Kardashevskiy --- hw/misc/vfio.c | 15 ++++++++------- include/hw/misc/vfio.h | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 include/hw/misc/vfio.h diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c index 693a9ff..503125e 100644 --- a/hw/misc/vfio.c +++ b/hw/misc/vfio.c @@ -39,6 +39,7 @@ #include "qemu/range.h" #include "sysemu/kvm.h" #include "sysemu/sysemu.h" +#include "hw/misc/vfio.h" /* #define DEBUG_VFIO */ #ifdef DEBUG_VFIO @@ -1877,8 +1878,8 @@ static void vfio_pci_write_config(PCIDevice *pdev, uint32_t addr, /* * DMA - Mapping and unmapping for the "type1" IOMMU interface used on x86 */ -static int vfio_dma_unmap(VFIOContainer *container, - hwaddr iova, ram_addr_t size) +int vfio_dma_unmap(VFIOContainer *container, + hwaddr iova, ram_addr_t size) { struct vfio_iommu_type1_dma_unmap unmap = { .argsz = sizeof(unmap), @@ -1895,8 +1896,8 @@ static int vfio_dma_unmap(VFIOContainer *container, return 0; } -static int vfio_dma_map(VFIOContainer *container, hwaddr iova, - ram_addr_t size, void *vaddr, bool readonly) +int vfio_dma_map(VFIOContainer *container, hwaddr iova, + ram_addr_t size, void *vaddr, bool readonly) { struct vfio_iommu_type1_dma_map map = { .argsz = sizeof(map), @@ -2706,7 +2707,7 @@ static void vfio_disconnect_container(VFIOGroup *group) } } -static VFIOGroup *vfio_get_group(int groupid) +VFIOGroup *vfio_get_group(int groupid, bool connect) { VFIOGroup *group; char path[32]; @@ -2747,7 +2748,7 @@ static VFIOGroup *vfio_get_group(int groupid) group->groupid = groupid; QLIST_INIT(&group->device_list); - if (vfio_connect_container(group)) { + if (connect && vfio_connect_container(group)) { error_report("vfio: failed to setup container for group %d", groupid); close(group->fd); g_free(group); @@ -2980,7 +2981,7 @@ static int vfio_initfn(PCIDevice *pdev) DPRINTF("%s(%04x:%02x:%02x.%x) group %d\n", __func__, vdev->host.domain, vdev->host.bus, vdev->host.slot, vdev->host.function, groupid); - group = vfio_get_group(groupid); + group = vfio_get_group(groupid, true); if (!group) { error_report("vfio: failed to get group %d", groupid); return -ENOENT; diff --git a/include/hw/misc/vfio.h b/include/hw/misc/vfio.h new file mode 100644 index 0000000..f39aef8 --- /dev/null +++ b/include/hw/misc/vfio.h @@ -0,0 +1,17 @@ +#ifndef VFIO_API_H +#define VFIO_API_H + +#include + +struct VFIOContainer; +struct VFIOGroup; + +extern int vfio_dma_unmap(struct VFIOContainer *container, + hwaddr iova, ram_addr_t size); + +extern int vfio_dma_map(struct VFIOContainer *container, hwaddr iova, + ram_addr_t size, void *vaddr, bool readonly); + +extern struct VFIOGroup *vfio_get_group(int groupid, bool connect); + +#endif -- 1.7.10.4