2 * debug.c - ACPI debug interface to userspace.
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");
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 /* --------------------------------------------------------------------------
96 -------------------------------------------------------------------------- */
97 static int param_get_debug_layer(char *buffer
, struct kernel_param
*kp
) {
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",
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
);
119 static int param_get_debug_level(char *buffer
, struct kernel_param
*kp
) {
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
].
132 result
+= sprintf(buffer
+result
, "--\ndebug_level = 0x%08X (* = enabled)\n",
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
)
152 if (!strncmp(val
, "enable", strlen("enable") - 1)) {
153 result
= acpi_debug_trace(trace_method_name
, trace_debug_level
,
154 trace_debug_layer
, 0);
160 if (!strncmp(val
, "disable", strlen("disable") - 1)) {
162 result
= acpi_debug_trace((char *)&name
, trace_debug_level
,
163 trace_debug_layer
, 0);
169 if (!strncmp(val
, "1", 1)) {
170 result
= acpi_debug_trace(trace_method_name
, trace_debug_level
,
171 trace_debug_layer
, 1);
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");
187 if (acpi_gbl_trace_flags
& 1)
188 return sprintf(buffer
, "1");
190 return sprintf(buffer
, "enable");
195 module_param_call(trace_state
, param_set_trace_state
, param_get_trace_state
,
198 /* --------------------------------------------------------------------------
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
)
209 seq_printf(m
, "%-25s\tHex SET\n", "Description");
211 switch ((unsigned long)m
->private) {
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
].
220 seq_printf(m
, "%-25s\t0x%08X [%c]\n", "ACPI_ALL_DRIVERS",
222 (acpi_dbg_layer
& ACPI_ALL_DRIVERS
) ==
223 ACPI_ALL_DRIVERS
? '*' : (acpi_dbg_layer
&
227 "--\ndebug_layer = 0x%08X (* = enabled, - = partial)\n",
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
].
238 seq_printf(m
, "--\ndebug_level = 0x%08X (* = enabled)\n",
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)
260 if (copy_from_user(debug_string
, buffer
, count
))
263 debug_string
[count
] = '\0';
265 switch ((unsigned long)PDE(file
->f_path
.dentry
->d_inode
)->data
) {
267 acpi_dbg_layer
= simple_strtoul(debug_string
, NULL
, 0);
270 acpi_dbg_level
= simple_strtoul(debug_string
, NULL
, 0);
279 static const struct file_operations acpi_system_debug_proc_fops
= {
280 .owner
= THIS_MODULE
,
281 .open
= acpi_system_debug_proc_open
,
284 .release
= single_release
,
285 .write
= acpi_system_debug_proc_write
,
289 int __init
acpi_debug_init(void)
291 #ifdef CONFIG_ACPI_PROCFS
292 struct proc_dir_entry
*entry
;
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
,
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
,
316 remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LEVEL
, acpi_root_dir
);
317 remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LAYER
, acpi_root_dir
);