aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhang Rui <rui.zhang@intel.com>2010-07-14 22:46:15 -0400
committerLen Brown <len.brown@intel.com>2010-08-14 23:02:00 -0400
commita25ee9200eef07377e1703697afbb5d81f89e500 (patch)
treeefecbc42b6a600ee17c81951834d88f1ad0566e3
parent9fe6206f400646a2322096b56c59891d530e8d51 (diff)
ACPI: introduce drivers/acpi/debugfs.c
Introduce drivers/acpi/debugfs.c. Code for ACPI debugfs I/F, i.e. /sys/kernel/debug/acpi/custom_method, is moved to this file. And make ACPI debugfs always built in, even if CONFIG_ACPI_DEBUG is cleared. BTW:this adds about 400bytes code to ACPI, when CONFIG_ACPI_DEBUG is cleared. [uaccess.h build fix from Andrew Morton <akpm@linux-foundation.org>] Signed-off-by: Zhang Rui <rui.zhang@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
-rw-r--r--drivers/acpi/Makefile1
-rw-r--r--drivers/acpi/bus.c1
-rw-r--r--drivers/acpi/debug.c75
-rw-r--r--drivers/acpi/debugfs.c85
-rw-r--r--drivers/acpi/internal.h6
5 files changed, 93 insertions, 75 deletions
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 6ee33169e1dc..7891904419fc 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -39,6 +39,7 @@ acpi-y += pci_root.o pci_link.o pci_irq.o pci_bind.o
39acpi-y += power.o 39acpi-y += power.o
40acpi-y += system.o event.o 40acpi-y += system.o event.o
41acpi-$(CONFIG_ACPI_DEBUG) += debug.o 41acpi-$(CONFIG_ACPI_DEBUG) += debug.o
42acpi-$(CONFIG_DEBUG_FS) += debugfs.o
42acpi-$(CONFIG_ACPI_NUMA) += numa.o 43acpi-$(CONFIG_ACPI_NUMA) += numa.o
43acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o 44acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o
44ifdef CONFIG_ACPI_VIDEO 45ifdef CONFIG_ACPI_VIDEO
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index c1d23cd71652..7136f24e3002 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -1036,6 +1036,7 @@ static int __init acpi_init(void)
1036 acpi_power_init(); 1036 acpi_power_init();
1037 acpi_system_init(); 1037 acpi_system_init();
1038 acpi_debug_init(); 1038 acpi_debug_init();
1039 acpi_debugfs_init();
1039 acpi_sleep_proc_init(); 1040 acpi_sleep_proc_init();
1040 acpi_wakeup_device_init(); 1041 acpi_wakeup_device_init();
1041 return result; 1042 return result;
diff --git a/drivers/acpi/debug.c b/drivers/acpi/debug.c
index 146135e7a6a1..22476eab2b08 100644
--- a/drivers/acpi/debug.c
+++ b/drivers/acpi/debug.c
@@ -198,80 +198,6 @@ module_param_call(trace_state, param_set_trace_state, param_get_trace_state,
198 NULL, 0644); 198 NULL, 0644);
199 199
200/* -------------------------------------------------------------------------- 200/* --------------------------------------------------------------------------
201 DebugFS Interface
202 -------------------------------------------------------------------------- */
203
204static 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;
243 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
244 }
245
246 return count;
247}
248
249static const struct file_operations cm_fops = {
250 .write = cm_write,
251};
252
253static 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
268err:
269 if (acpi_dir)
270 debugfs_remove(acpi_dir);
271 return -EINVAL;
272}
273
274/* --------------------------------------------------------------------------
275 FS Interface (/proc) 201 FS Interface (/proc)
276 -------------------------------------------------------------------------- */ 202 -------------------------------------------------------------------------- */
277#ifdef CONFIG_ACPI_PROCFS 203#ifdef CONFIG_ACPI_PROCFS
@@ -400,7 +326,6 @@ int __init acpi_procfs_init(void)
400 326
401int __init acpi_debug_init(void) 327int __init acpi_debug_init(void)
402{ 328{
403 acpi_debugfs_init();
404 acpi_procfs_init(); 329 acpi_procfs_init();
405 return 0; 330 return 0;
406} 331}
diff --git a/drivers/acpi/debugfs.c b/drivers/acpi/debugfs.c
new file mode 100644
index 000000000000..abfcf9f6e766
--- /dev/null
+++ b/drivers/acpi/debugfs.c
@@ -0,0 +1,85 @@
1/*
2 * debugfs.c - ACPI debugfs interface to userspace.
3 */
4
5#include <linux/init.h>
6#include <linux/module.h>
7#include <linux/kernel.h>
8#include <linux/uaccess.h>
9#include <linux/debugfs.h>
10#include <acpi/acpi_drivers.h>
11
12#define _COMPONENT ACPI_SYSTEM_COMPONENT
13ACPI_MODULE_NAME("debugfs");
14
15/* /sys/kernel/debug/acpi/custom_method */
16
17static ssize_t cm_write(struct file *file, const char __user * user_buf,
18 size_t count, loff_t *ppos)
19{
20 static char *buf;
21 static int uncopied_bytes;
22 struct acpi_table_header table;
23 acpi_status status;
24
25 if (!(*ppos)) {
26 /* parse the table header to get the table length */
27 if (count <= sizeof(struct acpi_table_header))
28 return -EINVAL;
29 if (copy_from_user(&table, user_buf,
30 sizeof(struct acpi_table_header)))
31 return -EFAULT;
32 uncopied_bytes = table.length;
33 buf = kzalloc(uncopied_bytes, GFP_KERNEL);
34 if (!buf)
35 return -ENOMEM;
36 }
37
38 if (uncopied_bytes < count) {
39 kfree(buf);
40 return -EINVAL;
41 }
42
43 if (copy_from_user(buf + (*ppos), user_buf, count)) {
44 kfree(buf);
45 return -EFAULT;
46 }
47
48 uncopied_bytes -= count;
49 *ppos += count;
50
51 if (!uncopied_bytes) {
52 status = acpi_install_method(buf);
53 kfree(buf);
54 if (ACPI_FAILURE(status))
55 return -EINVAL;
56 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
57 }
58
59 return count;
60}
61
62static const struct file_operations cm_fops = {
63 .write = cm_write,
64};
65
66int __init acpi_debugfs_init(void)
67{
68 struct dentry *acpi_dir, *cm_dentry;
69
70 acpi_dir = debugfs_create_dir("acpi", NULL);
71 if (!acpi_dir)
72 goto err;
73
74 cm_dentry = debugfs_create_file("custom_method", S_IWUGO,
75 acpi_dir, NULL, &cm_fops);
76 if (!cm_dentry)
77 goto err;
78
79 return 0;
80
81err:
82 if (acpi_dir)
83 debugfs_remove(acpi_dir);
84 return -EINVAL;
85}
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index f8f190ec066e..0650e343867e 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -30,6 +30,12 @@ int acpi_debug_init(void);
30static inline int acpi_debug_init(void) { return 0; } 30static inline int acpi_debug_init(void) { return 0; }
31#endif 31#endif
32 32
33#ifdef CONFIG_DEBUG_FS
34int acpi_debugfs_init(void);
35#else
36static inline int acpi_debugfs_init(void) { return 0; }
37#endif
38
33/* -------------------------------------------------------------------------- 39/* --------------------------------------------------------------------------
34 Power Resource 40 Power Resource
35 -------------------------------------------------------------------------- */ 41 -------------------------------------------------------------------------- */