From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by dpdk.org (Postfix) with ESMTP id AE5C22C2E for ; Tue, 27 Jun 2017 18:11:35 +0200 (CEST) Received: by mail-wm0-f42.google.com with SMTP id b184so31869561wme.1 for ; Tue, 27 Jun 2017 09:11:35 -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=81iH1CTt2OiuE0cVbLlcSxtTg8Nfz4CJ/vIai/LoWNo=; b=Clo1tVIM63SWPe28huNRWdVjmrW4FAJ8e+9bX7AeM19ERlAOQQhdL87XEVFeFPvkjm XOJqufE8IJELkoVzPMFlQIeGtI7sCwShhAHsxsN0XaP01rGJikmPXP9g2r2Rki3Lrv6m n1TI2j4t9mOu51D+bmN4EmdX1hv5oOXQcrqo17zMc+BX4m7mw9plCU6ndxWQLi26awhS sjG6kW2vOGzTr7SLGtWo/tr8HH4thRJtiDKtLlmwkLpbCVrnbo54hFBiZTCYrNj1nIiX w3Iuc3eh7bnxc5oWEof5g/+ujAs8wx39CI7gGi7hKGW/Txs+Z7kFk43P/rVOJCxCy54S IZ+Q== 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=81iH1CTt2OiuE0cVbLlcSxtTg8Nfz4CJ/vIai/LoWNo=; b=AqKjf1JSM70cK/WGyZ4UrwlViaEDR3UGKFyHpbZN8WkkS6R3srkKnLhEaUnT2GNQnC /BGmk8PCUzz+pk1hUvrEzgwkLE3nJrdiZkvRNhsTUMqzCeQVhyhWT6Dxn2bSz42LCjS3 r4RGD4UCbVNC+j9vfuz72MD7Kv4mtFmrZYVnIBv61HO5OpoKfdGr1fUzP3ruVFbz2+1G 5miWZSEb1RXeAsTaUAEPlre/P+bq70XZzDLtybWrkLN2HPp0io5U80VSfC9VXx3mQG0c dCoxLJFG3lCvGGgh+I71jtYW2BXW7vjzbLM4Hye7pFsz5NgLt6KIgDk1owIeXarW5MLo DHMw== X-Gm-Message-State: AKS2vOwg3NlhM5D8Z7zgAIRZpvYU9Xjd/6cduy2iU/D2v7uHEqs0zq9p R0jrRx+Q9ZZBTOWYJIk= X-Received: by 10.28.132.11 with SMTP id g11mr3819996wmd.57.1498579894754; Tue, 27 Jun 2017 09:11:34 -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 v13sm4080465wmd.5.2017.06.27.09.11.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Jun 2017 09:11:33 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck , Gaetan Rivet Date: Tue, 27 Jun 2017 18:11:09 +0200 Message-Id: <8d5bbb91cb07550fee6a2dfefe2b0c23ad6a281d.1498577192.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v6 02/11] bus: add device iterator method 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, 27 Jun 2017 16:11:36 -0000 From: Jan Blunck This new method allows buses to expose their devices in a controlled manner. A comparison function is provided by the user to discriminate between devices, using arbitrary data as identifier. It is possible to start an iteration from a specific point, in order to continue a search. Signed-off-by: Jan Blunck Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/include/rte_bus.h | 28 ++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 21 +++++++++++++++++++++ 2 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 ecf839b..51f41d9 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -82,6 +82,33 @@ typedef int (*rte_bus_scan_t)(void); typedef int (*rte_bus_probe_t)(void); /** + * Device iterator to find a device on a bus. + * + * This function returns an rte_device if one of those held by the bus + * matches the data passed as parameter. + * + * If the comparison function returns zero this function should stop iterating + * over any more devices. To continue a search the device of a previous search + * can be passed via the start parameter. + * + * @param cmp + * Comparison function. + * + * @param data + * Data to compare each device against. + * + * @param start + * starting point for the iteration + * + * @return + * The first device matching the data, NULL if none exists. + */ +typedef struct rte_device * +(*rte_bus_find_device_t)(rte_dev_cmp_t cmp, + const void *data, + const struct rte_device *start); + +/** * A structure describing a generic bus. */ struct rte_bus { @@ -89,6 +116,7 @@ struct rte_bus { const char *name; /**< Name of the bus */ rte_bus_scan_t scan; /**< Scan for devices attached to bus */ rte_bus_probe_t probe; /**< Probe devices on bus */ + rte_bus_find_device_t find_device; /**< Find a device on the bus */ }; /** diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index de20c06..04d9c28 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -191,6 +191,27 @@ int rte_eal_dev_attach(const char *name, const char *devargs); */ int rte_eal_dev_detach(const char *name); +/** + * Device comparison function. + * + * This type of function is used to compare an rte_device with arbitrary + * data. + * + * @param dev + * Device handle. + * + * @param data + * Data to compare against. The type of this parameter is determined by + * the kind of comparison performed by the function. + * + * @return + * 0 if the device matches the data. + * !0 if the device does not match. + * <0 if ordering is possible and the device is lower than the data. + * >0 if ordering is possible and the device is greater than the data. + */ +typedef int (*rte_dev_cmp_t)(const struct rte_device *dev, const void *data); + #define RTE_PMD_EXPORT_NAME_ARRAY(n, idx) n##idx[] #define RTE_PMD_EXPORT_NAME(name, idx) \ -- 2.1.4