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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Based on arch/arm/kernel/atags_proc.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/printk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/bootinfo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) static char bootinfo_tmp[1536] __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static void *bootinfo_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static size_t bootinfo_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static ssize_t bootinfo_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 			  size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	return simple_read_from_buffer(buf, count, ppos, bootinfo_copy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 				       bootinfo_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static const struct proc_ops bootinfo_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	.proc_read	= bootinfo_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	.proc_lseek	= default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) void __init save_bootinfo(const struct bi_record *bi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	const void *start = bi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	size_t size = sizeof(bi->tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	while (be16_to_cpu(bi->tag) != BI_LAST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		uint16_t n = be16_to_cpu(bi->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 		size += n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 		bi = (struct bi_record *)((unsigned long)bi + n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	if (size > sizeof(bootinfo_tmp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 		pr_err("Cannot save %zu bytes of bootinfo\n", size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	pr_info("Saving %zu bytes of bootinfo\n", size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	memcpy(bootinfo_tmp, start, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	bootinfo_size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static int __init init_bootinfo_procfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	 * This cannot go into save_bootinfo() because kmalloc and proc don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	 * work yet when it is called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	struct proc_dir_entry *pde;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	if (!bootinfo_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	bootinfo_copy = kmemdup(bootinfo_tmp, bootinfo_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	if (!bootinfo_copy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	pde = proc_create_data("bootinfo", 0400, NULL, &bootinfo_proc_ops, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	if (!pde) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 		kfree(bootinfo_copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) arch_initcall(init_bootinfo_procfs);