From: Gaetan Rivet Date: Fri, 7 Jul 2017 00:03:11 +0000 (+0200) Subject: bus: add helper to find a bus from a device name X-Git-Tag: spdx-start~2565 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=cfdbd65300db216a34e98d0f40cc210b2d0a4450;hp=595876836932ce45c3a47cb17892f4851eb5f7b8;p=dpdk.git 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 Acked-by: Bruce Richardson --- diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index 96eb4fd52a..1d3635c50c 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); +} diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index 6cacce0732..0836339375 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_ */