From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f182.google.com (mail-wr0-f182.google.com [209.85.128.182]) by dpdk.org (Postfix) with ESMTP id A0E2237B7 for ; Wed, 21 Jun 2017 01:29:51 +0200 (CEST) Received: by mail-wr0-f182.google.com with SMTP id r103so111471597wrb.0 for ; Tue, 20 Jun 2017 16:29:51 -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=CyE2rSKYm5L7QQRANnDJgfNWmJ52pbg/MPhrj7E/R3A=; b=lgv2QbxwTLQ/iF8B6+P+NVvjHS2oyJx4p/a0nmueIHYc3aGP3NZzYc7MUcVvyKTuSL 3a0tK7vbR8wB2buOOBaydW6ReC7N2ucqRO787ii5ouFDLf6zIZp3nps/GuBLtyZVasFK WttYQJASczZOveZvINH31Pz5b5VFfIW7/Eoh+3gUgUSwacOA9WCkuPLHi6D7K7GC4wRs mbnTvTtNM9P/TLJkmOTXRBIiFvIkmIWBNKaJzcrg1qpy5FPmkvEB0MkDrjC6eq3zAmzB iz26WUCoLgDX8kXp5HQBgorUPKQJ3PQxysvs1yqctYawsqFAea5aqN2qe3Fsr8sQrf3Z FUZg== 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=CyE2rSKYm5L7QQRANnDJgfNWmJ52pbg/MPhrj7E/R3A=; b=PVATG/pjaVZk+jPJICFUXoEKeX3oOtId6zFiPcrJEeXms1G9CgVaV4GWFNZttLJvdK KGv6/h3bDpPZ1zMnCNu0vFNacQqkuG1iBiGg7+0SMzAKFMddpXxTtMeOKvIDlK9b7DaP gaq8CwkIcUnClH2N68oxNdpMXeltn3xhCkRNGV92sOHeuOTMKO8rCjoqIWkH6ULeLt1r 89yvmf3EjYKxC6QwK7dWCJXISW4FEkcI+O+7oz5AFXbaxQlrPC7etKP6GN9sNyh6lrS3 gZmN+28PRGMOYpa25+rzHH/tU7IhvyI60qR1RNomV3duY3tFOCpVgtU0z/hw66Vc824a kMaA== X-Gm-Message-State: AKS2vOwW1FCK0bwfS5mR5NWZQ7aVkz2IiHKDgno09nPB+Ki1NXG8ryx9 KeGvSff91Q+uF6t7DG8= X-Received: by 10.28.13.139 with SMTP id 133mr4723142wmn.82.1498001390694; Tue, 20 Jun 2017 16:29:50 -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 l127sm8592248wml.26.2017.06.20.16.29.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Jun 2017 16:29:49 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck , Gaetan Rivet Date: Wed, 21 Jun 2017 01:29:25 +0200 Message-Id: <82d275852b7179929081d005e62d458283d7b304.1497999601.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 v4 4/9] 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: Tue, 20 Jun 2017 23:29:52 -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 | 24 ++++++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 23 +++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 4 files changed, 49 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 a38b576..9d84727 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -189,3 +189,27 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev) { return rte_bus_find(bus_find_device, (const void *)dev, NULL); } + +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 started = start == NULL; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + if (!bus->find_device) + continue; + if (!started) { + dev = bus->find_device(cmp_rte_device, start); + if (dev) + started = 1; + 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 fa12f55..e078c00 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -189,6 +189,29 @@ struct rte_bus *rte_bus_find(rte_bus_cmp_t cmp, const struct rte_bus *start); /** + * 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