From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id CC0731BE6C for ; Wed, 4 Jul 2018 00:15:45 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id v16-v6so3797647wmv.5 for ; Tue, 03 Jul 2018 15:15:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=+PtSwL92xvH7QaDOLlLEBP1myR80ZkQw2JwqGJe+bOA=; b=k3CrXusUMOVLa+lXJfElspjsm+qcd/OYCmAsvAgaQ89BDZ2yz56HefaZI/tghJnAkW OBnUOlFETB7+vG6jXNDACC7c3N4T6/F1XcuHB0Fwwum72ywAS3JSiybHEUlG250ZtqPh N5xS9IlOnBs0aV/I61kwZsmNKYi83qYj3piacW5Iea2fPnjJ2sJcXM5MpAjVnveL8IPy 6QyiwEd3iDqrx2jchNKnmgartIw9S1oLdrIS900xovGWCuFs1QOUTIRsAmQKoOuOLxY5 uHIymP2D8QZkQ8oL9Unupv3CJj/rOIsrvv6Lf+bdpdds7PTI2CUYMfjUvSLNOhZrerTR StUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=+PtSwL92xvH7QaDOLlLEBP1myR80ZkQw2JwqGJe+bOA=; b=W5LAmtVerq3wd/BeK0YzmavAVDbkHRqN6/IdToScBuBIlj93qeKmGOTdG4HjDX1LO9 CY3pJbGOacZGC9dYLEWJ50tWagOrgS+wMTk5rDfhei/zjsS57lwm8/TGyJUd77Q1BSRZ QP+y6XidWsGDOG+Dum2vYEda7ILe3y6jNAVJln8bPO+KqwTIZ1KbcR9h0xwSW8rFel6k W3f0AqK/3r6Gp27YrcvAVYBYMwteyZcC5s5O9kvD0mk1T/WaRn1VG3SDh2jJfCTcHZS2 ZPP33N8CDqi6nGUf65f1m/jHywD+xBzdwE8gdVrsGHojfKEPXzkTbI0dfsoyAT4TzjMW mYGw== X-Gm-Message-State: APt69E3LOyM2pV5njuUVS3IuCUkik/jea1WPxVmTDBC6JDinv/fgNsZy ywXGtlLvILZAnqgk6YM29JSlQxta X-Google-Smtp-Source: AAOMgpc8ZKZn279OwmbAMHCsJ7A6UhVuEFtOODUZDCiMDrRJ+VFklPbwbzWp3woaBCuXmPk3SYcH+Q== X-Received: by 2002:a1c:f106:: with SMTP id p6-v6mr11571786wmh.68.1530656145139; Tue, 03 Jul 2018 15:15:45 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id i190-v6sm3771084wmd.33.2018.07.03.15.15.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jul 2018 15:15:44 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 4 Jul 2018 00:14:52 +0200 Message-Id: <062cf5694b1776a18f2f0718224d7e379c77ba7c.1530655929.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v9 09/27] eal/dev: add device iterator interface 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: Tue, 03 Jul 2018 22:15:46 -0000 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 then 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 returning 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 | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index 3879ff3ca..120df729f 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -285,6 +285,53 @@ __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. */ + const char *busstr; /**< bus-related part of device string. */ + const char *clsstr; /**< class-related part of device string. */ + struct rte_bus *bus; /**< bus handle. */ + struct rte_class *cls; /**< class handle. */ + struct rte_device *device; /**< current position. */ + void *class_device; /**< additional specialized context. */ +}; + +/** + * Device iteration function. + * + * Find the next device matching properties passed in parameters. + * The function takes an additional ``start`` parameter, that is + * used as starting context when relevant. + * + * The function returns the current element in the iteration. + * This return value will potentially be used as a start parameter + * in subsequent calls to the function. + * + * The additional iterator parameter is only there if a specific + * implementation needs additional context. It must not be modified by + * the iteration function itself. + * + * @param start + * Starting iteration context. + * + * @param devstr + * Device description string. + * + * @param it + * Device iterator. + * + * @return + * The address of the current element matching the device description + * string. + */ +typedef void *(*rte_dev_iterate_t)(const void *start, + const char *devstr, + const struct rte_dev_iterator *it); + #ifdef __cplusplus } #endif -- 2.11.0