From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f181.google.com (mail-wr0-f181.google.com [209.85.128.181]) by dpdk.org (Postfix) with ESMTP id B9F3F968 for ; Mon, 26 Jun 2017 02:22:26 +0200 (CEST) Received: by mail-wr0-f181.google.com with SMTP id k67so131076392wrc.2 for ; Sun, 25 Jun 2017 17:22:26 -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=8T1DeRZ6hdjXFOkLiaN6RV/xkwnIpcBRaqQJdwls50c=; b=H21VfFouaAmUZscdkrMXJQVBy+XDAwHWAzd527ecZRok2vnsr7hrWFfz8oXK85qrpO 1fFj5or0+yC58utOU+gJiTAPfKzaZgn1J3rMRqwAp0ue+LrAWRCz5TSCPKspIq5uLJuc 4IuZRNGh7oAfeKJYikOwOpeds9iDeb0JXrPynycLPtqbxMs5UXF7Pp6eYTnJgYxdf3JA iuTPf4Qp14+AmSPU6neZ91ZaFLFbnSHtNt/3W/nIYAvQVHnae/IPWP1a/y3aS7Na3m4h dTgpcOdQ7/yOsnO3nt50BGAJu9mEkL8aTiApEXK5hNe3uz4XkWaEcLy6M7nrBR259V2j LwbA== 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=8T1DeRZ6hdjXFOkLiaN6RV/xkwnIpcBRaqQJdwls50c=; b=TFU+X7b7xFlw1Kw00zecg/CvLp7ulGiawfGJedrk27rj2jDFRLOeoEPb2vaH8rWagx ltMhO6GtppgHrHZ/aae//Zz8jEbI1kjsaYsBa2gCAQ092wicV/n52ieeMX1XgvR+5Lv4 3lfcj31XI/QnKN0sGW0bZ2OQ2oleX3Ct0n1SsM5qXyLFpgaElwDVQ63sTXnMmBQMF/Qx tBlERnSi9IDNJEfCEwe/fbXjSJh8V2L4tQ6Rj9qYgJ8GbT2fVL1yk6opQ96fGK83JMlI hoQbac1GKzCpTWx4byVcqraMEJZTgbSHOwDCpdfbucIHMnq9aTpXBnonU0VBOS9cWI/U t+xA== X-Gm-Message-State: AKS2vOzVl2EKXXTrVEvPxKf08Mgcr/7DCRwp5wmUPqSdV6E8FAMk1EXH BH+FUQ8OJXB0osV3AKo= X-Received: by 10.223.162.208 with SMTP id t16mr13218809wra.151.1498436546070; Sun, 25 Jun 2017 17:22:26 -0700 (PDT) Received: from bidouze.dev.6wind.com ([62.23.145.78]) by smtp.gmail.com with ESMTPSA id 19sm16061626wrx.26.2017.06.25.17.22.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 25 Jun 2017 17:22:24 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck , Gaetan Rivet Date: Mon, 26 Jun 2017 02:21:59 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v5 01/12] 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: Mon, 26 Jun 2017 00:22:27 -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..4619eb2 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 started = start == NULL; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + if (!started) { + if (bus == start) + started = 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