From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gaetan Rivet Subject: [PATCH v1 13/18] bus/pci: implement device iteration and comparison Date: Thu, 15 Mar 2018 18:49:43 +0100 Message-ID: References: Cc: Gaetan Rivet To: dev@dpdk.org Return-path: Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id BA9A8AADD for ; Thu, 15 Mar 2018 18:50:27 +0100 (CET) Received: by mail-wm0-f68.google.com with SMTP id t3so12031344wmc.2 for ; Thu, 15 Mar 2018 10:50:27 -0700 (PDT) In-Reply-To: In-Reply-To: References: List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Signed-off-by: Gaetan Rivet --- drivers/bus/pci/Makefile | 2 +- drivers/bus/pci/pci_common.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/bus/pci/Makefile b/drivers/bus/pci/Makefile index f3df1c4ce..73498dc77 100644 --- a/drivers/bus/pci/Makefile +++ b/drivers/bus/pci/Makefile @@ -50,7 +50,7 @@ CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common CFLAGS += -I$(RTE_SDK)/lib/librte_eal/$(SYSTEM)app/eal LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring -LDLIBS += -lrte_ethdev -lrte_pci +LDLIBS += -lrte_ethdev -lrte_pci -lrte_kvargs include $(RTE_SDK)/drivers/bus/pci/$(SYSTEM)/Makefile SRCS-$(CONFIG_RTE_LIBRTE_PCI_BUS) := $(addprefix $(SYSTEM)/,$(SRCS)) diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index 2c45f8151..482c96df2 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -497,6 +498,58 @@ pci_unplug(struct rte_device *dev) return ret; } +static int +pci_dev_match(const struct rte_device *dev, + const void *_kvlist) +{ + const struct rte_kvargs *kvlist = _kvlist; + + (void) dev; + (void) kvlist; + return 0; +} + +static struct rte_device * +pci_dev_iterate(struct rte_dev_iterator *it) +{ + struct rte_device *dev = it->device; + struct rte_kvargs *kvargs = NULL; + char *str = NULL; + + if (it->busstr != NULL) { + char *slash; + + str = strdup(it->busstr); + if (str == NULL) { + RTE_LOG(ERR, EAL, "could not allocate string copy\n"); + rte_errno = ENOMEM; + return NULL; + } + slash = strchr(str, '/'); + slash = slash ? slash : strchr(str, '\0'); + if (slash == NULL) { + RTE_LOG(ERR, EAL, "malformed string\n"); + rte_errno = EINVAL; + goto free_str; + } + slash[0] = '\0'; + kvargs = rte_kvargs_parse(str, NULL); + if (kvargs == NULL) { + RTE_LOG(ERR, EAL, "cannot parse argument list\n"); + rte_errno = EINVAL; + goto free_str; + } + } + dev = pci_find_device(dev, pci_dev_match, kvargs); + it->device = dev; +free_str: + if (it->busstr != NULL) { + free(str); + rte_kvargs_free(kvargs); + } + return dev; +} + struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_pci_scan, @@ -506,6 +559,7 @@ struct rte_pci_bus rte_pci_bus = { .unplug = pci_unplug, .parse = pci_parse, .get_iommu_class = rte_pci_get_iommu_class, + .dev_iterate = pci_dev_iterate, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list), -- 2.11.0