+static bool
+pci_ignore_device(const struct rte_pci_device *dev)
+{
+ struct rte_devargs *devargs = dev->device.devargs;
+
+ switch (rte_pci_bus.bus.conf.scan_mode) {
+ case RTE_BUS_SCAN_WHITELIST:
+ if (devargs && devargs->policy == RTE_DEV_WHITELISTED)
+ return false;
+ break;
+ case RTE_BUS_SCAN_UNDEFINED:
+ case RTE_BUS_SCAN_BLACKLIST:
+ if (devargs == NULL ||
+ devargs->policy != RTE_DEV_BLACKLISTED)
+ return false;
+ break;
+ }
+ return true;
+}
+
+enum rte_iova_mode
+rte_pci_get_iommu_class(void)
+{
+ enum rte_iova_mode iova_mode = RTE_IOVA_DC;
+ const struct rte_pci_device *dev;
+ const struct rte_pci_driver *drv;
+ bool devices_want_va = false;
+ bool devices_want_pa = false;
+
+ FOREACH_DEVICE_ON_PCIBUS(dev) {
+ if (pci_ignore_device(dev))
+ continue;
+ if (dev->kdrv == RTE_KDRV_UNKNOWN ||
+ dev->kdrv == RTE_KDRV_NONE)
+ continue;
+ FOREACH_DRIVER_ON_PCIBUS(drv) {
+ enum rte_iova_mode dev_iova_mode;
+
+ if (!rte_pci_match(drv, dev))
+ continue;
+
+ dev_iova_mode = pci_device_iova_mode(drv, dev);
+ RTE_LOG(DEBUG, EAL, "PCI driver %s for device "
+ PCI_PRI_FMT " wants IOVA as '%s'\n",
+ drv->driver.name,
+ dev->addr.domain, dev->addr.bus,
+ dev->addr.devid, dev->addr.function,
+ dev_iova_mode == RTE_IOVA_DC ? "DC" :
+ (dev_iova_mode == RTE_IOVA_PA ? "PA" : "VA"));
+ if (dev_iova_mode == RTE_IOVA_PA)
+ devices_want_pa = true;
+ else if (dev_iova_mode == RTE_IOVA_VA)
+ devices_want_va = true;
+ }
+ }
+ if (devices_want_pa) {
+ iova_mode = RTE_IOVA_PA;
+ if (devices_want_va)
+ RTE_LOG(WARNING, EAL, "Some devices want 'VA' but forcing 'PA' because other devices want it\n");
+ } else if (devices_want_va) {
+ iova_mode = RTE_IOVA_VA;
+ }
+ return iova_mode;
+}
+