diff options
author | Mauro Carvalho Chehab <mchehab@infradead.org> | 2007-08-02 23:31:54 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2007-08-02 23:31:54 -0300 |
commit | 6c1ecebd3cede92652f697eb2cbf456ce6226ced (patch) | |
tree | 7a0d892486af448d9abcdbf6519c2e4ecceed585 | |
parent | 9beccd8652e3b4ffa1b9bffa7ab7d434c172cbfc (diff) | |
download | mediapointer-dvb-s2-6c1ecebd3cede92652f697eb2cbf456ce6226ced.tar.gz mediapointer-dvb-s2-6c1ecebd3cede92652f697eb2cbf456ce6226ced.tar.bz2 |
Convert vivi to use videobuf-vmalloc
This patch removes the usage of videobuf-dma-sg from vivi driver, using
instead videobuf-vmalloc. This way, vivi will be useful for testing the
newer method. Reverting this patch won't hurt vivi, since both methods
work fine.
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
---
linux/drivers/media/video/vivi.c | 211 ++-------------------------------------
1 file changed, 14 insertions(+), 197 deletions(-)
-rw-r--r-- | linux/drivers/media/video/vivi.c | 211 |
1 files changed, 14 insertions, 197 deletions
diff --git a/linux/drivers/media/video/vivi.c b/linux/drivers/media/video/vivi.c index 2b443f798..aa91f1a9a 100644 --- a/linux/drivers/media/video/vivi.c +++ b/linux/drivers/media/video/vivi.c @@ -38,7 +38,7 @@ #include <linux/videodev.h> #endif #include <linux/interrupt.h> -#include <media/videobuf-dma-sg.h> +#include <media/videobuf-vmalloc.h> #include <media/v4l2-common.h> #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) #include <linux/kthread.h> @@ -154,10 +154,6 @@ struct vivi_buffer { struct videobuf_buffer vb; struct vivi_fmt *fmt; - -#ifdef CONFIG_VIVI_SCATTER - struct sg_to_addr *to_addr; -#endif }; struct vivi_dmaqueue { @@ -250,70 +246,13 @@ static u8 bars[8][3] = { #define TSTAMP_MAX_Y TSTAMP_MIN_Y+15 #define TSTAMP_MIN_X 64 -#ifdef CONFIG_VIVI_SCATTER -static void prep_to_addr(struct sg_to_addr to_addr[], - struct videobuf_buffer *vb) -{ - struct videobuf_dmabuf *dma=videobuf_to_dma(vb); - - int i, pos=0; - - for (i=0;i<vb->dma.nr_pages;i++) { - to_addr[i].sg=dma->sglist[i]; - to_addr[i].pos=pos; - pos += dma->sglist[i].length; - } -} - -static int get_addr_pos(int pos, int pages, struct sg_to_addr to_addr[]) -{ - int p1=0,p2=pages-1,p3=pages/2; - - /* Sanity test */ - BUG_ON (pos>=to_addr[p2].pos+to_addr[p2].sg->length); - while (p1+1<p2) { - if (pos < to_addr[p3].pos) { - p2=p3; - } else { - p1=p3; - } - p3=(p1+p2)/2; - } - if (pos >= to_addr[p2].pos) - p1=p2; - - return (p1); -} -#endif - -#ifdef CONFIG_VIVI_SCATTER -static void gen_line(struct sg_to_addr to_addr[],int inipos,int pages,int wmax, - int hmax, int line, char *timestr) -#else static void gen_line(char *basep,int inipos,int wmax, int hmax, int line, char *timestr) -#endif { int w,i,j,pos=inipos,y; char *p,*s; u8 chr,r,g,b,color; -#ifdef CONFIG_VIVI_SCATTER - int pgpos,oldpg; - char *basep; - struct page *pg; - - unsigned long flags; - spinlock_t spinlock; - - spin_lock_init(&spinlock); - - /* Get first addr pointed to pixel position */ - oldpg=get_addr_pos(pos,pages,to_addr); - pg=pfn_to_page(sg_dma_address(to_addr[oldpg].sg) >> PAGE_SHIFT); - spin_lock_irqsave(&spinlock,flags); - basep = kmap_atomic(pg, KM_BOUNCE_READ)+to_addr[oldpg].sg->offset; -#endif /* We will just duplicate the second pixel at the packet */ wmax/=2; @@ -325,18 +264,7 @@ static void gen_line(char *basep,int inipos,int wmax, b=bars[w*7/wmax][2]; for (color=0;color<4;color++) { -#ifdef CONFIG_VIVI_SCATTER - pgpos=get_addr_pos(pos,pages,to_addr); - if (pgpos!=oldpg) { - pg=pfn_to_page(sg_dma_address(to_addr[pgpos].sg) >> PAGE_SHIFT); - kunmap_atomic(basep, KM_BOUNCE_READ); - basep= kmap_atomic(pg, KM_BOUNCE_READ)+to_addr[pgpos].sg->offset; - oldpg=pgpos; - } - p=basep+pos-to_addr[pgpos].pos; -#else p=basep+pos; -#endif switch (color) { case 0: @@ -381,23 +309,7 @@ static void gen_line(char *basep,int inipos,int wmax, pos=inipos+j*2; for (color=0;color<4;color++) { -#ifdef CONFIG_VIVI_SCATTER - pgpos=get_addr_pos(pos,pages,to_addr); - if (pgpos!=oldpg) { - pg=pfn_to_page(sg_dma_address( - to_addr[pgpos].sg) - >> PAGE_SHIFT); - kunmap_atomic(basep, - KM_BOUNCE_READ); - basep= kmap_atomic(pg, - KM_BOUNCE_READ)+ - to_addr[pgpos].sg->offset; - oldpg=pgpos; - } - p=basep+pos-to_addr[pgpos].pos; -#else p=basep+pos; -#endif y=TO_Y(r,g,b); @@ -434,12 +346,7 @@ static void gen_line(char *basep,int inipos,int wmax, #endif end: -#ifdef CONFIG_VIVI_SCATTER - kunmap_atomic(basep, KM_BOUNCE_READ); - spin_unlock_irqrestore(&spinlock,flags); -#else return; -#endif } static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf) { @@ -447,49 +354,22 @@ static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf) int hmax = buf->vb.height; int wmax = buf->vb.width; struct timeval ts; -#ifdef CONFIG_VIVI_SCATTER - struct sg_to_addr *to_addr=buf->to_addr; - struct videobuf_buffer *vb=&buf->vb; -#else - char *tmpbuf; -#endif - struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); + char *tmpbuf = kmalloc(wmax*2,GFP_KERNEL); + void *vbuf=videobuf_to_vmalloc (&buf->vb); - -#ifdef CONFIG_VIVI_SCATTER - /* Test if DMA mapping is ready */ - if (!sg_dma_address(&vb->dma.sglist[0])) + if (!tmpbuf) return; - prep_to_addr(to_addr,vb); - - /* Check if there is enough memory */ - BUG_ON(dma->nr_pages << PAGE_SHIFT < (buf->vb.width*buf->vb.height)*2); -#else - if (dma->varea) { - tmpbuf=kmalloc (wmax*2, GFP_KERNEL); - } else { - tmpbuf=dma->vmalloc; - } - -#endif - for (h=0;h<hmax;h++) { -#ifdef CONFIG_VIVI_SCATTER - gen_line(to_addr,pos,vb->dma.nr_pages,wmax,hmax,h,dev->timestr); -#else - if (dma->varea) { - gen_line(tmpbuf,0,wmax,hmax,h,dev->timestr); - /* FIXME: replacing to __copy_to_user */ - if (copy_to_user(dma->varea+pos,tmpbuf,wmax*2)!=0) - dprintk(2,"vivifill copy_to_user failed.\n"); - } else { - gen_line(tmpbuf,pos,wmax,hmax,h,dev->timestr); - } -#endif + gen_line(tmpbuf,0,wmax,hmax,h,dev->timestr); + /* FIXME: replacing to __copy_to_user */ + if (copy_to_user(vbuf+pos,tmpbuf,wmax*2)!=0) + dprintk(2,"vivifill copy_to_user failed.\n"); pos += wmax*2; } + kfree(tmpbuf); + /* Updates stream time */ dev->us+=jiffies_to_usecs(jiffies-dev->jiffies); @@ -512,7 +392,7 @@ static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf) dev->h,dev->m,dev->s,(dev->us+500)/1000); dprintk(2,"vivifill at %s: Buffer 0x%08lx size= %d\n",dev->timestr, - (unsigned long)dma->varea,pos); + (unsigned long)tmpbuf,pos); /* Advice that buffer was filled */ buf->vb.state = STATE_DONE; @@ -808,22 +688,13 @@ buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size) static void free_buffer(struct videobuf_queue *vq, struct vivi_buffer *buf) { - struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); - dprintk(1,"%s\n",__FUNCTION__); if (in_interrupt()) BUG(); -#ifdef CONFIG_VIVI_SCATTER - /*FIXME: Maybe a spinlock is required here */ - kfree(buf->to_addr); - buf->to_addr=NULL; -#endif - videobuf_waiton(&buf->vb,0,0); - videobuf_dma_unmap(vq, dma); - videobuf_dma_free(dma); + videobuf_vmalloc_free(&buf->vb); buf->vb.state = STATE_NEEDS_INIT; } @@ -935,48 +806,6 @@ static void buffer_release(struct videobuf_queue *vq, struct videobuf_buffer *vb free_buffer(vq,buf); } -#ifdef CONFIG_VIVI_SCATTER -static int vivi_map_sg(void *dev, struct scatterlist *sg, int nents, - int direction) -{ - int i; - - dprintk(1,"%s, number of pages=%d\n",__FUNCTION__,nents); - BUG_ON(direction == DMA_NONE); - - for (i = 0; i < nents; i++ ) { - BUG_ON(!sg[i].page); - - sg_dma_address(&sg[i]) = page_to_phys(sg[i].page) + sg[i].offset; - } - - return nents; -} - -static int vivi_unmap_sg(void *dev,struct scatterlist *sglist,int nr_pages, - int direction) -{ - dprintk(1,"%s\n",__FUNCTION__); - return 0; -} - -static int vivi_dma_sync_sg(void *dev,struct scatterlist *sglist, int nr_pages, - int direction) -{ -// dprintk(1,"%s\n",__FUNCTION__); - -// flush_write_buffers(); - return 0; -} - -static struct videobuf_dma_sg_ops pci_ops = { - /* Non-pci handling routines */ - .vb_map_sg = vivi_map_sg, - .vb_dma_sync_sg = vivi_dma_sync_sg, - .vb_unmap_sg = vivi_unmap_sg, -}; -#endif - static struct videobuf_queue_ops vivi_video_qops = { .buf_setup = buffer_setup, .buf_prepare = buffer_prepare, @@ -1348,23 +1177,11 @@ static int vivi_open(struct inode *inode, struct file *file) sprintf(dev->timestr,"%02d:%02d:%02d:%03d", dev->h,dev->m,dev->s,(dev->us+500)/1000); -#ifdef CONFIG_VIVI_SCATTER - videobuf_queue_pci_init(&fh->vb_vidq,VIDEOBUF_DMA_SCATTER, &vivi_video_qops, + videobuf_queue_vmalloc_init(&fh->vb_vidq, &vivi_video_qops, NULL, NULL, fh->type, V4L2_FIELD_INTERLACED, sizeof(struct vivi_buffer),fh); -#else - videobuf_queue_pci_init(&fh->vb_vidq, &vivi_video_qops, - NULL, NULL, - fh->type, - V4L2_FIELD_INTERLACED, - sizeof(struct vivi_buffer),fh); -#endif - -#ifdef CONFIG_VIVI_SCATTER - videobuf_set_pci_ops (&fh->vb_vidq, NULL); -#endif return 0; } @@ -1464,7 +1281,7 @@ static const struct file_operations vivi_fops = { .read = vivi_read, .poll = vivi_poll, .ioctl = video_ioctl2, /* V4L2 ioctl handler */ - .mmap = vivi_mmap, + .mmap = vivi_mmap, .llseek = no_llseek, }; |