1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
8 #include <rte_common.h>
11 * determine if VFIO is present on the system
13 #if !defined(VFIO_PRESENT) && defined(RTE_EAL_VFIO)
14 #include <linux/version.h>
15 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)
18 #pragma message("VFIO configured but not supported by this kernel, disabling.")
19 #endif /* kernel version >= 3.6.0 */
20 #endif /* RTE_EAL_VFIO */
25 #include <linux/vfio.h>
27 #define RTE_VFIO_TYPE1 VFIO_TYPE1_IOMMU
29 #ifndef VFIO_SPAPR_TCE_v2_IOMMU
30 #define RTE_VFIO_SPAPR 7
31 #define VFIO_IOMMU_SPAPR_REGISTER_MEMORY _IO(VFIO_TYPE, VFIO_BASE + 17)
32 #define VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY _IO(VFIO_TYPE, VFIO_BASE + 18)
33 #define VFIO_IOMMU_SPAPR_TCE_CREATE _IO(VFIO_TYPE, VFIO_BASE + 19)
34 #define VFIO_IOMMU_SPAPR_TCE_REMOVE _IO(VFIO_TYPE, VFIO_BASE + 20)
36 struct vfio_iommu_spapr_register_memory {
43 struct vfio_iommu_spapr_tce_create {
56 struct vfio_iommu_spapr_tce_remove {
63 struct vfio_iommu_spapr_tce_ddw_info {
65 uint32_t max_dynamic_windows_supported;
69 /* SPAPR_v2 is not present, but SPAPR might be */
70 #ifndef VFIO_SPAPR_TCE_IOMMU
71 #define VFIO_IOMMU_SPAPR_TCE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
73 struct vfio_iommu_spapr_tce_info {
76 uint32_t dma32_window_start;
77 uint32_t dma32_window_size;
78 struct vfio_iommu_spapr_tce_ddw_info ddw;
80 #endif /* VFIO_SPAPR_TCE_IOMMU */
82 #else /* VFIO_SPAPR_TCE_v2_IOMMU */
83 #define RTE_VFIO_SPAPR VFIO_SPAPR_TCE_v2_IOMMU
86 #define VFIO_MAX_GROUPS RTE_MAX_VFIO_GROUPS
87 #define VFIO_MAX_CONTAINERS RTE_MAX_VFIO_CONTAINERS
90 * we don't need to store device fd's anywhere since they can be obtained from
91 * the group fd via an ioctl() call.
99 /* DMA mapping function prototype.
100 * Takes VFIO container fd as a parameter.
101 * Returns 0 on success, -1 on error.
103 typedef int (*vfio_dma_func_t)(int);
105 /* Custom memory region DMA mapping function prototype.
106 * Takes VFIO container fd, virtual address, phisical address, length and
107 * operation type (0 to unmap 1 for map) as a parameters.
108 * Returns 0 on success, -1 on error.
110 typedef int (*vfio_dma_user_func_t)(int fd, uint64_t vaddr, uint64_t iova,
111 uint64_t len, int do_map);
113 struct vfio_iommu_type {
116 vfio_dma_user_func_t dma_user_map_func;
117 vfio_dma_func_t dma_map_func;
120 /* get the vfio container that devices are bound to by default */
121 int vfio_get_default_container_fd(void);
123 /* pick IOMMU type. returns a pointer to vfio_iommu_type or NULL for error */
124 const struct vfio_iommu_type *
125 vfio_set_iommu_type(int vfio_container_fd);
128 vfio_get_iommu_type(void);
130 /* check if we have any supported extensions */
132 vfio_has_supported_extensions(int vfio_container_fd);
134 int vfio_mp_sync_setup(void);
136 #define EAL_VFIO_MP "eal_vfio_mp_sync"
138 #define SOCKET_REQ_CONTAINER 0x100
139 #define SOCKET_REQ_GROUP 0x200
140 #define SOCKET_REQ_DEFAULT_CONTAINER 0x400
141 #define SOCKET_REQ_IOMMU_TYPE 0x800
142 #define SOCKET_OK 0x0
143 #define SOCKET_NO_FD 0x1
144 #define SOCKET_ERR 0xFF
146 struct vfio_mp_param {
156 #endif /* VFIO_PRESENT */
158 #endif /* EAL_VFIO_H_ */