public inbox for dmaengine@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] dma: Add devm_dma_request_chan()
@ 2024-12-22 14:14 Bence Csókás
  2024-12-24  9:20 ` Vinod Koul
  0 siblings, 1 reply; 4+ messages in thread
From: Bence Csókás @ 2024-12-22 14:14 UTC (permalink / raw)
  To: dmaengine, linux-kernel; +Cc: Bence Csókás, Vinod Koul

Expand the arsenal of devm functions for DMA
devices, this time for requesting channels.

Signed-off-by: Bence Csókás <csokas.bence@prolan.hu>
---

Notes:
    Changes in v2:
    * add prototype to header
    * fix ERR_PTR() mixup

 drivers/dma/dmaengine.c   | 30 ++++++++++++++++++++++++++++++
 include/linux/dmaengine.h |  7 +++++++
 2 files changed, 37 insertions(+)

diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index c1357d7f3dc6..02c29d26ac85 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -926,6 +926,36 @@ void dma_release_channel(struct dma_chan *chan)
 }
 EXPORT_SYMBOL_GPL(dma_release_channel);
 
+static void dmaenginem_release_channel(void *chan)
+{
+	dma_release_channel(chan);
+}
+
+/**
+ * devm_dma_request_chan - try to allocate an exclusive slave channel
+ * @dev:	pointer to client device structure
+ * @name:	slave channel name
+ *
+ * Returns pointer to appropriate DMA channel on success or an error pointer.
+ *
+ * The operation is managed and will be undone on driver detach.
+ */
+
+struct dma_chan *devm_dma_request_chan(struct device *dev, const char *name)
+{
+	struct dma_chan *chan = dma_request_chan(dev, name);
+	int ret = 0;
+
+	if (!IS_ERR(chan))
+		ret = devm_add_action_or_reset(dev, dmaenginem_release_channel, chan);
+
+	if (ret)
+		return ERR_PTR(ret);
+
+	return chan;
+}
+EXPORT_SYMBOL_GPL(devm_dma_request_chan);
+
 /**
  * dmaengine_get - register interest in dma_channels
  */
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index b137fdb56093..631519552c5a 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -1521,6 +1521,7 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
 
 struct dma_chan *dma_request_chan(struct device *dev, const char *name);
 struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask);
+struct dma_chan *devm_dma_request_chan(struct device *dev, const char *name);
 
 void dma_release_channel(struct dma_chan *chan);
 int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps);
@@ -1557,6 +1558,12 @@ static inline struct dma_chan *dma_request_chan_by_mask(
 {
 	return ERR_PTR(-ENODEV);
 }
+
+static inline struct dma_chan *devm_dma_request_chan(struct device *dev, const char *name)
+{
+	return ERR_PTR(-ENODEV);
+}
+
 static inline void dma_release_channel(struct dma_chan *chan)
 {
 }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] dma: Add devm_dma_request_chan()
  2024-12-22 14:14 [PATCH v2] dma: Add devm_dma_request_chan() Bence Csókás
@ 2024-12-24  9:20 ` Vinod Koul
  2024-12-26 14:46   ` Csókás Bence
  0 siblings, 1 reply; 4+ messages in thread
From: Vinod Koul @ 2024-12-24  9:20 UTC (permalink / raw)
  To: Bence Csókás; +Cc: dmaengine, linux-kernel

On 22-12-24, 15:14, Bence Csókás wrote:
> Expand the arsenal of devm functions for DMA
> devices, this time for requesting channels.

Looks good, users for this?

> 
> Signed-off-by: Bence Csókás <csokas.bence@prolan.hu>
> ---
> 
> Notes:
>     Changes in v2:
>     * add prototype to header
>     * fix ERR_PTR() mixup
> 
>  drivers/dma/dmaengine.c   | 30 ++++++++++++++++++++++++++++++
>  include/linux/dmaengine.h |  7 +++++++
>  2 files changed, 37 insertions(+)
> 
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index c1357d7f3dc6..02c29d26ac85 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -926,6 +926,36 @@ void dma_release_channel(struct dma_chan *chan)
>  }
>  EXPORT_SYMBOL_GPL(dma_release_channel);
>  
> +static void dmaenginem_release_channel(void *chan)
> +{
> +	dma_release_channel(chan);
> +}
> +
> +/**
> + * devm_dma_request_chan - try to allocate an exclusive slave channel
> + * @dev:	pointer to client device structure
> + * @name:	slave channel name
> + *
> + * Returns pointer to appropriate DMA channel on success or an error pointer.
> + *
> + * The operation is managed and will be undone on driver detach.
> + */
> +
> +struct dma_chan *devm_dma_request_chan(struct device *dev, const char *name)
> +{
> +	struct dma_chan *chan = dma_request_chan(dev, name);
> +	int ret = 0;
> +
> +	if (!IS_ERR(chan))
> +		ret = devm_add_action_or_reset(dev, dmaenginem_release_channel, chan);
> +
> +	if (ret)
> +		return ERR_PTR(ret);
> +
> +	return chan;
> +}
> +EXPORT_SYMBOL_GPL(devm_dma_request_chan);
> +
>  /**
>   * dmaengine_get - register interest in dma_channels
>   */
> diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
> index b137fdb56093..631519552c5a 100644
> --- a/include/linux/dmaengine.h
> +++ b/include/linux/dmaengine.h
> @@ -1521,6 +1521,7 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
>  
>  struct dma_chan *dma_request_chan(struct device *dev, const char *name);
>  struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask);
> +struct dma_chan *devm_dma_request_chan(struct device *dev, const char *name);
>  
>  void dma_release_channel(struct dma_chan *chan);
>  int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps);
> @@ -1557,6 +1558,12 @@ static inline struct dma_chan *dma_request_chan_by_mask(
>  {
>  	return ERR_PTR(-ENODEV);
>  }
> +
> +static inline struct dma_chan *devm_dma_request_chan(struct device *dev, const char *name)
> +{
> +	return ERR_PTR(-ENODEV);
> +}
> +
>  static inline void dma_release_channel(struct dma_chan *chan)
>  {
>  }
> -- 
> 2.34.1
> 

-- 
~Vinod

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] dma: Add devm_dma_request_chan()
  2024-12-24  9:20 ` Vinod Koul
@ 2024-12-26 14:46   ` Csókás Bence
  2025-01-14 15:39     ` Csókás Bence
  0 siblings, 1 reply; 4+ messages in thread
From: Csókás Bence @ 2024-12-26 14:46 UTC (permalink / raw)
  To: Vinod Koul; +Cc: dmaengine, linux-kernel

Hi,

On 2024. 12. 24. 10:20, Vinod Koul wrote:
> On 22-12-24, 15:14, Bence Csókás wrote:
>> Expand the arsenal of devm functions for DMA
>> devices, this time for requesting channels.
> 
> Looks good, users for this?

I plan to use it in drivers/spi/atmel-quadspi.c. I already have that 
patch ready, I'll submit it once it has been tested, and after my 
outstanding patches have been merged (linux-spi ML has been quiet during 
the holidays, understandably), but for now I wanted to get it into 
dmaengine, so it will be ready for the SPI guys to use.

>> Signed-off-by: Bence Csókás <csokas.bence@prolan.hu>

Bence


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] dma: Add devm_dma_request_chan()
  2024-12-26 14:46   ` Csókás Bence
@ 2025-01-14 15:39     ` Csókás Bence
  0 siblings, 0 replies; 4+ messages in thread
From: Csókás Bence @ 2025-01-14 15:39 UTC (permalink / raw)
  To: Vinod Koul; +Cc: dmaengine, linux-kernel

Hi,

On 2024. 12. 26. 15:46, Csókás Bence wrote:
> Hi,
> 
> On 2024. 12. 24. 10:20, Vinod Koul wrote:
>> On 22-12-24, 15:14, Bence Csókás wrote:
>>> Expand the arsenal of devm functions for DMA
>>> devices, this time for requesting channels.
>>
>> Looks good, users for this?
> 
> I plan to use it in drivers/spi/atmel-quadspi.c. I already have that 
> patch ready, I'll submit it once it has been tested, and after my 
> outstanding patches have been merged (linux-spi ML has been quiet during 
> the holidays, understandably), but for now I wanted to get it into 
> dmaengine, so it will be ready for the SPI guys to use.

Can this be merged or is there something I should improve upon? I want 
to submit the SPI parts to give them time before the upcoming merge window.

Bence


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-01-14 15:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-22 14:14 [PATCH v2] dma: Add devm_dma_request_chan() Bence Csókás
2024-12-24  9:20 ` Vinod Koul
2024-12-26 14:46   ` Csókás Bence
2025-01-14 15:39     ` Csókás Bence

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox