bus/pci: implement method to find device
authorJan Blunck <jblunck@infradead.org>
Fri, 30 Jun 2017 18:19:33 +0000 (20:19 +0200)
committerThomas Monjalon <thomas@monjalon.net>
Mon, 3 Jul 2017 23:08:21 +0000 (01:08 +0200)
Signed-off-by: Jan Blunck <jblunck@infradead.org>
lib/librte_eal/common/eal_common_pci.c

index 479c62d..e449758 100644 (file)
@@ -485,10 +485,31 @@ rte_pci_remove_device(struct rte_pci_device *pci_dev)
        TAILQ_REMOVE(&rte_pci_bus.device_list, pci_dev, next);
 }
 
+static struct rte_device *
+pci_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
+               const void *data)
+{
+       struct rte_pci_device *dev;
+       bool start_found = !start;
+
+       FOREACH_DEVICE_ON_PCIBUS(dev) {
+               if (!start_found) {
+                       if (&dev->device == start)
+                               start_found = 1;
+                       continue;
+               }
+               if (cmp(&dev->device, data) == 0)
+                       return &dev->device;
+       }
+
+       return NULL;
+}
+
 struct rte_pci_bus rte_pci_bus = {
        .bus = {
                .scan = rte_pci_scan,
                .probe = rte_pci_probe,
+               .find_device = pci_find_device,
        },
        .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
        .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),