From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f172.google.com (mail-wr0-f172.google.com [209.85.128.172]) by dpdk.org (Postfix) with ESMTP id 2179B7D01 for ; Wed, 24 May 2017 18:16:10 +0200 (CEST) Received: by mail-wr0-f172.google.com with SMTP id l50so57944156wrc.3 for ; Wed, 24 May 2017 09:16:10 -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=eczSZKcmoR0SmMLE7465mUvcIV+pVioWgnj1qvl/hhmOVeFHslJU16Q3uo7yEePEiT pelXDBcUfBz0As25SpLqQZmiX4ApzFYI84UTnML62+eaEemO34yiAFT0c5B0ewwpKlcY Jyyy6UMfMOKvaFGu8wu7C7aIizz2iioYygfN4HkFSK/q7TfkbQ79Dv7/RoLZoDOsma7B 3tOHG9iy86EFVZhV48wpihEBP1zq9V3udWxRpaqouXygjEiWCVbdAwvI/cPk4LZnVQpA 0dydwY8V76AFOql9bwc0M1MMBAGNNXPWi1yLHRqkAW3jobRN7TMOpvZwHYnfwlbvejtE lTBA== 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=tN9/OEcfrr2Lerk23F2pXRoHw69yEgZ3ligE4Tmtw7H1KK+mR2psYpa3DhHNuUlh0m biM2j3rD6M+djBXyfX027fUL0CoOAfBoBcihIK1BI97RdCOECLVAD5Tf3d3d81BWYblQ SDZ1g63xTOm/MNcKM8VyGgEiOccSJjy5UeG9BrLzVV09O2JJIwoFCm1ay4ITqd0xcmDn mW8aYMYnh7SaP9Cu9Ml6n0YafbrKxXbEh5h+rhEUYVIcPOkEysu3ngIkaNiX/wsr8PH+ ZlM3Pu+fSNm4B01keiDzBDb5RYNE6xtEAq/AmaFG7IMZ1B6kGrAqEvIq7biLWfmnmHyh Enpg== X-Gm-Message-State: AODbwcCr5S9mcCka2ctRBpzHX82q1F0LxGj5xXba5lEmyBW3K8HeKJM1 Ki4t706IkzlfsBYEEl8= X-Received: by 10.223.135.42 with SMTP id a39mr18847674wra.113.1495642570128; Wed, 24 May 2017 09:16:10 -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 l7sm7783055wrc.52.2017.05.24.09.16.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 May 2017 09:16:09 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 24 May 2017 18:15:49 +0200 Message-Id: <8d9f73aa4d9755538489317ec7366c3fd3ef2c5f.1495642202.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 v2 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 16:16:11 -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