DPDK 22.11.5
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
14extern "C" {
15#endif
16
17#include <stdbool.h>
18#include <stdint.h>
19
20/*
21 * determine if VFIO is present on the system
22 */
23#if !defined(VFIO_PRESENT) && defined(RTE_EAL_VFIO)
24#include <linux/version.h>
25#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)
26#define VFIO_PRESENT
27#endif /* kernel version >= 3.6.0 */
28#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)
29#define HAVE_VFIO_DEV_REQ_INTERFACE
30#endif /* kernel version >= 4.0.0 */
31#endif /* RTE_EAL_VFIO */
32
33#ifdef VFIO_PRESENT
34
35#include <linux/vfio.h>
36
37#define VFIO_DIR "/dev/vfio"
38#define VFIO_CONTAINER_PATH "/dev/vfio/vfio"
39#define VFIO_GROUP_FMT "/dev/vfio/%u"
40#define VFIO_NOIOMMU_GROUP_FMT "/dev/vfio/noiommu-%u"
41#define VFIO_GET_REGION_ADDR(x) ((uint64_t) x << 40ULL)
42#define VFIO_GET_REGION_IDX(x) (x >> 40)
43#define VFIO_NOIOMMU_MODE \
44 "/sys/module/vfio/parameters/enable_unsafe_noiommu_mode"
45
46/* NOIOMMU is defined from kernel version 4.5 onwards */
47#ifdef VFIO_NOIOMMU_IOMMU
48#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU
49#else
50#define RTE_VFIO_NOIOMMU 8
51#endif
52
53/*
54 * capabilities are only supported on kernel 4.6+. there were also some API
55 * changes as well, so add a macro to get cap offset.
56 */
57#ifdef VFIO_REGION_INFO_FLAG_CAPS
58#define RTE_VFIO_INFO_FLAG_CAPS VFIO_REGION_INFO_FLAG_CAPS
59#define VFIO_CAP_OFFSET(x) (x->cap_offset)
60#else
61#define RTE_VFIO_INFO_FLAG_CAPS (1 << 3)
62#define VFIO_CAP_OFFSET(x) (x->resv)
63struct vfio_info_cap_header {
64 uint16_t id;
65 uint16_t version;
66 uint32_t next;
67};
68#endif
69
70/* kernels 4.16+ can map BAR containing MSI-X table */
71#ifdef VFIO_REGION_INFO_CAP_MSIX_MAPPABLE
72#define RTE_VFIO_CAP_MSIX_MAPPABLE VFIO_REGION_INFO_CAP_MSIX_MAPPABLE
73#else
74#define RTE_VFIO_CAP_MSIX_MAPPABLE 3
75#endif
76
77#else /* not VFIO_PRESENT */
78
79/* we don't need an actual definition, only pointer is used */
80struct vfio_device_info;
81
82#endif /* VFIO_PRESENT */
83
84#define RTE_VFIO_DEFAULT_CONTAINER_FD (-1)
85
111int rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
112 int *vfio_dev_fd, struct vfio_device_info *device_info);
113
133int rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd);
134
148int rte_vfio_enable(const char *modname);
149
162int rte_vfio_is_enabled(const char *modname);
163
175
189int
190rte_vfio_clear_group(int vfio_group_fd);
191
212int
213rte_vfio_get_group_num(const char *sysfs_base,
214 const char *dev_addr, int *iommu_group_num);
215
226int
228
242int
243rte_vfio_get_group_fd(int iommu_group_num);
244
260int
262
273int
275
289int
290rte_vfio_container_group_bind(int container_fd, int iommu_group_num);
291
305int
306rte_vfio_container_group_unbind(int container_fd, int iommu_group_num);
307
328int
329rte_vfio_container_dma_map(int container_fd, uint64_t vaddr,
330 uint64_t iova, uint64_t len);
331
352int
353rte_vfio_container_dma_unmap(int container_fd, uint64_t vaddr,
354 uint64_t iova, uint64_t len);
355
356#ifdef __cplusplus
357}
358#endif
359
360#endif /* _RTE_VFIO_H_ */
int rte_vfio_clear_group(int vfio_group_fd)
int rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_dev_fd, struct vfio_device_info *device_info)
int rte_vfio_get_group_num(const char *sysfs_base, const char *dev_addr, int *iommu_group_num)
int rte_vfio_is_enabled(const char *modname)
int rte_vfio_container_group_bind(int container_fd, int iommu_group_num)
int rte_vfio_container_group_unbind(int container_fd, int iommu_group_num)
int rte_vfio_get_container_fd(void)
int rte_vfio_enable(const char *modname)
int rte_vfio_container_destroy(int container_fd)
int rte_vfio_container_dma_map(int container_fd, uint64_t vaddr, uint64_t iova, uint64_t len)
int rte_vfio_noiommu_is_enabled(void)
int rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd)
int rte_vfio_container_dma_unmap(int container_fd, uint64_t vaddr, uint64_t iova, uint64_t len)
int rte_vfio_container_create(void)
int rte_vfio_get_group_fd(int iommu_group_num)