Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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