Re: [PATCH v6 09/17] iio: buffer-dmaengine: add devm_iio_dmaengine_buffer_setup_with_handle()

From: Nuno Sá
Date: Tue Dec 17 2024 - 06:47:01 EST


On Wed, 2024-12-11 at 14:54 -0600, David Lechner wrote:
> Add a new devm_iio_dmaengine_buffer_setup_with_handle() function to
> handle cases where the DMA channel is managed by the caller rather than
> being requested and released by the iio_dmaengine module.
>
> Signed-off-by: David Lechner <dlechner@xxxxxxxxxxxx>
> ---
>

Reviewed-by: Nuno Sa <nuno.sa@xxxxxxxxxx>

> v6 changes:
> * Rename from devm_iio_dmaengine_buffer_setup_ext2()
> * This patch now just adds the new function - prep work was split out
>   to a separate patch
>
> v5 changes: none
>
> v4 changes:
> * This replaces "iio: buffer-dmaengine: generalize requesting DMA channel"
> ---
>  drivers/iio/buffer/industrialio-buffer-dmaengine.c | 38
> ++++++++++++++++++++++
>  include/linux/iio/buffer-dmaengine.h               |  5 +++
>  2 files changed, 43 insertions(+)
>
> diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> index
> 02847d3962fcbb43ec76167db6482ab951f20942..e9d9a7d39fe191c2b6e8c196a08cdd26cd3a
> 8d4b 100644
> --- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> +++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> @@ -380,6 +380,44 @@ int devm_iio_dmaengine_buffer_setup_ext(struct device
> *dev,
>  }
>  EXPORT_SYMBOL_NS_GPL(devm_iio_dmaengine_buffer_setup_ext,
> "IIO_DMAENGINE_BUFFER");
>  
> +static void devm_iio_dmaengine_buffer_free(void *buffer)
> +{
> + iio_dmaengine_buffer_free(buffer);
> +}
> +
> +/**
> + * devm_iio_dmaengine_buffer_setup_with_handle() - Setup a DMA buffer for an
> + *    IIO device
> + * @dev: Device for devm ownership
> + * @indio_dev: IIO device to which to attach this buffer.
> + * @chan: DMA channel
> + * @dir: Direction of buffer (in or out)
> + *
> + * This allocates a new IIO buffer with devm_iio_dmaengine_buffer_alloc()
> + * and attaches it to an IIO device with iio_device_attach_buffer().
> + * It also appends the INDIO_BUFFER_HARDWARE mode to the supported modes of
> the
> + * IIO device.
> + *
> + * This is the same as devm_iio_dmaengine_buffer_setup_ext() except that the
> + * caller manages requesting and releasing the DMA channel handle.
> + */
> +int devm_iio_dmaengine_buffer_setup_with_handle(struct device *dev,
> + struct iio_dev *indio_dev,
> + struct dma_chan *chan,
> + enum iio_buffer_direction
> dir)
> +{
> + struct iio_buffer *buffer;
> +
> + buffer = __iio_dmaengine_buffer_setup_ext(indio_dev, chan, dir);
> + if (IS_ERR(buffer))
> + return PTR_ERR(buffer);
> +
> + return devm_add_action_or_reset(dev, devm_iio_dmaengine_buffer_free,
> + buffer);
> +}
> +EXPORT_SYMBOL_NS_GPL(devm_iio_dmaengine_buffer_setup_with_handle,
> +      "IIO_DMAENGINE_BUFFER");
> +
>  MODULE_AUTHOR("Lars-Peter Clausen <lars@xxxxxxxxxx>");
>  MODULE_DESCRIPTION("DMA buffer for the IIO framework");
>  MODULE_LICENSE("GPL");
> diff --git a/include/linux/iio/buffer-dmaengine.h b/include/linux/iio/buffer-
> dmaengine.h
> index
> 72a2e3fd8a5bf5e8f27ee226ddd92979d233754b..37f27545f69f761c3327c307cc6311b02a75
> 1096 100644
> --- a/include/linux/iio/buffer-dmaengine.h
> +++ b/include/linux/iio/buffer-dmaengine.h
> @@ -11,6 +11,7 @@
>  
>  struct iio_dev;
>  struct device;
> +struct dma_chan;
>  
>  void iio_dmaengine_buffer_teardown(struct iio_buffer *buffer);
>  struct iio_buffer *iio_dmaengine_buffer_setup_ext(struct device *dev,
> @@ -26,6 +27,10 @@ int devm_iio_dmaengine_buffer_setup_ext(struct device *dev,
>   struct iio_dev *indio_dev,
>   const char *channel,
>   enum iio_buffer_direction dir);
> +int devm_iio_dmaengine_buffer_setup_with_handle(struct device *dev,
> + struct iio_dev *indio_dev,
> + struct dma_chan *chan,
> + enum iio_buffer_direction
> dir);
>  
>  #define devm_iio_dmaengine_buffer_setup(dev, indio_dev, channel) \
>   devm_iio_dmaengine_buffer_setup_ext(dev, indio_dev, channel, \
>