DMA Engine development
 help / color / mirror / Atom feed
* dmaengine: add a new helper dmam_async_device_register
@ 2018-07-25 12:38 Vinod Koul
  0 siblings, 0 replies; 4+ messages in thread
From: Vinod Koul @ 2018-07-25 12:38 UTC (permalink / raw)
  To: Huang Shijie
  Cc: corbet, dan.j.williams, robh, linux-doc, dmaengine, linux-kernel

On 25-07-18, 13:46, Huang Shijie wrote:
> This patch adds the dmam_async_device_register for DMA code.
> Use the Devres to call the release for the DMA engine driver.

no users?

> 
> Signed-off-by: Huang Shijie <sjhuang@iluvatar.ai>
> ---
>  Documentation/driver-model/devres.txt |  1 +
>  drivers/dma/dmaengine.c               | 35 +++++++++++++++++++++++++++
>  include/linux/dmaengine.h             |  1 +
>  3 files changed, 37 insertions(+)
> 
> diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
> index a3e8bceb5f19..26c6de621446 100644
> --- a/Documentation/driver-model/devres.txt
> +++ b/Documentation/driver-model/devres.txt
> @@ -240,6 +240,7 @@ CLOCK
>    devm_of_clk_add_hw_provider()
>  
>  DMA
> +  dmam_async_device_register()

can we name it dmaengine_async_device_register, not to confuse with dma APIs

>    dmam_alloc_coherent()
>    dmam_alloc_attrs()
>    dmam_declare_coherent_memory()
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index 84ac38dbdb65..2477af0bdfc7 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -1135,6 +1135,41 @@ void dma_async_device_unregister(struct dma_device *device)
>  }
>  EXPORT_SYMBOL(dma_async_device_unregister);
>  
> +static void dmam_device_release(struct device *dev, void *res)
> +{
> +	struct dma_device *device;
> +
> +	device = *(struct dma_device **)res;
> +	dma_async_device_unregister(device);
> +}
> +
> +/**
> + * dmam_async_device_register - registers DMA devices found
> + * @device: &dma_device
> + *
> + * The operation is managed and will be undone on driver detach.
> + */
> +int dmam_async_device_register(struct dma_device *device)
> +{
> +	void *p;
> +	int ret;
> +
> +	p = devres_alloc(dmam_device_release, sizeof(void *), GFP_KERNEL);
> +	if (!p)
> +		return -ENOMEM;
> +
> +	ret = dma_async_device_register(device);
> +	if (!ret) {
> +		*(struct dma_device **)p = device;
> +		devres_add(device->dev, p);
> +	} else {
> +		devres_free(p);
> +	}
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL(dmam_async_device_register);
> +
>  struct dmaengine_unmap_pool {
>  	struct kmem_cache *cache;
>  	const char *name;
> diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
> index c8c3a7a93802..b98bced0b98e 100644
> --- a/include/linux/dmaengine.h
> +++ b/include/linux/dmaengine.h
> @@ -1406,6 +1406,7 @@ static inline int dmaengine_desc_free(struct dma_async_tx_descriptor *desc)
>  /* --- DMA device --- */
>  
>  int dma_async_device_register(struct dma_device *device);
> +int dmam_async_device_register(struct dma_device *device);
>  void dma_async_device_unregister(struct dma_device *device);
>  void dma_run_dependencies(struct dma_async_tx_descriptor *tx);
>  struct dma_chan *dma_get_slave_channel(struct dma_chan *chan);
> -- 
> 2.17.1

^ permalink raw reply	[flat|nested] 4+ messages in thread
* dmaengine: add a new helper dmam_async_device_register
@ 2018-07-26  4:10 Vinod Koul
  0 siblings, 0 replies; 4+ messages in thread
From: Vinod Koul @ 2018-07-26  4:10 UTC (permalink / raw)
  To: Huang Shijie
  Cc: corbet, dan.j.williams, robh, linux-doc, dmaengine, linux-kernel

On 26-07-18, 09:21, Huang Shijie wrote:
> > > @@ -240,6 +240,7 @@ CLOCK
> > >     devm_of_clk_add_hw_provider()
> > >   DMA
> > > +  dmam_async_device_register()
> > can we name it dmaengine_async_device_register, not to confuse with dma APIs
> ok.
> If no one objects the dmaengine_async_device_register().
> I will use it in the next version.

Relooking at it, we also need to suggest that it is devm api, so:

dmaenginem_async_device_register() would be better IMO

^ permalink raw reply	[flat|nested] 4+ messages in thread
* dmaengine: add a new helper dmam_async_device_register
@ 2018-07-26  1:21 Huang Shijie
  0 siblings, 0 replies; 4+ messages in thread
From: Huang Shijie @ 2018-07-26  1:21 UTC (permalink / raw)
  To: Vinod; +Cc: corbet, dan.j.williams, robh, linux-doc, dmaengine, linux-kernel

Hi Vinod,


在 2018年07月25日 20:38, Vinod 写道:
> On 25-07-18, 13:46, Huang Shijie wrote:
>> This patch adds the dmam_async_device_register for DMA code.
>> Use the Devres to call the release for the DMA engine driver.
> no users?
I can add some new users if you want.
I will add an extra patch for it.

>
>> Signed-off-by: Huang Shijie <sjhuang@iluvatar.ai>
>> ---
>>   Documentation/driver-model/devres.txt |  1 +
>>   drivers/dma/dmaengine.c               | 35 +++++++++++++++++++++++++++
>>   include/linux/dmaengine.h             |  1 +
>>   3 files changed, 37 insertions(+)
>>
>> diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
>> index a3e8bceb5f19..26c6de621446 100644
>> --- a/Documentation/driver-model/devres.txt
>> +++ b/Documentation/driver-model/devres.txt
>> @@ -240,6 +240,7 @@ CLOCK
>>     devm_of_clk_add_hw_provider()
>>   
>>   DMA
>> +  dmam_async_device_register()
> can we name it dmaengine_async_device_register, not to confuse with dma APIs
ok.
If no one objects the dmaengine_async_device_register().
I will use it in the next version.

Thanks
Huang Shijie
---
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread
* dmaengine: add a new helper dmam_async_device_register
@ 2018-07-25  5:46 Huang Shijie
  0 siblings, 0 replies; 4+ messages in thread
From: Huang Shijie @ 2018-07-25  5:46 UTC (permalink / raw)
  To: vkoul
  Cc: corbet, dan.j.williams, robh, linux-doc, dmaengine, linux-kernel,
	Huang Shijie

This patch adds the dmam_async_device_register for DMA code.
Use the Devres to call the release for the DMA engine driver.

Signed-off-by: Huang Shijie <sjhuang@iluvatar.ai>
---
 Documentation/driver-model/devres.txt |  1 +
 drivers/dma/dmaengine.c               | 35 +++++++++++++++++++++++++++
 include/linux/dmaengine.h             |  1 +
 3 files changed, 37 insertions(+)

diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
index a3e8bceb5f19..26c6de621446 100644
--- a/Documentation/driver-model/devres.txt
+++ b/Documentation/driver-model/devres.txt
@@ -240,6 +240,7 @@ CLOCK
   devm_of_clk_add_hw_provider()
 
 DMA
+  dmam_async_device_register()
   dmam_alloc_coherent()
   dmam_alloc_attrs()
   dmam_declare_coherent_memory()
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 84ac38dbdb65..2477af0bdfc7 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -1135,6 +1135,41 @@ void dma_async_device_unregister(struct dma_device *device)
 }
 EXPORT_SYMBOL(dma_async_device_unregister);
 
+static void dmam_device_release(struct device *dev, void *res)
+{
+	struct dma_device *device;
+
+	device = *(struct dma_device **)res;
+	dma_async_device_unregister(device);
+}
+
+/**
+ * dmam_async_device_register - registers DMA devices found
+ * @device: &dma_device
+ *
+ * The operation is managed and will be undone on driver detach.
+ */
+int dmam_async_device_register(struct dma_device *device)
+{
+	void *p;
+	int ret;
+
+	p = devres_alloc(dmam_device_release, sizeof(void *), GFP_KERNEL);
+	if (!p)
+		return -ENOMEM;
+
+	ret = dma_async_device_register(device);
+	if (!ret) {
+		*(struct dma_device **)p = device;
+		devres_add(device->dev, p);
+	} else {
+		devres_free(p);
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL(dmam_async_device_register);
+
 struct dmaengine_unmap_pool {
 	struct kmem_cache *cache;
 	const char *name;
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index c8c3a7a93802..b98bced0b98e 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -1406,6 +1406,7 @@ static inline int dmaengine_desc_free(struct dma_async_tx_descriptor *desc)
 /* --- DMA device --- */
 
 int dma_async_device_register(struct dma_device *device);
+int dmam_async_device_register(struct dma_device *device);
 void dma_async_device_unregister(struct dma_device *device);
 void dma_run_dependencies(struct dma_async_tx_descriptor *tx);
 struct dma_chan *dma_get_slave_channel(struct dma_chan *chan);

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

end of thread, other threads:[~2018-07-26  4:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-25 12:38 dmaengine: add a new helper dmam_async_device_register Vinod Koul
  -- strict thread matches above, loose matches on Subject: below --
2018-07-26  4:10 Vinod Koul
2018-07-26  1:21 Huang Shijie
2018-07-25  5:46 Huang Shijie

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