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 9A615326B for ; Thu, 8 Jun 2017 01:56:28 +0200 (CEST) Received: by mail-wr0-f172.google.com with SMTP id v111so11984523wrc.3 for ; Wed, 07 Jun 2017 16:56:28 -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=L74p6F1d9Gxqx77H4nX0Pn2SG5M/AItmKZz9MmWdEKM=; b=IJh7ZdT7Ltt5xO3dIR2cjsGhfXo2ySew3UAHPGyy7C0DQEjFQG1PbtvR3yocIe9CVk DPA3jTJH27SLdYGV1tGmrZGkGd+1F9K98o68xL50jAX/+hZh4kMkXCV+rnJ3svk+euEY lZukgG9S9Arng4ZzpG/swsvV1I7VlasK9wUh0HfzR3xP/YRr9m3wlA53c9ry5DHwrIme AaMAzoyd1NKducyjgHZEk7SCP9FDqEsXr5tBYvRndoSWZGHz70c+c80+Q8I6wPDuVOcV IcwG+9zVeKWM7T3koEtxm8OlJf+XwTL3I/un7PWK/7LDp06foD6z5NwfXm6cIVt+xIE8 v9JA== 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=L74p6F1d9Gxqx77H4nX0Pn2SG5M/AItmKZz9MmWdEKM=; b=KQZ7TK1/aTd/pGvnmZkrjU2dDC1lMdrvwbvWt//PPdNnKHxbZf4Qmo1tMrowePyH08 DYS9mVMqwxyjhWYRcnb5LfoW2YCKf1Ac4v0fdMZKaXgSvWMC2BLdpwQqR4QGAPLa9Z+L YMV9CMgYvhOCfOEjQHAOc6/jdTzNiNnLQx6jrSWH94Sbj9rEh4bXRZHESB7VwfdRkg7c VlwMAZLSJlpP/a2/vhvPtu/spogDiwwYl+oQxFSYOOki0+ny9pONqU4YuHtieS1y5Urv ne0RsPSWEsrMO91an4wSm3Kk6EN/lqq6XOonSdPfz5KLj0Sx0iHKWnvD/SrBpA73eDot kRWw== X-Gm-Message-State: AODbwcBTNHuHJ9FgOXxUA0lRwTYjo+lMtqn/83ON1S5o5liPSXvCs12w sEZkTnhr6CE+iLgEUQk= X-Received: by 10.223.170.193 with SMTP id i1mr21767217wrc.143.1496879788071; Wed, 07 Jun 2017 16:56:28 -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 m40sm2624808wrm.4.2017.06.07.16.56.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Jun 2017 16:56:27 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 8 Jun 2017 01:56:06 +0200 Message-Id: <1ba7323d2a979a0a0367e2b183da05fcb41e359d.1496876810.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 v4 6/9] bus: add helper to find a bus from a bus 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, 07 Jun 2017 23:56:29 -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 d9d8f62..2b41ba2 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -220,3 +220,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 9b50451..b236893 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -261,6 +261,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