From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f54.google.com (mail-wm0-f54.google.com [74.125.82.54]) by dpdk.org (Postfix) with ESMTP id 0133F2C8 for ; Tue, 27 Jun 2017 18:11:33 +0200 (CEST) Received: by mail-wm0-f54.google.com with SMTP id i127so31942981wma.0 for ; Tue, 27 Jun 2017 09:11:33 -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=NHMbh0mibmE+YZVMh5UZm3Z3PJ0PLudMvCg+9nQ5OFg=; b=hI8WTBN0qGJIsu1bXvk+ihicrYnQAZQDa2jSQUMTo3xSikJHE9nlZdJx1JshtGOQxM 4GX6PIhnKrAWqQXjtsJvWkXggTLyS65dj5qxW/pl94x3eWz5MApyheujse0FeOrfymd7 SD+1Z4hBaMvtEFvxS3E1s87/vVWr/HQnr0AFcVJltLYIFoXYaUXodM4KX4IRcwoqRH2G q5ZYIEcdsdfbMxMSAJlcwS2JiatFlI+vB0ozABhO8D+UtkBqn1NSZxFder9FjGePDe6+ ySFB0y5a+Cpc/7AERAsTjX/ocPwiT71ks7iQPJkBCSWkn/cenrIwNLxAQ5Nld4INehnx xPyw== 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=NHMbh0mibmE+YZVMh5UZm3Z3PJ0PLudMvCg+9nQ5OFg=; b=sZBsmk6fjvJ8rvC0qzn7n2QoSAts0dwJmjvwdMt4y7sOsykqXu8loz5URK4Bo4Jkm3 SQlAHfQms63qnQAP/83RPwaQIt1TyJ8OY7JXQEGIVJR3tJnCt6UNr5CE+pM9jBA6Wqfb NZ7xc13sH/hYpzfwEKhqJy2voxAvKN8ZUEhaSQGGJ6sV0NV2+xj/NoU1Yin0VjlZFylE fVrZOxIhdu9KdUlx44DufjtmGDkxZK4xcQNVculwk4RJenNRVLCcNpPAp/fMPCnoaS9w 8SLCyfX1cWBiYc6gH8nYeTOZ5o6rByCFXezshR8WQDTJke4BQqrhOcJBRVeU5kwOweH1 RP4A== X-Gm-Message-State: AKS2vOyuUfPaMSjUUPDuiZioqRZ19BylZK37cPCXmWLrBFKMwI5Y/eRX A90X1tlh7DfYRGeBbO0= X-Received: by 10.28.63.132 with SMTP id m126mr4087014wma.125.1498579893256; Tue, 27 Jun 2017 09:11:33 -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 v13sm4080465wmd.5.2017.06.27.09.11.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Jun 2017 09:11:32 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck , Gaetan Rivet Date: Tue, 27 Jun 2017 18:11:08 +0200 Message-Id: <6953b4ffef892e69c915a58df97bcd18487a3135.1498577192.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 v6 01/11] bus: add bus iterator to find a bus 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, 27 Jun 2017 16:11:34 -0000 From: Jan Blunck This helper allows to iterate over all registered buses and find one matching data used as parameter. Signed-off-by: Jan Blunck Signed-off-by: Gaetan Rivet --- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/eal_common_bus.c | 20 ++++++++++++ lib/librte_eal/common/include/rte_bus.h | 43 +++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 4 files changed, 65 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 2e48a73..ed09ab2 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -162,6 +162,7 @@ DPDK_17.02 { DPDK_17.05 { global: + rte_bus_find; rte_cpu_is_supported; rte_log_dump; rte_log_register; diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index 8f9baf8..86a54d1 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -145,3 +145,23 @@ rte_bus_dump(FILE *f) } } } + +struct rte_bus * +rte_bus_find(rte_bus_cmp_t cmp, + const void *data, + const struct rte_bus *start) +{ + struct rte_bus *bus = NULL; + int start_found = !!(start == NULL); + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + if (!start_found) { + if (bus == start) + start_found = 1; + continue; + } + if (cmp(bus, data) == 0) + break; + } + return bus; +} diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index 5f47b82..ecf839b 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -141,6 +141,49 @@ int rte_bus_probe(void); void rte_bus_dump(FILE *f); /** + * Bus comparison function. + * + * @param bus + * Bus under test. + * + * @param data + * Data to compare against. + * + * @return + * 0 if the bus matches the data. + * !0 if the bus does not match. + * <0 if ordering is possible and the bus is lower than the data. + * >0 if ordering is possible and the bus is greater than the data. + */ +typedef int (*rte_bus_cmp_t)(const struct rte_bus *bus, const void *data); + +/** + * Bus iterator to find a particular bus. + * + * This function compares each registered bus to find one that matches + * the data passed as parameter. + * + * If the comparison function returns zero this function will stop iterating + * over any more buses. To continue a search the bus of a previous search can + * be passed via the start parameter. + * + * @param cmp + * Comparison function. + * + * @param data + * Data to pass to comparison function. + * + * @param start + * Starting point for the iteration. + * + * @return + * A pointer to a rte_bus structure or NULL in case no bus matches + */ +struct rte_bus *rte_bus_find(rte_bus_cmp_t cmp, + const void *data, + const struct rte_bus *start); + +/** * 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 670bab3..6efa517 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -166,6 +166,7 @@ DPDK_17.02 { DPDK_17.05 { global: + rte_bus_find; rte_cpu_is_supported; rte_intr_free_epoll_fd; rte_log_dump; -- 2.1.4