17 #include <sys/types.h> 21 #include <sys/ioctl.h> 31 #ifndef VFIO_NOIOMMU_IOMMU 32 #define VFIO_NOIOMMU_IOMMU 8 42 struct vfio_iommu_type1_dma_map dm = { 0 };
45 dm.argsz =
sizeof (
struct vfio_iommu_type1_dma_map);
46 dm.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE;
51 vec_foreach_index (i, pr->page_table)
54 dm.vaddr = pointer_to_uword (pr->mem) + (i << pr->log2_page_size);
55 dm.size = 1 << pr->log2_page_size;
57 if ((rv = ioctl (fd, VFIO_IOMMU_MAP_DMA, &dm)))
91 struct vfio_group_status group_status;
101 s =
format (s,
"/dev/vfio/%s%u%c", is_noiommu ?
"noiommu-" :
"", group, 0);
102 fd = open ((
char *) s, O_RDWR);
106 group_status.argsz =
sizeof (group_status);
107 if (ioctl (fd, VFIO_GROUP_GET_STATUS, &group_status) < 0)
114 if (!(group_status.flags & VFIO_GROUP_FLAGS_VIABLE))
117 "devices in this group bound to vfio-pci)",
122 if (ioctl (fd, VFIO_GROUP_SET_CONTAINER, &lvm->
container_fd) < 0)
172 iommu_group = atoi ((
char *) tmpstr);
184 format (s,
"/sys/bus/pci/devices/%U/iommu_group/name",
189 if (strncmp ((
char *) tmpstr,
"vfio-noiommu", 12) == 0)
202 if ((fd = ioctl (g->
fd, VFIO_GROUP_GET_DEVICE_FD, (
char *) s)) < 0)
223 fd = open (
"/dev/vfio/vfio", O_RDWR);
228 if (ioctl (fd, VFIO_GET_API_VERSION) != VFIO_API_VERSION)
235 if (ioctl (fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU) == 1)
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)
static int map_regions(vlib_main_t *vm, int fd)
#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)
uword * iommu_pool_index_by_group
#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