Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / acpi / debugfs.c
blob384f7abcff77984fb67c21c34b462761bc8f611e
1 /*
2 * debugfs.c - ACPI debugfs interface to userspace.
3 */
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>
12 #define _COMPONENT ACPI_SYSTEM_COMPONENT
13 ACPI_MODULE_NAME("debugfs");
16 /* /sys/modules/acpi/parameters/aml_debug_output */
18 module_param_named(aml_debug_output, acpi_gbl_enable_aml_debug_object,
19 bool, 0644);
20 MODULE_PARM_DESC(aml_debug_output,
21 "To enable/disable the ACPI Debug Object output.");
23 /* /sys/kernel/debug/acpi/custom_method */
25 static ssize_t cm_write(struct file *file, const char __user * user_buf,
26 size_t count, loff_t *ppos)
28 static char *buf;
29 static u32 max_size;
30 static u32 uncopied_bytes;
32 struct acpi_table_header table;
33 acpi_status status;
35 if (!(*ppos)) {
36 /* parse the table header to get the table length */
37 if (count <= sizeof(struct acpi_table_header))
38 return -EINVAL;
39 if (copy_from_user(&table, user_buf,
40 sizeof(struct acpi_table_header)))
41 return -EFAULT;
42 uncopied_bytes = max_size = table.length;
43 buf = kzalloc(max_size, GFP_KERNEL);
44 if (!buf)
45 return -ENOMEM;
48 if (buf == NULL)
49 return -EINVAL;
51 if ((*ppos > max_size) ||
52 (*ppos + count > max_size) ||
53 (*ppos + count < count) ||
54 (count > uncopied_bytes))
55 return -EINVAL;
57 if (copy_from_user(buf + (*ppos), user_buf, count)) {
58 kfree(buf);
59 buf = NULL;
60 return -EFAULT;
63 uncopied_bytes -= count;
64 *ppos += count;
66 if (!uncopied_bytes) {
67 status = acpi_install_method(buf);
68 kfree(buf);
69 buf = NULL;
70 if (ACPI_FAILURE(status))
71 return -EINVAL;
72 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
75 return count;
78 static const struct file_operations cm_fops = {
79 .write = cm_write,
80 .llseek = default_llseek,
83 int __init acpi_debugfs_init(void)
85 struct dentry *acpi_dir, *cm_dentry;
87 acpi_dir = debugfs_create_dir("acpi", NULL);
88 if (!acpi_dir)
89 goto err;
91 cm_dentry = debugfs_create_file("custom_method", S_IWUSR,
92 acpi_dir, NULL, &cm_fops);
93 if (!cm_dentry)
94 goto err;
96 return 0;
98 err:
99 if (acpi_dir)
100 debugfs_remove(acpi_dir);
101 return -EINVAL;