debugfs.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 u32 max_size;
  23. static u32 uncopied_bytes;
  24. struct acpi_table_header table;
  25. acpi_status status;
  26. if (!(*ppos)) {
  27. /* parse the table header to get the table length */
  28. if (count <= sizeof(struct acpi_table_header))
  29. return -EINVAL;
  30. if (copy_from_user(&table, user_buf,
  31. sizeof(struct acpi_table_header)))
  32. return -EFAULT;
  33. uncopied_bytes = max_size = table.length;
  34. buf = kzalloc(max_size, GFP_KERNEL);
  35. if (!buf)
  36. return -ENOMEM;
  37. }
  38. if (buf == NULL)
  39. return -EINVAL;
  40. if ((*ppos > max_size) ||
  41. (*ppos + count > max_size) ||
  42. (*ppos + count < count) ||
  43. (count > uncopied_bytes))
  44. return -EINVAL;
  45. if (copy_from_user(buf + (*ppos), user_buf, count)) {
  46. kfree(buf);
  47. buf = NULL;
  48. return -EFAULT;
  49. }
  50. uncopied_bytes -= count;
  51. *ppos += count;
  52. if (!uncopied_bytes) {
  53. status = acpi_install_method(buf);
  54. kfree(buf);
  55. buf = NULL;
  56. if (ACPI_FAILURE(status))
  57. return -EINVAL;
  58. add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
  59. }
  60. return count;
  61. }
  62. static const struct file_operations cm_fops = {
  63. .write = cm_write,
  64. .llseek = default_llseek,
  65. };
  66. int __init acpi_debugfs_init(void)
  67. {
  68. struct dentry *acpi_dir, *cm_dentry;
  69. acpi_dir = debugfs_create_dir("acpi", NULL);
  70. if (!acpi_dir)
  71. goto err;
  72. cm_dentry = debugfs_create_file("custom_method", S_IWUSR,
  73. acpi_dir, NULL, &cm_fops);
  74. if (!cm_dentry)
  75. goto err;
  76. return 0;
  77. err:
  78. if (acpi_dir)
  79. debugfs_remove(acpi_dir);
  80. return -EINVAL;
  81. }