From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f174.google.com (mail-wr0-f174.google.com [209.85.128.174]) by dpdk.org (Postfix) with ESMTP id C37C22C8 for ; Fri, 7 Jul 2017 02:03:46 +0200 (CEST) Received: by mail-wr0-f174.google.com with SMTP id 77so24189532wrb.1 for ; Thu, 06 Jul 2017 17:03:46 -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=4zqLiHamSsL4Ktwv0MZKwfp7Cc5bM85HnHSwZoRilOg=; b=bNCpI917pWlAVXQcmcjv343eDaiTg1A+/wohDUAuCBcGIC7q4vmrrqiPBaY1q5Hg+8 hM160rq824UdVDM9KkuCj8C6d+88fJhQLqPC7pzqCjU789JPCvEnwkpyBOFxJ0jHdQH5 BShr1//w+WIhf/dfiJO+kjcKtzewoSczgmX071NMJFrzGvkA0r8fQR2BEwnTmtrEs+Th LGVmWbHtgbpJM5395YQacw3TmTTIr/r6L+Y0dwfJ95vimwm4fVwDtIzkfULZXH1ZMfBI j+54SbWCBiAhgpNSYxVzAJdm0zUPeMOuq/SUta+FEWuz396a/Vi4SSyak4tqBxaEmnPQ aSJg== 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=4zqLiHamSsL4Ktwv0MZKwfp7Cc5bM85HnHSwZoRilOg=; b=QPXwzPQDBcbUrZQVSbyJA2c/HVDa/fr6Jf7PM4402bXxV3rv1cWjwsYT1wU0hhSvtd JtgJlWYNdLQdpN17VVO2mcuOor28CCBxXlspfEpO+RdZwytMEjeJ6IRkT12ZAXGxvZPi xDR41eLNofNd4fqFP5NJAlSvSI0AsjoYj3N6TAM6FQhugc306GDCR7DTOwrQHdWMTBT6 KJav1xlOOe3mlvzXaWl8HEZkOse5IC/qoBy43Qz2GfWfBuflrEJhXfzs4i8SOsr39f2j 1jl/vzkDZqUN+0YMF6RKNlH9h9jUIL+dYL1J4+BanWLc6dJ2rpJNa/q1zMUJm0uMO3a2 bWkA== X-Gm-Message-State: AIVw113RUTqY1Y142mHxcQ/B8tmpx+vALM47fcCFVo/slnv4kfN06kZ5 amESZo1wsAQ1Z+FWH44= X-Received: by 10.28.198.1 with SMTP id w1mr227600wmf.78.1499385826101; Thu, 06 Jul 2017 17:03:46 -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 p7sm2364921wmf.11.2017.07.06.17.03.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 06 Jul 2017 17:03:45 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Fri, 7 Jul 2017 02:03:11 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 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: Fri, 07 Jul 2017 00:03:47 -0000 Find which bus should be able to parse this device name into an internal device representation. Signed-off-by: Gaetan Rivet Acked-by: Bruce Richardson --- 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 fd59b7c..4fc30bb 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[RTE_DEV_NAME_MAX_LEN]; + 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