From patchwork Wed May 24 15:12:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 24505 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id BF58C7D3E; Wed, 24 May 2017 17:13:18 +0200 (CEST) Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45]) by dpdk.org (Postfix) with ESMTP id 5DE0B7CF8 for ; Wed, 24 May 2017 17:13:01 +0200 (CEST) Received: by mail-wm0-f45.google.com with SMTP id b84so67961973wmh.0 for ; Wed, 24 May 2017 08:13:01 -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=So+lXVXW0jFj+Dwe2zqHbdnfFFZq4jql7m0aJ9gt+6A=; b=Gyww5C9eStY1Dia/sVisCl+zqmzYoYJW8w7DCiDQUArp/PNI1PGqWpLdSF/zxvindC TW4nv+MjiwCxrMfFpPLH/XnAwoFUQuqe2vLX93Dk5iQ4WmhbBZiDNGjiO8Sfj+fgmf7L u4uMd4fW2KlWWnT7pI4vQJDvJOiYRYQYZBU1xuoMjGfeEGQoutSOTH4AHn1e+Ga3DdhC s2qfV4RvF5ZrFRk/pmOadmfh6UKYQEFQpijuMioVp6p8vGwgsq+vj5q1DEVI9fV6BuiR 3CYNRLY0Rt0fDjVsUbGa5Ah4vaTfG1z6w8ZH1x314rbJH79n18X429TyrqGcd9uxk4R1 tPoQ== 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=So+lXVXW0jFj+Dwe2zqHbdnfFFZq4jql7m0aJ9gt+6A=; b=sLdMKDsEQY56nKiccwJf9lZQXHbjtc7YONHeSXuu/V8VTY5tJbnTSuhE0Xvh2yUAyH YoRDzKYTCrRwEb5rgY/PML0X2phrT6jm/7NGp9ORy0fu6YeeYmmLymBfXXG+DoRcS4N0 ToQssNhMDS34MC6teTtD8UvujT4mYTc8wmcLEzODFKrxv8Md1LSwahKCZZ0Y9a2NIj4p 3XaweLjmt6HEabVPODMuPN34fArNxOyAWNDW8q5NYNPBV1h8GnN/VWLCjJRqLdbSnbXQ VLuIVeS4Xj9ULXJtJmlvS9mcDaDPE6v63/6FNIIxa8yjfDCFlDCniL8hF26czEzDSqtg Br+g== X-Gm-Message-State: AODbwcB57CZ9SqDi90vk5Mo9zb0dhDB3I5tFXgwY3X3QEYwNvJacHgVp 8X8nCZJfl7/toVDa X-Received: by 10.28.210.13 with SMTP id j13mr6193562wmg.110.1495638780611; Wed, 24 May 2017 08:13:00 -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 9sm5633351wmh.17.2017.05.24.08.12.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 May 2017 08:12:59 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet , Jan Blunck , Stephen Hemminger , Maxime Coquelin , Jerin Jacob , David Marchand Date: Wed, 24 May 2017 17:12:39 +0200 Message-Id: <1a54f0dd79200960921ca495aa7381817a599bc0.1495629122.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 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 7977190..08fff60 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -242,3 +242,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)); +} + +/* 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 5b87ac4..0b48e66 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -251,6 +251,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 structure 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;