Commit | Line | Data |
---|---|---|
a25ee920 ZR |
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 | |
13 | ACPI_MODULE_NAME("debugfs"); | |
14 | ||
c637e486 ZR |
15 | |
16 | /* /sys/modules/acpi/parameters/aml_debug_output */ | |
17 | ||
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."); | |
22 | ||
a25ee920 ZR |
23 | /* /sys/kernel/debug/acpi/custom_method */ |
24 | ||
25 | static ssize_t cm_write(struct file *file, const char __user * user_buf, | |
26 | size_t count, loff_t *ppos) | |
27 | { | |
28 | static char *buf; | |
2949ad50 VK |
29 | static u32 max_size; |
30 | static u32 uncopied_bytes; | |
31 | ||
a25ee920 ZR |
32 | 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; | |
2949ad50 VK |
42 | uncopied_bytes = max_size = table.length; |
43 | buf = kzalloc(max_size, GFP_KERNEL); | |
a25ee920 ZR |
44 | if (!buf) |
45 | return -ENOMEM; | |
46 | } | |
47 | ||
2949ad50 VK |
48 | if (buf == NULL) |
49 | return -EINVAL; | |
50 | ||
51 | if ((*ppos > max_size) || | |
52 | (*ppos + count > max_size) || | |
53 | (*ppos + count < count) || | |
54 | (count > uncopied_bytes)) | |
a25ee920 | 55 | return -EINVAL; |
a25ee920 ZR |
56 | |
57 | if (copy_from_user(buf + (*ppos), user_buf, count)) { | |
58 | kfree(buf); | |
2949ad50 | 59 | buf = NULL; |
a25ee920 ZR |
60 | 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); | |
2949ad50 | 69 | buf = NULL; |
a25ee920 ZR |
70 | if (ACPI_FAILURE(status)) |
71 | return -EINVAL; | |
72 | add_taint(TAINT_OVERRIDDEN_ACPI_TABLE); | |
73 | } | |
74 | ||
75 | return count; | |
76 | } | |
77 | ||
78 | static const struct file_operations cm_fops = { | |
79 | .write = cm_write, | |
6038f373 | 80 | .llseek = default_llseek, |
a25ee920 ZR |
81 | }; |
82 | ||
83 | int __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 | ||
ed3aada1 | 91 | cm_dentry = debugfs_create_file("custom_method", S_IWUSR, |
a25ee920 ZR |
92 | acpi_dir, NULL, &cm_fops); |
93 | if (!cm_dentry) | |
94 | goto err; | |
95 | ||
96 | return 0; | |
97 | ||
98 | err: | |
99 | if (acpi_dir) | |
100 | debugfs_remove(acpi_dir); | |
101 | return -EINVAL; | |
102 | } |