DPDK  18.08.1
rte_vfio.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 6WIND S.A.
3  */
4 
5 #ifndef _RTE_VFIO_H_
6 #define _RTE_VFIO_H_
7 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /*
18  * determine if VFIO is present on the system
19  */
20 #if !defined(VFIO_PRESENT) && defined(RTE_EAL_VFIO)
21 #include <linux/version.h>
22 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)
23 #define VFIO_PRESENT
24 #endif /* kernel version >= 3.6.0 */
25 #endif /* RTE_EAL_VFIO */
26 
27 #ifdef VFIO_PRESENT
28 
29 #include <linux/vfio.h>
30 
31 #define VFIO_DIR "/dev/vfio"
32 #define VFIO_CONTAINER_PATH "/dev/vfio/vfio"
33 #define VFIO_GROUP_FMT "/dev/vfio/%u"
34 #define VFIO_NOIOMMU_GROUP_FMT "/dev/vfio/noiommu-%u"
35 #define VFIO_GET_REGION_ADDR(x) ((uint64_t) x << 40ULL)
36 #define VFIO_GET_REGION_IDX(x) (x >> 40)
37 #define VFIO_NOIOMMU_MODE \
38  "/sys/module/vfio/parameters/enable_unsafe_noiommu_mode"
39 
40 /* NOIOMMU is defined from kernel version 4.5 onwards */
41 #ifdef VFIO_NOIOMMU_IOMMU
42 #define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU
43 #else
44 #define RTE_VFIO_NOIOMMU 8
45 #endif
46 
47 #else /* not VFIO_PRESENT */
48 
49 /* we don't need an actual definition, only pointer is used */
50 struct vfio_device_info;
51 
52 #endif /* VFIO_PRESENT */
53 
79 int rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
80  int *vfio_dev_fd, struct vfio_device_info *device_info);
81 
101 int rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd);
102 
116 int rte_vfio_enable(const char *modname);
117 
131 int rte_vfio_is_enabled(const char *modname);
132 
144 
158 int
159 rte_vfio_clear_group(int vfio_group_fd);
160 
182 int
183 rte_vfio_dma_map(uint64_t vaddr, uint64_t iova, uint64_t len);
184 
185 
203 int
204 rte_vfio_dma_unmap(uint64_t vaddr, uint64_t iova, uint64_t len);
225 int
226 rte_vfio_get_group_num(const char *sysfs_base,
227  const char *dev_addr, int *iommu_group_num);
228 
239 int
241 
255 int
256 rte_vfio_get_group_fd(int iommu_group_num);
257 
269 int
271 
282 int
283 rte_vfio_container_destroy(int container_fd);
284 
298 int
299 rte_vfio_container_group_bind(int container_fd, int iommu_group_num);
300 
314 int
315 rte_vfio_container_group_unbind(int container_fd, int iommu_group_num);
316 
336 int
337 rte_vfio_container_dma_map(int container_fd, uint64_t vaddr,
338  uint64_t iova, uint64_t len);
339 
359 int
360 rte_vfio_container_dma_unmap(int container_fd, uint64_t vaddr,
361  uint64_t iova, uint64_t len);
362 
363 #ifdef __cplusplus
364 }
365 #endif
366 
367 #endif /* _RTE_VFIO_H_ */