From patchwork Thu Jul 5 11:48:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 42344 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D59DA1BF2B; Thu, 5 Jul 2018 13:49:30 +0200 (CEST) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by dpdk.org (Postfix) with ESMTP id 414061BEDA for ; Thu, 5 Jul 2018 13:49:09 +0200 (CEST) Received: by mail-wm0-f65.google.com with SMTP id s12-v6so10652275wmc.1 for ; Thu, 05 Jul 2018 04:49:09 -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; bh=ZaTY600S/w2aMPXxpxdxYg2oJRiJH9R4k/SlAVvW0/0=; b=Lc8RvlDSpO32FC1v0dCccIYJG98iAbGMPOLMJUdvZdI/XkgWkxECrAlQmMZvBAtuyG FbUMY6GLcrq+LZA8ctigaKTu+t2ZbctgBqFqNCCwTjFHIsOOm2h4mJvxfUheGFfN+Vf3 1UP1MYfyW1qqLg1APdaP0iJK6hv7D0KntsU4Jzy10bLpvjsOy8BJoxoXAFoLRqQboKSg Xs/9dkpdjl7cYF40ilvI0eFCRoP/TRPiBl1yqP32cjIySp9LpqUFySDW5/R//JjwE5+d DgYsRKtJXHRgQsdGvtv2kZzv6HQPKyMBzBhMCXplzKYF+sMI34pjX0mHhUqhTwumGKv3 vVzg== 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; bh=ZaTY600S/w2aMPXxpxdxYg2oJRiJH9R4k/SlAVvW0/0=; b=WljtjKOo2tjrYBbXQGJUmyMFOtxL295sGcmZOWvo2134ltfl5d+EUSLx9kuI+5ZJXs NE4h9YMQLU78W1l87QkOjHCMnpYd6BDW9G+U+xXARfrpy6N2BF199BO+osa1ouwN7MU+ jZYYW4ZOVq7Jp9Yp4qQePLpLZBXUtesr4xoTqOv2e6qUYsBAVVwGCPwOwzpZ03rdkACS skg2xXmRyD2N1PYJm0GvdaEbhSgTAhgVx6i5J0AqGvefgaogx2v3M8+kJLcgHeShiiZE idN/5hpgzFaWZFQNcRTsCoNoGxriAU/Pli1sggpjzyST4jWI+5CZgLr1h8FNd9zqYzoe Bu3w== X-Gm-Message-State: APt69E2g6HTpMVy4hxNh9M3lj0XyHIvNW4zuHoCILicFYxenhkp4T4Yu HuNGXpthMGPSS/WCNhNYc/RcTcXs X-Google-Smtp-Source: AAOMgpcJZhw+TlrX+HV37JajCBK3V2BzIah0YUBubCphjSZco11IvXj5MSIo6xamtuJoRx5gRU0HCA== X-Received: by 2002:adf:b726:: with SMTP id l38-v6mr4517669wre.115.1530791348442; Thu, 05 Jul 2018 04:49:08 -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 o42-v6sm15809183wrc.50.2018.07.05.04.49.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Jul 2018 04:49:07 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 5 Jul 2018 13:48:16 +0200 Message-Id: <133ee7dfdeaad08347346daeb088d1df0d042e55.1530791217.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v10 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: , 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 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