From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40108) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUBiP-0001d5-4O for qemu-devel@nongnu.org; Mon, 22 Apr 2013 04:03:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UUBiK-0006ke-B3 for qemu-devel@nongnu.org; Mon, 22 Apr 2013 04:03:09 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:44372) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUBiK-0006kU-3C for qemu-devel@nongnu.org; Mon, 22 Apr 2013 04:03:04 -0400 Received: by mail-pd0-f176.google.com with SMTP id r11so3367190pdi.21 for ; Mon, 22 Apr 2013 01:03:03 -0700 (PDT) From: Alexey Kardashevskiy Date: Mon, 22 Apr 2013 18:02:36 +1000 Message-Id: <1366617757-6604-3-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 2/3] vfio: add support for spapr platform (powerpc64 server) 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 existing code assumes that containers are capable of multiple groups support which is not the case for POWERPC64 where groups are defined by the hardware configuration and cannot share one container. The earlier proposal for PPC64 support was: - spapr_phb_vfio_init(): create a spapr-pci-vfio-host-bridge, IOMMU ID is already known at this stage; - spapr_pci_vfio_scan(): start scanning the group and adding devices; - vfio_initfn(): the VFIO device init function allocates a group struct (if not yet); - vfio_get_group(): a group struct allocator allocates a container (if not yet); - vfio_connect_container(): connects a group to a container, requests POWERPC64 specific properties and calls a callback to spapr_pci.c passing those properties. As the group ID is knows from the very beginning (as it is supplied via the command line), it makes more sense to create group and container structs first and then add devices from this group. In order to achieve this, this patch adds a vfio_container_spapr_alloc() function which allocates sPAPR container and returns its properties which are a DMA window size and start. Cc: David Gibson Signed-off-by: Alexey Kardashevskiy --- hw/misc/vfio.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/misc/vfio.h | 3 ++ 2 files changed, 82 insertions(+) diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c index 503125e..adcbb80 100644 --- a/hw/misc/vfio.c +++ b/hw/misc/vfio.c @@ -2684,6 +2684,85 @@ static int vfio_connect_container(VFIOGroup *group) return 0; } +VFIOContainer *vfio_container_spapr_alloc(VFIOGroup *group, + struct vfio_iommu_spapr_tce_info *info) +{ + VFIOContainer *container; + int ret, fd; + + if (group->container) { + return NULL; + } + + fd = qemu_open("/dev/vfio/vfio", O_RDWR); + if (fd < 0) { + error_report("vfio: failed to open /dev/vfio/vfio: %m"); + return NULL; + } + + ret = ioctl(fd, VFIO_GET_API_VERSION); + if (ret != VFIO_API_VERSION) { + error_report("vfio: supported vfio version: %d, " + "reported version: %d", VFIO_API_VERSION, ret); + close(fd); + return NULL; + } + + container = g_malloc0(sizeof(*container)); + container->fd = fd; + + if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_SPAPR_TCE_IOMMU)) { + ret = ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &fd); + if (ret) { + error_report("vfio: failed to set group container: %s", + strerror(errno)); + g_free(container); + close(fd); + return NULL; + } + + ret = ioctl(fd, VFIO_SET_IOMMU, VFIO_SPAPR_TCE_IOMMU); + if (ret) { + error_report("vfio: failed to set iommu for container: %s", + strerror(errno)); + g_free(container); + close(fd); + return NULL; + } + + ret = ioctl(fd, VFIO_IOMMU_SPAPR_TCE_GET_INFO, info); + if (ret) { + error_report("vfio: failed to get iommu info for container: %s", + strerror(errno)); + g_free(container); + close(fd); + return NULL; + } + + ret = ioctl(container->fd, VFIO_IOMMU_ENABLE); + if (ret) { + error_report("vfio: failed to enable container: %s", + strerror(errno)); + g_free(container); + close(fd); + return NULL; + } + } else { + error_report("vfio: No available IOMMU models"); + g_free(container); + close(fd); + return NULL; + } + + QLIST_INIT(&container->group_list); + QLIST_INSERT_HEAD(&container_list, container, next); + + group->container = container; + QLIST_INSERT_HEAD(&container->group_list, group, container_next); + + return container; +} + static void vfio_disconnect_container(VFIOGroup *group) { VFIOContainer *container = group->container; diff --git a/include/hw/misc/vfio.h b/include/hw/misc/vfio.h index f39aef8..d1c7ff1 100644 --- a/include/hw/misc/vfio.h +++ b/include/hw/misc/vfio.h @@ -14,4 +14,7 @@ extern int vfio_dma_map(struct VFIOContainer *container, hwaddr iova, extern struct VFIOGroup *vfio_get_group(int groupid, bool connect); +extern struct VFIOContainer *vfio_container_spapr_alloc(struct VFIOGroup *group, + struct vfio_iommu_spapr_tce_info *info); + #endif -- 1.7.10.4