V4L/DVB (7237): Convert videobuf-dma-sg to generic DMA API
[linux-2.6] / drivers / media / video / videobuf-dma-sg.c
1 /*
2  * helper functions for SG DMA video4linux capture buffers
3  *
4  * The functions expect the hardware being able to scatter gatter
5  * (i.e. the buffers are not linear in physical memory, but fragmented
6  * into PAGE_SIZE chunks).  They also assume the driver does not need
7  * to touch the video data.
8  *
9  * (c) 2007 Mauro Carvalho Chehab, <mchehab@infradead.org>
10  *
11  * Highly based on video-buf written originally by:
12  * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
13  * (c) 2006 Mauro Carvalho Chehab, <mchehab@infradead.org>
14  * (c) 2006 Ted Walther and John Sokol
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 2
19  */
20
21 #include <linux/init.h>
22 #include <linux/module.h>
23 #include <linux/moduleparam.h>
24 #include <linux/slab.h>
25 #include <linux/interrupt.h>
26
27 #include <linux/dma-mapping.h>
28 #include <linux/vmalloc.h>
29 #include <linux/pagemap.h>
30 #include <linux/scatterlist.h>
31 #include <asm/page.h>
32 #include <asm/pgtable.h>
33
34 #include <media/videobuf-dma-sg.h>
35
36 #define MAGIC_DMABUF 0x19721112
37 #define MAGIC_SG_MEM 0x17890714
38
39 #define MAGIC_CHECK(is,should)  if (unlikely((is) != (should))) \
40         { printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); }
41
42 static int debug;
43 module_param(debug, int, 0644);
44
45 MODULE_DESCRIPTION("helper module to manage video4linux dma sg buffers");
46 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
47 MODULE_LICENSE("GPL");
48
49 #define dprintk(level, fmt, arg...)     if (debug >= level) \
50         printk(KERN_DEBUG "vbuf-sg: " fmt , ## arg)
51
52 /* --------------------------------------------------------------------- */
53
54 struct scatterlist*
55 videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
56 {
57         struct scatterlist *sglist;
58         struct page *pg;
59         int i;
60
61         sglist = kcalloc(nr_pages, sizeof(struct scatterlist), GFP_KERNEL);
62         if (NULL == sglist)
63                 return NULL;
64         sg_init_table(sglist, nr_pages);
65         for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) {
66                 pg = vmalloc_to_page(virt);
67                 if (NULL == pg)
68                         goto err;
69                 BUG_ON(PageHighMem(pg));
70                 sg_set_page(&sglist[i], pg, PAGE_SIZE, 0);
71         }
72         return sglist;
73
74  err:
75         kfree(sglist);
76         return NULL;
77 }
78
79 struct scatterlist*
80 videobuf_pages_to_sg(struct page **pages, int nr_pages, int offset)
81 {
82         struct scatterlist *sglist;
83         int i = 0;
84
85         if (NULL == pages[0])
86                 return NULL;
87         sglist = kcalloc(nr_pages, sizeof(*sglist), GFP_KERNEL);
88         if (NULL == sglist)
89                 return NULL;
90         sg_init_table(sglist, nr_pages);
91
92         if (NULL == pages[0])
93                 goto nopage;
94         if (PageHighMem(pages[0]))
95                 /* DMA to highmem pages might not work */
96                 goto highmem;
97         sg_set_page(&sglist[0], pages[0], PAGE_SIZE - offset, offset);
98         for (i = 1; i < nr_pages; i++) {
99                 if (NULL == pages[i])
100                         goto nopage;
101                 if (PageHighMem(pages[i]))
102                         goto highmem;
103                 sg_set_page(&sglist[i], pages[i], PAGE_SIZE, 0);
104         }
105         return sglist;
106
107  nopage:
108         dprintk(2,"sgl: oops - no page\n");
109         kfree(sglist);
110         return NULL;
111
112  highmem:
113         dprintk(2,"sgl: oops - highmem page\n");
114         kfree(sglist);
115         return NULL;
116 }
117
118 /* --------------------------------------------------------------------- */
119
120 struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf)
121 {
122         struct videobuf_dma_sg_memory *mem = buf->priv;
123         BUG_ON(!mem);
124
125         MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
126
127         return &mem->dma;
128 }
129
130 void videobuf_dma_init(struct videobuf_dmabuf *dma)
131 {
132         memset(dma,0,sizeof(*dma));
133         dma->magic = MAGIC_DMABUF;
134 }
135
136 static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
137                         int direction, unsigned long data, unsigned long size)
138 {
139         unsigned long first,last;
140         int err, rw = 0;
141
142         dma->direction = direction;
143         switch (dma->direction) {
144         case DMA_FROM_DEVICE:
145                 rw = READ;
146                 break;
147         case DMA_TO_DEVICE:
148                 rw = WRITE;
149                 break;
150         default:
151                 BUG();
152         }
153
154         first = (data          & PAGE_MASK) >> PAGE_SHIFT;
155         last  = ((data+size-1) & PAGE_MASK) >> PAGE_SHIFT;
156         dma->offset   = data & ~PAGE_MASK;
157         dma->nr_pages = last-first+1;
158         dma->pages = kmalloc(dma->nr_pages * sizeof(struct page*),
159                              GFP_KERNEL);
160         if (NULL == dma->pages)
161                 return -ENOMEM;
162         dprintk(1,"init user [0x%lx+0x%lx => %d pages]\n",
163                 data,size,dma->nr_pages);
164
165         dma->varea = (void *) data;
166
167
168         err = get_user_pages(current,current->mm,
169                              data & PAGE_MASK, dma->nr_pages,
170                              rw == READ, 1, /* force */
171                              dma->pages, NULL);
172
173         if (err != dma->nr_pages) {
174                 dma->nr_pages = (err >= 0) ? err : 0;
175                 dprintk(1,"get_user_pages: err=%d [%d]\n",err,dma->nr_pages);
176                 return err < 0 ? err : -EINVAL;
177         }
178         return 0;
179 }
180
181 int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
182                            unsigned long data, unsigned long size)
183 {
184         int ret;
185         down_read(&current->mm->mmap_sem);
186         ret = videobuf_dma_init_user_locked(dma, direction, data, size);
187         up_read(&current->mm->mmap_sem);
188
189         return ret;
190 }
191
192 int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
193                              int nr_pages)
194 {
195         dprintk(1,"init kernel [%d pages]\n",nr_pages);
196         dma->direction = direction;
197         dma->vmalloc = vmalloc_32(nr_pages << PAGE_SHIFT);
198         if (NULL == dma->vmalloc) {
199                 dprintk(1,"vmalloc_32(%d pages) failed\n",nr_pages);
200                 return -ENOMEM;
201         }
202         dprintk(1,"vmalloc is at addr 0x%08lx, size=%d\n",
203                                 (unsigned long)dma->vmalloc,
204                                 nr_pages << PAGE_SHIFT);
205         memset(dma->vmalloc,0,nr_pages << PAGE_SHIFT);
206         dma->nr_pages = nr_pages;
207         return 0;
208 }
209
210 int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
211                               dma_addr_t addr, int nr_pages)
212 {
213         dprintk(1,"init overlay [%d pages @ bus 0x%lx]\n",
214                 nr_pages,(unsigned long)addr);
215         dma->direction = direction;
216         if (0 == addr)
217                 return -EINVAL;
218
219         dma->bus_addr = addr;
220         dma->nr_pages = nr_pages;
221         return 0;
222 }
223
224 int videobuf_dma_map(struct videobuf_queue* q, struct videobuf_dmabuf *dma)
225 {
226         MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
227         BUG_ON(0 == dma->nr_pages);
228
229         if (dma->pages) {
230                 dma->sglist = videobuf_pages_to_sg(dma->pages, dma->nr_pages,
231                                                    dma->offset);
232         }
233         if (dma->vmalloc) {
234                 dma->sglist = videobuf_vmalloc_to_sg
235                                                 (dma->vmalloc,dma->nr_pages);
236         }
237         if (dma->bus_addr) {
238                 dma->sglist = kmalloc(sizeof(struct scatterlist), GFP_KERNEL);
239                 if (NULL != dma->sglist) {
240                         dma->sglen  = 1;
241                         sg_dma_address(&dma->sglist[0]) = dma->bus_addr & PAGE_MASK;
242                         dma->sglist[0].offset           = dma->bus_addr & ~PAGE_MASK;
243                         sg_dma_len(&dma->sglist[0])     = dma->nr_pages * PAGE_SIZE;
244                 }
245         }
246         if (NULL == dma->sglist) {
247                 dprintk(1,"scatterlist is NULL\n");
248                 return -ENOMEM;
249         }
250         if (!dma->bus_addr) {
251                 dma->sglen = dma_map_sg(q->dev, dma->sglist,
252                                         dma->nr_pages, dma->direction);
253                 if (0 == dma->sglen) {
254                         printk(KERN_WARNING
255                                "%s: videobuf_map_sg failed\n",__FUNCTION__);
256                         kfree(dma->sglist);
257                         dma->sglist = NULL;
258                         dma->sglen = 0;
259                         return -EIO;
260                 }
261         }
262         return 0;
263 }
264
265 int videobuf_dma_sync(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
266 {
267         MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
268         BUG_ON(!dma->sglen);
269
270         dma_sync_sg_for_cpu(q->dev, dma->sglist, dma->nr_pages, dma->direction);
271         return 0;
272 }
273
274 int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
275 {
276         void                   *dev=q->dev;
277
278         MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
279         if (!dma->sglen)
280                 return 0;
281
282         dma_unmap_sg(q->dev, dma->sglist, dma->nr_pages, dma->direction);
283
284         kfree(dma->sglist);
285         dma->sglist = NULL;
286         dma->sglen = 0;
287         return 0;
288 }
289
290 int videobuf_dma_free(struct videobuf_dmabuf *dma)
291 {
292         MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
293         BUG_ON(dma->sglen);
294
295         if (dma->pages) {
296                 int i;
297                 for (i=0; i < dma->nr_pages; i++)
298                         page_cache_release(dma->pages[i]);
299                 kfree(dma->pages);
300                 dma->pages = NULL;
301         }
302
303         vfree(dma->vmalloc);
304         dma->vmalloc = NULL;
305         dma->varea = NULL;
306
307         if (dma->bus_addr) {
308                 dma->bus_addr = 0;
309         }
310         dma->direction = DMA_NONE;
311         return 0;
312 }
313
314 /* --------------------------------------------------------------------- */
315
316 int videobuf_sg_dma_map(struct device *dev, struct videobuf_dmabuf *dma)
317 {
318         struct videobuf_queue q;
319
320         q.dev = dev;
321
322         return videobuf_dma_map(&q, dma);
323 }
324
325 int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
326 {
327         struct videobuf_queue q;
328
329         q.dev = dev;
330
331         return videobuf_dma_unmap(&q, dma);
332 }
333
334 /* --------------------------------------------------------------------- */
335
336 static void
337 videobuf_vm_open(struct vm_area_struct *vma)
338 {
339         struct videobuf_mapping *map = vma->vm_private_data;
340
341         dprintk(2,"vm_open %p [count=%d,vma=%08lx-%08lx]\n",map,
342                 map->count,vma->vm_start,vma->vm_end);
343         map->count++;
344 }
345
346 static void
347 videobuf_vm_close(struct vm_area_struct *vma)
348 {
349         struct videobuf_mapping *map = vma->vm_private_data;
350         struct videobuf_queue *q = map->q;
351         struct videobuf_dma_sg_memory *mem;
352         int i;
353
354         dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map,
355                 map->count,vma->vm_start,vma->vm_end);
356
357         map->count--;
358         if (0 == map->count) {
359                 dprintk(1,"munmap %p q=%p\n",map,q);
360                 mutex_lock(&q->vb_lock);
361                 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
362                         if (NULL == q->bufs[i])
363                                 continue;
364                         mem=q->bufs[i]->priv;
365
366                         if (!mem)
367                                 continue;
368
369                         MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
370
371                         if (q->bufs[i]->map != map)
372                                 continue;
373                         q->bufs[i]->map   = NULL;
374                         q->bufs[i]->baddr = 0;
375                         q->ops->buf_release(q,q->bufs[i]);
376                 }
377                 mutex_unlock(&q->vb_lock);
378                 kfree(map);
379         }
380         return;
381 }
382
383 /*
384  * Get a anonymous page for the mapping.  Make sure we can DMA to that
385  * memory location with 32bit PCI devices (i.e. don't use highmem for
386  * now ...).  Bounce buffers don't work very well for the data rates
387  * video capture has.
388  */
389 static int
390 videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
391 {
392         struct page *page;
393
394         dprintk(3,"fault: fault @ %08lx [vma %08lx-%08lx]\n",
395                 (unsigned long)vmf->virtual_address,vma->vm_start,vma->vm_end);
396         page = alloc_page(GFP_USER | __GFP_DMA32);
397         if (!page)
398                 return VM_FAULT_OOM;
399         clear_user_page(page_address(page), (unsigned long)vmf->virtual_address,
400                         page);
401         vmf->page = page;
402         return 0;
403 }
404
405 static struct vm_operations_struct videobuf_vm_ops =
406 {
407         .open     = videobuf_vm_open,
408         .close    = videobuf_vm_close,
409         .fault    = videobuf_vm_fault,
410 };
411
412 /* ---------------------------------------------------------------------
413  * SG handlers for the generic methods
414  */
415
416 /* Allocated area consists on 3 parts:
417         struct video_buffer
418         struct <driver>_buffer (cx88_buffer, saa7134_buf, ...)
419         struct videobuf_dma_sg_memory
420  */
421
422 static void *__videobuf_alloc(size_t size)
423 {
424         struct videobuf_dma_sg_memory *mem;
425         struct videobuf_buffer *vb;
426
427         vb = kzalloc(size+sizeof(*mem),GFP_KERNEL);
428
429         mem = vb->priv = ((char *)vb)+size;
430         mem->magic=MAGIC_SG_MEM;
431
432         videobuf_dma_init(&mem->dma);
433
434         dprintk(1,"%s: allocated at %p(%ld+%ld) & %p(%ld)\n",
435                 __FUNCTION__,vb,(long)sizeof(*vb),(long)size-sizeof(*vb),
436                 mem,(long)sizeof(*mem));
437
438         return vb;
439 }
440
441 static int __videobuf_iolock (struct videobuf_queue* q,
442                               struct videobuf_buffer *vb,
443                               struct v4l2_framebuffer *fbuf)
444 {
445         int err,pages;
446         dma_addr_t bus;
447         struct videobuf_dma_sg_memory *mem = vb->priv;
448         BUG_ON(!mem);
449
450         MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
451
452         switch (vb->memory) {
453         case V4L2_MEMORY_MMAP:
454         case V4L2_MEMORY_USERPTR:
455                 if (0 == vb->baddr) {
456                         /* no userspace addr -- kernel bounce buffer */
457                         pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
458                         err = videobuf_dma_init_kernel( &mem->dma,
459                                                         DMA_FROM_DEVICE,
460                                                         pages );
461                         if (0 != err)
462                                 return err;
463                 } else if (vb->memory == V4L2_MEMORY_USERPTR) {
464                         /* dma directly to userspace */
465                         err = videobuf_dma_init_user( &mem->dma,
466                                                       DMA_FROM_DEVICE,
467                                                       vb->baddr,vb->bsize );
468                         if (0 != err)
469                                 return err;
470                 } else {
471                         /* NOTE: HACK: videobuf_iolock on V4L2_MEMORY_MMAP
472                         buffers can only be called from videobuf_qbuf
473                         we take current->mm->mmap_sem there, to prevent
474                         locking inversion, so don't take it here */
475
476                         err = videobuf_dma_init_user_locked(&mem->dma,
477                                                       DMA_FROM_DEVICE,
478                                                       vb->baddr, vb->bsize);
479                         if (0 != err)
480                                 return err;
481                 }
482                 break;
483         case V4L2_MEMORY_OVERLAY:
484                 if (NULL == fbuf)
485                         return -EINVAL;
486                 /* FIXME: need sanity checks for vb->boff */
487                 /*
488                  * Using a double cast to avoid compiler warnings when
489                  * building for PAE. Compiler doesn't like direct casting
490                  * of a 32 bit ptr to 64 bit integer.
491                  */
492                 bus   = (dma_addr_t)(unsigned long)fbuf->base + vb->boff;
493                 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
494                 err = videobuf_dma_init_overlay(&mem->dma, DMA_FROM_DEVICE,
495                                                 bus, pages);
496                 if (0 != err)
497                         return err;
498                 break;
499         default:
500                 BUG();
501         }
502         err = videobuf_dma_map(q, &mem->dma);
503         if (0 != err)
504                 return err;
505
506         return 0;
507 }
508
509 static int __videobuf_sync(struct videobuf_queue *q,
510                            struct videobuf_buffer *buf)
511 {
512         struct videobuf_dma_sg_memory *mem = buf->priv;
513         BUG_ON(!mem);
514         MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
515
516         return  videobuf_dma_sync(q,&mem->dma);
517 }
518
519 static int __videobuf_mmap_free(struct videobuf_queue *q)
520 {
521         int i;
522
523         for (i = 0; i < VIDEO_MAX_FRAME; i++) {
524                 if (q->bufs[i]) {
525                         if (q->bufs[i]->map)
526                                 return -EBUSY;
527                 }
528         }
529
530         return 0;
531 }
532
533 static int __videobuf_mmap_mapper(struct videobuf_queue *q,
534                          struct vm_area_struct *vma)
535 {
536         struct videobuf_dma_sg_memory *mem;
537         struct videobuf_mapping *map;
538         unsigned int first,last,size,i;
539         int retval;
540
541         retval = -EINVAL;
542         if (!(vma->vm_flags & VM_WRITE)) {
543                 dprintk(1,"mmap app bug: PROT_WRITE please\n");
544                 goto done;
545         }
546         if (!(vma->vm_flags & VM_SHARED)) {
547                 dprintk(1,"mmap app bug: MAP_SHARED please\n");
548                 goto done;
549         }
550
551         /* look for first buffer to map */
552         for (first = 0; first < VIDEO_MAX_FRAME; first++) {
553                 if (NULL == q->bufs[first])
554                         continue;
555                 mem=q->bufs[first]->priv;
556                 BUG_ON(!mem);
557                 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
558
559                 if (V4L2_MEMORY_MMAP != q->bufs[first]->memory)
560                         continue;
561                 if (q->bufs[first]->boff == (vma->vm_pgoff << PAGE_SHIFT))
562                         break;
563         }
564         if (VIDEO_MAX_FRAME == first) {
565                 dprintk(1,"mmap app bug: offset invalid [offset=0x%lx]\n",
566                         (vma->vm_pgoff << PAGE_SHIFT));
567                 goto done;
568         }
569
570         /* look for last buffer to map */
571         for (size = 0, last = first; last < VIDEO_MAX_FRAME; last++) {
572                 if (NULL == q->bufs[last])
573                         continue;
574                 if (V4L2_MEMORY_MMAP != q->bufs[last]->memory)
575                         continue;
576                 if (q->bufs[last]->map) {
577                         retval = -EBUSY;
578                         goto done;
579                 }
580                 size += q->bufs[last]->bsize;
581                 if (size == (vma->vm_end - vma->vm_start))
582                         break;
583         }
584         if (VIDEO_MAX_FRAME == last) {
585                 dprintk(1,"mmap app bug: size invalid [size=0x%lx]\n",
586                         (vma->vm_end - vma->vm_start));
587                 goto done;
588         }
589
590         /* create mapping + update buffer list */
591         retval = -ENOMEM;
592         map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL);
593         if (NULL == map)
594                 goto done;
595         for (size = 0, i = first; i <= last; size += q->bufs[i++]->bsize) {
596                 q->bufs[i]->map   = map;
597                 q->bufs[i]->baddr = vma->vm_start + size;
598         }
599         map->count    = 1;
600         map->start    = vma->vm_start;
601         map->end      = vma->vm_end;
602         map->q        = q;
603         vma->vm_ops   = &videobuf_vm_ops;
604         vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
605         vma->vm_flags &= ~VM_IO; /* using shared anonymous pages */
606         vma->vm_private_data = map;
607         dprintk(1,"mmap %p: q=%p %08lx-%08lx pgoff %08lx bufs %d-%d\n",
608                 map,q,vma->vm_start,vma->vm_end,vma->vm_pgoff,first,last);
609         retval = 0;
610
611  done:
612         return retval;
613 }
614
615 static int __videobuf_copy_to_user ( struct videobuf_queue *q,
616                                 char __user *data, size_t count,
617                                 int nonblocking )
618 {
619         struct videobuf_dma_sg_memory *mem = q->read_buf->priv;
620         BUG_ON(!mem);
621         MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
622
623         /* copy to userspace */
624         if (count > q->read_buf->size - q->read_off)
625                 count = q->read_buf->size - q->read_off;
626
627         if (copy_to_user(data, mem->dma.vmalloc+q->read_off, count))
628                 return -EFAULT;
629
630         return count;
631 }
632
633 static int __videobuf_copy_stream ( struct videobuf_queue *q,
634                                 char __user *data, size_t count, size_t pos,
635                                 int vbihack, int nonblocking )
636 {
637         unsigned int  *fc;
638         struct videobuf_dma_sg_memory *mem = q->read_buf->priv;
639         BUG_ON(!mem);
640         MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
641
642         if (vbihack) {
643                 /* dirty, undocumented hack -- pass the frame counter
644                         * within the last four bytes of each vbi data block.
645                         * We need that one to maintain backward compatibility
646                         * to all vbi decoding software out there ... */
647                 fc  = (unsigned int*)mem->dma.vmalloc;
648                 fc += (q->read_buf->size>>2) -1;
649                 *fc = q->read_buf->field_count >> 1;
650                 dprintk(1,"vbihack: %d\n",*fc);
651         }
652
653         /* copy stuff using the common method */
654         count = __videobuf_copy_to_user (q,data,count,nonblocking);
655
656         if ( (count==-EFAULT) && (0 == pos) )
657                 return -EFAULT;
658
659         return count;
660 }
661
662 static struct videobuf_qtype_ops sg_ops = {
663         .magic        = MAGIC_QTYPE_OPS,
664
665         .alloc        = __videobuf_alloc,
666         .iolock       = __videobuf_iolock,
667         .sync         = __videobuf_sync,
668         .mmap_free    = __videobuf_mmap_free,
669         .mmap_mapper  = __videobuf_mmap_mapper,
670         .video_copy_to_user = __videobuf_copy_to_user,
671         .copy_stream  = __videobuf_copy_stream,
672 };
673
674 void *videobuf_sg_alloc(size_t size)
675 {
676         struct videobuf_queue q;
677
678         /* Required to make generic handler to call __videobuf_alloc */
679         q.int_ops = &sg_ops;
680
681         q.msize = size;
682
683         return videobuf_alloc(&q);
684 }
685
686 void videobuf_queue_sg_init(struct videobuf_queue* q,
687                          struct videobuf_queue_ops *ops,
688                          struct device *dev,
689                          spinlock_t *irqlock,
690                          enum v4l2_buf_type type,
691                          enum v4l2_field field,
692                          unsigned int msize,
693                          void *priv)
694 {
695         videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
696                                  priv, &sg_ops);
697 }
698
699 /* --------------------------------------------------------------------- */
700
701 EXPORT_SYMBOL_GPL(videobuf_vmalloc_to_sg);
702
703 EXPORT_SYMBOL_GPL(videobuf_to_dma);
704 EXPORT_SYMBOL_GPL(videobuf_dma_init);
705 EXPORT_SYMBOL_GPL(videobuf_dma_init_user);
706 EXPORT_SYMBOL_GPL(videobuf_dma_init_kernel);
707 EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay);
708 EXPORT_SYMBOL_GPL(videobuf_dma_map);
709 EXPORT_SYMBOL_GPL(videobuf_dma_sync);
710 EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
711 EXPORT_SYMBOL_GPL(videobuf_dma_free);
712
713 EXPORT_SYMBOL_GPL(videobuf_sg_dma_map);
714 EXPORT_SYMBOL_GPL(videobuf_sg_dma_unmap);
715 EXPORT_SYMBOL_GPL(videobuf_sg_alloc);
716
717 EXPORT_SYMBOL_GPL(videobuf_queue_sg_init);
718
719 /*
720  * Local variables:
721  * c-basic-offset: 8
722  * End:
723  */