linux/drivers/media/pci/mantis/mantis_pci.c
Christophe JAILLET 2e774b3699 media: mantis: switch from 'pci_' to 'dma_' API
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>
2021-03-22 17:19:02 +01:00

157 lines
3.5 KiB
C

// SPDX-License-Identifier: GPL-2.0-or-later
/*
Mantis PCI bridge driver
Copyright (C) Manu Abraham (abraham.manu@gmail.com)
*/
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <asm/io.h>
#include <asm/page.h>
#include <linux/kmod.h>
#include <linux/vmalloc.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/pci.h>
#include <asm/irq.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <media/dmxdev.h>
#include <media/dvbdev.h>
#include <media/dvb_demux.h>
#include <media/dvb_frontend.h>
#include <media/dvb_net.h>
#include "mantis_common.h"
#include "mantis_reg.h"
#include "mantis_pci.h"
#define DRIVER_NAME "Mantis Core"
int mantis_pci_init(struct mantis_pci *mantis)
{
u8 latency;
struct mantis_hwconfig *config = mantis->hwconfig;
struct pci_dev *pdev = mantis->pdev;
int err, ret = 0;
dprintk(MANTIS_ERROR, 0, "found a %s PCI %s device on (%02x:%02x.%x),\n",
config->model_name,
config->dev_type,
mantis->pdev->bus->number,
PCI_SLOT(mantis->pdev->devfn),
PCI_FUNC(mantis->pdev->devfn));
err = pci_enable_device(pdev);
if (err != 0) {
ret = -ENODEV;
dprintk(MANTIS_ERROR, 1, "ERROR: PCI enable failed <%i>", err);
goto fail0;
}
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;
goto fail1;
}
pci_set_master(pdev);
if (!request_mem_region(pci_resource_start(pdev, 0),
pci_resource_len(pdev, 0),
DRIVER_NAME)) {
dprintk(MANTIS_ERROR, 1, "ERROR: BAR0 Request failed !");
ret = -ENODEV;
goto fail1;
}
mantis->mmio = ioremap(pci_resource_start(pdev, 0),
pci_resource_len(pdev, 0));
if (!mantis->mmio) {
dprintk(MANTIS_ERROR, 1, "ERROR: BAR0 remap failed !");
ret = -ENODEV;
goto fail2;
}
pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
mantis->latency = latency;
mantis->revision = pdev->revision;
dprintk(MANTIS_ERROR, 0, " Mantis Rev %d [%04x:%04x], ",
mantis->revision,
mantis->pdev->subsystem_vendor,
mantis->pdev->subsystem_device);
dprintk(MANTIS_ERROR, 0,
"irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p\n",
mantis->pdev->irq,
mantis->latency,
mantis->mantis_addr,
mantis->mmio);
err = request_irq(pdev->irq,
config->irq_handler,
IRQF_SHARED,
DRIVER_NAME,
mantis);
if (err != 0) {
dprintk(MANTIS_ERROR, 1, "ERROR: IRQ registration failed ! <%d>", err);
ret = -ENODEV;
goto fail3;
}
pci_set_drvdata(pdev, mantis);
return ret;
/* Error conditions */
fail3:
dprintk(MANTIS_ERROR, 1, "ERROR: <%d> I/O unmap", ret);
if (mantis->mmio)
iounmap(mantis->mmio);
fail2:
dprintk(MANTIS_ERROR, 1, "ERROR: <%d> releasing regions", ret);
release_mem_region(pci_resource_start(pdev, 0),
pci_resource_len(pdev, 0));
fail1:
dprintk(MANTIS_ERROR, 1, "ERROR: <%d> disabling device", ret);
pci_disable_device(pdev);
fail0:
dprintk(MANTIS_ERROR, 1, "ERROR: <%d> exiting", ret);
return ret;
}
EXPORT_SYMBOL_GPL(mantis_pci_init);
void mantis_pci_exit(struct mantis_pci *mantis)
{
struct pci_dev *pdev = mantis->pdev;
dprintk(MANTIS_NOTICE, 1, " mem: 0x%p", mantis->mmio);
free_irq(pdev->irq, mantis);
if (mantis->mmio) {
iounmap(mantis->mmio);
release_mem_region(pci_resource_start(pdev, 0),
pci_resource_len(pdev, 0));
}
pci_disable_device(pdev);
}
EXPORT_SYMBOL_GPL(mantis_pci_exit);
MODULE_DESCRIPTION("Mantis PCI DTV bridge driver");
MODULE_AUTHOR("Manu Abraham");
MODULE_LICENSE("GPL");