Skip to content

Commit 2180a0d

Browse files
Hans Verkuilgregkh
authored andcommitted
carma-fpga-program: drop videobuf dependency
This driver abuses videobuf helper functions. This is a bad idea because: 1) this driver is completely unrelated to media drivers 2) the videobuf API is deprecated and will be removed eventually This patch replaces the videobuf functions with the normal DMA kernel API. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 27361ff commit 2180a0d

File tree

2 files changed

+81
-19
lines changed

2 files changed

+81
-19
lines changed

drivers/misc/carma/Kconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ config CARMA_FPGA
88

99
config CARMA_FPGA_PROGRAM
1010
tristate "CARMA DATA-FPGA Programmer"
11-
depends on FSL_SOC && PPC_83xx && MEDIA_SUPPORT && HAS_DMA && FSL_DMA
12-
select VIDEOBUF_DMA_SG
11+
depends on FSL_SOC && PPC_83xx && HAS_DMA && FSL_DMA
1312
default n
1413
help
1514
Say Y here to include support for programming the data processing

drivers/misc/carma/carma-fpga-program.c

Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/fsldma.h>
2020
#include <linux/interrupt.h>
2121
#include <linux/highmem.h>
22+
#include <linux/vmalloc.h>
2223
#include <linux/kernel.h>
2324
#include <linux/module.h>
2425
#include <linux/mutex.h>
@@ -30,8 +31,6 @@
3031
#include <linux/fs.h>
3132
#include <linux/io.h>
3233

33-
#include <media/videobuf-dma-sg.h>
34-
3534
/* MPC8349EMDS specific get_immrbase() */
3635
#include <sysdev/fsl_soc.h>
3736

@@ -67,14 +66,79 @@ struct fpga_dev {
6766
/* FPGA Bitfile */
6867
struct mutex lock;
6968

70-
struct videobuf_dmabuf vb;
71-
bool vb_allocated;
69+
void *vaddr;
70+
struct scatterlist *sglist;
71+
int sglen;
72+
int nr_pages;
73+
bool buf_allocated;
7274

7375
/* max size and written bytes */
7476
size_t fw_size;
7577
size_t bytes;
7678
};
7779

80+
static int fpga_dma_init(struct fpga_dev *priv, int nr_pages)
81+
{
82+
struct page *pg;
83+
int i;
84+
85+
priv->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT);
86+
if (NULL == priv->vaddr) {
87+
pr_debug("vmalloc_32(%d pages) failed\n", nr_pages);
88+
return -ENOMEM;
89+
}
90+
91+
pr_debug("vmalloc is at addr 0x%08lx, size=%d\n",
92+
(unsigned long)priv->vaddr,
93+
nr_pages << PAGE_SHIFT);
94+
95+
memset(priv->vaddr, 0, nr_pages << PAGE_SHIFT);
96+
priv->nr_pages = nr_pages;
97+
98+
priv->sglist = vzalloc(priv->nr_pages * sizeof(*priv->sglist));
99+
if (NULL == priv->sglist)
100+
goto vzalloc_err;
101+
102+
sg_init_table(priv->sglist, priv->nr_pages);
103+
for (i = 0; i < priv->nr_pages; i++) {
104+
pg = vmalloc_to_page(priv->vaddr + i * PAGE_SIZE);
105+
if (NULL == pg)
106+
goto vmalloc_to_page_err;
107+
sg_set_page(&priv->sglist[i], pg, PAGE_SIZE, 0);
108+
}
109+
return 0;
110+
111+
vmalloc_to_page_err:
112+
vfree(priv->sglist);
113+
priv->sglist = NULL;
114+
vzalloc_err:
115+
vfree(priv->vaddr);
116+
priv->vaddr = NULL;
117+
return -ENOMEM;
118+
}
119+
120+
static int fpga_dma_map(struct fpga_dev *priv)
121+
{
122+
priv->sglen = dma_map_sg(priv->dev, priv->sglist,
123+
priv->nr_pages, DMA_TO_DEVICE);
124+
125+
if (0 == priv->sglen) {
126+
pr_warn("%s: dma_map_sg failed\n", __func__);
127+
return -ENOMEM;
128+
}
129+
return 0;
130+
}
131+
132+
static int fpga_dma_unmap(struct fpga_dev *priv)
133+
{
134+
if (!priv->sglen)
135+
return 0;
136+
137+
dma_unmap_sg(priv->dev, priv->sglist, priv->sglen, DMA_TO_DEVICE);
138+
priv->sglen = 0;
139+
return 0;
140+
}
141+
78142
/*
79143
* FPGA Bitfile Helpers
80144
*/
@@ -87,8 +151,9 @@ struct fpga_dev {
87151
*/
88152
static void fpga_drop_firmware_data(struct fpga_dev *priv)
89153
{
90-
videobuf_dma_free(&priv->vb);
91-
priv->vb_allocated = false;
154+
vfree(priv->sglist);
155+
vfree(priv->vaddr);
156+
priv->buf_allocated = false;
92157
priv->bytes = 0;
93158
}
94159

@@ -427,7 +492,7 @@ static noinline int fpga_program_cpu(struct fpga_dev *priv)
427492
dev_dbg(priv->dev, "enabled the controller\n");
428493

429494
/* Write each chunk of the FPGA bitfile to FPGA programmer */
430-
ret = fpga_program_block(priv, priv->vb.vaddr, priv->bytes);
495+
ret = fpga_program_block(priv, priv->vaddr, priv->bytes);
431496
if (ret)
432497
goto out_disable_controller;
433498

@@ -463,7 +528,6 @@ static noinline int fpga_program_cpu(struct fpga_dev *priv)
463528
*/
464529
static noinline int fpga_program_dma(struct fpga_dev *priv)
465530
{
466-
struct videobuf_dmabuf *vb = &priv->vb;
467531
struct dma_chan *chan = priv->chan;
468532
struct dma_async_tx_descriptor *tx;
469533
size_t num_pages, len, avail = 0;
@@ -505,7 +569,7 @@ static noinline int fpga_program_dma(struct fpga_dev *priv)
505569
}
506570

507571
/* Map the buffer for DMA */
508-
ret = videobuf_dma_map(priv->dev, &priv->vb);
572+
ret = fpga_dma_map(priv);
509573
if (ret) {
510574
dev_err(priv->dev, "Unable to map buffer for DMA\n");
511575
goto out_free_table;
@@ -534,7 +598,7 @@ static noinline int fpga_program_dma(struct fpga_dev *priv)
534598
/* setup and submit the DMA transaction */
535599

536600
tx = dmaengine_prep_dma_sg(chan, table.sgl, num_pages,
537-
vb->sglist, vb->sglen, 0);
601+
priv->sglist, priv->sglen, 0);
538602
if (!tx) {
539603
dev_err(priv->dev, "Unable to prep DMA transaction\n");
540604
ret = -ENOMEM;
@@ -572,7 +636,7 @@ static noinline int fpga_program_dma(struct fpga_dev *priv)
572636
out_disable_controller:
573637
fpga_programmer_disable(priv);
574638
out_dma_unmap:
575-
videobuf_dma_unmap(priv->dev, vb);
639+
fpga_dma_unmap(priv);
576640
out_free_table:
577641
sg_free_table(&table);
578642
out_return:
@@ -702,20 +766,20 @@ static int fpga_open(struct inode *inode, struct file *filp)
702766
priv->bytes = 0;
703767

704768
/* Check if we have already allocated a buffer */
705-
if (priv->vb_allocated)
769+
if (priv->buf_allocated)
706770
return 0;
707771

708772
/* Allocate a buffer to hold enough data for the bitfile */
709773
nr_pages = DIV_ROUND_UP(priv->fw_size, PAGE_SIZE);
710-
ret = videobuf_dma_init_kernel(&priv->vb, DMA_TO_DEVICE, nr_pages);
774+
ret = fpga_dma_init(priv, nr_pages);
711775
if (ret) {
712776
dev_err(priv->dev, "unable to allocate data buffer\n");
713777
mutex_unlock(&priv->lock);
714778
kref_put(&priv->ref, fpga_dev_remove);
715779
return ret;
716780
}
717781

718-
priv->vb_allocated = true;
782+
priv->buf_allocated = true;
719783
return 0;
720784
}
721785

@@ -738,7 +802,7 @@ static ssize_t fpga_write(struct file *filp, const char __user *buf,
738802
return -ENOSPC;
739803

740804
count = min_t(size_t, priv->fw_size - priv->bytes, count);
741-
if (copy_from_user(priv->vb.vaddr + priv->bytes, buf, count))
805+
if (copy_from_user(priv->vaddr + priv->bytes, buf, count))
742806
return -EFAULT;
743807

744808
priv->bytes += count;
@@ -750,7 +814,7 @@ static ssize_t fpga_read(struct file *filp, char __user *buf, size_t count,
750814
{
751815
struct fpga_dev *priv = filp->private_data;
752816
return simple_read_from_buffer(buf, count, f_pos,
753-
priv->vb.vaddr, priv->bytes);
817+
priv->vaddr, priv->bytes);
754818
}
755819

756820
static loff_t fpga_llseek(struct file *filp, loff_t offset, int origin)
@@ -952,7 +1016,6 @@ static int fpga_of_probe(struct platform_device *op)
9521016
priv->dev = &op->dev;
9531017
mutex_init(&priv->lock);
9541018
init_completion(&priv->completion);
955-
videobuf_dma_init(&priv->vb);
9561019

9571020
dev_set_drvdata(priv->dev, priv);
9581021
dma_cap_zero(mask);

0 commit comments

Comments
 (0)