@@ -26,6 +26,7 @@ enum rte_pci_kernel_driver {
RTE_PCI_KDRV_NIC_UIO, /* nic_uio for FreeBSD */
RTE_PCI_KDRV_NONE, /* no attached driver */
RTE_PCI_KDRV_NET_UIO, /* NetUIO for Windows */
+ RTE_PCI_KDRV_VFIO_IOMMUFD, /* VFIO IOMMUFD for Linux */
};
/**
@@ -65,6 +65,12 @@ rte_pci_map_device(struct rte_pci_device *dev)
#ifdef VFIO_PRESENT
if (pci_vfio_is_enabled())
ret = pci_vfio_map_resource(dev);
+#endif
+ break;
+ case RTE_PCI_KDRV_VFIO_IOMMUFD:
+#ifdef VFIO_IOMMUFD_PRESENT
+ if (pci_iommufd_is_enabled())
+ ret = pci_vfio_map_resource(dev);
#endif
break;
case RTE_PCI_KDRV_IGB_UIO:
@@ -94,6 +100,12 @@ rte_pci_unmap_device(struct rte_pci_device *dev)
#ifdef VFIO_PRESENT
if (pci_vfio_is_enabled())
pci_vfio_unmap_resource(dev);
+#endif
+ break;
+ case RTE_PCI_KDRV_VFIO_IOMMUFD:
+#ifdef VFIO_IOMMUFD_PRESENT
+ if (pci_iommufd_is_enabled())
+ pci_vfio_unmap_resource(dev);
#endif
break;
case RTE_PCI_KDRV_IGB_UIO:
@@ -645,6 +657,7 @@ int rte_pci_read_config(const struct rte_pci_device *device,
return pci_uio_read_config(intr_handle, buf, len, offset);
#ifdef VFIO_PRESENT
case RTE_PCI_KDRV_VFIO:
+ case RTE_PCI_KDRV_VFIO_IOMMUFD:
return pci_vfio_read_config(device, buf, len, offset);
#endif
default:
@@ -669,6 +682,7 @@ int rte_pci_write_config(const struct rte_pci_device *device,
return pci_uio_write_config(intr_handle, buf, len, offset);
#ifdef VFIO_PRESENT
case RTE_PCI_KDRV_VFIO:
+ case RTE_PCI_KDRV_VFIO_IOMMUFD:
return pci_vfio_write_config(device, buf, len, offset);
#endif
default:
@@ -79,4 +79,8 @@ int pci_vfio_is_enabled(void);
#endif
+#ifdef VFIO_IOMMUFD_PRESENT
+int pci_iommufd_is_enabled(void);
+#endif
+
#endif /* EAL_PCI_INIT_H_ */
@@ -21,6 +21,9 @@
#include <bus_driver.h>
#include <rte_spinlock.h>
#include <rte_tailq.h>
+#ifdef VFIO_IOMMUFD_PRESENT
+#include <rte_iommufd.h>
+#endif
#include "eal_filesystem.h"
@@ -783,10 +786,21 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)
snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT,
loc->domain, loc->bus, loc->devid, loc->function);
- ret = rte_vfio_setup_device(rte_pci_get_sysfs_path(), pci_addr,
- &vfio_dev_fd, &device_info);
- if (ret)
- return ret;
+#ifdef VFIO_IOMMUFD_PRESENT
+ if (dev->kdrv == RTE_PCI_KDRV_VFIO_IOMMUFD) {
+ ret = rte_vfio_iommufd_setup_device(rte_pci_get_sysfs_path(), pci_addr,
+ &vfio_dev_fd, &device_info);
+ if (ret)
+ return ret;
+ } else {
+#endif
+ ret = rte_vfio_setup_device(rte_pci_get_sysfs_path(), pci_addr,
+ &vfio_dev_fd, &device_info);
+ if (ret)
+ return ret;
+#ifdef VFIO_IOMMUFD_PRESENT
+ }
+#endif
if (rte_intr_dev_fd_set(dev->intr_handle, vfio_dev_fd))
goto err_vfio_dev_fd;
@@ -1148,12 +1162,24 @@ pci_vfio_unmap_resource_primary(struct rte_pci_device *dev)
return -1;
}
- ret = rte_vfio_release_device(rte_pci_get_sysfs_path(), pci_addr,
- vfio_dev_fd);
- if (ret < 0) {
- RTE_LOG(ERR, EAL, "Cannot release VFIO device\n");
- return ret;
+#ifdef VFIO_IOMMUFD_PRESENT
+ if (dev->kdrv == RTE_PCI_KDRV_VFIO_IOMMUFD) {
+ ret = rte_vfio_iommufd_release_device(pci_addr, vfio_dev_fd);
+ if (ret < 0) {
+ RTE_LOG(ERR, EAL, "Cannot release VFIO device\n");
+ return ret;
+ }
+ } else {
+#endif
+ ret = rte_vfio_release_device(rte_pci_get_sysfs_path(), pci_addr,
+ vfio_dev_fd);
+ if (ret < 0) {
+ RTE_LOG(ERR, EAL, "Cannot release VFIO device\n");
+ return ret;
+ }
+#ifdef VFIO_IOMMUFD_PRESENT
}
+#endif
vfio_res_list =
RTE_TAILQ_CAST(rte_vfio_tailq.head, mapped_pci_res_list);
@@ -1327,3 +1353,11 @@ pci_vfio_is_enabled(void)
return rte_vfio_is_enabled("vfio_pci");
}
#endif
+
+#ifdef VFIO_IOMMUFD_PRESENT
+int
+pci_iommufd_is_enabled(void)
+{
+ return rte_iommufd_is_enabled("iommufd");
+}
+#endif