Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 197380
b: refs/heads/master
c: 717f4a5
h: refs/heads/master
v: v3
  • Loading branch information
Marin Mitov authored and Greg Kroah-Hartman committed May 11, 2010
1 parent becbea6 commit ba44a61
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 0cbd8d9854284d3ff38d04aaa3ae726fb1c4a958
refs/heads/master: 717f4a5f55e307b3ba2b1a8c05428bb5dd35047e
68 changes: 36 additions & 32 deletions trunk/drivers/staging/dt3155v4l/dt3155v4l.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/***************************************************************************
* Copyright (C) 2006-2010 by Marin Mitov *
* mitov@issp.bas.bg *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/

#include <media/v4l2-dev.h>
#include <media/videobuf-core.h>
#include <media/v4l2-ioctl.h>
Expand Down Expand Up @@ -260,9 +280,11 @@ dt3155_dma_contig_user_get(struct videobuf_dma_contig_memory *mem,
struct vm_area_struct *vma;
unsigned long prev_pfn, this_pfn;
unsigned long pages_done, user_address;
unsigned int offset;
int ret;

mem->size = PAGE_ALIGN(vb->size);
offset = vb->baddr & ~PAGE_MASK;
mem->size = PAGE_ALIGN(vb->size + offset);
mem->is_userptr = 0;
ret = -EINVAL;

Expand All @@ -285,7 +307,7 @@ dt3155_dma_contig_user_get(struct videobuf_dma_contig_memory *mem,
break;

if (pages_done == 0)
mem->dma_handle = this_pfn << PAGE_SHIFT;
mem->dma_handle = (this_pfn << PAGE_SHIFT) + offset;
else if (this_pfn != (prev_pfn + 1))
ret = -EFAULT;

Expand Down Expand Up @@ -416,14 +438,14 @@ dt3155_vm_close(struct vm_area_struct *vma)
struct videobuf_queue *q = map->q;
int i;

dev_dbg(map->q->dev, "vm_close %p [count=%u,vma=%08lx-%08lx]\n",
dev_dbg(q->dev, "vm_close %p [count=%u,vma=%08lx-%08lx]\n",
map, map->count, vma->vm_start, vma->vm_end);

map->count--;
if (0 == map->count) {
struct videobuf_dma_contig_memory *mem;

dev_dbg(map->q->dev, "munmap %p q=%p\n", map, q);
dev_dbg(q->dev, "munmap %p q=%p\n", map, q);
mutex_lock(&q->vb_lock);

/* We need first to cancel streams, before unmapping */
Expand All @@ -450,7 +472,7 @@ dt3155_vm_close(struct vm_area_struct *vma)
/* vfree is not atomic - can't be
called with IRQ's disabled
*/
dev_dbg(map->q->dev, "buf[%d] freeing %p\n",
dev_dbg(q->dev, "buf[%d] freeing %p\n",
i, mem->vaddr);

dt3155_free_buffer(q->dev, mem->size,
Expand All @@ -475,51 +497,33 @@ static const struct vm_operations_struct dt3155_vm_ops = {

/* same as videobuf_mmap_mapper(), but allocates from the pool */
static int
dt3155_mmap_mapper(struct videobuf_queue *q, struct vm_area_struct *vma)
dt3155_mmap_mapper(struct videobuf_queue *q, struct videobuf_buffer *buf,
struct vm_area_struct *vma)
{
struct videobuf_dma_contig_memory *mem;
struct videobuf_mapping *map;
unsigned int first;
int retval;
unsigned long size, offset = vma->vm_pgoff << PAGE_SHIFT;
unsigned long size;

dev_dbg(q->dev, "%s\n", __func__);
if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED))
return -EINVAL;

/* look for first buffer to map */
for (first = 0; first < VIDEO_MAX_FRAME; first++) {
if (!q->bufs[first])
continue;

if (V4L2_MEMORY_MMAP != q->bufs[first]->memory)
continue;
if (q->bufs[first]->boff == offset)
break;
}
if (VIDEO_MAX_FRAME == first) {
dev_dbg(q->dev, "invalid user space offset [offset=0x%lx]\n",
offset);
return -EINVAL;
}

/* create mapping + update buffer list */
map = kzalloc(sizeof(struct videobuf_mapping), GFP_KERNEL);
if (!map)
return -ENOMEM;

q->bufs[first]->map = map;
buf->map = map;
map->start = vma->vm_start;
map->end = vma->vm_end;
map->q = q;

q->bufs[first]->baddr = vma->vm_start;
buf->baddr = vma->vm_start;

mem = q->bufs[first]->priv;
mem = buf->priv;
BUG_ON(!mem);
MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);

mem->size = PAGE_ALIGN(q->bufs[first]->bsize);
mem->size = PAGE_ALIGN(buf->bsize);
mem->vaddr = dt3155_alloc_buffer(q->dev, mem->size,
&mem->dma_handle, GFP_KERNEL);
if (!mem->vaddr) {
Expand Down Expand Up @@ -552,8 +556,8 @@ dt3155_mmap_mapper(struct videobuf_queue *q, struct vm_area_struct *vma)

dev_dbg(q->dev, "mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx buf %d\n",
map, q, vma->vm_start, vma->vm_end,
(long int) q->bufs[first]->bsize,
vma->vm_pgoff, first);
(long int)buf->bsize,
vma->vm_pgoff, buf->i);

dt3155_vm_open(vma);

Expand Down

0 comments on commit ba44a61

Please sign in to comment.