ARM/dmaengine: edma: Move of_dma_controller_register to the dmaengine driver
authorPeter Ujfalusi <peter.ujfalusi@ti.com>
Wed, 14 Oct 2015 11:42:47 +0000 (14:42 +0300)
committerVinod Koul <vinod.koul@intel.com>
Wed, 14 Oct 2015 14:27:11 +0000 (19:57 +0530)
If the of_dma_controller is registered in the non dmaengine driver we could
have race condition:
the of_dma_controller has been registered, but the dmaengine driver is not
yet probed. Drivers requesting DMA channels during this window will fail
since we do not yet have dmaengine drivers registered.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
arch/arm/common/edma.c
drivers/dma/edma.c

index 7c2fe527e53bea8ab779abfee110a899fb55eb0e..d82fceda13a304dc05c4da9fc32d6e51a8a25988 100644 (file)
@@ -29,7 +29,6 @@
 #include <linux/dma-mapping.h>
 #include <linux/of_address.h>
 #include <linux/of_device.h>
-#include <linux/of_dma.h>
 #include <linux/of_irq.h>
 #include <linux/pm_runtime.h>
 
@@ -1191,10 +1190,6 @@ static int edma_of_parse_dt(struct device *dev,
        return ret;
 }
 
-static struct of_dma_filter_info edma_filter_info = {
-       .filter_fn = edma_filter_fn,
-};
-
 static struct edma_soc_info *edma_setup_info_from_dt(struct device *dev,
                                                      struct device_node *node)
 {
@@ -1209,11 +1204,6 @@ static struct edma_soc_info *edma_setup_info_from_dt(struct device *dev,
        if (ret)
                return ERR_PTR(ret);
 
-       dma_cap_set(DMA_SLAVE, edma_filter_info.dma_cap);
-       dma_cap_set(DMA_CYCLIC, edma_filter_info.dma_cap);
-       of_dma_controller_register(dev->of_node, of_dma_simple_xlate,
-                                  &edma_filter_info);
-
        return info;
 }
 #else
index 19fa49d6f5551c249346da5edae328c2e85a2bae..fcb4680efed7b78887767f74aed2c9f66152ddaa 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/of.h>
+#include <linux/of_dma.h>
 
 #include <linux/platform_data/edma.h>
 
@@ -987,9 +988,14 @@ static void edma_dma_init(struct edma_cc *ecc, struct dma_device *dma,
        INIT_LIST_HEAD(&dma->channels);
 }
 
+static struct of_dma_filter_info edma_filter_info = {
+       .filter_fn = edma_filter_fn,
+};
+
 static int edma_probe(struct platform_device *pdev)
 {
        struct edma_cc *ecc;
+       struct device_node *parent_node = pdev->dev.parent->of_node;
        int ret;
 
        ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
@@ -1024,6 +1030,13 @@ static int edma_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, ecc);
 
+       if (parent_node) {
+               dma_cap_set(DMA_SLAVE, edma_filter_info.dma_cap);
+               dma_cap_set(DMA_CYCLIC, edma_filter_info.dma_cap);
+               of_dma_controller_register(parent_node, of_dma_simple_xlate,
+                                          &edma_filter_info);
+       }
+
        dev_info(&pdev->dev, "TI EDMA DMA engine driver\n");
 
        return 0;
@@ -1037,7 +1050,10 @@ static int edma_remove(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
        struct edma_cc *ecc = dev_get_drvdata(dev);
+       struct device_node *parent_node = pdev->dev.parent->of_node;
 
+       if (parent_node)
+               of_dma_controller_free(parent_node);
        dma_async_device_unregister(&ecc->dma_slave);
        edma_free_slot(ecc->dummy_slot);