Patchwork [v2] mtdchar: allow mmap() on MTD RAM/ROM char devices

login
register
mail settings
Submitter Anatolij Gustschin
Date April 28, 2010, 4:20 p.m.
Message ID <1272471640-27073-1-git-send-email-agust@denx.de>
Download mbox | patch
Permalink /patch/51170/
State New
Headers show

Comments

Anatolij Gustschin - April 28, 2010, 4:20 p.m.
Signed-off-by: Anatolij Gustschin <agust@denx.de>
---
v1 -> v2:
 - Fixed compilation breakage on x86_64 while compiling
   as module, since on x86_64 phys_mem_access_prot() is
   not exported. Sorry for the breakage.

 drivers/mtd/mtdchar.c |   30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)
Anatolij Gustschin - April 29, 2010, 2:13 p.m.
Hi Artem,

On Wed, 28 Apr 2010 18:20:40 +0200
Anatolij Gustschin <agust@denx.de> wrote:

> Signed-off-by: Anatolij Gustschin <agust@denx.de>
> ---
> v1 -> v2:
>  - Fixed compilation breakage on x86_64 while compiling
>    as module, since on x86_64 phys_mem_access_prot() is
>    not exported. Sorry for the breakage.
> 
>  drivers/mtd/mtdchar.c |   30 +++++++++++++++++++++++++++++-
>  1 files changed, 29 insertions(+), 1 deletions(-)

Is this patch ok now?

Thanks,
Anatolij
Artem Bityutskiy - May 4, 2010, 1:45 p.m.
On Thu, 2010-04-29 at 16:13 +0200, Anatolij Gustschin wrote:
> Hi Artem,
> 
> On Wed, 28 Apr 2010 18:20:40 +0200
> Anatolij Gustschin <agust@denx.de> wrote:
> 
> > Signed-off-by: Anatolij Gustschin <agust@denx.de>
> > ---
> > v1 -> v2:
> >  - Fixed compilation breakage on x86_64 while compiling
> >    as module, since on x86_64 phys_mem_access_prot() is
> >    not exported. Sorry for the breakage.
> > 
> >  drivers/mtd/mtdchar.c |   30 +++++++++++++++++++++++++++++-
> >  1 files changed, 29 insertions(+), 1 deletions(-)
> 
> Is this patch ok now?

Not sure, I did not really review it, but it compiles now and I've
pushed it to my l2-mtd-2.6 / dunno tree.

Patch

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index c355491..db755a4 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -17,6 +17,7 @@ 
 #include <linux/compat.h>
 
 #include <linux/mtd/mtd.h>
+#include <linux/mtd/map.h>
 #include <linux/mtd/compatmac.h>
 
 #include <asm/uaccess.h>
@@ -925,9 +926,36 @@  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) {
+		if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
+			return -EINVAL;
+		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;