media: mantis: switch from 'pci_' to 'dma_' API
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sun, 13 Sep 2020 14:57:16 +0000 (16:57 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Mon, 22 Mar 2021 16:19:02 +0000 (17:19 +0100)
The wrappers in include/linux/pci-dma-compat.h should go away.

The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.

When memory is allocated in 'mantis_alloc_buffers()' (mantis_dma.c)
GFP_KERNEL can be used because it is called from 'mantis_dma_init()' which
is only called from probe functions and no lock is taken in the between.

@@
@@
-    PCI_DMA_BIDIRECTIONAL
+    DMA_BIDIRECTIONAL

@@
@@
-    PCI_DMA_TODEVICE
+    DMA_TO_DEVICE

@@
@@
-    PCI_DMA_FROMDEVICE
+    DMA_FROM_DEVICE

@@
@@
-    PCI_DMA_NONE
+    DMA_NONE

@@
expression e1, e2, e3;
@@
-    pci_alloc_consistent(e1, e2, e3)
+    dma_alloc_coherent(&e1->dev, e2, e3, GFP_)

@@
expression e1, e2, e3;
@@
-    pci_zalloc_consistent(e1, e2, e3)
+    dma_alloc_coherent(&e1->dev, e2, e3, GFP_)

@@
expression e1, e2, e3, e4;
@@
-    pci_free_consistent(e1, e2, e3, e4)
+    dma_free_coherent(&e1->dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-    pci_map_single(e1, e2, e3, e4)
+    dma_map_single(&e1->dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-    pci_unmap_single(e1, e2, e3, e4)
+    dma_unmap_single(&e1->dev, e2, e3, e4)

@@
expression e1, e2, e3, e4, e5;
@@
-    pci_map_page(e1, e2, e3, e4, e5)
+    dma_map_page(&e1->dev, e2, e3, e4, e5)

@@
expression e1, e2, e3, e4;
@@
-    pci_unmap_page(e1, e2, e3, e4)
+    dma_unmap_page(&e1->dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-    pci_map_sg(e1, e2, e3, e4)
+    dma_map_sg(&e1->dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-    pci_unmap_sg(e1, e2, e3, e4)
+    dma_unmap_sg(&e1->dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-    pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+    dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-    pci_dma_sync_single_for_device(e1, e2, e3, e4)
+    dma_sync_single_for_device(&e1->dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-    pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+    dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-    pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+    dma_sync_sg_for_device(&e1->dev, e2, e3, e4)

@@
expression e1, e2;
@@
-    pci_dma_mapping_error(e1, e2)
+    dma_mapping_error(&e1->dev, e2)

@@
expression e1, e2;
@@
-    pci_set_dma_mask(e1, e2)
+    dma_set_mask(&e1->dev, e2)

@@
expression e1, e2;
@@
-    pci_set_consistent_dma_mask(e1, e2)
+    dma_set_coherent_mask(&e1->dev, e2)

Link: https://lore.kernel.org/linux-media/20200913145716.361507-1-christophe.jaillet@wanadoo.fr
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/pci/mantis/mantis_dma.c
drivers/media/pci/mantis/mantis_pci.c

index 4df571f..80c8439 100644 (file)
@@ -52,8 +52,8 @@ int mantis_dma_exit(struct mantis_pci *mantis)
                         mantis->buf_cpu,
                         MANTIS_BUF_SIZE);
 
-               pci_free_consistent(mantis->pdev, MANTIS_BUF_SIZE,
-                                   mantis->buf_cpu, mantis->buf_dma);
+               dma_free_coherent(&mantis->pdev->dev, MANTIS_BUF_SIZE,
+                                 mantis->buf_cpu, mantis->buf_dma);
 
                mantis->buf_cpu = NULL;
        }
@@ -64,8 +64,8 @@ int mantis_dma_exit(struct mantis_pci *mantis)
                        mantis->risc_cpu,
                        MANTIS_RISC_SIZE);
 
-               pci_free_consistent(mantis->pdev, MANTIS_RISC_SIZE,
-                                   mantis->risc_cpu, mantis->risc_dma);
+               dma_free_coherent(&mantis->pdev->dev, MANTIS_RISC_SIZE,
+                                 mantis->risc_cpu, mantis->risc_dma);
 
                mantis->risc_cpu = NULL;
        }
@@ -77,9 +77,9 @@ EXPORT_SYMBOL_GPL(mantis_dma_exit);
 static inline int mantis_alloc_buffers(struct mantis_pci *mantis)
 {
        if (!mantis->buf_cpu) {
-               mantis->buf_cpu = pci_alloc_consistent(mantis->pdev,
-                                                      MANTIS_BUF_SIZE,
-                                                      &mantis->buf_dma);
+               mantis->buf_cpu = dma_alloc_coherent(&mantis->pdev->dev,
+                                                    MANTIS_BUF_SIZE,
+                                                    &mantis->buf_dma, GFP_KERNEL);
                if (!mantis->buf_cpu) {
                        dprintk(MANTIS_ERROR, 1,
                                "DMA buffer allocation failed");
@@ -92,9 +92,9 @@ static inline int mantis_alloc_buffers(struct mantis_pci *mantis)
                        mantis->buf_cpu, MANTIS_BUF_SIZE);
        }
        if (!mantis->risc_cpu) {
-               mantis->risc_cpu = pci_alloc_consistent(mantis->pdev,
-                                                       MANTIS_RISC_SIZE,
-                                                       &mantis->risc_dma);
+               mantis->risc_cpu = dma_alloc_coherent(&mantis->pdev->dev,
+                                                     MANTIS_RISC_SIZE,
+                                                     &mantis->risc_dma, GFP_KERNEL);
 
                if (!mantis->risc_cpu) {
                        dprintk(MANTIS_ERROR, 1,
index 3bfb3e9..9fbce74 100644 (file)
@@ -55,7 +55,7 @@ int mantis_pci_init(struct mantis_pci *mantis)
                goto fail0;
        }
 
-       err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
+       err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
        if (err != 0) {
                dprintk(MANTIS_ERROR, 1, "ERROR: Unable to obtain 32 bit DMA <%i>", err);
                ret = -ENOMEM;