From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f177.google.com (mail-wr0-f177.google.com [209.85.128.177]) by dpdk.org (Postfix) with ESMTP id A3D657CF8 for ; Wed, 24 May 2017 17:12:59 +0200 (CEST) Received: by mail-wr0-f177.google.com with SMTP id w50so56963860wrc.0 for ; Wed, 24 May 2017 08:12:59 -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=Qqjrf8T2U6qQoxylIUjYNXDaTIwjw6xORURwmkIvly4=; b=QbmdpeNS/NIVjQTO81gy0EWXbbgigUcsjqegjF0CYSq7UBD32vf/jRV6RcbP4Cl9hq YvdYH8pakDeKBvx+ib5N88dMxCwl2gahbUWRLZS/wCcOgGZBymAZZpUoavQx0pOsO5KZ 6sk4vubO5FzZTjpNfMcpbInKZvKKZpLxdREO9kInc3AEVimwX9uJft3QYCbvcz8q0KQm IpmG5fWLX0cHeB9T14zH0zzMgW3RjZTiayeT0Pjg8msoR4rGAson7OcHYrdxq6CubL5G 6hC+iwNhuIPlX7TsROIsANCiYPZK2PrCarEOBCmdnNQMfYOsEmEBNCrKrmuGmKe/RUOq AfpA== 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=Qqjrf8T2U6qQoxylIUjYNXDaTIwjw6xORURwmkIvly4=; b=A1La93SVWkzhgjJc5WUVIa7tgjTlsmRgJNTrgSoamaxqGGh4AzqkcCEnb9Mm9XnMey ZQTkQZyLwpa553+BmZNqOhhs4yZQuEL90jonZ0Ycw+taA212i3QzQeyjpDyaJATzawFc JS2fR0R/Rx0yQMP+A30n0n6bW2qk+/54QCJYzgPFYnou9ZoN3bNZpYXog24NcSKhbp5y R+DyeSfN5IAywuYpDSn+LxXieEMlTnyBfGxA4xewc4nm+FJRvg+ndwKdiImvsW12lHQV 8v4NiouFxMEtOWzBw8uD//i0tdOON5juChyogjsjJ6sfF4AkNFcI/K2LHHpS95D1UJ2Q 4StA== X-Gm-Message-State: AODbwcDPDMJnDO187aXKRV2LEV0QhXHH5TOnGh28wI+/RM0ipR69juOC Wjzrju6ippN5MGiO X-Received: by 10.223.164.148 with SMTP id g20mr20232626wrb.89.1495638779346; Wed, 24 May 2017 08:12:59 -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 9sm5633351wmh.17.2017.05.24.08.12.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 May 2017 08:12:58 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet , Jan Blunck , Stephen Hemminger , Maxime Coquelin , Jerin Jacob , David Marchand Date: Wed, 24 May 2017 17:12:38 +0200 Message-Id: <4523e9b593641e00358a8d11bc70e670bacd2bc8.1495629122.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 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: , X-List-Received-Date: Wed, 24 May 2017 15:13:00 -0000 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 8ef859a..7977190 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 00fc6d2..5b87ac4 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -236,6 +236,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; -- 2.1.4