aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/debug.c')
-rw-r--r--drivers/acpi/debug.c422
1 files changed, 0 insertions, 422 deletions
diff --git a/drivers/acpi/debug.c b/drivers/acpi/debug.c
deleted file mode 100644
index 295dbfa2db9c..000000000000
--- a/drivers/acpi/debug.c
+++ /dev/null
@@ -1,422 +0,0 @@
1/*
2 * debug.c - ACPI debug interface to userspace.
3 */
4
5#include <linux/proc_fs.h>
6#include <linux/seq_file.h>
7#include <linux/init.h>
8#include <linux/module.h>
9#include <linux/kernel.h>
10#include <linux/moduleparam.h>
11#include <linux/debugfs.h>
12#include <linux/slab.h>
13#include <asm/uaccess.h>
14#include <acpi/acpi_drivers.h>
15
16#define _COMPONENT ACPI_SYSTEM_COMPONENT
17ACPI_MODULE_NAME("debug");
18
19struct acpi_dlayer {
20 const char *name;
21 unsigned long value;
22};
23struct acpi_dlevel {
24 const char *name;
25 unsigned long value;
26};
27#define ACPI_DEBUG_INIT(v) { .name = #v, .value = v }
28
29static const struct acpi_dlayer acpi_debug_layers[] = {
30 ACPI_DEBUG_INIT(ACPI_UTILITIES),
31 ACPI_DEBUG_INIT(ACPI_HARDWARE),
32 ACPI_DEBUG_INIT(ACPI_EVENTS),
33 ACPI_DEBUG_INIT(ACPI_TABLES),
34 ACPI_DEBUG_INIT(ACPI_NAMESPACE),
35 ACPI_DEBUG_INIT(ACPI_PARSER),
36 ACPI_DEBUG_INIT(ACPI_DISPATCHER),
37 ACPI_DEBUG_INIT(ACPI_EXECUTER),
38 ACPI_DEBUG_INIT(ACPI_RESOURCES),
39 ACPI_DEBUG_INIT(ACPI_CA_DEBUGGER),
40 ACPI_DEBUG_INIT(ACPI_OS_SERVICES),
41 ACPI_DEBUG_INIT(ACPI_CA_DISASSEMBLER),
42 ACPI_DEBUG_INIT(ACPI_COMPILER),
43 ACPI_DEBUG_INIT(ACPI_TOOLS),
44
45 ACPI_DEBUG_INIT(ACPI_BUS_COMPONENT),
46 ACPI_DEBUG_INIT(ACPI_AC_COMPONENT),
47 ACPI_DEBUG_INIT(ACPI_BATTERY_COMPONENT),
48 ACPI_DEBUG_INIT(ACPI_BUTTON_COMPONENT),
49 ACPI_DEBUG_INIT(ACPI_SBS_COMPONENT),
50 ACPI_DEBUG_INIT(ACPI_FAN_COMPONENT),
51 ACPI_DEBUG_INIT(ACPI_PCI_COMPONENT),
52 ACPI_DEBUG_INIT(ACPI_POWER_COMPONENT),
53 ACPI_DEBUG_INIT(ACPI_CONTAINER_COMPONENT),
54 ACPI_DEBUG_INIT(ACPI_SYSTEM_COMPONENT),
55 ACPI_DEBUG_INIT(ACPI_THERMAL_COMPONENT),
56 ACPI_DEBUG_INIT(ACPI_MEMORY_DEVICE_COMPONENT),
57 ACPI_DEBUG_INIT(ACPI_VIDEO_COMPONENT),
58 ACPI_DEBUG_INIT(ACPI_PROCESSOR_COMPONENT),
59};
60
61static const struct acpi_dlevel acpi_debug_levels[] = {
62 ACPI_DEBUG_INIT(ACPI_LV_INIT),
63 ACPI_DEBUG_INIT(ACPI_LV_DEBUG_OBJECT),
64 ACPI_DEBUG_INIT(ACPI_LV_INFO),
65
66 ACPI_DEBUG_INIT(ACPI_LV_INIT_NAMES),
67 ACPI_DEBUG_INIT(ACPI_LV_PARSE),
68 ACPI_DEBUG_INIT(ACPI_LV_LOAD),
69 ACPI_DEBUG_INIT(ACPI_LV_DISPATCH),
70 ACPI_DEBUG_INIT(ACPI_LV_EXEC),
71 ACPI_DEBUG_INIT(ACPI_LV_NAMES),
72 ACPI_DEBUG_INIT(ACPI_LV_OPREGION),
73 ACPI_DEBUG_INIT(ACPI_LV_BFIELD),
74 ACPI_DEBUG_INIT(ACPI_LV_TABLES),
75 ACPI_DEBUG_INIT(ACPI_LV_VALUES),
76 ACPI_DEBUG_INIT(ACPI_LV_OBJECTS),
77 ACPI_DEBUG_INIT(ACPI_LV_RESOURCES),
78 ACPI_DEBUG_INIT(ACPI_LV_USER_REQUESTS),
79 ACPI_DEBUG_INIT(ACPI_LV_PACKAGE),
80
81 ACPI_DEBUG_INIT(ACPI_LV_ALLOCATIONS),
82 ACPI_DEBUG_INIT(ACPI_LV_FUNCTIONS),
83 ACPI_DEBUG_INIT(ACPI_LV_OPTIMIZATIONS),
84
85 ACPI_DEBUG_INIT(ACPI_LV_MUTEX),
86 ACPI_DEBUG_INIT(ACPI_LV_THREADS),
87 ACPI_DEBUG_INIT(ACPI_LV_IO),
88 ACPI_DEBUG_INIT(ACPI_LV_INTERRUPTS),
89
90 ACPI_DEBUG_INIT(ACPI_LV_AML_DISASSEMBLE),
91 ACPI_DEBUG_INIT(ACPI_LV_VERBOSE_INFO),
92 ACPI_DEBUG_INIT(ACPI_LV_FULL_TABLES),
93 ACPI_DEBUG_INIT(ACPI_LV_EVENTS),
94};
95
96/* --------------------------------------------------------------------------
97 FS Interface (/sys)
98 -------------------------------------------------------------------------- */
99static int param_get_debug_layer(char *buffer, const struct kernel_param *kp)
100{
101 int result = 0;
102 int i;
103
104 result = sprintf(buffer, "%-25s\tHex SET\n", "Description");
105
106 for(i = 0; i <ARRAY_SIZE(acpi_debug_layers); i++) {
107 result += sprintf(buffer+result, "%-25s\t0x%08lX [%c]\n",
108 acpi_debug_layers[i].name,
109 acpi_debug_layers[i].value,
110 (acpi_dbg_layer & acpi_debug_layers[i].value) ? '*' : ' ');
111 }
112 result += sprintf(buffer+result, "%-25s\t0x%08X [%c]\n", "ACPI_ALL_DRIVERS",
113 ACPI_ALL_DRIVERS,
114 (acpi_dbg_layer & ACPI_ALL_DRIVERS) ==
115 ACPI_ALL_DRIVERS ? '*' : (acpi_dbg_layer &
116 ACPI_ALL_DRIVERS) == 0 ? ' ' : '-');
117 result += sprintf(buffer+result, "--\ndebug_layer = 0x%08X ( * = enabled)\n", acpi_dbg_layer);
118
119 return result;
120}
121
122static int param_get_debug_level(char *buffer, const struct kernel_param *kp)
123{
124 int result = 0;
125 int i;
126
127 result = sprintf(buffer, "%-25s\tHex SET\n", "Description");
128
129 for (i = 0; i < ARRAY_SIZE(acpi_debug_levels); i++) {
130 result += sprintf(buffer+result, "%-25s\t0x%08lX [%c]\n",
131 acpi_debug_levels[i].name,
132 acpi_debug_levels[i].value,
133 (acpi_dbg_level & acpi_debug_levels[i].
134 value) ? '*' : ' ');
135 }
136 result += sprintf(buffer+result, "--\ndebug_level = 0x%08X (* = enabled)\n",
137 acpi_dbg_level);
138
139 return result;
140}
141
142static struct kernel_param_ops acpi_debug_layer_ops = {
143 .set = param_set_uint,
144 .get = param_get_debug_layer,
145};
146
147static struct kernel_param_ops acpi_debug_level_ops = {
148 .set = param_set_uint,
149 .get = param_get_debug_level,
150};
151
152module_param_cb(debug_layer, &acpi_debug_layer_ops, &acpi_dbg_layer, 0644);
153module_param_cb(debug_level, &acpi_debug_level_ops, &acpi_dbg_level, 0644);
154
155static char trace_method_name[6];
156module_param_string(trace_method_name, trace_method_name, 6, 0644);
157static unsigned int trace_debug_layer;
158module_param(trace_debug_layer, uint, 0644);
159static unsigned int trace_debug_level;
160module_param(trace_debug_level, uint, 0644);
161
162static int param_set_trace_state(const char *val, const struct kernel_param *kp)
163{
164 int result = 0;
165
166 if (!strncmp(val, "enable", strlen("enable") - 1)) {
167 result = acpi_debug_trace(trace_method_name, trace_debug_level,
168 trace_debug_layer, 0);
169 if (result)
170 result = -EBUSY;
171 goto exit;
172 }
173
174 if (!strncmp(val, "disable", strlen("disable") - 1)) {
175 int name = 0;
176 result = acpi_debug_trace((char *)&name, trace_debug_level,
177 trace_debug_layer, 0);
178 if (result)
179 result = -EBUSY;
180 goto exit;
181 }
182
183 if (!strncmp(val, "1", 1)) {
184 result = acpi_debug_trace(trace_method_name, trace_debug_level,
185 trace_debug_layer, 1);
186 if (result)
187 result = -EBUSY;
188 goto exit;
189 }
190
191 result = -EINVAL;
192exit:
193 return result;
194}
195
196static int param_get_trace_state(char *buffer, const struct kernel_param *kp)
197{
198 if (!acpi_gbl_trace_method_name)
199 return sprintf(buffer, "disable");
200 else {
201 if (acpi_gbl_trace_flags & 1)
202 return sprintf(buffer, "1");
203 else
204 return sprintf(buffer, "enable");
205 }
206 return 0;
207}
208
209static struct kernel_param_ops param_ops_trace_state = {
210 .set = param_set_trace_state,
211 .get = param_get_trace_state,
212};
213
214module_param_cb(trace_state, &param_ops_trace_state, NULL, 0644);
215
216/* --------------------------------------------------------------------------
217 DebugFS Interface
218 -------------------------------------------------------------------------- */
219
220static ssize_t cm_write(struct file *file, const char __user *user_buf,
221 size_t count, loff_t *ppos)
222{
223 static char *buf;
224 static int uncopied_bytes;
225 struct acpi_table_header table;
226 acpi_status status;
227
228 if (!(*ppos)) {
229 /* parse the table header to get the table length */
230 if (count <= sizeof(struct acpi_table_header))
231 return -EINVAL;
232 if (copy_from_user(&table, user_buf,
233 sizeof(struct acpi_table_header)))
234 return -EFAULT;
235 uncopied_bytes = table.length;
236 buf = kzalloc(uncopied_bytes, GFP_KERNEL);
237 if (!buf)
238 return -ENOMEM;
239 }
240
241 if (uncopied_bytes < count) {
242 kfree(buf);
243 return -EINVAL;
244 }
245
246 if (copy_from_user(buf + (*ppos), user_buf, count)) {
247 kfree(buf);
248 return -EFAULT;
249 }
250
251 uncopied_bytes -= count;
252 *ppos += count;
253
254 if (!uncopied_bytes) {
255 status = acpi_install_method(buf);
256 kfree(buf);
257 if (ACPI_FAILURE(status))
258 return -EINVAL;
259 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
260 }
261
262 return count;
263}
264
265static const struct file_operations cm_fops = {
266 .write = cm_write,
267};
268
269static int acpi_debugfs_init(void)
270{
271 struct dentry *acpi_dir, *cm_dentry;
272
273 acpi_dir = debugfs_create_dir("acpi", NULL);
274 if (!acpi_dir)
275 goto err;
276
277 cm_dentry = debugfs_create_file("custom_method", S_IWUGO,
278 acpi_dir, NULL, &cm_fops);
279 if (!cm_dentry)
280 goto err;
281
282 return 0;
283
284err:
285 if (acpi_dir)
286 debugfs_remove(acpi_dir);
287 return -EINVAL;
288}
289
290/* --------------------------------------------------------------------------
291 FS Interface (/proc)
292 -------------------------------------------------------------------------- */
293#ifdef CONFIG_ACPI_PROCFS
294#define ACPI_SYSTEM_FILE_DEBUG_LAYER "debug_layer"
295#define ACPI_SYSTEM_FILE_DEBUG_LEVEL "debug_level"
296
297static int acpi_system_debug_proc_show(struct seq_file *m, void *v)
298{
299 unsigned int i;
300
301 seq_printf(m, "%-25s\tHex SET\n", "Description");
302
303 switch ((unsigned long)m->private) {
304 case 0:
305 for (i = 0; i < ARRAY_SIZE(acpi_debug_layers); i++) {
306 seq_printf(m, "%-25s\t0x%08lX [%c]\n",
307 acpi_debug_layers[i].name,
308 acpi_debug_layers[i].value,
309 (acpi_dbg_layer & acpi_debug_layers[i].
310 value) ? '*' : ' ');
311 }
312 seq_printf(m, "%-25s\t0x%08X [%c]\n", "ACPI_ALL_DRIVERS",
313 ACPI_ALL_DRIVERS,
314 (acpi_dbg_layer & ACPI_ALL_DRIVERS) ==
315 ACPI_ALL_DRIVERS ? '*' : (acpi_dbg_layer &
316 ACPI_ALL_DRIVERS) ==
317 0 ? ' ' : '-');
318 seq_printf(m,
319 "--\ndebug_layer = 0x%08X (* = enabled, - = partial)\n",
320 acpi_dbg_layer);
321 break;
322 case 1:
323 for (i = 0; i < ARRAY_SIZE(acpi_debug_levels); i++) {
324 seq_printf(m, "%-25s\t0x%08lX [%c]\n",
325 acpi_debug_levels[i].name,
326 acpi_debug_levels[i].value,
327 (acpi_dbg_level & acpi_debug_levels[i].
328 value) ? '*' : ' ');
329 }
330 seq_printf(m, "--\ndebug_level = 0x%08X (* = enabled)\n",
331 acpi_dbg_level);
332 break;
333 }
334 return 0;
335}
336
337static int acpi_system_debug_proc_open(struct inode *inode, struct file *file)
338{
339 return single_open(file, acpi_system_debug_proc_show, PDE(inode)->data);
340}
341
342static ssize_t acpi_system_debug_proc_write(struct file *file,
343 const char __user * buffer,
344 size_t count, loff_t *pos)
345{
346 char debug_string[12] = { '\0' };
347
348
349 if (count > sizeof(debug_string) - 1)
350 return -EINVAL;
351
352 if (copy_from_user(debug_string, buffer, count))
353 return -EFAULT;
354
355 debug_string[count] = '\0';
356
357 switch ((unsigned long)PDE(file->f_path.dentry->d_inode)->data) {
358 case 0:
359 acpi_dbg_layer = simple_strtoul(debug_string, NULL, 0);
360 break;
361 case 1:
362 acpi_dbg_level = simple_strtoul(debug_string, NULL, 0);
363 break;
364 default:
365 return -EINVAL;
366 }
367
368 return count;
369}
370
371static const struct file_operations acpi_system_debug_proc_fops = {
372 .owner = THIS_MODULE,
373 .open = acpi_system_debug_proc_open,
374 .read = seq_read,
375 .llseek = seq_lseek,
376 .release = single_release,
377 .write = acpi_system_debug_proc_write,
378};
379#endif
380
381int __init acpi_procfs_init(void)
382{
383#ifdef CONFIG_ACPI_PROCFS
384 struct proc_dir_entry *entry;
385 int error = 0;
386 char *name;
387
388 /* 'debug_layer' [R/W] */
389 name = ACPI_SYSTEM_FILE_DEBUG_LAYER;
390 entry = proc_create_data(name, S_IFREG | S_IRUGO | S_IWUSR,
391 acpi_root_dir, &acpi_system_debug_proc_fops,
392 (void *)0);
393 if (!entry)
394 goto Error;
395
396 /* 'debug_level' [R/W] */
397 name = ACPI_SYSTEM_FILE_DEBUG_LEVEL;
398 entry = proc_create_data(name, S_IFREG | S_IRUGO | S_IWUSR,
399 acpi_root_dir, &acpi_system_debug_proc_fops,
400 (void *)1);
401 if (!entry)
402 goto Error;
403
404 Done:
405 return error;
406
407 Error:
408 remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LEVEL, acpi_root_dir);
409 remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LAYER, acpi_root_dir);
410 error = -ENODEV;
411 goto Done;
412#else
413 return 0;
414#endif
415}
416
417int __init acpi_debug_init(void)
418{
419 acpi_debugfs_init();
420 acpi_procfs_init();
421 return 0;
422}