patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / acpi / debug.c
1 /*
2  * debug.c - ACPI debug interface to userspace.
3  */
4
5 #include <linux/proc_fs.h>
6 #include <linux/init.h>
7 #include <asm/uaccess.h>
8 #include <acpi/acpi_drivers.h>
9
10 #define _COMPONENT              ACPI_SYSTEM_COMPONENT
11 ACPI_MODULE_NAME                ("debug")
12
13 #define ACPI_SYSTEM_FILE_DEBUG_LAYER    "debug_layer"
14 #define ACPI_SYSTEM_FILE_DEBUG_LEVEL    "debug_level"
15
16 static int
17 acpi_system_read_debug (
18         char                    *page,
19         char                    **start,
20         off_t                   off,
21         int                     count,
22         int                     *eof,
23         void                    *data)
24 {
25         char                    *p = page;
26         int                     size = 0;
27
28         if (off != 0)
29                 goto end;
30
31         switch ((unsigned long) data) {
32         case 0:
33                 p += sprintf(p, "0x%08x\n", acpi_dbg_layer);
34                 break;
35         case 1:
36                 p += sprintf(p, "0x%08x\n", acpi_dbg_level);
37                 break;
38         default:
39                 p += sprintf(p, "Invalid debug option\n");
40                 break;
41         }
42         
43 end:
44         size = (p - page);
45         if (size <= off+count) *eof = 1;
46         *start = page + off;
47         size -= off;
48         if (size>count) size = count;
49         if (size<0) size = 0;
50
51         return size;
52 }
53
54
55 static int
56 acpi_system_write_debug (
57         struct file             *file,
58         const char              __user *buffer,
59         unsigned long           count,
60         void                    *data)
61 {
62         char                    debug_string[12] = {'\0'};
63
64         ACPI_FUNCTION_TRACE("acpi_system_write_debug");
65
66         if (count > sizeof(debug_string) - 1)
67                 return_VALUE(-EINVAL);
68
69         if (copy_from_user(debug_string, buffer, count))
70                 return_VALUE(-EFAULT);
71
72         debug_string[count] = '\0';
73
74         switch ((unsigned long) data) {
75         case 0:
76                 acpi_dbg_layer = simple_strtoul(debug_string, NULL, 0);
77                 break;
78         case 1:
79                 acpi_dbg_level = simple_strtoul(debug_string, NULL, 0);
80                 break;
81         default:
82                 return_VALUE(-EINVAL);
83         }
84
85         return_VALUE(count);
86 }
87
88 static int __init acpi_debug_init(void)
89 {
90         struct proc_dir_entry   *entry;
91         int error = 0;
92         char * name;
93
94         ACPI_FUNCTION_TRACE("acpi_debug_init");
95
96         if (acpi_disabled)
97                 return_VALUE(0);
98
99         /* 'debug_layer' [R/W] */
100         name = ACPI_SYSTEM_FILE_DEBUG_LAYER;
101         entry = create_proc_read_entry(name, S_IFREG|S_IRUGO|S_IWUSR, acpi_root_dir,
102                                        acpi_system_read_debug,(void *)0);
103         if (entry)
104                 entry->write_proc = acpi_system_write_debug;
105         else
106                 goto Error;
107
108         /* 'debug_level' [R/W] */
109         name = ACPI_SYSTEM_FILE_DEBUG_LEVEL;
110         entry = create_proc_read_entry(name, S_IFREG|S_IRUGO|S_IWUSR, acpi_root_dir,
111                                        acpi_system_read_debug, (void *)1);
112         if (entry) 
113                 entry->write_proc = acpi_system_write_debug;
114         else
115                 goto Error;
116
117  Done:
118         return_VALUE(error);
119
120  Error:
121         ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 
122                          "Unable to create '%s' proc fs entry\n", name));
123
124         remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LEVEL, acpi_root_dir);
125         remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LAYER, acpi_root_dir);
126         error = -EFAULT;
127         goto Done;
128 }
129
130 subsys_initcall(acpi_debug_init);