]> err.no Git - linux-2.6/blobdiff - drivers/char/mem.c
[PATCH] parport: add NetMOS 9805 support
[linux-2.6] / drivers / char / mem.c
index 01b3c17ca851f4cb2e106a5276929bba63355f7b..f182752fe918b9b08bb601bd0bc827bb3e1f0cf2 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/highmem.h>
 #include <linux/crash_dump.h>
 #include <linux/backing-dev.h>
+#include <linux/bootmem.h>
 
 #include <asm/uaccess.h>
 #include <asm/io.h>
 # include <linux/efi.h>
 #endif
 
-#if defined(CONFIG_S390_TAPE) && defined(CONFIG_S390_TAPE_CHAR)
-extern void tapechar_init(void);
-#endif
-
 /*
  * Architectures vary in how they handle caching for addresses
  * outside of main memory.
@@ -260,7 +257,11 @@ static int mmap_mem(struct file * file, struct vm_area_struct * vma)
 
 static int mmap_kmem(struct file * file, struct vm_area_struct * vma)
 {
-        unsigned long long val;
+       unsigned long pfn;
+
+       /* Turn a kernel-virtual address into a physical page frame */
+       pfn = __pa((u64)vma->vm_pgoff << PAGE_SHIFT) >> PAGE_SHIFT;
+
        /*
         * RED-PEN: on some architectures there is more mapped memory
         * than available in mem_map which pfn_valid checks
@@ -268,65 +269,43 @@ static int mmap_kmem(struct file * file, struct vm_area_struct * vma)
         *
         * RED-PEN: vmalloc is not supported right now.
         */
-       if (!pfn_valid(vma->vm_pgoff))
+       if (!pfn_valid(pfn))
                return -EIO;
-       val = (u64)vma->vm_pgoff << PAGE_SHIFT;
-       vma->vm_pgoff = __pa(val) >> PAGE_SHIFT;
+
+       vma->vm_pgoff = pfn;
        return mmap_mem(file, vma);
 }
 
 #ifdef CONFIG_CRASH_DUMP
 /*
  * Read memory corresponding to the old kernel.
- * If we are reading from the reserved section, which is
- * actually used by the current kernel, we just return zeroes.
- * Or if we are reading from the first 640k, we return from the
- * backed up area.
  */
-static ssize_t read_oldmem(struct file * file, char * buf,
+static ssize_t read_oldmem(struct file *file, char __user *buf,
                                size_t count, loff_t *ppos)
 {
-       unsigned long pfn;
-       unsigned backup_start, backup_end, relocate_start;
-       size_t read=0, csize;
-
-       backup_start = CRASH_BACKUP_BASE / PAGE_SIZE;
-       backup_end = backup_start + (CRASH_BACKUP_SIZE / PAGE_SIZE);
-       relocate_start = (CRASH_BACKUP_BASE + CRASH_BACKUP_SIZE) / PAGE_SIZE;
+       unsigned long pfn, offset;
+       size_t read = 0, csize;
+       int rc = 0;
 
-       while(count) {
+       while (count) {
                pfn = *ppos / PAGE_SIZE;
+               if (pfn > saved_max_pfn)
+                       return read;
 
-               csize = (count > PAGE_SIZE) ? PAGE_SIZE : count;
-
-               /* Perform translation (see comment above) */
-               if ((pfn >= backup_start) && (pfn < backup_end)) {
-                       if (clear_user(buf, csize)) {
-                               read = -EFAULT;
-                               goto done;
-                       }
-
-                       goto copy_done;
-               } else if (pfn < (CRASH_RELOCATE_SIZE / PAGE_SIZE))
-                       pfn += relocate_start;
-
-               if (pfn > saved_max_pfn) {
-                       read = 0;
-                       goto done;
-               }
-
-               if (copy_oldmem_page(pfn, buf, csize, 1)) {
-                       read = -EFAULT;
-                       goto done;
-               }
+               offset = (unsigned long)(*ppos % PAGE_SIZE);
+               if (count > PAGE_SIZE - offset)
+                       csize = PAGE_SIZE - offset;
+               else
+                       csize = count;
 
-copy_done:
+               rc = copy_oldmem_page(pfn, buf, csize, offset, 1);
+               if (rc < 0)
+                       return rc;
                buf += csize;
                *ppos += csize;
                read += csize;
                count -= csize;
        }
-done:
        return read;
 }
 #endif