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> |
| 6 | #include <linux/init.h> |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/kernel.h> |
| 9 | #include <linux/moduleparam.h> |
| 10 | #include <asm/uaccess.h> |
| 11 | #include <acpi/acpi_drivers.h> |
| 12 | #include <acpi/acglobal.h> |
| 13 | |
| 14 | #define _COMPONENT ACPI_SYSTEM_COMPONENT |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 15 | ACPI_MODULE_NAME("debug") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #define ACPI_SYSTEM_FILE_DEBUG_LAYER "debug_layer" |
| 17 | #define ACPI_SYSTEM_FILE_DEBUG_LEVEL "debug_level" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #ifdef MODULE_PARAM_PREFIX |
| 19 | #undef MODULE_PARAM_PREFIX |
| 20 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #define MODULE_PARAM_PREFIX |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 22 | module_param(acpi_dbg_layer, uint, 0400); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | module_param(acpi_dbg_level, uint, 0400); |
| 24 | |
| 25 | struct acpi_dlayer { |
| 26 | const char *name; |
| 27 | unsigned long value; |
| 28 | }; |
| 29 | struct acpi_dlevel { |
| 30 | const char *name; |
| 31 | unsigned long value; |
| 32 | }; |
| 33 | #define ACPI_DEBUG_INIT(v) { .name = #v, .value = v } |
| 34 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 35 | static const struct acpi_dlayer acpi_debug_layers[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | ACPI_DEBUG_INIT(ACPI_UTILITIES), |
| 37 | ACPI_DEBUG_INIT(ACPI_HARDWARE), |
| 38 | ACPI_DEBUG_INIT(ACPI_EVENTS), |
| 39 | ACPI_DEBUG_INIT(ACPI_TABLES), |
| 40 | ACPI_DEBUG_INIT(ACPI_NAMESPACE), |
| 41 | ACPI_DEBUG_INIT(ACPI_PARSER), |
| 42 | ACPI_DEBUG_INIT(ACPI_DISPATCHER), |
| 43 | ACPI_DEBUG_INIT(ACPI_EXECUTER), |
| 44 | ACPI_DEBUG_INIT(ACPI_RESOURCES), |
| 45 | ACPI_DEBUG_INIT(ACPI_CA_DEBUGGER), |
| 46 | ACPI_DEBUG_INIT(ACPI_OS_SERVICES), |
| 47 | ACPI_DEBUG_INIT(ACPI_CA_DISASSEMBLER), |
| 48 | ACPI_DEBUG_INIT(ACPI_COMPILER), |
| 49 | ACPI_DEBUG_INIT(ACPI_TOOLS), |
| 50 | }; |
| 51 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | static const struct acpi_dlevel acpi_debug_levels[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | ACPI_DEBUG_INIT(ACPI_LV_ERROR), |
| 54 | ACPI_DEBUG_INIT(ACPI_LV_WARN), |
| 55 | ACPI_DEBUG_INIT(ACPI_LV_INIT), |
| 56 | ACPI_DEBUG_INIT(ACPI_LV_DEBUG_OBJECT), |
| 57 | ACPI_DEBUG_INIT(ACPI_LV_INFO), |
| 58 | |
| 59 | ACPI_DEBUG_INIT(ACPI_LV_INIT_NAMES), |
| 60 | ACPI_DEBUG_INIT(ACPI_LV_PARSE), |
| 61 | ACPI_DEBUG_INIT(ACPI_LV_LOAD), |
| 62 | ACPI_DEBUG_INIT(ACPI_LV_DISPATCH), |
| 63 | ACPI_DEBUG_INIT(ACPI_LV_EXEC), |
| 64 | ACPI_DEBUG_INIT(ACPI_LV_NAMES), |
| 65 | ACPI_DEBUG_INIT(ACPI_LV_OPREGION), |
| 66 | ACPI_DEBUG_INIT(ACPI_LV_BFIELD), |
| 67 | ACPI_DEBUG_INIT(ACPI_LV_TABLES), |
| 68 | ACPI_DEBUG_INIT(ACPI_LV_VALUES), |
| 69 | ACPI_DEBUG_INIT(ACPI_LV_OBJECTS), |
| 70 | ACPI_DEBUG_INIT(ACPI_LV_RESOURCES), |
| 71 | ACPI_DEBUG_INIT(ACPI_LV_USER_REQUESTS), |
| 72 | ACPI_DEBUG_INIT(ACPI_LV_PACKAGE), |
| 73 | |
| 74 | ACPI_DEBUG_INIT(ACPI_LV_ALLOCATIONS), |
| 75 | ACPI_DEBUG_INIT(ACPI_LV_FUNCTIONS), |
| 76 | ACPI_DEBUG_INIT(ACPI_LV_OPTIMIZATIONS), |
| 77 | |
| 78 | ACPI_DEBUG_INIT(ACPI_LV_MUTEX), |
| 79 | ACPI_DEBUG_INIT(ACPI_LV_THREADS), |
| 80 | ACPI_DEBUG_INIT(ACPI_LV_IO), |
| 81 | ACPI_DEBUG_INIT(ACPI_LV_INTERRUPTS), |
| 82 | |
| 83 | ACPI_DEBUG_INIT(ACPI_LV_AML_DISASSEMBLE), |
| 84 | ACPI_DEBUG_INIT(ACPI_LV_VERBOSE_INFO), |
| 85 | ACPI_DEBUG_INIT(ACPI_LV_FULL_TABLES), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 86 | ACPI_DEBUG_INIT(ACPI_LV_EVENTS), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 90 | acpi_system_read_debug(char *page, |
| 91 | char **start, off_t off, int count, int *eof, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 93 | char *p = page; |
| 94 | int size = 0; |
| 95 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
| 97 | if (off != 0) |
| 98 | goto end; |
| 99 | |
| 100 | p += sprintf(p, "%-25s\tHex SET\n", "Description"); |
| 101 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 102 | switch ((unsigned long)data) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | case 0: |
| 104 | for (i = 0; i < ARRAY_SIZE(acpi_debug_layers); i++) { |
| 105 | p += sprintf(p, "%-25s\t0x%08lX [%c]\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 106 | acpi_debug_layers[i].name, |
| 107 | acpi_debug_layers[i].value, |
| 108 | (acpi_dbg_layer & acpi_debug_layers[i]. |
| 109 | value) ? '*' : ' '); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | p += sprintf(p, "%-25s\t0x%08X [%c]\n", "ACPI_ALL_DRIVERS", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 112 | ACPI_ALL_DRIVERS, |
| 113 | (acpi_dbg_layer & ACPI_ALL_DRIVERS) == |
| 114 | ACPI_ALL_DRIVERS ? '*' : (acpi_dbg_layer & |
| 115 | ACPI_ALL_DRIVERS) == |
| 116 | 0 ? ' ' : '-'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | p += sprintf(p, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 118 | "--\ndebug_layer = 0x%08X (* = enabled, - = partial)\n", |
| 119 | acpi_dbg_layer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | break; |
| 121 | case 1: |
| 122 | for (i = 0; i < ARRAY_SIZE(acpi_debug_levels); i++) { |
| 123 | p += sprintf(p, "%-25s\t0x%08lX [%c]\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 124 | acpi_debug_levels[i].name, |
| 125 | acpi_debug_levels[i].value, |
| 126 | (acpi_dbg_level & acpi_debug_levels[i]. |
| 127 | value) ? '*' : ' '); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
| 129 | p += sprintf(p, "--\ndebug_level = 0x%08X (* = enabled)\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 130 | acpi_dbg_level); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | break; |
| 132 | default: |
| 133 | p += sprintf(p, "Invalid debug option\n"); |
| 134 | break; |
| 135 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 136 | |
| 137 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | size = (p - page); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 139 | if (size <= off + count) |
| 140 | *eof = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | *start = page + off; |
| 142 | size -= off; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 143 | if (size > count) |
| 144 | size = count; |
| 145 | if (size < 0) |
| 146 | size = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | return size; |
| 149 | } |
| 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 152 | acpi_system_write_debug(struct file *file, |
| 153 | const char __user * buffer, |
| 154 | unsigned long count, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | char debug_string[12] = { '\0' }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
| 159 | if (count > sizeof(debug_string) - 1) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 160 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | if (copy_from_user(debug_string, buffer, count)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 163 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | debug_string[count] = '\0'; |
| 166 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 167 | switch ((unsigned long)data) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | case 0: |
| 169 | acpi_dbg_layer = simple_strtoul(debug_string, NULL, 0); |
| 170 | break; |
| 171 | case 1: |
| 172 | acpi_dbg_level = simple_strtoul(debug_string, NULL, 0); |
| 173 | break; |
| 174 | default: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 175 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 178 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | static int __init acpi_debug_init(void) |
| 182 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 183 | struct proc_dir_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | int error = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 185 | char *name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | if (acpi_disabled) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 189 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | /* 'debug_layer' [R/W] */ |
| 192 | name = ACPI_SYSTEM_FILE_DEBUG_LAYER; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 193 | entry = |
| 194 | create_proc_read_entry(name, S_IFREG | S_IRUGO | S_IWUSR, |
| 195 | acpi_root_dir, acpi_system_read_debug, |
| 196 | (void *)0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | if (entry) |
| 198 | entry->write_proc = acpi_system_write_debug; |
| 199 | else |
| 200 | goto Error; |
| 201 | |
| 202 | /* 'debug_level' [R/W] */ |
| 203 | name = ACPI_SYSTEM_FILE_DEBUG_LEVEL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | entry = |
| 205 | create_proc_read_entry(name, S_IFREG | S_IRUGO | S_IWUSR, |
| 206 | acpi_root_dir, acpi_system_read_debug, |
| 207 | (void *)1); |
| 208 | if (entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | entry->write_proc = acpi_system_write_debug; |
| 210 | else |
| 211 | goto Error; |
| 212 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 213 | Done: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 214 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | Error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LEVEL, acpi_root_dir); |
| 218 | remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LAYER, acpi_root_dir); |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 219 | error = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | goto Done; |
| 221 | } |
| 222 | |
| 223 | subsys_initcall(acpi_debug_init); |