From patchwork Thu Oct 26 10:05:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 30946 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 46F2B1BAB6; Thu, 26 Oct 2017 12:06:51 +0200 (CEST) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by dpdk.org (Postfix) with ESMTP id 36EE91B78E for ; Thu, 26 Oct 2017 12:06:37 +0200 (CEST) Received: by mail-wm0-f66.google.com with SMTP id m72so18850940wmc.0 for ; Thu, 26 Oct 2017 03:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=wKiOISqAWU4Kn4HwZwZIA0UeaSAV0+Pa7e7J9vQURws=; b=SFEp143Er6moh/6DWkHN0P9wuW24j/dDImCkKKBLCgkqmFKPXNn/poOOYYquNV1wcn 8P4aVQ9NnxwdeOZOvy/IoBxDZsvvB+pRmRrpShu1THkoUJan0FXUdaT45DIp9m7nN3WO oELLjIpe7AvN7mMDHdgRWv2l+ZCN82G/HoRp7jpjEyUhTtyeReoW9gE40zioEEpkAAyZ vRN6MtKOVfwjBYiMj+SJCkrx9nYWV0yFnEZaxlbW33QlDZCVHPuGJvcGFf5PpHXb8d+z KLVyrVzAZrFkSiodqnO+O6t7JbfjDKVUW7hh9xd+0t9xrzGTxyy/jACTdNDE+ef2ukoW RRnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=wKiOISqAWU4Kn4HwZwZIA0UeaSAV0+Pa7e7J9vQURws=; b=GSwdJzFUVi2aY06SisdQp50qLkWrt/PGVhNCsL5JBHgJF+8Nov89eFPOD7IgFtXZbX w3Hn2GWbQFKqmfWc3lzagxICRblch9gCMxldBqCzNCHC3ZlAJuPui+tAOfp3+Nj+TclN AsYBhE8uTZvmW7rC1AnehtIW0XrDWjyp/x3umyWzQmWThW5vKRvTtVMIIeBWOG9nbLgc WoCdJZ7vI+S7sFCOfRrqHcDmFOJaNS6fDQfVL3RLv6/47vYhOj5bi3Id1Ej/0aALTVnX gG/bU9bfBC8Mg4EG0+iX5ZJ44pdR/cDr/VMOYIhiPN14TEjT2u8P4nT9aJemS0Xos5j/ PVGQ== X-Gm-Message-State: AMCzsaUQYPI0OQb4d3jrdLXALDw1NL8DVq9Nt+Sg5pvo1yvXRtg0VzXC D9Mqa4frcw9GVcoHQ0e25ZQ8xjQk X-Google-Smtp-Source: ABhQp+RnlPUkl8HvOupiXCtAo4mIPep0eyCn6RaNllJKsR8ta2a1ICRZmbSKrzv2kvNBAzAZo+nm+g== X-Received: by 10.80.142.17 with SMTP id 17mr8861892edw.115.1509012396330; Thu, 26 Oct 2017 03:06:36 -0700 (PDT) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id u12sm3339619edk.45.2017.10.26.03.06.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Oct 2017 03:06:35 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 26 Oct 2017 12:05:52 +0200 Message-Id: <5ebf9444deceddd3901441077d0bfa7daa5d748c.1509012196.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 07/25] eal: expose vfio symbols X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The following symbols are used by vfio implementations within the PCI bus. They need to be publicly available for the PCI bus to be outside the EAL. + vfio_enable; + vfio_is_enabled; + vfio_noiommu_is_enabled; + vfio_release_device; + vfio_setup_device; Signed-off-by: Gaetan Rivet --- drivers/bus/fslmc/fslmc_vfio.h | 2 + lib/librte_eal/bsdapp/eal/eal.c | 41 ++++++++ lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/include/rte_vfio.h | 139 +++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal.c | 1 + lib/librte_eal/linuxapp/eal/eal_interrupts.c | 1 + lib/librte_eal/linuxapp/eal/eal_pci.c | 2 +- lib/librte_eal/linuxapp/eal/eal_pci_init.h | 4 +- lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 1 + lib/librte_eal/linuxapp/eal/eal_vfio.c | 1 + lib/librte_eal/linuxapp/eal/eal_vfio.h | 26 ----- lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c | 2 + lib/librte_eal/rte_eal_version.map | 5 + 13 files changed, 197 insertions(+), 30 deletions(-) create mode 100644 lib/librte_eal/common/include/rte_vfio.h diff --git a/drivers/bus/fslmc/fslmc_vfio.h b/drivers/bus/fslmc/fslmc_vfio.h index 5470a41..b442dc0 100644 --- a/drivers/bus/fslmc/fslmc_vfio.h +++ b/drivers/bus/fslmc/fslmc_vfio.h @@ -34,6 +34,8 @@ #ifndef _FSLMC_VFIO_H_ #define _FSLMC_VFIO_H_ +#include + #include "eal_vfio.h" #define DPAA2_MC_DPNI_DEVID 7 diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index d54a280..af15812 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -739,3 +739,44 @@ rte_eal_vfio_intr_mode(void) { return RTE_INTR_MODE_NONE; } + +/* dummy forward declaration. */ +struct vfio_device_info; + +/* dummy prototypes. */ +int vfio_setup_device(const char *sysfs_base, const char *dev_addr, + int *vfio_dev_fd, struct vfio_device_info *device_info); +int vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd); +int vfio_enable(const char *modname); +int vfio_is_enabled(const char *modname); +int vfio_noiommu_is_enabled(void); + +int vfio_setup_device(__rte_unused const char *sysfs_base, + __rte_unused const char *dev_addr, + __rte_unused int *vfio_dev_fd, + __rte_unused struct vfio_device_info *device_info) +{ + return -1; +} + +int vfio_release_device(__rte_unused const char *sysfs_base, + __rte_unused const char *dev_addr, + __rte_unused int fd) +{ + return -1; +} + +int vfio_enable(__rte_unused const char *modname) +{ + return -1; +} + +int vfio_is_enabled(__rte_unused const char *modname) +{ + return 0; +} + +int vfio_noiommu_is_enabled(void) +{ + return 0; +} diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile index 6f5b3f3..64ff811 100644 --- a/lib/librte_eal/common/Makefile +++ b/lib/librte_eal/common/Makefile @@ -43,7 +43,7 @@ INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h rte_vdev.h INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h INC += rte_malloc.h rte_keepalive.h rte_time.h INC += rte_service.h rte_service_component.h -INC += rte_bitmap.h +INC += rte_bitmap.h rte_vfio.h GENERIC_INC := rte_atomic.h rte_byteorder.h rte_cycles.h rte_prefetch.h GENERIC_INC += rte_spinlock.h rte_memcpy.h rte_cpuflags.h rte_rwlock.h diff --git a/lib/librte_eal/common/include/rte_vfio.h b/lib/librte_eal/common/include/rte_vfio.h new file mode 100644 index 0000000..a9b7057 --- /dev/null +++ b/lib/librte_eal/common/include/rte_vfio.h @@ -0,0 +1,139 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 6WIND S.A. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of 6WIND nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _RTE_VFIO_H_ +#define _RTE_VFIO_H_ + +#include + +#define VFIO_DIR "/dev/vfio" +#define VFIO_CONTAINER_PATH "/dev/vfio/vfio" +#define VFIO_GROUP_FMT "/dev/vfio/%u" +#define VFIO_NOIOMMU_GROUP_FMT "/dev/vfio/noiommu-%u" +#define VFIO_GET_REGION_ADDR(x) ((uint64_t) x << 40ULL) +#define VFIO_GET_REGION_IDX(x) (x >> 40) +#define VFIO_NOIOMMU_MODE \ + "/sys/module/vfio/parameters/enable_unsafe_noiommu_mode" + +/** + * Setup vfio_cfg for the device identified by its address. + * It discovers the configured I/O MMU groups or sets a new one for the device. + * If a new groups is assigned, the DMA mapping is performed. + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param sysfs_base + * sysfs path prefix. + * + * @param dev_addr + * device location. + * + * @param vfio_dev_fd + * VFIO fd. + * + * @param device_info + * Device information. + * + * @return + * 0 on success. + * <0 on failure. + * >1 if the device cannot be managed this way. + */ +int vfio_setup_device(const char *sysfs_base, const char *dev_addr, + int *vfio_dev_fd, struct vfio_device_info *device_info); + +/** + * Release a device mapped to a VFIO-managed I/O MMU group. + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param sysfs_base + * sysfs path prefix. + * + * @param dev_addr + * device location. + * + * @param fd + * VFIO fd. + * + * @return + * 0 on success. + * <0 on failure. + */ +int vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd); + +/** + * Enable a VFIO-related kmod. + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param modname + * kernel module name. + * + * @return + * 0 on success. + * <0 on failure. + */ +int vfio_enable(const char *modname); + +/** + * Check whether a VFIO-related kmod is enabled. + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param modname + * kernel module name. + * + * @return + * !0 if true. + * 0 otherwise. + */ +int vfio_is_enabled(const char *modname); + +/** + * Whether VFIO NOIOMMU mode is enabled. + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @return + * !0 if true. + * 0 otherwise. + */ +int vfio_noiommu_is_enabled(void); + +#endif /* _RTE_VFIO_H_ */ diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index 18a07b0..bee3bbe 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -77,6 +77,7 @@ #include #include #include +#include #include "eal_private.h" #include "eal_thread.h" diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c index 3e9ac41..6df63d4 100644 --- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c +++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c @@ -65,6 +65,7 @@ #include #include #include +#include #include "eal_private.h" #include "eal_vfio.h" diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index b4dbf95..8682ee6 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -41,11 +41,11 @@ #include #include #include +#include #include "eal_filesystem.h" #include "eal_private.h" #include "eal_pci_init.h" -#include "eal_vfio.h" /** * @file diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h index ae2980d..a20783d 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h +++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h @@ -34,7 +34,7 @@ #ifndef EAL_PCI_INIT_H_ #define EAL_PCI_INIT_H_ -#include "eal_vfio.h" +#include /** IO resource type: */ #define IORESOURCE_IO 0x00000100 @@ -72,7 +72,7 @@ void pci_uio_ioport_write(struct rte_pci_ioport *p, const void *data, size_t len, off_t offset); int pci_uio_ioport_unmap(struct rte_pci_ioport *p); -#ifdef VFIO_PRESENT +#ifdef RTE_EAL_VFIO /* access config space */ int pci_vfio_read_config(const struct rte_intr_handle *intr_handle, diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c index d407c87..8fa101b 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c @@ -44,6 +44,7 @@ #include #include #include +#include #include "eal_filesystem.h" #include "eal_pci_init.h" diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c index 3f56967..5bbcdf9 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c @@ -39,6 +39,7 @@ #include #include #include +#include #include "eal_filesystem.h" #include "eal_vfio.h" diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h index 4bab363..8eb12db 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.h +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h @@ -144,15 +144,6 @@ struct vfio_config { struct vfio_group vfio_groups[VFIO_MAX_GROUPS]; }; -#define VFIO_DIR "/dev/vfio" -#define VFIO_CONTAINER_PATH "/dev/vfio/vfio" -#define VFIO_GROUP_FMT "/dev/vfio/%u" -#define VFIO_NOIOMMU_GROUP_FMT "/dev/vfio/noiommu-%u" -#define VFIO_GET_REGION_ADDR(x) ((uint64_t) x << 40ULL) -#define VFIO_GET_REGION_IDX(x) (x >> 40) -#define VFIO_NOIOMMU_MODE \ - "/sys/module/vfio/parameters/enable_unsafe_noiommu_mode" - /* DMA mapping function prototype. * Takes VFIO container fd as a parameter. * Returns 0 on success, -1 on error. @@ -192,27 +183,10 @@ vfio_get_group_fd(int iommu_group_no); int clear_group(int vfio_group_fd); -/** - * Setup vfio_cfg for the device identified by its address. It discovers - * the configured I/O MMU groups or sets a new one for the device. If a new - * groups is assigned, the DMA mapping is performed. - * Returns 0 on success, a negative value on failure and a positive value in - * case the given device cannot be managed this way. - */ -int vfio_setup_device(const char *sysfs_base, const char *dev_addr, - int *vfio_dev_fd, struct vfio_device_info *device_info); - -int vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd); - -int vfio_enable(const char *modname); -int vfio_is_enabled(const char *modname); - int pci_vfio_is_enabled(void); int vfio_mp_sync_setup(void); -int vfio_noiommu_is_enabled(void); - #define SOCKET_REQ_CONTAINER 0x100 #define SOCKET_REQ_GROUP 0x200 #define SOCKET_CLR_GROUP 0x300 diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c index 537beeb..05d63e8 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c @@ -52,9 +52,11 @@ #include #include #include +#include #include "eal_filesystem.h" #include "eal_pci_init.h" +#include "eal_vfio.h" #include "eal_thread.h" /** diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 9f06d23..262211a 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -252,5 +252,10 @@ DPDK_17.11 { rte_memcpy_ptr; rte_pci_get_iommu_class; rte_pci_match; + vfio_enable; + vfio_is_enabled; + vfio_noiommu_is_enabled; + vfio_release_device; + vfio_setup_device; } DPDK_17.08;