blob: 942deac4d43aa1e2b8eb0e3118933f9b4a140e58 [file] [log] [blame]
Vivek Goyal60e64d42005-06-25 14:58:19 -07001/*
2 * kernel/crash_dump.c - Memory preserving reboot related code.
3 *
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>
10
Vivek Goyal60e64d42005-06-25 14:58:19 -070011#include <asm/uaccess.h>
Vivek Goyal4ae362b2006-01-09 20:51:50 -080012#include <asm/io.h>
Vivek Goyal60e64d42005-06-25 14:58:19 -070013
Randy Dunlape77e1712005-07-27 11:45:11 -070014/**
15 * copy_oldmem_page - copy one page from "oldmem"
16 * @pfn: page frame number to be copied
17 * @buf: target memory address for the copy; this can be in kernel address
18 * space or user address space (see @userbuf)
19 * @csize: number of bytes to copy
20 * @offset: offset in bytes into the page (based on pfn) to begin the copy
21 * @userbuf: if set, @buf is in user address space, use copy_to_user(),
22 * otherwise @buf is in kernel address space, use memcpy().
23 *
Vivek Goyal60e64d42005-06-25 14:58:19 -070024 * Copy a page from "oldmem". For this page, there is no pte mapped
25 * in the current kernel. We stitch up a pte, similar to kmap_atomic.
26 */
27ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
Vivek Goyal4ae362b2006-01-09 20:51:50 -080028 size_t csize, unsigned long offset, int userbuf)
Vivek Goyal60e64d42005-06-25 14:58:19 -070029{
Vivek Goyal4ae362b2006-01-09 20:51:50 -080030 void *vaddr;
Vivek Goyal60e64d42005-06-25 14:58:19 -070031
32 if (!csize)
33 return 0;
34
Vivek Goyal4ae362b2006-01-09 20:51:50 -080035 vaddr = ioremap(pfn << PAGE_SHIFT, PAGE_SIZE);
Vivek Goyal60e64d42005-06-25 14:58:19 -070036
37 if (userbuf) {
Vivek Goyal4ae362b2006-01-09 20:51:50 -080038 if (copy_to_user(buf, (vaddr + offset), csize)) {
39 iounmap(vaddr);
Vivek Goyal60e64d42005-06-25 14:58:19 -070040 return -EFAULT;
41 }
Vivek Goyal4ae362b2006-01-09 20:51:50 -080042 } else
43 memcpy(buf, (vaddr + offset), csize);
Vivek Goyal60e64d42005-06-25 14:58:19 -070044
Vivek Goyal4ae362b2006-01-09 20:51:50 -080045 iounmap(vaddr);
Vivek Goyal60e64d42005-06-25 14:58:19 -070046 return csize;
47}