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 };
54 "mapped", addr, page_index);
58 dm.argsz =
sizeof (
struct vfio_iommu_type1_dma_map);
59 dm.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE;
60 dm.vaddr = physmem_start + (page_index << log2_page_size);
61 dm.size = 1ULL << log2_page_size;
64 "size:0x%lx", page_index, dm.vaddr, dm.iova, dm.size);
66 if (ioctl (lvm->
container_fd, VFIO_IOMMU_MAP_DMA, &dm) == -1)
69 "size:0x%lx failed, error %s (errno %d)", page_index,
70 dm.vaddr, dm.iova, dm.size, strerror (errno), errno);
96 struct vfio_group_status group_status;
102 if ((fd = open (
"/dev/vfio/vfio", O_RDWR)) == -1)
105 if (ioctl (fd, VFIO_GET_API_VERSION) != VFIO_API_VERSION)
121 s =
format (s,
"/dev/vfio/%s%u%c", is_noiommu ?
"noiommu-" :
"", group, 0);
122 fd = open ((
char *) s, O_RDWR);
126 group_status.argsz =
sizeof (group_status);
127 if (ioctl (fd, VFIO_GROUP_GET_STATUS, &group_status) < 0)
134 if (!(group_status.flags & VFIO_GROUP_FLAGS_VIABLE))
137 "devices in this group bound to vfio-pci)",
142 if (ioctl (fd, VFIO_GROUP_SET_CONTAINER, &lvm->
container_fd) < 0)
194 iommu_group = atoi ((
char *) tmpstr);
205 s =
format (s,
"/sys/bus/pci/devices/%U/iommu_group/name%c",
210 if (strncmp ((
char *) tmpstr,
"vfio-noiommu", 12) == 0)
224 if ((fd = ioctl (g->
fd, VFIO_GROUP_GET_DEVICE_FD, (
char *) s)) < 0)
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
#define hash_set(h, key, value)
vlib_physmem_main_t physmem_main
static linux_pci_vfio_iommu_group_t * get_vfio_iommu_group(int group)
static uword * clib_bitmap_set(uword *ai, uword i, uword value)
Sets the ith bit of a bitmap to new_value Removes trailing zeros from the bitmap. ...
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.
clib_pmalloc_main_t * pmalloc_main
linux_pci_vfio_iommu_group_t * iommu_groups
#define clib_error_return(e, args...)
clib_error_t * linux_vfio_group_get_device_fd(vlib_pci_addr_t *addr, int *fdp, int *is_noiommu)
#define vlib_log_debug(...)
#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).
static u64 vlib_physmem_get_page_index(vlib_main_t *vm, void *mem)
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
#define hash_create(elts, value_bytes)
clib_bitmap_t * physmem_pages_mapped
clib_error_t * vfio_map_physmem_page(vlib_main_t *vm, void *addr)
uword * iommu_pool_index_by_group
static uword pointer_to_uword(const void *p)
#define clib_error_free(e)
#define vlib_log_err(...)
static clib_error_t * open_vfio_iommu_group(int group, int is_noiommu)
format_function_t format_vlib_pci_addr
u8 * clib_sysfs_link_to_name(char *link)
linux_vfio_main_t vfio_main