17 #include <sys/types.h> 21 #include <sys/ioctl.h> 31 #ifndef VFIO_NOIOMMU_IOMMU 32 #define VFIO_NOIOMMU_IOMMU 8 43 struct vfio_iommu_type1_dma_map dm = { 0 };
46 dm.argsz =
sizeof (
struct vfio_iommu_type1_dma_map);
47 dm.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE;
52 vec_foreach_index (i, pr->page_table)
55 dm.vaddr = pointer_to_uword (pr->mem) + (i << pr->log2_page_size);
56 dm.size = 1 << pr->log2_page_size;
58 vlib_log_debug (lvm->log_default,
"map DMA va:0x%lx iova:%lx " 59 "size:0x%lx", dm.vaddr, dm.iova, dm.size);
61 if ((rv = ioctl (fd, VFIO_IOMMU_MAP_DMA, &dm)) &&
64 vlib_log_err (lvm->log_default,
"map DMA va:0x%lx iova:%lx " 65 "size:0x%lx failed, error %s (errno %d)",
66 dm.vaddr, dm.iova, dm.size, strerror (errno),
102 struct vfio_group_status group_status;
112 s =
format (s,
"/dev/vfio/%s%u%c", is_noiommu ?
"noiommu-" :
"", group, 0);
113 fd = open ((
char *) s, O_RDWR);
117 group_status.argsz =
sizeof (group_status);
118 if (ioctl (fd, VFIO_GROUP_GET_STATUS, &group_status) < 0)
125 if (!(group_status.flags & VFIO_GROUP_FLAGS_VIABLE))
128 "devices in this group bound to vfio-pci)",
133 if (ioctl (fd, VFIO_GROUP_SET_CONTAINER, &lvm->
container_fd) < 0)
183 iommu_group = atoi ((
char *) tmpstr);
195 format (s,
"/sys/bus/pci/devices/%U/iommu_group/name",
200 if (strncmp ((
char *) tmpstr,
"vfio-noiommu", 12) == 0)
213 if ((fd = ioctl (g->
fd, VFIO_GROUP_GET_DEVICE_FD, (
char *) s)) < 0)
236 fd = open (
"/dev/vfio/vfio", O_RDWR);
241 if (ioctl (fd, VFIO_GET_API_VERSION) != VFIO_API_VERSION)
248 if (ioctl (fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU) == 1)
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
format_function_t format_vlib_pci_addr
#define hash_set(h, key, value)
void linux_vfio_dma_map_regions(vlib_main_t *vm)
clib_error_t * linux_vfio_group_get_device_fd(vlib_pci_addr_t *addr, int *fdp)
static linux_pci_vfio_iommu_group_t * get_vfio_iommu_group(int group)
vlib_log_class_t log_default
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
linux_pci_vfio_iommu_group_t * iommu_groups
#define LINUX_VFIO_F_HAVE_IOMMU
#define LINUX_VFIO_F_HAVE_NOIOMMU
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
#define clib_error_return(e, args...)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
#define clib_error_return_unix(e, args...)
#define VFIO_NOIOMMU_IOMMU
clib_error_t * linux_vfio_init(vlib_main_t *vm)
clib_error_t * clib_sysfs_read(char *file_name, char *fmt,...)
#define vec_free(V)
Free vector's memory (no header).
#define hash_create(elts, value_bytes)
static int vfio_map_regions(vlib_main_t *vm, int fd)
uword * iommu_pool_index_by_group
#define vlib_log_info(...)
#define clib_error_free(e)
vlib_physmem_main_t physmem_main
static clib_error_t * open_vfio_iommu_group(int group, int is_noiommu)
vlib_physmem_region_t * regions
u8 * clib_sysfs_link_to_name(char *link)
linux_vfio_main_t vfio_main