From patchwork Fri Dec 1 20:46:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mfornero@gmail.com X-Patchwork-Id: 10087993 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3E8736035E for ; Fri, 1 Dec 2017 20:46:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 316C42A6F4 for ; Fri, 1 Dec 2017 20:46:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 265212A70B; Fri, 1 Dec 2017 20:46:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD2AD2A6F4 for ; Fri, 1 Dec 2017 20:46:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750968AbdLAUq3 (ORCPT ); Fri, 1 Dec 2017 15:46:29 -0500 Received: from mail-qk0-f196.google.com ([209.85.220.196]:34431 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750881AbdLAUq3 (ORCPT ); Fri, 1 Dec 2017 15:46:29 -0500 Received: by mail-qk0-f196.google.com with SMTP id d66so14835603qkg.1 for ; Fri, 01 Dec 2017 12:46:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=66c81LIbfDXopwbTgzkdVrIK/RUtD9meZ2Dn9yZyzCA=; b=miTHbdMh44HYbVo50TUsR8tIo2W3wWqppoD6TMN3wLIb2jttl+A0poMz++rT6F/ia6 um8ytzgNNC+pL/8P5VRM6PTRpm3Iopjv5Wp5gA6Ymzya+mOzcO0a3iZqyhPiJvVFlF8B U826qt5ubdGd2+U1agnEcMwFSDqjsjt2RyxPk8cWLDqQjR+8wz9OJpWT9ZCG0DdO0Se0 Q1yG8kfLNHWJnZOq1VIZD2E+JlVUfjMKtlgqGrylk6J9evNstuYeM+uB7HYUpVhCPWFD vNb4+RYT5Hw6elfhpKJbMibgGeFcbFlcMef6xyzSraojEbP7Dbm6cnTy0ymtAin9E6vT gPMQ== 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; bh=66c81LIbfDXopwbTgzkdVrIK/RUtD9meZ2Dn9yZyzCA=; b=HJdWa9Pagk/gnVl7Eeti854XnJREt9VYikXJQ5NcF8TApzYAnSOdP1i1yvFLz6diys nExS1zjGj9by6C3zhiDbOxnW/otXDmUahY2246+MilndAMOBEGaogWBUiRC66W3eVtPN gjFJCInxD5fDnmFc34NyqSlrqSc63KuPFaPsSzbxD0/2XeluxhF3HJ3KxO+r9TRtsWuN XHjXeiNpHApQdnBIZevmDbcaryJcuXc3S/vwaBuLTAwYJTJfMrPbIy5h52t+Rp2oizX0 eJ3SKO4ldB7vi7OqK6zBYHi5Dhge+UOm6fOyjTG2t08KQ6XJ/I7sO7hoKDIHP8rzV7eV xoiQ== X-Gm-Message-State: AKGB3mInS+/ilUm0uG2CnsXh8nYqeiRZiYqeRLhDBOEJyEMI2X1Hwacz JRWSTMSBrlPfeKui4szBKXTPuTeBG3A= X-Google-Smtp-Source: AGs4zMY+DMp8vXpD5kgBo5vWkIyX4EOu9EMOIX+aIHCmo4KgE+mZ62YaP2a6EwKi5YJdb1cY7kkKtg== X-Received: by 10.233.216.70 with SMTP id u67mr10328992qkf.133.1512161188138; Fri, 01 Dec 2017 12:46:28 -0800 (PST) Received: from mfornero-deb8-64.mathworks.com (ext.mathworks.com. [144.212.3.4]) by smtp.gmail.com with ESMTPSA id 33sm5370235qts.76.2017.12.01.12.46.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Dec 2017 12:46:27 -0800 (PST) From: mfornero@gmail.com To: linux-iio@vger.kernel.org Cc: Matt Fornero Subject: [PATCH] iio: buffer-dma: Expose data available Date: Fri, 1 Dec 2017 15:46:20 -0500 Message-Id: <1512161180-30116-1-git-send-email-mfornero@gmail.com> X-Mailer: git-send-email 2.1.4 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Matt Fornero Add a sysfs attribute that exposes the buffer data available to userspace. This attribute can be checked at runtime to determine the overall buffer fill level (across all allocated DMA buffers). Signed-off-by: Matt Fornero --- drivers/iio/buffer/industrialio-buffer-dma.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/iio/buffer/industrialio-buffer-dma.c b/drivers/iio/buffer/industrialio-buffer-dma.c index ff03324..8739a41 100644 --- a/drivers/iio/buffer/industrialio-buffer-dma.c +++ b/drivers/iio/buffer/industrialio-buffer-dma.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -599,6 +600,28 @@ int iio_dma_buffer_set_length(struct iio_buffer *buffer, int length) } EXPORT_SYMBOL_GPL(iio_dma_buffer_set_length); + +static ssize_t iio_dma_get_data_available(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + size_t bytes; + + bytes = iio_dma_buffer_data_available(indio_dev->buffer); + + return sprintf(buf, "%llu\n", (unsigned long long)bytes); +} + +static IIO_DEVICE_ATTR(data_available, S_IRUGO, + iio_dma_get_data_available, NULL, 0); + +static const struct attribute *iio_dma_buffer_attributes[] = { + &iio_dev_attr_data_available.dev_attr.attr, + NULL, +}; + + /** * iio_dma_buffer_init() - Initialize DMA buffer queue * @queue: Buffer to initialize @@ -615,6 +638,7 @@ int iio_dma_buffer_init(struct iio_dma_buffer_queue *queue, iio_buffer_init(&queue->buffer); queue->buffer.length = PAGE_SIZE; queue->buffer.watermark = queue->buffer.length / 2; + queue->buffer.attrs = iio_dma_buffer_attributes; queue->dev = dev; queue->ops = ops;