-}
-
-static clib_error_t *
-scan_vfio_fd (void *arg, u8 * path_name, u8 * file_name)
-{
- const char fn[] = "/dev/vfio/vfio";
- char buff[sizeof (fn)] = { 0 };
-
- if (readlink ((char *) path_name, buff, sizeof (fn)) + 1 != sizeof (fn))
- return 0;
-
- if (strncmp (fn, buff, sizeof (fn)))
- return 0;
-
- vfio_container_fd = atoi ((char *) file_name);
- return 0;
-}
-
-static clib_error_t *
-unix_physmem_region_iommu_register (vlib_physmem_region_t * pr)
-{
- struct vfio_iommu_type1_dma_map dma_map = { 0 };
- int i, fd;
-
- if (vfio_container_fd == -1)
- foreach_directory_file ("/proc/self/fd", scan_vfio_fd, 0, 0);
-
- fd = vfio_container_fd;
-
- if (fd < 0)
- return 0;
-
- if (ioctl (fd, VFIO_GET_API_VERSION) != VFIO_API_VERSION)
- return 0;
-
- if (ioctl (fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU) == 0)
- return 0;
-
- dma_map.argsz = sizeof (struct vfio_iommu_type1_dma_map);
- dma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE;
-
- vec_foreach_index (i, pr->page_table)
- {
- dma_map.vaddr = pointer_to_uword (pr->mem) + (i << pr->log2_page_size);
- dma_map.size = 1 << pr->log2_page_size;
- dma_map.iova = pr->page_table[i];
- if (ioctl (fd, VFIO_IOMMU_MAP_DMA, &dma_map) != 0)
- return clib_error_return_unix (0, "ioctl (VFIO_IOMMU_MAP_DMA)");
- }
- return 0;