From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f170.google.com (mail-wr0-f170.google.com [209.85.128.170]) by dpdk.org (Postfix) with ESMTP id 9A3E83252 for ; Thu, 8 Jun 2017 01:56:29 +0200 (CEST) Received: by mail-wr0-f170.google.com with SMTP id v104so12027596wrb.0 for ; Wed, 07 Jun 2017 16:56:29 -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=bseh4798LG+FZrmUvAjSWzVz6tOe+cZXD9DX5M2rqD8=; b=dFGPSgboR1LhwCseO2aDMktpVr7sUKoIXYRFKcTM7mz+5F0V7CKNlpgymcUe4VbMLA mVQrOtmaF+y/3T4tED0LC9y0fPvWSwmpNlNUwJnu0tVNiPHD7oXRbIFRMHXSfg4slzkv jKi5x8AiZOF1nPGEqznFJOUo+SR8Frf5GfMJvqwo7O9EDvPYkJNyX+uLW36qTx23zgwF tSE17z8s5/bYJcNQa3Qv2WS//faqxh1VRQVorY5feWrcUlor5XYcElIA96QrGPrOvR/D GSv6JQb+ClOkQ1aWUPlvXXoMsESHdb3XsOqRdLuXT7AOubucKiyNUnIzuTltUh3bZW6P ZTgg== 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=bseh4798LG+FZrmUvAjSWzVz6tOe+cZXD9DX5M2rqD8=; b=lTdPoyoZbu/W2iB1TmEoxXURNxu84MLGoxXi2DfrK0ijsKndoEPIxgD3CMyrGjDojn v2IzwXukRcd6H897orNJ+e4J/IT3h5tJqVmVUsum1PNyIbHyUxZFgbreO3+Eqwe6k1Px xgKW/ASagJ6Fgc4mDaRb+UTGb23sqn/MQUJM53XJM0KR71iqZ6hBI/QH3Ve0k2t5TspR 4kQgYyHP64s+3cVLVZLlM9wp1obD+k9fC9I8m2JK0VI2a3P5xP0VLd0UTAL/o5iwrrLX ZGINO+tedHZoW2HRXCeVnAE+Btvb2Hivzr47ZWyQHiYq11vVvLr3Ze/7C4c3e19BX6Al mr2A== X-Gm-Message-State: AODbwcBa3TqmJ+Dp4h6iVp99drIoO88XFWYOCvb7uh0524tlqClaxKBO 75X8LaxBATNoUqcULOY= X-Received: by 10.223.172.145 with SMTP id o17mr15721521wrc.181.1496879788987; 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.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Jun 2017 16:56:28 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 8 Jun 2017 01:56:07 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v4 7/9] 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: Wed, 07 Jun 2017 23:56:30 -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 2b41ba2..bad1bd9 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -239,3 +239,18 @@ rte_bus_from_name(const char *str) return NULL; return rte_bus_find(bus_cmp_name, str); } + +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); +} diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index b236893..4bed780 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -276,6 +276,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