]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: bt8xx: switch from 'pci_' to 'dma_' API
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Mon, 27 Jul 2020 13:51:37 +0000 (15:51 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Fri, 27 Nov 2020 13:09:01 +0000 (14:09 +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 'bt878_mem_alloc()' (bt878.c), GFP_KERNEL can
be used because it is only called from the probe function (i.e.
'bt878_probe()') and no lock is taken.

When memory is allocated in 'btcx_riscmem_alloc()' (btcx-risc.c),
GFP_KERNEL can be used because all the callers either already use
GFP_KERNEL or are called from a probe function or are called from a
.buf_prepare function.

The 4 callers are all in 'bttv-risc.c'.
   - bttv_risc_packed() and bttv_risc_planar(): only called from
        'videobuf_queue_ops''s '.buf_prepare' functions.
        The call chains are:

        .buf_prepare                     (in 'bttv-driver.c')
           --> buffer_prepare            (in 'bttv-driver.c')
              --> bttv_prepare_buffer
                 --> bttv_buffer_risc
                    --> bttv_risc_packed (x8 times)
                    --> bttv_risc_planar (x6 times)

        .buf_prepare                     (in 'bttv-vbi.c')
           --> vbi_buffer_prepare        (in 'bttv-vbi.c')
              --> bttv_risc_packed       (x2 times)

   - bttv_risc_overlay(): already uses GFP_KERNEL
   - bttv_risc_init_main(): only called from the 'bttv_probe()' probe
        function and no spin_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)

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/pci/bt8xx/bt878.c
drivers/media/pci/bt8xx/btcx-risc.c
drivers/media/pci/bt8xx/bttv-driver.c

index 79ba15a9385a58dd9d61deccbb4bc9e8e2f9dfb2..78dd35c9b65d7d1d0ca3c5707325fe3a516df2f9 100644 (file)
@@ -67,14 +67,14 @@ EXPORT_SYMBOL(bt878);
 static void bt878_mem_free(struct bt878 *bt)
 {
        if (bt->buf_cpu) {
-               pci_free_consistent(bt->dev, bt->buf_size, bt->buf_cpu,
-                                   bt->buf_dma);
+               dma_free_coherent(&bt->dev->dev, bt->buf_size, bt->buf_cpu,
+                                 bt->buf_dma);
                bt->buf_cpu = NULL;
        }
 
        if (bt->risc_cpu) {
-               pci_free_consistent(bt->dev, bt->risc_size, bt->risc_cpu,
-                                   bt->risc_dma);
+               dma_free_coherent(&bt->dev->dev, bt->risc_size, bt->risc_cpu,
+                                 bt->risc_dma);
                bt->risc_cpu = NULL;
        }
 }
@@ -84,16 +84,16 @@ static int bt878_mem_alloc(struct bt878 *bt)
        if (!bt->buf_cpu) {
                bt->buf_size = 128 * 1024;
 
-               bt->buf_cpu = pci_zalloc_consistent(bt->dev, bt->buf_size,
-                                                   &bt->buf_dma);
+               bt->buf_cpu = dma_alloc_coherent(&bt->dev->dev, bt->buf_size,
+                                                &bt->buf_dma, GFP_KERNEL);
                if (!bt->buf_cpu)
                        return -ENOMEM;
        }
 
        if (!bt->risc_cpu) {
                bt->risc_size = PAGE_SIZE;
-               bt->risc_cpu = pci_zalloc_consistent(bt->dev, bt->risc_size,
-                                                    &bt->risc_dma);
+               bt->risc_cpu = dma_alloc_coherent(&bt->dev->dev, bt->risc_size,
+                                                 &bt->risc_dma, GFP_KERNEL);
                if (!bt->risc_cpu) {
                        bt878_mem_free(bt);
                        return -ENOMEM;
index 51257980f5391bf13dc3485fce15d8570f68b7a8..13bb1490a56836dd5d91f36215940f61698c3d10 100644 (file)
@@ -48,7 +48,7 @@ void btcx_riscmem_free(struct pci_dev *pci,
        dprintk("btcx: riscmem free [%d] dma=%lx\n",
                memcnt, (unsigned long)risc->dma);
 
-       pci_free_consistent(pci, risc->size, risc->cpu, risc->dma);
+       dma_free_coherent(&pci->dev, risc->size, risc->cpu, risc->dma);
        memset(risc,0,sizeof(*risc));
 }
 
@@ -62,7 +62,7 @@ int btcx_riscmem_alloc(struct pci_dev *pci,
        if (NULL != risc->cpu && risc->size < size)
                btcx_riscmem_free(pci,risc);
        if (NULL == risc->cpu) {
-               cpu = pci_alloc_consistent(pci, size, &dma);
+               cpu = dma_alloc_coherent(&pci->dev, size, &dma, GFP_KERNEL);
                if (NULL == cpu)
                        return -ENOMEM;
                risc->cpu  = cpu;
index 956a12e311c04b93c89e7651a3f97e8a82e3a65e..2aba3e2813215733fd7c6611be3a5def7bdf1e15 100644 (file)
@@ -4008,7 +4008,7 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
                result = -EIO;
                goto free_mem;
        }
-       if (pci_set_dma_mask(dev, DMA_BIT_MASK(32))) {
+       if (dma_set_mask(&dev->dev, DMA_BIT_MASK(32))) {
                pr_warn("%d: No suitable DMA available\n", btv->c.nr);
                result = -EIO;
                goto free_mem;