1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Routines for doing kexec-based kdump
4 *
5 * Copyright (C) 2017 Linaro Limited
6 * Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
7 */
8
9#include <linux/crash_dump.h>
10#include <linux/errno.h>
11#include <linux/io.h>
12#include <linux/uio.h>
13#include <asm/memory.h>
14
15ssize_t copy_oldmem_page(struct iov_iter *iter, unsigned long pfn,
16 size_t csize, unsigned long offset)
17{
18 void *vaddr;
19
20 if (!csize)
21 return 0;
22
23 vaddr = memremap(__pfn_to_phys(pfn), PAGE_SIZE, flags: MEMREMAP_WB);
24 if (!vaddr)
25 return -ENOMEM;
26
27 csize = copy_to_iter(addr: vaddr + offset, bytes: csize, i: iter);
28
29 memunmap(addr: vaddr);
30
31 return csize;
32}
33
34/**
35 * elfcorehdr_read - read from ELF core header
36 * @buf: buffer where the data is placed
37 * @count: number of bytes to read
38 * @ppos: address in the memory
39 *
40 * This function reads @count bytes from elf core header which exists
41 * on crash dump kernel's memory.
42 */
43ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos)
44{
45 memcpy(buf, phys_to_virt((phys_addr_t)*ppos), count);
46 *ppos += count;
47
48 return count;
49}
50

source code of linux/arch/arm64/kernel/crash_dump.c