debugfs.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. .llseek = default_llseek,
  59. };
  60. int __init acpi_debugfs_init(void)
  61. {
  62. struct dentry *acpi_dir, *cm_dentry;
  63. acpi_dir = debugfs_create_dir("acpi", NULL);
  64. if (!acpi_dir)
  65. goto err;
  66. cm_dentry = debugfs_create_file("custom_method", S_IWUSR,
  67. acpi_dir, NULL, &cm_fops);
  68. if (!cm_dentry)
  69. goto err;
  70. return 0;
  71. err:
  72. if (acpi_dir)
  73. debugfs_remove(acpi_dir);
  74. return -EINVAL;
  75. }