From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by dpdk.org (Postfix) with ESMTP id 3AB6E101B for ; Wed, 7 Jun 2017 18:42:00 +0200 (CEST) Received: by mail-wm0-f65.google.com with SMTP id 70so3400661wme.1 for ; Wed, 07 Jun 2017 09:42:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=jYiH6GzugL6wbHQVXWN/ov/XlbsTM7hABNGtmozGyjs=; b=DJaUQbyVVi5e3g7Kignh08gPHrlDsy85qzLk/XnzxGc1Kdv4asaAVVFv/78gFALOfb cFUiBDFlqH24puFA0TbURsDAQMie6nraeQJLxaIOEpv7P00gOqwQniA7Sm2k3w1szqoL fdQwqhUQKn2nDMqIBxq3tIiuaBZA65d4Voi248EK9WpCKIW7sdCYhescK4q2UixgctsR uQ1s6Pjo76j/CmN7OXTCpKgdP0XlfGtEw41QlU0/WC+z+EAuZAAn96X2dwxIiHrU1xQ+ YUTFxEJP+NNQZt9G9ZdI2gAtQ0TTkP2uCSENefA8L+mmMF2rIEHWQ80JCthz+4ebANSO v2uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=jYiH6GzugL6wbHQVXWN/ov/XlbsTM7hABNGtmozGyjs=; b=Pqxlq4kFp8xeDa4vXOX4GXW8IpvZeP1rZqNXyuwkk5OchC5wD4SiA85p6z3XSmPi7n ENyRdR+uh1Z+6wlSgCm/U41c87ODIsMH7JwsJQzNnd7bHCnOp40QVuoRbCkbjB6QfjG0 VfOAyExZ65jP4Ko9PVw9EUKsBUbK+AjihpQPMTVTM65DNQ8YDUNOosCmT7pPzI+n3OiV Cg9pKFGZkIcIClSU57sXhqikf50HHhCxAHizQqNNIGTsl+vkfR3wthkgEgtZNRuzwGco 8aYU/b4RVqM3uMXhzZ8Os4zX12kvXij3itloh4MjwqH6NZ9PHmHP68p8AfzswN8G/VCD NV8Q== X-Gm-Message-State: AODbwcCQASUuLlWdmuJXpWUK2YdS9S9KfijE7SuL0+PZS6Ju/Cet/+qC QvSHXhEO0/zp5GpUoIBN4vpfKiJtLQj1 X-Received: by 10.28.109.210 with SMTP id b79mr381661wmi.55.1496853719397; Wed, 07 Jun 2017 09:41:59 -0700 (PDT) MIME-Version: 1.0 Sender: jblunck@gmail.com Received: by 10.28.25.65 with HTTP; Wed, 7 Jun 2017 09:41:58 -0700 (PDT) In-Reply-To: References: From: Jan Blunck Date: Wed, 7 Jun 2017 18:41:58 +0200 X-Google-Sender-Auth: PvvkzULELynazp-jeSRegM5uD60 Message-ID: To: Gaetan Rivet Cc: dev Content-Type: text/plain; charset="UTF-8" Subject: Re: [dpdk-dev] [PATCH v2 04/11] bus: add bus helper iterator to find a particular device X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Jun 2017 16:42:00 -0000 On Wed, May 31, 2017 at 3:17 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 | 25 +++++++++++++++++++++++++ > lib/librte_eal/common/include/rte_bus.h | 23 +++++++++++++++++++++++ > lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + > 4 files changed, 50 insertions(+) > > diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map > index f1a0765..21640d6 100644 > --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map > +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map > @@ -164,6 +164,7 @@ DPDK_17.05 { > > rte_bus_find; > rte_bus_find_by_device; > + rte_bus_find_device; > 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 811aff3..632a6e7 100644 > --- a/lib/librte_eal/common/eal_common_bus.c > +++ b/lib/librte_eal/common/eal_common_bus.c > @@ -182,3 +182,28 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev) > { > return rte_bus_find(bus_find_device, (const void *)dev); > } > + > +struct rte_device * > +rte_bus_find_device(const struct rte_device *start, > + rte_dev_match_t match, const void *data) > +{ > + struct rte_bus *bus; > + struct rte_device *dev = NULL; > + int start_seen = 0; > + > + TAILQ_FOREACH(bus, &rte_bus_list, next) { I don't think that this should use the TAILQ_FOREACH() macro since it makes the code nesting deeper unnecessarily. > + if (!bus->find_device) > + continue; > + if (!!start ^ start_seen) { > + dev = bus->find_device(cmp_rte_device, start); > + if (dev) > + start_seen = 1; > + else > + continue; > + } > + dev = bus->find_device(match, data); > + if (dev) > + break; > + } > + return dev; > +} > diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h > index 0664662..b56018f 100644 > --- a/lib/librte_eal/common/include/rte_bus.h > +++ b/lib/librte_eal/common/include/rte_bus.h > @@ -180,6 +180,29 @@ typedef int (*rte_bus_match_t)(const struct rte_bus *bus, const void *data); > struct rte_bus *rte_bus_find(rte_bus_match_t match, const void *data); > > /** > + * Bus iterator to find a particular device. > + * > + * If the callback returns non-zero this function will stop iterating over any > + * more buses and devices. To continue a search the device of a previous search > + * is passed via the start parameters. > + * > + * @param start > + * Start device of the iteration > + * > + * @param match > + * Callback function to check device > + * > + * @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_device * > +rte_bus_find_device(const struct rte_device *start, > + rte_dev_match_t match, const void *data); > + > +/** > * Find the registered bus for a particular device. > */ > struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev); > diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map > index 6f77222..e0a056d 100644 > --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map > +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map > @@ -168,6 +168,7 @@ DPDK_17.05 { > > rte_bus_find; > rte_bus_find_by_device; > + rte_bus_find_device; > rte_cpu_is_supported; > rte_intr_free_epoll_fd; > rte_log_dump; > -- > 2.1.4 >