Message ID | 20211115142243.60605-3-paul@crapouillou.net (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
Series | iio: buffer-dma: write() and new DMABUF based API | expand |
On Mon, Nov 15, 2021 at 4:23 PM Paul Cercueil <paul@crapouillou.net> wrote: > > Handle the IIO_BUFFER_DMABUF_CYCLIC flag to support cyclic buffers. > Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com> > Signed-off-by: Paul Cercueil <paul@crapouillou.net> > --- > 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 fb39054d8c15..6658f103ee17 100644 > --- a/drivers/iio/buffer/industrialio-buffer-dma.c > +++ b/drivers/iio/buffer/industrialio-buffer-dma.c > @@ -933,6 +933,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 85e55fe35282..27639fdf7b54 100644 > --- a/include/linux/iio/buffer-dma.h > +++ b/include/linux/iio/buffer-dma.h > @@ -42,6 +42,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 > */ > @@ -65,6 +66,8 @@ struct iio_dma_buffer_block { > */ > enum iio_block_state state; > > + bool cyclic; > + > bool fileio; > struct dma_buf *dmabuf; > }; > -- > 2.33.0 >
diff --git a/drivers/iio/buffer/industrialio-buffer-dma.c b/drivers/iio/buffer/industrialio-buffer-dma.c index fb39054d8c15..6658f103ee17 100644 --- a/drivers/iio/buffer/industrialio-buffer-dma.c +++ b/drivers/iio/buffer/industrialio-buffer-dma.c @@ -933,6 +933,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 85e55fe35282..27639fdf7b54 100644 --- a/include/linux/iio/buffer-dma.h +++ b/include/linux/iio/buffer-dma.h @@ -42,6 +42,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 */ @@ -65,6 +66,8 @@ struct iio_dma_buffer_block { */ enum iio_block_state state; + bool cyclic; + bool fileio; struct dma_buf *dmabuf; };
Handle the IIO_BUFFER_DMABUF_CYCLIC flag to support cyclic buffers. Signed-off-by: Paul Cercueil <paul@crapouillou.net> --- 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(-)