1 // SPDX-License-Identifier: GPL-2.0-only
3 * Routines for doing kexec-based kdump
5 * Copyright (C) 2017 Linaro Limited
6 * Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
9 #include <linux/crash_dump.h>
10 #include <linux/errno.h>
12 #include <linux/memblock.h>
13 #include <linux/uaccess.h>
14 #include <asm/memory.h>
17 * copy_oldmem_page() - copy one page from old kernel memory
18 * @pfn: page frame number to be copied
19 * @buf: buffer where the copied page is placed
20 * @csize: number of bytes to copy
21 * @offset: offset in bytes into the page
22 * @userbuf: if set, @buf is in a user address space
24 * This function copies one page from old kernel memory into buffer pointed by
25 * @buf. If @buf is in userspace, set @userbuf to %1. Returns number of bytes
26 * copied or negative error in case of failure.
28 ssize_t
copy_oldmem_page(unsigned long pfn
, char *buf
,
29 size_t csize
, unsigned long offset
,
37 vaddr
= memremap(__pfn_to_phys(pfn
), PAGE_SIZE
, MEMREMAP_WB
);
42 if (copy_to_user((char __user
*)buf
, vaddr
+ offset
, csize
)) {
47 memcpy(buf
, vaddr
+ offset
, csize
);
56 * elfcorehdr_read - read from ELF core header
57 * @buf: buffer where the data is placed
58 * @count: number of bytes to read
59 * @ppos: address in the memory
61 * This function reads @count bytes from elf core header which exists
62 * on crash dump kernel's memory.
64 ssize_t
elfcorehdr_read(char *buf
, size_t count
, u64
*ppos
)
66 memcpy(buf
, phys_to_virt((phys_addr_t
)*ppos
), count
);