From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by dpdk.org (Postfix) with ESMTP id ACDCA1B539 for ; Wed, 11 Jul 2018 23:45:49 +0200 (CEST) Received: by mail-wr1-f67.google.com with SMTP id g6-v6so10691651wrp.0 for ; Wed, 11 Jul 2018 14:45:49 -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=C4kfmhhDec3yERy3OYFtMnirjd6NayeqAesuv3kzo7U=; b=gy6CO9u0q4m6939Fos37SmigNznPBtuHIFP3Rwa5Q63hsczapkuWISb6RlT6kg7tFG QlYaDYnokJhsw7474uwpuh1hPv9YM8cC2Jp5Doh6t/WppFCckWmWmSvdt7LaEUEZpP04 k0lqpqNnwsrkseHvKH9hBRXnYtxRXpVtbTF8l/LjXtFJ3RfFSrcipb1k4066j8Z3aKor GPjvGLETNVTUvqEUBLRa6+n/nS1wYIUkGVP14mcCDfZA38Dp+qEQiDGnLtb/BHcOV5Lj l4blZ2374IGpv1Pie6qqED1nH0a9I4wS5Yp2S9WZ8N368BztQeKgD9R10uEoxh/zbEiO tP6Q== 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=C4kfmhhDec3yERy3OYFtMnirjd6NayeqAesuv3kzo7U=; b=QgEE9Unnhij4eEF1jpuDb4nKAnh/NIc8mMQdMDvKlZY0V/OCDtC6d2uZ7hONlDQo+U M9NT/Dwv6Z/LCqtC4pak2sB1qnJNyGA7YzLi947sXQ32V2hvHnmYUVQ97eIg926giGdu 6a69SMCbboJ3rfP+7xJb1wNYTK/+GYh17Tim0t3xrBJoOyIxeZA9U8UBw5sGv2EAjv1F cvG8eWhFn4Vk3cqiqy8DNfyKUUhRyaNLJKmEz9iclYNsRjs8mnqaMYdFJZmeHl9HfBNP Gp1fv97qMZDBZBzKtCiyB6mE/GKD8jZ2P7x4xt/MK4ftUlUIVJZaJ8Fs0HScdmsWlJX/ tAhg== X-Gm-Message-State: AOUpUlErzl8fDrJIyHUsGmDcQ1fwE6mVgxwKdHqbjR3/R09W03+nhP4D M3k9CGSZAeRaVT7W35sSiCmxxvzq X-Google-Smtp-Source: AAOMgpcKdUXT000vQvkpenPvkqzt5xw6u7LaqF8frDufcnf8uPcssp4N73Mp0fRWlQvmEp6Mqm6Eng== X-Received: by 2002:adf:92a5:: with SMTP id 34-v6mr224764wrn.83.1531345549017; Wed, 11 Jul 2018 14:45:49 -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 h5-v6sm10550936wrr.19.2018.07.11.14.45.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 14:45:47 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 11 Jul 2018 23:44:59 +0200 Message-Id: <55bada19d99b0d3edd5ca31c9a9d897162a3dec6.1531345404.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v11 09/25] 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: Wed, 11 Jul 2018 21:45:50 -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_bus.h | 1 + lib/librte_eal/common/include/rte_class.h | 1 + lib/librte_eal/common/include/rte_dev.h | 47 +++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index eb9eded4e..747baf140 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -211,6 +211,7 @@ struct rte_bus { rte_bus_parse_t parse; /**< Parse a device name */ struct rte_bus_conf conf; /**< Bus configuration */ rte_bus_get_iommu_class_t get_iommu_class; /**< Get iommu class */ + rte_dev_iterate_t dev_iterate; /**< Device iterator. */ }; /** diff --git a/lib/librte_eal/common/include/rte_class.h b/lib/librte_eal/common/include/rte_class.h index a79f3152e..85dad5a11 100644 --- a/lib/librte_eal/common/include/rte_class.h +++ b/lib/librte_eal/common/include/rte_class.h @@ -35,6 +35,7 @@ TAILQ_HEAD(rte_class_list, rte_class); struct rte_class { TAILQ_ENTRY(rte_class) next; /**< Next device class in linked list */ const char *name; /**< Name of the class */ + rte_dev_iterate_t dev_iterate; /**< Device iterator. */ }; /** diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index ba6e445fc..49000abac 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -284,6 +284,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 *dev_str; /**< device string. */ + const char *bus_str; /**< bus-related part of device string. */ + const char *cls_str; /**< 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.18.0