blob: 53cb924353920263617bba724ff6039d9fe483a5 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Mika Westerberg67742c82010-05-10 09:26:19 +01002/*
3 * arch/arm/kernel/crash_dump.c
4 *
5 * Copyright (C) 2010 Nokia Corporation.
6 * Author: Mika Westerberg
7 *
8 * This code is taken from arch/x86/kernel/crash_dump_64.c
9 * Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
10 * Copyright (C) IBM Corporation, 2004. All rights reserved
Mika Westerberg67742c82010-05-10 09:26:19 +010011 */
12
13#include <linux/errno.h>
14#include <linux/crash_dump.h>
15#include <linux/uaccess.h>
16#include <linux/io.h>
17
Mika Westerberg67742c82010-05-10 09:26:19 +010018/**
19 * copy_oldmem_page() - copy one page from old kernel memory
20 * @pfn: page frame number to be copied
21 * @buf: buffer where the copied page is placed
22 * @csize: number of bytes to copy
23 * @offset: offset in bytes into the page
24 * @userbuf: if set, @buf is int he user address space
25 *
26 * This function copies one page from old kernel memory into buffer pointed by
27 * @buf. If @buf is in userspace, set @userbuf to %1. Returns number of bytes
28 * copied or negative error in case of failure.
29 */
30ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
31 size_t csize, unsigned long offset,
32 int userbuf)
33{
34 void *vaddr;
35
36 if (!csize)
37 return 0;
38
Liu Hua8fad87b2014-03-27 06:56:18 +010039 vaddr = ioremap(__pfn_to_phys(pfn), PAGE_SIZE);
Mika Westerberg67742c82010-05-10 09:26:19 +010040 if (!vaddr)
41 return -ENOMEM;
42
43 if (userbuf) {
44 if (copy_to_user(buf, vaddr + offset, csize)) {
45 iounmap(vaddr);
46 return -EFAULT;
47 }
48 } else {
49 memcpy(buf, vaddr + offset, csize);
50 }
51
52 iounmap(vaddr);
53 return csize;
54}