Linux 4.9.243
[linux/fpc-iii.git] / arch / x86 / kernel / kdebugfs.c
blobbdb83e431d8976086e3c17328f01a9bdac2c1c8b
1 /*
2 * Architecture specific debugfs files
4 * Copyright (C) 2007, Intel Corp.
5 * Huang Ying <ying.huang@intel.com>
7 * This file is released under the GPLv2.
8 */
9 #include <linux/debugfs.h>
10 #include <linux/uaccess.h>
11 #include <linux/export.h>
12 #include <linux/slab.h>
13 #include <linux/init.h>
14 #include <linux/stat.h>
15 #include <linux/io.h>
16 #include <linux/mm.h>
18 #include <asm/setup.h>
20 struct dentry *arch_debugfs_dir;
21 EXPORT_SYMBOL(arch_debugfs_dir);
23 #ifdef CONFIG_DEBUG_BOOT_PARAMS
24 struct setup_data_node {
25 u64 paddr;
26 u32 type;
27 u32 len;
30 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
31 size_t count, loff_t *ppos)
33 struct setup_data_node *node = file->private_data;
34 unsigned long remain;
35 loff_t pos = *ppos;
36 struct page *pg;
37 void *p;
38 u64 pa;
40 if (pos < 0)
41 return -EINVAL;
43 if (pos >= node->len)
44 return 0;
46 if (count > node->len - pos)
47 count = node->len - pos;
49 pa = node->paddr + sizeof(struct setup_data) + pos;
50 pg = pfn_to_page((pa + count - 1) >> PAGE_SHIFT);
51 if (PageHighMem(pg)) {
52 p = ioremap_cache(pa, count);
53 if (!p)
54 return -ENXIO;
55 } else
56 p = __va(pa);
58 remain = copy_to_user(user_buf, p, count);
60 if (PageHighMem(pg))
61 iounmap(p);
63 if (remain)
64 return -EFAULT;
66 *ppos = pos + count;
68 return count;
71 static const struct file_operations fops_setup_data = {
72 .read = setup_data_read,
73 .open = simple_open,
74 .llseek = default_llseek,
77 static int __init
78 create_setup_data_node(struct dentry *parent, int no,
79 struct setup_data_node *node)
81 struct dentry *d, *type, *data;
82 char buf[16];
84 sprintf(buf, "%d", no);
85 d = debugfs_create_dir(buf, parent);
86 if (!d)
87 return -ENOMEM;
89 type = debugfs_create_x32("type", S_IRUGO, d, &node->type);
90 if (!type)
91 goto err_dir;
93 data = debugfs_create_file("data", S_IRUGO, d, node, &fops_setup_data);
94 if (!data)
95 goto err_type;
97 return 0;
99 err_type:
100 debugfs_remove(type);
101 err_dir:
102 debugfs_remove(d);
103 return -ENOMEM;
106 static int __init create_setup_data_nodes(struct dentry *parent)
108 struct setup_data_node *node;
109 struct setup_data *data;
110 int error;
111 struct dentry *d;
112 struct page *pg;
113 u64 pa_data;
114 int no = 0;
116 d = debugfs_create_dir("setup_data", parent);
117 if (!d)
118 return -ENOMEM;
120 pa_data = boot_params.hdr.setup_data;
122 while (pa_data) {
123 node = kmalloc(sizeof(*node), GFP_KERNEL);
124 if (!node) {
125 error = -ENOMEM;
126 goto err_dir;
129 pg = pfn_to_page((pa_data+sizeof(*data)-1) >> PAGE_SHIFT);
130 if (PageHighMem(pg)) {
131 data = ioremap_cache(pa_data, sizeof(*data));
132 if (!data) {
133 kfree(node);
134 error = -ENXIO;
135 goto err_dir;
137 } else
138 data = __va(pa_data);
140 node->paddr = pa_data;
141 node->type = data->type;
142 node->len = data->len;
143 error = create_setup_data_node(d, no, node);
144 pa_data = data->next;
146 if (PageHighMem(pg))
147 iounmap(data);
148 if (error)
149 goto err_dir;
150 no++;
153 return 0;
155 err_dir:
156 debugfs_remove(d);
157 return error;
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)
167 struct dentry *dbp, *version, *data;
168 int error = -ENOMEM;
170 dbp = debugfs_create_dir("boot_params", NULL);
171 if (!dbp)
172 return -ENOMEM;
174 version = debugfs_create_x16("version", S_IRUGO, dbp,
175 &boot_params.hdr.version);
176 if (!version)
177 goto err_dir;
179 data = debugfs_create_blob("data", S_IRUGO, dbp,
180 &boot_params_blob);
181 if (!data)
182 goto err_version;
184 error = create_setup_data_nodes(dbp);
185 if (error)
186 goto err_data;
188 return 0;
190 err_data:
191 debugfs_remove(data);
192 err_version:
193 debugfs_remove(version);
194 err_dir:
195 debugfs_remove(dbp);
196 return error;
198 #endif /* CONFIG_DEBUG_BOOT_PARAMS */
200 static int __init arch_kdebugfs_init(void)
202 int error = 0;
204 arch_debugfs_dir = debugfs_create_dir("x86", NULL);
205 if (!arch_debugfs_dir)
206 return -ENOMEM;
208 #ifdef CONFIG_DEBUG_BOOT_PARAMS
209 error = boot_params_kdebugfs_init();
210 #endif
212 return error;
214 arch_initcall(arch_kdebugfs_init);