rte_vfio.h(3)
πΈ rte_vfio.h β the VFIO bestie handbook πΈ
okay so bestie, welcome to rte_vfio.h, straight outta section 3 of the Library Functions Manual π. This is DPDK's VFIO utility header and it's giving big kernel-adjacent energy. Buckle up, we're going through every single function, no skipping, no skimming, periodt. π
β¨
π NAME
rte_vfio.h
β¨ SYNOPSIS β¨
First, the little pre-party β the stuff you gotta pull in:
#include <stdbool.h>
#include <stdint.h>
#include <rte_compat.h>
π¦ Functions
Here's the whole squad of function signatures, exactly as they come:
int rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_dev_fd, struct vfio_device_info *device_info)
int rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd)
int rte_vfio_enable(const char *modname)
int rte_vfio_is_enabled(const char *modname)
int rte_vfio_noiommu_is_enabled(void)
int rte_vfio_clear_group(int vfio_group_fd)
int rte_vfio_get_group_num(const char *sysfs_base, const char *dev_addr, int *iommu_group_num)
__rte_experimental int rte_vfio_get_device_info(const char *sysfs_base, const char *dev_addr, int *vfio_dev_fd, struct vfio_device_info *device_info)
int rte_vfio_get_container_fd(void)
int rte_vfio_get_group_fd(int iommu_group_num)
int rte_vfio_container_create(void)
int rte_vfio_container_destroy(int container_fd)
int rte_vfio_container_group_bind(int container_fd, int iommu_group_num)
int rte_vfio_container_group_unbind(int container_fd, int iommu_group_num)
int rte_vfio_container_dma_map(int container_fd, uint64_t vaddr, uint64_t iova, uint64_t len)
int rte_vfio_container_dma_unmap(int container_fd, uint64_t vaddr, uint64_t iova, uint64_t len)
π Detailed Description π
RTE VFIO. This library hands you a whole lil bundle of VFIO-related utility functions so you can do the device-passthrough thing. π«Ά
Definition in file rte_vfio.h.
π§ Function Documentation π§
rte_vfio_setup_device
int rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
int *vfio_dev_fd, struct vfio_device_info *device_info)
Sets up vfio_cfg for the device that you identify by its address. It goes and discovers the I/O MMU groups that are already configured, or it sets up a brand new one for this device. And if a new group gets assigned? Then the DMA mapping happens too. Iconic multitasking. β¨
heads up bestie: this function is only relevant to linux and will return an error on BSD. no BSD crumbs for this one. π
Parameters
sysfs_baseβ sysfs path prefix.dev_addrβ device location.vfio_dev_fdβ VFIO fd.device_infoβ Device information.
Returns
0on success.<0on failure.>1if the device cannot be managed this way.
rte_vfio_release_device
int rte_vfio_release_device(const char *sysfs_base, const char *dev_addr,
int fd)
Releases a device that's mapped to a VFIO-managed I/O MMU group. Say bye π
same deal: only relevant to linux, returns an error on BSD.
Parameters
sysfs_baseβ sysfs path prefix.dev_addrβ device location.fdβ VFIO fd.
Returns
0on success.<0on failure.
rte_vfio_enable
int rte_vfio_enable(const char *modname)
Turns on a VFIO-related kmod. basically the "go go go" button for your kernel module. π₯
you guessed it: only relevant to linux, returns an error on BSD.
Parameters
modnameβ kernel module name.
Returns
0on success.<0on failure.
rte_vfio_is_enabled
int rte_vfio_is_enabled(const char *modname)
Checks whether a VFIO-related kmod is enabled. vibe check on your kernel module, fr fr. π΅οΈββοΈ
note the capital L: only relevant to Linux.
Parameters
modnameβ kernel module name.
Returns
1if true.0otherwise.
rte_vfio_noiommu_is_enabled
int rte_vfio_noiommu_is_enabled(void)
Tells you whether VFIO <cyanish>NOIOMMU mode is enabled. (are we doing the no-iommu thing or not, bestie?)
Linux only for this one.
Returns
1if true.0if false.<0for errors.
rte_vfio_clear_group
int rte_vfio_clear_group(int vfio_group_fd)
Removes a group fd from the internal VFIO group fd array/ β yep, that trailing slash is how it's written and I am not touching it. π
linux only, and it will return an error on BSD.
Parameters
vfio_group_fdβ VFIO Group FD.
Returns
0on success.<0on failure.
rte_vfio_get_group_num
int rte_vfio_get_group_num(const char *sysfs_base, const char *dev_addr,
int *iommu_group_num)
Parses the IOMMU group number for a device. π’
linux only, error on BSD.
Parameters
sysfs_baseβ sysfs path prefix.dev_addrβ device location.iommu_group_numβ iommu group number.
Returns
>0on success.0for non-existent group or VFIO.<0for errors.
rte_vfio_get_device_info
__rte_experimental int rte_vfio_get_device_info(const char *sysfs_base,
const char *dev_addr, int *vfio_dev_fd,
struct vfio_device_info *device_info)
Gets device information. π (yes, it's marked __rte_experimental β experimental things can wiggle around, so don't get too attached.)
Linux only, and returns an error on BSD.
Parameters
sysfs_baseβ sysfs path prefix.dev_addrβ device location.vfio_dev_fdβ VFIO fd.device_infoβ Device information.
Returns
0on success.<0on failure.
rte_vfio_get_container_fd
int rte_vfio_get_container_fd(void)
Gets the default VFIO container fd. the OG container, if you will. π§Ί
linux only, error on BSD.
Returns
0β default container fd.< 0if VFIO is not enabled or not supported.
rte_vfio_get_group_fd
int rte_vfio_get_group_fd(int iommu_group_num)
Opens a VFIO group fd, or grabs an already-existing one. πͺ
linux only, error on BSD.
Parameters
iommu_group_numβ iommu group number.
Returns
0β group fd.< 0for errors.
rte_vfio_container_create
int rte_vfio_container_create(void)
Creates a shiny new container for device binding. β¨π§Ί
Note (read this twice, bestie): - Any newly allocated DPDK memory will not be mapped into these containers by default, user needs to manage DMA mappings for any container created by this API. - When creating containers using this API, the container will only be available in the process that has created it. Sharing containers and devices between multiple processes is not supported. π no group-chat sharing here.
Returns
- the container fd if successful.
<0if failed.
rte_vfio_container_destroy
int rte_vfio_container_destroy(int container_fd)
Destroys the container, and unbinds all vfio groups within it. bye forever π«‘
Parameters
container_fdβ the container fd to destroy.
Returns
0if successful.<0if failed.
rte_vfio_container_group_bind
int rte_vfio_container_group_bind(int container_fd, int iommu_group_num)
Binds an IOMMU group to a container. it's giving arranged marriage but for fds. π
Parameters
container_fdβ the container's fd.iommu_group_numβ the iommu group number to bind to container.
Returns
- group fd if successful.
<0if failed.
rte_vfio_container_group_unbind
int rte_vfio_container_group_unbind(int container_fd, int iommu_group_num)
Unbinds an IOMMU group from a container. π
Parameters
container_fdβ the container fd of container.iommu_group_numβ the iommu group number to delete from container.
Returns
0if successful.<0if failed.
rte_vfio_container_dma_map
int rte_vfio_container_dma_map(int container_fd, uint64_t vaddr,
uint64_t iova, uint64_t len)
Performs DMA mapping for devices in a container. πΊοΈ
Parameters
container_fdβ the specified container fd. UseRTE_VFIO_DEFAULT_CONTAINER_FDto use the default container.vaddrβ Starting virtual address of memory to be mapped.iovaβ Starting IOVA address of memory to be mapped.lenβ Length of memory segment being mapped.
Returns
0if successful.<0if failed.
rte_vfio_container_dma_unmap
int rte_vfio_container_dma_unmap(int container_fd, uint64_t vaddr,
uint64_t iova, uint64_t len)
Performs DMA unmapping for devices in a container. π§Ή (reverse of the map, duh)
Parameters
container_fdβ the specified container fd. UseRTE_VFIO_DEFAULT_CONTAINER_FDto use the default container.vaddrβ Starting virtual address of memory to be unmapped.iovaβ Starting IOVA address of memory to be unmapped.lenβ Length of memory segment being unmapped.
Returns
0if successful.<0if failed.
π Author
Generated automatically by Doxygen for DPDK from the source code.
and that's the whole page bestie, you ate it π β¨
this was DPDK, Version 25.11.3, from the rte_vfio.h(3) page π β go forth and map your DMA, no cap π«ΆπΈ
π¦ where this page comes from
- ubuntu resolute: dpdk-doc 25.11.3-0ubuntu0.26.04.1 Β· BSD-3-Clause
- ubuntu stonking: dpdk-doc 25.11.3-1 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms