aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/videobuf-dma-sg.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/videobuf-dma-sg.c')
-rw-r--r--drivers/media/video/videobuf-dma-sg.c117
1 files changed, 59 insertions, 58 deletions
diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
index 7008afabe92c..6141a13bfc97 100644
--- a/drivers/media/video/videobuf-dma-sg.c
+++ b/drivers/media/video/videobuf-dma-sg.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * helper functions for PCI DMA video4linux capture buffers 2 * helper functions for SG DMA video4linux capture buffers
3 * 3 *
4 * The functions expect the hardware being able to scatter gatter 4 * The functions expect the hardware being able to scatter gatter
5 * (i.e. the buffers are not linear in physical memory, but fragmented 5 * (i.e. the buffers are not linear in physical memory, but fragmented
@@ -24,7 +24,7 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26 26
27#include <linux/pci.h> 27#include <linux/dma-mapping.h>
28#include <linux/vmalloc.h> 28#include <linux/vmalloc.h>
29#include <linux/pagemap.h> 29#include <linux/pagemap.h>
30#include <linux/scatterlist.h> 30#include <linux/scatterlist.h>
@@ -42,7 +42,7 @@
42static int debug; 42static int debug;
43module_param(debug, int, 0644); 43module_param(debug, int, 0644);
44 44
45MODULE_DESCRIPTION("helper module to manage video4linux pci dma sg buffers"); 45MODULE_DESCRIPTION("helper module to manage video4linux dma sg buffers");
46MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); 46MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
47MODULE_LICENSE("GPL"); 47MODULE_LICENSE("GPL");
48 48
@@ -119,10 +119,10 @@ videobuf_pages_to_sg(struct page **pages, int nr_pages, int offset)
119 119
120struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf) 120struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf)
121{ 121{
122 struct videbuf_pci_sg_memory *mem=buf->priv; 122 struct videobuf_dma_sg_memory *mem = buf->priv;
123 BUG_ON (!mem); 123 BUG_ON(!mem);
124 124
125 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 125 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
126 126
127 return &mem->dma; 127 return &mem->dma;
128} 128}
@@ -141,9 +141,14 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
141 141
142 dma->direction = direction; 142 dma->direction = direction;
143 switch (dma->direction) { 143 switch (dma->direction) {
144 case PCI_DMA_FROMDEVICE: rw = READ; break; 144 case DMA_FROM_DEVICE:
145 case PCI_DMA_TODEVICE: rw = WRITE; break; 145 rw = READ;
146 default: BUG(); 146 break;
147 case DMA_TO_DEVICE:
148 rw = WRITE;
149 break;
150 default:
151 BUG();
147 } 152 }
148 153
149 first = (data & PAGE_MASK) >> PAGE_SHIFT; 154 first = (data & PAGE_MASK) >> PAGE_SHIFT;
@@ -216,10 +221,8 @@ int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
216 return 0; 221 return 0;
217} 222}
218 223
219int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma) 224int videobuf_dma_map(struct videobuf_queue* q, struct videobuf_dmabuf *dma)
220{ 225{
221 void *dev=q->dev;
222
223 MAGIC_CHECK(dma->magic,MAGIC_DMABUF); 226 MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
224 BUG_ON(0 == dma->nr_pages); 227 BUG_ON(0 == dma->nr_pages);
225 228
@@ -245,7 +248,7 @@ int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
245 return -ENOMEM; 248 return -ENOMEM;
246 } 249 }
247 if (!dma->bus_addr) { 250 if (!dma->bus_addr) {
248 dma->sglen = pci_map_sg(dev,dma->sglist, 251 dma->sglen = dma_map_sg(q->dev, dma->sglist,
249 dma->nr_pages, dma->direction); 252 dma->nr_pages, dma->direction);
250 if (0 == dma->sglen) { 253 if (0 == dma->sglen) {
251 printk(KERN_WARNING 254 printk(KERN_WARNING
@@ -259,14 +262,12 @@ int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
259 return 0; 262 return 0;
260} 263}
261 264
262int videobuf_dma_sync(struct videobuf_queue *q,struct videobuf_dmabuf *dma) 265int videobuf_dma_sync(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
263{ 266{
264 void *dev=q->dev; 267 MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
265
266 MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
267 BUG_ON(!dma->sglen); 268 BUG_ON(!dma->sglen);
268 269
269 pci_dma_sync_sg_for_cpu (dev,dma->sglist,dma->nr_pages,dma->direction); 270 dma_sync_sg_for_cpu(q->dev, dma->sglist, dma->nr_pages, dma->direction);
270 return 0; 271 return 0;
271} 272}
272 273
@@ -274,11 +275,11 @@ int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
274{ 275{
275 void *dev=q->dev; 276 void *dev=q->dev;
276 277
277 MAGIC_CHECK(dma->magic,MAGIC_DMABUF); 278 MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
278 if (!dma->sglen) 279 if (!dma->sglen)
279 return 0; 280 return 0;
280 281
281 pci_unmap_sg (dev,dma->sglist,dma->nr_pages,dma->direction); 282 dma_unmap_sg(q->dev, dma->sglist, dma->nr_pages, dma->direction);
282 283
283 kfree(dma->sglist); 284 kfree(dma->sglist);
284 dma->sglist = NULL; 285 dma->sglist = NULL;
@@ -306,28 +307,28 @@ int videobuf_dma_free(struct videobuf_dmabuf *dma)
306 if (dma->bus_addr) { 307 if (dma->bus_addr) {
307 dma->bus_addr = 0; 308 dma->bus_addr = 0;
308 } 309 }
309 dma->direction = PCI_DMA_NONE; 310 dma->direction = DMA_NONE;
310 return 0; 311 return 0;
311} 312}
312 313
313/* --------------------------------------------------------------------- */ 314/* --------------------------------------------------------------------- */
314 315
315int videobuf_pci_dma_map(struct pci_dev *pci,struct videobuf_dmabuf *dma) 316int videobuf_sg_dma_map(struct device *dev, struct videobuf_dmabuf *dma)
316{ 317{
317 struct videobuf_queue q; 318 struct videobuf_queue q;
318 319
319 q.dev=pci; 320 q.dev = dev;
320 321
321 return (videobuf_dma_map(&q,dma)); 322 return videobuf_dma_map(&q, dma);
322} 323}
323 324
324int videobuf_pci_dma_unmap(struct pci_dev *pci,struct videobuf_dmabuf *dma) 325int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
325{ 326{
326 struct videobuf_queue q; 327 struct videobuf_queue q;
327 328
328 q.dev=pci; 329 q.dev = dev;
329 330
330 return (videobuf_dma_unmap(&q,dma)); 331 return videobuf_dma_unmap(&q, dma);
331} 332}
332 333
333/* --------------------------------------------------------------------- */ 334/* --------------------------------------------------------------------- */
@@ -347,7 +348,7 @@ videobuf_vm_close(struct vm_area_struct *vma)
347{ 348{
348 struct videobuf_mapping *map = vma->vm_private_data; 349 struct videobuf_mapping *map = vma->vm_private_data;
349 struct videobuf_queue *q = map->q; 350 struct videobuf_queue *q = map->q;
350 struct videbuf_pci_sg_memory *mem; 351 struct videobuf_dma_sg_memory *mem;
351 int i; 352 int i;
352 353
353 dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map, 354 dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map,
@@ -409,18 +410,18 @@ static struct vm_operations_struct videobuf_vm_ops =
409}; 410};
410 411
411/* --------------------------------------------------------------------- 412/* ---------------------------------------------------------------------
412 * PCI handlers for the generic methods 413 * SG handlers for the generic methods
413 */ 414 */
414 415
415/* Allocated area consists on 3 parts: 416/* Allocated area consists on 3 parts:
416 struct video_buffer 417 struct video_buffer
417 struct <driver>_buffer (cx88_buffer, saa7134_buf, ...) 418 struct <driver>_buffer (cx88_buffer, saa7134_buf, ...)
418 struct videobuf_pci_sg_memory 419 struct videobuf_dma_sg_memory
419 */ 420 */
420 421
421static void *__videobuf_alloc(size_t size) 422static void *__videobuf_alloc(size_t size)
422{ 423{
423 struct videbuf_pci_sg_memory *mem; 424 struct videobuf_dma_sg_memory *mem;
424 struct videobuf_buffer *vb; 425 struct videobuf_buffer *vb;
425 426
426 vb = kzalloc(size+sizeof(*mem),GFP_KERNEL); 427 vb = kzalloc(size+sizeof(*mem),GFP_KERNEL);
@@ -443,10 +444,10 @@ static int __videobuf_iolock (struct videobuf_queue* q,
443{ 444{
444 int err,pages; 445 int err,pages;
445 dma_addr_t bus; 446 dma_addr_t bus;
446 struct videbuf_pci_sg_memory *mem=vb->priv; 447 struct videobuf_dma_sg_memory *mem = vb->priv;
447 BUG_ON(!mem); 448 BUG_ON(!mem);
448 449
449 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 450 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
450 451
451 switch (vb->memory) { 452 switch (vb->memory) {
452 case V4L2_MEMORY_MMAP: 453 case V4L2_MEMORY_MMAP:
@@ -455,14 +456,14 @@ static int __videobuf_iolock (struct videobuf_queue* q,
455 /* no userspace addr -- kernel bounce buffer */ 456 /* no userspace addr -- kernel bounce buffer */
456 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT; 457 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
457 err = videobuf_dma_init_kernel( &mem->dma, 458 err = videobuf_dma_init_kernel( &mem->dma,
458 PCI_DMA_FROMDEVICE, 459 DMA_FROM_DEVICE,
459 pages ); 460 pages );
460 if (0 != err) 461 if (0 != err)
461 return err; 462 return err;
462 } else if (vb->memory == V4L2_MEMORY_USERPTR) { 463 } else if (vb->memory == V4L2_MEMORY_USERPTR) {
463 /* dma directly to userspace */ 464 /* dma directly to userspace */
464 err = videobuf_dma_init_user( &mem->dma, 465 err = videobuf_dma_init_user( &mem->dma,
465 PCI_DMA_FROMDEVICE, 466 DMA_FROM_DEVICE,
466 vb->baddr,vb->bsize ); 467 vb->baddr,vb->bsize );
467 if (0 != err) 468 if (0 != err)
468 return err; 469 return err;
@@ -473,7 +474,7 @@ static int __videobuf_iolock (struct videobuf_queue* q,
473 locking inversion, so don't take it here */ 474 locking inversion, so don't take it here */
474 475
475 err = videobuf_dma_init_user_locked(&mem->dma, 476 err = videobuf_dma_init_user_locked(&mem->dma,
476 PCI_DMA_FROMDEVICE, 477 DMA_FROM_DEVICE,
477 vb->baddr, vb->bsize); 478 vb->baddr, vb->bsize);
478 if (0 != err) 479 if (0 != err)
479 return err; 480 return err;
@@ -490,7 +491,7 @@ static int __videobuf_iolock (struct videobuf_queue* q,
490 */ 491 */
491 bus = (dma_addr_t)(unsigned long)fbuf->base + vb->boff; 492 bus = (dma_addr_t)(unsigned long)fbuf->base + vb->boff;
492 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT; 493 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
493 err = videobuf_dma_init_overlay(&mem->dma,PCI_DMA_FROMDEVICE, 494 err = videobuf_dma_init_overlay(&mem->dma, DMA_FROM_DEVICE,
494 bus, pages); 495 bus, pages);
495 if (0 != err) 496 if (0 != err)
496 return err; 497 return err;
@@ -498,7 +499,7 @@ static int __videobuf_iolock (struct videobuf_queue* q,
498 default: 499 default:
499 BUG(); 500 BUG();
500 } 501 }
501 err = videobuf_dma_map(q,&mem->dma); 502 err = videobuf_dma_map(q, &mem->dma);
502 if (0 != err) 503 if (0 != err)
503 return err; 504 return err;
504 505
@@ -508,8 +509,8 @@ static int __videobuf_iolock (struct videobuf_queue* q,
508static int __videobuf_sync(struct videobuf_queue *q, 509static int __videobuf_sync(struct videobuf_queue *q,
509 struct videobuf_buffer *buf) 510 struct videobuf_buffer *buf)
510{ 511{
511 struct videbuf_pci_sg_memory *mem=buf->priv; 512 struct videobuf_dma_sg_memory *mem = buf->priv;
512 BUG_ON (!mem); 513 BUG_ON(!mem);
513 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 514 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
514 515
515 return videobuf_dma_sync(q,&mem->dma); 516 return videobuf_dma_sync(q,&mem->dma);
@@ -532,7 +533,7 @@ static int __videobuf_mmap_free(struct videobuf_queue *q)
532static int __videobuf_mmap_mapper(struct videobuf_queue *q, 533static int __videobuf_mmap_mapper(struct videobuf_queue *q,
533 struct vm_area_struct *vma) 534 struct vm_area_struct *vma)
534{ 535{
535 struct videbuf_pci_sg_memory *mem; 536 struct videobuf_dma_sg_memory *mem;
536 struct videobuf_mapping *map; 537 struct videobuf_mapping *map;
537 unsigned int first,last,size,i; 538 unsigned int first,last,size,i;
538 int retval; 539 int retval;
@@ -552,7 +553,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
552 if (NULL == q->bufs[first]) 553 if (NULL == q->bufs[first])
553 continue; 554 continue;
554 mem=q->bufs[first]->priv; 555 mem=q->bufs[first]->priv;
555 BUG_ON (!mem); 556 BUG_ON(!mem);
556 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 557 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
557 558
558 if (V4L2_MEMORY_MMAP != q->bufs[first]->memory) 559 if (V4L2_MEMORY_MMAP != q->bufs[first]->memory)
@@ -615,8 +616,8 @@ static int __videobuf_copy_to_user ( struct videobuf_queue *q,
615 char __user *data, size_t count, 616 char __user *data, size_t count,
616 int nonblocking ) 617 int nonblocking )
617{ 618{
618 struct videbuf_pci_sg_memory *mem=q->read_buf->priv; 619 struct videobuf_dma_sg_memory *mem = q->read_buf->priv;
619 BUG_ON (!mem); 620 BUG_ON(!mem);
620 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 621 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
621 622
622 /* copy to userspace */ 623 /* copy to userspace */
@@ -634,8 +635,8 @@ static int __videobuf_copy_stream ( struct videobuf_queue *q,
634 int vbihack, int nonblocking ) 635 int vbihack, int nonblocking )
635{ 636{
636 unsigned int *fc; 637 unsigned int *fc;
637 struct videbuf_pci_sg_memory *mem=q->read_buf->priv; 638 struct videobuf_dma_sg_memory *mem = q->read_buf->priv;
638 BUG_ON (!mem); 639 BUG_ON(!mem);
639 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 640 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
640 641
641 if (vbihack) { 642 if (vbihack) {
@@ -658,7 +659,7 @@ static int __videobuf_copy_stream ( struct videobuf_queue *q,
658 return count; 659 return count;
659} 660}
660 661
661static struct videobuf_qtype_ops pci_ops = { 662static struct videobuf_qtype_ops sg_ops = {
662 .magic = MAGIC_QTYPE_OPS, 663 .magic = MAGIC_QTYPE_OPS,
663 664
664 .alloc = __videobuf_alloc, 665 .alloc = __videobuf_alloc,
@@ -670,21 +671,21 @@ static struct videobuf_qtype_ops pci_ops = {
670 .copy_stream = __videobuf_copy_stream, 671 .copy_stream = __videobuf_copy_stream,
671}; 672};
672 673
673void *videobuf_pci_alloc (size_t size) 674void *videobuf_sg_alloc(size_t size)
674{ 675{
675 struct videobuf_queue q; 676 struct videobuf_queue q;
676 677
677 /* Required to make generic handler to call __videobuf_alloc */ 678 /* Required to make generic handler to call __videobuf_alloc */
678 q.int_ops=&pci_ops; 679 q.int_ops = &sg_ops;
679 680
680 q.msize=size; 681 q.msize = size;
681 682
682 return videobuf_alloc (&q); 683 return videobuf_alloc(&q);
683} 684}
684 685
685void videobuf_queue_pci_init(struct videobuf_queue* q, 686void videobuf_queue_sg_init(struct videobuf_queue* q,
686 struct videobuf_queue_ops *ops, 687 struct videobuf_queue_ops *ops,
687 void *dev, 688 struct device *dev,
688 spinlock_t *irqlock, 689 spinlock_t *irqlock,
689 enum v4l2_buf_type type, 690 enum v4l2_buf_type type,
690 enum v4l2_field field, 691 enum v4l2_field field,
@@ -692,7 +693,7 @@ void videobuf_queue_pci_init(struct videobuf_queue* q,
692 void *priv) 693 void *priv)
693{ 694{
694 videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize, 695 videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
695 priv, &pci_ops); 696 priv, &sg_ops);
696} 697}
697 698
698/* --------------------------------------------------------------------- */ 699/* --------------------------------------------------------------------- */
@@ -709,11 +710,11 @@ EXPORT_SYMBOL_GPL(videobuf_dma_sync);
709EXPORT_SYMBOL_GPL(videobuf_dma_unmap); 710EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
710EXPORT_SYMBOL_GPL(videobuf_dma_free); 711EXPORT_SYMBOL_GPL(videobuf_dma_free);
711 712
712EXPORT_SYMBOL_GPL(videobuf_pci_dma_map); 713EXPORT_SYMBOL_GPL(videobuf_sg_dma_map);
713EXPORT_SYMBOL_GPL(videobuf_pci_dma_unmap); 714EXPORT_SYMBOL_GPL(videobuf_sg_dma_unmap);
714EXPORT_SYMBOL_GPL(videobuf_pci_alloc); 715EXPORT_SYMBOL_GPL(videobuf_sg_alloc);
715 716
716EXPORT_SYMBOL_GPL(videobuf_queue_pci_init); 717EXPORT_SYMBOL_GPL(videobuf_queue_sg_init);
717 718
718/* 719/*
719 * Local variables: 720 * Local variables: