1 // SPDX-License-Identifier: GPL-2.0-only
3 * Architecture specific debugfs files
5 * Copyright (C) 2007, Intel Corp.
6 * Huang Ying <ying.huang@intel.com>
8 #include <linux/debugfs.h>
9 #include <linux/uaccess.h>
10 #include <linux/export.h>
11 #include <linux/slab.h>
12 #include <linux/init.h>
13 #include <linux/stat.h>
17 #include <asm/setup.h>
19 struct dentry *arch_debugfs_dir;
20 EXPORT_SYMBOL(arch_debugfs_dir);
22 #ifdef CONFIG_DEBUG_BOOT_PARAMS
23 struct setup_data_node {
29 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
30 size_t count, loff_t *ppos)
32 struct setup_data_node *node = file->private_data;
44 if (count > node->len - pos)
45 count = node->len - pos;
47 pa = node->paddr + pos;
49 /* Is it direct data or invalid indirect one? */
50 if (!(node->type & SETUP_INDIRECT) || node->type == SETUP_INDIRECT)
51 pa += sizeof(struct setup_data);
53 p = memremap(pa, count, MEMREMAP_WB);
57 remain = copy_to_user(user_buf, p, count);
69 static const struct file_operations fops_setup_data = {
70 .read = setup_data_read,
72 .llseek = default_llseek,
76 create_setup_data_node(struct dentry *parent, int no,
77 struct setup_data_node *node)
82 sprintf(buf, "%d", no);
83 d = debugfs_create_dir(buf, parent);
85 debugfs_create_x32("type", S_IRUGO, d, &node->type);
86 debugfs_create_file("data", S_IRUGO, d, node, &fops_setup_data);
89 static int __init create_setup_data_nodes(struct dentry *parent)
91 struct setup_indirect *indirect;
92 struct setup_data_node *node;
93 struct setup_data *data;
100 d = debugfs_create_dir("setup_data", parent);
102 pa_data = boot_params.hdr.setup_data;
105 node = kmalloc(sizeof(*node), GFP_KERNEL);
111 data = memremap(pa_data, sizeof(*data), MEMREMAP_WB);
117 pa_next = data->next;
119 if (data->type == SETUP_INDIRECT) {
120 len = sizeof(*data) + data->len;
122 data = memremap(pa_data, len, MEMREMAP_WB);
129 indirect = (struct setup_indirect *)data->data;
131 if (indirect->type != SETUP_INDIRECT) {
132 node->paddr = indirect->addr;
133 node->type = indirect->type;
134 node->len = indirect->len;
136 node->paddr = pa_data;
137 node->type = data->type;
138 node->len = data->len;
141 node->paddr = pa_data;
142 node->type = data->type;
143 node->len = data->len;
146 create_setup_data_node(d, no, node);
156 debugfs_remove_recursive(d);
160 static struct debugfs_blob_wrapper boot_params_blob = {
161 .data = &boot_params,
162 .size = sizeof(boot_params),
165 static int __init boot_params_kdebugfs_init(void)
170 dbp = debugfs_create_dir("boot_params", arch_debugfs_dir);
172 debugfs_create_x16("version", S_IRUGO, dbp, &boot_params.hdr.version);
173 debugfs_create_blob("data", S_IRUGO, dbp, &boot_params_blob);
175 error = create_setup_data_nodes(dbp);
177 debugfs_remove_recursive(dbp);
181 #endif /* CONFIG_DEBUG_BOOT_PARAMS */
183 static int __init arch_kdebugfs_init(void)
187 arch_debugfs_dir = debugfs_create_dir("x86", NULL);
189 #ifdef CONFIG_DEBUG_BOOT_PARAMS
190 error = boot_params_kdebugfs_init();
195 arch_initcall(arch_kdebugfs_init);