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)  * Architecture specific debugfs files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2007, Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	Huang Ying <ying.huang@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) struct dentry *arch_debugfs_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) EXPORT_SYMBOL(arch_debugfs_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #ifdef CONFIG_DEBUG_BOOT_PARAMS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) struct setup_data_node {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	u64 paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	u32 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	u32 len;
^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 ssize_t setup_data_read(struct file *file, char __user *user_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 			       size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct setup_data_node *node = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	unsigned long remain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	loff_t pos = *ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	void *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	u64 pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (pos < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (pos >= node->len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (count > node->len - pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		count = node->len - pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	pa = node->paddr + pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	/* Is it direct data or invalid indirect one? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	if (!(node->type & SETUP_INDIRECT) || node->type == SETUP_INDIRECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		pa += sizeof(struct setup_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	p = memremap(pa, count, MEMREMAP_WB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	remain = copy_to_user(user_buf, p, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	memunmap(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	if (remain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	*ppos = pos + count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static const struct file_operations fops_setup_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	.read		= setup_data_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	.open		= simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	.llseek		= default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) create_setup_data_node(struct dentry *parent, int no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		       struct setup_data_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct dentry *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	char buf[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	sprintf(buf, "%d", no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	d = debugfs_create_dir(buf, parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	debugfs_create_x32("type", S_IRUGO, d, &node->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	debugfs_create_file("data", S_IRUGO, d, node, &fops_setup_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static int __init create_setup_data_nodes(struct dentry *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct setup_indirect *indirect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct setup_data_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct setup_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	u64 pa_data, pa_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct dentry *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	u32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	int no = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	d = debugfs_create_dir("setup_data", parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	pa_data = boot_params.hdr.setup_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	while (pa_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		node = kmalloc(sizeof(*node), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		if (!node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			goto err_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		data = memremap(pa_data, sizeof(*data), MEMREMAP_WB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		if (!data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			kfree(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			goto err_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		pa_next = data->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		if (data->type == SETUP_INDIRECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			len = sizeof(*data) + data->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			memunmap(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			data = memremap(pa_data, len, MEMREMAP_WB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			if (!data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 				kfree(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 				error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 				goto err_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			indirect = (struct setup_indirect *)data->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			if (indirect->type != SETUP_INDIRECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 				node->paddr = indirect->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 				node->type  = indirect->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 				node->len   = indirect->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 				node->paddr = pa_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 				node->type  = data->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 				node->len   = data->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			node->paddr = pa_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			node->type  = data->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			node->len   = data->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		create_setup_data_node(d, no, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		pa_data = pa_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		memunmap(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		no++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) err_dir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	debugfs_remove_recursive(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static struct debugfs_blob_wrapper boot_params_blob = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	.data		= &boot_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	.size		= sizeof(boot_params),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static int __init boot_params_kdebugfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct dentry *dbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	dbp = debugfs_create_dir("boot_params", arch_debugfs_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	debugfs_create_x16("version", S_IRUGO, dbp, &boot_params.hdr.version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	debugfs_create_blob("data", S_IRUGO, dbp, &boot_params_blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	error = create_setup_data_nodes(dbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		debugfs_remove_recursive(dbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) #endif /* CONFIG_DEBUG_BOOT_PARAMS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static int __init arch_kdebugfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	arch_debugfs_dir = debugfs_create_dir("x86", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) #ifdef CONFIG_DEBUG_BOOT_PARAMS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	error = boot_params_kdebugfs_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) arch_initcall(arch_kdebugfs_init);