From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f175.google.com (mail-wr0-f175.google.com [209.85.128.175]) by dpdk.org (Postfix) with ESMTP id 2CC222C1A for ; Thu, 8 Jun 2017 01:53:43 +0200 (CEST) Received: by mail-wr0-f175.google.com with SMTP id q97so12005941wrb.2 for ; Wed, 07 Jun 2017 16:53:43 -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=WO0FOsENmoNztOEoZgibpHuc1cgAl8/t+5vkSQenmv8=; b=MQcJg6nUixpmt3R/FwKGZMmn+iWwd4BqRz0EewYp8Op3vKWUuqDIHJSAZoEozjdlGZ p1Sv01FqPNRf78p/bVQYz5ZHrGtNJ6NLnw75vDXHehO009YfuTJ9GW++8AAzdzqMndNe 8Dhjn19jHorAWeNOP9HZHnBkPRsdtdAT+Ylg6K8opqI6L+HhKTme6qhfakZ88dTwYIkt liVpXk04yaFSZ1fNPLIuhT4y7IOXFnEPRRIqZeOBSTtsIvV9y1zAVkx7a4PKrKiW0Etq Fp9eGy9faX4KZOV1fJ3M8r7b60z1V1qKELh93c2XH5Rxj3zU+fjqW6mAc0ynZyyICVmD bsvw== 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=WO0FOsENmoNztOEoZgibpHuc1cgAl8/t+5vkSQenmv8=; b=tFM5cft3A7y0z/8qlmuK9oSD0wIeoy8kyT179g4Z4PmpGLQ+/2OHLD7VWQ4z2UXTID Lh6iYa2cAneumuKbdQLIK7aW+eroTh9pNkGAjWjHX32UnpiXFf2TZlpLONAR3Ob4N+vS 6cqtDPDyt9Ihbxv9vRL1YwKUYUCKL5d8tDQt+EYwPHEVjq768hb3bokblqul2wrbp3Yr u/v2EbpLOGgb3AjmQLBQ34YliApDaF63dzEEBsElXRY4JgBrMCQsV8xlFhpd0wtYQZRz askNBcmkCFG+xywpopyT+KeGDUA7QTXsLUScx+piOK1r3JVdRepdUT5B/iQ5MjSIJof7 n8rA== X-Gm-Message-State: AODbwcCJs1xDgGn8OtR8V6X8kzVRp48L755350xKjzIxGn36rpqZGlHf SsFufQm45EG1xtPJmdE= X-Received: by 10.223.136.131 with SMTP id f3mr26967120wrf.151.1496879622609; Wed, 07 Jun 2017 16:53:42 -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 z23sm4589942wrz.0.2017.06.07.16.53.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Jun 2017 16:53:41 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck , Gaetan Rivet Date: Thu, 8 Jun 2017 01:53:18 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 04/10] bus: add bus helper iterator to find a particular device 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: Wed, 07 Jun 2017 23:53:43 -0000 From: Jan Blunck 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 | 25 +++++++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 23 +++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 4 files changed, 50 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index f1a0765..21640d6 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -164,6 +164,7 @@ DPDK_17.05 { rte_bus_find; rte_bus_find_by_device; + rte_bus_find_device; 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 42f1076..451884f 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -180,3 +180,28 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev) { return rte_bus_find(bus_find_device, (const void *)dev); } + +struct rte_device * +rte_bus_find_device(const struct rte_device *start, + rte_dev_cmp_t cmp, const void *data) +{ + struct rte_bus *bus; + struct rte_device *dev = NULL; + int start_seen = 0; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + if (!bus->find_device) + continue; + if (!!start ^ start_seen) { + dev = bus->find_device(cmp_rte_device, start); + if (dev) + start_seen = 1; + else + continue; + } + dev = bus->find_device(cmp, data); + if (dev) + break; + } + return dev; +} diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index b3bc6e8..eba407d 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -182,6 +182,29 @@ typedef int (*rte_bus_cmp_t)(const struct rte_bus *bus, const void *data); struct rte_bus *rte_bus_find(rte_bus_cmp_t cmp, const void *data); /** + * Bus iterator to find a particular device. + * + * If the callback returns non-zero this function will stop iterating over any + * more buses and devices. To continue a search the device of a previous search + * is passed via the start parameters. + * + * @param start + * Start device of the iteration. + * + * @param cmp + * Callback function to check device. + * + * @param data + * Data to pass to match callback. + * + * @return + * A pointer to a rte_bus structure or NULL in case no bus matches. + */ +struct rte_device * +rte_bus_find_device(const struct rte_device *start, + rte_dev_cmp_t cmp, const void *data); + +/** * Find the registered bus for a particular device. */ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev); diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index 6f77222..e0a056d 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -168,6 +168,7 @@ DPDK_17.05 { rte_bus_find; rte_bus_find_by_device; + rte_bus_find_device; rte_cpu_is_supported; rte_intr_free_epoll_fd; rte_log_dump; -- 2.1.4