From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f180.google.com (mail-wr0-f180.google.com [209.85.128.180]) by dpdk.org (Postfix) with ESMTP id D4C773256 for ; Wed, 21 Jun 2017 01:30:55 +0200 (CEST) Received: by mail-wr0-f180.google.com with SMTP id 77so111492685wrb.1 for ; Tue, 20 Jun 2017 16:30:55 -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=LkoFhL/EQv3e+Sdycou0TcESoGFXwC7L4wcVoF5bsiA=; b=X6tX1AeuIC/P+M4/FvpAIS/B6t4dRcJz+QDjx3f3ehI8KxRU7C0m7dFwVQXibHWCnP kyCCIhxgzfjcjO68y9r51Z35+oa0HbGAbv7wzvAPl6dMQa2GPkjErejpW7vBHHnbtYWA EOP3DWXhUyfbYgP9DFij2USseRqcMhR4qJIkkvJ49vu0Ml5uMBm9IN0JAcYbFBaUpogo 1R7OyXOQ0JQKqT9XhbRse7Qs+XjCacVkoLbcg2L7sHl/A98TjPl3LwuSRGF4xL+dOWvd +J3uUuKCoQfL4EU9weaL/OeY+Z5q0glKjIOkCd20jsR/Q6yGktfUuyXfCvDDy2fwdF64 +6vg== 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=LkoFhL/EQv3e+Sdycou0TcESoGFXwC7L4wcVoF5bsiA=; b=Cw9HTkyjAjmAIoy+NfigIPql7RhUEox9DbXYr11ZFpxC8hkizopo4NOyH/vqbulbOu rdlNSg+oyYb6gfq8TWjw6/yXLgi3iCXCaCAO7IFEjEp9VimsRCNvL0N7I2Kk1ktdREiD PDWg/XXXH3CP+9OC3ItVUrBRBTB+cDQkxcgaHQs5/NCm1tIO0/1KOfunA5eqOciwdWeT qT0Q//axWssynyvmRZHZocIUW4Sjnk/RbZH9YJBbOK8saz3CIXUx0aS48rsVLffspaFm Q+XSMavjVNCvDgzVJDNkRdbo05w/3XiCa2/yW9Bbuv1v7kHj24oJyQlu3oqGNjsJX+Z8 WpPA== X-Gm-Message-State: AKS2vOzmAD4SfHmSJiwk/mxdZ8xJsaBEik1ml3eLKgOxnqzlj4A281q1 04INh3ST9sewvTJogcY= X-Received: by 10.28.238.213 with SMTP id j82mr4386538wmi.33.1498001455280; Tue, 20 Jun 2017 16:30:55 -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 w30sm17593338wrb.49.2017.06.20.16.30.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Jun 2017 16:30:54 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 21 Jun 2017 01:30:34 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v5 5/7] 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, 20 Jun 2017 23:30:56 -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/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/eal_common_bus.c | 15 +++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 12 ++++++++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 4 files changed, 29 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 3517d74..04fa882 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -202,5 +202,6 @@ DPDK_17.08 { global: rte_bus_from_name; + rte_bus_from_dev; } DPDK_17.05; diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index e69ce38..e9fbc03 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -231,3 +231,18 @@ rte_bus_from_name(const char *str) { return rte_bus_find(bus_cmp_name, str, NULL); } + +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); +} + +/* find a bus capable of parsing a device description */ +struct rte_bus * +rte_bus_from_dev(const char *str) +{ + return rte_bus_find(bus_can_parse, str, NULL); +} diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index da8b8a1..61d9e6e 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -283,6 +283,18 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev); struct rte_bus *rte_bus_from_name(const char *str); /** + * 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_from_dev(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 6607acc..a5127d6 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -206,5 +206,6 @@ DPDK_17.08 { global: rte_bus_from_name; + rte_bus_from_dev; } DPDK_17.05; -- 2.1.4