aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/testing/sysfs-devices-power_resources_D013
-rw-r--r--Documentation/ABI/testing/sysfs-devices-power_resources_D114
-rw-r--r--Documentation/ABI/testing/sysfs-devices-power_resources_D214
-rw-r--r--Documentation/ABI/testing/sysfs-devices-power_resources_D3hot14
-rw-r--r--Documentation/ABI/testing/sysfs-devices-power_state20
-rw-r--r--Documentation/ABI/testing/sysfs-devices-real_power_state23
-rw-r--r--Documentation/ABI/testing/sysfs-devices-resource_in_use12
-rw-r--r--drivers/acpi/bus.c270
-rw-r--r--drivers/acpi/device_pm.c342
-rw-r--r--drivers/acpi/internal.h20
-rw-r--r--drivers/acpi/power.c730
-rw-r--r--drivers/acpi/proc.c9
-rw-r--r--drivers/acpi/scan.c457
-rw-r--r--drivers/acpi/sleep.c89
-rw-r--r--drivers/acpi/sleep.h2
-rw-r--r--drivers/ata/libata-acpi.c18
-rw-r--r--drivers/pci/pci-acpi.c2
-rw-r--r--fs/sysfs/group.c42
-rw-r--r--fs/sysfs/symlink.c45
-rw-r--r--fs/sysfs/sysfs.h2
-rw-r--r--include/acpi/acpi_bus.h54
-rw-r--r--include/linux/acpi.h2
-rw-r--r--include/linux/sysfs.h16
23 files changed, 1313 insertions, 897 deletions
diff --git a/Documentation/ABI/testing/sysfs-devices-power_resources_D0 b/Documentation/ABI/testing/sysfs-devices-power_resources_D0
new file mode 100644
index 000000000000..73b77a6be196
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-power_resources_D0
@@ -0,0 +1,13 @@
1What: /sys/devices/.../power_resources_D0/
2Date: January 2013
3Contact: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
4Description:
5 The /sys/devices/.../power_resources_D0/ directory is only
6 present for device objects representing ACPI device nodes that
7 use ACPI power resources for power management.
8
9 If present, it contains symbolic links to device directories
10 representing ACPI power resources that need to be turned on for
11 the given device node to be in ACPI power state D0. The names
12 of the links are the same as the names of the directories they
13 point to.
diff --git a/Documentation/ABI/testing/sysfs-devices-power_resources_D1 b/Documentation/ABI/testing/sysfs-devices-power_resources_D1
new file mode 100644
index 000000000000..30c20703fb8c
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-power_resources_D1
@@ -0,0 +1,14 @@
1What: /sys/devices/.../power_resources_D1/
2Date: January 2013
3Contact: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
4Description:
5 The /sys/devices/.../power_resources_D1/ directory is only
6 present for device objects representing ACPI device nodes that
7 use ACPI power resources for power management and support ACPI
8 power state D1.
9
10 If present, it contains symbolic links to device directories
11 representing ACPI power resources that need to be turned on for
12 the given device node to be in ACPI power state D1. The names
13 of the links are the same as the names of the directories they
14 point to.
diff --git a/Documentation/ABI/testing/sysfs-devices-power_resources_D2 b/Documentation/ABI/testing/sysfs-devices-power_resources_D2
new file mode 100644
index 000000000000..fd9d84b421e1
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-power_resources_D2
@@ -0,0 +1,14 @@
1What: /sys/devices/.../power_resources_D2/
2Date: January 2013
3Contact: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
4Description:
5 The /sys/devices/.../power_resources_D2/ directory is only
6 present for device objects representing ACPI device nodes that
7 use ACPI power resources for power management and support ACPI
8 power state D2.
9
10 If present, it contains symbolic links to device directories
11 representing ACPI power resources that need to be turned on for
12 the given device node to be in ACPI power state D2. The names
13 of the links are the same as the names of the directories they
14 point to.
diff --git a/Documentation/ABI/testing/sysfs-devices-power_resources_D3hot b/Documentation/ABI/testing/sysfs-devices-power_resources_D3hot
new file mode 100644
index 000000000000..3df32c20addf
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-power_resources_D3hot
@@ -0,0 +1,14 @@
1What: /sys/devices/.../power_resources_D3hot/
2Date: January 2013
3Contact: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
4Description:
5 The /sys/devices/.../power_resources_D3hot/ directory is only
6 present for device objects representing ACPI device nodes that
7 use ACPI power resources for power management and support ACPI
8 power state D3hot.
9
10 If present, it contains symbolic links to device directories
11 representing ACPI power resources that need to be turned on for
12 the given device node to be in ACPI power state D3hot. The
13 names of the links are the same as the names of the directories
14 they point to.
diff --git a/Documentation/ABI/testing/sysfs-devices-power_state b/Documentation/ABI/testing/sysfs-devices-power_state
new file mode 100644
index 000000000000..7ad9546748f0
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-power_state
@@ -0,0 +1,20 @@
1What: /sys/devices/.../power_state
2Date: January 2013
3Contact: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
4Description:
5 The /sys/devices/.../power_state attribute is only present for
6 device objects representing ACPI device nodes that provide power
7 management methods.
8
9 If present, it contains a string representing the current ACPI
10 power state of the given device node. Its possible values,
11 "D0", "D1", "D2", "D3hot", and "D3cold", reflect the power state
12 names defined by the ACPI specification (ACPI 4 and above).
13
14 If the device node uses shared ACPI power resources, this state
15 determines a list of power resources required not to be turned
16 off. However, some power resources needed by the device node in
17 higher-power (lower-number) states may also be ON because of
18 some other devices using them at the moment.
19
20 This attribute is read-only.
diff --git a/Documentation/ABI/testing/sysfs-devices-real_power_state b/Documentation/ABI/testing/sysfs-devices-real_power_state
new file mode 100644
index 000000000000..8b3527c82a7d
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-real_power_state
@@ -0,0 +1,23 @@
1What: /sys/devices/.../real_power_state
2Date: January 2013
3Contact: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
4Description:
5 The /sys/devices/.../real_power_state attribute is only present
6 for device objects representing ACPI device nodes that provide
7 power management methods and use ACPI power resources for power
8 management.
9
10 If present, it contains a string representing the real ACPI
11 power state of the given device node as returned by the _PSC
12 control method or inferred from the configuration of power
13 resources. Its possible values, "D0", "D1", "D2", "D3hot", and
14 "D3cold", reflect the power state names defined by the ACPI
15 specification (ACPI 4 and above).
16
17 In some situations the value of this attribute may be different
18 from the value of the /sys/devices/.../power_state attribute for
19 the same device object. If that happens, some shared power
20 resources used by the device node are only ON because of some
21 other devices using them at the moment.
22
23 This attribute is read-only.
diff --git a/Documentation/ABI/testing/sysfs-devices-resource_in_use b/Documentation/ABI/testing/sysfs-devices-resource_in_use
new file mode 100644
index 000000000000..b4a3bc5922a3
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-resource_in_use
@@ -0,0 +1,12 @@
1What: /sys/devices/.../resource_in_use
2Date: January 2013
3Contact: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
4Description:
5 The /sys/devices/.../resource_in_use attribute is only present
6 for device objects representing ACPI power resources.
7
8 If present, it contains a number (0 or 1) representing the
9 current status of the given power resource (0 means that the
10 resource is not in use and therefore it has been turned off).
11
12 This attribute is read-only.
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 1f0d457ecbcf..01708a165368 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -178,276 +178,6 @@ int acpi_bus_get_private_data(acpi_handle handle, void **data)
178} 178}
179EXPORT_SYMBOL(acpi_bus_get_private_data); 179EXPORT_SYMBOL(acpi_bus_get_private_data);
180 180
181/* --------------------------------------------------------------------------
182 Power Management
183 -------------------------------------------------------------------------- */
184
185static const char *state_string(int state)
186{
187 switch (state) {
188 case ACPI_STATE_D0:
189 return "D0";
190 case ACPI_STATE_D1:
191 return "D1";
192 case ACPI_STATE_D2:
193 return "D2";
194 case ACPI_STATE_D3_HOT:
195 return "D3hot";
196 case ACPI_STATE_D3_COLD:
197 return "D3";
198 default:
199 return "(unknown)";
200 }
201}
202
203static int __acpi_bus_get_power(struct acpi_device *device, int *state)
204{
205 int result = ACPI_STATE_UNKNOWN;
206
207 if (!device || !state)
208 return -EINVAL;
209
210 if (!device->flags.power_manageable) {
211 /* TBD: Non-recursive algorithm for walking up hierarchy. */
212 *state = device->parent ?
213 device->parent->power.state : ACPI_STATE_D0;
214 goto out;
215 }
216
217 /*
218 * Get the device's power state either directly (via _PSC) or
219 * indirectly (via power resources).
220 */
221 if (device->power.flags.explicit_get) {
222 unsigned long long psc;
223 acpi_status status = acpi_evaluate_integer(device->handle,
224 "_PSC", NULL, &psc);
225 if (ACPI_FAILURE(status))
226 return -ENODEV;
227
228 result = psc;
229 }
230 /* The test below covers ACPI_STATE_UNKNOWN too. */
231 if (result <= ACPI_STATE_D2) {
232 ; /* Do nothing. */
233 } else if (device->power.flags.power_resources) {
234 int error = acpi_power_get_inferred_state(device, &result);
235 if (error)
236 return error;
237 } else if (result == ACPI_STATE_D3_HOT) {
238 result = ACPI_STATE_D3;
239 }
240
241 /*
242 * If we were unsure about the device parent's power state up to this
243 * point, the fact that the device is in D0 implies that the parent has
244 * to be in D0 too.
245 */
246 if (device->parent && device->parent->power.state == ACPI_STATE_UNKNOWN
247 && result == ACPI_STATE_D0)
248 device->parent->power.state = ACPI_STATE_D0;
249
250 *state = result;
251
252 out:
253 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is %s\n",
254 device->pnp.bus_id, state_string(*state)));
255
256 return 0;
257}
258
259
260/**
261 * acpi_device_set_power - Set power state of an ACPI device.
262 * @device: Device to set the power state of.
263 * @state: New power state to set.
264 *
265 * Callers must ensure that the device is power manageable before using this
266 * function.
267 */
268int acpi_device_set_power(struct acpi_device *device, int state)
269{
270 int result = 0;
271 acpi_status status = AE_OK;
272 char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
273
274 if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3_COLD))
275 return -EINVAL;
276
277 /* Make sure this is a valid target state */
278
279 if (state == device->power.state) {
280 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at %s\n",
281 state_string(state)));
282 return 0;
283 }
284
285 if (!device->power.states[state].flags.valid) {
286 printk(KERN_WARNING PREFIX "Device does not support %s\n",
287 state_string(state));
288 return -ENODEV;
289 }
290 if (device->parent && (state < device->parent->power.state)) {
291 printk(KERN_WARNING PREFIX
292 "Cannot set device to a higher-powered"
293 " state than parent\n");
294 return -ENODEV;
295 }
296
297 /* For D3cold we should execute _PS3, not _PS4. */
298 if (state == ACPI_STATE_D3_COLD)
299 object_name[3] = '3';
300
301 /*
302 * Transition Power
303 * ----------------
304 * On transitions to a high-powered state we first apply power (via
305 * power resources) then evalute _PSx. Conversly for transitions to
306 * a lower-powered state.
307 */
308 if (state < device->power.state) {
309 if (device->power.state >= ACPI_STATE_D3_HOT &&
310 state != ACPI_STATE_D0) {
311 printk(KERN_WARNING PREFIX
312 "Cannot transition to non-D0 state from D3\n");
313 return -ENODEV;
314 }
315 if (device->power.flags.power_resources) {
316 result = acpi_power_transition(device, state);
317 if (result)
318 goto end;
319 }
320 if (device->power.states[state].flags.explicit_set) {
321 status = acpi_evaluate_object(device->handle,
322 object_name, NULL, NULL);
323 if (ACPI_FAILURE(status)) {
324 result = -ENODEV;
325 goto end;
326 }
327 }
328 } else {
329 if (device->power.states[state].flags.explicit_set) {
330 status = acpi_evaluate_object(device->handle,
331 object_name, NULL, NULL);
332 if (ACPI_FAILURE(status)) {
333 result = -ENODEV;
334 goto end;
335 }
336 }
337 if (device->power.flags.power_resources) {
338 result = acpi_power_transition(device, state);
339 if (result)
340 goto end;
341 }
342 }
343
344 end:
345 if (result)
346 printk(KERN_WARNING PREFIX
347 "Device [%s] failed to transition to %s\n",
348 device->pnp.bus_id, state_string(state));
349 else {
350 device->power.state = state;
351 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
352 "Device [%s] transitioned to %s\n",
353 device->pnp.bus_id, state_string(state)));
354 }
355
356 return result;
357}
358EXPORT_SYMBOL(acpi_device_set_power);
359
360
361int acpi_bus_set_power(acpi_handle handle, int state)
362{
363 struct acpi_device *device;
364 int result;
365
366 result = acpi_bus_get_device(handle, &device);
367 if (result)
368 return result;
369
370 if (!device->flags.power_manageable) {
371 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
372 "Device [%s] is not power manageable\n",
373 dev_name(&device->dev)));
374 return -ENODEV;
375 }
376
377 return acpi_device_set_power(device, state);
378}
379EXPORT_SYMBOL(acpi_bus_set_power);
380
381
382int acpi_bus_init_power(struct acpi_device *device)
383{
384 int state;
385 int result;
386
387 if (!device)
388 return -EINVAL;
389
390 device->power.state = ACPI_STATE_UNKNOWN;
391
392 result = __acpi_bus_get_power(device, &state);
393 if (result)
394 return result;
395
396 if (device->power.flags.power_resources)
397 result = acpi_power_on_resources(device, state);
398
399 if (!result)
400 device->power.state = state;
401
402 return result;
403}
404
405
406int acpi_bus_update_power(acpi_handle handle, int *state_p)
407{
408 struct acpi_device *device;
409 int state;
410 int result;
411
412 result = acpi_bus_get_device(handle, &device);
413 if (result)
414 return result;
415
416 result = __acpi_bus_get_power(device, &state);
417 if (result)
418 return result;
419
420 result = acpi_device_set_power(device, state);
421 if (!result && state_p)
422 *state_p = state;
423
424 return result;
425}
426EXPORT_SYMBOL_GPL(acpi_bus_update_power);
427
428
429bool acpi_bus_power_manageable(acpi_handle handle)
430{
431 struct acpi_device *device;
432 int result;
433
434 result = acpi_bus_get_device(handle, &device);
435 return result ? false : device->flags.power_manageable;
436}
437
438EXPORT_SYMBOL(acpi_bus_power_manageable);
439
440bool acpi_bus_can_wakeup(acpi_handle handle)
441{
442 struct acpi_device *device;
443 int result;
444
445 result = acpi_bus_get_device(handle, &device);
446 return result ? false : device->wakeup.flags.valid;
447}
448
449EXPORT_SYMBOL(acpi_bus_can_wakeup);
450
451static void acpi_print_osc_error(acpi_handle handle, 181static void acpi_print_osc_error(acpi_handle handle,
452 struct acpi_osc_context *context, char *error) 182 struct acpi_osc_context *context, char *error)
453{ 183{
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 995019063f64..4cbc9505b365 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -30,6 +30,12 @@
30 30
31#include <acpi/acpi.h> 31#include <acpi/acpi.h>
32#include <acpi/acpi_bus.h> 32#include <acpi/acpi_bus.h>
33#include <acpi/acpi_drivers.h>
34
35#include "internal.h"
36
37#define _COMPONENT ACPI_POWER_COMPONENT
38ACPI_MODULE_NAME("device_pm");
33 39
34static DEFINE_MUTEX(acpi_pm_notifier_lock); 40static DEFINE_MUTEX(acpi_pm_notifier_lock);
35 41
@@ -94,6 +100,284 @@ acpi_status acpi_remove_pm_notifier(struct acpi_device *adev,
94} 100}
95 101
96/** 102/**
103 * acpi_power_state_string - String representation of ACPI device power state.
104 * @state: ACPI device power state to return the string representation of.
105 */
106const char *acpi_power_state_string(int state)
107{
108 switch (state) {
109 case ACPI_STATE_D0:
110 return "D0";
111 case ACPI_STATE_D1:
112 return "D1";
113 case ACPI_STATE_D2:
114 return "D2";
115 case ACPI_STATE_D3_HOT:
116 return "D3hot";
117 case ACPI_STATE_D3_COLD:
118 return "D3cold";
119 default:
120 return "(unknown)";
121 }
122}
123
124/**
125 * acpi_device_get_power - Get power state of an ACPI device.
126 * @device: Device to get the power state of.
127 * @state: Place to store the power state of the device.
128 *
129 * This function does not update the device's power.state field, but it may
130 * update its parent's power.state field (when the parent's power state is
131 * unknown and the device's power state turns out to be D0).
132 */
133int acpi_device_get_power(struct acpi_device *device, int *state)
134{
135 int result = ACPI_STATE_UNKNOWN;
136
137 if (!device || !state)
138 return -EINVAL;
139
140 if (!device->flags.power_manageable) {
141 /* TBD: Non-recursive algorithm for walking up hierarchy. */
142 *state = device->parent ?
143 device->parent->power.state : ACPI_STATE_D0;
144 goto out;
145 }
146
147 /*
148 * Get the device's power state either directly (via _PSC) or
149 * indirectly (via power resources).
150 */
151 if (device->power.flags.explicit_get) {
152 unsigned long long psc;
153 acpi_status status = acpi_evaluate_integer(device->handle,
154 "_PSC", NULL, &psc);
155 if (ACPI_FAILURE(status))
156 return -ENODEV;
157
158 result = psc;
159 }
160 /* The test below covers ACPI_STATE_UNKNOWN too. */
161 if (result <= ACPI_STATE_D2) {
162 ; /* Do nothing. */
163 } else if (device->power.flags.power_resources) {
164 int error = acpi_power_get_inferred_state(device, &result);
165 if (error)
166 return error;
167 } else if (result == ACPI_STATE_D3_HOT) {
168 result = ACPI_STATE_D3;
169 }
170
171 /*
172 * If we were unsure about the device parent's power state up to this
173 * point, the fact that the device is in D0 implies that the parent has
174 * to be in D0 too.
175 */
176 if (device->parent && device->parent->power.state == ACPI_STATE_UNKNOWN
177 && result == ACPI_STATE_D0)
178 device->parent->power.state = ACPI_STATE_D0;
179
180 *state = result;
181
182 out:
183 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is %s\n",
184 device->pnp.bus_id, acpi_power_state_string(*state)));
185
186 return 0;
187}
188
189static int acpi_dev_pm_explicit_set(struct acpi_device *adev, int state)
190{
191 if (adev->power.states[state].flags.explicit_set) {
192 char method[5] = { '_', 'P', 'S', '0' + state, '\0' };
193 acpi_status status;
194
195 status = acpi_evaluate_object(adev->handle, method, NULL, NULL);
196 if (ACPI_FAILURE(status))
197 return -ENODEV;
198 }
199 return 0;
200}
201
202/**
203 * acpi_device_set_power - Set power state of an ACPI device.
204 * @device: Device to set the power state of.
205 * @state: New power state to set.
206 *
207 * Callers must ensure that the device is power manageable before using this
208 * function.
209 */
210int acpi_device_set_power(struct acpi_device *device, int state)
211{
212 int result = 0;
213 bool cut_power = false;
214
215 if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3_COLD))
216 return -EINVAL;
217
218 /* Make sure this is a valid target state */
219
220 if (state == device->power.state) {
221 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at %s\n",
222 acpi_power_state_string(state)));
223 return 0;
224 }
225
226 if (!device->power.states[state].flags.valid) {
227 printk(KERN_WARNING PREFIX "Device does not support %s\n",
228 acpi_power_state_string(state));
229 return -ENODEV;
230 }
231 if (device->parent && (state < device->parent->power.state)) {
232 printk(KERN_WARNING PREFIX
233 "Cannot set device to a higher-powered"
234 " state than parent\n");
235 return -ENODEV;
236 }
237
238 /* For D3cold we should first transition into D3hot. */
239 if (state == ACPI_STATE_D3_COLD
240 && device->power.states[ACPI_STATE_D3_COLD].flags.os_accessible) {
241 state = ACPI_STATE_D3_HOT;
242 cut_power = true;
243 }
244
245 if (state < device->power.state && state != ACPI_STATE_D0
246 && device->power.state >= ACPI_STATE_D3_HOT) {
247 printk(KERN_WARNING PREFIX
248 "Cannot transition to non-D0 state from D3\n");
249 return -ENODEV;
250 }
251
252 /*
253 * Transition Power
254 * ----------------
255 * In accordance with the ACPI specification first apply power (via
256 * power resources) and then evalute _PSx.
257 */
258 if (device->power.flags.power_resources) {
259 result = acpi_power_transition(device, state);
260 if (result)
261 goto end;
262 }
263 result = acpi_dev_pm_explicit_set(device, state);
264 if (result)
265 goto end;
266
267 if (cut_power) {
268 device->power.state = state;
269 state = ACPI_STATE_D3_COLD;
270 result = acpi_power_transition(device, state);
271 }
272
273 end:
274 if (result) {
275 printk(KERN_WARNING PREFIX
276 "Device [%s] failed to transition to %s\n",
277 device->pnp.bus_id,
278 acpi_power_state_string(state));
279 } else {
280 device->power.state = state;
281 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
282 "Device [%s] transitioned to %s\n",
283 device->pnp.bus_id,
284 acpi_power_state_string(state)));
285 }
286
287 return result;
288}
289EXPORT_SYMBOL(acpi_device_set_power);
290
291int acpi_bus_set_power(acpi_handle handle, int state)
292{
293 struct acpi_device *device;
294 int result;
295
296 result = acpi_bus_get_device(handle, &device);
297 if (result)
298 return result;
299
300 if (!device->flags.power_manageable) {
301 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
302 "Device [%s] is not power manageable\n",
303 dev_name(&device->dev)));
304 return -ENODEV;
305 }
306
307 return acpi_device_set_power(device, state);
308}
309EXPORT_SYMBOL(acpi_bus_set_power);
310
311int acpi_bus_init_power(struct acpi_device *device)
312{
313 int state;
314 int result;
315
316 if (!device)
317 return -EINVAL;
318
319 device->power.state = ACPI_STATE_UNKNOWN;
320
321 result = acpi_device_get_power(device, &state);
322 if (result)
323 return result;
324
325 if (state < ACPI_STATE_D3_COLD && device->power.flags.power_resources) {
326 result = acpi_power_on_resources(device, state);
327 if (result)
328 return result;
329
330 result = acpi_dev_pm_explicit_set(device, state);
331 if (result)
332 return result;
333 }
334 device->power.state = state;
335 return 0;
336}
337
338int acpi_bus_update_power(acpi_handle handle, int *state_p)
339{
340 struct acpi_device *device;
341 int state;
342 int result;
343
344 result = acpi_bus_get_device(handle, &device);
345 if (result)
346 return result;
347
348 result = acpi_device_get_power(device, &state);
349 if (result)
350 return result;
351
352 result = acpi_device_set_power(device, state);
353 if (!result && state_p)
354 *state_p = state;
355
356 return result;
357}
358EXPORT_SYMBOL_GPL(acpi_bus_update_power);
359
360bool acpi_bus_power_manageable(acpi_handle handle)
361{
362 struct acpi_device *device;
363 int result;
364
365 result = acpi_bus_get_device(handle, &device);
366 return result ? false : device->flags.power_manageable;
367}
368EXPORT_SYMBOL(acpi_bus_power_manageable);
369
370bool acpi_bus_can_wakeup(acpi_handle handle)
371{
372 struct acpi_device *device;
373 int result;
374
375 result = acpi_bus_get_device(handle, &device);
376 return result ? false : device->wakeup.flags.valid;
377}
378EXPORT_SYMBOL(acpi_bus_can_wakeup);
379
380/**
97 * acpi_device_power_state - Get preferred power state of ACPI device. 381 * acpi_device_power_state - Get preferred power state of ACPI device.
98 * @dev: Device whose preferred target power state to return. 382 * @dev: Device whose preferred target power state to return.
99 * @adev: ACPI device node corresponding to @dev. 383 * @adev: ACPI device node corresponding to @dev.
@@ -304,7 +588,7 @@ static inline void acpi_wakeup_device(acpi_handle handle, u32 event,
304 void *context) {} 588 void *context) {}
305#endif /* CONFIG_PM_RUNTIME */ 589#endif /* CONFIG_PM_RUNTIME */
306 590
307 #ifdef CONFIG_PM_SLEEP 591#ifdef CONFIG_PM_SLEEP
308/** 592/**
309 * __acpi_device_sleep_wake - Enable or disable device to wake up the system. 593 * __acpi_device_sleep_wake - Enable or disable device to wake up the system.
310 * @dev: Device to enable/desible to wake up the system. 594 * @dev: Device to enable/desible to wake up the system.
@@ -665,3 +949,59 @@ void acpi_dev_pm_detach(struct device *dev, bool power_off)
665 } 949 }
666} 950}
667EXPORT_SYMBOL_GPL(acpi_dev_pm_detach); 951EXPORT_SYMBOL_GPL(acpi_dev_pm_detach);
952
953/**
954 * acpi_dev_pm_add_dependent - Add physical device depending for PM.
955 * @handle: Handle of ACPI device node.
956 * @depdev: Device depending on that node for PM.
957 */
958void acpi_dev_pm_add_dependent(acpi_handle handle, struct device *depdev)
959{
960 struct acpi_device_physical_node *dep;
961 struct acpi_device *adev;
962
963 if (!depdev || acpi_bus_get_device(handle, &adev))
964 return;
965
966 mutex_lock(&adev->physical_node_lock);
967
968 list_for_each_entry(dep, &adev->power_dependent, node)
969 if (dep->dev == depdev)
970 goto out;
971
972 dep = kzalloc(sizeof(*dep), GFP_KERNEL);
973 if (dep) {
974 dep->dev = depdev;
975 list_add_tail(&dep->node, &adev->power_dependent);
976 }
977
978 out:
979 mutex_unlock(&adev->physical_node_lock);
980}
981EXPORT_SYMBOL_GPL(acpi_dev_pm_add_dependent);
982
983/**
984 * acpi_dev_pm_remove_dependent - Remove physical device depending for PM.
985 * @handle: Handle of ACPI device node.
986 * @depdev: Device depending on that node for PM.
987 */
988void acpi_dev_pm_remove_dependent(acpi_handle handle, struct device *depdev)
989{
990 struct acpi_device_physical_node *dep;
991 struct acpi_device *adev;
992
993 if (!depdev || acpi_bus_get_device(handle, &adev))
994 return;
995
996 mutex_lock(&adev->physical_node_lock);
997
998 list_for_each_entry(dep, &adev->power_dependent, node)
999 if (dep->dev == depdev) {
1000 list_del(&dep->node);
1001 kfree(dep);
1002 break;
1003 }
1004
1005 mutex_unlock(&adev->physical_node_lock);
1006}
1007EXPORT_SYMBOL_GPL(acpi_dev_pm_remove_dependent);
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index e050254ae143..c5a61cd6c1a5 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -35,15 +35,33 @@ static inline void acpi_debugfs_init(void) { return; }
35#endif 35#endif
36 36
37/* -------------------------------------------------------------------------- 37/* --------------------------------------------------------------------------
38 Device Node Initialization / Removal
39 -------------------------------------------------------------------------- */
40#define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \
41 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING)
42
43int acpi_device_add(struct acpi_device *device,
44 void (*release)(struct device *));
45void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
46 int type, unsigned long long sta);
47void acpi_device_add_finalize(struct acpi_device *device);
48void acpi_free_ids(struct acpi_device *device);
49
50/* --------------------------------------------------------------------------
38 Power Resource 51 Power Resource
39 -------------------------------------------------------------------------- */ 52 -------------------------------------------------------------------------- */
40int acpi_power_init(void); 53int acpi_power_init(void);
54void acpi_power_resources_list_free(struct list_head *list);
55int acpi_extract_power_resources(union acpi_object *package, unsigned int start,
56 struct list_head *list);
57int acpi_add_power_resource(acpi_handle handle);
58void acpi_power_add_remove_device(struct acpi_device *adev, bool add);
59int acpi_power_min_system_level(struct list_head *list);
41int acpi_device_sleep_wake(struct acpi_device *dev, 60int acpi_device_sleep_wake(struct acpi_device *dev,
42 int enable, int sleep_state, int dev_state); 61 int enable, int sleep_state, int dev_state);
43int acpi_power_get_inferred_state(struct acpi_device *device, int *state); 62int acpi_power_get_inferred_state(struct acpi_device *device, int *state);
44int acpi_power_on_resources(struct acpi_device *device, int state); 63int acpi_power_on_resources(struct acpi_device *device, int state);
45int acpi_power_transition(struct acpi_device *device, int state); 64int acpi_power_transition(struct acpi_device *device, int state);
46int acpi_bus_init_power(struct acpi_device *device);
47 65
48int acpi_wakeup_device_init(void); 66int acpi_wakeup_device_init(void);
49void acpi_early_processor_set_pdc(void); 67void acpi_early_processor_set_pdc(void);
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index 6e7b9d523812..b820528a5fa3 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -41,6 +41,7 @@
41#include <linux/types.h> 41#include <linux/types.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/pm_runtime.h> 43#include <linux/pm_runtime.h>
44#include <linux/sysfs.h>
44#include <acpi/acpi_bus.h> 45#include <acpi/acpi_bus.h>
45#include <acpi/acpi_drivers.h> 46#include <acpi/acpi_drivers.h>
46#include "sleep.h" 47#include "sleep.h"
@@ -58,88 +59,121 @@ ACPI_MODULE_NAME("power");
58#define ACPI_POWER_RESOURCE_STATE_ON 0x01 59#define ACPI_POWER_RESOURCE_STATE_ON 0x01
59#define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF 60#define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF
60 61
61static int acpi_power_add(struct acpi_device *device); 62struct acpi_power_dependent_device {
62static int acpi_power_remove(struct acpi_device *device, int type); 63 struct list_head node;
63 64 struct acpi_device *adev;
64static const struct acpi_device_id power_device_ids[] = { 65 struct work_struct work;
65 {ACPI_POWER_HID, 0},
66 {"", 0},
67};
68MODULE_DEVICE_TABLE(acpi, power_device_ids);
69
70#ifdef CONFIG_PM_SLEEP
71static int acpi_power_resume(struct device *dev);
72#endif
73static SIMPLE_DEV_PM_OPS(acpi_power_pm, NULL, acpi_power_resume);
74
75static struct acpi_driver acpi_power_driver = {
76 .name = "power",
77 .class = ACPI_POWER_CLASS,
78 .ids = power_device_ids,
79 .ops = {
80 .add = acpi_power_add,
81 .remove = acpi_power_remove,
82 },
83 .drv.pm = &acpi_power_pm,
84};
85
86/*
87 * A power managed device
88 * A device may rely on multiple power resources.
89 * */
90struct acpi_power_managed_device {
91 struct device *dev; /* The physical device */
92 acpi_handle *handle;
93};
94
95struct acpi_power_resource_device {
96 struct acpi_power_managed_device *device;
97 struct acpi_power_resource_device *next;
98}; 66};
99 67
100struct acpi_power_resource { 68struct acpi_power_resource {
101 struct acpi_device * device; 69 struct acpi_device device;
102 acpi_bus_id name; 70 struct list_head list_node;
71 struct list_head dependent;
72 char *name;
103 u32 system_level; 73 u32 system_level;
104 u32 order; 74 u32 order;
105 unsigned int ref_count; 75 unsigned int ref_count;
106 struct mutex resource_lock; 76 struct mutex resource_lock;
77};
107 78
108 /* List of devices relying on this power resource */ 79struct acpi_power_resource_entry {
109 struct acpi_power_resource_device *devices; 80 struct list_head node;
110 struct mutex devices_lock; 81 struct acpi_power_resource *resource;
111}; 82};
112 83
113static struct list_head acpi_power_resource_list; 84static LIST_HEAD(acpi_power_resource_list);
85static DEFINE_MUTEX(power_resource_list_lock);
114 86
115/* -------------------------------------------------------------------------- 87/* --------------------------------------------------------------------------
116 Power Resource Management 88 Power Resource Management
117 -------------------------------------------------------------------------- */ 89 -------------------------------------------------------------------------- */
118 90
119static int 91static inline
120acpi_power_get_context(acpi_handle handle, 92struct acpi_power_resource *to_power_resource(struct acpi_device *device)
121 struct acpi_power_resource **resource)
122{ 93{
123 int result = 0; 94 return container_of(device, struct acpi_power_resource, device);
124 struct acpi_device *device = NULL; 95}
96
97static struct acpi_power_resource *acpi_power_get_context(acpi_handle handle)
98{
99 struct acpi_device *device;
125 100
101 if (acpi_bus_get_device(handle, &device))
102 return NULL;
126 103
127 if (!resource) 104 return to_power_resource(device);
128 return -ENODEV; 105}
129 106
130 result = acpi_bus_get_device(handle, &device); 107static int acpi_power_resources_list_add(acpi_handle handle,
131 if (result) { 108 struct list_head *list)
132 printk(KERN_WARNING PREFIX "Getting context [%p]\n", handle); 109{
133 return result; 110 struct acpi_power_resource *resource = acpi_power_get_context(handle);
134 } 111 struct acpi_power_resource_entry *entry;
135 112
136 *resource = acpi_driver_data(device); 113 if (!resource || !list)
137 if (!*resource) 114 return -EINVAL;
138 return -ENODEV; 115
116 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
117 if (!entry)
118 return -ENOMEM;
119
120 entry->resource = resource;
121 if (!list_empty(list)) {
122 struct acpi_power_resource_entry *e;
139 123
124 list_for_each_entry(e, list, node)
125 if (e->resource->order > resource->order) {
126 list_add_tail(&entry->node, &e->node);
127 return 0;
128 }
129 }
130 list_add_tail(&entry->node, list);
140 return 0; 131 return 0;
141} 132}
142 133
134void acpi_power_resources_list_free(struct list_head *list)
135{
136 struct acpi_power_resource_entry *entry, *e;
137
138 list_for_each_entry_safe(entry, e, list, node) {
139 list_del(&entry->node);
140 kfree(entry);
141 }
142}
143
144int acpi_extract_power_resources(union acpi_object *package, unsigned int start,
145 struct list_head *list)
146{
147 unsigned int i;
148 int err = 0;
149
150 for (i = start; i < package->package.count; i++) {
151 union acpi_object *element = &package->package.elements[i];
152 acpi_handle rhandle;
153
154 if (element->type != ACPI_TYPE_LOCAL_REFERENCE) {
155 err = -ENODATA;
156 break;
157 }
158 rhandle = element->reference.handle;
159 if (!rhandle) {
160 err = -ENODEV;
161 break;
162 }
163 err = acpi_add_power_resource(rhandle);
164 if (err)
165 break;
166
167 err = acpi_power_resources_list_add(rhandle, list);
168 if (err)
169 break;
170 }
171 if (err)
172 acpi_power_resources_list_free(list);
173
174 return err;
175}
176
143static int acpi_power_get_state(acpi_handle handle, int *state) 177static int acpi_power_get_state(acpi_handle handle, int *state)
144{ 178{
145 acpi_status status = AE_OK; 179 acpi_status status = AE_OK;
@@ -167,31 +201,23 @@ static int acpi_power_get_state(acpi_handle handle, int *state)
167 return 0; 201 return 0;
168} 202}
169 203
170static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state) 204static int acpi_power_get_list_state(struct list_head *list, int *state)
171{ 205{
206 struct acpi_power_resource_entry *entry;
172 int cur_state; 207 int cur_state;
173 int i = 0;
174 208
175 if (!list || !state) 209 if (!list || !state)
176 return -EINVAL; 210 return -EINVAL;
177 211
178 /* The state of the list is 'on' IFF all resources are 'on'. */ 212 /* The state of the list is 'on' IFF all resources are 'on'. */
179 213 list_for_each_entry(entry, list, node) {
180 for (i = 0; i < list->count; i++) { 214 struct acpi_power_resource *resource = entry->resource;
181 struct acpi_power_resource *resource; 215 acpi_handle handle = resource->device.handle;
182 acpi_handle handle = list->handles[i];
183 int result; 216 int result;
184 217
185 result = acpi_power_get_context(handle, &resource);
186 if (result)
187 return result;
188
189 mutex_lock(&resource->resource_lock); 218 mutex_lock(&resource->resource_lock);
190
191 result = acpi_power_get_state(handle, &cur_state); 219 result = acpi_power_get_state(handle, &cur_state);
192
193 mutex_unlock(&resource->resource_lock); 220 mutex_unlock(&resource->resource_lock);
194
195 if (result) 221 if (result)
196 return result; 222 return result;
197 223
@@ -203,54 +229,52 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
203 cur_state ? "on" : "off")); 229 cur_state ? "on" : "off"));
204 230
205 *state = cur_state; 231 *state = cur_state;
206
207 return 0; 232 return 0;
208} 233}
209 234
210/* Resume the device when all power resources in _PR0 are on */ 235static void acpi_power_resume_dependent(struct work_struct *work)
211static void acpi_power_on_device(struct acpi_power_managed_device *device)
212{ 236{
213 struct acpi_device *acpi_dev; 237 struct acpi_power_dependent_device *dep;
214 acpi_handle handle = device->handle; 238 struct acpi_device_physical_node *pn;
239 struct acpi_device *adev;
215 int state; 240 int state;
216 241
217 if (acpi_bus_get_device(handle, &acpi_dev)) 242 dep = container_of(work, struct acpi_power_dependent_device, work);
243 adev = dep->adev;
244 if (acpi_power_get_inferred_state(adev, &state))
218 return; 245 return;
219 246
220 if(acpi_power_get_inferred_state(acpi_dev, &state)) 247 if (state > ACPI_STATE_D0)
221 return; 248 return;
222 249
223 if (state == ACPI_STATE_D0 && pm_runtime_suspended(device->dev)) 250 mutex_lock(&adev->physical_node_lock);
224 pm_request_resume(device->dev); 251
252 list_for_each_entry(pn, &adev->physical_node_list, node)
253 pm_request_resume(pn->dev);
254
255 list_for_each_entry(pn, &adev->power_dependent, node)
256 pm_request_resume(pn->dev);
257
258 mutex_unlock(&adev->physical_node_lock);
225} 259}
226 260
227static int __acpi_power_on(struct acpi_power_resource *resource) 261static int __acpi_power_on(struct acpi_power_resource *resource)
228{ 262{
229 acpi_status status = AE_OK; 263 acpi_status status = AE_OK;
230 264
231 status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL); 265 status = acpi_evaluate_object(resource->device.handle, "_ON", NULL, NULL);
232 if (ACPI_FAILURE(status)) 266 if (ACPI_FAILURE(status))
233 return -ENODEV; 267 return -ENODEV;
234 268
235 /* Update the power resource's _device_ power state */
236 resource->device->power.state = ACPI_STATE_D0;
237
238 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Power resource [%s] turned on\n", 269 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Power resource [%s] turned on\n",
239 resource->name)); 270 resource->name));
240 271
241 return 0; 272 return 0;
242} 273}
243 274
244static int acpi_power_on(acpi_handle handle) 275static int acpi_power_on(struct acpi_power_resource *resource)
245{ 276{
246 int result = 0; 277 int result = 0;;
247 bool resume_device = false;
248 struct acpi_power_resource *resource = NULL;
249 struct acpi_power_resource_device *device_list;
250
251 result = acpi_power_get_context(handle, &resource);
252 if (result)
253 return result;
254 278
255 mutex_lock(&resource->resource_lock); 279 mutex_lock(&resource->resource_lock);
256 280
@@ -260,39 +284,38 @@ static int acpi_power_on(acpi_handle handle)
260 resource->name)); 284 resource->name));
261 } else { 285 } else {
262 result = __acpi_power_on(resource); 286 result = __acpi_power_on(resource);
263 if (result) 287 if (result) {
264 resource->ref_count--; 288 resource->ref_count--;
265 else 289 } else {
266 resume_device = true; 290 struct acpi_power_dependent_device *dep;
291
292 list_for_each_entry(dep, &resource->dependent, node)
293 schedule_work(&dep->work);
294 }
267 } 295 }
268 296
269 mutex_unlock(&resource->resource_lock); 297 mutex_unlock(&resource->resource_lock);
270 298
271 if (!resume_device) 299 return result;
272 return result; 300}
273
274 mutex_lock(&resource->devices_lock);
275 301
276 device_list = resource->devices; 302static int __acpi_power_off(struct acpi_power_resource *resource)
277 while (device_list) { 303{
278 acpi_power_on_device(device_list->device); 304 acpi_status status;
279 device_list = device_list->next;
280 }
281 305
282 mutex_unlock(&resource->devices_lock); 306 status = acpi_evaluate_object(resource->device.handle, "_OFF",
307 NULL, NULL);
308 if (ACPI_FAILURE(status))
309 return -ENODEV;
283 310
284 return result; 311 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Power resource [%s] turned off\n",
312 resource->name));
313 return 0;
285} 314}
286 315
287static int acpi_power_off(acpi_handle handle) 316static int acpi_power_off(struct acpi_power_resource *resource)
288{ 317{
289 int result = 0; 318 int result = 0;
290 acpi_status status = AE_OK;
291 struct acpi_power_resource *resource = NULL;
292
293 result = acpi_power_get_context(handle, &resource);
294 if (result)
295 return result;
296 319
297 mutex_lock(&resource->resource_lock); 320 mutex_lock(&resource->resource_lock);
298 321
@@ -307,19 +330,10 @@ static int acpi_power_off(acpi_handle handle)
307 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 330 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
308 "Power resource [%s] still in use\n", 331 "Power resource [%s] still in use\n",
309 resource->name)); 332 resource->name));
310 goto unlock;
311 }
312
313 status = acpi_evaluate_object(resource->device->handle, "_OFF", NULL, NULL);
314 if (ACPI_FAILURE(status)) {
315 result = -ENODEV;
316 } else { 333 } else {
317 /* Update the power resource's _device_ power state */ 334 result = __acpi_power_off(resource);
318 resource->device->power.state = ACPI_STATE_D3; 335 if (result)
319 336 resource->ref_count++;
320 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
321 "Power resource [%s] turned off\n",
322 resource->name));
323 } 337 }
324 338
325 unlock: 339 unlock:
@@ -328,148 +342,202 @@ static int acpi_power_off(acpi_handle handle)
328 return result; 342 return result;
329} 343}
330 344
331static void __acpi_power_off_list(struct acpi_handle_list *list, int num_res) 345static int acpi_power_off_list(struct list_head *list)
332{ 346{
333 int i; 347 struct acpi_power_resource_entry *entry;
348 int result = 0;
334 349
335 for (i = num_res - 1; i >= 0 ; i--) 350 list_for_each_entry_reverse(entry, list, node) {
336 acpi_power_off(list->handles[i]); 351 result = acpi_power_off(entry->resource);
337} 352 if (result)
353 goto err;
354 }
355 return 0;
338 356
339static void acpi_power_off_list(struct acpi_handle_list *list) 357 err:
340{ 358 list_for_each_entry_continue(entry, list, node)
341 __acpi_power_off_list(list, list->count); 359 acpi_power_on(entry->resource);
360
361 return result;
342} 362}
343 363
344static int acpi_power_on_list(struct acpi_handle_list *list) 364static int acpi_power_on_list(struct list_head *list)
345{ 365{
366 struct acpi_power_resource_entry *entry;
346 int result = 0; 367 int result = 0;
347 int i;
348 368
349 for (i = 0; i < list->count; i++) { 369 list_for_each_entry(entry, list, node) {
350 result = acpi_power_on(list->handles[i]); 370 result = acpi_power_on(entry->resource);
351 if (result) { 371 if (result)
352 __acpi_power_off_list(list, i); 372 goto err;
353 break;
354 }
355 } 373 }
374 return 0;
375
376 err:
377 list_for_each_entry_continue_reverse(entry, list, node)
378 acpi_power_off(entry->resource);
356 379
357 return result; 380 return result;
358} 381}
359 382
360static void __acpi_power_resource_unregister_device(struct device *dev, 383static void acpi_power_add_dependent(struct acpi_power_resource *resource,
361 acpi_handle res_handle) 384 struct acpi_device *adev)
362{ 385{
363 struct acpi_power_resource *resource = NULL; 386 struct acpi_power_dependent_device *dep;
364 struct acpi_power_resource_device *prev, *curr;
365 387
366 if (acpi_power_get_context(res_handle, &resource)) 388 mutex_lock(&resource->resource_lock);
367 return; 389
390 list_for_each_entry(dep, &resource->dependent, node)
391 if (dep->adev == adev)
392 goto out;
393
394 dep = kzalloc(sizeof(*dep), GFP_KERNEL);
395 if (!dep)
396 goto out;
397
398 dep->adev = adev;
399 INIT_WORK(&dep->work, acpi_power_resume_dependent);
400 list_add_tail(&dep->node, &resource->dependent);
368 401
369 mutex_lock(&resource->devices_lock); 402 out:
370 prev = NULL; 403 mutex_unlock(&resource->resource_lock);
371 curr = resource->devices; 404}
372 while (curr) { 405
373 if (curr->device->dev == dev) { 406static void acpi_power_remove_dependent(struct acpi_power_resource *resource,
374 if (!prev) 407 struct acpi_device *adev)
375 resource->devices = curr->next; 408{
376 else 409 struct acpi_power_dependent_device *dep;
377 prev->next = curr->next; 410 struct work_struct *work = NULL;
378 411
379 kfree(curr); 412 mutex_lock(&resource->resource_lock);
413
414 list_for_each_entry(dep, &resource->dependent, node)
415 if (dep->adev == adev) {
416 list_del(&dep->node);
417 work = &dep->work;
380 break; 418 break;
381 } 419 }
382 420
383 prev = curr; 421 mutex_unlock(&resource->resource_lock);
384 curr = curr->next; 422
423 if (work) {
424 cancel_work_sync(work);
425 kfree(dep);
385 } 426 }
386 mutex_unlock(&resource->devices_lock);
387} 427}
388 428
389/* Unlink dev from all power resources in _PR0 */ 429static struct attribute *attrs[] = {
390void acpi_power_resource_unregister_device(struct device *dev, acpi_handle handle) 430 NULL,
391{ 431};
392 struct acpi_device *acpi_dev;
393 struct acpi_handle_list *list;
394 int i;
395 432
396 if (!dev || !handle) 433static struct attribute_group attr_groups[] = {
397 return; 434 [ACPI_STATE_D0] = {
435 .name = "power_resources_D0",
436 .attrs = attrs,
437 },
438 [ACPI_STATE_D1] = {
439 .name = "power_resources_D1",
440 .attrs = attrs,
441 },
442 [ACPI_STATE_D2] = {
443 .name = "power_resources_D2",
444 .attrs = attrs,
445 },
446 [ACPI_STATE_D3_HOT] = {
447 .name = "power_resources_D3hot",
448 .attrs = attrs,
449 },
450};
398 451
399 if (acpi_bus_get_device(handle, &acpi_dev)) 452static void acpi_power_hide_list(struct acpi_device *adev, int state)
453{
454 struct acpi_device_power_state *ps = &adev->power.states[state];
455 struct acpi_power_resource_entry *entry;
456
457 if (list_empty(&ps->resources))
400 return; 458 return;
401 459
402 list = &acpi_dev->power.states[ACPI_STATE_D0].resources; 460 list_for_each_entry_reverse(entry, &ps->resources, node) {
461 struct acpi_device *res_dev = &entry->resource->device;
403 462
404 for (i = 0; i < list->count; i++) 463 sysfs_remove_link_from_group(&adev->dev.kobj,
405 __acpi_power_resource_unregister_device(dev, 464 attr_groups[state].name,
406 list->handles[i]); 465 dev_name(&res_dev->dev));
466 }
467 sysfs_remove_group(&adev->dev.kobj, &attr_groups[state]);
407} 468}
408EXPORT_SYMBOL_GPL(acpi_power_resource_unregister_device);
409 469
410static int __acpi_power_resource_register_device( 470static void acpi_power_expose_list(struct acpi_device *adev, int state)
411 struct acpi_power_managed_device *powered_device, acpi_handle handle)
412{ 471{
413 struct acpi_power_resource *resource = NULL; 472 struct acpi_device_power_state *ps = &adev->power.states[state];
414 struct acpi_power_resource_device *power_resource_device; 473 struct acpi_power_resource_entry *entry;
415 int result; 474 int ret;
416
417 result = acpi_power_get_context(handle, &resource);
418 if (result)
419 return result;
420 475
421 power_resource_device = kzalloc( 476 if (list_empty(&ps->resources))
422 sizeof(*power_resource_device), GFP_KERNEL); 477 return;
423 if (!power_resource_device)
424 return -ENOMEM;
425 478
426 power_resource_device->device = powered_device; 479 ret = sysfs_create_group(&adev->dev.kobj, &attr_groups[state]);
480 if (ret)
481 return;
427 482
428 mutex_lock(&resource->devices_lock); 483 list_for_each_entry(entry, &ps->resources, node) {
429 power_resource_device->next = resource->devices; 484 struct acpi_device *res_dev = &entry->resource->device;
430 resource->devices = power_resource_device;
431 mutex_unlock(&resource->devices_lock);
432 485
433 return 0; 486 ret = sysfs_add_link_to_group(&adev->dev.kobj,
487 attr_groups[state].name,
488 &res_dev->dev.kobj,
489 dev_name(&res_dev->dev));
490 if (ret) {
491 acpi_power_hide_list(adev, state);
492 break;
493 }
494 }
434} 495}
435 496
436/* Link dev to all power resources in _PR0 */ 497void acpi_power_add_remove_device(struct acpi_device *adev, bool add)
437int acpi_power_resource_register_device(struct device *dev, acpi_handle handle)
438{ 498{
439 struct acpi_device *acpi_dev; 499 struct acpi_device_power_state *ps;
440 struct acpi_handle_list *list; 500 struct acpi_power_resource_entry *entry;
441 struct acpi_power_managed_device *powered_device; 501 int state;
442 int i, ret;
443 502
444 if (!dev || !handle) 503 if (!adev->power.flags.power_resources)
445 return -ENODEV; 504 return;
446 505
447 ret = acpi_bus_get_device(handle, &acpi_dev); 506 ps = &adev->power.states[ACPI_STATE_D0];
448 if (ret || !acpi_dev->power.flags.power_resources) 507 list_for_each_entry(entry, &ps->resources, node) {
449 return -ENODEV; 508 struct acpi_power_resource *resource = entry->resource;
450 509
451 powered_device = kzalloc(sizeof(*powered_device), GFP_KERNEL); 510 if (add)
452 if (!powered_device) 511 acpi_power_add_dependent(resource, adev);
453 return -ENOMEM; 512 else
513 acpi_power_remove_dependent(resource, adev);
514 }
454 515
455 powered_device->dev = dev; 516 for (state = ACPI_STATE_D0; state <= ACPI_STATE_D3_HOT; state++) {
456 powered_device->handle = handle; 517 if (add)
518 acpi_power_expose_list(adev, state);
519 else
520 acpi_power_hide_list(adev, state);
521 }
522}
457 523
458 list = &acpi_dev->power.states[ACPI_STATE_D0].resources; 524int acpi_power_min_system_level(struct list_head *list)
525{
526 struct acpi_power_resource_entry *entry;
527 int system_level = 5;
459 528
460 for (i = 0; i < list->count; i++) { 529 list_for_each_entry(entry, list, node) {
461 ret = __acpi_power_resource_register_device(powered_device, 530 struct acpi_power_resource *resource = entry->resource;
462 list->handles[i]);
463 531
464 if (ret) { 532 if (system_level > resource->system_level)
465 acpi_power_resource_unregister_device(dev, handle); 533 system_level = resource->system_level;
466 break;
467 }
468 } 534 }
469 535 return system_level;
470 return ret;
471} 536}
472EXPORT_SYMBOL_GPL(acpi_power_resource_register_device); 537
538/* --------------------------------------------------------------------------
539 Device Power Management
540 -------------------------------------------------------------------------- */
473 541
474/** 542/**
475 * acpi_device_sleep_wake - execute _DSW (Device Sleep Wake) or (deprecated in 543 * acpi_device_sleep_wake - execute _DSW (Device Sleep Wake) or (deprecated in
@@ -542,7 +610,7 @@ int acpi_device_sleep_wake(struct acpi_device *dev,
542 */ 610 */
543int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state) 611int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
544{ 612{
545 int i, err = 0; 613 int err = 0;
546 614
547 if (!dev || !dev->wakeup.flags.valid) 615 if (!dev || !dev->wakeup.flags.valid)
548 return -EINVAL; 616 return -EINVAL;
@@ -552,24 +620,17 @@ int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
552 if (dev->wakeup.prepare_count++) 620 if (dev->wakeup.prepare_count++)
553 goto out; 621 goto out;
554 622
555 /* Open power resource */ 623 err = acpi_power_on_list(&dev->wakeup.resources);
556 for (i = 0; i < dev->wakeup.resources.count; i++) { 624 if (err) {
557 int ret = acpi_power_on(dev->wakeup.resources.handles[i]); 625 dev_err(&dev->dev, "Cannot turn wakeup power resources on\n");
558 if (ret) { 626 dev->wakeup.flags.valid = 0;
559 printk(KERN_ERR PREFIX "Transition power state\n"); 627 } else {
560 dev->wakeup.flags.valid = 0; 628 /*
561 err = -ENODEV; 629 * Passing 3 as the third argument below means the device may be
562 goto err_out; 630 * put into arbitrary power state afterward.
563 } 631 */
632 err = acpi_device_sleep_wake(dev, 1, sleep_state, 3);
564 } 633 }
565
566 /*
567 * Passing 3 as the third argument below means the device may be placed
568 * in arbitrary power state afterwards.
569 */
570 err = acpi_device_sleep_wake(dev, 1, sleep_state, 3);
571
572 err_out:
573 if (err) 634 if (err)
574 dev->wakeup.prepare_count = 0; 635 dev->wakeup.prepare_count = 0;
575 636
@@ -586,7 +647,7 @@ int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
586 */ 647 */
587int acpi_disable_wakeup_device_power(struct acpi_device *dev) 648int acpi_disable_wakeup_device_power(struct acpi_device *dev)
588{ 649{
589 int i, err = 0; 650 int err = 0;
590 651
591 if (!dev || !dev->wakeup.flags.valid) 652 if (!dev || !dev->wakeup.flags.valid)
592 return -EINVAL; 653 return -EINVAL;
@@ -607,15 +668,10 @@ int acpi_disable_wakeup_device_power(struct acpi_device *dev)
607 if (err) 668 if (err)
608 goto out; 669 goto out;
609 670
610 /* Close power resource */ 671 err = acpi_power_off_list(&dev->wakeup.resources);
611 for (i = 0; i < dev->wakeup.resources.count; i++) { 672 if (err) {
612 int ret = acpi_power_off(dev->wakeup.resources.handles[i]); 673 dev_err(&dev->dev, "Cannot turn wakeup power resources off\n");
613 if (ret) { 674 dev->wakeup.flags.valid = 0;
614 printk(KERN_ERR PREFIX "Transition power state\n");
615 dev->wakeup.flags.valid = 0;
616 err = -ENODEV;
617 goto out;
618 }
619 } 675 }
620 676
621 out: 677 out:
@@ -623,14 +679,9 @@ int acpi_disable_wakeup_device_power(struct acpi_device *dev)
623 return err; 679 return err;
624} 680}
625 681
626/* --------------------------------------------------------------------------
627 Device Power Management
628 -------------------------------------------------------------------------- */
629
630int acpi_power_get_inferred_state(struct acpi_device *device, int *state) 682int acpi_power_get_inferred_state(struct acpi_device *device, int *state)
631{ 683{
632 int result = 0; 684 int result = 0;
633 struct acpi_handle_list *list = NULL;
634 int list_state = 0; 685 int list_state = 0;
635 int i = 0; 686 int i = 0;
636 687
@@ -642,8 +693,9 @@ int acpi_power_get_inferred_state(struct acpi_device *device, int *state)
642 * required for a given D-state are 'on'. 693 * required for a given D-state are 'on'.
643 */ 694 */
644 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) { 695 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) {
645 list = &device->power.states[i].resources; 696 struct list_head *list = &device->power.states[i].resources;
646 if (list->count < 1) 697
698 if (list_empty(list))
647 continue; 699 continue;
648 700
649 result = acpi_power_get_list_state(list, &list_state); 701 result = acpi_power_get_list_state(list, &list_state);
@@ -662,7 +714,7 @@ int acpi_power_get_inferred_state(struct acpi_device *device, int *state)
662 714
663int acpi_power_on_resources(struct acpi_device *device, int state) 715int acpi_power_on_resources(struct acpi_device *device, int state)
664{ 716{
665 if (!device || state < ACPI_STATE_D0 || state > ACPI_STATE_D3) 717 if (!device || state < ACPI_STATE_D0 || state > ACPI_STATE_D3_HOT)
666 return -EINVAL; 718 return -EINVAL;
667 719
668 return acpi_power_on_list(&device->power.states[state].resources); 720 return acpi_power_on_list(&device->power.states[state].resources);
@@ -675,7 +727,7 @@ int acpi_power_transition(struct acpi_device *device, int state)
675 if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3_COLD)) 727 if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3_COLD))
676 return -EINVAL; 728 return -EINVAL;
677 729
678 if (device->power.state == state) 730 if (device->power.state == state || !device->flags.power_manageable)
679 return 0; 731 return 0;
680 732
681 if ((device->power.state < ACPI_STATE_D0) 733 if ((device->power.state < ACPI_STATE_D0)
@@ -703,118 +755,126 @@ int acpi_power_transition(struct acpi_device *device, int state)
703 return result; 755 return result;
704} 756}
705 757
706/* -------------------------------------------------------------------------- 758static void acpi_release_power_resource(struct device *dev)
707 Driver Interface 759{
708 -------------------------------------------------------------------------- */ 760 struct acpi_device *device = to_acpi_device(dev);
761 struct acpi_power_resource *resource;
762
763 resource = container_of(device, struct acpi_power_resource, device);
764
765 mutex_lock(&power_resource_list_lock);
766 list_del(&resource->list_node);
767 mutex_unlock(&power_resource_list_lock);
768
769 acpi_free_ids(device);
770 kfree(resource);
771}
709 772
710static int acpi_power_add(struct acpi_device *device) 773static ssize_t acpi_power_in_use_show(struct device *dev,
774 struct device_attribute *attr,
775 char *buf) {
776 struct acpi_power_resource *resource;
777
778 resource = to_power_resource(to_acpi_device(dev));
779 return sprintf(buf, "%u\n", !!resource->ref_count);
780}
781static DEVICE_ATTR(resource_in_use, 0444, acpi_power_in_use_show, NULL);
782
783static void acpi_power_sysfs_remove(struct acpi_device *device)
711{ 784{
712 int result = 0, state; 785 device_remove_file(&device->dev, &dev_attr_resource_in_use);
713 acpi_status status = AE_OK; 786}
714 struct acpi_power_resource *resource = NULL; 787
788int acpi_add_power_resource(acpi_handle handle)
789{
790 struct acpi_power_resource *resource;
791 struct acpi_device *device = NULL;
715 union acpi_object acpi_object; 792 union acpi_object acpi_object;
716 struct acpi_buffer buffer = { sizeof(acpi_object), &acpi_object }; 793 struct acpi_buffer buffer = { sizeof(acpi_object), &acpi_object };
794 acpi_status status;
795 int state, result = -ENODEV;
717 796
797 acpi_bus_get_device(handle, &device);
798 if (device)
799 return 0;
718 800
719 if (!device) 801 resource = kzalloc(sizeof(*resource), GFP_KERNEL);
720 return -EINVAL;
721
722 resource = kzalloc(sizeof(struct acpi_power_resource), GFP_KERNEL);
723 if (!resource) 802 if (!resource)
724 return -ENOMEM; 803 return -ENOMEM;
725 804
726 resource->device = device; 805 device = &resource->device;
806 acpi_init_device_object(device, handle, ACPI_BUS_TYPE_POWER,
807 ACPI_STA_DEFAULT);
727 mutex_init(&resource->resource_lock); 808 mutex_init(&resource->resource_lock);
728 mutex_init(&resource->devices_lock); 809 INIT_LIST_HEAD(&resource->dependent);
729 strcpy(resource->name, device->pnp.bus_id); 810 resource->name = device->pnp.bus_id;
730 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME); 811 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
731 strcpy(acpi_device_class(device), ACPI_POWER_CLASS); 812 strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
732 device->driver_data = resource; 813 device->power.state = ACPI_STATE_UNKNOWN;
733 814
734 /* Evalute the object to get the system level and resource order. */ 815 /* Evalute the object to get the system level and resource order. */
735 status = acpi_evaluate_object(device->handle, NULL, NULL, &buffer); 816 status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
736 if (ACPI_FAILURE(status)) { 817 if (ACPI_FAILURE(status))
737 result = -ENODEV; 818 goto err;
738 goto end; 819
739 }
740 resource->system_level = acpi_object.power_resource.system_level; 820 resource->system_level = acpi_object.power_resource.system_level;
741 resource->order = acpi_object.power_resource.resource_order; 821 resource->order = acpi_object.power_resource.resource_order;
742 822
743 result = acpi_power_get_state(device->handle, &state); 823 result = acpi_power_get_state(handle, &state);
744 if (result) 824 if (result)
745 goto end; 825 goto err;
746
747 switch (state) {
748 case ACPI_POWER_RESOURCE_STATE_ON:
749 device->power.state = ACPI_STATE_D0;
750 break;
751 case ACPI_POWER_RESOURCE_STATE_OFF:
752 device->power.state = ACPI_STATE_D3;
753 break;
754 default:
755 device->power.state = ACPI_STATE_UNKNOWN;
756 break;
757 }
758 826
759 printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device), 827 printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device),
760 acpi_device_bid(device), state ? "on" : "off"); 828 acpi_device_bid(device), state ? "on" : "off");
761 829
762 end: 830 device->flags.match_driver = true;
831 result = acpi_device_add(device, acpi_release_power_resource);
763 if (result) 832 if (result)
764 kfree(resource); 833 goto err;
765 834
766 return result; 835 if (!device_create_file(&device->dev, &dev_attr_resource_in_use))
767} 836 device->remove = acpi_power_sysfs_remove;
768
769static int acpi_power_remove(struct acpi_device *device, int type)
770{
771 struct acpi_power_resource *resource;
772
773 if (!device)
774 return -EINVAL;
775
776 resource = acpi_driver_data(device);
777 if (!resource)
778 return -EINVAL;
779
780 kfree(resource);
781 837
838 mutex_lock(&power_resource_list_lock);
839 list_add(&resource->list_node, &acpi_power_resource_list);
840 mutex_unlock(&power_resource_list_lock);
841 acpi_device_add_finalize(device);
782 return 0; 842 return 0;
843
844 err:
845 acpi_release_power_resource(&device->dev);
846 return result;
783} 847}
784 848
785#ifdef CONFIG_PM_SLEEP 849#ifdef CONFIG_ACPI_SLEEP
786static int acpi_power_resume(struct device *dev) 850void acpi_resume_power_resources(void)
787{ 851{
788 int result = 0, state;
789 struct acpi_device *device;
790 struct acpi_power_resource *resource; 852 struct acpi_power_resource *resource;
791 853
792 if (!dev) 854 mutex_lock(&power_resource_list_lock);
793 return -EINVAL;
794 855
795 device = to_acpi_device(dev); 856 list_for_each_entry(resource, &acpi_power_resource_list, list_node) {
796 resource = acpi_driver_data(device); 857 int result, state;
797 if (!resource)
798 return -EINVAL;
799 858
800 mutex_lock(&resource->resource_lock); 859 mutex_lock(&resource->resource_lock);
801 860
802 result = acpi_power_get_state(device->handle, &state); 861 result = acpi_power_get_state(resource->device.handle, &state);
803 if (result) 862 if (result)
804 goto unlock; 863 continue;
805 864
806 if (state == ACPI_POWER_RESOURCE_STATE_OFF && resource->ref_count) 865 if (state == ACPI_POWER_RESOURCE_STATE_OFF
807 result = __acpi_power_on(resource); 866 && resource->ref_count) {
867 dev_info(&resource->device.dev, "Turning ON\n");
868 __acpi_power_on(resource);
869 } else if (state == ACPI_POWER_RESOURCE_STATE_ON
870 && !resource->ref_count) {
871 dev_info(&resource->device.dev, "Turning OFF\n");
872 __acpi_power_off(resource);
873 }
808 874
809 unlock: 875 mutex_unlock(&resource->resource_lock);
810 mutex_unlock(&resource->resource_lock); 876 }
811 877
812 return result; 878 mutex_unlock(&power_resource_list_lock);
813} 879}
814#endif 880#endif
815
816int __init acpi_power_init(void)
817{
818 INIT_LIST_HEAD(&acpi_power_resource_list);
819 return acpi_bus_register_driver(&acpi_power_driver);
820}
diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
index ef98796b3824..52ce76725c20 100644
--- a/drivers/acpi/proc.c
+++ b/drivers/acpi/proc.c
@@ -311,11 +311,12 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
311 dev->pnp.bus_id, 311 dev->pnp.bus_id,
312 (u32) dev->wakeup.sleep_state); 312 (u32) dev->wakeup.sleep_state);
313 313
314 if (!dev->physical_node_count) 314 if (!dev->physical_node_count) {
315 seq_printf(seq, "%c%-8s\n", 315 seq_printf(seq, "%c%-8s\n",
316 dev->wakeup.flags.run_wake ? 316 dev->wakeup.flags.run_wake ? '*' : ' ',
317 '*' : ' ', "disabled"); 317 device_may_wakeup(&dev->dev) ?
318 else { 318 "enabled" : "disabled");
319 } else {
319 struct device *ldev; 320 struct device *ldev;
320 list_for_each_entry(entry, &dev->physical_node_list, 321 list_for_each_entry(entry, &dev->physical_node_list,
321 node) { 322 node) {
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 0989b323e65f..a4a2595b6d88 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -178,6 +178,32 @@ err_out:
178} 178}
179EXPORT_SYMBOL(acpi_bus_hot_remove_device); 179EXPORT_SYMBOL(acpi_bus_hot_remove_device);
180 180
181static ssize_t real_power_state_show(struct device *dev,
182 struct device_attribute *attr, char *buf)
183{
184 struct acpi_device *adev = to_acpi_device(dev);
185 int state;
186 int ret;
187
188 ret = acpi_device_get_power(adev, &state);
189 if (ret)
190 return ret;
191
192 return sprintf(buf, "%s\n", acpi_power_state_string(state));
193}
194
195static DEVICE_ATTR(real_power_state, 0444, real_power_state_show, NULL);
196
197static ssize_t power_state_show(struct device *dev,
198 struct device_attribute *attr, char *buf)
199{
200 struct acpi_device *adev = to_acpi_device(dev);
201
202 return sprintf(buf, "%s\n", acpi_power_state_string(adev->power.state));
203}
204
205static DEVICE_ATTR(power_state, 0444, power_state_show, NULL);
206
181static ssize_t 207static ssize_t
182acpi_eject_store(struct device *d, struct device_attribute *attr, 208acpi_eject_store(struct device *d, struct device_attribute *attr,
183 const char *buf, size_t count) 209 const char *buf, size_t count)
@@ -369,8 +395,22 @@ static int acpi_device_setup_files(struct acpi_device *dev)
369 * hot-removal function from userland. 395 * hot-removal function from userland.
370 */ 396 */
371 status = acpi_get_handle(dev->handle, "_EJ0", &temp); 397 status = acpi_get_handle(dev->handle, "_EJ0", &temp);
372 if (ACPI_SUCCESS(status)) 398 if (ACPI_SUCCESS(status)) {
373 result = device_create_file(&dev->dev, &dev_attr_eject); 399 result = device_create_file(&dev->dev, &dev_attr_eject);
400 if (result)
401 return result;
402 }
403
404 if (dev->flags.power_manageable) {
405 result = device_create_file(&dev->dev, &dev_attr_power_state);
406 if (result)
407 return result;
408
409 if (dev->power.flags.power_resources)
410 result = device_create_file(&dev->dev,
411 &dev_attr_real_power_state);
412 }
413
374end: 414end:
375 return result; 415 return result;
376} 416}
@@ -380,6 +420,13 @@ static void acpi_device_remove_files(struct acpi_device *dev)
380 acpi_status status; 420 acpi_status status;
381 acpi_handle temp; 421 acpi_handle temp;
382 422
423 if (dev->flags.power_manageable) {
424 device_remove_file(&dev->dev, &dev_attr_power_state);
425 if (dev->power.flags.power_resources)
426 device_remove_file(&dev->dev,
427 &dev_attr_real_power_state);
428 }
429
383 /* 430 /*
384 * If device has _STR, remove 'description' file 431 * If device has _STR, remove 'description' file
385 */ 432 */
@@ -464,7 +511,7 @@ int acpi_match_device_ids(struct acpi_device *device,
464} 511}
465EXPORT_SYMBOL(acpi_match_device_ids); 512EXPORT_SYMBOL(acpi_match_device_ids);
466 513
467static void acpi_free_ids(struct acpi_device *device) 514void acpi_free_ids(struct acpi_device *device)
468{ 515{
469 struct acpi_hardware_id *id, *tmp; 516 struct acpi_hardware_id *id, *tmp;
470 517
@@ -472,6 +519,23 @@ static void acpi_free_ids(struct acpi_device *device)
472 kfree(id->id); 519 kfree(id->id);
473 kfree(id); 520 kfree(id);
474 } 521 }
522 kfree(device->pnp.unique_id);
523}
524
525static void acpi_free_power_resources_lists(struct acpi_device *device)
526{
527 int i;
528
529 if (device->wakeup.flags.valid)
530 acpi_power_resources_list_free(&device->wakeup.resources);
531
532 if (!device->flags.power_manageable)
533 return;
534
535 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) {
536 struct acpi_device_power_state *ps = &device->power.states[i];
537 acpi_power_resources_list_free(&ps->resources);
538 }
475} 539}
476 540
477static void acpi_device_release(struct device *dev) 541static void acpi_device_release(struct device *dev)
@@ -479,7 +543,7 @@ static void acpi_device_release(struct device *dev)
479 struct acpi_device *acpi_dev = to_acpi_device(dev); 543 struct acpi_device *acpi_dev = to_acpi_device(dev);
480 544
481 acpi_free_ids(acpi_dev); 545 acpi_free_ids(acpi_dev);
482 kfree(acpi_dev->pnp.unique_id); 546 acpi_free_power_resources_lists(acpi_dev);
483 kfree(acpi_dev); 547 kfree(acpi_dev);
484} 548}
485 549
@@ -616,12 +680,25 @@ struct bus_type acpi_bus_type = {
616 .uevent = acpi_device_uevent, 680 .uevent = acpi_device_uevent,
617}; 681};
618 682
619static int acpi_device_register(struct acpi_device *device) 683int acpi_device_add(struct acpi_device *device,
684 void (*release)(struct device *))
620{ 685{
621 int result; 686 int result;
622 struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id; 687 struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
623 int found = 0; 688 int found = 0;
624 689
690 if (device->handle) {
691 acpi_status status;
692
693 status = acpi_attach_data(device->handle, acpi_bus_data_handler,
694 device);
695 if (ACPI_FAILURE(status)) {
696 acpi_handle_err(device->handle,
697 "Unable to attach device data\n");
698 return -ENODEV;
699 }
700 }
701
625 /* 702 /*
626 * Linkage 703 * Linkage
627 * ------- 704 * -------
@@ -632,11 +709,13 @@ static int acpi_device_register(struct acpi_device *device)
632 INIT_LIST_HEAD(&device->wakeup_list); 709 INIT_LIST_HEAD(&device->wakeup_list);
633 INIT_LIST_HEAD(&device->physical_node_list); 710 INIT_LIST_HEAD(&device->physical_node_list);
634 mutex_init(&device->physical_node_lock); 711 mutex_init(&device->physical_node_lock);
712 INIT_LIST_HEAD(&device->power_dependent);
635 713
636 new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL); 714 new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
637 if (!new_bus_id) { 715 if (!new_bus_id) {
638 printk(KERN_ERR PREFIX "Memory allocation error\n"); 716 pr_err(PREFIX "Memory allocation error\n");
639 return -ENOMEM; 717 result = -ENOMEM;
718 goto err_detach;
640 } 719 }
641 720
642 mutex_lock(&acpi_device_lock); 721 mutex_lock(&acpi_device_lock);
@@ -671,11 +750,11 @@ static int acpi_device_register(struct acpi_device *device)
671 if (device->parent) 750 if (device->parent)
672 device->dev.parent = &device->parent->dev; 751 device->dev.parent = &device->parent->dev;
673 device->dev.bus = &acpi_bus_type; 752 device->dev.bus = &acpi_bus_type;
674 device->dev.release = &acpi_device_release; 753 device->dev.release = release;
675 result = device_register(&device->dev); 754 result = device_add(&device->dev);
676 if (result) { 755 if (result) {
677 dev_err(&device->dev, "Error registering device\n"); 756 dev_err(&device->dev, "Error registering device\n");
678 goto end; 757 goto err;
679 } 758 }
680 759
681 result = acpi_device_setup_files(device); 760 result = acpi_device_setup_files(device);
@@ -685,12 +764,16 @@ static int acpi_device_register(struct acpi_device *device)
685 764
686 device->removal_type = ACPI_BUS_REMOVAL_NORMAL; 765 device->removal_type = ACPI_BUS_REMOVAL_NORMAL;
687 return 0; 766 return 0;
688end: 767
768 err:
689 mutex_lock(&acpi_device_lock); 769 mutex_lock(&acpi_device_lock);
690 if (device->parent) 770 if (device->parent)
691 list_del(&device->node); 771 list_del(&device->node);
692 list_del(&device->wakeup_list); 772 list_del(&device->wakeup_list);
693 mutex_unlock(&acpi_device_lock); 773 mutex_unlock(&acpi_device_lock);
774
775 err_detach:
776 acpi_detach_data(device->handle, acpi_bus_data_handler);
694 return result; 777 return result;
695} 778}
696 779
@@ -705,8 +788,18 @@ static void acpi_device_unregister(struct acpi_device *device)
705 788
706 acpi_detach_data(device->handle, acpi_bus_data_handler); 789 acpi_detach_data(device->handle, acpi_bus_data_handler);
707 790
791 acpi_power_add_remove_device(device, false);
708 acpi_device_remove_files(device); 792 acpi_device_remove_files(device);
709 device_unregister(&device->dev); 793 if (device->remove)
794 device->remove(device);
795
796 device_del(&device->dev);
797 /*
798 * Drop the reference counts of all power resources the device depends
799 * on and turn off the ones that have no more references.
800 */
801 acpi_power_transition(device, ACPI_STATE_D3_COLD);
802 put_device(&device->dev);
710} 803}
711 804
712/* -------------------------------------------------------------------------- 805/* --------------------------------------------------------------------------
@@ -849,52 +942,43 @@ void acpi_bus_data_handler(acpi_handle handle, void *context)
849 return; 942 return;
850} 943}
851 944
852static int acpi_bus_get_perf_flags(struct acpi_device *device) 945static int acpi_bus_extract_wakeup_device_power_package(acpi_handle handle,
853{ 946 struct acpi_device_wakeup *wakeup)
854 device->performance.state = ACPI_STATE_UNKNOWN;
855 return 0;
856}
857
858static acpi_status
859acpi_bus_extract_wakeup_device_power_package(acpi_handle handle,
860 struct acpi_device_wakeup *wakeup)
861{ 947{
862 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 948 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
863 union acpi_object *package = NULL; 949 union acpi_object *package = NULL;
864 union acpi_object *element = NULL; 950 union acpi_object *element = NULL;
865 acpi_status status; 951 acpi_status status;
866 int i = 0; 952 int err = -ENODATA;
867 953
868 if (!wakeup) 954 if (!wakeup)
869 return AE_BAD_PARAMETER; 955 return -EINVAL;
956
957 INIT_LIST_HEAD(&wakeup->resources);
870 958
871 /* _PRW */ 959 /* _PRW */
872 status = acpi_evaluate_object(handle, "_PRW", NULL, &buffer); 960 status = acpi_evaluate_object(handle, "_PRW", NULL, &buffer);
873 if (ACPI_FAILURE(status)) { 961 if (ACPI_FAILURE(status)) {
874 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW")); 962 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW"));
875 return status; 963 return err;
876 } 964 }
877 965
878 package = (union acpi_object *)buffer.pointer; 966 package = (union acpi_object *)buffer.pointer;
879 967
880 if (!package || (package->package.count < 2)) { 968 if (!package || package->package.count < 2)
881 status = AE_BAD_DATA;
882 goto out; 969 goto out;
883 }
884 970
885 element = &(package->package.elements[0]); 971 element = &(package->package.elements[0]);
886 if (!element) { 972 if (!element)
887 status = AE_BAD_DATA;
888 goto out; 973 goto out;
889 } 974
890 if (element->type == ACPI_TYPE_PACKAGE) { 975 if (element->type == ACPI_TYPE_PACKAGE) {
891 if ((element->package.count < 2) || 976 if ((element->package.count < 2) ||
892 (element->package.elements[0].type != 977 (element->package.elements[0].type !=
893 ACPI_TYPE_LOCAL_REFERENCE) 978 ACPI_TYPE_LOCAL_REFERENCE)
894 || (element->package.elements[1].type != ACPI_TYPE_INTEGER)) { 979 || (element->package.elements[1].type != ACPI_TYPE_INTEGER))
895 status = AE_BAD_DATA;
896 goto out; 980 goto out;
897 } 981
898 wakeup->gpe_device = 982 wakeup->gpe_device =
899 element->package.elements[0].reference.handle; 983 element->package.elements[0].reference.handle;
900 wakeup->gpe_number = 984 wakeup->gpe_number =
@@ -903,38 +987,35 @@ acpi_bus_extract_wakeup_device_power_package(acpi_handle handle,
903 wakeup->gpe_device = NULL; 987 wakeup->gpe_device = NULL;
904 wakeup->gpe_number = element->integer.value; 988 wakeup->gpe_number = element->integer.value;
905 } else { 989 } else {
906 status = AE_BAD_DATA;
907 goto out; 990 goto out;
908 } 991 }
909 992
910 element = &(package->package.elements[1]); 993 element = &(package->package.elements[1]);
911 if (element->type != ACPI_TYPE_INTEGER) { 994 if (element->type != ACPI_TYPE_INTEGER)
912 status = AE_BAD_DATA;
913 goto out; 995 goto out;
914 } 996
915 wakeup->sleep_state = element->integer.value; 997 wakeup->sleep_state = element->integer.value;
916 998
917 if ((package->package.count - 2) > ACPI_MAX_HANDLES) { 999 err = acpi_extract_power_resources(package, 2, &wakeup->resources);
918 status = AE_NO_MEMORY; 1000 if (err)
919 goto out; 1001 goto out;
920 }
921 wakeup->resources.count = package->package.count - 2;
922 for (i = 0; i < wakeup->resources.count; i++) {
923 element = &(package->package.elements[i + 2]);
924 if (element->type != ACPI_TYPE_LOCAL_REFERENCE) {
925 status = AE_BAD_DATA;
926 goto out;
927 }
928 1002
929 wakeup->resources.handles[i] = element->reference.handle; 1003 if (!list_empty(&wakeup->resources)) {
930 } 1004 int sleep_state;
931 1005
1006 sleep_state = acpi_power_min_system_level(&wakeup->resources);
1007 if (sleep_state < wakeup->sleep_state) {
1008 acpi_handle_warn(handle, "Overriding _PRW sleep state "
1009 "(S%d) by S%d from power resources\n",
1010 (int)wakeup->sleep_state, sleep_state);
1011 wakeup->sleep_state = sleep_state;
1012 }
1013 }
932 acpi_setup_gpe_for_wake(handle, wakeup->gpe_device, wakeup->gpe_number); 1014 acpi_setup_gpe_for_wake(handle, wakeup->gpe_device, wakeup->gpe_number);
933 1015
934 out: 1016 out:
935 kfree(buffer.pointer); 1017 kfree(buffer.pointer);
936 1018 return err;
937 return status;
938} 1019}
939 1020
940static void acpi_bus_set_run_wake_flags(struct acpi_device *device) 1021static void acpi_bus_set_run_wake_flags(struct acpi_device *device)
@@ -974,17 +1055,17 @@ static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
974{ 1055{
975 acpi_handle temp; 1056 acpi_handle temp;
976 acpi_status status = 0; 1057 acpi_status status = 0;
977 int psw_error; 1058 int err;
978 1059
979 /* Presence of _PRW indicates wake capable */ 1060 /* Presence of _PRW indicates wake capable */
980 status = acpi_get_handle(device->handle, "_PRW", &temp); 1061 status = acpi_get_handle(device->handle, "_PRW", &temp);
981 if (ACPI_FAILURE(status)) 1062 if (ACPI_FAILURE(status))
982 return; 1063 return;
983 1064
984 status = acpi_bus_extract_wakeup_device_power_package(device->handle, 1065 err = acpi_bus_extract_wakeup_device_power_package(device->handle,
985 &device->wakeup); 1066 &device->wakeup);
986 if (ACPI_FAILURE(status)) { 1067 if (err) {
987 ACPI_EXCEPTION((AE_INFO, status, "Extracting _PRW package")); 1068 dev_err(&device->dev, "_PRW evaluation error: %d\n", err);
988 return; 1069 return;
989 } 1070 }
990 1071
@@ -997,20 +1078,73 @@ static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
997 * So it is necessary to call _DSW object first. Only when it is not 1078 * So it is necessary to call _DSW object first. Only when it is not
998 * present will the _PSW object used. 1079 * present will the _PSW object used.
999 */ 1080 */
1000 psw_error = acpi_device_sleep_wake(device, 0, 0, 0); 1081 err = acpi_device_sleep_wake(device, 0, 0, 0);
1001 if (psw_error) 1082 if (err)
1002 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 1083 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1003 "error in _DSW or _PSW evaluation\n")); 1084 "error in _DSW or _PSW evaluation\n"));
1004} 1085}
1005 1086
1006static void acpi_bus_add_power_resource(acpi_handle handle); 1087static void acpi_bus_init_power_state(struct acpi_device *device, int state)
1088{
1089 struct acpi_device_power_state *ps = &device->power.states[state];
1090 char pathname[5] = { '_', 'P', 'R', '0' + state, '\0' };
1091 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1092 acpi_handle handle;
1093 acpi_status status;
1007 1094
1008static int acpi_bus_get_power_flags(struct acpi_device *device) 1095 INIT_LIST_HEAD(&ps->resources);
1096
1097 /* Evaluate "_PRx" to get referenced power resources */
1098 status = acpi_evaluate_object(device->handle, pathname, NULL, &buffer);
1099 if (ACPI_SUCCESS(status)) {
1100 union acpi_object *package = buffer.pointer;
1101
1102 if (buffer.length && package
1103 && package->type == ACPI_TYPE_PACKAGE
1104 && package->package.count) {
1105 int err = acpi_extract_power_resources(package, 0,
1106 &ps->resources);
1107 if (!err)
1108 device->power.flags.power_resources = 1;
1109 }
1110 ACPI_FREE(buffer.pointer);
1111 }
1112
1113 /* Evaluate "_PSx" to see if we can do explicit sets */
1114 pathname[2] = 'S';
1115 status = acpi_get_handle(device->handle, pathname, &handle);
1116 if (ACPI_SUCCESS(status))
1117 ps->flags.explicit_set = 1;
1118
1119 /*
1120 * State is valid if there are means to put the device into it.
1121 * D3hot is only valid if _PR3 present.
1122 */
1123 if (!list_empty(&ps->resources)
1124 || (ps->flags.explicit_set && state < ACPI_STATE_D3_HOT)) {
1125 ps->flags.valid = 1;
1126 ps->flags.os_accessible = 1;
1127 }
1128
1129 ps->power = -1; /* Unknown - driver assigned */
1130 ps->latency = -1; /* Unknown - driver assigned */
1131}
1132
1133static void acpi_bus_get_power_flags(struct acpi_device *device)
1009{ 1134{
1010 acpi_status status = 0; 1135 acpi_status status;
1011 acpi_handle handle = NULL; 1136 acpi_handle handle;
1012 u32 i = 0; 1137 u32 i;
1013 1138
1139 /* Presence of _PS0|_PR0 indicates 'power manageable' */
1140 status = acpi_get_handle(device->handle, "_PS0", &handle);
1141 if (ACPI_FAILURE(status)) {
1142 status = acpi_get_handle(device->handle, "_PR0", &handle);
1143 if (ACPI_FAILURE(status))
1144 return;
1145 }
1146
1147 device->flags.power_manageable = 1;
1014 1148
1015 /* 1149 /*
1016 * Power Management Flags 1150 * Power Management Flags
@@ -1025,40 +1159,10 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
1025 /* 1159 /*
1026 * Enumerate supported power management states 1160 * Enumerate supported power management states
1027 */ 1161 */
1028 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) { 1162 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++)
1029 struct acpi_device_power_state *ps = &device->power.states[i]; 1163 acpi_bus_init_power_state(device, i);
1030 char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' };
1031
1032 /* Evaluate "_PRx" to se if power resources are referenced */
1033 acpi_evaluate_reference(device->handle, object_name, NULL,
1034 &ps->resources);
1035 if (ps->resources.count) {
1036 int j;
1037 1164
1038 device->power.flags.power_resources = 1; 1165 INIT_LIST_HEAD(&device->power.states[ACPI_STATE_D3_COLD].resources);
1039 for (j = 0; j < ps->resources.count; j++)
1040 acpi_bus_add_power_resource(ps->resources.handles[j]);
1041 }
1042
1043 /* Evaluate "_PSx" to see if we can do explicit sets */
1044 object_name[2] = 'S';
1045 status = acpi_get_handle(device->handle, object_name, &handle);
1046 if (ACPI_SUCCESS(status))
1047 ps->flags.explicit_set = 1;
1048
1049 /*
1050 * State is valid if there are means to put the device into it.
1051 * D3hot is only valid if _PR3 present.
1052 */
1053 if (ps->resources.count ||
1054 (ps->flags.explicit_set && i < ACPI_STATE_D3_HOT)) {
1055 ps->flags.valid = 1;
1056 ps->flags.os_accessible = 1;
1057 }
1058
1059 ps->power = -1; /* Unknown - driver assigned */
1060 ps->latency = -1; /* Unknown - driver assigned */
1061 }
1062 1166
1063 /* Set defaults for D0 and D3 states (always valid) */ 1167 /* Set defaults for D0 and D3 states (always valid) */
1064 device->power.states[ACPI_STATE_D0].flags.valid = 1; 1168 device->power.states[ACPI_STATE_D0].flags.valid = 1;
@@ -1076,16 +1180,13 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
1076 device->power.states[ACPI_STATE_D3_COLD].flags.os_accessible = 1; 1180 device->power.states[ACPI_STATE_D3_COLD].flags.os_accessible = 1;
1077 1181
1078 acpi_bus_init_power(device); 1182 acpi_bus_init_power(device);
1079
1080 return 0;
1081} 1183}
1082 1184
1083static int acpi_bus_get_flags(struct acpi_device *device) 1185static void acpi_bus_get_flags(struct acpi_device *device)
1084{ 1186{
1085 acpi_status status = AE_OK; 1187 acpi_status status = AE_OK;
1086 acpi_handle temp = NULL; 1188 acpi_handle temp = NULL;
1087 1189
1088
1089 /* Presence of _STA indicates 'dynamic_status' */ 1190 /* Presence of _STA indicates 'dynamic_status' */
1090 status = acpi_get_handle(device->handle, "_STA", &temp); 1191 status = acpi_get_handle(device->handle, "_STA", &temp);
1091 if (ACPI_SUCCESS(status)) 1192 if (ACPI_SUCCESS(status))
@@ -1105,21 +1206,6 @@ static int acpi_bus_get_flags(struct acpi_device *device)
1105 if (ACPI_SUCCESS(status)) 1206 if (ACPI_SUCCESS(status))
1106 device->flags.ejectable = 1; 1207 device->flags.ejectable = 1;
1107 } 1208 }
1108
1109 /* Power resources cannot be power manageable. */
1110 if (device->device_type == ACPI_BUS_TYPE_POWER)
1111 return 0;
1112
1113 /* Presence of _PS0|_PR0 indicates 'power manageable' */
1114 status = acpi_get_handle(device->handle, "_PS0", &temp);
1115 if (ACPI_FAILURE(status))
1116 status = acpi_get_handle(device->handle, "_PR0", &temp);
1117 if (ACPI_SUCCESS(status))
1118 device->flags.power_manageable = 1;
1119
1120 /* TBD: Performance management */
1121
1122 return 0;
1123} 1209}
1124 1210
1125static void acpi_device_get_busid(struct acpi_device *device) 1211static void acpi_device_get_busid(struct acpi_device *device)
@@ -1344,27 +1430,25 @@ static void acpi_device_set_id(struct acpi_device *device)
1344 } 1430 }
1345} 1431}
1346 1432
1347static int acpi_device_set_context(struct acpi_device *device) 1433void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
1434 int type, unsigned long long sta)
1348{ 1435{
1349 acpi_status status; 1436 INIT_LIST_HEAD(&device->pnp.ids);
1350 1437 device->device_type = type;
1351 /* 1438 device->handle = handle;
1352 * Context 1439 device->parent = acpi_bus_get_parent(handle);
1353 * ------- 1440 STRUCT_TO_INT(device->status) = sta;
1354 * Attach this 'struct acpi_device' to the ACPI object. This makes 1441 acpi_device_get_busid(device);
1355 * resolutions from handle->device very efficient. Fixed hardware 1442 acpi_device_set_id(device);
1356 * devices have no handles, so we skip them. 1443 acpi_bus_get_flags(device);
1357 */ 1444 device_initialize(&device->dev);
1358 if (!device->handle) 1445 dev_set_uevent_suppress(&device->dev, true);
1359 return 0; 1446}
1360
1361 status = acpi_attach_data(device->handle,
1362 acpi_bus_data_handler, device);
1363 if (ACPI_SUCCESS(status))
1364 return 0;
1365 1447
1366 printk(KERN_ERR PREFIX "Error attaching device data\n"); 1448void acpi_device_add_finalize(struct acpi_device *device)
1367 return -ENODEV; 1449{
1450 dev_set_uevent_suppress(&device->dev, false);
1451 kobject_uevent(&device->dev.kobj, KOBJ_ADD);
1368} 1452}
1369 1453
1370static int acpi_add_single_object(struct acpi_device **child, 1454static int acpi_add_single_object(struct acpi_device **child,
@@ -1381,90 +1465,26 @@ static int acpi_add_single_object(struct acpi_device **child,
1381 return -ENOMEM; 1465 return -ENOMEM;
1382 } 1466 }
1383 1467
1384 INIT_LIST_HEAD(&device->pnp.ids); 1468 acpi_init_device_object(device, handle, type, sta);
1385 device->device_type = type; 1469 acpi_bus_get_power_flags(device);
1386 device->handle = handle;
1387 device->parent = acpi_bus_get_parent(handle);
1388 STRUCT_TO_INT(device->status) = sta;
1389
1390 acpi_device_get_busid(device);
1391
1392 /*
1393 * Flags
1394 * -----
1395 * Note that we only look for object handles -- cannot evaluate objects
1396 * until we know the device is present and properly initialized.
1397 */
1398 result = acpi_bus_get_flags(device);
1399 if (result)
1400 goto end;
1401
1402 /*
1403 * Initialize Device
1404 * -----------------
1405 * TBD: Synch with Core's enumeration/initialization process.
1406 */
1407 acpi_device_set_id(device);
1408
1409 /*
1410 * Power Management
1411 * ----------------
1412 */
1413 if (device->flags.power_manageable) {
1414 result = acpi_bus_get_power_flags(device);
1415 if (result)
1416 goto end;
1417 }
1418
1419 /*
1420 * Wakeup device management
1421 *-----------------------
1422 */
1423 acpi_bus_get_wakeup_device_flags(device); 1470 acpi_bus_get_wakeup_device_flags(device);
1424 1471
1425 /*
1426 * Performance Management
1427 * ----------------------
1428 */
1429 if (device->flags.performance_manageable) {
1430 result = acpi_bus_get_perf_flags(device);
1431 if (result)
1432 goto end;
1433 }
1434
1435 if ((result = acpi_device_set_context(device)))
1436 goto end;
1437
1438 device->flags.match_driver = match_driver; 1472 device->flags.match_driver = match_driver;
1439 result = acpi_device_register(device); 1473 result = acpi_device_add(device, acpi_device_release);
1440 1474 if (result) {
1441end:
1442 if (!result) {
1443 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1444 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1445 "Adding %s [%s] parent %s\n", dev_name(&device->dev),
1446 (char *) buffer.pointer,
1447 device->parent ? dev_name(&device->parent->dev) :
1448 "(null)"));
1449 kfree(buffer.pointer);
1450 *child = device;
1451 } else
1452 acpi_device_release(&device->dev); 1475 acpi_device_release(&device->dev);
1476 return result;
1477 }
1453 1478
1454 return result; 1479 acpi_power_add_remove_device(device, true);
1455} 1480 acpi_device_add_finalize(device);
1456 1481 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1457#define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \ 1482 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Added %s [%s] parent %s\n",
1458 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING) 1483 dev_name(&device->dev), (char *) buffer.pointer,
1459 1484 device->parent ? dev_name(&device->parent->dev) : "(null)"));
1460static void acpi_bus_add_power_resource(acpi_handle handle) 1485 kfree(buffer.pointer);
1461{ 1486 *child = device;
1462 struct acpi_device *device = NULL; 1487 return 0;
1463
1464 acpi_bus_get_device(handle, &device);
1465 if (!device)
1466 acpi_add_single_object(&device, handle, ACPI_BUS_TYPE_POWER,
1467 ACPI_STA_DEFAULT, true);
1468} 1488}
1469 1489
1470static int acpi_bus_type_and_status(acpi_handle handle, int *type, 1490static int acpi_bus_type_and_status(acpi_handle handle, int *type,
@@ -1523,20 +1543,26 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,
1523 if (result) 1543 if (result)
1524 return AE_OK; 1544 return AE_OK;
1525 1545
1546 if (type == ACPI_BUS_TYPE_POWER) {
1547 acpi_add_power_resource(handle);
1548 return AE_OK;
1549 }
1550
1526 if (!(sta & ACPI_STA_DEVICE_PRESENT) && 1551 if (!(sta & ACPI_STA_DEVICE_PRESENT) &&
1527 !(sta & ACPI_STA_DEVICE_FUNCTIONING)) { 1552 !(sta & ACPI_STA_DEVICE_FUNCTIONING)) {
1528 struct acpi_device_wakeup wakeup; 1553 struct acpi_device_wakeup wakeup;
1529 acpi_handle temp; 1554 acpi_handle temp;
1530 1555
1531 status = acpi_get_handle(handle, "_PRW", &temp); 1556 status = acpi_get_handle(handle, "_PRW", &temp);
1532 if (ACPI_SUCCESS(status)) 1557 if (ACPI_SUCCESS(status)) {
1533 acpi_bus_extract_wakeup_device_power_package(handle, 1558 acpi_bus_extract_wakeup_device_power_package(handle,
1534 &wakeup); 1559 &wakeup);
1560 acpi_power_resources_list_free(&wakeup.resources);
1561 }
1535 return AE_CTRL_DEPTH; 1562 return AE_CTRL_DEPTH;
1536 } 1563 }
1537 1564
1538 acpi_add_single_object(&device, handle, type, sta, 1565 acpi_add_single_object(&device, handle, type, sta, false);
1539 type == ACPI_BUS_TYPE_POWER);
1540 if (!device) 1566 if (!device)
1541 return AE_CTRL_DEPTH; 1567 return AE_CTRL_DEPTH;
1542 1568
@@ -1684,7 +1710,6 @@ int __init acpi_scan_init(void)
1684 printk(KERN_ERR PREFIX "Could not register bus type\n"); 1710 printk(KERN_ERR PREFIX "Could not register bus type\n");
1685 } 1711 }
1686 1712
1687 acpi_power_init();
1688 acpi_pci_root_init(); 1713 acpi_pci_root_init();
1689 1714
1690 /* 1715 /*
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 2fcc67d34b11..277aa825edd9 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -386,6 +386,8 @@ static void acpi_pm_finish(void)
386 386
387 acpi_target_sleep_state = ACPI_STATE_S0; 387 acpi_target_sleep_state = ACPI_STATE_S0;
388 388
389 acpi_resume_power_resources();
390
389 /* If we were woken with the fixed power button, provide a small 391 /* If we were woken with the fixed power button, provide a small
390 * hint to userspace in the form of a wakeup event on the fixed power 392 * hint to userspace in the form of a wakeup event on the fixed power
391 * button device (if it can be found). 393 * button device (if it can be found).
@@ -577,7 +579,28 @@ static const struct platform_suspend_ops acpi_suspend_ops_old = {
577 .end = acpi_pm_end, 579 .end = acpi_pm_end,
578 .recover = acpi_pm_finish, 580 .recover = acpi_pm_finish,
579}; 581};
580#endif /* CONFIG_SUSPEND */ 582
583static void acpi_sleep_suspend_setup(void)
584{
585 int i;
586
587 for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) {
588 acpi_status status;
589 u8 type_a, type_b;
590
591 status = acpi_get_sleep_type_data(i, &type_a, &type_b);
592 if (ACPI_SUCCESS(status)) {
593 sleep_states[i] = 1;
594 pr_cont(" S%d", i);
595 }
596 }
597
598 suspend_set_ops(old_suspend_ordering ?
599 &acpi_suspend_ops_old : &acpi_suspend_ops);
600}
601#else /* !CONFIG_SUSPEND */
602static inline void acpi_sleep_suspend_setup(void) {}
603#endif /* !CONFIG_SUSPEND */
581 604
582#ifdef CONFIG_HIBERNATION 605#ifdef CONFIG_HIBERNATION
583static unsigned long s4_hardware_signature; 606static unsigned long s4_hardware_signature;
@@ -698,7 +721,30 @@ static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
698 .restore_cleanup = acpi_pm_thaw, 721 .restore_cleanup = acpi_pm_thaw,
699 .recover = acpi_pm_finish, 722 .recover = acpi_pm_finish,
700}; 723};
701#endif /* CONFIG_HIBERNATION */ 724
725static void acpi_sleep_hibernate_setup(void)
726{
727 acpi_status status;
728 u8 type_a, type_b;
729
730 status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
731 if (ACPI_FAILURE(status))
732 return;
733
734 hibernation_set_ops(old_suspend_ordering ?
735 &acpi_hibernation_ops_old : &acpi_hibernation_ops);
736 sleep_states[ACPI_STATE_S4] = 1;
737 pr_cont(KERN_CONT " S4");
738 if (nosigcheck)
739 return;
740
741 acpi_get_table(ACPI_SIG_FACS, 1, (struct acpi_table_header **)&facs);
742 if (facs)
743 s4_hardware_signature = facs->hardware_signature;
744}
745#else /* !CONFIG_HIBERNATION */
746static inline void acpi_sleep_hibernate_setup(void) {}
747#endif /* !CONFIG_HIBERNATION */
702 748
703int acpi_suspend(u32 acpi_state) 749int acpi_suspend(u32 acpi_state)
704{ 750{
@@ -734,9 +780,6 @@ int __init acpi_sleep_init(void)
734{ 780{
735 acpi_status status; 781 acpi_status status;
736 u8 type_a, type_b; 782 u8 type_a, type_b;
737#ifdef CONFIG_SUSPEND
738 int i = 0;
739#endif
740 783
741 if (acpi_disabled) 784 if (acpi_disabled)
742 return 0; 785 return 0;
@@ -744,45 +787,19 @@ int __init acpi_sleep_init(void)
744 acpi_sleep_dmi_check(); 787 acpi_sleep_dmi_check();
745 788
746 sleep_states[ACPI_STATE_S0] = 1; 789 sleep_states[ACPI_STATE_S0] = 1;
747 printk(KERN_INFO PREFIX "(supports S0"); 790 pr_info(PREFIX "(supports S0");
748 791
749#ifdef CONFIG_SUSPEND 792 acpi_sleep_suspend_setup();
750 for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) { 793 acpi_sleep_hibernate_setup();
751 status = acpi_get_sleep_type_data(i, &type_a, &type_b);
752 if (ACPI_SUCCESS(status)) {
753 sleep_states[i] = 1;
754 printk(KERN_CONT " S%d", i);
755 }
756 }
757 794
758 suspend_set_ops(old_suspend_ordering ?
759 &acpi_suspend_ops_old : &acpi_suspend_ops);
760#endif
761
762#ifdef CONFIG_HIBERNATION
763 status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
764 if (ACPI_SUCCESS(status)) {
765 hibernation_set_ops(old_suspend_ordering ?
766 &acpi_hibernation_ops_old : &acpi_hibernation_ops);
767 sleep_states[ACPI_STATE_S4] = 1;
768 printk(KERN_CONT " S4");
769 if (!nosigcheck) {
770 acpi_get_table(ACPI_SIG_FACS, 1,
771 (struct acpi_table_header **)&facs);
772 if (facs)
773 s4_hardware_signature =
774 facs->hardware_signature;
775 }
776 }
777#endif
778 status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b); 795 status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
779 if (ACPI_SUCCESS(status)) { 796 if (ACPI_SUCCESS(status)) {
780 sleep_states[ACPI_STATE_S5] = 1; 797 sleep_states[ACPI_STATE_S5] = 1;
781 printk(KERN_CONT " S5"); 798 pr_cont(" S5");
782 pm_power_off_prepare = acpi_power_off_prepare; 799 pm_power_off_prepare = acpi_power_off_prepare;
783 pm_power_off = acpi_power_off; 800 pm_power_off = acpi_power_off;
784 } 801 }
785 printk(KERN_CONT ")\n"); 802 pr_cont(")\n");
786 /* 803 /*
787 * Register the tts_notifier to reboot notifier list so that the _TTS 804 * Register the tts_notifier to reboot notifier list so that the _TTS
788 * object can also be evaluated when the system enters S5. 805 * object can also be evaluated when the system enters S5.
diff --git a/drivers/acpi/sleep.h b/drivers/acpi/sleep.h
index 74d59c8f4678..0143540a2519 100644
--- a/drivers/acpi/sleep.h
+++ b/drivers/acpi/sleep.h
@@ -6,3 +6,5 @@ extern void acpi_disable_wakeup_devices(u8 sleep_state);
6 6
7extern struct list_head acpi_wakeup_device_list; 7extern struct list_head acpi_wakeup_device_list;
8extern struct mutex acpi_device_lock; 8extern struct mutex acpi_device_lock;
9
10extern void acpi_resume_power_resources(void);
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index ef01ac07502e..6fc67f7efb22 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -1029,30 +1029,20 @@ static void ata_acpi_register_power_resource(struct ata_device *dev)
1029{ 1029{
1030 struct scsi_device *sdev = dev->sdev; 1030 struct scsi_device *sdev = dev->sdev;
1031 acpi_handle handle; 1031 acpi_handle handle;
1032 struct device *device;
1033 1032
1034 handle = ata_dev_acpi_handle(dev); 1033 handle = ata_dev_acpi_handle(dev);
1035 if (!handle) 1034 if (handle)
1036 return; 1035 acpi_dev_pm_remove_dependent(handle, &sdev->sdev_gendev);
1037
1038 device = &sdev->sdev_gendev;
1039
1040 acpi_power_resource_register_device(device, handle);
1041} 1036}
1042 1037
1043static void ata_acpi_unregister_power_resource(struct ata_device *dev) 1038static void ata_acpi_unregister_power_resource(struct ata_device *dev)
1044{ 1039{
1045 struct scsi_device *sdev = dev->sdev; 1040 struct scsi_device *sdev = dev->sdev;
1046 acpi_handle handle; 1041 acpi_handle handle;
1047 struct device *device;
1048 1042
1049 handle = ata_dev_acpi_handle(dev); 1043 handle = ata_dev_acpi_handle(dev);
1050 if (!handle) 1044 if (handle)
1051 return; 1045 acpi_dev_pm_remove_dependent(handle, &sdev->sdev_gendev);
1052
1053 device = &sdev->sdev_gendev;
1054
1055 acpi_power_resource_unregister_device(device, handle);
1056} 1046}
1057 1047
1058void ata_acpi_bind(struct ata_device *dev) 1048void ata_acpi_bind(struct ata_device *dev)
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 42736e213f25..e407c61559ca 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -345,7 +345,6 @@ static void pci_acpi_setup(struct device *dev)
345 acpi_pci_irq_add_prt(handle, pci_domain_nr(pci_dev->bus), bus); 345 acpi_pci_irq_add_prt(handle, pci_domain_nr(pci_dev->bus), bus);
346 } 346 }
347 347
348 acpi_power_resource_register_device(dev, handle);
349 if (acpi_bus_get_device(handle, &adev) || !adev->wakeup.flags.valid) 348 if (acpi_bus_get_device(handle, &adev) || !adev->wakeup.flags.valid)
350 return; 349 return;
351 350
@@ -368,7 +367,6 @@ static void pci_acpi_cleanup(struct device *dev)
368 device_set_run_wake(dev, false); 367 device_set_run_wake(dev, false);
369 pci_acpi_remove_pm_notifier(adev); 368 pci_acpi_remove_pm_notifier(adev);
370 } 369 }
371 acpi_power_resource_unregister_device(dev, handle);
372 370
373 if (pci_dev->subordinate) 371 if (pci_dev->subordinate)
374 acpi_pci_irq_del_prt(pci_domain_nr(pci_dev->bus), 372 acpi_pci_irq_del_prt(pci_domain_nr(pci_dev->bus),
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 2df555c66d57..aec3d5c98c94 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -205,6 +205,48 @@ void sysfs_unmerge_group(struct kobject *kobj,
205} 205}
206EXPORT_SYMBOL_GPL(sysfs_unmerge_group); 206EXPORT_SYMBOL_GPL(sysfs_unmerge_group);
207 207
208/**
209 * sysfs_add_link_to_group - add a symlink to an attribute group.
210 * @kobj: The kobject containing the group.
211 * @group_name: The name of the group.
212 * @target: The target kobject of the symlink to create.
213 * @link_name: The name of the symlink to create.
214 */
215int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
216 struct kobject *target, const char *link_name)
217{
218 struct sysfs_dirent *dir_sd;
219 int error = 0;
220
221 dir_sd = sysfs_get_dirent(kobj->sd, NULL, group_name);
222 if (!dir_sd)
223 return -ENOENT;
224
225 error = sysfs_create_link_sd(dir_sd, target, link_name);
226 sysfs_put(dir_sd);
227
228 return error;
229}
230EXPORT_SYMBOL_GPL(sysfs_add_link_to_group);
231
232/**
233 * sysfs_remove_link_from_group - remove a symlink from an attribute group.
234 * @kobj: The kobject containing the group.
235 * @group_name: The name of the group.
236 * @link_name: The name of the symlink to remove.
237 */
238void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
239 const char *link_name)
240{
241 struct sysfs_dirent *dir_sd;
242
243 dir_sd = sysfs_get_dirent(kobj->sd, NULL, group_name);
244 if (dir_sd) {
245 sysfs_hash_and_remove(dir_sd, NULL, link_name);
246 sysfs_put(dir_sd);
247 }
248}
249EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group);
208 250
209EXPORT_SYMBOL_GPL(sysfs_create_group); 251EXPORT_SYMBOL_GPL(sysfs_create_group);
210EXPORT_SYMBOL_GPL(sysfs_update_group); 252EXPORT_SYMBOL_GPL(sysfs_update_group);
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 3c9eb5624f5e..8c940df97a52 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -21,26 +21,17 @@
21 21
22#include "sysfs.h" 22#include "sysfs.h"
23 23
24static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target, 24static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd,
25 const char *name, int warn) 25 struct kobject *target,
26 const char *name, int warn)
26{ 27{
27 struct sysfs_dirent *parent_sd = NULL;
28 struct sysfs_dirent *target_sd = NULL; 28 struct sysfs_dirent *target_sd = NULL;
29 struct sysfs_dirent *sd = NULL; 29 struct sysfs_dirent *sd = NULL;
30 struct sysfs_addrm_cxt acxt; 30 struct sysfs_addrm_cxt acxt;
31 enum kobj_ns_type ns_type; 31 enum kobj_ns_type ns_type;
32 int error; 32 int error;
33 33
34 BUG_ON(!name); 34 BUG_ON(!name || !parent_sd);
35
36 if (!kobj)
37 parent_sd = &sysfs_root;
38 else
39 parent_sd = kobj->sd;
40
41 error = -EFAULT;
42 if (!parent_sd)
43 goto out_put;
44 35
45 /* target->sd can go away beneath us but is protected with 36 /* target->sd can go away beneath us but is protected with
46 * sysfs_assoc_lock. Fetch target_sd from it. 37 * sysfs_assoc_lock. Fetch target_sd from it.
@@ -96,6 +87,34 @@ static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target,
96} 87}
97 88
98/** 89/**
90 * sysfs_create_link_sd - create symlink to a given object.
91 * @sd: directory we're creating the link in.
92 * @target: object we're pointing to.
93 * @name: name of the symlink.
94 */
95int sysfs_create_link_sd(struct sysfs_dirent *sd, struct kobject *target,
96 const char *name)
97{
98 return sysfs_do_create_link_sd(sd, target, name, 1);
99}
100
101static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target,
102 const char *name, int warn)
103{
104 struct sysfs_dirent *parent_sd = NULL;
105
106 if (!kobj)
107 parent_sd = &sysfs_root;
108 else
109 parent_sd = kobj->sd;
110
111 if (!parent_sd)
112 return -EFAULT;
113
114 return sysfs_do_create_link_sd(parent_sd, target, name, warn);
115}
116
117/**
99 * sysfs_create_link - create symlink between two objects. 118 * sysfs_create_link - create symlink between two objects.
100 * @kobj: object whose directory we're creating the link in. 119 * @kobj: object whose directory we're creating the link in.
101 * @target: object we're pointing to. 120 * @target: object we're pointing to.
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index d73c0932bbd6..d1e4043eb0c3 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -240,3 +240,5 @@ void unmap_bin_file(struct sysfs_dirent *attr_sd);
240 * symlink.c 240 * symlink.c
241 */ 241 */
242extern const struct inode_operations sysfs_symlink_inode_operations; 242extern const struct inode_operations sysfs_symlink_inode_operations;
243int sysfs_create_link_sd(struct sysfs_dirent *sd, struct kobject *target,
244 const char *name);
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 31b33d9cabcc..fc76b1f7ef06 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -197,7 +197,7 @@ struct acpi_device_power_state {
197 } flags; 197 } flags;
198 int power; /* % Power (compared to D0) */ 198 int power; /* % Power (compared to D0) */
199 int latency; /* Dx->D0 time (microseconds) */ 199 int latency; /* Dx->D0 time (microseconds) */
200 struct acpi_handle_list resources; /* Power resources referenced */ 200 struct list_head resources; /* Power resources referenced */
201}; 201};
202 202
203struct acpi_device_power { 203struct acpi_device_power {
@@ -240,7 +240,7 @@ struct acpi_device_wakeup {
240 acpi_handle gpe_device; 240 acpi_handle gpe_device;
241 u64 gpe_number; 241 u64 gpe_number;
242 u64 sleep_state; 242 u64 sleep_state;
243 struct acpi_handle_list resources; 243 struct list_head resources;
244 struct acpi_device_wakeup_flags flags; 244 struct acpi_device_wakeup_flags flags;
245 int prepare_count; 245 int prepare_count;
246}; 246};
@@ -277,6 +277,8 @@ struct acpi_device {
277 struct list_head physical_node_list; 277 struct list_head physical_node_list;
278 struct mutex physical_node_lock; 278 struct mutex physical_node_lock;
279 DECLARE_BITMAP(physical_node_id_bitmap, ACPI_MAX_PHYSICAL_NODE); 279 DECLARE_BITMAP(physical_node_id_bitmap, ACPI_MAX_PHYSICAL_NODE);
280 struct list_head power_dependent;
281 void (*remove)(struct acpi_device *);
280}; 282};
281 283
282static inline void *acpi_driver_data(struct acpi_device *d) 284static inline void *acpi_driver_data(struct acpi_device *d)
@@ -327,13 +329,51 @@ void acpi_bus_data_handler(acpi_handle handle, void *context);
327acpi_status acpi_bus_get_status_handle(acpi_handle handle, 329acpi_status acpi_bus_get_status_handle(acpi_handle handle,
328 unsigned long long *sta); 330 unsigned long long *sta);
329int acpi_bus_get_status(struct acpi_device *device); 331int acpi_bus_get_status(struct acpi_device *device);
332
333#ifdef CONFIG_PM
330int acpi_bus_set_power(acpi_handle handle, int state); 334int acpi_bus_set_power(acpi_handle handle, int state);
335const char *acpi_power_state_string(int state);
336int acpi_device_get_power(struct acpi_device *device, int *state);
331int acpi_device_set_power(struct acpi_device *device, int state); 337int acpi_device_set_power(struct acpi_device *device, int state);
338int acpi_bus_init_power(struct acpi_device *device);
332int acpi_bus_update_power(acpi_handle handle, int *state_p); 339int acpi_bus_update_power(acpi_handle handle, int *state_p);
333bool acpi_bus_power_manageable(acpi_handle handle); 340bool acpi_bus_power_manageable(acpi_handle handle);
334bool acpi_bus_can_wakeup(acpi_handle handle); 341bool acpi_bus_can_wakeup(acpi_handle handle);
335int acpi_power_resource_register_device(struct device *dev, acpi_handle handle); 342#else /* !CONFIG_PM */
336void acpi_power_resource_unregister_device(struct device *dev, acpi_handle handle); 343static inline int acpi_bus_set_power(acpi_handle handle, int state)
344{
345 return 0;
346}
347static inline const char *acpi_power_state_string(int state)
348{
349 return "D0";
350}
351static inline int acpi_device_get_power(struct acpi_device *device, int *state)
352{
353 return 0;
354}
355static inline int acpi_device_set_power(struct acpi_device *device, int state)
356{
357 return 0;
358}
359static inline int acpi_bus_init_power(struct acpi_device *device)
360{
361 return 0;
362}
363static inline int acpi_bus_update_power(acpi_handle handle, int *state_p)
364{
365 return 0;
366}
367static inline bool acpi_bus_power_manageable(acpi_handle handle)
368{
369 return false;
370}
371static inline bool acpi_bus_can_wakeup(acpi_handle handle)
372{
373 return false;
374}
375#endif /* !CONFIG_PM */
376
337#ifdef CONFIG_ACPI_PROC_EVENT 377#ifdef CONFIG_ACPI_PROC_EVENT
338int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data); 378int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data);
339int acpi_bus_generate_proc_event4(const char *class, const char *bid, u8 type, int data); 379int acpi_bus_generate_proc_event4(const char *class, const char *bid, u8 type, int data);
@@ -412,6 +452,8 @@ acpi_status acpi_remove_pm_notifier(struct acpi_device *adev,
412int acpi_device_power_state(struct device *dev, struct acpi_device *adev, 452int acpi_device_power_state(struct device *dev, struct acpi_device *adev,
413 u32 target_state, int d_max_in, int *d_min_p); 453 u32 target_state, int d_max_in, int *d_min_p);
414int acpi_pm_device_sleep_state(struct device *, int *, int); 454int acpi_pm_device_sleep_state(struct device *, int *, int);
455void acpi_dev_pm_add_dependent(acpi_handle handle, struct device *depdev);
456void acpi_dev_pm_remove_dependent(acpi_handle handle, struct device *depdev);
415#else 457#else
416static inline acpi_status acpi_add_pm_notifier(struct acpi_device *adev, 458static inline acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
417 acpi_notify_handler handler, 459 acpi_notify_handler handler,
@@ -441,6 +483,10 @@ static inline int acpi_pm_device_sleep_state(struct device *d, int *p, int m)
441{ 483{
442 return __acpi_device_power_state(m, p); 484 return __acpi_device_power_state(m, p);
443} 485}
486static inline void acpi_dev_pm_add_dependent(acpi_handle handle,
487 struct device *depdev) {}
488static inline void acpi_dev_pm_remove_dependent(acpi_handle handle,
489 struct device *depdev) {}
444#endif 490#endif
445 491
446#ifdef CONFIG_PM_RUNTIME 492#ifdef CONFIG_PM_RUNTIME
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 8c1d6f2a2193..5f2be833aaf8 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -511,7 +511,7 @@ static inline int acpi_subsys_runtime_suspend(struct device *dev) { return 0; }
511static inline int acpi_subsys_runtime_resume(struct device *dev) { return 0; } 511static inline int acpi_subsys_runtime_resume(struct device *dev) { return 0; }
512#endif 512#endif
513 513
514#ifdef CONFIG_ACPI_SLEEP 514#if defined(CONFIG_ACPI) && defined(CONFIG_PM_SLEEP)
515int acpi_dev_suspend_late(struct device *dev); 515int acpi_dev_suspend_late(struct device *dev);
516int acpi_dev_resume_early(struct device *dev); 516int acpi_dev_resume_early(struct device *dev);
517int acpi_subsys_prepare(struct device *dev); 517int acpi_subsys_prepare(struct device *dev);
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 381f06db2fe5..e2cee22f578a 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -181,6 +181,10 @@ int sysfs_merge_group(struct kobject *kobj,
181 const struct attribute_group *grp); 181 const struct attribute_group *grp);
182void sysfs_unmerge_group(struct kobject *kobj, 182void sysfs_unmerge_group(struct kobject *kobj,
183 const struct attribute_group *grp); 183 const struct attribute_group *grp);
184int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
185 struct kobject *target, const char *link_name);
186void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
187 const char *link_name);
184 188
185void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr); 189void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
186void sysfs_notify_dirent(struct sysfs_dirent *sd); 190void sysfs_notify_dirent(struct sysfs_dirent *sd);
@@ -326,6 +330,18 @@ static inline void sysfs_unmerge_group(struct kobject *kobj,
326{ 330{
327} 331}
328 332
333static inline int sysfs_add_link_to_group(struct kobject *kobj,
334 const char *group_name, struct kobject *target,
335 const char *link_name)
336{
337 return 0;
338}
339
340static inline void sysfs_remove_link_from_group(struct kobject *kobj,
341 const char *group_name, const char *link_name)
342{
343}
344
329static inline void sysfs_notify(struct kobject *kobj, const char *dir, 345static inline void sysfs_notify(struct kobject *kobj, const char *dir,
330 const char *attr) 346 const char *attr)
331{ 347{