Commit 12c71c4b authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'vm_ioremap_memory-examples'

I'm going to do an -rc8, so I'm just going to do this rather than delay
it any further. They are arguably stable material anyway.

* vm_ioremap_memory-examples:
  mtdchar: remove no-longer-used vma helpers
  vm: convert snd_pcm_lib_mmap_iomem() to vm_iomap_memory() helper
  vm: convert fb_mmap to vm_iomap_memory() helper
  vm: convert mtdchar mmap to vm_iomap_memory() helper
  vm: convert HPET mmap to vm_iomap_memory() helper
parents 830ac852 f86b11fb
...@@ -373,26 +373,14 @@ static int hpet_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -373,26 +373,14 @@ static int hpet_mmap(struct file *file, struct vm_area_struct *vma)
struct hpet_dev *devp; struct hpet_dev *devp;
unsigned long addr; unsigned long addr;
if (((vma->vm_end - vma->vm_start) != PAGE_SIZE) || vma->vm_pgoff)
return -EINVAL;
devp = file->private_data; devp = file->private_data;
addr = devp->hd_hpets->hp_hpet_phys; addr = devp->hd_hpets->hp_hpet_phys;
if (addr & (PAGE_SIZE - 1)) if (addr & (PAGE_SIZE - 1))
return -ENOSYS; return -ENOSYS;
vma->vm_flags |= VM_IO;
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
return vm_iomap_memory(vma, addr, PAGE_SIZE);
if (io_remap_pfn_range(vma, vma->vm_start, addr >> PAGE_SHIFT,
PAGE_SIZE, vma->vm_page_prot)) {
printk(KERN_ERR "%s: io_remap_pfn_range failed\n",
__func__);
return -EAGAIN;
}
return 0;
#else #else
return -ENOSYS; return -ENOSYS;
#endif #endif
......
...@@ -1123,33 +1123,6 @@ static unsigned long mtdchar_get_unmapped_area(struct file *file, ...@@ -1123,33 +1123,6 @@ static unsigned long mtdchar_get_unmapped_area(struct file *file,
} }
#endif #endif
static inline unsigned long get_vm_size(struct vm_area_struct *vma)
{
return vma->vm_end - vma->vm_start;
}
static inline resource_size_t get_vm_offset(struct vm_area_struct *vma)
{
return (resource_size_t) vma->vm_pgoff << PAGE_SHIFT;
}
/*
* Set a new vm offset.
*
* Verify that the incoming offset really works as a page offset,
* and that the offset and size fit in a resource_size_t.
*/
static inline int set_vm_offset(struct vm_area_struct *vma, resource_size_t off)
{
pgoff_t pgoff = off >> PAGE_SHIFT;
if (off != (resource_size_t) pgoff << PAGE_SHIFT)
return -EINVAL;
if (off + get_vm_size(vma) - 1 < off)
return -EINVAL;
vma->vm_pgoff = pgoff;
return 0;
}
/* /*
* set up a mapping for shared memory segments * set up a mapping for shared memory segments
*/ */
...@@ -1159,45 +1132,17 @@ static int mtdchar_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -1159,45 +1132,17 @@ static int mtdchar_mmap(struct file *file, struct vm_area_struct *vma)
struct mtd_file_info *mfi = file->private_data; struct mtd_file_info *mfi = file->private_data;
struct mtd_info *mtd = mfi->mtd; struct mtd_info *mtd = mfi->mtd;
struct map_info *map = mtd->priv; struct map_info *map = mtd->priv;
resource_size_t start, off;
unsigned long len, vma_len;
/* This is broken because it assumes the MTD device is map-based /* This is broken because it assumes the MTD device is map-based
and that mtd->priv is a valid struct map_info. It should be and that mtd->priv is a valid struct map_info. It should be
replaced with something that uses the mtd_get_unmapped_area() replaced with something that uses the mtd_get_unmapped_area()
operation properly. */ operation properly. */
if (0 /*mtd->type == MTD_RAM || mtd->type == MTD_ROM*/) { if (0 /*mtd->type == MTD_RAM || mtd->type == MTD_ROM*/) {
off = get_vm_offset(vma);
start = map->phys;
len = PAGE_ALIGN((start & ~PAGE_MASK) + map->size);
start &= PAGE_MASK;
vma_len = get_vm_size(vma);
/* Overflow in off+len? */
if (vma_len + off < off)
return -EINVAL;
/* Does it fit in the mapping? */
if (vma_len + off > len)
return -EINVAL;
off += start;
/* Did that overflow? */
if (off < start)
return -EINVAL;
if (set_vm_offset(vma, off) < 0)
return -EINVAL;
vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
#ifdef pgprot_noncached #ifdef pgprot_noncached
if (file->f_flags & O_DSYNC || off >= __pa(high_memory)) if (file->f_flags & O_DSYNC || map->phys >= __pa(high_memory))
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
#endif #endif
if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, return vm_iomap_memory(vma, map->phys, map->size);
vma->vm_end - vma->vm_start,
vma->vm_page_prot))
return -EAGAIN;
return 0;
} }
return -ENOSYS; return -ENOSYS;
#else #else
......
...@@ -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
......
...@@ -3222,18 +3222,10 @@ EXPORT_SYMBOL_GPL(snd_pcm_lib_default_mmap); ...@@ -3222,18 +3222,10 @@ EXPORT_SYMBOL_GPL(snd_pcm_lib_default_mmap);
int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream,
struct vm_area_struct *area) struct vm_area_struct *area)
{ {
long size; struct snd_pcm_runtime *runtime = substream->runtime;;
unsigned long offset;
area->vm_page_prot = pgprot_noncached(area->vm_page_prot); area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
area->vm_flags |= VM_IO; return vm_iomap_memory(area, runtime->dma_addr, runtime->dma_bytes);
size = area->vm_end - area->vm_start;
offset = area->vm_pgoff << PAGE_SHIFT;
if (io_remap_pfn_range(area, area->vm_start,
(substream->runtime->dma_addr + offset) >> PAGE_SHIFT,
size, area->vm_page_prot))
return -EAGAIN;
return 0;
} }
EXPORT_SYMBOL(snd_pcm_lib_mmap_iomem); EXPORT_SYMBOL(snd_pcm_lib_mmap_iomem);
......
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