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)
253 struct vfio_region_info *r = va_arg (*args,
struct vfio_region_info *);
255 s =
format (s,
"region_info index:%u size:0x%lx offset:0x%lx flags:",
256 r->index, r->size, r->offset);
258 if (r->flags & VFIO_REGION_INFO_FLAG_READ)
261 if (r->flags & VFIO_REGION_INFO_FLAG_WRITE)
264 if (r->flags & VFIO_REGION_INFO_FLAG_MMAP)
267 #ifdef VFIO_REGION_INFO_FLAG_CAPS 268 if (r->flags & VFIO_REGION_INFO_FLAG_CAPS)
272 s =
format (s,
" (0x%x)", r->flags);
274 #ifdef VFIO_REGION_INFO_FLAG_CAPS 277 if ((r->flags & VFIO_REGION_INFO_FLAG_CAPS) == 0)
280 s =
format (s,
"\n caps:");
281 cap_offset = r->cap_offset;
285 struct vfio_info_cap_header *cap = (
void *) r + cap_offset;
286 #ifdef VFIO_REGION_INFO_CAP_SPARSE_MMAP 287 if (cap->id == VFIO_REGION_INFO_CAP_SPARSE_MMAP)
288 s =
format (s,
" sparse-mmap");
290 #ifdef VFIO_REGION_INFO_CAP_TYPE 291 if (cap->id == VFIO_REGION_INFO_CAP_TYPE)
294 #ifdef VFIO_REGION_INFO_CAP_MSIX_MAPPABLE 295 if (cap->id == VFIO_REGION_INFO_CAP_MSIX_MAPPABLE)
296 s =
format (s,
" msix-mappable");
298 cap_offset = cap->next;
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
u8 * format_vfio_region_info(u8 *s, va_list *args)
#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