Vivek Goyal | 60e64d4 | 2005-06-25 14:58:19 -0700 | [diff] [blame] | 1 | /* |
Dave Jones | 835c34a | 2007-10-12 21:10:53 -0400 | [diff] [blame] | 2 | * Memory preserving reboot related code. |
Vivek Goyal | 60e64d4 | 2005-06-25 14:58:19 -0700 | [diff] [blame] | 3 | * |
| 4 | * Created by: Hariprasad Nellitheertha (hari@in.ibm.com) |
| 5 | * Copyright (C) IBM Corporation, 2004. All rights reserved |
| 6 | */ |
| 7 | |
Vivek Goyal | 60e64d4 | 2005-06-25 14:58:19 -0700 | [diff] [blame] | 8 | #include <linux/errno.h> |
Vivek Goyal | 60e64d4 | 2005-06-25 14:58:19 -0700 | [diff] [blame] | 9 | #include <linux/crash_dump.h> |
Gustavo F. Padovan | 08aadf0 | 2008-07-29 02:48:53 -0300 | [diff] [blame] | 10 | #include <linux/uaccess.h> |
| 11 | #include <linux/io.h> |
Vivek Goyal | 60e64d4 | 2005-06-25 14:58:19 -0700 | [diff] [blame] | 12 | |
Vivek Goyal | 57cac4d | 2008-10-18 20:28:25 -0700 | [diff] [blame] | 13 | /* Stores the physical address of elf header of crash image. */ |
| 14 | unsigned long long elfcorehdr_addr = ELFCORE_ADDR_MAX; |
| 15 | |
Randy Dunlap | e77e171 | 2005-07-27 11:45:11 -0700 | [diff] [blame] | 16 | /** |
| 17 | * copy_oldmem_page - copy one page from "oldmem" |
| 18 | * @pfn: page frame number to be copied |
| 19 | * @buf: target memory address for the copy; this can be in kernel address |
| 20 | * space or user address space (see @userbuf) |
| 21 | * @csize: number of bytes to copy |
| 22 | * @offset: offset in bytes into the page (based on pfn) to begin the copy |
| 23 | * @userbuf: if set, @buf is in user address space, use copy_to_user(), |
| 24 | * otherwise @buf is in kernel address space, use memcpy(). |
| 25 | * |
Vivek Goyal | 60e64d4 | 2005-06-25 14:58:19 -0700 | [diff] [blame] | 26 | * Copy a page from "oldmem". For this page, there is no pte mapped |
| 27 | * in the current kernel. We stitch up a pte, similar to kmap_atomic. |
| 28 | */ |
| 29 | ssize_t copy_oldmem_page(unsigned long pfn, char *buf, |
Gustavo F. Padovan | 08aadf0 | 2008-07-29 02:48:53 -0300 | [diff] [blame] | 30 | size_t csize, unsigned long offset, int userbuf) |
Vivek Goyal | 60e64d4 | 2005-06-25 14:58:19 -0700 | [diff] [blame] | 31 | { |
Vivek Goyal | 4ae362b | 2006-01-09 20:51:50 -0800 | [diff] [blame] | 32 | void *vaddr; |
Vivek Goyal | 60e64d4 | 2005-06-25 14:58:19 -0700 | [diff] [blame] | 33 | |
| 34 | if (!csize) |
| 35 | return 0; |
| 36 | |
Vivek Goyal | 4ae362b | 2006-01-09 20:51:50 -0800 | [diff] [blame] | 37 | vaddr = ioremap(pfn << PAGE_SHIFT, PAGE_SIZE); |
Akinobu Mita | af2d237 | 2008-09-21 23:27:13 +0900 | [diff] [blame] | 38 | if (!vaddr) |
| 39 | return -ENOMEM; |
Vivek Goyal | 60e64d4 | 2005-06-25 14:58:19 -0700 | [diff] [blame] | 40 | |
| 41 | if (userbuf) { |
Akinobu Mita | af2d237 | 2008-09-21 23:27:13 +0900 | [diff] [blame] | 42 | if (copy_to_user(buf, vaddr + offset, csize)) { |
Vivek Goyal | 4ae362b | 2006-01-09 20:51:50 -0800 | [diff] [blame] | 43 | iounmap(vaddr); |
Vivek Goyal | 60e64d4 | 2005-06-25 14:58:19 -0700 | [diff] [blame] | 44 | return -EFAULT; |
| 45 | } |
Vivek Goyal | 4ae362b | 2006-01-09 20:51:50 -0800 | [diff] [blame] | 46 | } else |
Akinobu Mita | af2d237 | 2008-09-21 23:27:13 +0900 | [diff] [blame] | 47 | memcpy(buf, vaddr + offset, csize); |
Vivek Goyal | 60e64d4 | 2005-06-25 14:58:19 -0700 | [diff] [blame] | 48 | |
Vivek Goyal | 4ae362b | 2006-01-09 20:51:50 -0800 | [diff] [blame] | 49 | iounmap(vaddr); |
Vivek Goyal | 60e64d4 | 2005-06-25 14:58:19 -0700 | [diff] [blame] | 50 | return csize; |
| 51 | } |