proc.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/proc_fs.h>
  3. #include <linux/seq_file.h>
  4. #include <linux/export.h>
  5. #include <linux/suspend.h>
  6. #include <linux/bcd.h>
  7. #include <linux/acpi.h>
  8. #include <linux/uaccess.h>
  9. #include "sleep.h"
  10. #include "internal.h"
  11. #define _COMPONENT ACPI_SYSTEM_COMPONENT
  12. /*
  13. * this file provides support for:
  14. * /proc/acpi/wakeup
  15. */
  16. ACPI_MODULE_NAME("sleep")
  17. static int
  18. acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
  19. {
  20. struct list_head *node, *next;
  21. seq_printf(seq, "Device\tS-state\t Status Sysfs node\n");
  22. mutex_lock(&acpi_device_lock);
  23. list_for_each_safe(node, next, &acpi_wakeup_device_list) {
  24. struct acpi_device *dev =
  25. container_of(node, struct acpi_device, wakeup_list);
  26. struct acpi_device_physical_node *entry;
  27. if (!dev->wakeup.flags.valid)
  28. continue;
  29. seq_printf(seq, "%s\t S%d\t",
  30. dev->pnp.bus_id,
  31. (u32) dev->wakeup.sleep_state);
  32. mutex_lock(&dev->physical_node_lock);
  33. if (!dev->physical_node_count) {
  34. seq_printf(seq, "%c%-8s\n",
  35. dev->wakeup.flags.valid ? '*' : ' ',
  36. device_may_wakeup(&dev->dev) ?
  37. "enabled" : "disabled");
  38. } else {
  39. struct device *ldev;
  40. list_for_each_entry(entry, &dev->physical_node_list,
  41. node) {
  42. ldev = get_device(entry->dev);
  43. if (!ldev)
  44. continue;
  45. if (&entry->node !=
  46. dev->physical_node_list.next)
  47. seq_printf(seq, "\t\t");
  48. seq_printf(seq, "%c%-8s %s:%s\n",
  49. dev->wakeup.flags.valid ? '*' : ' ',
  50. (device_may_wakeup(&dev->dev) ||
  51. device_may_wakeup(ldev)) ?
  52. "enabled" : "disabled",
  53. ldev->bus ? ldev->bus->name :
  54. "no-bus", dev_name(ldev));
  55. put_device(ldev);
  56. }
  57. }
  58. mutex_unlock(&dev->physical_node_lock);
  59. }
  60. mutex_unlock(&acpi_device_lock);
  61. return 0;
  62. }
  63. static void physical_device_enable_wakeup(struct acpi_device *adev)
  64. {
  65. struct acpi_device_physical_node *entry;
  66. mutex_lock(&adev->physical_node_lock);
  67. list_for_each_entry(entry,
  68. &adev->physical_node_list, node)
  69. if (entry->dev && device_can_wakeup(entry->dev)) {
  70. bool enable = !device_may_wakeup(entry->dev);
  71. device_set_wakeup_enable(entry->dev, enable);
  72. }
  73. mutex_unlock(&adev->physical_node_lock);
  74. }
  75. static ssize_t
  76. acpi_system_write_wakeup_device(struct file *file,
  77. const char __user * buffer,
  78. size_t count, loff_t * ppos)
  79. {
  80. struct list_head *node, *next;
  81. char strbuf[5];
  82. char str[5] = "";
  83. if (count > 4)
  84. count = 4;
  85. if (copy_from_user(strbuf, buffer, count))
  86. return -EFAULT;
  87. strbuf[count] = '\0';
  88. sscanf(strbuf, "%s", str);
  89. mutex_lock(&acpi_device_lock);
  90. list_for_each_safe(node, next, &acpi_wakeup_device_list) {
  91. struct acpi_device *dev =
  92. container_of(node, struct acpi_device, wakeup_list);
  93. if (!dev->wakeup.flags.valid)
  94. continue;
  95. if (!strncmp(dev->pnp.bus_id, str, 4)) {
  96. if (device_can_wakeup(&dev->dev)) {
  97. bool enable = !device_may_wakeup(&dev->dev);
  98. device_set_wakeup_enable(&dev->dev, enable);
  99. } else {
  100. physical_device_enable_wakeup(dev);
  101. }
  102. break;
  103. }
  104. }
  105. mutex_unlock(&acpi_device_lock);
  106. return count;
  107. }
  108. static int
  109. acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
  110. {
  111. return single_open(file, acpi_system_wakeup_device_seq_show,
  112. PDE_DATA(inode));
  113. }
  114. static const struct file_operations acpi_system_wakeup_device_fops = {
  115. .owner = THIS_MODULE,
  116. .open = acpi_system_wakeup_device_open_fs,
  117. .read = seq_read,
  118. .write = acpi_system_write_wakeup_device,
  119. .llseek = seq_lseek,
  120. .release = single_release,
  121. };
  122. void __init acpi_sleep_proc_init(void)
  123. {
  124. /* 'wakeup device' [R/W] */
  125. proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
  126. acpi_root_dir, &acpi_system_wakeup_device_fops);
  127. }