From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by dpdk.org (Postfix) with ESMTP id 440071B53 for ; Wed, 31 May 2017 15:18:14 +0200 (CEST) Received: by mail-wm0-f42.google.com with SMTP id b84so118889203wmh.0 for ; Wed, 31 May 2017 06:18:14 -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=88aQ+rYi14Af3hyZNy0Jseb8c018+yuyHDtmvdtgJKE=; b=UaC3+Y96Acb6H3HrWqvY7oyzxkvT22XAClydJME7l8DDc7h+7cNnbeo1cQ3oMcm0rp +R3gfn5QnaIBqX8YNOucnbm5bb06p/ZdoknJLfekK8wsrU5Mu+uDHrp4fM5uwrTgvSe7 4KvjjVuL7dkaIa5pWSVPLBieySKzUNE4XlxZGrY+6iiHaE4LwCrXfepMul5dKyWtOlPX sLsYO9uQVvlaP2fFbMr6s/elabfwmdivGOwUm7K3OHk86XK9uodbKqrFGhpfIGo4rsML RD6vPQ8rrECvD4zyj7HyBup2d737HNLdb6BtW79G6p8pIepQjo9qwkVCSwhsiXZh8ktv BdSg== 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=88aQ+rYi14Af3hyZNy0Jseb8c018+yuyHDtmvdtgJKE=; b=NK3Y0z48P0djGpGJ2QTuy8RSXcMXbG/KXH9Ik7BNfiGDEFdLNYEFTJyi11YULl+oR1 IoRNyvdBZtJ90vSultUvYyfyd6UCLy8aejV+0NIuDSyQ1SumuRmMQ58Q4V4cV7mEUlNc womffo0HL2JzuJLPAAdzGnYmCyYZjwovgjmnBAigdxkXSnJrcLqz+HuL93iph2DjfxKe CpFMNAu5WdwslBkMpT4YUjC0wyUys1QhfRPSL4KmC/SIkyYCAmcz+uxV2VJH/2y8/c/z oJbOU+fesGuCHBs90pUX12KDCBXssD8vI8fiyxZGB4nixetkbldo0WAtAoOrRoczGbpA A2Qg== X-Gm-Message-State: AODbwcDba0bMj9pUVIG0+ZBKjB5QHVJs+K2/O868XjPuQvBeOp4nfH/a 3Mg8N25lCQVO4tVRduU= X-Received: by 10.223.154.15 with SMTP id z15mr13115881wrb.136.1496236693621; Wed, 31 May 2017 06:18:13 -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 g77sm10045744wmd.19.2017.05.31.06.18.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 May 2017 06:18:12 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck , Gaetan Rivet Date: Wed, 31 May 2017 15:17:49 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2 04/11] 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, 31 May 2017 13:18:14 -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 811aff3..632a6e7 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -182,3 +182,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_match_t match, 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(match, 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 0664662..b56018f 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -180,6 +180,29 @@ typedef int (*rte_bus_match_t)(const struct rte_bus *bus, const void *data); struct rte_bus *rte_bus_find(rte_bus_match_t match, 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 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, + rte_dev_match_t match, 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