Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

V4L/DVB (3516): Make video_buf more generic

Video_buf were concerned to allow PCI devices to be used as
video capture devices. This patch extends video_buf features
by virtualizing pci-dependent functions and allowing other
type of devices to use it.
It is still DMA centric, although it may be used also by
devices that emulates scatter/gather behavior or a DMA device

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>

+340 -174
+3 -2
drivers/media/common/saa7146_fops.c
··· 50 50 /********************************************************************************/ 51 51 /* common dma functions */ 52 52 53 - void saa7146_dma_free(struct saa7146_dev *dev,struct saa7146_buf *buf) 53 + void saa7146_dma_free(struct saa7146_dev *dev,struct videobuf_queue *q, 54 + struct saa7146_buf *buf) 54 55 { 55 56 DEB_EE(("dev:%p, buf:%p\n",dev,buf)); 56 57 57 58 BUG_ON(in_interrupt()); 58 59 59 60 videobuf_waiton(&buf->vb,0,0); 60 - videobuf_dma_pci_unmap(dev->pci, &buf->vb.dma); 61 + videobuf_dma_unmap(q, &buf->vb.dma); 61 62 videobuf_dma_free(&buf->vb.dma); 62 63 buf->vb.state = STATE_NEEDS_INIT; 63 64 }
+4 -4
drivers/media/common/saa7146_vbi.c
··· 236 236 } 237 237 238 238 if (buf->vb.size != size) 239 - saa7146_dma_free(dev,buf); 239 + saa7146_dma_free(dev,q,buf); 240 240 241 241 if (STATE_NEEDS_INIT == buf->vb.state) { 242 242 buf->vb.width = llength; ··· 247 247 saa7146_pgtable_free(dev->pci, &buf->pt[2]); 248 248 saa7146_pgtable_alloc(dev->pci, &buf->pt[2]); 249 249 250 - err = videobuf_iolock(dev->pci,&buf->vb, NULL); 250 + err = videobuf_iolock(q,&buf->vb, NULL); 251 251 if (err) 252 252 goto oops; 253 253 err = saa7146_pgtable_build_single(dev->pci, &buf->pt[2], buf->vb.dma.sglist, buf->vb.dma.sglen); ··· 261 261 262 262 oops: 263 263 DEB_VBI(("error out.\n")); 264 - saa7146_dma_free(dev,buf); 264 + saa7146_dma_free(dev,q,buf); 265 265 266 266 return err; 267 267 } ··· 301 301 struct saa7146_buf *buf = (struct saa7146_buf *)vb; 302 302 303 303 DEB_VBI(("vb:%p\n",vb)); 304 - saa7146_dma_free(dev,buf); 304 + saa7146_dma_free(dev,q,buf); 305 305 } 306 306 307 307 static struct videobuf_queue_ops vbi_qops = {
+4 -4
drivers/media/common/saa7146_video.c
··· 1275 1275 buf->vb.field != field || 1276 1276 buf->vb.field != fh->video_fmt.field || 1277 1277 buf->fmt != &fh->video_fmt) { 1278 - saa7146_dma_free(dev,buf); 1278 + saa7146_dma_free(dev,q,buf); 1279 1279 } 1280 1280 1281 1281 if (STATE_NEEDS_INIT == buf->vb.state) { ··· 1304 1304 saa7146_pgtable_alloc(dev->pci, &buf->pt[0]); 1305 1305 } 1306 1306 1307 - err = videobuf_iolock(dev->pci,&buf->vb, &vv->ov_fb); 1307 + err = videobuf_iolock(q,&buf->vb, &vv->ov_fb); 1308 1308 if (err) 1309 1309 goto oops; 1310 1310 err = saa7146_pgtable_build(dev,buf); ··· 1318 1318 1319 1319 oops: 1320 1320 DEB_D(("error out.\n")); 1321 - saa7146_dma_free(dev,buf); 1321 + saa7146_dma_free(dev,q,buf); 1322 1322 1323 1323 return err; 1324 1324 } ··· 1363 1363 struct saa7146_buf *buf = (struct saa7146_buf *)vb; 1364 1364 1365 1365 DEB_CAP(("vbuf:%p\n",vb)); 1366 - saa7146_dma_free(dev,buf); 1366 + saa7146_dma_free(dev,q,buf); 1367 1367 } 1368 1368 1369 1369 static struct videobuf_queue_ops video_qops = {
+10 -9
drivers/media/video/bttv-driver.c
··· 1397 1397 free_btres(btv,fh,RESOURCE_OVERLAY); 1398 1398 if (NULL != old) { 1399 1399 dprintk("switch_overlay: old=%p state is %d\n",old,old->vb.state); 1400 - bttv_dma_free(btv, old); 1400 + bttv_dma_free(&fh->cap,btv, old); 1401 1401 kfree(old); 1402 1402 } 1403 1403 dprintk("switch_overlay: done\n"); ··· 1407 1407 /* ----------------------------------------------------------------------- */ 1408 1408 /* video4linux (1) interface */ 1409 1409 1410 - static int bttv_prepare_buffer(struct bttv *btv, struct bttv_buffer *buf, 1410 + static int bttv_prepare_buffer(struct videobuf_queue *q,struct bttv *btv, 1411 + struct bttv_buffer *buf, 1411 1412 const struct bttv_format *fmt, 1412 1413 unsigned int width, unsigned int height, 1413 1414 enum v4l2_field field) ··· 1451 1450 /* alloc risc memory */ 1452 1451 if (STATE_NEEDS_INIT == buf->vb.state) { 1453 1452 redo_dma_risc = 1; 1454 - if (0 != (rc = videobuf_iolock(btv->c.pci,&buf->vb,&btv->fbuf))) 1453 + if (0 != (rc = videobuf_iolock(q,&buf->vb,&btv->fbuf))) 1455 1454 goto fail; 1456 1455 } 1457 1456 ··· 1463 1462 return 0; 1464 1463 1465 1464 fail: 1466 - bttv_dma_free(btv,buf); 1465 + bttv_dma_free(q,btv,buf); 1467 1466 return rc; 1468 1467 } 1469 1468 ··· 1487 1486 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); 1488 1487 struct bttv_fh *fh = q->priv_data; 1489 1488 1490 - return bttv_prepare_buffer(fh->btv, buf, fh->fmt, 1489 + return bttv_prepare_buffer(q,fh->btv, buf, fh->fmt, 1491 1490 fh->width, fh->height, field); 1492 1491 } 1493 1492 ··· 1511 1510 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); 1512 1511 struct bttv_fh *fh = q->priv_data; 1513 1512 1514 - bttv_dma_free(fh->btv,buf); 1513 + bttv_dma_free(&fh->cap,fh->btv,buf); 1515 1514 } 1516 1515 1517 1516 static struct videobuf_queue_ops bttv_video_qops = { ··· 2497 2496 field = (vm->height > bttv_tvnorms[btv->tvnorm].sheight/2) 2498 2497 ? V4L2_FIELD_INTERLACED 2499 2498 : V4L2_FIELD_BOTTOM; 2500 - retval = bttv_prepare_buffer(btv,buf, 2499 + retval = bttv_prepare_buffer(&fh->cap,btv,buf, 2501 2500 format_by_palette(vm->format), 2502 2501 vm->width,vm->height,field); 2503 2502 if (0 != retval) ··· 2529 2528 retval = -EIO; 2530 2529 /* fall through */ 2531 2530 case STATE_DONE: 2532 - videobuf_dma_pci_sync(btv->c.pci,&buf->vb.dma); 2533 - bttv_dma_free(btv,buf); 2531 + videobuf_dma_sync(&fh->cap,&buf->vb.dma); 2532 + bttv_dma_free(&fh->cap,btv,buf); 2534 2533 break; 2535 2534 default: 2536 2535 retval = -EINVAL;
+2 -2
drivers/media/video/bttv-risc.c
··· 509 509 } 510 510 511 511 void 512 - bttv_dma_free(struct bttv *btv, struct bttv_buffer *buf) 512 + bttv_dma_free(struct videobuf_queue *q,struct bttv *btv, struct bttv_buffer *buf) 513 513 { 514 514 BUG_ON(in_interrupt()); 515 515 videobuf_waiton(&buf->vb,0,0); 516 - videobuf_dma_pci_unmap(btv->c.pci, &buf->vb.dma); 516 + videobuf_dma_unmap(q, &buf->vb.dma); 517 517 videobuf_dma_free(&buf->vb.dma); 518 518 btcx_riscmem_free(btv->c.pci,&buf->bottom); 519 519 btcx_riscmem_free(btv->c.pci,&buf->top);
+3 -3
drivers/media/video/bttv-vbi.c
··· 96 96 return -EINVAL; 97 97 98 98 if (STATE_NEEDS_INIT == buf->vb.state) { 99 - if (0 != (rc = videobuf_iolock(btv->c.pci, &buf->vb, NULL))) 99 + if (0 != (rc = videobuf_iolock(q, &buf->vb, NULL))) 100 100 goto fail; 101 101 if (0 != (rc = vbi_buffer_risc(btv,buf,fh->lines))) 102 102 goto fail; ··· 109 109 return 0; 110 110 111 111 fail: 112 - bttv_dma_free(btv,buf); 112 + bttv_dma_free(q,btv,buf); 113 113 return rc; 114 114 } 115 115 ··· 136 136 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); 137 137 138 138 dprintk("free %p\n",vb); 139 - bttv_dma_free(fh->btv,buf); 139 + bttv_dma_free(&fh->cap,fh->btv,buf); 140 140 } 141 141 142 142 struct videobuf_queue_ops bttv_vbi_qops = {
+2 -1
drivers/media/video/bttvp.h
··· 190 190 struct bttv_buffer_set *set); 191 191 int bttv_buffer_activate_vbi(struct bttv *btv, 192 192 struct bttv_buffer *vbi); 193 - void bttv_dma_free(struct bttv *btv, struct bttv_buffer *buf); 193 + void bttv_dma_free(struct videobuf_queue *q, struct bttv *btv, 194 + struct bttv_buffer *buf); 194 195 195 196 /* overlay handling */ 196 197 int bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov,
+2 -2
drivers/media/video/cx88/cx88-alsa.c
··· 303 303 BUG_ON(!chip->dma_size); 304 304 305 305 dprintk(2,"Freeing buffer\n"); 306 - videobuf_dma_pci_unmap(chip->pci, &chip->dma_risc); 306 + videobuf_pci_dma_unmap(chip->pci, &chip->dma_risc); 307 307 videobuf_dma_free(&chip->dma_risc); 308 308 btcx_riscmem_free(chip->pci,&chip->buf->risc); 309 309 kfree(chip->buf); ··· 429 429 videobuf_dma_init_kernel(&buf->vb.dma,PCI_DMA_FROMDEVICE, 430 430 (PAGE_ALIGN(buf->vb.size) >> PAGE_SHIFT)); 431 431 432 - videobuf_dma_pci_map(chip->pci,&buf->vb.dma); 432 + videobuf_pci_dma_map(chip->pci,&buf->vb.dma); 433 433 434 434 435 435 cx88_risc_databuffer(chip->pci, &buf->risc,
+2 -3
drivers/media/video/cx88/cx88-blackbird.c
··· 1341 1341 enum v4l2_field field) 1342 1342 { 1343 1343 struct cx8802_fh *fh = q->priv_data; 1344 - return cx8802_buf_prepare(fh->dev, (struct cx88_buffer*)vb, field); 1344 + return cx8802_buf_prepare(q, fh->dev, (struct cx88_buffer*)vb, field); 1345 1345 } 1346 1346 1347 1347 static void ··· 1354 1354 static void 1355 1355 bb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 1356 1356 { 1357 - struct cx8802_fh *fh = q->priv_data; 1358 - cx88_free_buffer(fh->dev->pci, (struct cx88_buffer*)vb); 1357 + cx88_free_buffer(q, (struct cx88_buffer*)vb); 1359 1358 } 1360 1359 1361 1360 static struct videobuf_queue_ops blackbird_qops = {
+3 -3
drivers/media/video/cx88/cx88-core.c
··· 213 213 } 214 214 215 215 void 216 - cx88_free_buffer(struct pci_dev *pci, struct cx88_buffer *buf) 216 + cx88_free_buffer(struct videobuf_queue *q, struct cx88_buffer *buf) 217 217 { 218 218 BUG_ON(in_interrupt()); 219 219 videobuf_waiton(&buf->vb,0,0); 220 - videobuf_dma_pci_unmap(pci, &buf->vb.dma); 220 + videobuf_dma_unmap(q, &buf->vb.dma); 221 221 videobuf_dma_free(&buf->vb.dma); 222 - btcx_riscmem_free(pci, &buf->risc); 222 + btcx_riscmem_free((struct pci_dev *)q->dev, &buf->risc); 223 223 buf->vb.state = STATE_NEEDS_INIT; 224 224 } 225 225
+2 -3
drivers/media/video/cx88/cx88-dvb.c
··· 90 90 enum v4l2_field field) 91 91 { 92 92 struct cx8802_dev *dev = q->priv_data; 93 - return cx8802_buf_prepare(dev, (struct cx88_buffer*)vb,field); 93 + return cx8802_buf_prepare(q, dev, (struct cx88_buffer*)vb,field); 94 94 } 95 95 96 96 static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb) ··· 101 101 102 102 static void dvb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 103 103 { 104 - struct cx8802_dev *dev = q->priv_data; 105 - cx88_free_buffer(dev->pci, (struct cx88_buffer*)vb); 104 + cx88_free_buffer(q, (struct cx88_buffer*)vb); 106 105 } 107 106 108 107 static struct videobuf_queue_ops dvb_qops = {
+14 -14
drivers/media/video/cx88/cx88-mpeg.c
··· 163 163 164 164 /* ------------------------------------------------------------------ */ 165 165 166 - int cx8802_buf_prepare(struct cx8802_dev *dev, struct cx88_buffer *buf, 167 - enum v4l2_field field) 166 + int cx8802_buf_prepare(struct videobuf_queue *q, struct cx8802_dev *dev, 167 + struct cx88_buffer *buf, enum v4l2_field field) 168 168 { 169 169 int size = dev->ts_packet_size * dev->ts_packet_count; 170 170 int rc; ··· 179 179 buf->vb.size = size; 180 180 buf->vb.field = field /*V4L2_FIELD_TOP*/; 181 181 182 - if (0 != (rc = videobuf_iolock(dev->pci,&buf->vb,NULL))) 182 + if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL))) 183 183 goto fail; 184 184 cx88_risc_databuffer(dev->pci, &buf->risc, 185 185 buf->vb.dma.sglist, ··· 189 189 return 0; 190 190 191 191 fail: 192 - cx88_free_buffer(dev->pci,buf); 192 + cx88_free_buffer(q,buf); 193 193 return rc; 194 194 } 195 195 196 196 void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf) 197 197 { 198 198 struct cx88_buffer *prev; 199 - struct cx88_dmaqueue *q = &dev->mpegq; 199 + struct cx88_dmaqueue *cx88q = &dev->mpegq; 200 200 201 201 dprintk( 1, "cx8802_buf_queue\n" ); 202 202 /* add jump to stopper */ 203 203 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); 204 - buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); 204 + buf->risc.jmp[1] = cpu_to_le32(cx88q->stopper.dma); 205 205 206 - if (list_empty(&q->active)) { 206 + if (list_empty(&cx88q->active)) { 207 207 dprintk( 0, "queue is empty - first active\n" ); 208 - list_add_tail(&buf->vb.queue,&q->active); 209 - cx8802_start_dma(dev, q, buf); 208 + list_add_tail(&buf->vb.queue,&cx88q->active); 209 + cx8802_start_dma(dev, cx88q, buf); 210 210 buf->vb.state = STATE_ACTIVE; 211 - buf->count = q->count++; 212 - mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 211 + buf->count = cx88q->count++; 212 + mod_timer(&cx88q->timeout, jiffies+BUFFER_TIMEOUT); 213 213 dprintk(0,"[%p/%d] %s - first active\n", 214 214 buf, buf->vb.i, __FUNCTION__); 215 215 216 216 } else { 217 217 dprintk( 1, "queue is not empty - append to active\n" ); 218 - prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue); 219 - list_add_tail(&buf->vb.queue,&q->active); 218 + prev = list_entry(cx88q->active.prev, struct cx88_buffer, vb.queue); 219 + list_add_tail(&buf->vb.queue,&cx88q->active); 220 220 buf->vb.state = STATE_ACTIVE; 221 - buf->count = q->count++; 221 + buf->count = cx88q->count++; 222 222 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 223 223 dprintk( 1, "[%p/%d] %s - append to active\n", 224 224 buf, buf->vb.i, __FUNCTION__);
+3 -4
drivers/media/video/cx88/cx88-vbi.c
··· 175 175 buf->vb.size = size; 176 176 buf->vb.field = V4L2_FIELD_SEQ_TB; 177 177 178 - if (0 != (rc = videobuf_iolock(dev->pci,&buf->vb,NULL))) 178 + if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL))) 179 179 goto fail; 180 180 cx88_risc_buffer(dev->pci, &buf->risc, 181 181 buf->vb.dma.sglist, ··· 187 187 return 0; 188 188 189 189 fail: 190 - cx88_free_buffer(dev->pci,buf); 190 + cx88_free_buffer(q,buf); 191 191 return rc; 192 192 } 193 193 ··· 227 227 static void vbi_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 228 228 { 229 229 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); 230 - struct cx8800_fh *fh = q->priv_data; 231 230 232 - cx88_free_buffer(fh->dev->pci,buf); 231 + cx88_free_buffer(q,buf); 233 232 } 234 233 235 234 struct videobuf_queue_ops cx8800_vbi_qops = {
+27 -8
drivers/media/video/cx88/cx88-video.c
··· 564 564 565 565 if (STATE_NEEDS_INIT == buf->vb.state) { 566 566 init_buffer = 1; 567 - if (0 != (rc = videobuf_iolock(dev->pci,&buf->vb,NULL))) 567 + if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL))) 568 568 goto fail; 569 569 } 570 570 ··· 614 614 return 0; 615 615 616 616 fail: 617 - cx88_free_buffer(dev->pci,buf); 617 + cx88_free_buffer(q,buf); 618 618 return rc; 619 619 } 620 620 ··· 671 671 static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 672 672 { 673 673 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); 674 - struct cx8800_fh *fh = q->priv_data; 675 674 676 - cx88_free_buffer(fh->dev->pci,buf); 675 + cx88_free_buffer(q,buf); 677 676 } 678 677 679 678 static struct videobuf_queue_ops cx8800_video_qops = { ··· 1250 1251 { 1251 1252 int err; 1252 1253 1253 - dprintk(2, "CORE IOCTL: 0x%x\n", cmd ); 1254 - if (video_debug > 1) 1255 - v4l_print_ioctl(core->name,cmd); 1254 + if (video_debug) { 1255 + if (video_debug > 1) { 1256 + if (_IOC_DIR(cmd) & _IOC_WRITE) 1257 + v4l_printk_ioctl_arg("cx88(w)",cmd, arg); 1258 + else if (!_IOC_DIR(cmd) & _IOC_READ) { 1259 + v4l_print_ioctl("cx88", cmd); 1260 + } 1261 + } else 1262 + v4l_print_ioctl(core->name,cmd); 1263 + 1264 + } 1256 1265 1257 1266 switch (cmd) { 1258 1267 /* ---------- tv norms ---------- */ ··· 1467 1460 static int video_ioctl(struct inode *inode, struct file *file, 1468 1461 unsigned int cmd, unsigned long arg) 1469 1462 { 1470 - return video_usercopy(inode, file, cmd, arg, video_do_ioctl); 1463 + int retval; 1464 + 1465 + retval=video_usercopy(inode, file, cmd, arg, video_do_ioctl); 1466 + 1467 + if (video_debug > 1) { 1468 + if (retval < 0) { 1469 + v4l_print_ioctl("cx88(err)", cmd); 1470 + printk(KERN_DEBUG "cx88(err): errcode=%d\n",retval); 1471 + } else if (_IOC_DIR(cmd) & _IOC_READ) 1472 + v4l_printk_ioctl_arg("cx88(r)",cmd, (void *)arg); 1473 + } 1474 + 1475 + return retval; 1471 1476 } 1472 1477 1473 1478 /* ----------------------------------------------------------- */
+3 -3
drivers/media/video/cx88/cx88.h
··· 485 485 cx88_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc, 486 486 u32 reg, u32 mask, u32 value); 487 487 extern void 488 - cx88_free_buffer(struct pci_dev *pci, struct cx88_buffer *buf); 488 + cx88_free_buffer(struct videobuf_queue *q, struct cx88_buffer *buf); 489 489 490 490 extern void cx88_risc_disasm(struct cx88_core *core, 491 491 struct btcx_riscmem *risc); ··· 577 577 /* ----------------------------------------------------------- */ 578 578 /* cx88-mpeg.c */ 579 579 580 - int cx8802_buf_prepare(struct cx8802_dev *dev, struct cx88_buffer *buf, 581 - enum v4l2_field field); 580 + int cx8802_buf_prepare(struct videobuf_queue *q,struct cx8802_dev *dev, 581 + struct cx88_buffer *buf, enum v4l2_field field); 582 582 void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf); 583 583 void cx8802_cancel_buffers(struct cx8802_dev *dev); 584 584
+5 -5
drivers/media/video/saa7134/saa7134-alsa.c
··· 507 507 /* release the old buffer */ 508 508 if (substream->runtime->dma_area) { 509 509 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt); 510 - videobuf_dma_pci_unmap(dev->pci, &dev->dmasound.dma); 510 + videobuf_pci_dma_unmap(dev->pci, &dev->dmasound.dma); 511 511 dsp_buffer_free(dev); 512 512 substream->runtime->dma_area = NULL; 513 513 } ··· 523 523 return err; 524 524 } 525 525 526 - if (0 != (err = videobuf_dma_pci_map(dev->pci, &dev->dmasound.dma))) { 526 + if (0 != (err = videobuf_pci_dma_map(dev->pci, &dev->dmasound.dma))) { 527 527 dsp_buffer_free(dev); 528 528 return err; 529 529 } 530 530 if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt))) { 531 - videobuf_dma_pci_unmap(dev->pci, &dev->dmasound.dma); 531 + videobuf_pci_dma_unmap(dev->pci, &dev->dmasound.dma); 532 532 dsp_buffer_free(dev); 533 533 return err; 534 534 } ··· 537 537 dev->dmasound.dma.sglen, 538 538 0))) { 539 539 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt); 540 - videobuf_dma_pci_unmap(dev->pci, &dev->dmasound.dma); 540 + videobuf_pci_dma_unmap(dev->pci, &dev->dmasound.dma); 541 541 dsp_buffer_free(dev); 542 542 return err; 543 543 } ··· 571 571 572 572 if (substream->runtime->dma_area) { 573 573 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt); 574 - videobuf_dma_pci_unmap(dev->pci, &dev->dmasound.dma); 574 + videobuf_pci_dma_unmap(dev->pci, &dev->dmasound.dma); 575 575 dsp_buffer_free(dev); 576 576 substream->runtime->dma_area = NULL; 577 577 }
+2 -2
drivers/media/video/saa7134/saa7134-core.c
··· 254 254 255 255 /* ------------------------------------------------------------------ */ 256 256 257 - void saa7134_dma_free(struct saa7134_dev *dev,struct saa7134_buf *buf) 257 + void saa7134_dma_free(struct videobuf_queue *q,struct saa7134_buf *buf) 258 258 { 259 259 BUG_ON(in_interrupt()); 260 260 261 261 videobuf_waiton(&buf->vb,0,0); 262 - videobuf_dma_pci_unmap(dev->pci, &buf->vb.dma); 262 + videobuf_dma_unmap(q, &buf->vb.dma); 263 263 videobuf_dma_free(&buf->vb.dma); 264 264 buf->vb.state = STATE_NEEDS_INIT; 265 265 }
+3 -3
drivers/media/video/saa7134/saa7134-oss.c
··· 124 124 unsigned long flags; 125 125 126 126 /* prepare buffer */ 127 - if (0 != (err = videobuf_dma_pci_map(dev->pci,&dev->dmasound.dma))) 127 + if (0 != (err = videobuf_pci_dma_map(dev->pci,&dev->dmasound.dma))) 128 128 return err; 129 129 if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt))) 130 130 goto fail1; ··· 213 213 fail2: 214 214 saa7134_pgtable_free(dev->pci,&dev->dmasound.pt); 215 215 fail1: 216 - videobuf_dma_pci_unmap(dev->pci,&dev->dmasound.dma); 216 + videobuf_pci_dma_unmap(dev->pci,&dev->dmasound.dma); 217 217 return err; 218 218 } 219 219 ··· 231 231 232 232 /* unlock buffer */ 233 233 saa7134_pgtable_free(dev->pci,&dev->dmasound.pt); 234 - videobuf_dma_pci_unmap(dev->pci,&dev->dmasound.dma); 234 + videobuf_pci_dma_unmap(dev->pci,&dev->dmasound.dma); 235 235 return 0; 236 236 } 237 237
+4 -5
drivers/media/video/saa7134/saa7134-ts.c
··· 89 89 return -EINVAL; 90 90 91 91 if (buf->vb.size != size) { 92 - saa7134_dma_free(dev,buf); 92 + saa7134_dma_free(q,buf); 93 93 } 94 94 95 95 if (STATE_NEEDS_INIT == buf->vb.state) { ··· 98 98 buf->vb.size = size; 99 99 buf->pt = &dev->ts.pt_ts; 100 100 101 - err = videobuf_iolock(dev->pci,&buf->vb,NULL); 101 + err = videobuf_iolock(q,&buf->vb,NULL); 102 102 if (err) 103 103 goto oops; 104 104 err = saa7134_pgtable_build(dev->pci,buf->pt, ··· 126 126 return 0; 127 127 128 128 oops: 129 - saa7134_dma_free(dev,buf); 129 + saa7134_dma_free(q,buf); 130 130 return err; 131 131 } 132 132 ··· 152 152 153 153 static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 154 154 { 155 - struct saa7134_dev *dev = q->priv_data; 156 155 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb); 157 156 158 - saa7134_dma_free(dev,buf); 157 + saa7134_dma_free(q,buf); 159 158 } 160 159 161 160 struct videobuf_queue_ops saa7134_ts_qops = {
+4 -6
drivers/media/video/saa7134/saa7134-vbi.c
··· 135 135 return -EINVAL; 136 136 137 137 if (buf->vb.size != size) 138 - saa7134_dma_free(dev,buf); 138 + saa7134_dma_free(q,buf); 139 139 140 140 if (STATE_NEEDS_INIT == buf->vb.state) { 141 141 buf->vb.width = llength; ··· 143 143 buf->vb.size = size; 144 144 buf->pt = &fh->pt_vbi; 145 145 146 - err = videobuf_iolock(dev->pci,&buf->vb,NULL); 146 + err = videobuf_iolock(q,&buf->vb,NULL); 147 147 if (err) 148 148 goto oops; 149 149 err = saa7134_pgtable_build(dev->pci,buf->pt, ··· 159 159 return 0; 160 160 161 161 oops: 162 - saa7134_dma_free(dev,buf); 162 + saa7134_dma_free(q,buf); 163 163 return err; 164 164 } 165 165 ··· 190 190 191 191 static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 192 192 { 193 - struct saa7134_fh *fh = q->priv_data; 194 - struct saa7134_dev *dev = fh->dev; 195 193 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb); 196 194 197 - saa7134_dma_free(dev,buf); 195 + saa7134_dma_free(q,buf); 198 196 } 199 197 200 198 struct videobuf_queue_ops saa7134_vbi_qops = {
+4 -5
drivers/media/video/saa7134/saa7134-video.c
··· 993 993 buf->vb.size != size || 994 994 buf->vb.field != field || 995 995 buf->fmt != fh->fmt) { 996 - saa7134_dma_free(dev,buf); 996 + saa7134_dma_free(q,buf); 997 997 } 998 998 999 999 if (STATE_NEEDS_INIT == buf->vb.state) { ··· 1004 1004 buf->fmt = fh->fmt; 1005 1005 buf->pt = &fh->pt_cap; 1006 1006 1007 - err = videobuf_iolock(dev->pci,&buf->vb,&dev->ovbuf); 1007 + err = videobuf_iolock(q,&buf->vb,&dev->ovbuf); 1008 1008 if (err) 1009 1009 goto oops; 1010 1010 err = saa7134_pgtable_build(dev->pci,buf->pt, ··· 1019 1019 return 0; 1020 1020 1021 1021 oops: 1022 - saa7134_dma_free(dev,buf); 1022 + saa7134_dma_free(q,buf); 1023 1023 return err; 1024 1024 } 1025 1025 ··· 1045 1045 1046 1046 static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 1047 1047 { 1048 - struct saa7134_fh *fh = q->priv_data; 1049 1048 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb); 1050 1049 1051 - saa7134_dma_free(fh->dev,buf); 1050 + saa7134_dma_free(q,buf); 1052 1051 } 1053 1052 1054 1053 static struct videobuf_queue_ops video_qops = {
+1 -1
drivers/media/video/saa7134/saa7134.h
··· 579 579 unsigned int state); 580 580 void saa7134_buffer_next(struct saa7134_dev *dev, struct saa7134_dmaqueue *q); 581 581 void saa7134_buffer_timeout(unsigned long data); 582 - void saa7134_dma_free(struct saa7134_dev *dev,struct saa7134_buf *buf); 582 + void saa7134_dma_free(struct videobuf_queue *q,struct saa7134_buf *buf); 583 583 584 584 int saa7134_set_dmabits(struct saa7134_dev *dev); 585 585
+3 -3
drivers/media/video/v4l2-common.c
··· 481 481 prt_names(p->memory,v4l2_memory_names), 482 482 p->m.userptr); 483 483 printk ("%s: timecode= %02d:%02d:%02d type=%d, " 484 - "flags=0x%08d, frames=%d, userbits=0x%08x", 484 + "flags=0x%08d, frames=%d, userbits=0x%08x\n", 485 485 s,tc->hours,tc->minutes,tc->seconds, 486 486 tc->type, tc->flags, tc->frames, (__u32) tc->userbits); 487 487 break; ··· 489 489 case VIDIOC_QUERYCAP: 490 490 { 491 491 struct v4l2_capability *p=arg; 492 - printk ("%s: driver=%s, card=%s, bus=%s, version=%d, " 493 - "capabilities=%d\n", s, 492 + printk ("%s: driver=%s, card=%s, bus=%s, version=0x%08x, " 493 + "capabilities=0x%08x\n", s, 494 494 p->driver,p->card,p->bus_info, 495 495 p->version, 496 496 p->capabilities);
+187 -63
drivers/media/video/video-buf.c
··· 1 1 /* 2 2 * 3 3 * generic helper functions for video4linux capture buffers, to handle 4 - * memory management and PCI DMA. Right now bttv + saa7134 use it. 4 + * memory management and PCI DMA. 5 + * Right now, bttv, saa7134, saa7146 and cx88 use it. 5 6 * 6 7 * The functions expect the hardware being able to scatter gatter 7 8 * (i.e. the buffers are not linear in physical memory, but fragmented 8 9 * into PAGE_SIZE chunks). They also assume the driver does not need 9 - * to touch the video data (thus it is probably not useful for USB 1.1 10 - * as data often must be uncompressed by the drivers). 10 + * to touch the video data. 11 + * 12 + * device specific map/unmap/sync stuff now are mapped as operations 13 + * to allow its usage by USB and virtual devices. 11 14 * 12 15 * (c) 2001-2004 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs] 16 + * (c) 2006 Mauro Carvalho Chehab <mchehab@infradead.org> 17 + * (c) 2006 Ted Walther and John Sokol 13 18 * 14 19 * This program is free software; you can redistribute it and/or modify 15 20 * it under the terms of the GNU General Public License as published by ··· 172 167 dprintk(1,"vmalloc_32(%d pages) failed\n",nr_pages); 173 168 return -ENOMEM; 174 169 } 170 + dprintk(1,"vmalloc is at addr 0x%08lx, size=%d\n", 171 + (unsigned long)dma->vmalloc, 172 + nr_pages << PAGE_SHIFT); 175 173 memset(dma->vmalloc,0,nr_pages << PAGE_SHIFT); 176 174 dma->nr_pages = nr_pages; 177 175 return 0; ··· 194 186 return 0; 195 187 } 196 188 197 - int videobuf_dma_pci_map(struct pci_dev *dev, struct videobuf_dmabuf *dma) 189 + int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma) 198 190 { 191 + void *dev=q->dev; 192 + 199 193 MAGIC_CHECK(dma->magic,MAGIC_DMABUF); 200 194 BUG_ON(0 == dma->nr_pages); 201 195 ··· 207 197 } 208 198 if (dma->vmalloc) { 209 199 dma->sglist = videobuf_vmalloc_to_sg 210 - (dma->vmalloc,dma->nr_pages); 200 + (dma->vmalloc,dma->nr_pages); 211 201 } 212 202 if (dma->bus_addr) { 213 203 dma->sglist = kmalloc(sizeof(struct scatterlist), GFP_KERNEL); ··· 222 212 dprintk(1,"scatterlist is NULL\n"); 223 213 return -ENOMEM; 224 214 } 225 - 226 215 if (!dma->bus_addr) { 227 - dma->sglen = pci_map_sg(dev,dma->sglist,dma->nr_pages, 228 - dma->direction); 216 + if (q->ops->vb_map_sg) { 217 + dma->sglen = q->ops->vb_map_sg(dev,dma->sglist, 218 + dma->nr_pages, dma->direction); 219 + } 229 220 if (0 == dma->sglen) { 230 221 printk(KERN_WARNING 231 - "%s: pci_map_sg failed\n",__FUNCTION__); 222 + "%s: videobuf_map_sg failed\n",__FUNCTION__); 232 223 kfree(dma->sglist); 233 224 dma->sglist = NULL; 234 225 dma->sglen = 0; ··· 239 228 return 0; 240 229 } 241 230 242 - int videobuf_dma_pci_sync(struct pci_dev *dev, struct videobuf_dmabuf *dma) 231 + int videobuf_dma_sync(struct videobuf_queue* q,struct videobuf_dmabuf *dma) 243 232 { 233 + void *dev=q->dev; 234 + 244 235 MAGIC_CHECK(dma->magic,MAGIC_DMABUF); 245 236 BUG_ON(!dma->sglen); 246 237 247 - if (!dma->bus_addr) 248 - pci_dma_sync_sg_for_cpu(dev,dma->sglist,dma->nr_pages,dma->direction); 238 + if (!dma->bus_addr && q->ops->vb_dma_sync_sg) 239 + q->ops->vb_dma_sync_sg(dev,dma->sglist,dma->nr_pages, 240 + dma->direction); 241 + 249 242 return 0; 250 243 } 251 244 252 - int videobuf_dma_pci_unmap(struct pci_dev *dev, struct videobuf_dmabuf *dma) 245 + int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma) 253 246 { 247 + void *dev=q->dev; 248 + 254 249 MAGIC_CHECK(dma->magic,MAGIC_DMABUF); 255 250 if (!dma->sglen) 256 251 return 0; 257 252 258 - if (!dma->bus_addr) 259 - pci_unmap_sg(dev,dma->sglist,dma->nr_pages,dma->direction); 253 + if (!dma->bus_addr && q->ops->vb_unmap_sg) 254 + q->ops->vb_unmap_sg(dev,dma->sglist,dma->nr_pages, 255 + dma->direction); 260 256 kfree(dma->sglist); 261 257 dma->sglist = NULL; 262 258 dma->sglen = 0; ··· 336 318 } 337 319 338 320 int 339 - videobuf_iolock(struct pci_dev *pci, struct videobuf_buffer *vb, 321 + videobuf_iolock(struct videobuf_queue* q, struct videobuf_buffer *vb, 340 322 struct v4l2_framebuffer *fbuf) 341 323 { 342 324 int err,pages; ··· 375 357 default: 376 358 BUG(); 377 359 } 378 - err = videobuf_dma_pci_map(pci,&vb->dma); 360 + err = videobuf_dma_map(q,&vb->dma); 379 361 if (0 != err) 380 362 return err; 381 363 ··· 384 366 385 367 /* --------------------------------------------------------------------- */ 386 368 369 + void videobuf_queue_pci(struct videobuf_queue* q) 370 + { 371 + /* If not specified, defaults to PCI map sg */ 372 + if (!q->ops->vb_map_sg) 373 + q->ops->vb_map_sg=(vb_map_sg_t *)pci_map_sg; 374 + 375 + if (!q->ops->vb_dma_sync_sg) 376 + q->ops->vb_dma_sync_sg=(vb_map_sg_t *)pci_dma_sync_sg_for_cpu; 377 + if (!q->ops->vb_unmap_sg) 378 + q->ops->vb_unmap_sg=(vb_map_sg_t *)pci_unmap_sg; 379 + } 380 + 381 + int videobuf_pci_dma_map(struct pci_dev *pci,struct videobuf_dmabuf *dma) 382 + { 383 + struct videobuf_queue q; 384 + 385 + q.dev=pci; 386 + q.ops->vb_map_sg=(vb_map_sg_t *)pci_unmap_sg; 387 + 388 + return (videobuf_dma_unmap(&q,dma)); 389 + } 390 + 391 + int videobuf_pci_dma_unmap(struct pci_dev *pci,struct videobuf_dmabuf *dma) 392 + { 393 + struct videobuf_queue q; 394 + 395 + q.dev=pci; 396 + q.ops->vb_map_sg=(vb_map_sg_t *)pci_unmap_sg; 397 + 398 + return (videobuf_dma_unmap(&q,dma)); 399 + } 400 + 387 401 void videobuf_queue_init(struct videobuf_queue* q, 388 402 struct videobuf_queue_ops *ops, 389 - struct pci_dev *pci, 403 + void *dev, 390 404 spinlock_t *irqlock, 391 405 enum v4l2_buf_type type, 392 406 enum v4l2_field field, ··· 427 377 { 428 378 memset(q,0,sizeof(*q)); 429 379 q->irqlock = irqlock; 430 - q->pci = pci; 380 + q->dev = dev; 431 381 q->type = type; 432 382 q->field = field; 433 383 q->msize = msize; 434 384 q->ops = ops; 435 385 q->priv_data = priv; 386 + 387 + videobuf_queue_pci(q); 436 388 437 389 mutex_init(&q->lock); 438 390 INIT_LIST_HEAD(&q->stream); ··· 483 431 int i; 484 432 485 433 /* remove queued buffers from list */ 486 - spin_lock_irqsave(q->irqlock,flags); 434 + if (q->irqlock) 435 + spin_lock_irqsave(q->irqlock,flags); 487 436 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 488 437 if (NULL == q->bufs[i]) 489 438 continue; ··· 493 440 q->bufs[i]->state = STATE_ERROR; 494 441 } 495 442 } 496 - spin_unlock_irqrestore(q->irqlock,flags); 443 + if (q->irqlock) 444 + spin_unlock_irqrestore(q->irqlock,flags); 497 445 498 446 /* free all buffers + clear queue */ 499 447 for (i = 0; i < VIDEO_MAX_FRAME; i++) { ··· 588 534 unsigned int size,count; 589 535 int retval; 590 536 591 - if (req->type != q->type) 537 + if (req->type != q->type) { 538 + dprintk(1,"reqbufs: queue type invalid\n"); 592 539 return -EINVAL; 593 - if (req->count < 1) 540 + } 541 + if (req->count < 1) { 542 + dprintk(1,"reqbufs: count invalid (%d)\n",req->count); 594 543 return -EINVAL; 544 + } 595 545 if (req->memory != V4L2_MEMORY_MMAP && 596 546 req->memory != V4L2_MEMORY_USERPTR && 597 - req->memory != V4L2_MEMORY_OVERLAY) 547 + req->memory != V4L2_MEMORY_OVERLAY) { 548 + dprintk(1,"reqbufs: memory type invalid\n"); 598 549 return -EINVAL; 550 + } 599 551 600 - if (q->streaming) 552 + if (q->streaming) { 553 + dprintk(1,"reqbufs: streaming already exists\n"); 601 554 return -EBUSY; 602 - if (!list_empty(&q->stream)) 555 + } 556 + if (!list_empty(&q->stream)) { 557 + dprintk(1,"reqbufs: stream running\n"); 603 558 return -EBUSY; 559 + } 604 560 605 561 mutex_lock(&q->lock); 606 562 count = req->count; ··· 623 559 count, size, (count*size)>>PAGE_SHIFT); 624 560 625 561 retval = videobuf_mmap_setup(q,count,size,req->memory); 626 - if (retval < 0) 562 + if (retval < 0) { 563 + dprintk(1,"reqbufs: mmap setup returned %d\n",retval); 627 564 goto done; 565 + } 628 566 629 567 req->count = count; 630 568 ··· 638 572 int 639 573 videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b) 640 574 { 641 - if (unlikely(b->type != q->type)) 575 + if (unlikely(b->type != q->type)) { 576 + dprintk(1,"querybuf: Wrong type.\n"); 642 577 return -EINVAL; 643 - if (unlikely(b->index < 0 || b->index >= VIDEO_MAX_FRAME)) 578 + } 579 + if (unlikely(b->index < 0 || b->index >= VIDEO_MAX_FRAME)) { 580 + dprintk(1,"querybuf: index out of range.\n"); 644 581 return -EINVAL; 645 - if (unlikely(NULL == q->bufs[b->index])) 582 + } 583 + if (unlikely(NULL == q->bufs[b->index])) { 584 + dprintk(1,"querybuf: buffer is null.\n"); 646 585 return -EINVAL; 586 + } 647 587 videobuf_status(b,q->bufs[b->index],q->type); 648 588 return 0; 649 589 } ··· 665 593 666 594 mutex_lock(&q->lock); 667 595 retval = -EBUSY; 668 - if (q->reading) 596 + if (q->reading) { 597 + dprintk(1,"qbuf: Reading running...\n"); 669 598 goto done; 599 + } 670 600 retval = -EINVAL; 671 - if (b->type != q->type) 601 + if (b->type != q->type) { 602 + dprintk(1,"qbuf: Wrong type.\n"); 672 603 goto done; 673 - if (b->index < 0 || b->index >= VIDEO_MAX_FRAME) 604 + } 605 + if (b->index < 0 || b->index >= VIDEO_MAX_FRAME) { 606 + dprintk(1,"qbuf: index out of range.\n"); 674 607 goto done; 608 + } 675 609 buf = q->bufs[b->index]; 676 - if (NULL == buf) 610 + if (NULL == buf) { 611 + dprintk(1,"qbuf: buffer is null.\n"); 677 612 goto done; 613 + } 678 614 MAGIC_CHECK(buf->magic,MAGIC_BUFFER); 679 - if (buf->memory != b->memory) 615 + if (buf->memory != b->memory) { 616 + dprintk(1,"qbuf: memory type is wrong.\n"); 680 617 goto done; 618 + } 681 619 if (buf->state == STATE_QUEUED || 682 - buf->state == STATE_ACTIVE) 620 + buf->state == STATE_ACTIVE) { 621 + dprintk(1,"qbuf: buffer is already queued or active.\n"); 683 622 goto done; 623 + } 684 624 685 625 if (b->flags & V4L2_BUF_FLAG_INPUT) { 686 - if (b->input >= q->inputs) 626 + if (b->input >= q->inputs) { 627 + dprintk(1,"qbuf: wrong input.\n"); 687 628 goto done; 629 + } 688 630 buf->input = b->input; 689 631 } else { 690 632 buf->input = UNSET; ··· 706 620 707 621 switch (b->memory) { 708 622 case V4L2_MEMORY_MMAP: 709 - if (0 == buf->baddr) 623 + if (0 == buf->baddr) { 624 + dprintk(1,"qbuf: mmap requested but buffer addr is zero!\n"); 710 625 goto done; 626 + } 711 627 break; 712 628 case V4L2_MEMORY_USERPTR: 713 - if (b->length < buf->bsize) 629 + if (b->length < buf->bsize) { 630 + dprintk(1,"qbuf: buffer length is not enough\n"); 714 631 goto done; 632 + } 715 633 if (STATE_NEEDS_INIT != buf->state && buf->baddr != b->m.userptr) 716 634 q->ops->buf_release(q,buf); 717 635 buf->baddr = b->m.userptr; ··· 724 634 buf->boff = b->m.offset; 725 635 break; 726 636 default: 637 + dprintk(1,"qbuf: wrong memory type\n"); 727 638 goto done; 728 639 } 729 640 641 + dprintk(1,"qbuf: requesting next field\n"); 730 642 field = videobuf_next_field(q); 731 643 retval = q->ops->buf_prepare(q,buf,field); 732 - if (0 != retval) 644 + if (0 != retval) { 645 + dprintk(1,"qbuf: buffer_prepare returned %d\n",retval); 733 646 goto done; 647 + } 734 648 735 649 list_add_tail(&buf->stream,&q->stream); 736 650 if (q->streaming) { 737 - spin_lock_irqsave(q->irqlock,flags); 651 + if (q->irqlock) 652 + spin_lock_irqsave(q->irqlock,flags); 738 653 q->ops->buf_queue(q,buf); 739 - spin_unlock_irqrestore(q->irqlock,flags); 654 + if (q->irqlock) 655 + spin_unlock_irqrestore(q->irqlock,flags); 740 656 } 657 + dprintk(1,"qbuf: succeded\n"); 741 658 retval = 0; 742 659 743 660 done: ··· 761 664 762 665 mutex_lock(&q->lock); 763 666 retval = -EBUSY; 764 - if (q->reading) 667 + if (q->reading) { 668 + dprintk(1,"dqbuf: Reading running...\n"); 765 669 goto done; 670 + } 766 671 retval = -EINVAL; 767 - if (b->type != q->type) 672 + if (b->type != q->type) { 673 + dprintk(1,"dqbuf: Wrong type.\n"); 768 674 goto done; 769 - if (list_empty(&q->stream)) 675 + } 676 + if (list_empty(&q->stream)) { 677 + dprintk(1,"dqbuf: stream running\n"); 770 678 goto done; 679 + } 771 680 buf = list_entry(q->stream.next, struct videobuf_buffer, stream); 772 681 retval = videobuf_waiton(buf, nonblocking, 1); 773 - if (retval < 0) 682 + if (retval < 0) { 683 + dprintk(1,"dqbuf: waiton returned %d\n",retval); 774 684 goto done; 685 + } 775 686 switch (buf->state) { 776 687 case STATE_ERROR: 688 + dprintk(1,"dqbuf: state is error\n"); 777 689 retval = -EIO; 778 - /* fall through */ 690 + videobuf_dma_sync(q,&buf->dma); 691 + buf->state = STATE_IDLE; 692 + break; 779 693 case STATE_DONE: 780 - videobuf_dma_pci_sync(q->pci,&buf->dma); 694 + dprintk(1,"dqbuf: state is done\n"); 695 + videobuf_dma_sync(q,&buf->dma); 781 696 buf->state = STATE_IDLE; 782 697 break; 783 698 default: 699 + dprintk(1,"dqbuf: state invalid\n"); 784 700 retval = -EINVAL; 785 701 goto done; 786 702 } ··· 821 711 if (q->streaming) 822 712 goto done; 823 713 q->streaming = 1; 824 - spin_lock_irqsave(q->irqlock,flags); 714 + if (q->irqlock) 715 + spin_lock_irqsave(q->irqlock,flags); 825 716 list_for_each(list,&q->stream) { 826 717 buf = list_entry(list, struct videobuf_buffer, stream); 827 718 if (buf->state == STATE_PREPARED) 828 719 q->ops->buf_queue(q,buf); 829 720 } 830 - spin_unlock_irqrestore(q->irqlock,flags); 721 + if (q->irqlock) 722 + spin_unlock_irqrestore(q->irqlock,flags); 831 723 832 724 done: 833 725 mutex_unlock(&q->lock); ··· 874 762 goto done; 875 763 876 764 /* start capture & wait */ 877 - spin_lock_irqsave(q->irqlock,flags); 765 + if (q->irqlock) 766 + spin_lock_irqsave(q->irqlock,flags); 878 767 q->ops->buf_queue(q,q->read_buf); 879 - spin_unlock_irqrestore(q->irqlock,flags); 768 + if (q->irqlock) 769 + spin_unlock_irqrestore(q->irqlock,flags); 880 770 retval = videobuf_waiton(q->read_buf,0,0); 881 771 if (0 == retval) { 882 - videobuf_dma_pci_sync(q->pci,&q->read_buf->dma); 772 + videobuf_dma_sync(q,&q->read_buf->dma); 883 773 if (STATE_ERROR == q->read_buf->state) 884 774 retval = -EIO; 885 775 else ··· 923 809 /* need to capture a new frame */ 924 810 retval = -ENOMEM; 925 811 q->read_buf = videobuf_alloc(q->msize); 812 + dprintk(1,"video alloc=0x%08x\n",(unsigned int) q->read_buf); 926 813 if (NULL == q->read_buf) 927 814 goto done; 928 815 q->read_buf->memory = V4L2_MEMORY_USERPTR; ··· 935 820 q->read_buf = NULL; 936 821 goto done; 937 822 } 938 - spin_lock_irqsave(q->irqlock,flags); 823 + if (q->irqlock) 824 + spin_lock_irqsave(q->irqlock,flags); 939 825 q->ops->buf_queue(q,q->read_buf); 940 - spin_unlock_irqrestore(q->irqlock,flags); 826 + if (q->irqlock) 827 + spin_unlock_irqrestore(q->irqlock,flags); 941 828 q->read_off = 0; 942 829 } 943 830 ··· 947 830 retval = videobuf_waiton(q->read_buf, nonblocking, 1); 948 831 if (0 != retval) 949 832 goto done; 950 - videobuf_dma_pci_sync(q->pci,&q->read_buf->dma); 833 + videobuf_dma_sync(q,&q->read_buf->dma); 951 834 952 835 if (STATE_ERROR == q->read_buf->state) { 953 836 /* catch I/O errors */ ··· 1004 887 return err; 1005 888 list_add_tail(&q->bufs[i]->stream, &q->stream); 1006 889 } 1007 - spin_lock_irqsave(q->irqlock,flags); 890 + if (q->irqlock) 891 + spin_lock_irqsave(q->irqlock,flags); 1008 892 for (i = 0; i < count; i++) 1009 893 q->ops->buf_queue(q,q->bufs[i]); 1010 - spin_unlock_irqrestore(q->irqlock,flags); 894 + if (q->irqlock) 895 + spin_unlock_irqrestore(q->irqlock,flags); 1011 896 q->reading = 1; 1012 897 return 0; 1013 898 } ··· 1104 985 if (q->read_off == q->read_buf->size) { 1105 986 list_add_tail(&q->read_buf->stream, 1106 987 &q->stream); 1107 - spin_lock_irqsave(q->irqlock,flags); 988 + if (q->irqlock) 989 + spin_lock_irqsave(q->irqlock,flags); 1108 990 q->ops->buf_queue(q,q->read_buf); 1109 - spin_unlock_irqrestore(q->irqlock,flags); 991 + if (q->irqlock) 992 + spin_unlock_irqrestore(q->irqlock,flags); 1110 993 q->read_buf = NULL; 1111 994 } 1112 995 if (retval < 0) ··· 1370 1249 EXPORT_SYMBOL_GPL(videobuf_dma_init_user); 1371 1250 EXPORT_SYMBOL_GPL(videobuf_dma_init_kernel); 1372 1251 EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay); 1373 - EXPORT_SYMBOL_GPL(videobuf_dma_pci_map); 1374 - EXPORT_SYMBOL_GPL(videobuf_dma_pci_sync); 1375 - EXPORT_SYMBOL_GPL(videobuf_dma_pci_unmap); 1252 + EXPORT_SYMBOL_GPL(videobuf_dma_map); 1253 + EXPORT_SYMBOL_GPL(videobuf_dma_sync); 1254 + EXPORT_SYMBOL_GPL(videobuf_dma_unmap); 1376 1255 EXPORT_SYMBOL_GPL(videobuf_dma_free); 1256 + 1257 + EXPORT_SYMBOL_GPL(videobuf_pci_dma_map); 1258 + EXPORT_SYMBOL_GPL(videobuf_pci_dma_unmap); 1377 1259 1378 1260 EXPORT_SYMBOL_GPL(videobuf_alloc); 1379 1261 EXPORT_SYMBOL_GPL(videobuf_waiton);
+2 -1
include/media/saa7146_vv.h
··· 197 197 void saa7146_buffer_next(struct saa7146_dev *dev, struct saa7146_dmaqueue *q,int vbi); 198 198 int saa7146_buffer_queue(struct saa7146_dev *dev, struct saa7146_dmaqueue *q, struct saa7146_buf *buf); 199 199 void saa7146_buffer_timeout(unsigned long data); 200 - void saa7146_dma_free(struct saa7146_dev *dev,struct saa7146_buf *buf); 200 + void saa7146_dma_free(struct saa7146_dev* dev,struct videobuf_queue *q, 201 + struct saa7146_buf *buf); 201 202 202 203 int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv); 203 204 int saa7146_vv_release(struct saa7146_dev* dev);
+41 -15
include/media/video-buf.h
··· 1 1 /* 2 2 * 3 3 * generic helper functions for video4linux capture buffers, to handle 4 - * memory management and PCI DMA. Right now bttv + saa7134 use it. 4 + * memory management and PCI DMA. 5 + * Right now, bttv, saa7134, saa7146 and cx88 use it. 5 6 * 6 7 * The functions expect the hardware being able to scatter gatter 7 8 * (i.e. the buffers are not linear in physical memory, but fragmented 8 9 * into PAGE_SIZE chunks). They also assume the driver does not need 9 - * to touch the video data (thus it is probably not useful for USB as 10 - * data often must be uncompressed by the drivers). 10 + * to touch the video data. 11 + * 12 + * device specific map/unmap/sync stuff now are mapped as file operations 13 + * to allow its usage by USB and virtual devices. 11 14 * 12 15 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org> 16 + * (c) 2006 Mauro Carvalho Chehab, <mchehab@infradead.org> 17 + * (c) 2006 Ted Walther and John Sokol 13 18 * 14 19 * This program is free software; you can redistribute it and/or modify 15 20 * it under the terms of the GNU General Public License as published by ··· 43 38 struct scatterlist* videobuf_pages_to_sg(struct page **pages, int nr_pages, 44 39 int offset); 45 40 41 + struct videobuf_buffer; 42 + struct videobuf_queue; 43 + 46 44 /* --------------------------------------------------------------------- */ 47 45 48 46 /* ··· 57 49 * pointer + length. The kernel version just wants the size and 58 50 * does memory allocation too using vmalloc_32(). 59 51 * 60 - * videobuf_dma_pci_*() 52 + * videobuf_dma_*() 61 53 * see Documentation/DMA-mapping.txt, these functions to 62 54 * basically the same. The map function does also build a 63 55 * scatterlist for the buffer (and unmap frees it ...) ··· 94 86 int nr_pages); 95 87 int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction, 96 88 dma_addr_t addr, int nr_pages); 97 - int videobuf_dma_pci_map(struct pci_dev *dev, struct videobuf_dmabuf *dma); 98 - int videobuf_dma_pci_sync(struct pci_dev *dev, 99 - struct videobuf_dmabuf *dma); 100 - int videobuf_dma_pci_unmap(struct pci_dev *dev, struct videobuf_dmabuf *dma); 101 89 int videobuf_dma_free(struct videobuf_dmabuf *dma); 90 + 91 + int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma); 92 + int videobuf_dma_sync(struct videobuf_queue* q,struct videobuf_dmabuf *dma); 93 + int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma); 94 + 95 + /*FIXME: these variants are used only on *-alsa code, where videobuf is 96 + * used without queue 97 + */ 98 + int videobuf_pci_dma_map(struct pci_dev *pci,struct videobuf_dmabuf *dma); 99 + int videobuf_pci_dma_unmap(struct pci_dev *pci,struct videobuf_dmabuf *dma); 102 100 103 101 /* --------------------------------------------------------------------- */ 104 102 ··· 128 114 * videobuf_dma_init_user function listed above. 129 115 * 130 116 */ 131 - 132 - struct videobuf_buffer; 133 - struct videobuf_queue; 134 117 135 118 struct videobuf_mapping { 136 119 unsigned int count; ··· 175 164 struct timeval ts; 176 165 }; 177 166 167 + typedef int (vb_map_sg_t)(void *dev,struct scatterlist *sglist,int nr_pages, 168 + int direction); 169 + 170 + 178 171 struct videobuf_queue_ops { 179 172 int (*buf_setup)(struct videobuf_queue *q, 180 173 unsigned int *count, unsigned int *size); ··· 189 174 struct videobuf_buffer *vb); 190 175 void (*buf_release)(struct videobuf_queue *q, 191 176 struct videobuf_buffer *vb); 177 + 178 + /* Helper operations - device dependent. 179 + * If null, videobuf_init defaults all to PCI handling 180 + */ 181 + 182 + vb_map_sg_t *vb_map_sg; 183 + vb_map_sg_t *vb_dma_sync_sg; 184 + vb_map_sg_t *vb_unmap_sg; 192 185 }; 193 186 194 187 struct videobuf_queue { 195 188 struct mutex lock; 196 189 spinlock_t *irqlock; 197 - struct pci_dev *pci; 190 + void *dev; /* on pci, points to struct pci_dev */ 198 191 199 192 enum v4l2_buf_type type; 200 193 unsigned int inputs; /* for V4L2_BUF_FLAG_INPUT */ ··· 227 204 228 205 void* videobuf_alloc(unsigned int size); 229 206 int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr); 230 - int videobuf_iolock(struct pci_dev *pci, struct videobuf_buffer *vb, 231 - struct v4l2_framebuffer *fbuf); 207 + int videobuf_iolock(struct videobuf_queue* q, struct videobuf_buffer *vb, 208 + struct v4l2_framebuffer *fbuf); 209 + 210 + /* Maps fops to PCI stuff */ 211 + void videobuf_queue_pci(struct videobuf_queue* q); 232 212 233 213 void videobuf_queue_init(struct videobuf_queue *q, 234 214 struct videobuf_queue_ops *ops, 235 - struct pci_dev *pci, 215 + void *dev, 236 216 spinlock_t *irqlock, 237 217 enum v4l2_buf_type type, 238 218 enum v4l2_field field,