From patchwork Thu Jun 1 10:08:56 2017 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: 24951 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 805057CE3; Thu, 1 Jun 2017 12:09:25 +0200 (CEST) Received: from mail-wm0-f54.google.com (mail-wm0-f54.google.com [74.125.82.54]) by dpdk.org (Postfix) with ESMTP id DAD396841 for ; Thu, 1 Jun 2017 12:09:15 +0200 (CEST) Received: by mail-wm0-f54.google.com with SMTP id d127so53523235wmf.0 for ; Thu, 01 Jun 2017 03:09:15 -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=9RjntSs96ta1AEKetVIY6Wq/6w8jbzOBr5urXkcFcqs=; b=zN2+dkN9YR4vFmRXJsYyGOKNq440btelRGhTzScV9/KdUbuxfUeusxGiT5wjukRGnc TkDLKFbBnqDHpH1g5K7cGj2e41E86Mt/9YL1OrXN55M+veN5pYBtUrEbyCeqNIPGZYhu YnT6oTbuV6FjSW6VvNe1ZpaCNzE8pe8uJ5JwLcGTwSj+qSiK2ybIbcMEUH/adxJIYSJB u4GuuRtsEb/n9qyR0rWxqM5cf9Px1DvQ4E/VORWGw/MqXwGq7DU2p0ll5Zggcfsu+KOt ioQzv/CXEOGcLHNaqvT6H/aO27Z28UCB0Jx5djWVIHLvVJOJ62SLm2CM/UBqidiTmDLe bNNw== 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=9RjntSs96ta1AEKetVIY6Wq/6w8jbzOBr5urXkcFcqs=; b=Y+0mMbnevt0soBKZQk64Iii8sEu7j0S855vuIAOwIEDAvAMFBDVasKw4cadeG231wi 0L1cKzviGCSrU7YVB0dwTIvWccf2mn4AUQsuiOlMySQuC/3RdlTTj4KSzoihr4sorb8p J69HWOmT8AHS5LB6N/ItBVei3VmyEd5HDVuEEgfcSzZj+1JVoquc6yAZcXtRklAo4Xmw ME53Q6PxlHg2qM4rzichrXtmQMvu0CYhsX11eOOSTpQrjy3fpItERlC4SUUcRs8FEpDD RACbTUk3ZCd72rrFMIFyCGwX0GZi1fr3otC35Z7SYtakEQQ1c1TkmyYp4zLPCZctJbHg ELtA== X-Gm-Message-State: AODbwcCqERfqciYqhjMomYGN9nijVRrO91SfMN7OIdkTwx4zieMZUqvE Y7ikLsPBeGl9T2Dmkkk= X-Received: by 10.223.164.7 with SMTP id d7mr590035wra.183.1496311755185; Thu, 01 Jun 2017 03:09:15 -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 r10sm24305457wmd.9.2017.06.01.03.09.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Jun 2017 03:09:14 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 1 Jun 2017 12:08:56 +0200 Message-Id: <20555df609bc5054c09f280ee55c80c553f54f66.1496311609.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 v3 6/9] bus: add helper to find bus from a name 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" Signed-off-by: Gaetan Rivet --- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 7 +++++++ lib/librte_eal/common/eal_common_bus.c | 19 +++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 14 ++++++++++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 7 +++++++ 4 files changed, 47 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 150b0f7..3517d74 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -197,3 +197,10 @@ DPDK_17.05 { vfio_get_group_no; } DPDK_17.02; + +DPDK_17.08 { + global: + + rte_bus_from_name; + +} DPDK_17.05; diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index bc3c6c6..063fcea 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -223,3 +223,22 @@ rte_bus_name_valid(const char *name) i++; return i; } + +static int +bus_cmp_name(const struct rte_bus *bus, const void *_name) +{ + const char *name = _name; + size_t i = 0; + + i = rte_bus_name_valid(name); + return (!strncmp(bus->name, name, i)); +} + +/* find a bus by its name */ +struct rte_bus * +rte_bus_from_name(const char *str) +{ + if (rte_bus_name_valid(str) == 0) + return NULL; + return rte_bus_find(bus_cmp_name, str); +} diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index 7e73d62..0eacd88 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -248,6 +248,20 @@ rte_bus_find_device(const struct rte_device *start, */ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev); +/* + * Find a bus handle by its name. + * Compares the name of each bus up until any invalid character + * in the matched pattern. + * + * @param str + * A null terminated character string. + * + * @return + * A pointer to a bus if found. + * NULL if no bus matches. + */ +struct rte_bus *rte_bus_from_name(const char *str); + /** * Helper for Bus registration. * The constructor has higher priority than PMD constructors. diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index e0a056d..6607acc 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -201,3 +201,10 @@ DPDK_17.05 { vfio_get_group_no; } DPDK_17.02; + +DPDK_17.08 { + global: + + rte_bus_from_name; + +} DPDK_17.05;