blob: 8dd0562de287c4984427a2614d8e7e98e89d7ae8 [file] [log] [blame]
Thomas Gleixner77512ba2019-06-03 07:44:53 +02001// SPDX-License-Identifier: GPL-2.0-only
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -03002/*
Guennadi Liakhovetski07051352008-04-22 14:42:13 -03003 * helper functions for SG DMA video4linux capture buffers
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -03004 *
Magnus Damm5d6aaf52008-07-16 21:27:49 -03005 * The functions expect the hardware being able to scatter gather
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -03006 * (i.e. the buffers are not linear in physical memory, but fragmented
7 * into PAGE_SIZE chunks). They also assume the driver does not need
8 * to touch the video data.
9 *
Mauro Carvalho Chehab32590812018-04-25 05:34:48 -040010 * (c) 2007 Mauro Carvalho Chehab, <mchehab@kernel.org>
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030011 *
12 * Highly based on video-buf written originally by:
13 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
Mauro Carvalho Chehab32590812018-04-25 05:34:48 -040014 * (c) 2006 Mauro Carvalho Chehab, <mchehab@kernel.org>
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030015 * (c) 2006 Ted Walther and John Sokol
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030016 */
17
18#include <linux/init.h>
19#include <linux/module.h>
20#include <linux/moduleparam.h>
Ingo Molnar589ee622017-02-04 00:16:44 +010021#include <linux/sched/mm.h>
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030022#include <linux/slab.h>
23#include <linux/interrupt.h>
Mike Rapoport65fddcf2020-06-08 21:32:42 -070024#include <linux/pgtable.h>
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030025
Guennadi Liakhovetski07051352008-04-22 14:42:13 -030026#include <linux/dma-mapping.h>
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030027#include <linux/vmalloc.h>
28#include <linux/pagemap.h>
Ralf Baechle11763602007-10-23 20:42:11 +020029#include <linux/scatterlist.h>
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030030#include <asm/page.h>
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030031
32#include <media/videobuf-dma-sg.h>
33
34#define MAGIC_DMABUF 0x19721112
35#define MAGIC_SG_MEM 0x17890714
36
Pawel Osciak7a022642010-03-17 04:01:04 -030037#define MAGIC_CHECK(is, should) \
38 if (unlikely((is) != (should))) { \
39 printk(KERN_ERR "magic mismatch: %x (expected %x)\n", \
40 is, should); \
41 BUG(); \
42 }
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030043
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030044static int debug;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030045module_param(debug, int, 0644);
46
Guennadi Liakhovetski07051352008-04-22 14:42:13 -030047MODULE_DESCRIPTION("helper module to manage video4linux dma sg buffers");
Mauro Carvalho Chehab32590812018-04-25 05:34:48 -040048MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@kernel.org>");
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030049MODULE_LICENSE("GPL");
50
Pawel Osciak7a022642010-03-17 04:01:04 -030051#define dprintk(level, fmt, arg...) \
52 if (debug >= level) \
53 printk(KERN_DEBUG "vbuf-sg: " fmt , ## arg)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030054
55/* --------------------------------------------------------------------- */
56
Laurent Pinchart71817722010-05-11 10:36:32 -030057/*
58 * Return a scatterlist for some page-aligned vmalloc()'ed memory
59 * block (NULL on errors). Memory for the scatterlist is allocated
60 * using kmalloc. The caller must free the memory.
61 */
62static struct scatterlist *videobuf_vmalloc_to_sg(unsigned char *virt,
63 int nr_pages)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030064{
65 struct scatterlist *sglist;
66 struct page *pg;
67 int i;
68
Kees Cookfad953c2018-06-12 14:27:37 -070069 sglist = vzalloc(array_size(nr_pages, sizeof(*sglist)));
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030070 if (NULL == sglist)
71 return NULL;
Jens Axboe45711f12007-10-22 21:19:53 +020072 sg_init_table(sglist, nr_pages);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030073 for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) {
74 pg = vmalloc_to_page(virt);
75 if (NULL == pg)
76 goto err;
77 BUG_ON(PageHighMem(pg));
Jens Axboe642f149032007-10-24 11:20:47 +020078 sg_set_page(&sglist[i], pg, PAGE_SIZE, 0);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030079 }
80 return sglist;
81
Pawel Osciak7a022642010-03-17 04:01:04 -030082err:
Cohen David.A1010ed12009-05-11 11:00:20 -030083 vfree(sglist);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030084 return NULL;
85}
86
Laurent Pinchart71817722010-05-11 10:36:32 -030087/*
88 * Return a scatterlist for a an array of userpages (NULL on errors).
89 * Memory for the scatterlist is allocated using kmalloc. The caller
90 * must free the memory.
91 */
92static struct scatterlist *videobuf_pages_to_sg(struct page **pages,
Hans Verkuil2fc11532010-09-07 06:10:45 -030093 int nr_pages, int offset, size_t size)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030094{
95 struct scatterlist *sglist;
Christophe Jailleta47cacb2008-07-04 06:33:22 -030096 int i;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -030097
98 if (NULL == pages[0])
99 return NULL;
Kees Cook42bc47b2018-06-12 14:27:11 -0700100 sglist = vmalloc(array_size(nr_pages, sizeof(*sglist)));
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300101 if (NULL == sglist)
102 return NULL;
Jens Axboe45711f12007-10-22 21:19:53 +0200103 sg_init_table(sglist, nr_pages);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300104
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300105 if (PageHighMem(pages[0]))
106 /* DMA to highmem pages might not work */
107 goto highmem;
Newson Edouard45f239a2011-04-19 11:54:54 -0300108 sg_set_page(&sglist[0], pages[0],
109 min_t(size_t, PAGE_SIZE - offset, size), offset);
110 size -= min_t(size_t, PAGE_SIZE - offset, size);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300111 for (i = 1; i < nr_pages; i++) {
112 if (NULL == pages[i])
113 goto nopage;
114 if (PageHighMem(pages[i]))
115 goto highmem;
Mauro Carvalho Chehab1bede752010-10-07 09:31:33 -0300116 sg_set_page(&sglist[i], pages[i], min_t(size_t, PAGE_SIZE, size), 0);
117 size -= min_t(size_t, PAGE_SIZE, size);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300118 }
119 return sglist;
120
Pawel Osciak7a022642010-03-17 04:01:04 -0300121nopage:
122 dprintk(2, "sgl: oops - no page\n");
Cohen David.A1010ed12009-05-11 11:00:20 -0300123 vfree(sglist);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300124 return NULL;
125
Pawel Osciak7a022642010-03-17 04:01:04 -0300126highmem:
127 dprintk(2, "sgl: oops - highmem page\n");
Cohen David.A1010ed12009-05-11 11:00:20 -0300128 vfree(sglist);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300129 return NULL;
130}
131
132/* --------------------------------------------------------------------- */
133
Pawel Osciak7a022642010-03-17 04:01:04 -0300134struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300135{
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300136 struct videobuf_dma_sg_memory *mem = buf->priv;
137 BUG_ON(!mem);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300138
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300139 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300140
141 return &mem->dma;
142}
Pawel Osciak7a022642010-03-17 04:01:04 -0300143EXPORT_SYMBOL_GPL(videobuf_to_dma);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300144
Hans Verkuil861360a2014-12-23 09:46:27 -0300145static void videobuf_dma_init(struct videobuf_dmabuf *dma)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300146{
Pawel Osciak7a022642010-03-17 04:01:04 -0300147 memset(dma, 0, sizeof(*dma));
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300148 dma->magic = MAGIC_DMABUF;
149}
150
Maxim Levitsky99001322007-09-27 20:34:09 -0300151static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
152 int direction, unsigned long data, unsigned long size)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300153{
Pawel Osciak7a022642010-03-17 04:01:04 -0300154 unsigned long first, last;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300155 int err, rw = 0;
Lorenzo Stoakes768ae302016-10-13 01:20:16 +0100156 unsigned int flags = FOLL_FORCE;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300157
158 dma->direction = direction;
159 switch (dma->direction) {
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300160 case DMA_FROM_DEVICE:
161 rw = READ;
162 break;
163 case DMA_TO_DEVICE:
164 rw = WRITE;
165 break;
166 default:
167 BUG();
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300168 }
169
170 first = (data & PAGE_MASK) >> PAGE_SHIFT;
171 last = ((data+size-1) & PAGE_MASK) >> PAGE_SHIFT;
Hans Verkuil2fc11532010-09-07 06:10:45 -0300172 dma->offset = data & ~PAGE_MASK;
173 dma->size = size;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300174 dma->nr_pages = last-first+1;
Kees Cook6da2ec52018-06-12 13:55:00 -0700175 dma->pages = kmalloc_array(dma->nr_pages, sizeof(struct page *),
176 GFP_KERNEL);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300177 if (NULL == dma->pages)
178 return -ENOMEM;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300179
Lorenzo Stoakes768ae302016-10-13 01:20:16 +0100180 if (rw == READ)
181 flags |= FOLL_WRITE;
182
Mauro Carvalho Chehab1faa39e2020-09-01 11:09:26 +0200183 dprintk(1, "init user [0x%lx+0x%lx => %lu pages]\n",
Pawel Osciak7a022642010-03-17 04:01:04 -0300184 data, size, dma->nr_pages);
185
John Hubbard1f815af2020-01-30 22:13:20 -0800186 err = pin_user_pages(data & PAGE_MASK, dma->nr_pages,
Ira Weiny932f4a62019-05-13 17:17:03 -0700187 flags | FOLL_LONGTERM, dma->pages, NULL);
Maxim Levitsky99001322007-09-27 20:34:09 -0300188
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300189 if (err != dma->nr_pages) {
190 dma->nr_pages = (err >= 0) ? err : 0;
Mauro Carvalho Chehab1faa39e2020-09-01 11:09:26 +0200191 dprintk(1, "pin_user_pages: err=%d [%lu]\n", err,
Dan Williamsb70131d2017-11-29 16:10:43 -0800192 dma->nr_pages);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300193 return err < 0 ? err : -EINVAL;
194 }
195 return 0;
196}
197
Hans Verkuil861360a2014-12-23 09:46:27 -0300198static int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
Maxim Levitsky99001322007-09-27 20:34:09 -0300199 unsigned long data, unsigned long size)
200{
201 int ret;
Pawel Osciak7a022642010-03-17 04:01:04 -0300202
Michel Lespinassed8ed45c2020-06-08 21:33:25 -0700203 mmap_read_lock(current->mm);
Maxim Levitsky99001322007-09-27 20:34:09 -0300204 ret = videobuf_dma_init_user_locked(dma, direction, data, size);
Michel Lespinassed8ed45c2020-06-08 21:33:25 -0700205 mmap_read_unlock(current->mm);
Maxim Levitsky99001322007-09-27 20:34:09 -0300206
207 return ret;
208}
209
Hans Verkuil861360a2014-12-23 09:46:27 -0300210static int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
Mauro Carvalho Chehab1faa39e2020-09-01 11:09:26 +0200211 unsigned long nr_pages)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300212{
James Harper7b4eeed2014-06-12 06:53:38 -0300213 int i;
214
Mauro Carvalho Chehab1faa39e2020-09-01 11:09:26 +0200215 dprintk(1, "init kernel [%lu pages]\n", nr_pages);
Pawel Osciak7a022642010-03-17 04:01:04 -0300216
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300217 dma->direction = direction;
James Harper7b4eeed2014-06-12 06:53:38 -0300218 dma->vaddr_pages = kcalloc(nr_pages, sizeof(*dma->vaddr_pages),
219 GFP_KERNEL);
220 if (!dma->vaddr_pages)
221 return -ENOMEM;
222
223 dma->dma_addr = kcalloc(nr_pages, sizeof(*dma->dma_addr), GFP_KERNEL);
224 if (!dma->dma_addr) {
225 kfree(dma->vaddr_pages);
226 return -ENOMEM;
227 }
228 for (i = 0; i < nr_pages; i++) {
229 void *addr;
230
231 addr = dma_alloc_coherent(dma->dev, PAGE_SIZE,
232 &(dma->dma_addr[i]), GFP_KERNEL);
233 if (addr == NULL)
234 goto out_free_pages;
235
236 dma->vaddr_pages[i] = virt_to_page(addr);
237 }
238 dma->vaddr = vmap(dma->vaddr_pages, nr_pages, VM_MAP | VM_IOREMAP,
239 PAGE_KERNEL);
Laurent Pinchartbb6dbe72010-05-11 10:36:34 -0300240 if (NULL == dma->vaddr) {
Mauro Carvalho Chehab1faa39e2020-09-01 11:09:26 +0200241 dprintk(1, "vmalloc_32(%lu pages) failed\n", nr_pages);
James Harper7b4eeed2014-06-12 06:53:38 -0300242 goto out_free_pages;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300243 }
Pawel Osciak7a022642010-03-17 04:01:04 -0300244
Mauro Carvalho Chehab1faa39e2020-09-01 11:09:26 +0200245 dprintk(1, "vmalloc is at addr %p, size=%lu\n",
Mauro Carvalho Chehabb1a5dea62018-03-22 15:00:32 -0400246 dma->vaddr, nr_pages << PAGE_SHIFT);
Pawel Osciak7a022642010-03-17 04:01:04 -0300247
Laurent Pinchartbb6dbe72010-05-11 10:36:34 -0300248 memset(dma->vaddr, 0, nr_pages << PAGE_SHIFT);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300249 dma->nr_pages = nr_pages;
Pawel Osciak7a022642010-03-17 04:01:04 -0300250
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300251 return 0;
James Harper7b4eeed2014-06-12 06:53:38 -0300252out_free_pages:
253 while (i > 0) {
Dan Carpenter23d30902014-08-05 05:11:13 -0300254 void *addr;
255
James Harper7b4eeed2014-06-12 06:53:38 -0300256 i--;
Dan Carpenter23d30902014-08-05 05:11:13 -0300257 addr = page_address(dma->vaddr_pages[i]);
258 dma_free_coherent(dma->dev, PAGE_SIZE, addr, dma->dma_addr[i]);
James Harper7b4eeed2014-06-12 06:53:38 -0300259 }
260 kfree(dma->dma_addr);
261 dma->dma_addr = NULL;
262 kfree(dma->vaddr_pages);
263 dma->vaddr_pages = NULL;
264
265 return -ENOMEM;
266
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300267}
268
Hans Verkuil861360a2014-12-23 09:46:27 -0300269static int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
Mauro Carvalho Chehab1faa39e2020-09-01 11:09:26 +0200270 dma_addr_t addr, unsigned long nr_pages)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300271{
Mauro Carvalho Chehab1faa39e2020-09-01 11:09:26 +0200272 dprintk(1, "init overlay [%lu pages @ bus 0x%lx]\n",
Pawel Osciak7a022642010-03-17 04:01:04 -0300273 nr_pages, (unsigned long)addr);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300274 dma->direction = direction;
Pawel Osciak7a022642010-03-17 04:01:04 -0300275
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300276 if (0 == addr)
277 return -EINVAL;
278
279 dma->bus_addr = addr;
280 dma->nr_pages = nr_pages;
Pawel Osciak7a022642010-03-17 04:01:04 -0300281
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300282 return 0;
283}
284
Hans Verkuil861360a2014-12-23 09:46:27 -0300285static int videobuf_dma_map(struct device *dev, struct videobuf_dmabuf *dma)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300286{
Pawel Osciak7a022642010-03-17 04:01:04 -0300287 MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300288 BUG_ON(0 == dma->nr_pages);
289
290 if (dma->pages) {
291 dma->sglist = videobuf_pages_to_sg(dma->pages, dma->nr_pages,
Hans Verkuil2fc11532010-09-07 06:10:45 -0300292 dma->offset, dma->size);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300293 }
Laurent Pinchartbb6dbe72010-05-11 10:36:34 -0300294 if (dma->vaddr) {
295 dma->sglist = videobuf_vmalloc_to_sg(dma->vaddr,
Pawel Osciak7a022642010-03-17 04:01:04 -0300296 dma->nr_pages);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300297 }
298 if (dma->bus_addr) {
Cohen David.A1010ed12009-05-11 11:00:20 -0300299 dma->sglist = vmalloc(sizeof(*dma->sglist));
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300300 if (NULL != dma->sglist) {
Pawel Osciak7a022642010-03-17 04:01:04 -0300301 dma->sglen = 1;
302 sg_dma_address(&dma->sglist[0]) = dma->bus_addr
303 & PAGE_MASK;
304 dma->sglist[0].offset = dma->bus_addr & ~PAGE_MASK;
305 sg_dma_len(&dma->sglist[0]) = dma->nr_pages * PAGE_SIZE;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300306 }
307 }
308 if (NULL == dma->sglist) {
Pawel Osciak7a022642010-03-17 04:01:04 -0300309 dprintk(1, "scatterlist is NULL\n");
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300310 return -ENOMEM;
311 }
312 if (!dma->bus_addr) {
Laurent Pinchart95268402010-05-11 10:36:30 -0300313 dma->sglen = dma_map_sg(dev, dma->sglist,
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300314 dma->nr_pages, dma->direction);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300315 if (0 == dma->sglen) {
316 printk(KERN_WARNING
Pawel Osciak7a022642010-03-17 04:01:04 -0300317 "%s: videobuf_map_sg failed\n", __func__);
Cohen David.A1010ed12009-05-11 11:00:20 -0300318 vfree(dma->sglist);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300319 dma->sglist = NULL;
320 dma->sglen = 0;
Figo.zhang92051b22009-06-10 23:17:27 -0300321 return -ENOMEM;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300322 }
323 }
Pawel Osciak7a022642010-03-17 04:01:04 -0300324
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300325 return 0;
326}
327
Laurent Pinchart95268402010-05-11 10:36:30 -0300328int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300329{
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300330 MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
Pawel Osciak7a022642010-03-17 04:01:04 -0300331
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300332 if (!dma->sglen)
333 return 0;
334
Robin Murphy45730272018-04-30 12:56:28 -0400335 dma_unmap_sg(dev, dma->sglist, dma->nr_pages, dma->direction);
Mauro Carvalho Chehab5ddff432007-10-08 11:43:49 -0300336
Cohen David.A1010ed12009-05-11 11:00:20 -0300337 vfree(dma->sglist);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300338 dma->sglist = NULL;
339 dma->sglen = 0;
Pawel Osciak7a022642010-03-17 04:01:04 -0300340
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300341 return 0;
342}
Pawel Osciak7a022642010-03-17 04:01:04 -0300343EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300344
345int videobuf_dma_free(struct videobuf_dmabuf *dma)
346{
Pawel Osciak7a022642010-03-17 04:01:04 -0300347 int i;
348 MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300349 BUG_ON(dma->sglen);
350
351 if (dma->pages) {
John Hubbardf1f6a7d2020-01-30 22:13:35 -0800352 unpin_user_pages_dirty_lock(dma->pages, dma->nr_pages,
353 dma->direction == DMA_FROM_DEVICE);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300354 kfree(dma->pages);
355 dma->pages = NULL;
356 }
357
James Harper7b4eeed2014-06-12 06:53:38 -0300358 if (dma->dma_addr) {
359 for (i = 0; i < dma->nr_pages; i++) {
360 void *addr;
361
362 addr = page_address(dma->vaddr_pages[i]);
363 dma_free_coherent(dma->dev, PAGE_SIZE, addr,
364 dma->dma_addr[i]);
365 }
366 kfree(dma->dma_addr);
367 dma->dma_addr = NULL;
368 kfree(dma->vaddr_pages);
369 dma->vaddr_pages = NULL;
370 vunmap(dma->vaddr);
371 dma->vaddr = NULL;
372 }
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300373
Pawel Osciak7a022642010-03-17 04:01:04 -0300374 if (dma->bus_addr)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300375 dma->bus_addr = 0;
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300376 dma->direction = DMA_NONE;
Pawel Osciak7a022642010-03-17 04:01:04 -0300377
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300378 return 0;
379}
Pawel Osciak7a022642010-03-17 04:01:04 -0300380EXPORT_SYMBOL_GPL(videobuf_dma_free);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300381
382/* --------------------------------------------------------------------- */
383
Pawel Osciak7a022642010-03-17 04:01:04 -0300384static void videobuf_vm_open(struct vm_area_struct *vma)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300385{
386 struct videobuf_mapping *map = vma->vm_private_data;
387
Pawel Osciak7a022642010-03-17 04:01:04 -0300388 dprintk(2, "vm_open %p [count=%d,vma=%08lx-%08lx]\n", map,
389 map->count, vma->vm_start, vma->vm_end);
390
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300391 map->count++;
392}
393
Pawel Osciak7a022642010-03-17 04:01:04 -0300394static void videobuf_vm_close(struct vm_area_struct *vma)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300395{
396 struct videobuf_mapping *map = vma->vm_private_data;
397 struct videobuf_queue *q = map->q;
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300398 struct videobuf_dma_sg_memory *mem;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300399 int i;
400
Pawel Osciak7a022642010-03-17 04:01:04 -0300401 dprintk(2, "vm_close %p [count=%d,vma=%08lx-%08lx]\n", map,
402 map->count, vma->vm_start, vma->vm_end);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300403
Hans Verkuilcca36e22014-01-03 08:10:49 -0300404 map->count--;
405 if (0 == map->count) {
Pawel Osciak7a022642010-03-17 04:01:04 -0300406 dprintk(1, "munmap %p q=%p\n", map, q);
Hans Verkuilcca36e22014-01-03 08:10:49 -0300407 videobuf_queue_lock(q);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300408 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
409 if (NULL == q->bufs[i])
410 continue;
Pawel Osciak7a022642010-03-17 04:01:04 -0300411 mem = q->bufs[i]->priv;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300412 if (!mem)
413 continue;
414
Pawel Osciak7a022642010-03-17 04:01:04 -0300415 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300416
Mauro Carvalho Chehab851c0c92007-09-27 18:25:44 -0300417 if (q->bufs[i]->map != map)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300418 continue;
Mauro Carvalho Chehab851c0c92007-09-27 18:25:44 -0300419 q->bufs[i]->map = NULL;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300420 q->bufs[i]->baddr = 0;
Pawel Osciak7a022642010-03-17 04:01:04 -0300421 q->ops->buf_release(q, q->bufs[i]);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300422 }
Hans Verkuilcca36e22014-01-03 08:10:49 -0300423 videobuf_queue_unlock(q);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300424 kfree(map);
425 }
426 return;
427}
428
429/*
430 * Get a anonymous page for the mapping. Make sure we can DMA to that
431 * memory location with 32bit PCI devices (i.e. don't use highmem for
432 * now ...). Bounce buffers don't work very well for the data rates
433 * video capture has.
434 */
Souptick Joarder62d4cfd2018-04-18 14:47:16 -0400435static vm_fault_t videobuf_vm_fault(struct vm_fault *vmf)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300436{
Dave Jiang11bac802017-02-24 14:56:41 -0800437 struct vm_area_struct *vma = vmf->vma;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300438 struct page *page;
439
Pawel Osciak7a022642010-03-17 04:01:04 -0300440 dprintk(3, "fault: fault @ %08lx [vma %08lx-%08lx]\n",
Jan Kara1a29d852016-12-14 15:07:01 -0800441 vmf->address, vma->vm_start, vma->vm_end);
Pawel Osciak7a022642010-03-17 04:01:04 -0300442
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300443 page = alloc_page(GFP_USER | __GFP_DMA32);
444 if (!page)
Nick Piggin105354a2007-12-07 17:57:38 -0300445 return VM_FAULT_OOM;
Jan Kara1a29d852016-12-14 15:07:01 -0800446 clear_user_highpage(page, vmf->address);
Nick Piggin105354a2007-12-07 17:57:38 -0300447 vmf->page = page;
Pawel Osciak7a022642010-03-17 04:01:04 -0300448
Nick Piggin105354a2007-12-07 17:57:38 -0300449 return 0;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300450}
451
Pawel Osciak7a022642010-03-17 04:01:04 -0300452static const struct vm_operations_struct videobuf_vm_ops = {
453 .open = videobuf_vm_open,
454 .close = videobuf_vm_close,
455 .fault = videobuf_vm_fault,
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300456};
457
458/* ---------------------------------------------------------------------
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300459 * SG handlers for the generic methods
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300460 */
461
462/* Allocated area consists on 3 parts:
463 struct video_buffer
464 struct <driver>_buffer (cx88_buffer, saa7134_buf, ...)
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300465 struct videobuf_dma_sg_memory
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300466 */
467
Pawel Osciak33c38282010-05-11 10:36:28 -0300468static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300469{
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300470 struct videobuf_dma_sg_memory *mem;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300471 struct videobuf_buffer *vb;
472
Pawel Osciak7a022642010-03-17 04:01:04 -0300473 vb = kzalloc(size + sizeof(*mem), GFP_KERNEL);
Pawel Osciakbee527f2010-02-22 13:10:06 -0300474 if (!vb)
475 return vb;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300476
Pawel Osciak7a022642010-03-17 04:01:04 -0300477 mem = vb->priv = ((char *)vb) + size;
478 mem->magic = MAGIC_SG_MEM;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300479
480 videobuf_dma_init(&mem->dma);
481
Pawel Osciak7a022642010-03-17 04:01:04 -0300482 dprintk(1, "%s: allocated at %p(%ld+%ld) & %p(%ld)\n",
483 __func__, vb, (long)sizeof(*vb), (long)size - sizeof(*vb),
484 mem, (long)sizeof(*mem));
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300485
486 return vb;
487}
488
Hans Verkuil037c75e2010-03-28 08:18:37 -0300489static void *__videobuf_to_vaddr(struct videobuf_buffer *buf)
Mauro Carvalho Chehab59d34482008-04-13 15:10:00 -0300490{
491 struct videobuf_dma_sg_memory *mem = buf->priv;
492 BUG_ON(!mem);
493
494 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
495
Laurent Pinchartbb6dbe72010-05-11 10:36:34 -0300496 return mem->dma.vaddr;
Mauro Carvalho Chehab59d34482008-04-13 15:10:00 -0300497}
498
Pawel Osciak7a022642010-03-17 04:01:04 -0300499static int __videobuf_iolock(struct videobuf_queue *q,
500 struct videobuf_buffer *vb,
501 struct v4l2_framebuffer *fbuf)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300502{
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300503 struct videobuf_dma_sg_memory *mem = vb->priv;
Mauro Carvalho Chehab1faa39e2020-09-01 11:09:26 +0200504 unsigned long pages;
505 dma_addr_t bus;
506 int err;
507
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300508 BUG_ON(!mem);
509
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300510 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300511
James Harper7b4eeed2014-06-12 06:53:38 -0300512 if (!mem->dma.dev)
513 mem->dma.dev = q->dev;
514 else
515 WARN_ON(mem->dma.dev != q->dev);
516
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300517 switch (vb->memory) {
518 case V4L2_MEMORY_MMAP:
519 case V4L2_MEMORY_USERPTR:
520 if (0 == vb->baddr) {
521 /* no userspace addr -- kernel bounce buffer */
522 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
Pawel Osciak7a022642010-03-17 04:01:04 -0300523 err = videobuf_dma_init_kernel(&mem->dma,
524 DMA_FROM_DEVICE,
525 pages);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300526 if (0 != err)
527 return err;
Maxim Levitsky99001322007-09-27 20:34:09 -0300528 } else if (vb->memory == V4L2_MEMORY_USERPTR) {
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300529 /* dma directly to userspace */
Pawel Osciak7a022642010-03-17 04:01:04 -0300530 err = videobuf_dma_init_user(&mem->dma,
531 DMA_FROM_DEVICE,
532 vb->baddr, vb->bsize);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300533 if (0 != err)
534 return err;
Maxim Levitsky99001322007-09-27 20:34:09 -0300535 } else {
536 /* NOTE: HACK: videobuf_iolock on V4L2_MEMORY_MMAP
537 buffers can only be called from videobuf_qbuf
Michel Lespinassec1e8d7c2020-06-08 21:33:54 -0700538 we take current->mm->mmap_lock there, to prevent
Maxim Levitsky99001322007-09-27 20:34:09 -0300539 locking inversion, so don't take it here */
540
541 err = videobuf_dma_init_user_locked(&mem->dma,
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300542 DMA_FROM_DEVICE,
Maxim Levitsky99001322007-09-27 20:34:09 -0300543 vb->baddr, vb->bsize);
544 if (0 != err)
545 return err;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300546 }
547 break;
548 case V4L2_MEMORY_OVERLAY:
549 if (NULL == fbuf)
550 return -EINVAL;
551 /* FIXME: need sanity checks for vb->boff */
552 /*
553 * Using a double cast to avoid compiler warnings when
554 * building for PAE. Compiler doesn't like direct casting
555 * of a 32 bit ptr to 64 bit integer.
556 */
557 bus = (dma_addr_t)(unsigned long)fbuf->base + vb->boff;
558 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300559 err = videobuf_dma_init_overlay(&mem->dma, DMA_FROM_DEVICE,
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300560 bus, pages);
561 if (0 != err)
562 return err;
563 break;
564 default:
565 BUG();
566 }
Laurent Pinchart95268402010-05-11 10:36:30 -0300567 err = videobuf_dma_map(q->dev, &mem->dma);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300568 if (0 != err)
569 return err;
570
571 return 0;
572}
573
574static int __videobuf_sync(struct videobuf_queue *q,
575 struct videobuf_buffer *buf)
576{
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300577 struct videobuf_dma_sg_memory *mem = buf->priv;
Mauro Carvalho Chehab97f81052010-05-05 16:23:09 -0300578 BUG_ON(!mem || !mem->dma.sglen);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300579
Mauro Carvalho Chehab97f81052010-05-05 16:23:09 -0300580 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
581 MAGIC_CHECK(mem->dma.magic, MAGIC_DMABUF);
582
583 dma_sync_sg_for_cpu(q->dev, mem->dma.sglist,
Robin Murphy45730272018-04-30 12:56:28 -0400584 mem->dma.nr_pages, mem->dma.direction);
Mauro Carvalho Chehab97f81052010-05-05 16:23:09 -0300585
586 return 0;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300587}
588
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300589static int __videobuf_mmap_mapper(struct videobuf_queue *q,
Hans Verkuil0b62b732010-03-28 09:09:05 -0300590 struct videobuf_buffer *buf,
591 struct vm_area_struct *vma)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300592{
Hans Verkuil0b62b732010-03-28 09:09:05 -0300593 struct videobuf_dma_sg_memory *mem = buf->priv;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300594 struct videobuf_mapping *map;
Mauro Carvalho Chehab474675a2010-04-25 11:23:52 -0300595 unsigned int first, last, size = 0, i;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300596 int retval;
597
598 retval = -EINVAL;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300599
Hans Verkuil0b62b732010-03-28 09:09:05 -0300600 BUG_ON(!mem);
601 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
602
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300603 /* look for first buffer to map */
604 for (first = 0; first < VIDEO_MAX_FRAME; first++) {
Hans Verkuil0b62b732010-03-28 09:09:05 -0300605 if (buf == q->bufs[first]) {
606 size = PAGE_ALIGN(q->bufs[first]->bsize);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300607 break;
Hans Verkuil0b62b732010-03-28 09:09:05 -0300608 }
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300609 }
Hans Verkuil0b62b732010-03-28 09:09:05 -0300610
611 /* paranoia, should never happen since buf is always valid. */
Mauro Carvalho Chehab474675a2010-04-25 11:23:52 -0300612 if (!size) {
Pawel Osciak7a022642010-03-17 04:01:04 -0300613 dprintk(1, "mmap app bug: offset invalid [offset=0x%lx]\n",
Hans Verkuil0b62b732010-03-28 09:09:05 -0300614 (vma->vm_pgoff << PAGE_SHIFT));
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300615 goto done;
616 }
617
Hans Verkuil0b62b732010-03-28 09:09:05 -0300618 last = first;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300619
620 /* create mapping + update buffer list */
621 retval = -ENOMEM;
Pawel Osciak7a022642010-03-17 04:01:04 -0300622 map = kmalloc(sizeof(struct videobuf_mapping), GFP_KERNEL);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300623 if (NULL == map)
624 goto done;
Brandon Philipsce540932008-04-02 18:10:59 -0300625
626 size = 0;
627 for (i = first; i <= last; i++) {
628 if (NULL == q->bufs[i])
629 continue;
Mauro Carvalho Chehab851c0c92007-09-27 18:25:44 -0300630 q->bufs[i]->map = map;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300631 q->bufs[i]->baddr = vma->vm_start + size;
Tuukka Toivonen7cbefad2009-07-23 10:56:25 -0300632 size += PAGE_ALIGN(q->bufs[i]->bsize);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300633 }
Brandon Philipsce540932008-04-02 18:10:59 -0300634
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300635 map->count = 1;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300636 map->q = q;
637 vma->vm_ops = &videobuf_vm_ops;
Konstantin Khlebnikov314e51b2012-10-08 16:29:02 -0700638 vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300639 vma->vm_flags &= ~VM_IO; /* using shared anonymous pages */
640 vma->vm_private_data = map;
Pawel Osciak7a022642010-03-17 04:01:04 -0300641 dprintk(1, "mmap %p: q=%p %08lx-%08lx pgoff %08lx bufs %d-%d\n",
642 map, q, vma->vm_start, vma->vm_end, vma->vm_pgoff, first, last);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300643 retval = 0;
644
Pawel Osciak7a022642010-03-17 04:01:04 -0300645done:
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300646 return retval;
647}
648
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300649static struct videobuf_qtype_ops sg_ops = {
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300650 .magic = MAGIC_QTYPE_OPS,
651
Pawel Osciak33c38282010-05-11 10:36:28 -0300652 .alloc_vb = __videobuf_alloc_vb,
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300653 .iolock = __videobuf_iolock,
654 .sync = __videobuf_sync,
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300655 .mmap_mapper = __videobuf_mmap_mapper,
Hans Verkuil037c75e2010-03-28 08:18:37 -0300656 .vaddr = __videobuf_to_vaddr,
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300657};
658
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300659void *videobuf_sg_alloc(size_t size)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300660{
661 struct videobuf_queue q;
662
663 /* Required to make generic handler to call __videobuf_alloc */
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300664 q.int_ops = &sg_ops;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300665
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300666 q.msize = size;
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300667
Pawel Osciak33c38282010-05-11 10:36:28 -0300668 return videobuf_alloc_vb(&q);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300669}
Pawel Osciak7a022642010-03-17 04:01:04 -0300670EXPORT_SYMBOL_GPL(videobuf_sg_alloc);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300671
Pawel Osciak7a022642010-03-17 04:01:04 -0300672void videobuf_queue_sg_init(struct videobuf_queue *q,
Jonathan Corbet38a54f32009-11-17 19:43:41 -0300673 const struct videobuf_queue_ops *ops,
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300674 struct device *dev,
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300675 spinlock_t *irqlock,
676 enum v4l2_buf_type type,
677 enum v4l2_field field,
678 unsigned int msize,
Hans Verkuil08bff032010-09-20 17:39:46 -0300679 void *priv,
680 struct mutex *ext_lock)
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300681{
Mauro Carvalho Chehabd4cae5a2007-10-08 12:20:02 -0300682 videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
Hans Verkuil08bff032010-09-20 17:39:46 -0300683 priv, &sg_ops, ext_lock);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300684}
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300685EXPORT_SYMBOL_GPL(videobuf_queue_sg_init);
Mauro Carvalho Chehab7a7d9a892007-08-23 16:26:14 -0300686