Commit fc9bbca8 authored by Linus Torvalds's avatar Linus Torvalds

vm: convert fb_mmap to vm_iomap_memory() helper

This is my example conversion of a few existing mmap users.  The
fb_mmap() case is a good example because it is a bit more complicated
than some: fb_mmap() mmaps one of two different memory areas depending
on the page offset of the mmap (but happily there is never any mixing of
the two, so the helper function still works).
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8558e4a2
...@@ -1373,15 +1373,12 @@ fb_mmap(struct file *file, struct vm_area_struct * vma) ...@@ -1373,15 +1373,12 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
{ {
struct fb_info *info = file_fb_info(file); struct fb_info *info = file_fb_info(file);
struct fb_ops *fb; struct fb_ops *fb;
unsigned long off; unsigned long mmio_pgoff;
unsigned long start; unsigned long start;
u32 len; u32 len;
if (!info) if (!info)
return -ENODEV; return -ENODEV;
if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
return -EINVAL;
off = vma->vm_pgoff << PAGE_SHIFT;
fb = info->fbops; fb = info->fbops;
if (!fb) if (!fb)
return -ENODEV; return -ENODEV;
...@@ -1393,32 +1390,24 @@ fb_mmap(struct file *file, struct vm_area_struct * vma) ...@@ -1393,32 +1390,24 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
return res; return res;
} }
/* frame buffer memory */ /*
* Ugh. This can be either the frame buffer mapping, or
* if pgoff points past it, the mmio mapping.
*/
start = info->fix.smem_start; start = info->fix.smem_start;
len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.smem_len); len = info->fix.smem_len;
if (off >= len) { mmio_pgoff = PAGE_ALIGN((start & ~PAGE_MASK) + len) >> PAGE_SHIFT;
/* memory mapped io */ if (vma->vm_pgoff >= mmio_pgoff) {
off -= len; vma->vm_pgoff -= mmio_pgoff;
if (info->var.accel_flags) {
mutex_unlock(&info->mm_lock);
return -EINVAL;
}
start = info->fix.mmio_start; start = info->fix.mmio_start;
len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len); len = info->fix.mmio_len;
} }
mutex_unlock(&info->mm_lock); mutex_unlock(&info->mm_lock);
start &= PAGE_MASK;
if ((vma->vm_end - vma->vm_start + off) > len)
return -EINVAL;
off += start;
vma->vm_pgoff = off >> PAGE_SHIFT;
/* VM_IO | VM_DONTEXPAND | VM_DONTDUMP are set by io_remap_pfn_range()*/
vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
fb_pgprotect(file, vma, off); fb_pgprotect(file, vma, start);
if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
vma->vm_end - vma->vm_start, vma->vm_page_prot)) return vm_iomap_memory(vma, start, len);
return -EAGAIN;
return 0;
} }
static int static int
......
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