From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59277) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V6z0w-0002zi-5m for qemu-devel@nongnu.org; Wed, 07 Aug 2013 04:22:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V6z0m-0007WX-38 for qemu-devel@nongnu.org; Wed, 07 Aug 2013 04:22:38 -0400 Received: from mail-pd0-f180.google.com ([209.85.192.180]:65509) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V6z0l-0007WF-TA for qemu-devel@nongnu.org; Wed, 07 Aug 2013 04:22:28 -0400 Received: by mail-pd0-f180.google.com with SMTP id 15so1133408pdi.11 for ; Wed, 07 Aug 2013 01:22:27 -0700 (PDT) From: Alexey Kardashevskiy Date: Wed, 7 Aug 2013 18:21:30 +1000 Message-Id: <1375863692-12207-7-git-send-email-aik@ozlabs.ru> In-Reply-To: <1375863692-12207-1-git-send-email-aik@ozlabs.ru> References: <1375863692-12207-1-git-send-email-aik@ozlabs.ru> Subject: [Qemu-devel] [PATCH 6/8] spapr vfio: add vfio_container_spapr_get_info() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , "Michael S . Tsirkin" , Alexey Kardashevskiy , Alexander Graf , Alex Williamson , qemu-ppc@nongnu.org, Paolo Bonzini , Paul Mackerras , David Gibson As sPAPR platform supports DMA windows on a PCI bus, the information about their location and size should be passed into the guest via the device tree. The patch adds a helper to read this info from the container fd. Signed-off-by: Alexey Kardashevskiy --- hw/misc/vfio.c | 37 +++++++++++++++++++++++++++++++++++++ include/hw/misc/vfio.h | 11 +++++++++++ 2 files changed, 48 insertions(+) create mode 100644 include/hw/misc/vfio.h diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c index 3855efe..4571f64 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 @@ -3488,3 +3489,39 @@ static void register_vfio_pci_dev_type(void) } type_init(register_vfio_pci_dev_type) + +int vfio_container_spapr_get_info(AddressSpace *as, int32_t groupid, + struct vfio_iommu_spapr_tce_info *info, + int *group_fd) +{ + VFIOAddressSpace *space; + VFIOGroup *group; + VFIOContainer *container; + int ret, fd; + + space = vfio_get_address_space(as); + if (!space) { + return -1; + } + group = vfio_get_group(groupid, space); + if (!group) { + return -1; + } + container = group->container; + if (!group->container) { + return -1; + } + fd = container->fd; + if (!ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_SPAPR_TCE_IOMMU)) { + return -1; + } + 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)); + return -1; + } + *group_fd = group->fd; + + return 0; +} diff --git a/include/hw/misc/vfio.h b/include/hw/misc/vfio.h new file mode 100644 index 0000000..ac9a971 --- /dev/null +++ b/include/hw/misc/vfio.h @@ -0,0 +1,11 @@ +#ifndef VFIO_API_H +#define VFIO_API_H + +#include "qemu/typedefs.h" +#include + +extern int vfio_container_spapr_get_info(AddressSpace *as, int32_t groupid, + struct vfio_iommu_spapr_tce_info *info, + int *group_fd); + +#endif -- 1.8.3.2