Commit 8a677b6e authored by Jan Kara's avatar Jan Kara Committed by Mauro Carvalho Chehab

[media] media: omap_vout: Convert omap_vout_uservirt_to_phys() to use get_vaddr_pfns()

Convert omap_vout_uservirt_to_phys() to use get_vaddr_pfns() instead of
hand made mapping of virtual address to physical address. Also the
function leaked page reference from get_user_pages() so fix that by
properly release the reference when omap_vout_buffer_release() is
called.
Signed-off-by: default avatarJan Kara <jack@suse.cz>
[hans.verkuil@cisco.com: remove unused variable]
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent 8025e5dd
...@@ -10,6 +10,7 @@ config VIDEO_OMAP2_VOUT ...@@ -10,6 +10,7 @@ config VIDEO_OMAP2_VOUT
select OMAP2_DSS if HAS_IOMEM && ARCH_OMAP2PLUS select OMAP2_DSS if HAS_IOMEM && ARCH_OMAP2PLUS
select OMAP2_VRFB if ARCH_OMAP2 || ARCH_OMAP3 select OMAP2_VRFB if ARCH_OMAP2 || ARCH_OMAP3
select VIDEO_OMAP2_VOUT_VRFB if VIDEO_OMAP2_VOUT && OMAP2_VRFB select VIDEO_OMAP2_VOUT_VRFB if VIDEO_OMAP2_VOUT && OMAP2_VRFB
select FRAME_VECTOR
default n default n
---help--- ---help---
V4L2 Display driver support for OMAP2/3 based boards. V4L2 Display driver support for OMAP2/3 based boards.
...@@ -195,46 +195,34 @@ static int omap_vout_try_format(struct v4l2_pix_format *pix) ...@@ -195,46 +195,34 @@ static int omap_vout_try_format(struct v4l2_pix_format *pix)
} }
/* /*
* omap_vout_uservirt_to_phys: This inline function is used to convert user * omap_vout_get_userptr: Convert user space virtual address to physical
* space virtual address to physical address. * address.
*/ */
static unsigned long omap_vout_uservirt_to_phys(unsigned long virtp) static int omap_vout_get_userptr(struct videobuf_buffer *vb, u32 virtp,
u32 *physp)
{ {
unsigned long physp = 0; struct frame_vector *vec;
struct vm_area_struct *vma; int ret;
struct mm_struct *mm = current->mm;
/* For kernel direct-mapped memory, take the easy way */ /* For kernel direct-mapped memory, take the easy way */
if (virtp >= PAGE_OFFSET) if (virtp >= PAGE_OFFSET) {
return virt_to_phys((void *) virtp); *physp = virt_to_phys((void *)virtp);
return 0;
down_read(&current->mm->mmap_sem); }
vma = find_vma(mm, virtp);
if (vma && (vma->vm_flags & VM_IO) && vma->vm_pgoff) {
/* this will catch, kernel-allocated, mmaped-to-usermode
addresses */
physp = (vma->vm_pgoff << PAGE_SHIFT) + (virtp - vma->vm_start);
up_read(&current->mm->mmap_sem);
} else {
/* otherwise, use get_user_pages() for general userland pages */
int res, nr_pages = 1;
struct page *pages;
res = get_user_pages(current, current->mm, virtp, nr_pages, 1, vec = frame_vector_create(1);
0, &pages, NULL); if (!vec)
up_read(&current->mm->mmap_sem); return -ENOMEM;
if (res == nr_pages) { ret = get_vaddr_frames(virtp, 1, true, false, vec);
physp = __pa(page_address(&pages[0]) + if (ret != 1) {
(virtp & ~PAGE_MASK)); frame_vector_destroy(vec);
} else { return -EINVAL;
printk(KERN_WARNING VOUT_NAME
"get_user_pages failed\n");
return 0;
}
} }
*physp = __pfn_to_phys(frame_vector_pfns(vec)[0]);
vb->priv = vec;
return physp; return 0;
} }
/* /*
...@@ -784,11 +772,15 @@ static int omap_vout_buffer_prepare(struct videobuf_queue *q, ...@@ -784,11 +772,15 @@ static int omap_vout_buffer_prepare(struct videobuf_queue *q,
* address of the buffer * address of the buffer
*/ */
if (V4L2_MEMORY_USERPTR == vb->memory) { if (V4L2_MEMORY_USERPTR == vb->memory) {
int ret;
if (0 == vb->baddr) if (0 == vb->baddr)
return -EINVAL; return -EINVAL;
/* Physical address */ /* Physical address */
vout->queued_buf_addr[vb->i] = (u8 *) ret = omap_vout_get_userptr(vb, vb->baddr,
omap_vout_uservirt_to_phys(vb->baddr); (u32 *)&vout->queued_buf_addr[vb->i]);
if (ret < 0)
return ret;
} else { } else {
unsigned long addr, dma_addr; unsigned long addr, dma_addr;
unsigned long size; unsigned long size;
...@@ -834,12 +826,13 @@ static void omap_vout_buffer_queue(struct videobuf_queue *q, ...@@ -834,12 +826,13 @@ static void omap_vout_buffer_queue(struct videobuf_queue *q,
static void omap_vout_buffer_release(struct videobuf_queue *q, static void omap_vout_buffer_release(struct videobuf_queue *q,
struct videobuf_buffer *vb) struct videobuf_buffer *vb)
{ {
struct omap_vout_device *vout = q->priv_data;
vb->state = VIDEOBUF_NEEDS_INIT; vb->state = VIDEOBUF_NEEDS_INIT;
if (vb->memory == V4L2_MEMORY_USERPTR && vb->priv) {
struct frame_vector *vec = vb->priv;
if (V4L2_MEMORY_MMAP != vout->memory) put_vaddr_frames(vec);
return; frame_vector_destroy(vec);
}
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment