xref: /openbmc/linux/arch/mips/kernel/crash_dump.c (revision 31e67366)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/highmem.h>
3 #include <linux/crash_dump.h>
4 
5 /**
6  * copy_oldmem_page - copy one page from "oldmem"
7  * @pfn: page frame number to be copied
8  * @buf: target memory address for the copy; this can be in kernel address
9  *	space or user address space (see @userbuf)
10  * @csize: number of bytes to copy
11  * @offset: offset in bytes into the page (based on pfn) to begin the copy
12  * @userbuf: if set, @buf is in user address space, use copy_to_user(),
13  *	otherwise @buf is in kernel address space, use memcpy().
14  *
15  * Copy a page from "oldmem". For this page, there is no pte mapped
16  * in the current kernel.
17  */
18 ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
19 			 size_t csize, unsigned long offset, int userbuf)
20 {
21 	void  *vaddr;
22 
23 	if (!csize)
24 		return 0;
25 
26 	vaddr = kmap_local_pfn(pfn);
27 
28 	if (!userbuf) {
29 		memcpy(buf, vaddr + offset, csize);
30 	} else {
31 		if (copy_to_user(buf, vaddr + offset, csize))
32 			csize = -EFAULT;
33 	}
34 
35 	kunmap_local(vaddr);
36 
37 	return csize;
38 }
39