dm writecache: add cond_resched to loop in persistent_memory_claim()
[linux/fpc-iii.git] / drivers / acpi / proc.c
blob7892980b3ce4d3b4e0769d710084d154d3a4006a
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>
10 #include "sleep.h"
11 #include "internal.h"
13 #define _COMPONENT ACPI_SYSTEM_COMPONENT
16 * this file provides support for:
17 * /proc/acpi/wakeup
20 ACPI_MODULE_NAME("sleep")
22 static int
23 acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
25 struct acpi_device *dev, *tmp;
27 seq_printf(seq, "Device\tS-state\t Status Sysfs node\n");
29 mutex_lock(&acpi_device_lock);
30 list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
31 wakeup_list) {
32 struct acpi_device_physical_node *entry;
34 if (!dev->wakeup.flags.valid)
35 continue;
37 seq_printf(seq, "%s\t S%d\t",
38 dev->pnp.bus_id,
39 (u32) dev->wakeup.sleep_state);
41 mutex_lock(&dev->physical_node_lock);
43 if (!dev->physical_node_count) {
44 seq_printf(seq, "%c%-8s\n",
45 dev->wakeup.flags.valid ? '*' : ' ',
46 device_may_wakeup(&dev->dev) ?
47 "enabled" : "disabled");
48 } else {
49 struct device *ldev;
50 list_for_each_entry(entry, &dev->physical_node_list,
51 node) {
52 ldev = get_device(entry->dev);
53 if (!ldev)
54 continue;
56 if (&entry->node !=
57 dev->physical_node_list.next)
58 seq_printf(seq, "\t\t");
60 seq_printf(seq, "%c%-8s %s:%s\n",
61 dev->wakeup.flags.valid ? '*' : ' ',
62 (device_may_wakeup(&dev->dev) ||
63 device_may_wakeup(ldev)) ?
64 "enabled" : "disabled",
65 ldev->bus ? ldev->bus->name :
66 "no-bus", dev_name(ldev));
67 put_device(ldev);
71 mutex_unlock(&dev->physical_node_lock);
73 mutex_unlock(&acpi_device_lock);
74 return 0;
77 static void physical_device_enable_wakeup(struct acpi_device *adev)
79 struct acpi_device_physical_node *entry;
81 mutex_lock(&adev->physical_node_lock);
83 list_for_each_entry(entry,
84 &adev->physical_node_list, node)
85 if (entry->dev && device_can_wakeup(entry->dev)) {
86 bool enable = !device_may_wakeup(entry->dev);
87 device_set_wakeup_enable(entry->dev, enable);
90 mutex_unlock(&adev->physical_node_lock);
93 static ssize_t
94 acpi_system_write_wakeup_device(struct file *file,
95 const char __user * buffer,
96 size_t count, loff_t * ppos)
98 struct acpi_device *dev, *tmp;
99 char strbuf[5];
100 char str[5] = "";
102 if (count > 4)
103 count = 4;
105 if (copy_from_user(strbuf, buffer, count))
106 return -EFAULT;
107 strbuf[count] = '\0';
108 sscanf(strbuf, "%s", str);
110 mutex_lock(&acpi_device_lock);
111 list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
112 wakeup_list) {
113 if (!dev->wakeup.flags.valid)
114 continue;
116 if (!strncmp(dev->pnp.bus_id, str, 4)) {
117 if (device_can_wakeup(&dev->dev)) {
118 bool enable = !device_may_wakeup(&dev->dev);
119 device_set_wakeup_enable(&dev->dev, enable);
120 } else {
121 physical_device_enable_wakeup(dev);
123 break;
126 mutex_unlock(&acpi_device_lock);
127 return count;
130 static int
131 acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
133 return single_open(file, acpi_system_wakeup_device_seq_show,
134 PDE_DATA(inode));
137 static const struct proc_ops acpi_system_wakeup_device_proc_ops = {
138 .proc_open = acpi_system_wakeup_device_open_fs,
139 .proc_read = seq_read,
140 .proc_write = acpi_system_write_wakeup_device,
141 .proc_lseek = seq_lseek,
142 .proc_release = single_release,
145 void __init acpi_sleep_proc_init(void)
147 /* 'wakeup device' [R/W] */
148 proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
149 acpi_root_dir, &acpi_system_wakeup_device_proc_ops);