vfio: expose functions

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 <gaetan.rivet@6wind.com>
This commit is contained in:
Gaetan Rivet 2017-10-26 12:05:52 +02:00 committed by Thomas Monjalon
parent 821f86e0f4
commit 279b581c89
13 changed files with 197 additions and 30 deletions

View File

@ -34,6 +34,8 @@
#ifndef _FSLMC_VFIO_H_
#define _FSLMC_VFIO_H_
#include <rte_vfio.h>
#include "eal_vfio.h"
#define DPAA2_MC_DPNI_DEVID 7

View File

@ -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;
}

View File

@ -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

View File

@ -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 <linux/vfio.h>
#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_ */

View File

@ -77,6 +77,7 @@
#include <rte_version.h>
#include <rte_atomic.h>
#include <malloc_heap.h>
#include <rte_vfio.h>
#include "eal_private.h"
#include "eal_thread.h"

View File

@ -65,6 +65,7 @@
#include <rte_errno.h>
#include <rte_spinlock.h>
#include <rte_pause.h>
#include <rte_vfio.h>
#include "eal_private.h"
#include "eal_vfio.h"

View File

@ -41,11 +41,11 @@
#include <rte_malloc.h>
#include <rte_devargs.h>
#include <rte_memcpy.h>
#include <rte_vfio.h>
#include "eal_filesystem.h"
#include "eal_private.h"
#include "eal_pci_init.h"
#include "eal_vfio.h"
/**
* @file

View File

@ -34,7 +34,7 @@
#ifndef EAL_PCI_INIT_H_
#define EAL_PCI_INIT_H_
#include "eal_vfio.h"
#include <rte_vfio.h>
/** 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,

View File

@ -44,6 +44,7 @@
#include <rte_pci.h>
#include <rte_eal_memconfig.h>
#include <rte_malloc.h>
#include <rte_vfio.h>
#include "eal_filesystem.h"
#include "eal_pci_init.h"

View File

@ -39,6 +39,7 @@
#include <rte_log.h>
#include <rte_memory.h>
#include <rte_eal_memconfig.h>
#include <rte_vfio.h>
#include "eal_filesystem.h"
#include "eal_vfio.h"

View File

@ -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

View File

@ -52,9 +52,11 @@
#include <rte_pci.h>
#include <rte_eal_memconfig.h>
#include <rte_malloc.h>
#include <rte_vfio.h>
#include "eal_filesystem.h"
#include "eal_pci_init.h"
#include "eal_vfio.h"
#include "eal_thread.h"
/**

View File

@ -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;