From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by dpdk.org (Postfix) with ESMTP id 7950F2BE1 for ; Thu, 29 Jun 2017 20:22:27 +0200 (CEST) Received: by mail-wm0-f65.google.com with SMTP id p204so4072189wmg.1 for ; Thu, 29 Jun 2017 11:22:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Jxiu7r182sPr/ThENemV7TEZ6lFCcQDuytHDqEYAPb0=; b=Yj/VPhaUMQEwKOvuBj2zmqnKTSv8CTcxa9C08K5wjKayYqz0HHxcgBM21IsY3Sd2AO WvLFlAOMFtuWyiM/n5gIcFwkQG+25RWNA/YcglrZEKVEHpjN95jG5Ryi5l4tlM8/JQHE nohMODnfjpRLJyDwK33cO6rkUKQtH7S8Ow896BazWdbOi6J9s1HOEFtpYYm+pZAtYjWa /yf+SD/6ZrmPuNmDq1zxnjbp3SxyCGtUwrMGXHzInKsa0kvLxsYnAPu9mWu2UyjwO4ar 5R2/lK4AsvGKqpCK1bsswQpJdtWuSQgY9x4VETxXQwYd3SX9TgRNMaNvmFQn1V4b68mN +wKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Jxiu7r182sPr/ThENemV7TEZ6lFCcQDuytHDqEYAPb0=; b=Z9bG7u2yK09KTXsZZZKIoNTI7mTD4q+7Y6UOQUiIiECNiCcK8u5GY+v4Qi5mreqOKg 5fSm0TngFMJGRv39M/M35ONKzt0DVePrPNeSXxv/3Oo8PEi4RA2twwmaF/yHwdI4vMvR Cpd+ljkOeiB3K2MtgwaC15Z9K2pQEDRZUFU9F8ZhOlqcvbJoU/siQ+HSLLO46+wcAYeX oUaatH8lS79hVy3WH9gGJvYK+N30dcsu+FX+ggajPBEN8rKYpIhdAOfMerJmfZOAHmBh iwprgM3a/YbnCX+YuIXqod77NiieWkHK5+kmwL2Ypk21Rdl+LISuwtN0mezBWcc1A7lk jxsw== X-Gm-Message-State: AKS2vOz5tnLNjVF/ntpGCmy3FnR2/dobbUHbEUHIfSkJLK+R06tfBGqD V3KNFdD1YQs8gp3o X-Received: by 10.80.170.23 with SMTP id o23mr2667235edc.164.1498760546946; Thu, 29 Jun 2017 11:22:26 -0700 (PDT) Received: from weierstrass.local ([91.200.110.13]) by smtp.gmail.com with ESMTPSA id e28sm1446366ede.14.2017.06.29.11.22.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2017 11:22:25 -0700 (PDT) Sender: Jan Blunck From: Jan Blunck To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, shreyansh.jain@nxp.com Date: Thu, 29 Jun 2017 20:21:52 +0200 Message-Id: <20170629182206.1072-2-jblunck@infradead.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170629182206.1072-1-jblunck@infradead.org> References: <20170629182206.1072-1-jblunck@infradead.org> Subject: [dpdk-dev] [PATCH v7 01/15] 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: Thu, 29 Jun 2017 18:22:27 -0000 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 | 19 +++++++++++ lib/librte_eal/common/include/rte_bus.h | 42 +++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 4 files changed, 63 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..3094daa 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -145,3 +145,22 @@ rte_bus_dump(FILE *f) } } } + +struct rte_bus * +rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp, + const void *data) +{ + struct rte_bus *bus = NULL; + bool start_found = !start; + + 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..c52b65b 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -141,6 +141,48 @@ 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 start + * Starting point for the iteration. + * + * @param cmp + * Comparison function. + * + * @param data + * Data to pass to comparison function. + * + * @return + * A pointer to a rte_bus structure or NULL in case no bus matches + */ +struct rte_bus *rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp, + const void *data); + +/** * 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.9.4