]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - drivers/mtd/mtdchar.c
Merge git://git.infradead.org/mtd-2.6
[mv-sheeva.git] / drivers / mtd / mtdchar.c
index 000d65ea55a42bf495ba773dca6c66f99f0d3136..a825002123c84bc0a24ce26e00400be277b09c22 100644 (file)
@@ -1,5 +1,19 @@
 /*
- * Character-device access to raw MTD devices.
+ * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
 
@@ -18,7 +32,7 @@
 #include <linux/mount.h>
 
 #include <linux/mtd/mtd.h>
-#include <linux/mtd/compatmac.h>
+#include <linux/mtd/map.h>
 
 #include <asm/uaccess.h>
 
@@ -404,14 +418,9 @@ static int mtd_do_writeoob(struct file *file, struct mtd_info *mtd,
        if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs))
                return -EINVAL;
 
-       ops.oobbuf = kmalloc(length, GFP_KERNEL);
-       if (!ops.oobbuf)
-               return -ENOMEM;
-
-       if (copy_from_user(ops.oobbuf, ptr, length)) {
-               kfree(ops.oobbuf);
-               return -EFAULT;
-       }
+       ops.oobbuf = memdup_user(ptr, length);
+       if (IS_ERR(ops.oobbuf))
+               return PTR_ERR(ops.oobbuf);
 
        start &= ~((uint64_t)mtd->oobsize - 1);
        ret = mtd->write_oob(mtd, start, &ops);
@@ -680,6 +689,20 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
                break;
        }
 
+       case MEMISLOCKED:
+       {
+               struct erase_info_user einfo;
+
+               if (copy_from_user(&einfo, argp, sizeof(einfo)))
+                       return -EFAULT;
+
+               if (!mtd->is_locked)
+                       ret = -EOPNOTSUPP;
+               else
+                       ret = mtd->is_locked(mtd, einfo.start, einfo.length);
+               break;
+       }
+
        /* Legacy interface */
        case MEMGETOOBSEL:
        {
@@ -955,9 +978,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;