blob: e80df06ad22ab1aaa7d86a76434a4a5b9a2aadf8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * pm.h - Power management interface
3 *
4 * Copyright (C) 2000 Andrew Henroid
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef _LINUX_PM_H
22#define _LINUX_PM_H
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/list.h>
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020025#include <linux/workqueue.h>
26#include <linux/spinlock.h>
27#include <linux/wait.h>
28#include <linux/timer.h>
Rafael J. Wysocki5af84b82010-01-23 22:23:32 +010029#include <linux/completion.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 * Callbacks for platform drivers to implement.
33 */
34extern void (*pm_idle)(void);
35extern void (*pm_power_off)(void);
Rafael J. Wysockibd804eb2007-07-19 01:47:40 -070036extern void (*pm_power_off_prepare)(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/*
39 * Device power management
40 */
41
42struct device;
43
Pavel Machekca078ba2005-09-03 15:56:57 -070044typedef struct pm_message {
45 int event;
46} pm_message_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Rafael J. Wysocki1eede072008-05-20 23:00:01 +020048/**
Rafael J. Wysockiadf09492008-10-06 22:46:05 +020049 * struct dev_pm_ops - device PM callbacks
Rafael J. Wysocki1eede072008-05-20 23:00:01 +020050 *
David Brownell82bb67f2006-08-14 23:11:04 -070051 * Several driver power state transitions are externally visible, affecting
52 * the state of pending I/O queues and (for drivers that touch hardware)
53 * interrupts, wakeups, DMA, and other hardware state. There may also be
54 * internal transitions to various low power modes, which are transparent
55 * to the rest of the driver stack (such as a driver that's ON gating off
56 * clocks which are not in active use).
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 *
Rafael J. Wysocki1eede072008-05-20 23:00:01 +020058 * The externally visible transitions are handled with the help of the following
59 * callbacks included in this structure:
60 *
61 * @prepare: Prepare the device for the upcoming transition, but do NOT change
62 * its hardware state. Prevent new children of the device from being
63 * registered after @prepare() returns (the driver's subsystem and
64 * generally the rest of the kernel is supposed to prevent new calls to the
65 * probe method from being made too once @prepare() has succeeded). If
66 * @prepare() detects a situation it cannot handle (e.g. registration of a
67 * child already in progress), it may return -EAGAIN, so that the PM core
68 * can execute it once again (e.g. after the new child has been registered)
69 * to recover from the race condition. This method is executed for all
70 * kinds of suspend transitions and is followed by one of the suspend
71 * callbacks: @suspend(), @freeze(), or @poweroff().
72 * The PM core executes @prepare() for all devices before starting to
73 * execute suspend callbacks for any of them, so drivers may assume all of
74 * the other devices to be present and functional while @prepare() is being
75 * executed. In particular, it is safe to make GFP_KERNEL memory
76 * allocations from within @prepare(). However, drivers may NOT assume
77 * anything about the availability of the user space at that time and it
78 * is not correct to request firmware from within @prepare() (it's too
79 * late to do that). [To work around this limitation, drivers may
80 * register suspend and hibernation notifiers that are executed before the
81 * freezing of tasks.]
82 *
83 * @complete: Undo the changes made by @prepare(). This method is executed for
84 * all kinds of resume transitions, following one of the resume callbacks:
85 * @resume(), @thaw(), @restore(). Also called if the state transition
86 * fails before the driver's suspend callback (@suspend(), @freeze(),
87 * @poweroff()) can be executed (e.g. if the suspend callback fails for one
88 * of the other devices that the PM core has unsuccessfully attempted to
89 * suspend earlier).
90 * The PM core executes @complete() after it has executed the appropriate
91 * resume callback for all devices.
92 *
93 * @suspend: Executed before putting the system into a sleep state in which the
94 * contents of main memory are preserved. Quiesce the device, put it into
95 * a low power state appropriate for the upcoming system state (such as
96 * PCI_D3hot), and enable wakeup events as appropriate.
97 *
98 * @resume: Executed after waking the system up from a sleep state in which the
99 * contents of main memory were preserved. Put the device into the
100 * appropriate state, according to the information saved in memory by the
101 * preceding @suspend(). The driver starts working again, responding to
102 * hardware events and software requests. The hardware may have gone
103 * through a power-off reset, or it may have maintained state from the
104 * previous suspend() which the driver may rely on while resuming. On most
105 * platforms, there are no restrictions on availability of resources like
106 * clocks during @resume().
107 *
108 * @freeze: Hibernation-specific, executed before creating a hibernation image.
109 * Quiesce operations so that a consistent image can be created, but do NOT
110 * otherwise put the device into a low power device state and do NOT emit
111 * system wakeup events. Save in main memory the device settings to be
112 * used by @restore() during the subsequent resume from hibernation or by
113 * the subsequent @thaw(), if the creation of the image or the restoration
114 * of main memory contents from it fails.
115 *
116 * @thaw: Hibernation-specific, executed after creating a hibernation image OR
117 * if the creation of the image fails. Also executed after a failing
118 * attempt to restore the contents of main memory from such an image.
119 * Undo the changes made by the preceding @freeze(), so the device can be
120 * operated in the same way as immediately before the call to @freeze().
121 *
122 * @poweroff: Hibernation-specific, executed after saving a hibernation image.
123 * Quiesce the device, put it into a low power state appropriate for the
124 * upcoming system state (such as PCI_D3hot), and enable wakeup events as
125 * appropriate.
126 *
127 * @restore: Hibernation-specific, executed after restoring the contents of main
128 * memory from a hibernation image. Driver starts working again,
129 * responding to hardware events and software requests. Drivers may NOT
130 * make ANY assumptions about the hardware state right prior to @restore().
131 * On most platforms, there are no restrictions on availability of
132 * resources like clocks during @restore().
133 *
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200134 * @suspend_noirq: Complete the operations of ->suspend() by carrying out any
135 * actions required for suspending the device that need interrupts to be
136 * disabled
137 *
138 * @resume_noirq: Prepare for the execution of ->resume() by carrying out any
139 * actions required for resuming the device that need interrupts to be
140 * disabled
141 *
142 * @freeze_noirq: Complete the operations of ->freeze() by carrying out any
143 * actions required for freezing the device that need interrupts to be
144 * disabled
145 *
146 * @thaw_noirq: Prepare for the execution of ->thaw() by carrying out any
147 * actions required for thawing the device that need interrupts to be
148 * disabled
149 *
150 * @poweroff_noirq: Complete the operations of ->poweroff() by carrying out any
151 * actions required for handling the device that need interrupts to be
152 * disabled
153 *
154 * @restore_noirq: Prepare for the execution of ->restore() by carrying out any
155 * actions required for restoring the operations of the device that need
156 * interrupts to be disabled
157 *
Rafael J. Wysockiadf09492008-10-06 22:46:05 +0200158 * All of the above callbacks, except for @complete(), return error codes.
159 * However, the error codes returned by the resume operations, @resume(),
160 * @thaw(), @restore(), @resume_noirq(), @thaw_noirq(), and @restore_noirq() do
161 * not cause the PM core to abort the resume transition during which they are
162 * returned. The error codes returned in that cases are only printed by the PM
163 * core to the system logs for debugging purposes. Still, it is recommended
164 * that drivers only return error codes from their resume methods in case of an
165 * unrecoverable failure (i.e. when the device being handled refuses to resume
166 * and becomes unusable) to allow us to modify the PM core in the future, so
167 * that it can avoid attempting to handle devices that failed to resume and
168 * their children.
169 *
170 * It is allowed to unregister devices while the above callbacks are being
171 * executed. However, it is not allowed to unregister a device from within any
172 * of its own callbacks.
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200173 *
174 * There also are the following callbacks related to run-time power management
175 * of devices:
176 *
177 * @runtime_suspend: Prepare the device for a condition in which it won't be
178 * able to communicate with the CPU(s) and RAM due to power management.
179 * This need not mean that the device should be put into a low power state.
180 * For example, if the device is behind a link which is about to be turned
181 * off, the device may remain at full power. If the device does go to low
Rafael J. Wysocki7a1a8eb2009-12-03 21:19:18 +0100182 * power and is capable of generating run-time wake-up events, remote
183 * wake-up (i.e., a hardware mechanism allowing the device to request a
184 * change of its power state via a wake-up event, such as PCI PME) should
185 * be enabled for it.
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200186 *
187 * @runtime_resume: Put the device into the fully active state in response to a
188 * wake-up event generated by hardware or at the request of software. If
189 * necessary, put the device into the full power state and restore its
190 * registers, so that it is fully operational.
191 *
192 * @runtime_idle: Device appears to be inactive and it might be put into a low
193 * power state if all of the necessary conditions are satisfied. Check
194 * these conditions and handle the device as appropriate, possibly queueing
195 * a suspend request for it. The return value is ignored by the PM core.
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200196 */
197
Rafael J. Wysockiadf09492008-10-06 22:46:05 +0200198struct dev_pm_ops {
199 int (*prepare)(struct device *dev);
200 void (*complete)(struct device *dev);
201 int (*suspend)(struct device *dev);
202 int (*resume)(struct device *dev);
203 int (*freeze)(struct device *dev);
204 int (*thaw)(struct device *dev);
205 int (*poweroff)(struct device *dev);
206 int (*restore)(struct device *dev);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200207 int (*suspend_noirq)(struct device *dev);
208 int (*resume_noirq)(struct device *dev);
209 int (*freeze_noirq)(struct device *dev);
210 int (*thaw_noirq)(struct device *dev);
211 int (*poweroff_noirq)(struct device *dev);
212 int (*restore_noirq)(struct device *dev);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200213 int (*runtime_suspend)(struct device *dev);
214 int (*runtime_resume)(struct device *dev);
215 int (*runtime_idle)(struct device *dev);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200216};
217
Albin Tonnerre9d62ec62009-08-05 23:59:59 +0200218/*
219 * Use this if you want to use the same suspend and resume callbacks for suspend
220 * to RAM and hibernation.
221 */
222#define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
Alexey Dobriyan47145212009-12-14 18:00:08 -0800223const struct dev_pm_ops name = { \
Albin Tonnerre9d62ec62009-08-05 23:59:59 +0200224 .suspend = suspend_fn, \
225 .resume = resume_fn, \
226 .freeze = suspend_fn, \
227 .thaw = resume_fn, \
228 .poweroff = suspend_fn, \
229 .restore = resume_fn, \
230}
231
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200232/**
233 * PM_EVENT_ messages
234 *
235 * The following PM_EVENT_ messages are defined for the internal use of the PM
236 * core, in order to provide a mechanism allowing the high level suspend and
237 * hibernation code to convey the necessary information to the device PM core
238 * code:
239 *
240 * ON No transition.
241 *
242 * FREEZE System is going to hibernate, call ->prepare() and ->freeze()
243 * for all devices.
244 *
245 * SUSPEND System is going to suspend, call ->prepare() and ->suspend()
246 * for all devices.
247 *
248 * HIBERNATE Hibernation image has been saved, call ->prepare() and
249 * ->poweroff() for all devices.
250 *
251 * QUIESCE Contents of main memory are going to be restored from a (loaded)
252 * hibernation image, call ->prepare() and ->freeze() for all
253 * devices.
254 *
255 * RESUME System is resuming, call ->resume() and ->complete() for all
256 * devices.
257 *
258 * THAW Hibernation image has been created, call ->thaw() and
259 * ->complete() for all devices.
260 *
261 * RESTORE Contents of main memory have been restored from a hibernation
262 * image, call ->restore() and ->complete() for all devices.
263 *
264 * RECOVER Creation of a hibernation image or restoration of the main
265 * memory contents from a hibernation image has failed, call
266 * ->thaw() and ->complete() for all devices.
Alan Stern8111d1b2008-07-23 21:28:37 -0700267 *
268 * The following PM_EVENT_ messages are defined for internal use by
269 * kernel subsystems. They are never issued by the PM core.
270 *
271 * USER_SUSPEND Manual selective suspend was issued by userspace.
272 *
273 * USER_RESUME Manual selective resume was issued by userspace.
274 *
275 * REMOTE_WAKEUP Remote-wakeup request was received from the device.
276 *
277 * AUTO_SUSPEND Automatic (device idle) runtime suspend was
278 * initiated by the subsystem.
279 *
280 * AUTO_RESUME Automatic (device needed) runtime resume was
281 * requested by a driver.
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200282 */
283
284#define PM_EVENT_ON 0x0000
285#define PM_EVENT_FREEZE 0x0001
286#define PM_EVENT_SUSPEND 0x0002
287#define PM_EVENT_HIBERNATE 0x0004
288#define PM_EVENT_QUIESCE 0x0008
289#define PM_EVENT_RESUME 0x0010
290#define PM_EVENT_THAW 0x0020
291#define PM_EVENT_RESTORE 0x0040
292#define PM_EVENT_RECOVER 0x0080
Alan Stern8111d1b2008-07-23 21:28:37 -0700293#define PM_EVENT_USER 0x0100
294#define PM_EVENT_REMOTE 0x0200
295#define PM_EVENT_AUTO 0x0400
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200296
Alan Stern8111d1b2008-07-23 21:28:37 -0700297#define PM_EVENT_SLEEP (PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
298#define PM_EVENT_USER_SUSPEND (PM_EVENT_USER | PM_EVENT_SUSPEND)
299#define PM_EVENT_USER_RESUME (PM_EVENT_USER | PM_EVENT_RESUME)
Alan Stern7f4f5d42008-11-17 11:14:19 -0500300#define PM_EVENT_REMOTE_RESUME (PM_EVENT_REMOTE | PM_EVENT_RESUME)
Alan Stern8111d1b2008-07-23 21:28:37 -0700301#define PM_EVENT_AUTO_SUSPEND (PM_EVENT_AUTO | PM_EVENT_SUSPEND)
302#define PM_EVENT_AUTO_RESUME (PM_EVENT_AUTO | PM_EVENT_RESUME)
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200303
Alan Stern8111d1b2008-07-23 21:28:37 -0700304#define PMSG_ON ((struct pm_message){ .event = PM_EVENT_ON, })
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200305#define PMSG_FREEZE ((struct pm_message){ .event = PM_EVENT_FREEZE, })
306#define PMSG_QUIESCE ((struct pm_message){ .event = PM_EVENT_QUIESCE, })
307#define PMSG_SUSPEND ((struct pm_message){ .event = PM_EVENT_SUSPEND, })
308#define PMSG_HIBERNATE ((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
309#define PMSG_RESUME ((struct pm_message){ .event = PM_EVENT_RESUME, })
310#define PMSG_THAW ((struct pm_message){ .event = PM_EVENT_THAW, })
311#define PMSG_RESTORE ((struct pm_message){ .event = PM_EVENT_RESTORE, })
312#define PMSG_RECOVER ((struct pm_message){ .event = PM_EVENT_RECOVER, })
Alan Stern7f4f5d42008-11-17 11:14:19 -0500313#define PMSG_USER_SUSPEND ((struct pm_message) \
Alan Stern8111d1b2008-07-23 21:28:37 -0700314 { .event = PM_EVENT_USER_SUSPEND, })
Alan Stern7f4f5d42008-11-17 11:14:19 -0500315#define PMSG_USER_RESUME ((struct pm_message) \
Alan Stern8111d1b2008-07-23 21:28:37 -0700316 { .event = PM_EVENT_USER_RESUME, })
Alan Stern7f4f5d42008-11-17 11:14:19 -0500317#define PMSG_REMOTE_RESUME ((struct pm_message) \
Alan Stern8111d1b2008-07-23 21:28:37 -0700318 { .event = PM_EVENT_REMOTE_RESUME, })
Alan Stern7f4f5d42008-11-17 11:14:19 -0500319#define PMSG_AUTO_SUSPEND ((struct pm_message) \
Alan Stern8111d1b2008-07-23 21:28:37 -0700320 { .event = PM_EVENT_AUTO_SUSPEND, })
Alan Stern7f4f5d42008-11-17 11:14:19 -0500321#define PMSG_AUTO_RESUME ((struct pm_message) \
Alan Stern8111d1b2008-07-23 21:28:37 -0700322 { .event = PM_EVENT_AUTO_RESUME, })
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200323
324/**
325 * Device power management states
326 *
327 * These state labels are used internally by the PM core to indicate the current
328 * status of a device with respect to the PM core operations.
329 *
330 * DPM_ON Device is regarded as operational. Set this way
331 * initially and when ->complete() is about to be called.
332 * Also set when ->prepare() fails.
333 *
334 * DPM_PREPARING Device is going to be prepared for a PM transition. Set
335 * when ->prepare() is about to be called.
336 *
337 * DPM_RESUMING Device is going to be resumed. Set when ->resume(),
338 * ->thaw(), or ->restore() is about to be called.
339 *
340 * DPM_SUSPENDING Device has been prepared for a power transition. Set
341 * when ->prepare() has just succeeded.
342 *
343 * DPM_OFF Device is regarded as inactive. Set immediately after
344 * ->suspend(), ->freeze(), or ->poweroff() has succeeded.
345 * Also set when ->resume()_noirq, ->thaw_noirq(), or
346 * ->restore_noirq() is about to be called.
347 *
348 * DPM_OFF_IRQ Device is in a "deep sleep". Set immediately after
349 * ->suspend_noirq(), ->freeze_noirq(), or
350 * ->poweroff_noirq() has just succeeded.
351 */
352
353enum dpm_state {
354 DPM_INVALID,
355 DPM_ON,
356 DPM_PREPARING,
357 DPM_RESUMING,
358 DPM_SUSPENDING,
359 DPM_OFF,
360 DPM_OFF_IRQ,
361};
362
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200363/**
364 * Device run-time power management status.
365 *
366 * These status labels are used internally by the PM core to indicate the
367 * current status of a device with respect to the PM core operations. They do
368 * not reflect the actual power state of the device or its status as seen by the
369 * driver.
370 *
371 * RPM_ACTIVE Device is fully operational. Indicates that the device
372 * bus type's ->runtime_resume() callback has completed
373 * successfully.
374 *
375 * RPM_SUSPENDED Device bus type's ->runtime_suspend() callback has
376 * completed successfully. The device is regarded as
377 * suspended.
378 *
379 * RPM_RESUMING Device bus type's ->runtime_resume() callback is being
380 * executed.
381 *
382 * RPM_SUSPENDING Device bus type's ->runtime_suspend() callback is being
383 * executed.
384 */
385
386enum rpm_status {
387 RPM_ACTIVE = 0,
388 RPM_RESUMING,
389 RPM_SUSPENDED,
390 RPM_SUSPENDING,
391};
392
393/**
394 * Device run-time power management request types.
395 *
396 * RPM_REQ_NONE Do nothing.
397 *
398 * RPM_REQ_IDLE Run the device bus type's ->runtime_idle() callback
399 *
400 * RPM_REQ_SUSPEND Run the device bus type's ->runtime_suspend() callback
401 *
402 * RPM_REQ_RESUME Run the device bus type's ->runtime_resume() callback
403 */
404
405enum rpm_request {
406 RPM_REQ_NONE = 0,
407 RPM_REQ_IDLE,
408 RPM_REQ_SUSPEND,
409 RPM_REQ_RESUME,
410};
411
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200412struct dev_pm_info {
413 pm_message_t power_state;
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200414 unsigned int can_wakeup:1;
415 unsigned int should_wakeup:1;
Rafael J. Wysocki5af84b82010-01-23 22:23:32 +0100416 unsigned async_suspend:1;
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200417 enum dpm_state status; /* Owned by the PM core */
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200418#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200419 struct list_head entry;
Rafael J. Wysocki5af84b82010-01-23 22:23:32 +0100420 struct completion completion;
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200421#endif
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200422#ifdef CONFIG_PM_RUNTIME
423 struct timer_list suspend_timer;
424 unsigned long timer_expires;
425 struct work_struct work;
426 wait_queue_head_t wait_queue;
427 spinlock_t lock;
428 atomic_t usage_count;
429 atomic_t child_count;
430 unsigned int disable_depth:3;
431 unsigned int ignore_children:1;
432 unsigned int idle_notification:1;
433 unsigned int request_pending:1;
434 unsigned int deferred_resume:1;
Rafael J. Wysocki7a1a8eb2009-12-03 21:19:18 +0100435 unsigned int run_wake:1;
Rafael J. Wysocki53823632010-01-23 22:02:51 +0100436 unsigned int runtime_auto:1;
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200437 enum rpm_request request;
438 enum rpm_status runtime_status;
439 int runtime_error;
440#endif
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200441};
442
443/*
444 * The PM_EVENT_ messages are also used by drivers implementing the legacy
445 * suspend framework, based on the ->suspend() and ->resume() callbacks common
446 * for suspend and hibernation transitions, according to the rules below.
447 */
448
449/* Necessary, because several drivers use PM_EVENT_PRETHAW */
450#define PM_EVENT_PRETHAW PM_EVENT_QUIESCE
451
452/*
David Brownell82bb67f2006-08-14 23:11:04 -0700453 * One transition is triggered by resume(), after a suspend() call; the
454 * message is implicit:
455 *
456 * ON Driver starts working again, responding to hardware events
457 * and software requests. The hardware may have gone through
458 * a power-off reset, or it may have maintained state from the
459 * previous suspend() which the driver will rely on while
460 * resuming. On most platforms, there are no restrictions on
461 * availability of resources like clocks during resume().
462 *
463 * Other transitions are triggered by messages sent using suspend(). All
464 * these transitions quiesce the driver, so that I/O queues are inactive.
465 * That commonly entails turning off IRQs and DMA; there may be rules
466 * about how to quiesce that are specific to the bus or the device's type.
467 * (For example, network drivers mark the link state.) Other details may
468 * differ according to the message:
469 *
470 * SUSPEND Quiesce, enter a low power device state appropriate for
471 * the upcoming system state (such as PCI_D3hot), and enable
472 * wakeup events as appropriate.
473 *
Rafael J. Wysocki3a2d5b72008-02-23 19:13:25 +0100474 * HIBERNATE Enter a low power device state appropriate for the hibernation
475 * state (eg. ACPI S4) and enable wakeup events as appropriate.
476 *
David Brownell82bb67f2006-08-14 23:11:04 -0700477 * FREEZE Quiesce operations so that a consistent image can be saved;
478 * but do NOT otherwise enter a low power device state, and do
479 * NOT emit system wakeup events.
480 *
481 * PRETHAW Quiesce as if for FREEZE; additionally, prepare for restoring
482 * the system from a snapshot taken after an earlier FREEZE.
483 * Some drivers will need to reset their hardware state instead
484 * of preserving it, to ensure that it's never mistaken for the
485 * state which that earlier snapshot had set up.
486 *
487 * A minimally power-aware driver treats all messages as SUSPEND, fully
488 * reinitializes its device during resume() -- whether or not it was reset
489 * during the suspend/resume cycle -- and can't issue wakeup events.
490 *
491 * More power-aware drivers may also use low power states at runtime as
492 * well as during system sleep states like PM_SUSPEND_STANDBY. They may
493 * be able to use wakeup events to exit from runtime low-power states,
494 * or from system low-power states such as standby or suspend-to-RAM.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 */
496
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200497#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200498extern void device_pm_lock(void);
Rafael J. Wysocki770824b2009-02-22 18:38:50 +0100499extern int sysdev_resume(void);
Alan Sternd1616302009-05-24 22:05:42 +0200500extern void dpm_resume_noirq(pm_message_t state);
501extern void dpm_resume_end(pm_message_t state);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200502
503extern void device_pm_unlock(void);
Rafael J. Wysocki770824b2009-02-22 18:38:50 +0100504extern int sysdev_suspend(pm_message_t state);
Alan Sternd1616302009-05-24 22:05:42 +0200505extern int dpm_suspend_noirq(pm_message_t state);
506extern int dpm_suspend_start(pm_message_t state);
David Brownell0ac85242005-09-12 19:39:34 -0700507
Andrew Morton02669492006-03-23 01:38:34 -0800508extern void __suspend_report_result(const char *function, void *fn, int ret);
509
510#define suspend_report_result(fn, ret) \
511 do { \
Harvey Harrisond5c003b2008-10-15 22:01:24 -0700512 __suspend_report_result(__func__, fn, ret); \
Andrew Morton02669492006-03-23 01:38:34 -0800513 } while (0)
Andrew Morton9a7834d2005-10-23 23:02:20 -0700514
Rafael J. Wysockif8824ce2010-01-27 23:47:38 +0100515extern void device_pm_wait_for_dev(struct device *sub, struct device *dev);
Alan Sternd288e472008-03-19 22:37:42 +0100516#else /* !CONFIG_PM_SLEEP */
517
Cornelia Huckffa6a702009-03-04 12:44:00 +0100518#define device_pm_lock() do {} while (0)
519#define device_pm_unlock() do {} while (0)
520
Alan Sternd1616302009-05-24 22:05:42 +0200521static inline int dpm_suspend_start(pm_message_t state)
Alan Sternd288e472008-03-19 22:37:42 +0100522{
523 return 0;
524}
525
Alan Stern9a3df1f2008-03-19 22:39:13 +0100526#define suspend_report_result(fn, ret) do {} while (0)
Alan Sternd288e472008-03-19 22:37:42 +0100527
Rafael J. Wysockif8824ce2010-01-27 23:47:38 +0100528static inline void device_pm_wait_for_dev(struct device *a, struct device *b) {}
Alan Sternd288e472008-03-19 22:37:42 +0100529#endif /* !CONFIG_PM_SLEEP */
530
Cornelia Huckffa6a702009-03-04 12:44:00 +0100531/* How to reorder dpm_list after device_move() */
532enum dpm_order {
533 DPM_ORDER_NONE,
534 DPM_ORDER_DEV_AFTER_PARENT,
535 DPM_ORDER_PARENT_BEFORE_DEV,
536 DPM_ORDER_DEV_LAST,
537};
538
Len Brown9f9adec2007-12-13 17:38:03 -0500539/*
540 * Global Power Management flags
541 * Used to keep APM and ACPI from both being active
542 */
543extern unsigned int pm_flags;
544
545#define PM_APM 1
546#define PM_ACPI 2
547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548#endif /* _LINUX_PM_H */