1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 6WIND S.A.
9 * determine if VFIO is present on the system
11 #if !defined(VFIO_PRESENT) && defined(RTE_EAL_VFIO)
12 #include <linux/version.h>
13 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)
15 #endif /* kernel version >= 3.6.0 */
16 #endif /* RTE_EAL_VFIO */
20 #include <linux/vfio.h>
22 #define VFIO_DIR "/dev/vfio"
23 #define VFIO_CONTAINER_PATH "/dev/vfio/vfio"
24 #define VFIO_GROUP_FMT "/dev/vfio/%u"
25 #define VFIO_NOIOMMU_GROUP_FMT "/dev/vfio/noiommu-%u"
26 #define VFIO_GET_REGION_ADDR(x) ((uint64_t) x << 40ULL)
27 #define VFIO_GET_REGION_IDX(x) (x >> 40)
28 #define VFIO_NOIOMMU_MODE \
29 "/sys/module/vfio/parameters/enable_unsafe_noiommu_mode"
32 * Setup vfio_cfg for the device identified by its address.
33 * It discovers the configured I/O MMU groups or sets a new one for the device.
34 * If a new groups is assigned, the DMA mapping is performed.
36 * This function is only relevant to linux and will return
54 * >1 if the device cannot be managed this way.
56 int rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
57 int *vfio_dev_fd, struct vfio_device_info *device_info);
60 * Release a device mapped to a VFIO-managed I/O MMU group.
62 * This function is only relevant to linux and will return
78 int rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd);
81 * Enable a VFIO-related kmod.
83 * This function is only relevant to linux and will return
93 int rte_vfio_enable(const char *modname);
96 * Check whether a VFIO-related kmod is enabled.
98 * This function is only relevant to linux and will return
102 * kernel module name.
108 int rte_vfio_is_enabled(const char *modname);
111 * Whether VFIO NOIOMMU mode is enabled.
113 * This function is only relevant to linux and will return
120 int rte_vfio_noiommu_is_enabled(void);
122 /* remove group fd from internal VFIO group fd array */
124 rte_vfio_clear_group(int vfio_group_fd);
126 #endif /* VFIO_PRESENT */
128 #endif /* _RTE_VFIO_H_ */