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"
36 * Setup vfio_cfg for the device identified by its address.
37 * It discovers the configured I/O MMU groups or sets a new one for the device.
38 * If a new groups is assigned, the DMA mapping is performed.
40 * This function is only relevant to linux and will return
58 * >1 if the device cannot be managed this way.
60 int rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
61 int *vfio_dev_fd, struct vfio_device_info *device_info);
64 * Release a device mapped to a VFIO-managed I/O MMU group.
66 * This function is only relevant to linux and will return
82 int rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd);
85 * Enable a VFIO-related kmod.
87 * This function is only relevant to linux and will return
97 int rte_vfio_enable(const char *modname);
100 * Check whether a VFIO-related kmod is enabled.
102 * This function is only relevant to linux and will return
106 * kernel module name.
112 int rte_vfio_is_enabled(const char *modname);
115 * Whether VFIO NOIOMMU mode is enabled.
117 * This function is only relevant to linux and will return
124 int rte_vfio_noiommu_is_enabled(void);
126 /* remove group fd from internal VFIO group fd array */
128 rte_vfio_clear_group(int vfio_group_fd);
131 * Map memory region for use with VFIO.
133 * @note requires at least one device to be attached at the time of mapping.
136 * Starting virtual address of memory to be mapped.
139 * Starting IOVA address of memory to be mapped.
142 * Length of memory segment being mapped.
148 int __rte_experimental
149 rte_vfio_dma_map(uint64_t vaddr, uint64_t iova, uint64_t len);
153 * Unmap memory region from VFIO.
156 * Starting virtual address of memory to be unmapped.
159 * Starting IOVA address of memory to be unmapped.
162 * Length of memory segment being unmapped.
168 int __rte_experimental
169 rte_vfio_dma_unmap(uint64_t vaddr, uint64_t iova, uint64_t len);
175 #endif /* VFIO_PRESENT */
177 #endif /* _RTE_VFIO_H_ */