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