* [PATCH v3] mtdchar: fix mmap() for MTD RAM/ROM char devices
@ 2010-06-12 19:35 Anatolij Gustschin
2010-06-13 1:31 ` Mike Frysinger
2010-06-15 7:30 ` [PATCH v4] " Anatolij Gustschin
0 siblings, 2 replies; 7+ messages in thread
From: Anatolij Gustschin @ 2010-06-12 19:35 UTC (permalink / raw)
To: linux-mtd
Cc: Artem Bityutskiy, Anatolij Gustschin, David Woodhouse,
Detlev Zundel
For no-mmu systems mmap() on RAM/ROM devices already works
but for systems with mmu it probably was not tested and
currently 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>
---
Changes since patch v2:
- improved commit message and patch description
- rebased to apply cleanly on current mtd-2.6 tree
drivers/mtd/mtdchar.c | 30 +++++++++++++++++++++++++++++-
1 files changed, 29 insertions(+), 1 deletions(-)
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 8b223c0..f3b848e 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>
@@ -941,9 +942,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;
--
1.7.0.4
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v3] mtdchar: fix mmap() for MTD RAM/ROM char devices
2010-06-12 19:35 [PATCH v3] mtdchar: fix mmap() for MTD RAM/ROM char devices Anatolij Gustschin
@ 2010-06-13 1:31 ` Mike Frysinger
2010-06-14 9:22 ` Anatolij Gustschin
2010-06-15 7:30 ` [PATCH v4] " Anatolij Gustschin
1 sibling, 1 reply; 7+ messages in thread
From: Mike Frysinger @ 2010-06-13 1:31 UTC (permalink / raw)
To: Anatolij Gustschin
Cc: Artem Bityutskiy, linux-mtd, David Woodhouse, Detlev Zundel
On Sat, Jun 12, 2010 at 15:35, Anatolij Gustschin wrote:
> For no-mmu systems mmap() on RAM/ROM devices already works
> but for systems with mmu it probably was not tested and
> currently doesn't work.
nope, never did
> + if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
> + return -EINVAL;
i'm pretty sure this is inappropriate and doesnt belong here
-mike
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3] mtdchar: fix mmap() for MTD RAM/ROM char devices
2010-06-13 1:31 ` Mike Frysinger
@ 2010-06-14 9:22 ` Anatolij Gustschin
2010-06-14 18:21 ` Mike Frysinger
0 siblings, 1 reply; 7+ messages in thread
From: Anatolij Gustschin @ 2010-06-14 9:22 UTC (permalink / raw)
To: Mike Frysinger
Cc: Artem Bityutskiy, linux-mtd, David Woodhouse, Detlev Zundel
On Sat, 12 Jun 2010 21:31:11 -0400
Mike Frysinger <vapier.adi@gmail.com> wrote:
> On Sat, Jun 12, 2010 at 15:35, Anatolij Gustschin wrote:
> > For no-mmu systems mmap() on RAM/ROM devices already works
> > but for systems with mmu it probably was not tested and
> > currently doesn't work.
>
> nope, never did
Do you mean it never worked on mmu systems?
>
> > + if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
> > + return -EINVAL;
>
> i'm pretty sure this is inappropriate and doesnt belong here
Then I'll drop this in the next patch.
Thanks,
Anatolij
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3] mtdchar: fix mmap() for MTD RAM/ROM char devices
2010-06-14 9:22 ` Anatolij Gustschin
@ 2010-06-14 18:21 ` Mike Frysinger
0 siblings, 0 replies; 7+ messages in thread
From: Mike Frysinger @ 2010-06-14 18:21 UTC (permalink / raw)
To: Anatolij Gustschin
Cc: Artem Bityutskiy, linux-mtd, David Woodhouse, Detlev Zundel
On Mon, Jun 14, 2010 at 05:22, Anatolij Gustschin wrote:
> On Sat, 12 Jun 2010 21:31:11 -0400 Mike Frysinger wrote:
>> On Sat, Jun 12, 2010 at 15:35, Anatolij Gustschin wrote:
>> > For no-mmu systems mmap() on RAM/ROM devices already works
>> > but for systems with mmu it probably was not tested and
>> > currently doesn't work.
>>
>> nope, never did
>
> Do you mean it never worked on mmu systems?
it probably wasnt tested too heavily if at all
-mike
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v4] mtdchar: fix mmap() for MTD RAM/ROM char devices
2010-06-12 19:35 [PATCH v3] mtdchar: fix mmap() for MTD RAM/ROM char devices Anatolij Gustschin
2010-06-13 1:31 ` Mike Frysinger
@ 2010-06-15 7:30 ` Anatolij Gustschin
2010-06-15 16:55 ` Mike Frysinger
2010-07-07 14:02 ` Artem Bityutskiy
1 sibling, 2 replies; 7+ messages in thread
From: Anatolij Gustschin @ 2010-06-15 7:30 UTC (permalink / raw)
To: linux-mtd
Cc: Artem Bityutskiy, Anatolij Gustschin, David Woodhouse,
Detlev Zundel
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>
---
Changes since v3:
- remove vma->vm_pgoff check as suggested by Mike
- update commit message
Changes since v2:
- improved commit message and patch description
- rebased to apply cleanly on current mtd-2.6 tree
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 8b223c0..c3e5423 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>
@@ -941,9 +942,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;
--
1.7.0.4
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v4] mtdchar: fix mmap() for MTD RAM/ROM char devices
2010-06-15 7:30 ` [PATCH v4] " Anatolij Gustschin
@ 2010-06-15 16:55 ` Mike Frysinger
2010-07-07 14:02 ` Artem Bityutskiy
1 sibling, 0 replies; 7+ messages in thread
From: Mike Frysinger @ 2010-06-15 16:55 UTC (permalink / raw)
To: Anatolij Gustschin
Cc: Artem Bityutskiy, linux-mtd, David Woodhouse, Detlev Zundel
On Tue, Jun 15, 2010 at 03:30, Anatolij Gustschin wrote:
> 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.
i dont really have a way of testing the MMU path, but this looks sane.
Acked-by: Mike Frysinger <vapier@gentoo.org>
-mike
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v4] mtdchar: fix mmap() for MTD RAM/ROM char devices
2010-06-15 7:30 ` [PATCH v4] " Anatolij Gustschin
2010-06-15 16:55 ` Mike Frysinger
@ 2010-07-07 14:02 ` Artem Bityutskiy
1 sibling, 0 replies; 7+ messages in thread
From: Artem Bityutskiy @ 2010-07-07 14:02 UTC (permalink / raw)
To: Anatolij Gustschin; +Cc: David Woodhouse, linux-mtd, Detlev Zundel
On Tue, 2010-06-15 at 09:30 +0200, Anatolij Gustschin wrote:
> 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>
Pushed to l2-mtd-2.6.git / dunno
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-07-07 14:02 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-12 19:35 [PATCH v3] mtdchar: fix mmap() for MTD RAM/ROM char devices Anatolij Gustschin
2010-06-13 1:31 ` Mike Frysinger
2010-06-14 9:22 ` Anatolij Gustschin
2010-06-14 18:21 ` Mike Frysinger
2010-06-15 7:30 ` [PATCH v4] " Anatolij Gustschin
2010-06-15 16:55 ` Mike Frysinger
2010-07-07 14:02 ` Artem Bityutskiy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).