Zhang Rui | a25ee92 | 2010-07-15 10:46:15 +0800 | [diff] [blame] | 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 | |
Zhang Rui | c637e48 | 2010-07-15 10:46:17 +0800 | [diff] [blame] | 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 | |
Zhang Rui | a25ee92 | 2010-07-15 10:46:15 +0800 | [diff] [blame] | 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; |
Vasiliy Kulikov | 2949ad5 | 2011-02-19 14:18:08 +0100 | [diff] [blame] | 29 | static u32 max_size; |
| 30 | static u32 uncopied_bytes; |
| 31 | |
Zhang Rui | a25ee92 | 2010-07-15 10:46:15 +0800 | [diff] [blame] | 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; |
Vasiliy Kulikov | 2949ad5 | 2011-02-19 14:18:08 +0100 | [diff] [blame] | 42 | uncopied_bytes = max_size = table.length; |
| 43 | buf = kzalloc(max_size, GFP_KERNEL); |
Zhang Rui | a25ee92 | 2010-07-15 10:46:15 +0800 | [diff] [blame] | 44 | if (!buf) |
| 45 | return -ENOMEM; |
| 46 | } |
| 47 | |
Vasiliy Kulikov | 2949ad5 | 2011-02-19 14:18:08 +0100 | [diff] [blame] | 48 | if (buf == NULL) |
Zhang Rui | a25ee92 | 2010-07-15 10:46:15 +0800 | [diff] [blame] | 49 | return -EINVAL; |
Vasiliy Kulikov | 2949ad5 | 2011-02-19 14:18:08 +0100 | [diff] [blame] | 50 | |
| 51 | if ((*ppos > max_size) || |
| 52 | (*ppos + count > max_size) || |
| 53 | (*ppos + count < count) || |
| 54 | (count > uncopied_bytes)) |
| 55 | return -EINVAL; |
Zhang Rui | a25ee92 | 2010-07-15 10:46:15 +0800 | [diff] [blame] | 56 | |
| 57 | if (copy_from_user(buf + (*ppos), user_buf, count)) { |
| 58 | kfree(buf); |
Vasiliy Kulikov | 2949ad5 | 2011-02-19 14:18:08 +0100 | [diff] [blame] | 59 | buf = NULL; |
Zhang Rui | a25ee92 | 2010-07-15 10:46:15 +0800 | [diff] [blame] | 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); |
Vasiliy Kulikov | 2949ad5 | 2011-02-19 14:18:08 +0100 | [diff] [blame] | 69 | buf = NULL; |
Zhang Rui | a25ee92 | 2010-07-15 10:46:15 +0800 | [diff] [blame] | 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, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 80 | .llseek = default_llseek, |
Zhang Rui | a25ee92 | 2010-07-15 10:46:15 +0800 | [diff] [blame] | 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 | |
Dave Jones | ed3aada | 2010-11-13 00:58:54 -0500 | [diff] [blame] | 91 | cm_dentry = debugfs_create_file("custom_method", S_IWUSR, |
Zhang Rui | a25ee92 | 2010-07-15 10:46:15 +0800 | [diff] [blame] | 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 | } |