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