summaryrefslogtreecommitdiff
path: root/lib/librte_eal/common/eal_common_bus.c
diff options
context:
space:
mode:
authorGaetan Rivet <gaetan.rivet@6wind.com>2017-07-07 02:03:11 +0200
committerThomas Monjalon <thomas@monjalon.net>2017-07-08 22:29:29 +0200
commitcfdbd65300db216a34e98d0f40cc210b2d0a4450 (patch)
treeb4a414332b8db5040b4e53e04b9eec6c2ea701f8 /lib/librte_eal/common/eal_common_bus.c
parent595876836932ce45c3a47cb17892f4851eb5f7b8 (diff)
downloaddpdk-cfdbd65300db216a34e98d0f40cc210b2d0a4450.zip
dpdk-cfdbd65300db216a34e98d0f40cc210b2d0a4450.tar.gz
dpdk-cfdbd65300db216a34e98d0f40cc210b2d0a4450.tar.xz
bus: add helper to find a bus from a device name
Find which bus should be able to parse this device name into an internal device representation. Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Diffstat (limited to 'lib/librte_eal/common/eal_common_bus.c')
-rw-r--r--lib/librte_eal/common/eal_common_bus.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 96eb4fd..1d3635c 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -202,3 +202,24 @@ rte_bus_find_by_name(const char *busname)
{
return rte_bus_find(NULL, cmp_bus_name, (const void *)busname);
}
+
+static int
+bus_can_parse(const struct rte_bus *bus, const void *_name)
+{
+ const char *name = _name;
+
+ return !(bus->parse && bus->parse(name, NULL) == 0);
+}
+
+struct rte_bus *
+rte_bus_find_by_device_name(const char *str)
+{
+ char name[RTE_DEV_NAME_MAX_LEN];
+ char *c;
+
+ snprintf(name, sizeof(name), "%s", str);
+ c = strchr(name, ',');
+ if (c != NULL)
+ c[0] = '\0';
+ return rte_bus_find(NULL, bus_can_parse, name);
+}