From: Jan Blunck Date: Fri, 30 Jun 2017 18:19:30 +0000 (+0200) Subject: bus: add iterator to find a bus X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=87bfa873afebbf73355310e25c2d19e9825c1e24;hp=fea892e35f211d1f7aa4991dd415a9b5f40dad76;p=dpdk.git bus: add iterator to find a bus This helper allows to iterate over all registered buses and find one matching data used as parameter. 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 2e48a7366b..edf9d7d0f2 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -193,3 +193,10 @@ DPDK_17.05 { vfio_get_group_no; } DPDK_17.02; + +DPDK_17.08 { + global: + + rte_bus_find; + +} DPDK_17.05; diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index 8f9baf8b8a..3094daa5a3 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -145,3 +145,22 @@ rte_bus_dump(FILE *f) } } } + +struct rte_bus * +rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp, + const void *data) +{ + struct rte_bus *bus = NULL; + bool start_found = !start; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + if (!start_found) { + if (bus == start) + start_found = 1; + continue; + } + if (cmp(bus, data) == 0) + break; + } + return bus; +} diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index 5f47b829b9..c52b65b1f1 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -140,6 +140,48 @@ int rte_bus_probe(void); */ void rte_bus_dump(FILE *f); +/** + * Bus comparison function. + * + * @param bus + * Bus under test. + * + * @param data + * Data to compare against. + * + * @return + * 0 if the bus matches the data. + * !0 if the bus does not match. + * <0 if ordering is possible and the bus is lower than the data. + * >0 if ordering is possible and the bus is greater than the data. + */ +typedef int (*rte_bus_cmp_t)(const struct rte_bus *bus, const void *data); + +/** + * Bus iterator to find a particular bus. + * + * This function compares each registered bus to find one that matches + * the data passed as parameter. + * + * If the comparison function returns zero this function will stop iterating + * over any more buses. To continue a search the bus of a previous search can + * be passed via the start parameter. + * + * @param start + * Starting point for the iteration. + * + * @param cmp + * Comparison function. + * + * @param data + * Data to pass to comparison function. + * + * @return + * A pointer to a rte_bus structure or NULL in case no bus matches + */ +struct rte_bus *rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp, + const void *data); + /** * 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 670bab3a5e..944416eda2 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -198,3 +198,10 @@ DPDK_17.05 { vfio_get_group_no; } DPDK_17.02; + +DPDK_17.08 { + global: + + rte_bus_find; + +} DPDK_17.05;