debugfs.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * debugfs.c - ACPI debugfs interface to userspace.
  3. */
  4. #include <linux/init.h>
  5. #include <linux/module.h>
  6. #include <linux/kernel.h>
  7. #include <linux/uaccess.h>
  8. #include <linux/debugfs.h>
  9. #include <acpi/acpi_drivers.h>
  10. #define _COMPONENT ACPI_SYSTEM_COMPONENT
  11. ACPI_MODULE_NAME("debugfs");
  12. /* /sys/modules/acpi/parameters/aml_debug_output */
  13. module_param_named(aml_debug_output, acpi_gbl_enable_aml_debug_object,
  14. bool, 0644);
  15. MODULE_PARM_DESC(aml_debug_output,
  16. "To enable/disable the ACPI Debug Object output.");
  17. /* /sys/kernel/debug/acpi/custom_method */
  18. static ssize_t cm_write(struct file *file, const char __user * user_buf,
  19. size_t count, loff_t *ppos)
  20. {
  21. static char *buf;
  22. static int uncopied_bytes;
  23. struct acpi_table_header table;
  24. acpi_status status;
  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. if (uncopied_bytes < count) {
  38. kfree(buf);
  39. return -EINVAL;
  40. }
  41. if (copy_from_user(buf + (*ppos), user_buf, count)) {
  42. kfree(buf);
  43. return -EFAULT;
  44. }
  45. uncopied_bytes -= count;
  46. *ppos += count;
  47. if (!uncopied_bytes) {
  48. status = acpi_install_method(buf);
  49. kfree(buf);
  50. if (ACPI_FAILURE(status))
  51. return -EINVAL;
  52. add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
  53. }
  54. return count;
  55. }
  56. static const struct file_operations cm_fops = {
  57. .write = cm_write,
  58. };
  59. int __init acpi_debugfs_init(void)
  60. {
  61. struct dentry *acpi_dir, *cm_dentry;
  62. acpi_dir = debugfs_create_dir("acpi", NULL);
  63. if (!acpi_dir)
  64. goto err;
  65. cm_dentry = debugfs_create_file("custom_method", S_IWUGO,
  66. acpi_dir, NULL, &cm_fops);
  67. if (!cm_dentry)
  68. goto err;
  69. return 0;
  70. err:
  71. if (acpi_dir)
  72. debugfs_remove(acpi_dir);
  73. return -EINVAL;
  74. }