From: Jan Blunck Date: Fri, 30 Jun 2017 18:19:35 +0000 (+0200) Subject: bus: add helper to find which bus holds a device X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=95d57b2b037ae505cf1a600adb08b731475a0b90;p=dpdk.git bus: add helper to find which bus holds a device Signed-off-by: Jan Blunck Signed-off-by: Gaetan Rivet --- diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index edf9d7d0f2..458e3a6f5d 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -198,5 +198,6 @@ DPDK_17.08 { global: rte_bus_find; + rte_bus_find_by_device; } DPDK_17.05; diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index e04ab4ff3d..b8a9e3072f 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -165,3 +165,26 @@ rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp, } return bus; } + +static int +cmp_rte_device(const struct rte_device *dev1, const void *_dev2) +{ + const struct rte_device *dev2 = _dev2; + + return dev1 != dev2; +} + +static int +bus_find_device(const struct rte_bus *bus, const void *_dev) +{ + struct rte_device *dev; + + dev = bus->find_device(NULL, cmp_rte_device, _dev); + return dev == NULL; +} + +struct rte_bus * +rte_bus_find_by_device(const struct rte_device *dev) +{ + return rte_bus_find(NULL, bus_find_device, (const void *)dev); +} diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index 052ac8d4cb..f8b321559e 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -209,6 +209,11 @@ typedef int (*rte_bus_cmp_t)(const struct rte_bus *bus, const void *data); struct rte_bus *rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp, const void *data); +/** + * Find the registered bus for a particular device. + */ +struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev); + /** * Helper for Bus registration. * The constructor has higher priority than PMD constructors. diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index 944416eda2..3c193e4927 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -203,5 +203,6 @@ DPDK_17.08 { global: rte_bus_find; + rte_bus_find_by_device; } DPDK_17.05;