Blame view

drivers/acpi/proc.c 3.41 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  // SPDX-License-Identifier: GPL-2.0
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
  #include <linux/proc_fs.h>
  #include <linux/seq_file.h>
214f2c90b   Paul Gortmaker   acpi: add export....
4
  #include <linux/export.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
6
  #include <linux/suspend.h>
  #include <linux/bcd.h>
8b48463f8   Lv Zheng   ACPI: Clean up in...
7
  #include <linux/acpi.h>
7c0f6ba68   Linus Torvalds   Replace <asm/uacc...
8
  #include <linux/uaccess.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
9

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
  #include "sleep.h"
6a368751d   Rashika   ACPI / proc: Incl...
11
  #include "internal.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
12

43532c8a4   Len Brown   ACPI: Kconfig: fo...
13
14
  /*
   * this file provides support for:
43532c8a4   Len Brown   ACPI: Kconfig: fo...
15
16
   * /proc/acpi/wakeup
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
18
19
  static int
  acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
  {
07761a4cd   chenqiwu   ACPI: list_for_ea...
20
  	struct acpi_device *dev, *tmp;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21

8aa55591b   David Brownell   ACPI: make /proc/...
22
23
  	seq_printf(seq, "Device\tS-state\t  Status   Sysfs node
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24

9090589d8   Shaohua Li   ACPI: convert acp...
25
  	mutex_lock(&acpi_device_lock);
07761a4cd   chenqiwu   ACPI: list_for_ea...
26
27
  	list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
  				 wakeup_list) {
1033f9041   Lan Tianyu   ACPI: Allow ACPI ...
28
  		struct acpi_device_physical_node *entry;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
30
31
  
  		if (!dev->wakeup.flags.valid)
  			continue;
8aa55591b   David Brownell   ACPI: make /proc/...
32

1033f9041   Lan Tianyu   ACPI: Allow ACPI ...
33
  		seq_printf(seq, "%s\t  S%d\t",
4be44fcd3   Len Brown   [ACPI] Lindent al...
34
  			   dev->pnp.bus_id,
1033f9041   Lan Tianyu   ACPI: Allow ACPI ...
35
  			   (u32) dev->wakeup.sleep_state);
623cf33cb   Rafael J. Wysocki   ACPI / PM: Walk p...
36
  		mutex_lock(&dev->physical_node_lock);
65ab96f60   Andreas Fleig   ACPI / PM: Fix /p...
37
  		if (!dev->physical_node_count) {
1033f9041   Lan Tianyu   ACPI: Allow ACPI ...
38
39
  			seq_printf(seq, "%c%-8s
  ",
a1a66393e   Rafael J. Wysocki   ACPI / PM: Drop r...
40
  				dev->wakeup.flags.valid ? '*' : ' ',
65ab96f60   Andreas Fleig   ACPI / PM: Fix /p...
41
42
43
  				device_may_wakeup(&dev->dev) ?
  					"enabled" : "disabled");
  		} else {
1033f9041   Lan Tianyu   ACPI: Allow ACPI ...
44
45
46
47
48
49
50
51
52
53
54
55
56
  			struct device *ldev;
  			list_for_each_entry(entry, &dev->physical_node_list,
  					node) {
  				ldev = get_device(entry->dev);
  				if (!ldev)
  					continue;
  
  				if (&entry->node !=
  						dev->physical_node_list.next)
  					seq_printf(seq, "\t\t");
  
  				seq_printf(seq, "%c%-8s  %s:%s
  ",
a1a66393e   Rafael J. Wysocki   ACPI / PM: Drop r...
57
  					dev->wakeup.flags.valid ? '*' : ' ',
1033f9041   Lan Tianyu   ACPI: Allow ACPI ...
58
  					(device_may_wakeup(&dev->dev) ||
085ca1175   Dan Carpenter   ACPI / proc: remo...
59
  					device_may_wakeup(ldev)) ?
1033f9041   Lan Tianyu   ACPI: Allow ACPI ...
60
61
62
63
64
65
  					"enabled" : "disabled",
  					ldev->bus ? ldev->bus->name :
  					"no-bus", dev_name(ldev));
  				put_device(ldev);
  			}
  		}
623cf33cb   Rafael J. Wysocki   ACPI / PM: Walk p...
66
67
  
  		mutex_unlock(&dev->physical_node_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
68
  	}
9090589d8   Shaohua Li   ACPI: convert acp...
69
  	mutex_unlock(&acpi_device_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
70
71
  	return 0;
  }
76acae04c   Rafael J. Wysocki   ACPI: Make /proc/...
72
73
  static void physical_device_enable_wakeup(struct acpi_device *adev)
  {
1033f9041   Lan Tianyu   ACPI: Allow ACPI ...
74
  	struct acpi_device_physical_node *entry;
76acae04c   Rafael J. Wysocki   ACPI: Make /proc/...
75

623cf33cb   Rafael J. Wysocki   ACPI / PM: Walk p...
76
  	mutex_lock(&adev->physical_node_lock);
1033f9041   Lan Tianyu   ACPI: Allow ACPI ...
77
78
79
80
81
82
  	list_for_each_entry(entry,
  		&adev->physical_node_list, node)
  		if (entry->dev && device_can_wakeup(entry->dev)) {
  			bool enable = !device_may_wakeup(entry->dev);
  			device_set_wakeup_enable(entry->dev, enable);
  		}
623cf33cb   Rafael J. Wysocki   ACPI / PM: Walk p...
83
84
  
  	mutex_unlock(&adev->physical_node_lock);
76acae04c   Rafael J. Wysocki   ACPI: Make /proc/...
85
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
86
  static ssize_t
4be44fcd3   Len Brown   [ACPI] Lindent al...
87
88
89
  acpi_system_write_wakeup_device(struct file *file,
  				const char __user * buffer,
  				size_t count, loff_t * ppos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
  {
07761a4cd   chenqiwu   ACPI: list_for_ea...
91
  	struct acpi_device *dev, *tmp;
4be44fcd3   Len Brown   [ACPI] Lindent al...
92
93
  	char strbuf[5];
  	char str[5] = "";
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94

05bce79e6   Cyril Roelandt   ACPI: drop unnece...
95
96
  	if (count > 4)
  		count = 4;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
97

05bce79e6   Cyril Roelandt   ACPI: drop unnece...
98
  	if (copy_from_user(strbuf, buffer, count))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
99
  		return -EFAULT;
05bce79e6   Cyril Roelandt   ACPI: drop unnece...
100
  	strbuf[count] = '\0';
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
101
  	sscanf(strbuf, "%s", str);
9090589d8   Shaohua Li   ACPI: convert acp...
102
  	mutex_lock(&acpi_device_lock);
07761a4cd   chenqiwu   ACPI: list_for_ea...
103
104
  	list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
  				 wakeup_list) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
105
106
107
108
  		if (!dev->wakeup.flags.valid)
  			continue;
  
  		if (!strncmp(dev->pnp.bus_id, str, 4)) {
f2b56bc80   Rafael J. Wysocki   ACPI / PM: Use de...
109
110
111
112
113
114
  			if (device_can_wakeup(&dev->dev)) {
  				bool enable = !device_may_wakeup(&dev->dev);
  				device_set_wakeup_enable(&dev->dev, enable);
  			} else {
  				physical_device_enable_wakeup(dev);
  			}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115
116
117
  			break;
  		}
  	}
9090589d8   Shaohua Li   ACPI: convert acp...
118
  	mutex_unlock(&acpi_device_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119
120
121
122
123
124
  	return count;
  }
  
  static int
  acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
125
  	return single_open(file, acpi_system_wakeup_device_seq_show,
d9dda78ba   Al Viro   procfs: new helpe...
126
  			   PDE_DATA(inode));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
127
  }
97a32539b   Alexey Dobriyan   proc: convert eve...
128
129
130
131
132
133
  static const struct proc_ops acpi_system_wakeup_device_proc_ops = {
  	.proc_open	= acpi_system_wakeup_device_open_fs,
  	.proc_read	= seq_read,
  	.proc_write	= acpi_system_write_wakeup_device,
  	.proc_lseek	= seq_lseek,
  	.proc_release	= single_release,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
134
  };
f934c7450   Rami Rosen   ACPI: change acpi...
135
  void __init acpi_sleep_proc_init(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
136
  {
c65ade4dc   Pavel Machek   [ACPI] whitespace
137
  	/* 'wakeup device' [R/W] */
cf7acfab0   Denis V. Lunev   acpi: use non-rac...
138
  	proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
97a32539b   Alexey Dobriyan   proc: convert eve...
139
  		    acpi_root_dir, &acpi_system_wakeup_device_proc_ops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
140
  }