From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gaetan Rivet Subject: [PATCH v1 05/18] eal/dev: add device iterator interface Date: Thu, 15 Mar 2018 18:49:35 +0100 Message-ID: References: Cc: Gaetan Rivet To: dev@dpdk.org Return-path: Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by dpdk.org (Postfix) with ESMTP id 61857A48F for ; Thu, 15 Mar 2018 18:50:17 +0100 (CET) Received: by mail-wm0-f66.google.com with SMTP id a20so24177358wmd.1 for ; Thu, 15 Mar 2018 10:50:17 -0700 (PDT) In-Reply-To: In-Reply-To: References: List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" A device iterator allows iterating over a set of devices. This set is defined by the two descriptions offered, * rte_bus * rte_class Only one description can be provided, or both. It is not allowed to provide no description at all. Each layer of abstraction them performs a filter based on the description provided. This filtering allows iterating on their internal set of devices, stopping when a match is valid and storing the current iteration context. This context allows starting the next iteration from the same point and going forward. Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/include/rte_dev.h | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index b688f1efd..d272d7191 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -263,6 +263,42 @@ __attribute__((used)) = str static const char DRV_EXP_TAG(name, kmod_dep_export)[] \ __attribute__((used)) = str +/** + * Iteration context. + * + * This context carries over the current iteration state. + */ +struct rte_dev_iterator { + const char *devstr; /**< device string. */ + /* Bus context. */ + struct rte_bus *bus; /**< bus handle. */ + const char *busstr; /**< bus-related part of device string. */ + struct rte_device *device; /**< current position. */ + /* Class context. */ + struct rte_class *cls; /**< class handle. */ + const char *clsstr; /**< class-related part of device string. */ + void *class_device; /**< additional specialized context. */ +}; + +/** + * Device iteration function. + * + * Iterate over a set of devices, defined in comprehension by + * the given iterator. + * + * This function must update the internal rte_dev_iterator ``device`` + * field. The ``context`` field can be used as an additional generic context + * when the current ``rte_device`` is insufficient. + * + * @param it + * Device iterator. + * + * @return + * The address of the current element when the stopping + * condition became valid. + */ +typedef struct rte_device *(*rte_dev_iterate_t)(struct rte_dev_iterator *it); + #ifdef __cplusplus } #endif -- 2.11.0