From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id 89E812BE1 for ; Fri, 30 Jun 2017 20:20:02 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id y5so9305217wmh.3 for ; Fri, 30 Jun 2017 11:20:02 -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=w0ooDcjsMckwOhbtc3MoL0i60Ef85RTwJUdG7KX7aAc=; b=qDUTiWpOn82edghJVdXsO5/OvSr+wu8zOB/WU5hrZIP1S8ap07HbXepA5+ua3SJ/cg GRWYJH7GZmrUJTkhAJov+s43DBdlSFagF8NGrTavw3ZDZJB4QAxxAL7JsW9OKaAR0o15 LJJ0cCwgX2FTDXLovFYHROUZLn9xzJGEKMho69Z9hrjeBqblEQB90qTx6oGJErXm8+4x 9O1z3BJsAa5jnVv+b4dYICfdFLJdk+SdkzxMm8tpdcwWtC0AVACZ6uLTtvCjN6XOt0SB ApxgGGfmvzg7l3SR+oNEdnK70oQEOav8NKrIGVIDAtbeZolaw6Ti30RTx1DIqzQ+pVfW VF4A== 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=w0ooDcjsMckwOhbtc3MoL0i60Ef85RTwJUdG7KX7aAc=; b=d8nhCOhYfBEJRKjkS9/3UlTxxNPhV0Dzk8PU2NUepuED/rVxVKOlOUtsjixCJiuaKo rkUVXtnAtheszheXPIcs+8I8rsvkm4WgySlA5+I7dor55MvkV5mVa89lyUyVh+x/sH7T l6G9eFWYkFcPBJdMBwx6msJrsA83rYaIk5kOAGOjDXLikTaDf3hsdYbgvFYQlejjIEZ/ slbeW8HcS50shGpRT6bQ5O6H83qo4IKFjygrDtuxuD6SwgVvD1Y52F1X4bgHuFzgQVjX 0wLFPT7qNpxrDNIyitIteXVhjj+2sPhe/VcAxthHxsDPoUQD9mqiIcc3b30eXrl0wlxS Cx7g== X-Gm-Message-State: AKS2vOxMjlSxBS3YA25u/dRwacD7aeW9vvQjsYlalCsHoIQmHoqFxVy8 Q3vksuGmrcfMqbRT X-Received: by 10.80.168.70 with SMTP id j64mr4395190edc.110.1498846802099; Fri, 30 Jun 2017 11:20:02 -0700 (PDT) Received: from weierstrass.local ([91.200.110.13]) by smtp.gmail.com with ESMTPSA id r28sm2826940edd.33.2017.06.30.11.20.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Jun 2017 11:20:01 -0700 (PDT) Sender: Jan Blunck From: Jan Blunck To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, shreyansh.jain@nxp.com Date: Fri, 30 Jun 2017 20:19:30 +0200 Message-Id: <20170630181943.23929-2-jblunck@infradead.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630181943.23929-1-jblunck@infradead.org> References: <20170629182206.1072-1-jblunck@infradead.org> <20170630181943.23929-1-jblunck@infradead.org> Subject: [dpdk-dev] [PATCH v8 01/14] 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: Fri, 30 Jun 2017 18:20:02 -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 | 7 +++++ 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 | 7 +++++ 4 files changed, 75 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..edf9d7d 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -193,3 +193,10 @@ DPDK_17.05 { vfio_get_group_no; } DPDK_17.02; + +DPDK_17.08 { + global: + + rte_bus_find; + +} DPDK_17.05; 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..944416e 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -198,3 +198,10 @@ DPDK_17.05 { vfio_get_group_no; } DPDK_17.02; + +DPDK_17.08 { + global: + + rte_bus_find; + +} DPDK_17.05; -- 2.9.4