From mboxrd@z Thu Jan 1 00:00:00 1970 From: Shreyansh Jain Subject: Re: [PATCH v2 01/11] bus: add bus iterator to find a particular bus Date: Wed, 7 Jun 2017 12:36:53 +0530 Message-ID: <33c95f6a-82b4-6557-7011-f210f34cbc88@nxp.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Cc: , Jan Blunck To: Gaetan Rivet Return-path: Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0083.outbound.protection.outlook.com [104.47.34.83]) by dpdk.org (Postfix) with ESMTP id D7B2B2BBB for ; Wed, 7 Jun 2017 08:58:45 +0200 (CEST) In-Reply-To: Content-Language: en-US List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hello Gaetan, On Wednesday 31 May 2017 06:47 PM, Gaetan Rivet wrote: > From: Jan Blunck > > Signed-off-by: Jan Blunck > Signed-off-by: Gaetan Rivet > --- > lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + > lib/librte_eal/common/eal_common_bus.c | 13 ++++++++++ > lib/librte_eal/common/include/rte_bus.h | 32 +++++++++++++++++++++++++ > lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + > 4 files changed, 47 insertions(+) > > diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map > index 2e48a73..ed09ab2 100644 > --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map > +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map > @@ -162,6 +162,7 @@ DPDK_17.02 { > DPDK_17.05 { > global: > > + rte_bus_find; > rte_cpu_is_supported; > rte_log_dump; > rte_log_register; > diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c > index 8f9baf8..68f70d0 100644 > --- a/lib/librte_eal/common/eal_common_bus.c > +++ b/lib/librte_eal/common/eal_common_bus.c > @@ -145,3 +145,16 @@ rte_bus_dump(FILE *f) > } > } > } > + > +struct rte_bus * > +rte_bus_find(rte_bus_match_t match, const void *data) > +{ > + struct rte_bus *bus = NULL; > + > + TAILQ_FOREACH(bus, &rte_bus_list, next) { > + if (match(bus, data)) > + break; > + } > + > + return bus; > +} > diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h > index 7c36969..006feca 100644 > --- a/lib/librte_eal/common/include/rte_bus.h > +++ b/lib/librte_eal/common/include/rte_bus.h > @@ -141,6 +141,38 @@ int rte_bus_probe(void); > void rte_bus_dump(FILE *f); > > /** > + * Bus match function. > + * > + * @param bus > + * bus under test. > + * > + * @param data > + * data matched > + * > + * @return > + * 0 if the bus does not match. > + * !0 if the bus matches. One of the common match function implementation could be simply to match a string. strcmp itself returns '0' for a successful match. On the same lines, should this function return value be reversed? - 0 if match !0 if not a match - That way, people would not have to change either the way strcmp works, for example, or the way various APIs expect '0' as success. same for rte_device_match_t as well. (in next patch) > + */ > +typedef int (*rte_bus_match_t)(const struct rte_bus *bus, const void *data); > + > +/** > + * Bus iterator to find a particular bus. > + * > + * If the callback returns non-zero this function will stop iterating over > + * any more buses. > + * > + * @param match > + * Callback function to check bus > + * > + * @param data > + * Data to pass to match callback > + * > + * @return > + * A pointer to a rte_bus structure or NULL in case no bus matches > + */ > +struct rte_bus *rte_bus_find(rte_bus_match_t match, 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 670bab3..6efa517 100644 > --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map > +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map > @@ -166,6 +166,7 @@ DPDK_17.02 { > DPDK_17.05 { > global: > > + rte_bus_find; > rte_cpu_is_supported; > rte_intr_free_epoll_fd; > rte_log_dump; >