diff options
author | Anatolij Gustschin <agust@denx.de> | 2010-06-15 03:30:15 -0400 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2010-08-04 05:57:33 -0400 |
commit | dd02b67d5e9e7896891fa27eb5db65f55a290998 (patch) | |
tree | 9e7236232878a894cbb745d68411fe8f54e35ec4 /drivers/mtd | |
parent | 68640c2a416849ba8e0a69577d4be51a458a045a (diff) |
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@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | 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 a8e69dd2b2e4..c27e65e3e291 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/mount.h> | 18 | #include <linux/mount.h> |
19 | 19 | ||
20 | #include <linux/mtd/mtd.h> | 20 | #include <linux/mtd/mtd.h> |
21 | #include <linux/mtd/map.h> | ||
21 | #include <linux/mtd/compatmac.h> | 22 | #include <linux/mtd/compatmac.h> |
22 | 23 | ||
23 | #include <asm/uaccess.h> | 24 | #include <asm/uaccess.h> |
@@ -955,9 +956,34 @@ static int mtd_mmap(struct file *file, struct vm_area_struct *vma) | |||
955 | #ifdef CONFIG_MMU | 956 | #ifdef CONFIG_MMU |
956 | struct mtd_file_info *mfi = file->private_data; | 957 | struct mtd_file_info *mfi = file->private_data; |
957 | struct mtd_info *mtd = mfi->mtd; | 958 | struct mtd_info *mtd = mfi->mtd; |
959 | struct map_info *map = mtd->priv; | ||
960 | unsigned long start; | ||
961 | unsigned long off; | ||
962 | u32 len; | ||
963 | |||
964 | if (mtd->type == MTD_RAM || mtd->type == MTD_ROM) { | ||
965 | off = vma->vm_pgoff << PAGE_SHIFT; | ||
966 | start = map->phys; | ||
967 | len = PAGE_ALIGN((start & ~PAGE_MASK) + map->size); | ||
968 | start &= PAGE_MASK; | ||
969 | if ((vma->vm_end - vma->vm_start + off) > len) | ||
970 | return -EINVAL; | ||
971 | |||
972 | off += start; | ||
973 | vma->vm_pgoff = off >> PAGE_SHIFT; | ||
974 | vma->vm_flags |= VM_IO | VM_RESERVED; | ||
975 | |||
976 | #ifdef pgprot_noncached | ||
977 | if (file->f_flags & O_DSYNC || off >= __pa(high_memory)) | ||
978 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); | ||
979 | #endif | ||
980 | if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, | ||
981 | vma->vm_end - vma->vm_start, | ||
982 | vma->vm_page_prot)) | ||
983 | return -EAGAIN; | ||
958 | 984 | ||
959 | if (mtd->type == MTD_RAM || mtd->type == MTD_ROM) | ||
960 | return 0; | 985 | return 0; |
986 | } | ||
961 | return -ENOSYS; | 987 | return -ENOSYS; |
962 | #else | 988 | #else |
963 | return vma->vm_flags & VM_SHARED ? 0 : -ENOSYS; | 989 | return vma->vm_flags & VM_SHARED ? 0 : -ENOSYS; |