blob: 045b36cada655370382231cb186d45d5d8820d95 [file] [log] [blame]
Vivek Goyal60e64d42005-06-25 14:58:19 -07001/*
Dave Jones835c34a2007-10-12 21:10:53 -04002 * Memory preserving reboot related code.
Vivek Goyal60e64d42005-06-25 14:58:19 -07003 *
4 * Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
5 * Copyright (C) IBM Corporation, 2004. All rights reserved
6 */
7
Vivek Goyal60e64d42005-06-25 14:58:19 -07008#include <linux/errno.h>
Vivek Goyal60e64d42005-06-25 14:58:19 -07009#include <linux/crash_dump.h>
Gustavo F. Padovan08aadf02008-07-29 02:48:53 -030010#include <linux/uaccess.h>
11#include <linux/io.h>
Vivek Goyal60e64d42005-06-25 14:58:19 -070012
Vivek Goyal57cac4d2008-10-18 20:28:25 -070013/* Stores the physical address of elf header of crash image. */
14unsigned long long elfcorehdr_addr = ELFCORE_ADDR_MAX;
15
Randy Dunlape77e1712005-07-27 11:45:11 -070016/**
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 Goyal60e64d42005-06-25 14:58:19 -070026 * 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 */
29ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
Gustavo F. Padovan08aadf02008-07-29 02:48:53 -030030 size_t csize, unsigned long offset, int userbuf)
Vivek Goyal60e64d42005-06-25 14:58:19 -070031{
Vivek Goyal4ae362b2006-01-09 20:51:50 -080032 void *vaddr;
Vivek Goyal60e64d42005-06-25 14:58:19 -070033
34 if (!csize)
35 return 0;
36
Vivek Goyal4ae362b2006-01-09 20:51:50 -080037 vaddr = ioremap(pfn << PAGE_SHIFT, PAGE_SIZE);
Akinobu Mitaaf2d2372008-09-21 23:27:13 +090038 if (!vaddr)
39 return -ENOMEM;
Vivek Goyal60e64d42005-06-25 14:58:19 -070040
41 if (userbuf) {
Akinobu Mitaaf2d2372008-09-21 23:27:13 +090042 if (copy_to_user(buf, vaddr + offset, csize)) {
Vivek Goyal4ae362b2006-01-09 20:51:50 -080043 iounmap(vaddr);
Vivek Goyal60e64d42005-06-25 14:58:19 -070044 return -EFAULT;
45 }
Vivek Goyal4ae362b2006-01-09 20:51:50 -080046 } else
Akinobu Mitaaf2d2372008-09-21 23:27:13 +090047 memcpy(buf, vaddr + offset, csize);
Vivek Goyal60e64d42005-06-25 14:58:19 -070048
Vivek Goyal4ae362b2006-01-09 20:51:50 -080049 iounmap(vaddr);
Vivek Goyal60e64d42005-06-25 14:58:19 -070050 return csize;
51}