From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by dpdk.org (Postfix) with ESMTP id 9CB20377E for ; Wed, 5 Jul 2017 01:55:44 +0200 (CEST) Received: by mail-wm0-f52.google.com with SMTP id i127so150650114wma.0 for ; Tue, 04 Jul 2017 16:55:44 -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=c0VQB2Gdq3FhT0SgVGUHclZ7XMR7/i2gpzu8ElC7N04=; b=Rf7yECxiDMXhEn592DBQZdkps7DX5DSZ21Tc8txOBnDbT3Q8+XLnm5kO8hvBHKp+jX JQxVF5nymHvhDHOhk86hQ6ihF4a4sa4fmr89s/MUC2pAcw6LaUMPBup8NLcJXLRwZyGt Sk37TsKQ9jt0c0d4zLIvS4C3mMtR1raJkzaqpQlkdT58wwalozREiiGw8TIu0zMzsCC4 9PedFUC7eQU4MiHm7PzLgOwY3sczCIOhao1X8VPb522pgYDWAg3pplco/khPqRcttgqO M3qU2Dcdmvs2wbYa66fZCSUe4y7YUjFkTevsaIc5GHNIzwsAfCT4misTTODbrcqYUSlN mdkg== 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=c0VQB2Gdq3FhT0SgVGUHclZ7XMR7/i2gpzu8ElC7N04=; b=QhtpZWK0DwrH7Rd9D6hWbvIb7j1rDE8Ynhc3MspXyrSkap2NQxK9spXBUzYkMrkBqJ 907zkg927bsIPxh8LfFDNEF/TVUuf6jhW8Og/jUjZCNuT3Y73CBqyFCuLKGleTevPCnB sI+kDo5P3UeJhltoM6iFFmxl0R1PgFysMnCQvZ6O95nC/gkEFrUr+UTfmpJPVDE+nQjU 5q2LBTvvdTlpFsKz2KzYd43gvR1pboGvyfvIS7EWjkWjO817oCc62xF5YNh32rTWUnkL xgEZ3c3CnNsZYM1RZe7Ny9TdteCKrUhI6gUmZtpy2an6uqtNkghxOr/Ia7fyaWUDt+mI aycA== X-Gm-Message-State: AKS2vOyolg8JefKnIaTw+6lUYZvfLZ/mLTIXjVDKROmgRPhZJg14sjOT QAliQGtffUXrDCfpGxI= X-Received: by 10.28.173.10 with SMTP id w10mr28651391wme.98.1499212543718; Tue, 04 Jul 2017 16:55:43 -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 19sm23406533wrx.26.2017.07.04.16.55.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 04 Jul 2017 16:55:42 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 5 Jul 2017 01:55:22 +0200 Message-Id: <3cedddd79f0f518e412431526c9e2b3058d3220b.1499211317.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 v7 5/6] bus: add helper to find a bus from a device 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: Tue, 04 Jul 2017 23:55:45 -0000 Find which bus should be able to parse this device name into an internal device representation. Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_bus.c | 21 +++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 12 ++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index 87b0c6e..34fcfa1 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -204,3 +204,24 @@ rte_bus_find_by_name(const char *busname) { return rte_bus_find(NULL, cmp_bus_name, (const void *)busname); } + +static int +bus_can_parse(const struct rte_bus *bus, const void *_name) +{ + const char *name = _name; + + return !(bus->parse && bus->parse(name, NULL) == 0); +} + +struct rte_bus * +rte_bus_find_by_device_name(const char *str) +{ + char name[32]; + char *c; + + snprintf(name, sizeof(name), "%s", str); + c = strchr(name, ','); + if (c != NULL) + c[0] = '\0'; + return rte_bus_find(NULL, bus_can_parse, name); +} diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index 6cacce0..0836339 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -338,4 +338,16 @@ int rte_eal_hugepage_attach(void); */ bool rte_eal_using_phys_addrs(void); +/** + * Find a bus capable of identifying a device. + * + * @param str + * A device identifier (PCI address, virtual PMD name, ...). + * + * @return + * A valid bus handle if found. + * NULL if no bus is able to parse this device. + */ +struct rte_bus *rte_bus_find_by_device_name(const char *str); + #endif /* _EAL_PRIVATE_H_ */ -- 2.1.4