From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id 427927D19 for ; Tue, 27 Mar 2018 01:19:14 +0200 (CEST) Received: by mail-wr0-f193.google.com with SMTP id z8so20510651wrh.7 for ; Mon, 26 Mar 2018 16:19:13 -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=6eZGoRLBzWwv3l2iaVF6qtwccKDlyB5ZmUHYY78ogm0=; b=QNMo7hsQCmiAnmo3XeuZ6zulc3AIdTn2yBX8oL0a00Ea73m61Mdw84nUBcGhgqCbAp Le62sJeZc9msCvPzmr0JBZGsSqmOPy4kmIthD31KYrJd53/LuQvCSK3SX0oGvfeK7gPa fYYZBmty/T+6ZeYoDzfqLWar467YG7aP67rxzdU2dJyGtyJqt68oBQiidlSml8ucT7Im fjjJELdhxLIPt5vd2Sy/7pZfEtm5IBlJtfdxEGZIbESRCWdqYlgMDudF8uc0rCh/Bh0J LSTWqPJryd9cPmMvSgzLVYWdalm4FT2vm3vyTb2RBa5AivS0FEBbDFpfZ+hnT95fhjsd ajGA== 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=6eZGoRLBzWwv3l2iaVF6qtwccKDlyB5ZmUHYY78ogm0=; b=je491Pvv4GiGGLOgId+Xje0BN5j7kVQXsi2cssncMFMO15JRcOspKP1DikMkFk5CsL HlFVS4MJfAcYTUYtd7zHY3RTWUY4sg+Wa3VTpl8BIfHL/naTw73bHcH+/CSk5dQV0gcC 4O79rJ9UUxYVyGVsdBEk9qabeNz0dz0YNrslib2CpyCAqA7g/sSnEJBom0gK8QRz8CUA wsXvDpvQy6eTjoj/ERGgyEzR0yId3nx3akXwAI0wrH0VloX86k5R9UF3h8arryDF2LTb OvonNd96HTCXQUI+JnFnB5ZLD5ZwzM//n3xp0nQny8r/iyiWRamL5XBtyKswod0w0YNa bgxQ== X-Gm-Message-State: AElRT7FvhPNbJwz0gswf/3H9rcUpDZU6r4Ufj1p5MP5CbOeToZkhpxIu 0ZJ9GS+fCdMJT29k3VdAq7lnHM5w X-Google-Smtp-Source: AG47ELtvSV/zsWJH9RTm2c6NKHBnpF/IlWYVaRsUY8t/m3MwZGmBc5GhybSscvlmFiqkWJ4uFvObiA== X-Received: by 10.223.133.182 with SMTP id 51mr30007391wrt.226.1522106353264; Mon, 26 Mar 2018 16:19: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 67sm343712wra.9.2018.03.26.16.19.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Mar 2018 16:19:12 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 27 Mar 2018 01:18:31 +0200 Message-Id: <05a44035858d241b32e172ae9077e3620ad3978d.1522105876.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 07/20] eal/dev: add device iterator interface 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: Mon, 26 Mar 2018 23:19:14 -0000 A device iterator allows iterating over a set of devices. This set is defined by the two descriptions offered, * rte_bus * rte_class Only one description can be provided, or both. It is not allowed to provide no description at all. Each layer of abstraction then performs a filter based on the description provided. This filtering allows iterating on their internal set of devices, stopping when a match is valid and returning the current iteration context. This context allows starting the next iteration from the same point and going forward. Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/include/rte_dev.h | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index b688f1efd..937ff6079 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -263,6 +263,53 @@ __attribute__((used)) = str static const char DRV_EXP_TAG(name, kmod_dep_export)[] \ __attribute__((used)) = str +/** + * Iteration context. + * + * This context carries over the current iteration state. + */ +struct rte_dev_iterator { + const char *devstr; /**< device string. */ + const char *busstr; /**< bus-related part of device string. */ + const char *clsstr; /**< class-related part of device string. */ + struct rte_bus *bus; /**< bus handle. */ + struct rte_class *cls; /**< class handle. */ + struct rte_device *device; /**< current position. */ + void *class_device; /**< additional specialized context. */ +}; + +/** + * Device iteration function. + * + * Find the next device matching properties passed in parameters. + * The function takes an additional ``start`` parameter, that is + * used as starting context when relevant. + * + * The function returns the current element in the iteration. + * This return value will potentially be used as a start parameter + * in subsequent calls to the function. + * + * The additional iterator parameter is only there if a specific + * implementation needs additional context. It must not be modified by + * the iteration function itself. + * + * @param start + * Starting iteration context. + * + * @param devstr + * Device description string. + * + * @param it + * Device iterator. + * + * @return + * The address of the current element matching the device description + * string. + */ +typedef void *(*rte_dev_iterate_t)(const void *start, + const char *devstr, + const struct rte_dev_iterator *it); + #ifdef __cplusplus } #endif -- 2.11.0