|
FD.io VPP
v21.06-3-gbb25fbf28
Vector Packet Processing
|
Go to the documentation of this file.
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;
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static u64 vlib_physmem_get_page_index(vlib_main_t *vm, void *mem)
__clib_export u8 * clib_sysfs_link_to_name(char *link)
static uword pointer_to_uword(const void *p)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
static clib_error_t * open_vfio_iommu_group(int group, int is_noiommu)
#define clib_error_return(e, args...)
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
clib_pmalloc_main_t * pmalloc_main
linux_vfio_main_t vfio_main
vnet_hw_if_output_node_runtime_t * r
#define hash_create(elts, value_bytes)
uword * iommu_pool_index_by_group
#define vlib_log_err(...)
#define hash_set(h, key, value)
clib_error_t * vfio_map_physmem_page(vlib_main_t *vm, void *addr)
__clib_export clib_error_t * clib_sysfs_read(char *file_name, char *fmt,...)
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
vlib_physmem_main_t physmem_main
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
#define vlib_log_debug(...)
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.
u8 * format_vfio_region_info(u8 *s, va_list *args)
vlib_log_class_t log_default
#define vec_free(V)
Free vector's memory (no header).
format_function_t format_vlib_pci_addr
description fragment has unexpected format
clib_bitmap_t * physmem_pages_mapped
clib_mem_page_sz_t def_log2_page_sz
#define clib_error_return_unix(e, args...)
clib_error_t * linux_vfio_init(vlib_main_t *vm)
static linux_pci_vfio_iommu_group_t * get_vfio_iommu_group(int group)
#define VFIO_NOIOMMU_IOMMU
#define clib_error_free(e)
clib_error_t * linux_vfio_group_get_device_fd(vlib_pci_addr_t *addr, int *fdp, int *is_noiommu)
linux_pci_vfio_iommu_group_t * iommu_groups