[dpdk-dev,v4,3/9] bus: add helper to find bus for a particular device
Checks
Commit Message
From: Jan Blunck <jblunck@infradead.org>
Signed-off-by: Jan Blunck <jblunck@infradead.org>
Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 +
lib/librte_eal/common/eal_common_bus.c | 24 ++++++++++++++++++++++++
lib/librte_eal/common/include/rte_bus.h | 5 +++++
lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 +
4 files changed, 31 insertions(+)
Comments
21/06/2017 01:29, Gaetan Rivet:
> +static int
> +cmp_rte_device(const struct rte_device *dev, const void *_dev2)
Better to rename dev into dev1.
> +{
> + const struct rte_device *dev2 = _dev2;
> +
> + return !(dev == dev2);
simpler: return dev1 != dev2
[...]
> +static int
> +bus_find_device(const struct rte_bus *bus, const void *_dev)
> +{
> + struct rte_device *dev;
> +
> + if (!bus->find_device)
It is preferred to check pointers against NULL.
> + return -1;
> + dev = bus->find_device(cmp_rte_device, _dev);
> + return !dev;
Here also: return dev == NULL:
> +}
> +
> +struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev)
> +{
> + return rte_bus_find(bus_find_device, (const void *)dev, NULL);
> +}
Nice
@@ -163,6 +163,7 @@ DPDK_17.05 {
global:
rte_bus_find;
+ rte_bus_find_by_device;
rte_cpu_is_supported;
rte_log_dump;
rte_log_register;
@@ -165,3 +165,27 @@ rte_bus_find(rte_bus_cmp_t cmp,
}
return bus;
}
+
+static int
+cmp_rte_device(const struct rte_device *dev, const void *_dev2)
+{
+ const struct rte_device *dev2 = _dev2;
+
+ return !(dev == dev2);
+}
+
+static int
+bus_find_device(const struct rte_bus *bus, const void *_dev)
+{
+ struct rte_device *dev;
+
+ if (!bus->find_device)
+ return -1;
+ dev = bus->find_device(cmp_rte_device, _dev);
+ return !dev;
+}
+
+struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev)
+{
+ return rte_bus_find(bus_find_device, (const void *)dev, NULL);
+}
@@ -189,6 +189,11 @@ struct rte_bus *rte_bus_find(rte_bus_cmp_t cmp,
const struct rte_bus *start);
/**
+ * 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.
*/
@@ -167,6 +167,7 @@ DPDK_17.05 {
global:
rte_bus_find;
+ rte_bus_find_by_device;
rte_cpu_is_supported;
rte_intr_free_epoll_fd;
rte_log_dump;