drm/nouveau: Kill global state in BIOS script interpreter
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / acpi / debug.c
blob8a690c3b8e234734df9ec63d1667c98671bc621a
1 /*
2 * debug.c - ACPI debug interface to userspace.
3 */
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 <asm/uaccess.h>
12 #include <acpi/acpi_drivers.h>
14 #define _COMPONENT ACPI_SYSTEM_COMPONENT
15 ACPI_MODULE_NAME("debug");
17 struct acpi_dlayer {
18 const char *name;
19 unsigned long value;
21 struct acpi_dlevel {
22 const char *name;
23 unsigned long value;
25 #define ACPI_DEBUG_INIT(v) { .name = #v, .value = v }
27 static const struct acpi_dlayer acpi_debug_layers[] = {
28 ACPI_DEBUG_INIT(ACPI_UTILITIES),
29 ACPI_DEBUG_INIT(ACPI_HARDWARE),
30 ACPI_DEBUG_INIT(ACPI_EVENTS),
31 ACPI_DEBUG_INIT(ACPI_TABLES),
32 ACPI_DEBUG_INIT(ACPI_NAMESPACE),
33 ACPI_DEBUG_INIT(ACPI_PARSER),
34 ACPI_DEBUG_INIT(ACPI_DISPATCHER),
35 ACPI_DEBUG_INIT(ACPI_EXECUTER),
36 ACPI_DEBUG_INIT(ACPI_RESOURCES),
37 ACPI_DEBUG_INIT(ACPI_CA_DEBUGGER),
38 ACPI_DEBUG_INIT(ACPI_OS_SERVICES),
39 ACPI_DEBUG_INIT(ACPI_CA_DISASSEMBLER),
40 ACPI_DEBUG_INIT(ACPI_COMPILER),
41 ACPI_DEBUG_INIT(ACPI_TOOLS),
43 ACPI_DEBUG_INIT(ACPI_BUS_COMPONENT),
44 ACPI_DEBUG_INIT(ACPI_AC_COMPONENT),
45 ACPI_DEBUG_INIT(ACPI_BATTERY_COMPONENT),
46 ACPI_DEBUG_INIT(ACPI_BUTTON_COMPONENT),
47 ACPI_DEBUG_INIT(ACPI_SBS_COMPONENT),
48 ACPI_DEBUG_INIT(ACPI_FAN_COMPONENT),
49 ACPI_DEBUG_INIT(ACPI_PCI_COMPONENT),
50 ACPI_DEBUG_INIT(ACPI_POWER_COMPONENT),
51 ACPI_DEBUG_INIT(ACPI_CONTAINER_COMPONENT),
52 ACPI_DEBUG_INIT(ACPI_SYSTEM_COMPONENT),
53 ACPI_DEBUG_INIT(ACPI_THERMAL_COMPONENT),
54 ACPI_DEBUG_INIT(ACPI_MEMORY_DEVICE_COMPONENT),
55 ACPI_DEBUG_INIT(ACPI_VIDEO_COMPONENT),
56 ACPI_DEBUG_INIT(ACPI_PROCESSOR_COMPONENT),
59 static const struct acpi_dlevel acpi_debug_levels[] = {
60 ACPI_DEBUG_INIT(ACPI_LV_INIT),
61 ACPI_DEBUG_INIT(ACPI_LV_DEBUG_OBJECT),
62 ACPI_DEBUG_INIT(ACPI_LV_INFO),
64 ACPI_DEBUG_INIT(ACPI_LV_INIT_NAMES),
65 ACPI_DEBUG_INIT(ACPI_LV_PARSE),
66 ACPI_DEBUG_INIT(ACPI_LV_LOAD),
67 ACPI_DEBUG_INIT(ACPI_LV_DISPATCH),
68 ACPI_DEBUG_INIT(ACPI_LV_EXEC),
69 ACPI_DEBUG_INIT(ACPI_LV_NAMES),
70 ACPI_DEBUG_INIT(ACPI_LV_OPREGION),
71 ACPI_DEBUG_INIT(ACPI_LV_BFIELD),
72 ACPI_DEBUG_INIT(ACPI_LV_TABLES),
73 ACPI_DEBUG_INIT(ACPI_LV_VALUES),
74 ACPI_DEBUG_INIT(ACPI_LV_OBJECTS),
75 ACPI_DEBUG_INIT(ACPI_LV_RESOURCES),
76 ACPI_DEBUG_INIT(ACPI_LV_USER_REQUESTS),
77 ACPI_DEBUG_INIT(ACPI_LV_PACKAGE),
79 ACPI_DEBUG_INIT(ACPI_LV_ALLOCATIONS),
80 ACPI_DEBUG_INIT(ACPI_LV_FUNCTIONS),
81 ACPI_DEBUG_INIT(ACPI_LV_OPTIMIZATIONS),
83 ACPI_DEBUG_INIT(ACPI_LV_MUTEX),
84 ACPI_DEBUG_INIT(ACPI_LV_THREADS),
85 ACPI_DEBUG_INIT(ACPI_LV_IO),
86 ACPI_DEBUG_INIT(ACPI_LV_INTERRUPTS),
88 ACPI_DEBUG_INIT(ACPI_LV_AML_DISASSEMBLE),
89 ACPI_DEBUG_INIT(ACPI_LV_VERBOSE_INFO),
90 ACPI_DEBUG_INIT(ACPI_LV_FULL_TABLES),
91 ACPI_DEBUG_INIT(ACPI_LV_EVENTS),
94 /* --------------------------------------------------------------------------
95 FS Interface (/sys)
96 -------------------------------------------------------------------------- */
97 static int param_get_debug_layer(char *buffer, struct kernel_param *kp) {
98 int result = 0;
99 int i;
101 result = sprintf(buffer, "%-25s\tHex SET\n", "Description");
103 for(i = 0; i <ARRAY_SIZE(acpi_debug_layers); i++) {
104 result += sprintf(buffer+result, "%-25s\t0x%08lX [%c]\n",
105 acpi_debug_layers[i].name,
106 acpi_debug_layers[i].value,
107 (acpi_dbg_layer & acpi_debug_layers[i].value) ? '*' : ' ');
109 result += sprintf(buffer+result, "%-25s\t0x%08X [%c]\n", "ACPI_ALL_DRIVERS",
110 ACPI_ALL_DRIVERS,
111 (acpi_dbg_layer & ACPI_ALL_DRIVERS) ==
112 ACPI_ALL_DRIVERS ? '*' : (acpi_dbg_layer &
113 ACPI_ALL_DRIVERS) == 0 ? ' ' : '-');
114 result += sprintf(buffer+result, "--\ndebug_layer = 0x%08X ( * = enabled)\n", acpi_dbg_layer);
116 return result;
119 static int param_get_debug_level(char *buffer, struct kernel_param *kp) {
120 int result = 0;
121 int i;
123 result = sprintf(buffer, "%-25s\tHex SET\n", "Description");
125 for (i = 0; i < ARRAY_SIZE(acpi_debug_levels); i++) {
126 result += sprintf(buffer+result, "%-25s\t0x%08lX [%c]\n",
127 acpi_debug_levels[i].name,
128 acpi_debug_levels[i].value,
129 (acpi_dbg_level & acpi_debug_levels[i].
130 value) ? '*' : ' ');
132 result += sprintf(buffer+result, "--\ndebug_level = 0x%08X (* = enabled)\n",
133 acpi_dbg_level);
135 return result;
138 module_param_call(debug_layer, param_set_uint, param_get_debug_layer, &acpi_dbg_layer, 0644);
139 module_param_call(debug_level, param_set_uint, param_get_debug_level, &acpi_dbg_level, 0644);
141 static char trace_method_name[6];
142 module_param_string(trace_method_name, trace_method_name, 6, 0644);
143 static unsigned int trace_debug_layer;
144 module_param(trace_debug_layer, uint, 0644);
145 static unsigned int trace_debug_level;
146 module_param(trace_debug_level, uint, 0644);
148 static int param_set_trace_state(const char *val, struct kernel_param *kp)
150 int result = 0;
152 if (!strncmp(val, "enable", strlen("enable") - 1)) {
153 result = acpi_debug_trace(trace_method_name, trace_debug_level,
154 trace_debug_layer, 0);
155 if (result)
156 result = -EBUSY;
157 goto exit;
160 if (!strncmp(val, "disable", strlen("disable") - 1)) {
161 int name = 0;
162 result = acpi_debug_trace((char *)&name, trace_debug_level,
163 trace_debug_layer, 0);
164 if (result)
165 result = -EBUSY;
166 goto exit;
169 if (!strncmp(val, "1", 1)) {
170 result = acpi_debug_trace(trace_method_name, trace_debug_level,
171 trace_debug_layer, 1);
172 if (result)
173 result = -EBUSY;
174 goto exit;
177 result = -EINVAL;
178 exit:
179 return result;
182 static int param_get_trace_state(char *buffer, struct kernel_param *kp)
184 if (!acpi_gbl_trace_method_name)
185 return sprintf(buffer, "disable");
186 else {
187 if (acpi_gbl_trace_flags & 1)
188 return sprintf(buffer, "1");
189 else
190 return sprintf(buffer, "enable");
192 return 0;
195 module_param_call(trace_state, param_set_trace_state, param_get_trace_state,
196 NULL, 0644);
198 /* --------------------------------------------------------------------------
199 FS Interface (/proc)
200 -------------------------------------------------------------------------- */
201 #ifdef CONFIG_ACPI_PROCFS
202 #define ACPI_SYSTEM_FILE_DEBUG_LAYER "debug_layer"
203 #define ACPI_SYSTEM_FILE_DEBUG_LEVEL "debug_level"
205 static int acpi_system_debug_proc_show(struct seq_file *m, void *v)
207 unsigned int i;
209 seq_printf(m, "%-25s\tHex SET\n", "Description");
211 switch ((unsigned long)m->private) {
212 case 0:
213 for (i = 0; i < ARRAY_SIZE(acpi_debug_layers); i++) {
214 seq_printf(m, "%-25s\t0x%08lX [%c]\n",
215 acpi_debug_layers[i].name,
216 acpi_debug_layers[i].value,
217 (acpi_dbg_layer & acpi_debug_layers[i].
218 value) ? '*' : ' ');
220 seq_printf(m, "%-25s\t0x%08X [%c]\n", "ACPI_ALL_DRIVERS",
221 ACPI_ALL_DRIVERS,
222 (acpi_dbg_layer & ACPI_ALL_DRIVERS) ==
223 ACPI_ALL_DRIVERS ? '*' : (acpi_dbg_layer &
224 ACPI_ALL_DRIVERS) ==
225 0 ? ' ' : '-');
226 seq_printf(m,
227 "--\ndebug_layer = 0x%08X (* = enabled, - = partial)\n",
228 acpi_dbg_layer);
229 break;
230 case 1:
231 for (i = 0; i < ARRAY_SIZE(acpi_debug_levels); i++) {
232 seq_printf(m, "%-25s\t0x%08lX [%c]\n",
233 acpi_debug_levels[i].name,
234 acpi_debug_levels[i].value,
235 (acpi_dbg_level & acpi_debug_levels[i].
236 value) ? '*' : ' ');
238 seq_printf(m, "--\ndebug_level = 0x%08X (* = enabled)\n",
239 acpi_dbg_level);
240 break;
242 return 0;
245 static int acpi_system_debug_proc_open(struct inode *inode, struct file *file)
247 return single_open(file, acpi_system_debug_proc_show, PDE(inode)->data);
250 static ssize_t acpi_system_debug_proc_write(struct file *file,
251 const char __user * buffer,
252 size_t count, loff_t *pos)
254 char debug_string[12] = { '\0' };
257 if (count > sizeof(debug_string) - 1)
258 return -EINVAL;
260 if (copy_from_user(debug_string, buffer, count))
261 return -EFAULT;
263 debug_string[count] = '\0';
265 switch ((unsigned long)PDE(file->f_path.dentry->d_inode)->data) {
266 case 0:
267 acpi_dbg_layer = simple_strtoul(debug_string, NULL, 0);
268 break;
269 case 1:
270 acpi_dbg_level = simple_strtoul(debug_string, NULL, 0);
271 break;
272 default:
273 return -EINVAL;
276 return count;
279 static const struct file_operations acpi_system_debug_proc_fops = {
280 .owner = THIS_MODULE,
281 .open = acpi_system_debug_proc_open,
282 .read = seq_read,
283 .llseek = seq_lseek,
284 .release = single_release,
285 .write = acpi_system_debug_proc_write,
287 #endif
289 int __init acpi_debug_init(void)
291 #ifdef CONFIG_ACPI_PROCFS
292 struct proc_dir_entry *entry;
293 int error = 0;
294 char *name;
296 /* 'debug_layer' [R/W] */
297 name = ACPI_SYSTEM_FILE_DEBUG_LAYER;
298 entry = proc_create_data(name, S_IFREG | S_IRUGO | S_IWUSR,
299 acpi_root_dir, &acpi_system_debug_proc_fops,
300 (void *)0);
301 if (!entry)
302 goto Error;
304 /* 'debug_level' [R/W] */
305 name = ACPI_SYSTEM_FILE_DEBUG_LEVEL;
306 entry = proc_create_data(name, S_IFREG | S_IRUGO | S_IWUSR,
307 acpi_root_dir, &acpi_system_debug_proc_fops,
308 (void *)1);
309 if (!entry)
310 goto Error;
312 Done:
313 return error;
315 Error:
316 remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LEVEL, acpi_root_dir);
317 remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LAYER, acpi_root_dir);
318 error = -ENODEV;
319 goto Done;
320 #else
321 return 0;
322 #endif