From patchwork Thu Jun 29 18:21:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Blunck X-Patchwork-Id: 26001 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 844D35A3E; Thu, 29 Jun 2017 20:22:34 +0200 (CEST) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id 14F275689 for ; Thu, 29 Jun 2017 20:22:29 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id j85so4071770wmj.0 for ; Thu, 29 Jun 2017 11:22:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=NpvOKAlRJos46VVwzY+MEIx6PMi16LCvrnfvjJi7BYg=; b=VwCYLPBMI08nmvlkXlfYRWIdjmyCVUVmTVt+UH/cfEjR+OxnvM8TS0Jgph/izM/tlg 1efWhwzr3yxScE85Cj2TjR2V/F5CsbMlL35k9z1RV6OtbaUZynCGMjHvWe5xxlNEDlEB MLZlvRjGl2mltLvjuR1ZWrvAbEIqnvFRnWkkb+/I/1MNvdoE20/imeT5noCDJGdCsEy7 GFljZCnmCfLBBcTb/6gV9RoJzyXPUa81McicSdB4woU29oXa8xsaSoe0RYeucgUU7Z6p UrstRG0iDxxztkMlg8C9j6+6Ux6agfv0cEGsgKKxUovwM/eC94e0YqwEKd2amadl59iB kdYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=NpvOKAlRJos46VVwzY+MEIx6PMi16LCvrnfvjJi7BYg=; b=O+m3IMsfLxflqolR80bXJDcQ+N3A2TgDoauDD5y0p/lTbjmjFaScCxtlCFMMVbWvZr E8lgVwd0Bdb+nkzrPk0B9chPfv9xXLa5ceyG1KadIfUabpjQnL8W9sN0Psgk3SQK2DwI fCqcuX0CtzxDzN1XJlmfFLLFSVfjWQM1VOXZiIyStSoqdDrj9DnE7kFEmQEidEsV9ug9 oIrVQ2NnPpPbBCgOQVPNvz+7SmTXDtDoZHmrc8dAe2gXofkwj3gXVqnsT8xuTNaOTPel UV4Z5BK6LPCfaaLuPT+SHdzUgl/IMXe4/KDUFTtfovOUk4ZRuQXQ7XD9eaW+CGKhLWWp 5IDg== X-Gm-Message-State: AKS2vOydyn10CN6yyWK9pZFtZ96sy5SLHXLEVVUQkCSV4r6xfeGtINGe oNLl3FNC6SnEruyQ X-Received: by 10.80.175.165 with SMTP id h34mr2701456edd.87.1498760548352; Thu, 29 Jun 2017 11:22:28 -0700 (PDT) Received: from weierstrass.local ([91.200.110.13]) by smtp.gmail.com with ESMTPSA id e28sm1446366ede.14.2017.06.29.11.22.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2017 11:22:27 -0700 (PDT) From: Jan Blunck To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, shreyansh.jain@nxp.com Date: Thu, 29 Jun 2017 20:21:53 +0200 Message-Id: <20170629182206.1072-3-jblunck@infradead.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170629182206.1072-1-jblunck@infradead.org> References: <20170629182206.1072-1-jblunck@infradead.org> Subject: [dpdk-dev] [PATCH v7 02/15] bus: add find_device bus operation 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" 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 | 27 +++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 21 +++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index c52b65b..052ac8d 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -82,6 +82,32 @@ 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)(const struct rte_device *start, rte_dev_cmp_t cmp, + const void *data); + +/** * A structure describing a generic bus. */ struct rte_bus { @@ -89,6 +115,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) \