Merge branch 'x86-platform-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / arch / x86 / kernel / kdebugfs.c
CommitLineData
6d7d7433
HY
1/*
2 * Architecture specific debugfs files
3 *
4 * Copyright (C) 2007, Intel Corp.
5 * Huang Ying <ying.huang@intel.com>
6 *
7 * This file is released under the GPLv2.
8 */
6d7d7433 9#include <linux/debugfs.h>
c14b2adf 10#include <linux/uaccess.h>
186f4360 11#include <linux/export.h>
5a0e3ad6 12#include <linux/slab.h>
6d7d7433 13#include <linux/init.h>
390cd85c 14#include <linux/stat.h>
c14b2adf
HY
15#include <linux/io.h>
16#include <linux/mm.h>
6d7d7433
HY
17
18#include <asm/setup.h>
19
ae79cdaa 20struct dentry *arch_debugfs_dir;
21EXPORT_SYMBOL(arch_debugfs_dir);
22
6d7d7433 23#ifdef CONFIG_DEBUG_BOOT_PARAMS
c14b2adf
HY
24struct setup_data_node {
25 u64 paddr;
26 u32 type;
27 u32 len;
28};
29
390cd85c
JSR
30static ssize_t setup_data_read(struct file *file, char __user *user_buf,
31 size_t count, loff_t *ppos)
c14b2adf
HY
32{
33 struct setup_data_node *node = file->private_data;
34 unsigned long remain;
35 loff_t pos = *ppos;
c14b2adf
HY
36 void *p;
37 u64 pa;
38
39 if (pos < 0)
40 return -EINVAL;
390cd85c 41
c14b2adf
HY
42 if (pos >= node->len)
43 return 0;
44
45 if (count > node->len - pos)
46 count = node->len - pos;
390cd85c 47
c14b2adf 48 pa = node->paddr + sizeof(struct setup_data) + pos;
f7750a79
TL
49 p = memremap(pa, count, MEMREMAP_WB);
50 if (!p)
51 return -ENOMEM;
c14b2adf
HY
52
53 remain = copy_to_user(user_buf, p, count);
54
f7750a79 55 memunmap(p);
c14b2adf
HY
56
57 if (remain)
58 return -EFAULT;
59
60 *ppos = pos + count;
61
62 return count;
63}
64
c14b2adf 65static const struct file_operations fops_setup_data = {
390cd85c 66 .read = setup_data_read,
234e3405 67 .open = simple_open,
6038f373 68 .llseek = default_llseek,
c14b2adf
HY
69};
70
71static int __init
72create_setup_data_node(struct dentry *parent, int no,
73 struct setup_data_node *node)
74{
75 struct dentry *d, *type, *data;
76 char buf[16];
c14b2adf
HY
77
78 sprintf(buf, "%d", no);
79 d = debugfs_create_dir(buf, parent);
390cd85c
JSR
80 if (!d)
81 return -ENOMEM;
82
c14b2adf 83 type = debugfs_create_x32("type", S_IRUGO, d, &node->type);
390cd85c 84 if (!type)
c14b2adf 85 goto err_dir;
390cd85c 86
c14b2adf 87 data = debugfs_create_file("data", S_IRUGO, d, node, &fops_setup_data);
390cd85c 88 if (!data)
c14b2adf 89 goto err_type;
390cd85c 90
c14b2adf
HY
91 return 0;
92
93err_type:
94 debugfs_remove(type);
95err_dir:
96 debugfs_remove(d);
390cd85c 97 return -ENOMEM;
c14b2adf
HY
98}
99
100static int __init create_setup_data_nodes(struct dentry *parent)
101{
102 struct setup_data_node *node;
103 struct setup_data *data;
41fb433b 104 int error;
c14b2adf 105 struct dentry *d;
c14b2adf 106 u64 pa_data;
390cd85c 107 int no = 0;
c14b2adf
HY
108
109 d = debugfs_create_dir("setup_data", parent);
390cd85c
JSR
110 if (!d)
111 return -ENOMEM;
c14b2adf
HY
112
113 pa_data = boot_params.hdr.setup_data;
114
115 while (pa_data) {
116 node = kmalloc(sizeof(*node), GFP_KERNEL);
41fb433b
JL
117 if (!node) {
118 error = -ENOMEM;
c14b2adf 119 goto err_dir;
41fb433b 120 }
390cd85c 121
f7750a79
TL
122 data = memremap(pa_data, sizeof(*data), MEMREMAP_WB);
123 if (!data) {
124 kfree(node);
125 error = -ENOMEM;
126 goto err_dir;
127 }
c14b2adf
HY
128
129 node->paddr = pa_data;
130 node->type = data->type;
131 node->len = data->len;
132 error = create_setup_data_node(d, no, node);
133 pa_data = data->next;
134
f7750a79 135 memunmap(data);
c14b2adf
HY
136 if (error)
137 goto err_dir;
138 no++;
139 }
390cd85c 140
c14b2adf
HY
141 return 0;
142
143err_dir:
144 debugfs_remove(d);
c14b2adf
HY
145 return error;
146}
147
6d7d7433 148static struct debugfs_blob_wrapper boot_params_blob = {
c14b2adf
HY
149 .data = &boot_params,
150 .size = sizeof(boot_params),
6d7d7433
HY
151};
152
153static int __init boot_params_kdebugfs_init(void)
154{
6d7d7433 155 struct dentry *dbp, *version, *data;
390cd85c 156 int error = -ENOMEM;
6d7d7433 157
10bce841 158 dbp = debugfs_create_dir("boot_params", arch_debugfs_dir);
390cd85c
JSR
159 if (!dbp)
160 return -ENOMEM;
161
6d7d7433
HY
162 version = debugfs_create_x16("version", S_IRUGO, dbp,
163 &boot_params.hdr.version);
390cd85c 164 if (!version)
6d7d7433 165 goto err_dir;
390cd85c 166
6d7d7433
HY
167 data = debugfs_create_blob("data", S_IRUGO, dbp,
168 &boot_params_blob);
390cd85c 169 if (!data)
6d7d7433 170 goto err_version;
390cd85c 171
c14b2adf
HY
172 error = create_setup_data_nodes(dbp);
173 if (error)
174 goto err_data;
390cd85c 175
6d7d7433 176 return 0;
c14b2adf
HY
177
178err_data:
179 debugfs_remove(data);
6d7d7433
HY
180err_version:
181 debugfs_remove(version);
182err_dir:
183 debugfs_remove(dbp);
6d7d7433
HY
184 return error;
185}
390cd85c 186#endif /* CONFIG_DEBUG_BOOT_PARAMS */
6d7d7433
HY
187
188static int __init arch_kdebugfs_init(void)
189{
190 int error = 0;
191
ae79cdaa 192 arch_debugfs_dir = debugfs_create_dir("x86", NULL);
193 if (!arch_debugfs_dir)
194 return -ENOMEM;
195
6d7d7433
HY
196#ifdef CONFIG_DEBUG_BOOT_PARAMS
197 error = boot_params_kdebugfs_init();
198#endif
199
200 return error;
201}
6d7d7433 202arch_initcall(arch_kdebugfs_init);