Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1524314pxb; Tue, 8 Feb 2022 21:03:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzAcHiFXTscwtTXMuDkBl2GNFoKo765Qpx7nBjzNF9YsbhCokv0+eYeWw9ojpHEj4wGhfQ8 X-Received: by 2002:a05:6a00:1253:: with SMTP id u19mr511573pfi.8.1644383026323; Tue, 08 Feb 2022 21:03:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644383026; cv=none; d=google.com; s=arc-20160816; b=eIvcUi3dc87vgwpIRiB3ZhJxjy4htfL3Yzqr9WJDw8JLvvZ5YkhjnLU+iV3pHre6ua i1VT+9YnCPcMsVReNBEdbHwX5HMrVnMn1YMCcO6W9ei5bl5aK/zIuCMe19/a5EFy4F8Y y2V32I7CXvQMDLgvLXfs2LEFM7evqYgKcAdDOgG8qAv20L2AH6KNwnGuiFUK1NNsyHOK 763i9iwvBgqy7hlyYy18E6SDk/d5e6o+tzjdjFnOIh2vfQCKODCsqPjbp4hOsREdozgo k8X+/0fSHBwnqB6uhSG3UnopKSm5oSIsKCmXmqxDubCzPtt19kpBKXhtTbMG4lc5eQoe WvyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=5qxT38iNl/jPDPnjrQn2UU/4jKMoPHUmOBmZLE8Q3Ok=; b=yukSveALr+KG6OUA8R+yYwGkLzdtI7v7Ip3fLPavYUlXx66D9ewWSqdqEd3haM67AC Y4dxC6VSwCbXXHp8mjlvNLNZHoCyBbpnQNLUWdML/g7MB59HO4hTCQKSM4Q4rCY23+tu DoZ+kIudonG/e5U9382P7GKPlCHZ9kze6Cl3CGuxG2OUOcGm+1IM4DwiyFgvtwHSfcQ8 cgFlgDaKbGg5EdrU/IqKAp6Jf7uxfBl0gAG7cIUFW76EhnMdfMY1VDbHj1dMlEAY4Qsw uzxfr6J0iq1JBCT+48E612lke0rCKdrcoWoLNalgldXfjxjdzMQeOhg0LjWP4gKCW+/j WZag== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id y7si12687830pfw.370.2022.02.08.21.03.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 21:03:46 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D9C9EC03E929; Tue, 8 Feb 2022 21:03:34 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1448741AbiBGNMt (ORCPT + 99 others); Mon, 7 Feb 2022 08:12:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386354AbiBGNBt (ORCPT ); Mon, 7 Feb 2022 08:01:49 -0500 X-Greylist: delayed 124 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 07 Feb 2022 05:01:48 PST Received: from aposti.net (aposti.net [89.234.176.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD585C043188; Mon, 7 Feb 2022 05:01:48 -0800 (PST) From: Paul Cercueil To: Jonathan Cameron Cc: Michael Hennerich , Lars-Peter Clausen , =?UTF-8?q?Christian=20K=C3=B6nig?= , Sumit Semwal , Jonathan Corbet , Alexandru Ardelean , dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Paul Cercueil Subject: [PATCH v2 11/12] iio: buffer-dmaengine: Add support for cyclic buffers Date: Mon, 7 Feb 2022 13:01:39 +0000 Message-Id: <20220207130140.81891-1-paul@crapouillou.net> In-Reply-To: <20220207125933.81634-1-paul@crapouillou.net> References: <20220207125933.81634-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Handle the IIO_BUFFER_DMABUF_CYCLIC flag to support cyclic buffers. Signed-off-by: Paul Cercueil Reviewed-by: Alexandru Ardelean --- drivers/iio/buffer/industrialio-buffer-dma.c | 1 + .../iio/buffer/industrialio-buffer-dmaengine.c | 15 ++++++++++++--- include/linux/iio/buffer-dma.h | 3 +++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/iio/buffer/industrialio-buffer-dma.c b/drivers/iio/buffer/industrialio-buffer-dma.c index b9c3b01c5ea0..6185af2f33f0 100644 --- a/drivers/iio/buffer/industrialio-buffer-dma.c +++ b/drivers/iio/buffer/industrialio-buffer-dma.c @@ -901,6 +901,7 @@ int iio_dma_buffer_enqueue_dmabuf(struct iio_buffer *buffer, } dma_block->bytes_used = iio_dmabuf->bytes_used ?: dma_block->size; + dma_block->cyclic = iio_dmabuf->flags & IIO_BUFFER_DMABUF_CYCLIC; switch (dma_block->state) { case IIO_BLOCK_STATE_QUEUED: diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c index 57a8b2e4ba3c..952e2160a11e 100644 --- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c +++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c @@ -81,9 +81,18 @@ static int iio_dmaengine_buffer_submit_block(struct iio_dma_buffer_queue *queue, if (!block->bytes_used || block->bytes_used > max_size) return -EINVAL; - desc = dmaengine_prep_slave_single(dmaengine_buffer->chan, - block->phys_addr, block->bytes_used, dma_dir, - DMA_PREP_INTERRUPT); + if (block->cyclic) { + desc = dmaengine_prep_dma_cyclic(dmaengine_buffer->chan, + block->phys_addr, + block->size, + block->bytes_used, + dma_dir, 0); + } else { + desc = dmaengine_prep_slave_single(dmaengine_buffer->chan, + block->phys_addr, + block->bytes_used, dma_dir, + DMA_PREP_INTERRUPT); + } if (!desc) return -ENOMEM; diff --git a/include/linux/iio/buffer-dma.h b/include/linux/iio/buffer-dma.h index 5bd687132355..3a5d9169e573 100644 --- a/include/linux/iio/buffer-dma.h +++ b/include/linux/iio/buffer-dma.h @@ -40,6 +40,7 @@ enum iio_block_state { * @phys_addr: Physical address of the blocks memory * @queue: Parent DMA buffer queue * @state: Current state of the block + * @cyclic: True if this is a cyclic buffer * @fileio: True if this buffer is used for fileio mode * @dmabuf: Underlying DMABUF object */ @@ -63,6 +64,8 @@ struct iio_dma_buffer_block { */ enum iio_block_state state; + bool cyclic; + bool fileio; struct dma_buf *dmabuf; }; -- 2.34.1