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 125A5532C for ; Fri, 30 Jun 2017 20:20:03 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id y5so9305292wmh.3 for ; Fri, 30 Jun 2017 11:20:03 -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=NpvOKAlRJos46VVwzY+MEIx6PMi16LCvrnfvjJi7BYg=; b=eqs8yxt1TleqhCF53Q/pVYdCL7GZbJUYEYDSWN45bpEmB6VkdMJs05NCNONDsxARVp jxbJmm0Qxw1oRdLAOKve0DJp1DVZkSBn0qwupC96LBio6KsdpL2i76P1DYaoViaNREFH kVI1afjaR7E4A8a9+y6DNIMlszhP7Q9fYRaGI1lY0svOQhllololVvhL6GWKE2kf/NDc xBe5rnakJoIfOnB2qv01yQKVHgUY/rdZXaO9s0zQOQ6sdAhLEYX5seZ2Tf/sKkb8xV/A 7ccZznk6OHur7HnGQk4R+HzOFMcvQ6HSE0hiAm7zIj14KtXxkJfnNiFNSFnnkuxoWmiB uTzg== 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=NpvOKAlRJos46VVwzY+MEIx6PMi16LCvrnfvjJi7BYg=; b=QEaF8T0gbESLgZx32/RklsrKVCXgonb5PwvZIWj7JxzyvAkzLfeSMn12+r02ucZVGz 5dqypsYf6j4CpE7mtiV/wRitBomDHGqEYUIujAHCIXv2MuhCi/33t4zF9Ahl0djdiS1Y T3NWFS7J8MFcD2KnX4LE3pBiWwu/s4QQ9B8Zk/STwWq3hfcQT10aL66dBQiLwNvEDNDN unq6N1j4FWNvlypIVEJJrIPSkgT6SqJo+RgS0W9QuJpxB1IffDcLLpz592Im19HM5CQb YdT5FiRyq1NocYIbPjVm3WxavAcXw0JR/cPHfVgcWrD7iFCufr0a/X83HYmo5HBANn/J fDdw== X-Gm-Message-State: AKS2vOyOO5FJo8HSpFJw8fW3z4n7yk1Ss052lKBDzBhDfEllBaUJt6qP TlVCUSVepGSrO8rD X-Received: by 10.80.180.4 with SMTP id b4mr6489045edh.103.1498846803419; Fri, 30 Jun 2017 11:20:03 -0700 (PDT) Received: from weierstrass.local ([91.200.110.13]) by smtp.gmail.com with ESMTPSA id r28sm2826940edd.33.2017.06.30.11.20.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Jun 2017 11:20:02 -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:31 +0200 Message-Id: <20170630181943.23929-3-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 02/14] bus: add find_device bus operation 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:04 -0000 This new method allows buses to expose their devices in a controlled manner. A comparison function is provided by the user to discriminate between devices, using arbitrary data as identifier. It is possible to start an iteration from a specific point, in order to continue a search. Signed-off-by: Jan Blunck Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/include/rte_bus.h | 27 +++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 21 +++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index c52b65b..052ac8d 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -82,6 +82,32 @@ typedef int (*rte_bus_scan_t)(void); typedef int (*rte_bus_probe_t)(void); /** + * Device iterator to find a device on a bus. + * + * This function returns an rte_device if one of those held by the bus + * matches the data passed as parameter. + * + * If the comparison function returns zero this function should stop iterating + * over any more devices. To continue a search the device of a previous search + * can be passed via the start parameter. + * + * @param cmp + * Comparison function. + * + * @param data + * Data to compare each device against. + * + * @param start + * starting point for the iteration + * + * @return + * The first device matching the data, NULL if none exists. + */ +typedef struct rte_device * +(*rte_bus_find_device_t)(const struct rte_device *start, rte_dev_cmp_t cmp, + const void *data); + +/** * A structure describing a generic bus. */ struct rte_bus { @@ -89,6 +115,7 @@ struct rte_bus { const char *name; /**< Name of the bus */ rte_bus_scan_t scan; /**< Scan for devices attached to bus */ rte_bus_probe_t probe; /**< Probe devices on bus */ + rte_bus_find_device_t find_device; /**< Find a device on the bus */ }; /** diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index de20c06..04d9c28 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -191,6 +191,27 @@ int rte_eal_dev_attach(const char *name, const char *devargs); */ int rte_eal_dev_detach(const char *name); +/** + * Device comparison function. + * + * This type of function is used to compare an rte_device with arbitrary + * data. + * + * @param dev + * Device handle. + * + * @param data + * Data to compare against. The type of this parameter is determined by + * the kind of comparison performed by the function. + * + * @return + * 0 if the device matches the data. + * !0 if the device does not match. + * <0 if ordering is possible and the device is lower than the data. + * >0 if ordering is possible and the device is greater than the data. + */ +typedef int (*rte_dev_cmp_t)(const struct rte_device *dev, const void *data); + #define RTE_PMD_EXPORT_NAME_ARRAY(n, idx) n##idx[] #define RTE_PMD_EXPORT_NAME(name, idx) \ -- 2.9.4