Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Hans Verkuil and committed by
Greg Kroah-Hartman
2180a0d4 27361ff5

+81 -19
+1 -2
drivers/misc/carma/Kconfig
··· 8 8 9 9 config CARMA_FPGA_PROGRAM 10 10 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 13 12 default n 14 13 help 15 14 Say Y here to include support for programming the data processing
+80 -17
drivers/misc/carma/carma-fpga-program.c
··· 19 19 #include <linux/fsldma.h> 20 20 #include <linux/interrupt.h> 21 21 #include <linux/highmem.h> 22 + #include <linux/vmalloc.h> 22 23 #include <linux/kernel.h> 23 24 #include <linux/module.h> 24 25 #include <linux/mutex.h> ··· 30 29 #include <linux/kref.h> 31 30 #include <linux/fs.h> 32 31 #include <linux/io.h> 33 - 34 - #include <media/videobuf-dma-sg.h> 35 32 36 33 /* MPC8349EMDS specific get_immrbase() */ 37 34 #include <sysdev/fsl_soc.h> ··· 66 67 /* FPGA Bitfile */ 67 68 struct mutex lock; 68 69 69 - struct videobuf_dmabuf vb; 70 - bool vb_allocated; 70 + void *vaddr; 71 + struct scatterlist *sglist; 72 + int sglen; 73 + int nr_pages; 74 + bool buf_allocated; 71 75 72 76 /* max size and written bytes */ 73 77 size_t fw_size; 74 78 size_t bytes; 75 79 }; 80 + 81 + static int fpga_dma_init(struct fpga_dev *priv, int nr_pages) 82 + { 83 + struct page *pg; 84 + int i; 85 + 86 + priv->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT); 87 + if (NULL == priv->vaddr) { 88 + pr_debug("vmalloc_32(%d pages) failed\n", nr_pages); 89 + return -ENOMEM; 90 + } 91 + 92 + pr_debug("vmalloc is at addr 0x%08lx, size=%d\n", 93 + (unsigned long)priv->vaddr, 94 + nr_pages << PAGE_SHIFT); 95 + 96 + memset(priv->vaddr, 0, nr_pages << PAGE_SHIFT); 97 + priv->nr_pages = nr_pages; 98 + 99 + priv->sglist = vzalloc(priv->nr_pages * sizeof(*priv->sglist)); 100 + if (NULL == priv->sglist) 101 + goto vzalloc_err; 102 + 103 + sg_init_table(priv->sglist, priv->nr_pages); 104 + for (i = 0; i < priv->nr_pages; i++) { 105 + pg = vmalloc_to_page(priv->vaddr + i * PAGE_SIZE); 106 + if (NULL == pg) 107 + goto vmalloc_to_page_err; 108 + sg_set_page(&priv->sglist[i], pg, PAGE_SIZE, 0); 109 + } 110 + return 0; 111 + 112 + vmalloc_to_page_err: 113 + vfree(priv->sglist); 114 + priv->sglist = NULL; 115 + vzalloc_err: 116 + vfree(priv->vaddr); 117 + priv->vaddr = NULL; 118 + return -ENOMEM; 119 + } 120 + 121 + static int fpga_dma_map(struct fpga_dev *priv) 122 + { 123 + priv->sglen = dma_map_sg(priv->dev, priv->sglist, 124 + priv->nr_pages, DMA_TO_DEVICE); 125 + 126 + if (0 == priv->sglen) { 127 + pr_warn("%s: dma_map_sg failed\n", __func__); 128 + return -ENOMEM; 129 + } 130 + return 0; 131 + } 132 + 133 + static int fpga_dma_unmap(struct fpga_dev *priv) 134 + { 135 + if (!priv->sglen) 136 + return 0; 137 + 138 + dma_unmap_sg(priv->dev, priv->sglist, priv->sglen, DMA_TO_DEVICE); 139 + priv->sglen = 0; 140 + return 0; 141 + } 76 142 77 143 /* 78 144 * FPGA Bitfile Helpers ··· 151 87 */ 152 88 static void fpga_drop_firmware_data(struct fpga_dev *priv) 153 89 { 154 - videobuf_dma_free(&priv->vb); 155 - priv->vb_allocated = false; 90 + vfree(priv->sglist); 91 + vfree(priv->vaddr); 92 + priv->buf_allocated = false; 156 93 priv->bytes = 0; 157 94 } 158 95 ··· 492 427 dev_dbg(priv->dev, "enabled the controller\n"); 493 428 494 429 /* Write each chunk of the FPGA bitfile to FPGA programmer */ 495 - ret = fpga_program_block(priv, priv->vb.vaddr, priv->bytes); 430 + ret = fpga_program_block(priv, priv->vaddr, priv->bytes); 496 431 if (ret) 497 432 goto out_disable_controller; 498 433 ··· 528 463 */ 529 464 static noinline int fpga_program_dma(struct fpga_dev *priv) 530 465 { 531 - struct videobuf_dmabuf *vb = &priv->vb; 532 466 struct dma_chan *chan = priv->chan; 533 467 struct dma_async_tx_descriptor *tx; 534 468 size_t num_pages, len, avail = 0; ··· 569 505 } 570 506 571 507 /* Map the buffer for DMA */ 572 - ret = videobuf_dma_map(priv->dev, &priv->vb); 508 + ret = fpga_dma_map(priv); 573 509 if (ret) { 574 510 dev_err(priv->dev, "Unable to map buffer for DMA\n"); 575 511 goto out_free_table; ··· 598 534 /* setup and submit the DMA transaction */ 599 535 600 536 tx = dmaengine_prep_dma_sg(chan, table.sgl, num_pages, 601 - vb->sglist, vb->sglen, 0); 537 + priv->sglist, priv->sglen, 0); 602 538 if (!tx) { 603 539 dev_err(priv->dev, "Unable to prep DMA transaction\n"); 604 540 ret = -ENOMEM; ··· 636 572 out_disable_controller: 637 573 fpga_programmer_disable(priv); 638 574 out_dma_unmap: 639 - videobuf_dma_unmap(priv->dev, vb); 575 + fpga_dma_unmap(priv); 640 576 out_free_table: 641 577 sg_free_table(&table); 642 578 out_return: ··· 766 702 priv->bytes = 0; 767 703 768 704 /* Check if we have already allocated a buffer */ 769 - if (priv->vb_allocated) 705 + if (priv->buf_allocated) 770 706 return 0; 771 707 772 708 /* Allocate a buffer to hold enough data for the bitfile */ 773 709 nr_pages = DIV_ROUND_UP(priv->fw_size, PAGE_SIZE); 774 - ret = videobuf_dma_init_kernel(&priv->vb, DMA_TO_DEVICE, nr_pages); 710 + ret = fpga_dma_init(priv, nr_pages); 775 711 if (ret) { 776 712 dev_err(priv->dev, "unable to allocate data buffer\n"); 777 713 mutex_unlock(&priv->lock); ··· 779 715 return ret; 780 716 } 781 717 782 - priv->vb_allocated = true; 718 + priv->buf_allocated = true; 783 719 return 0; 784 720 } 785 721 ··· 802 738 return -ENOSPC; 803 739 804 740 count = min_t(size_t, priv->fw_size - priv->bytes, count); 805 - if (copy_from_user(priv->vb.vaddr + priv->bytes, buf, count)) 741 + if (copy_from_user(priv->vaddr + priv->bytes, buf, count)) 806 742 return -EFAULT; 807 743 808 744 priv->bytes += count; ··· 814 750 { 815 751 struct fpga_dev *priv = filp->private_data; 816 752 return simple_read_from_buffer(buf, count, f_pos, 817 - priv->vb.vaddr, priv->bytes); 753 + priv->vaddr, priv->bytes); 818 754 } 819 755 820 756 static loff_t fpga_llseek(struct file *filp, loff_t offset, int origin) ··· 1016 952 priv->dev = &op->dev; 1017 953 mutex_init(&priv->lock); 1018 954 init_completion(&priv->completion); 1019 - videobuf_dma_init(&priv->vb); 1020 955 1021 956 dev_set_drvdata(priv->dev, priv); 1022 957 dma_cap_zero(mask);