1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
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)
16 #pragma message("VFIO configured but not supported by this kernel, disabling.")
17 #endif /* kernel version >= 3.6.0 */
18 #endif /* RTE_EAL_VFIO */
23 #include <linux/vfio.h>
25 #define RTE_VFIO_TYPE1 VFIO_TYPE1_IOMMU
27 #ifndef VFIO_SPAPR_TCE_v2_IOMMU
28 #define RTE_VFIO_SPAPR 7
29 #define VFIO_IOMMU_SPAPR_REGISTER_MEMORY _IO(VFIO_TYPE, VFIO_BASE + 17)
30 #define VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY _IO(VFIO_TYPE, VFIO_BASE + 18)
31 #define VFIO_IOMMU_SPAPR_TCE_CREATE _IO(VFIO_TYPE, VFIO_BASE + 19)
32 #define VFIO_IOMMU_SPAPR_TCE_REMOVE _IO(VFIO_TYPE, VFIO_BASE + 20)
34 struct vfio_iommu_spapr_register_memory {
41 struct vfio_iommu_spapr_tce_create {
54 struct vfio_iommu_spapr_tce_remove {
61 struct vfio_iommu_spapr_tce_ddw_info {
63 uint32_t max_dynamic_windows_supported;
67 /* SPAPR_v2 is not present, but SPAPR might be */
68 #ifndef VFIO_SPAPR_TCE_IOMMU
69 #define VFIO_IOMMU_SPAPR_TCE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
71 struct vfio_iommu_spapr_tce_info {
74 uint32_t dma32_window_start;
75 uint32_t dma32_window_size;
76 struct vfio_iommu_spapr_tce_ddw_info ddw;
78 #endif /* VFIO_SPAPR_TCE_IOMMU */
80 #else /* VFIO_SPAPR_TCE_v2_IOMMU */
81 #define RTE_VFIO_SPAPR VFIO_SPAPR_TCE_v2_IOMMU
84 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
85 #define RTE_VFIO_NOIOMMU 8
87 #define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU
90 #define VFIO_MAX_GROUPS RTE_MAX_VFIO_GROUPS
93 * Function prototypes for VFIO multiprocess sync functions
95 int vfio_mp_sync_send_request(int socket, int req);
96 int vfio_mp_sync_receive_request(int socket);
97 int vfio_mp_sync_send_fd(int socket, int fd);
98 int vfio_mp_sync_receive_fd(int socket);
99 int vfio_mp_sync_connect_to_primary(void);
102 * we don't need to store device fd's anywhere since they can be obtained from
103 * the group fd via an ioctl() call.
113 int vfio_container_fd;
114 int vfio_active_groups;
115 const struct vfio_iommu_type *vfio_iommu_type;
116 struct vfio_group vfio_groups[VFIO_MAX_GROUPS];
119 /* DMA mapping function prototype.
120 * Takes VFIO container fd as a parameter.
121 * Returns 0 on success, -1 on error.
123 typedef int (*vfio_dma_func_t)(int);
125 /* Custom memory region DMA mapping function prototype.
126 * Takes VFIO container fd, virtual address, phisical address, length and
127 * operation type (0 to unmap 1 for map) as a parameters.
128 * Returns 0 on success, -1 on error.
130 typedef int (*vfio_dma_user_func_t)(int fd, uint64_t vaddr, uint64_t iova,
131 uint64_t len, int do_map);
133 struct vfio_iommu_type {
136 vfio_dma_user_func_t dma_user_map_func;
137 vfio_dma_func_t dma_map_func;
140 /* pick IOMMU type. returns a pointer to vfio_iommu_type or NULL for error */
141 const struct vfio_iommu_type *
142 vfio_set_iommu_type(int vfio_container_fd);
144 /* check if we have any supported extensions */
146 vfio_has_supported_extensions(int vfio_container_fd);
148 /* open container fd or get an existing one */
150 vfio_get_container_fd(void);
152 /* parse IOMMU group number for a device
153 * returns 1 on success, -1 for errors, 0 for non-existent group
156 vfio_get_group_no(const char *sysfs_base,
157 const char *dev_addr, int *iommu_group_no);
159 /* open group fd or get an existing one */
161 vfio_get_group_fd(int iommu_group_no);
163 int vfio_mp_sync_setup(void);
165 #define SOCKET_REQ_CONTAINER 0x100
166 #define SOCKET_REQ_GROUP 0x200
167 #define SOCKET_CLR_GROUP 0x300
168 #define SOCKET_OK 0x0
169 #define SOCKET_NO_FD 0x1
170 #define SOCKET_ERR 0xFF
172 #endif /* VFIO_PRESENT */
174 #endif /* EAL_VFIO_H_ */