[PATCH v6 5/6] bus: add helper to find a bus from a device name
From: Gaetan Rivet <hidden>
Date: 2017-07-04 00:58:52
Subsystem:
library code, the rest · Maintainers:
Andrew Morton, Linus Torvalds
Find which bus should be able to parse this device name into an internal device representation. Signed-off-by: Gaetan Rivet <redacted> --- lib/librte_eal/common/eal_common_bus.c | 15 +++++++++++++++ lib/librte_eal/common/eal_private.h | 12 ++++++++++++ 2 files changed, 27 insertions(+)
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 87b0c6e..b143f21 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c@@ -204,3 +204,18 @@ 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); +} + +/* find a bus capable of parsing a device description */ +struct rte_bus * +rte_bus_find_by_device_name(const char *str) +{ + return rte_bus_find(NULL, bus_can_parse, str); +}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 6cacce0..0836339 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h@@ -338,4 +338,16 @@ int rte_eal_hugepage_attach(void); */ bool rte_eal_using_phys_addrs(void); +/** + * Find a bus capable of identifying a device. + * + * @param str + * A device identifier (PCI address, virtual PMD name, ...). + * + * @return + * A valid bus handle if found. + * NULL if no bus is able to parse this device. + */ +struct rte_bus *rte_bus_find_by_device_name(const char *str); + #endif /* _EAL_PRIVATE_H_ */
--
2.1.4