blob: 384f7abcff77984fb67c21c34b462761bc8f611e [file] [log] [blame]
Zhang Ruia25ee922010-07-15 10:46:15 +08001/*
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
Zhang Ruic637e482010-07-15 10:46:17 +080015
16/* /sys/modules/acpi/parameters/aml_debug_output */
17
18module_param_named(aml_debug_output, acpi_gbl_enable_aml_debug_object,
19 bool, 0644);
20MODULE_PARM_DESC(aml_debug_output,
21 "To enable/disable the ACPI Debug Object output.");
22
Zhang Ruia25ee922010-07-15 10:46:15 +080023/* /sys/kernel/debug/acpi/custom_method */
24
25static ssize_t cm_write(struct file *file, const char __user * user_buf,
26 size_t count, loff_t *ppos)
27{
28 static char *buf;
Vasiliy Kulikov2949ad52011-02-19 14:18:08 +010029 static u32 max_size;
30 static u32 uncopied_bytes;
31
Zhang Ruia25ee922010-07-15 10:46:15 +080032 struct acpi_table_header table;
33 acpi_status status;
34
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;
Vasiliy Kulikov2949ad52011-02-19 14:18:08 +010042 uncopied_bytes = max_size = table.length;
43 buf = kzalloc(max_size, GFP_KERNEL);
Zhang Ruia25ee922010-07-15 10:46:15 +080044 if (!buf)
45 return -ENOMEM;
46 }
47
Vasiliy Kulikov2949ad52011-02-19 14:18:08 +010048 if (buf == NULL)
Zhang Ruia25ee922010-07-15 10:46:15 +080049 return -EINVAL;
Vasiliy Kulikov2949ad52011-02-19 14:18:08 +010050
51 if ((*ppos > max_size) ||
52 (*ppos + count > max_size) ||
53 (*ppos + count < count) ||
54 (count > uncopied_bytes))
55 return -EINVAL;
Zhang Ruia25ee922010-07-15 10:46:15 +080056
57 if (copy_from_user(buf + (*ppos), user_buf, count)) {
58 kfree(buf);
Vasiliy Kulikov2949ad52011-02-19 14:18:08 +010059 buf = NULL;
Zhang Ruia25ee922010-07-15 10:46:15 +080060 return -EFAULT;
61 }
62
63 uncopied_bytes -= count;
64 *ppos += count;
65
66 if (!uncopied_bytes) {
67 status = acpi_install_method(buf);
68 kfree(buf);
Vasiliy Kulikov2949ad52011-02-19 14:18:08 +010069 buf = NULL;
Zhang Ruia25ee922010-07-15 10:46:15 +080070 if (ACPI_FAILURE(status))
71 return -EINVAL;
72 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
73 }
74
75 return count;
76}
77
78static const struct file_operations cm_fops = {
79 .write = cm_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +020080 .llseek = default_llseek,
Zhang Ruia25ee922010-07-15 10:46:15 +080081};
82
83int __init acpi_debugfs_init(void)
84{
85 struct dentry *acpi_dir, *cm_dentry;
86
87 acpi_dir = debugfs_create_dir("acpi", NULL);
88 if (!acpi_dir)
89 goto err;
90
Dave Jonesed3aada2010-11-13 00:58:54 -050091 cm_dentry = debugfs_create_file("custom_method", S_IWUSR,
Zhang Ruia25ee922010-07-15 10:46:15 +080092 acpi_dir, NULL, &cm_fops);
93 if (!cm_dentry)
94 goto err;
95
96 return 0;
97
98err:
99 if (acpi_dir)
100 debugfs_remove(acpi_dir);
101 return -EINVAL;
102}