]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: tw686x: switch from 'pci_' to 'dma_' API
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sun, 28 Mar 2021 17:02:18 +0000 (19:02 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tue, 6 Apr 2021 14:07:26 +0000 (16:07 +0200)
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 'tw686x_audio_dma_alloc()' (tw686x-audio.c)
GFP_KERNEL can be used because it is only called from a probe function
and no spinlock is taken in the between.
The call chain is:
  tw686x_probe (tw686x-core.c)
    --> tw686x_audio_init (tw686x-audio.c)
      --> tw686x_audio_dma_alloc (tw686x-audio.c)

When memory is allocated in 'tw686x_memcpy_dma_alloc()' and in
'tw686x_sg_dma_alloc()' (tw686x-video.c) GFP_KERNEL can be used because
these functions are .alloc functions from a tw686x_dma_ops structure.

@@
@@
-    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)

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/pci/tw686x/tw686x-audio.c
drivers/media/pci/tw686x/tw686x-core.c
drivers/media/pci/tw686x/tw686x-video.c

index 54144e23a4870812b4448e69d3bd09563d8646a4..74cba1368cfa5f4e454f505df2701d614b120218 100644 (file)
@@ -300,9 +300,9 @@ static void tw686x_audio_dma_free(struct tw686x_dev *dev,
        for (pb = 0; pb < 2; pb++) {
                if (!ac->dma_descs[pb].virt)
                        continue;
-               pci_free_consistent(dev->pci_dev, ac->dma_descs[pb].size,
-                                   ac->dma_descs[pb].virt,
-                                   ac->dma_descs[pb].phys);
+               dma_free_coherent(&dev->pci_dev->dev, ac->dma_descs[pb].size,
+                                 ac->dma_descs[pb].virt,
+                                 ac->dma_descs[pb].phys);
                ac->dma_descs[pb].virt = NULL;
        }
 }
@@ -313,7 +313,7 @@ static int tw686x_audio_dma_alloc(struct tw686x_dev *dev,
        int pb;
 
        /*
-        * In the memcpy DMA mode we allocate a consistent buffer
+        * In the memcpy DMA mode we allocate a coherent buffer
         * and use it for the DMA capture. Otherwise, DMA
         * acts on the ALSA buffers as received in pcm_prepare.
         */
@@ -324,8 +324,9 @@ static int tw686x_audio_dma_alloc(struct tw686x_dev *dev,
                u32 reg = pb ? ADMA_B_ADDR[ac->ch] : ADMA_P_ADDR[ac->ch];
                void *virt;
 
-               virt = pci_alloc_consistent(dev->pci_dev, AUDIO_DMA_SIZE_MAX,
-                                           &ac->dma_descs[pb].phys);
+               virt = dma_alloc_coherent(&dev->pci_dev->dev,
+                                         AUDIO_DMA_SIZE_MAX,
+                                         &ac->dma_descs[pb].phys, GFP_KERNEL);
                if (!virt) {
                        dev_err(&dev->pci_dev->dev,
                                "dma%d: unable to allocate audio DMA %s-buffer\n",
index 74ae4f0dcee768c3c0aae68b1c10d19c58d410a2..6676e069b515d809753e31628dc9bc02a983cd6f 100644 (file)
@@ -276,7 +276,7 @@ static int tw686x_probe(struct pci_dev *pci_dev,
        }
 
        pci_set_master(pci_dev);
-       err = pci_set_dma_mask(pci_dev, DMA_BIT_MASK(32));
+       err = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(32));
        if (err) {
                dev_err(&pci_dev->dev, "32-bit PCI DMA not supported\n");
                err = -EIO;
index 1ced2b0ddb2410cd921663b9415892853ff300e3..b227e9e78ebd0970ad9b53ae8b83bb8054e210b3 100644 (file)
@@ -92,8 +92,8 @@ static void tw686x_memcpy_dma_free(struct tw686x_video_channel *vc,
        }
 
        if (desc->virt) {
-               pci_free_consistent(dev->pci_dev, desc->size,
-                                   desc->virt, desc->phys);
+               dma_free_coherent(&dev->pci_dev->dev, desc->size, desc->virt,
+                                 desc->phys);
                desc->virt = NULL;
        }
 }
@@ -110,8 +110,8 @@ static int tw686x_memcpy_dma_alloc(struct tw686x_video_channel *vc,
             "Allocating buffer but previous still here\n");
 
        len = (vc->width * vc->height * vc->format->depth) >> 3;
-       virt = pci_alloc_consistent(dev->pci_dev, len,
-                                   &vc->dma_descs[pb].phys);
+       virt = dma_alloc_coherent(&dev->pci_dev->dev, len,
+                                 &vc->dma_descs[pb].phys, GFP_KERNEL);
        if (!virt) {
                v4l2_err(&dev->v4l2_dev,
                         "dma%d: unable to allocate %s-buffer\n",
@@ -258,8 +258,8 @@ static void tw686x_sg_dma_free(struct tw686x_video_channel *vc,
        struct tw686x_dev *dev = vc->dev;
 
        if (desc->size) {
-               pci_free_consistent(dev->pci_dev, desc->size,
-                                   desc->virt, desc->phys);
+               dma_free_coherent(&dev->pci_dev->dev, desc->size, desc->virt,
+                                 desc->phys);
                desc->virt = NULL;
        }
 
@@ -276,9 +276,8 @@ static int tw686x_sg_dma_alloc(struct tw686x_video_channel *vc,
        void *virt;
 
        if (desc->size) {
-
-               virt = pci_alloc_consistent(dev->pci_dev, desc->size,
-                                           &desc->phys);
+               virt = dma_alloc_coherent(&dev->pci_dev->dev, desc->size,
+                                         &desc->phys, GFP_KERNEL);
                if (!virt) {
                        v4l2_err(&dev->v4l2_dev,
                                 "dma%d: unable to allocate %s-buffer\n",