proc.c 3.6 KB

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