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 2A3417CE1 for ; Wed, 24 May 2017 17:05:40 +0200 (CEST) Received: by mail-wr0-f181.google.com with SMTP id l50so56706691wrc.3 for ; Wed, 24 May 2017 08:05:40 -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=UkghQBgt5H7zbyydyUT4OYhDN8ZXzn0OFnYjeJU6++0=; b=ZfDWUFUWEa5OquzBBMOOHNyGsrmvSaHHKcR75gtw7QCaKkoSKBRmKiyVrbmY1PqFmI aYsUS4RwAfXEeh6pGR1k+coPbhkbLjjHqfGvwFwBl1IbcVfH2oUScfBtXa+6kaWhHpNg NGy22YtdmTGdy3H3elYjhVGbHomtMfYmarNPeEm1iSiHBq38WcTfCYtG1lJs8jzros1V c3PBRVf6ruMMse4FQ93OPeaCVh9ax8nFSTIVGke7m52K9ujL4VrqFPx07DOQhDuOHMKc vXeqYoIFSDDEkS9ke345fh9wQSDl6kBsa8WS4l9gP/NVVgNcPBxeyfR6wJKIleX1WF6R NIiQ== 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=UkghQBgt5H7zbyydyUT4OYhDN8ZXzn0OFnYjeJU6++0=; b=fb1/KnVNac9hvFXvbrGDyOIhapHvUhdU27V1gPShMDgrKFRGleHhyOJlZBv94r0JP/ MWfvrjDsB6PqHFzMe1JP7Cp/Hw6K+VaT91IH663VXy2bRUEtNkcPa5m3h9r8X++PdVMd ERX7wEZgl7g2NRDCTYCvMjoylx88v5shv2BoJ5dZ34eq1piVzcmOgZT8hhL3IjwWSbZp oQ29fhLrZmOioA5MdT7PC77Void9+qBdZNuhAHIZN+/5f6csCKn6RREPtAR7cS4B7LP3 5UJVI52WxAwF/RlKlx5aTV2VAP3ablZE47KQh2l4M2u0Wv2gpByhIqbRsMyzJVQwilFi Tv6w== X-Gm-Message-State: AODbwcAQqQMYdyrR6X2Ig7aITD0tD8o0QjxuAmW0WlE1ezu65LV01YVU lyHERhcojP+t1wpmuf4= X-Received: by 10.223.150.179 with SMTP id u48mr19938156wrb.195.1495638339523; Wed, 24 May 2017 08:05:39 -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 25sm4076017wrz.8.2017.05.24.08.05.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 May 2017 08:05:38 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck Date: Wed, 24 May 2017 17:04:56 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH 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: Wed, 24 May 2017 15:05:40 -0000 From: Jan Blunck Signed-off-by: Jan Blunck --- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/eal_common_bus.c | 26 +++++++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 26 +++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 4 files changed, 54 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 97bcd65..b8f8384 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -182,3 +182,29 @@ 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, + int (*match)(const struct rte_device *dev, const void *data), + const void *data) +{ + struct rte_bus *bus; + struct rte_device *dev = NULL; + + if (start) { + bus = rte_bus_find_by_device(start); + if (!bus) + return NULL; + } else + bus = TAILQ_FIRST(&rte_bus_list); + + while (bus) { + dev = bus->find_device(match, data); + if (dev) + break; + + TAILQ_NEXT(bus, next); + } + + return dev; +} diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index 1707a1f..3b22fb8 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -169,6 +169,32 @@ struct rte_bus *rte_bus_find( const void *data); /** + * Bus iterator to find a particular device. + * + * The callback function should return 0 if the device doesn't match and + * non-zero if it does. 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 match + * 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, + int (*match)(const struct rte_device *dev, const void *data), + 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