From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Viktorin Subject: [PATCH v2 06/16] vfio: generalize pci_vfio_has_supported_extensions Date: Mon, 13 Jun 2016 15:01:56 +0200 Message-ID: <1465822926-23742-7-git-send-email-viktorin@rehivetech.com> References: <1465822926-23742-1-git-send-email-viktorin@rehivetech.com> Cc: Jan Viktorin , Anatoly Burakov , David Marchand , Keith Wiles , Santosh Shukla , Stephen Hemminger , Shreyansh Jain To: dev@dpdk.org Return-path: Received: from wes1-so1.wedos.net (wes1-so1.wedos.net [46.28.106.15]) by dpdk.org (Postfix) with ESMTP id 0E412559C for ; Mon, 13 Jun 2016 15:07:32 +0200 (CEST) In-Reply-To: <1465822926-23742-1-git-send-email-viktorin@rehivetech.com> In-Reply-To: <1461937456-22943-1-git-send-email-viktorin@rehivetech.com> References: <1461937456-22943-1-git-send-email-viktorin@rehivetech.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The pci_vfio_has_supported_extensions is not PCI-specific and it is a private function of the eal_pci_vfio.c. We just rename the function and make it available even for non-PCI devices. Signed-off-by: Jan Viktorin --- lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 36 +----------------------------- lib/librte_eal/linuxapp/eal/eal_vfio.c | 33 +++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_vfio.h | 4 ++++ 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c index f82368f..21aded7 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c @@ -203,40 +203,6 @@ pci_vfio_set_bus_master(int dev_fd) return 0; } -/* check if we have any supported extensions */ -static int -pci_vfio_has_supported_extensions(int vfio_container_fd) { - int ret; - unsigned idx, n_extensions = 0; - for (idx = 0; idx < RTE_DIM(iommu_types); idx++) { - const struct vfio_iommu_type *t = &iommu_types[idx]; - - ret = ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION, - t->type_id); - if (ret < 0) { - RTE_LOG(ERR, EAL, " could not get IOMMU type, " - "error %i (%s)\n", errno, - strerror(errno)); - close(vfio_container_fd); - return -1; - } else if (ret == 1) { - /* we found a supported extension */ - n_extensions++; - } - RTE_LOG(DEBUG, EAL, " IOMMU type %d (%s) is %s\n", - t->type_id, t->name, - ret ? "supported" : "not supported"); - } - - /* if we didn't find any supported IOMMU types, fail */ - if (!n_extensions) { - close(vfio_container_fd); - return -1; - } - - return 0; -} - /* set up interrupt support (but not enable interrupts) */ static int pci_vfio_setup_interrupts(struct rte_pci_device *dev, int vfio_dev_fd) @@ -360,7 +326,7 @@ pci_vfio_get_container_fd(void) return -1; } - ret = pci_vfio_has_supported_extensions(vfio_container_fd); + ret = vfio_has_supported_extensions(vfio_container_fd); if (ret) { RTE_LOG(ERR, EAL, " no supported IOMMU " "extensions found!\n"); diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c index ff85283..6a95d2a 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c @@ -62,6 +62,39 @@ vfio_set_iommu_type(int vfio_container_fd) { } int +vfio_has_supported_extensions(int vfio_container_fd) { + int ret; + unsigned idx, n_extensions = 0; + for (idx = 0; idx < RTE_DIM(iommu_types); idx++) { + const struct vfio_iommu_type *t = &iommu_types[idx]; + + ret = ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION, + t->type_id); + if (ret < 0) { + RTE_LOG(ERR, EAL, " could not get IOMMU type, " + "error %i (%s)\n", errno, + strerror(errno)); + close(vfio_container_fd); + return -1; + } else if (ret == 1) { + /* we found a supported extension */ + n_extensions++; + } + RTE_LOG(DEBUG, EAL, " IOMMU type %d (%s) is %s\n", + t->type_id, t->name, + ret ? "supported" : "not supported"); + } + + /* if we didn't find any supported IOMMU types, fail */ + if (!n_extensions) { + close(vfio_container_fd); + return -1; + } + + return 0; +} + +int vfio_type1_dma_map(int vfio_container_fd) { const struct rte_memseg *ms = rte_eal_get_physmem_layout(); diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h index afbb98a..8cb0d1d 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.h +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h @@ -111,6 +111,10 @@ struct vfio_iommu_type { const struct vfio_iommu_type * vfio_set_iommu_type(int vfio_container_fd); +/* check if we have any supported extensions */ +int +vfio_has_supported_extensions(int vfio_container_fd); + int vfio_type1_dma_map(int); int vfio_noiommu_dma_map(int); -- 2.8.0