mtd: mtdchar: fix mmap for MTD RAM/ROM char devices
Linux-MTD Mailing List
linux-mtd at lists.infradead.org
Wed Aug 4 06:59:07 EDT 2010
Gitweb: http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=dd02b67d5e9e7896891fa27eb5db65f55a290998
Commit: dd02b67d5e9e7896891fa27eb5db65f55a290998
Parent: 68640c2a416849ba8e0a69577d4be51a458a045a
Author: Anatolij Gustschin <agust at denx.de>
AuthorDate: Tue Jun 15 09:30:15 2010 +0200
Committer: David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Wed Aug 4 10:57:33 2010 +0100
mtd: mtdchar: fix mmap for MTD RAM/ROM char devices
For no-mmu systems mmap() on RAM/ROM devices already works
but for systems with mmu it probably was not tested and
doesn't work.
This patch allows using mmap() on MTD RAM/ROM devices on systems
with MMU. It has been tested on mpc5121e based platform with
MR0A16A MRAM device attached over LocalBus.
Signed-off-by: Anatolij Gustschin <agust at denx.de>
Acked-by: Mike Frysinger <vapier at gentoo.org>
Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
drivers/mtd/mtdchar.c | 28 +++++++++++++++++++++++++++-
1 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index a8e69dd..c27e65e 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -18,6 +18,7 @@
#include <linux/mount.h>
#include <linux/mtd/mtd.h>
+#include <linux/mtd/map.h>
#include <linux/mtd/compatmac.h>
#include <asm/uaccess.h>
@@ -955,9 +956,34 @@ static int mtd_mmap(struct file *file, struct vm_area_struct *vma)
#ifdef CONFIG_MMU
struct mtd_file_info *mfi = file->private_data;
struct mtd_info *mtd = mfi->mtd;
+ struct map_info *map = mtd->priv;
+ unsigned long start;
+ unsigned long off;
+ u32 len;
+
+ if (mtd->type == MTD_RAM || mtd->type == MTD_ROM) {
+ off = vma->vm_pgoff << PAGE_SHIFT;
+ start = map->phys;
+ len = PAGE_ALIGN((start & ~PAGE_MASK) + map->size);
+ start &= PAGE_MASK;
+ if ((vma->vm_end - vma->vm_start + off) > len)
+ return -EINVAL;
+
+ off += start;
+ vma->vm_pgoff = off >> PAGE_SHIFT;
+ vma->vm_flags |= VM_IO | VM_RESERVED;
+
+#ifdef pgprot_noncached
+ if (file->f_flags & O_DSYNC || off >= __pa(high_memory))
+ vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+#endif
+ if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
+ vma->vm_end - vma->vm_start,
+ vma->vm_page_prot))
+ return -EAGAIN;
- if (mtd->type == MTD_RAM || mtd->type == MTD_ROM)
return 0;
+ }
return -ENOSYS;
#else
return vma->vm_flags & VM_SHARED ? 0 : -ENOSYS;
More information about the linux-mtd-cvs
mailing list