Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * debug.c - ACPI debug interface to userspace. |
| 3 | */ |
| 4 | |
| 5 | #include <linux/proc_fs.h> |
Alexey Dobriyan | 7d7decb | 2009-09-18 12:41:08 -0700 | [diff] [blame] | 6 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/init.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/moduleparam.h> |
Zhang Rui | a1a541d | 2009-12-02 13:31:00 +0800 | [diff] [blame] | 11 | #include <linux/debugfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/uaccess.h> |
| 14 | #include <acpi/acpi_drivers.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | #define _COMPONENT ACPI_SYSTEM_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 17 | ACPI_MODULE_NAME("debug"); |
Zhang Rui | 219c3c8 | 2007-01-29 11:02:38 +0800 | [diff] [blame] | 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | struct acpi_dlayer { |
| 20 | const char *name; |
| 21 | unsigned long value; |
| 22 | }; |
| 23 | struct acpi_dlevel { |
| 24 | const char *name; |
| 25 | unsigned long value; |
| 26 | }; |
| 27 | #define ACPI_DEBUG_INIT(v) { .name = #v, .value = v } |
| 28 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 29 | static const struct acpi_dlayer acpi_debug_layers[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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), |
Bjorn Helgaas | bdd7279 | 2008-11-07 16:57:55 -0700 | [diff] [blame] | 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), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 61 | static const struct acpi_dlevel acpi_debug_levels[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 93 | ACPI_DEBUG_INIT(ACPI_LV_EVENTS), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
Zhang Rui | 219c3c8 | 2007-01-29 11:02:38 +0800 | [diff] [blame] | 96 | /* -------------------------------------------------------------------------- |
| 97 | FS Interface (/sys) |
| 98 | -------------------------------------------------------------------------- */ |
| 99 | static int param_get_debug_layer(char *buffer, struct kernel_param *kp) { |
| 100 | int result = 0; |
| 101 | int i; |
| 102 | |
| 103 | result = sprintf(buffer, "%-25s\tHex SET\n", "Description"); |
| 104 | |
| 105 | for(i = 0; i <ARRAY_SIZE(acpi_debug_layers); i++) { |
| 106 | result += sprintf(buffer+result, "%-25s\t0x%08lX [%c]\n", |
| 107 | acpi_debug_layers[i].name, |
| 108 | acpi_debug_layers[i].value, |
| 109 | (acpi_dbg_layer & acpi_debug_layers[i].value) ? '*' : ' '); |
| 110 | } |
| 111 | result += sprintf(buffer+result, "%-25s\t0x%08X [%c]\n", "ACPI_ALL_DRIVERS", |
| 112 | ACPI_ALL_DRIVERS, |
| 113 | (acpi_dbg_layer & ACPI_ALL_DRIVERS) == |
| 114 | ACPI_ALL_DRIVERS ? '*' : (acpi_dbg_layer & |
| 115 | ACPI_ALL_DRIVERS) == 0 ? ' ' : '-'); |
| 116 | result += sprintf(buffer+result, "--\ndebug_layer = 0x%08X ( * = enabled)\n", acpi_dbg_layer); |
| 117 | |
| 118 | return result; |
| 119 | } |
| 120 | |
| 121 | static int param_get_debug_level(char *buffer, struct kernel_param *kp) { |
| 122 | int result = 0; |
| 123 | int i; |
| 124 | |
| 125 | result = sprintf(buffer, "%-25s\tHex SET\n", "Description"); |
| 126 | |
| 127 | for (i = 0; i < ARRAY_SIZE(acpi_debug_levels); i++) { |
| 128 | result += sprintf(buffer+result, "%-25s\t0x%08lX [%c]\n", |
| 129 | acpi_debug_levels[i].name, |
| 130 | acpi_debug_levels[i].value, |
| 131 | (acpi_dbg_level & acpi_debug_levels[i]. |
| 132 | value) ? '*' : ' '); |
| 133 | } |
| 134 | result += sprintf(buffer+result, "--\ndebug_level = 0x%08X (* = enabled)\n", |
| 135 | acpi_dbg_level); |
| 136 | |
| 137 | return result; |
| 138 | } |
| 139 | |
| 140 | module_param_call(debug_layer, param_set_uint, param_get_debug_layer, &acpi_dbg_layer, 0644); |
| 141 | module_param_call(debug_level, param_set_uint, param_get_debug_level, &acpi_dbg_level, 0644); |
| 142 | |
Zhang Rui | 4169c45 | 2007-11-14 19:38:40 -0500 | [diff] [blame] | 143 | static char trace_method_name[6]; |
| 144 | module_param_string(trace_method_name, trace_method_name, 6, 0644); |
| 145 | static unsigned int trace_debug_layer; |
| 146 | module_param(trace_debug_layer, uint, 0644); |
| 147 | static unsigned int trace_debug_level; |
| 148 | module_param(trace_debug_level, uint, 0644); |
| 149 | |
| 150 | static int param_set_trace_state(const char *val, struct kernel_param *kp) |
| 151 | { |
| 152 | int result = 0; |
| 153 | |
| 154 | if (!strncmp(val, "enable", strlen("enable") - 1)) { |
| 155 | result = acpi_debug_trace(trace_method_name, trace_debug_level, |
| 156 | trace_debug_layer, 0); |
| 157 | if (result) |
| 158 | result = -EBUSY; |
| 159 | goto exit; |
| 160 | } |
| 161 | |
| 162 | if (!strncmp(val, "disable", strlen("disable") - 1)) { |
| 163 | int name = 0; |
| 164 | result = acpi_debug_trace((char *)&name, trace_debug_level, |
| 165 | trace_debug_layer, 0); |
| 166 | if (result) |
| 167 | result = -EBUSY; |
| 168 | goto exit; |
| 169 | } |
| 170 | |
| 171 | if (!strncmp(val, "1", 1)) { |
| 172 | result = acpi_debug_trace(trace_method_name, trace_debug_level, |
| 173 | trace_debug_layer, 1); |
| 174 | if (result) |
| 175 | result = -EBUSY; |
| 176 | goto exit; |
| 177 | } |
| 178 | |
| 179 | result = -EINVAL; |
| 180 | exit: |
| 181 | return result; |
| 182 | } |
| 183 | |
| 184 | static int param_get_trace_state(char *buffer, struct kernel_param *kp) |
| 185 | { |
| 186 | if (!acpi_gbl_trace_method_name) |
| 187 | return sprintf(buffer, "disable"); |
| 188 | else { |
| 189 | if (acpi_gbl_trace_flags & 1) |
| 190 | return sprintf(buffer, "1"); |
| 191 | else |
| 192 | return sprintf(buffer, "enable"); |
| 193 | } |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | module_param_call(trace_state, param_set_trace_state, param_get_trace_state, |
| 198 | NULL, 0644); |
| 199 | |
Zhang Rui | 219c3c8 | 2007-01-29 11:02:38 +0800 | [diff] [blame] | 200 | /* -------------------------------------------------------------------------- |
Zhang Rui | a1a541d | 2009-12-02 13:31:00 +0800 | [diff] [blame] | 201 | DebugFS Interface |
| 202 | -------------------------------------------------------------------------- */ |
| 203 | |
| 204 | static ssize_t cm_write(struct file *file, const char __user *user_buf, |
| 205 | size_t count, loff_t *ppos) |
| 206 | { |
| 207 | static char *buf; |
| 208 | static int uncopied_bytes; |
| 209 | struct acpi_table_header table; |
| 210 | acpi_status status; |
| 211 | |
| 212 | if (!(*ppos)) { |
| 213 | /* parse the table header to get the table length */ |
| 214 | if (count <= sizeof(struct acpi_table_header)) |
| 215 | return -EINVAL; |
| 216 | if (copy_from_user(&table, user_buf, |
| 217 | sizeof(struct acpi_table_header))) |
| 218 | return -EFAULT; |
| 219 | uncopied_bytes = table.length; |
| 220 | buf = kzalloc(uncopied_bytes, GFP_KERNEL); |
| 221 | if (!buf) |
| 222 | return -ENOMEM; |
| 223 | } |
| 224 | |
| 225 | if (uncopied_bytes < count) { |
| 226 | kfree(buf); |
| 227 | return -EINVAL; |
| 228 | } |
| 229 | |
| 230 | if (copy_from_user(buf + (*ppos), user_buf, count)) { |
| 231 | kfree(buf); |
| 232 | return -EFAULT; |
| 233 | } |
| 234 | |
| 235 | uncopied_bytes -= count; |
| 236 | *ppos += count; |
| 237 | |
| 238 | if (!uncopied_bytes) { |
| 239 | status = acpi_install_method(buf); |
| 240 | kfree(buf); |
| 241 | if (ACPI_FAILURE(status)) |
| 242 | return -EINVAL; |
Zhang Rui | 4bab30a | 2009-12-14 11:24:18 +0800 | [diff] [blame] | 243 | add_taint(TAINT_OVERRIDDEN_ACPI_TABLE); |
Zhang Rui | a1a541d | 2009-12-02 13:31:00 +0800 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | return count; |
| 247 | } |
| 248 | |
| 249 | static const struct file_operations cm_fops = { |
| 250 | .write = cm_write, |
| 251 | }; |
| 252 | |
| 253 | static int acpi_debugfs_init(void) |
| 254 | { |
| 255 | struct dentry *acpi_dir, *cm_dentry; |
| 256 | |
| 257 | acpi_dir = debugfs_create_dir("acpi", NULL); |
| 258 | if (!acpi_dir) |
| 259 | goto err; |
| 260 | |
| 261 | cm_dentry = debugfs_create_file("custom_method", S_IWUGO, |
| 262 | acpi_dir, NULL, &cm_fops); |
| 263 | if (!cm_dentry) |
| 264 | goto err; |
| 265 | |
| 266 | return 0; |
| 267 | |
| 268 | err: |
| 269 | if (acpi_dir) |
| 270 | debugfs_remove(acpi_dir); |
| 271 | return -EINVAL; |
| 272 | } |
| 273 | |
| 274 | /* -------------------------------------------------------------------------- |
Zhang Rui | 219c3c8 | 2007-01-29 11:02:38 +0800 | [diff] [blame] | 275 | FS Interface (/proc) |
| 276 | -------------------------------------------------------------------------- */ |
| 277 | #ifdef CONFIG_ACPI_PROCFS |
| 278 | #define ACPI_SYSTEM_FILE_DEBUG_LAYER "debug_layer" |
| 279 | #define ACPI_SYSTEM_FILE_DEBUG_LEVEL "debug_level" |
| 280 | |
Alexey Dobriyan | 7d7decb | 2009-09-18 12:41:08 -0700 | [diff] [blame] | 281 | static int acpi_system_debug_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 283 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Alexey Dobriyan | 7d7decb | 2009-09-18 12:41:08 -0700 | [diff] [blame] | 285 | seq_printf(m, "%-25s\tHex SET\n", "Description"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
Alexey Dobriyan | 7d7decb | 2009-09-18 12:41:08 -0700 | [diff] [blame] | 287 | switch ((unsigned long)m->private) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | case 0: |
| 289 | for (i = 0; i < ARRAY_SIZE(acpi_debug_layers); i++) { |
Alexey Dobriyan | 7d7decb | 2009-09-18 12:41:08 -0700 | [diff] [blame] | 290 | seq_printf(m, "%-25s\t0x%08lX [%c]\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 291 | acpi_debug_layers[i].name, |
| 292 | acpi_debug_layers[i].value, |
| 293 | (acpi_dbg_layer & acpi_debug_layers[i]. |
| 294 | value) ? '*' : ' '); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
Alexey Dobriyan | 7d7decb | 2009-09-18 12:41:08 -0700 | [diff] [blame] | 296 | seq_printf(m, "%-25s\t0x%08X [%c]\n", "ACPI_ALL_DRIVERS", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | ACPI_ALL_DRIVERS, |
| 298 | (acpi_dbg_layer & ACPI_ALL_DRIVERS) == |
| 299 | ACPI_ALL_DRIVERS ? '*' : (acpi_dbg_layer & |
| 300 | ACPI_ALL_DRIVERS) == |
| 301 | 0 ? ' ' : '-'); |
Alexey Dobriyan | 7d7decb | 2009-09-18 12:41:08 -0700 | [diff] [blame] | 302 | seq_printf(m, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 303 | "--\ndebug_layer = 0x%08X (* = enabled, - = partial)\n", |
| 304 | acpi_dbg_layer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | break; |
| 306 | case 1: |
| 307 | for (i = 0; i < ARRAY_SIZE(acpi_debug_levels); i++) { |
Alexey Dobriyan | 7d7decb | 2009-09-18 12:41:08 -0700 | [diff] [blame] | 308 | seq_printf(m, "%-25s\t0x%08lX [%c]\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 309 | acpi_debug_levels[i].name, |
| 310 | acpi_debug_levels[i].value, |
| 311 | (acpi_dbg_level & acpi_debug_levels[i]. |
| 312 | value) ? '*' : ' '); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
Alexey Dobriyan | 7d7decb | 2009-09-18 12:41:08 -0700 | [diff] [blame] | 314 | seq_printf(m, "--\ndebug_level = 0x%08X (* = enabled)\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 315 | acpi_dbg_level); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
Alexey Dobriyan | 7d7decb | 2009-09-18 12:41:08 -0700 | [diff] [blame] | 318 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Alexey Dobriyan | 7d7decb | 2009-09-18 12:41:08 -0700 | [diff] [blame] | 321 | static int acpi_system_debug_proc_open(struct inode *inode, struct file *file) |
| 322 | { |
| 323 | return single_open(file, acpi_system_debug_proc_show, PDE(inode)->data); |
| 324 | } |
| 325 | |
| 326 | static ssize_t acpi_system_debug_proc_write(struct file *file, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 327 | const char __user * buffer, |
Alexey Dobriyan | 7d7decb | 2009-09-18 12:41:08 -0700 | [diff] [blame] | 328 | size_t count, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 330 | char debug_string[12] = { '\0' }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
| 333 | if (count > sizeof(debug_string) - 1) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 334 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
| 336 | if (copy_from_user(debug_string, buffer, count)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 337 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | debug_string[count] = '\0'; |
| 340 | |
Alexey Dobriyan | 7d7decb | 2009-09-18 12:41:08 -0700 | [diff] [blame] | 341 | switch ((unsigned long)PDE(file->f_path.dentry->d_inode)->data) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | case 0: |
| 343 | acpi_dbg_layer = simple_strtoul(debug_string, NULL, 0); |
| 344 | break; |
| 345 | case 1: |
| 346 | acpi_dbg_level = simple_strtoul(debug_string, NULL, 0); |
| 347 | break; |
| 348 | default: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 349 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 352 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |
Alexey Dobriyan | 7d7decb | 2009-09-18 12:41:08 -0700 | [diff] [blame] | 354 | |
| 355 | static const struct file_operations acpi_system_debug_proc_fops = { |
| 356 | .owner = THIS_MODULE, |
| 357 | .open = acpi_system_debug_proc_open, |
| 358 | .read = seq_read, |
| 359 | .llseek = seq_lseek, |
| 360 | .release = single_release, |
| 361 | .write = acpi_system_debug_proc_write, |
| 362 | }; |
Bjorn Helgaas | 84f810c | 2009-03-24 16:50:03 -0600 | [diff] [blame] | 363 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
Zhang Rui | a1a541d | 2009-12-02 13:31:00 +0800 | [diff] [blame] | 365 | int __init acpi_procfs_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | { |
Bjorn Helgaas | 84f810c | 2009-03-24 16:50:03 -0600 | [diff] [blame] | 367 | #ifdef CONFIG_ACPI_PROCFS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 368 | struct proc_dir_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | int error = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 370 | char *name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | /* 'debug_layer' [R/W] */ |
| 373 | name = ACPI_SYSTEM_FILE_DEBUG_LAYER; |
Alexey Dobriyan | 7d7decb | 2009-09-18 12:41:08 -0700 | [diff] [blame] | 374 | entry = proc_create_data(name, S_IFREG | S_IRUGO | S_IWUSR, |
| 375 | acpi_root_dir, &acpi_system_debug_proc_fops, |
| 376 | (void *)0); |
| 377 | if (!entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | goto Error; |
| 379 | |
| 380 | /* 'debug_level' [R/W] */ |
| 381 | name = ACPI_SYSTEM_FILE_DEBUG_LEVEL; |
Alexey Dobriyan | 7d7decb | 2009-09-18 12:41:08 -0700 | [diff] [blame] | 382 | entry = proc_create_data(name, S_IFREG | S_IRUGO | S_IWUSR, |
| 383 | acpi_root_dir, &acpi_system_debug_proc_fops, |
| 384 | (void *)1); |
| 385 | if (!entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | goto Error; |
| 387 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 388 | Done: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 389 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 391 | Error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LEVEL, acpi_root_dir); |
| 393 | remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LAYER, acpi_root_dir); |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 394 | error = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | goto Done; |
Bjorn Helgaas | 84f810c | 2009-03-24 16:50:03 -0600 | [diff] [blame] | 396 | #else |
| 397 | return 0; |
Zhang Rui | 219c3c8 | 2007-01-29 11:02:38 +0800 | [diff] [blame] | 398 | #endif |
Bjorn Helgaas | 84f810c | 2009-03-24 16:50:03 -0600 | [diff] [blame] | 399 | } |
Zhang Rui | a1a541d | 2009-12-02 13:31:00 +0800 | [diff] [blame] | 400 | |
| 401 | int __init acpi_debug_init(void) |
| 402 | { |
| 403 | acpi_debugfs_init(); |
| 404 | acpi_procfs_init(); |
| 405 | return 0; |
| 406 | } |