pm.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /*
  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. #ifndef _LINUX_PM_H
  21. #define _LINUX_PM_H
  22. #include <linux/list.h>
  23. #include <linux/workqueue.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/wait.h>
  26. #include <linux/timer.h>
  27. #include <linux/completion.h>
  28. /*
  29. * Callbacks for platform drivers to implement.
  30. */
  31. extern void (*pm_idle)(void);
  32. extern void (*pm_power_off)(void);
  33. extern void (*pm_power_off_prepare)(void);
  34. /*
  35. * Device power management
  36. */
  37. struct device;
  38. typedef struct pm_message {
  39. int event;
  40. } pm_message_t;
  41. /**
  42. * struct dev_pm_ops - device PM callbacks
  43. *
  44. * Several driver power state transitions are externally visible, affecting
  45. * the state of pending I/O queues and (for drivers that touch hardware)
  46. * interrupts, wakeups, DMA, and other hardware state. There may also be
  47. * internal transitions to various low power modes, which are transparent
  48. * to the rest of the driver stack (such as a driver that's ON gating off
  49. * clocks which are not in active use).
  50. *
  51. * The externally visible transitions are handled with the help of the following
  52. * callbacks included in this structure:
  53. *
  54. * @prepare: Prepare the device for the upcoming transition, but do NOT change
  55. * its hardware state. Prevent new children of the device from being
  56. * registered after @prepare() returns (the driver's subsystem and
  57. * generally the rest of the kernel is supposed to prevent new calls to the
  58. * probe method from being made too once @prepare() has succeeded). If
  59. * @prepare() detects a situation it cannot handle (e.g. registration of a
  60. * child already in progress), it may return -EAGAIN, so that the PM core
  61. * can execute it once again (e.g. after the new child has been registered)
  62. * to recover from the race condition. This method is executed for all
  63. * kinds of suspend transitions and is followed by one of the suspend
  64. * callbacks: @suspend(), @freeze(), or @poweroff().
  65. * The PM core executes @prepare() for all devices before starting to
  66. * execute suspend callbacks for any of them, so drivers may assume all of
  67. * the other devices to be present and functional while @prepare() is being
  68. * executed. In particular, it is safe to make GFP_KERNEL memory
  69. * allocations from within @prepare(). However, drivers may NOT assume
  70. * anything about the availability of the user space at that time and it
  71. * is not correct to request firmware from within @prepare() (it's too
  72. * late to do that). [To work around this limitation, drivers may
  73. * register suspend and hibernation notifiers that are executed before the
  74. * freezing of tasks.]
  75. *
  76. * @complete: Undo the changes made by @prepare(). This method is executed for
  77. * all kinds of resume transitions, following one of the resume callbacks:
  78. * @resume(), @thaw(), @restore(). Also called if the state transition
  79. * fails before the driver's suspend callback (@suspend(), @freeze(),
  80. * @poweroff()) can be executed (e.g. if the suspend callback fails for one
  81. * of the other devices that the PM core has unsuccessfully attempted to
  82. * suspend earlier).
  83. * The PM core executes @complete() after it has executed the appropriate
  84. * resume callback for all devices.
  85. *
  86. * @suspend: Executed before putting the system into a sleep state in which the
  87. * contents of main memory are preserved. Quiesce the device, put it into
  88. * a low power state appropriate for the upcoming system state (such as
  89. * PCI_D3hot), and enable wakeup events as appropriate.
  90. *
  91. * @resume: Executed after waking the system up from a sleep state in which the
  92. * contents of main memory were preserved. Put the device into the
  93. * appropriate state, according to the information saved in memory by the
  94. * preceding @suspend(). The driver starts working again, responding to
  95. * hardware events and software requests. The hardware may have gone
  96. * through a power-off reset, or it may have maintained state from the
  97. * previous suspend() which the driver may rely on while resuming. On most
  98. * platforms, there are no restrictions on availability of resources like
  99. * clocks during @resume().
  100. *
  101. * @freeze: Hibernation-specific, executed before creating a hibernation image.
  102. * Quiesce operations so that a consistent image can be created, but do NOT
  103. * otherwise put the device into a low power device state and do NOT emit
  104. * system wakeup events. Save in main memory the device settings to be
  105. * used by @restore() during the subsequent resume from hibernation or by
  106. * the subsequent @thaw(), if the creation of the image or the restoration
  107. * of main memory contents from it fails.
  108. *
  109. * @thaw: Hibernation-specific, executed after creating a hibernation image OR
  110. * if the creation of the image fails. Also executed after a failing
  111. * attempt to restore the contents of main memory from such an image.
  112. * Undo the changes made by the preceding @freeze(), so the device can be
  113. * operated in the same way as immediately before the call to @freeze().
  114. *
  115. * @poweroff: Hibernation-specific, executed after saving a hibernation image.
  116. * Quiesce the device, put it into a low power state appropriate for the
  117. * upcoming system state (such as PCI_D3hot), and enable wakeup events as
  118. * appropriate.
  119. *
  120. * @restore: Hibernation-specific, executed after restoring the contents of main
  121. * memory from a hibernation image. Driver starts working again,
  122. * responding to hardware events and software requests. Drivers may NOT
  123. * make ANY assumptions about the hardware state right prior to @restore().
  124. * On most platforms, there are no restrictions on availability of
  125. * resources like clocks during @restore().
  126. *
  127. * @suspend_noirq: Complete the operations of ->suspend() by carrying out any
  128. * actions required for suspending the device that need interrupts to be
  129. * disabled
  130. *
  131. * @resume_noirq: Prepare for the execution of ->resume() by carrying out any
  132. * actions required for resuming the device that need interrupts to be
  133. * disabled
  134. *
  135. * @freeze_noirq: Complete the operations of ->freeze() by carrying out any
  136. * actions required for freezing the device that need interrupts to be
  137. * disabled
  138. *
  139. * @thaw_noirq: Prepare for the execution of ->thaw() by carrying out any
  140. * actions required for thawing the device that need interrupts to be
  141. * disabled
  142. *
  143. * @poweroff_noirq: Complete the operations of ->poweroff() by carrying out any
  144. * actions required for handling the device that need interrupts to be
  145. * disabled
  146. *
  147. * @restore_noirq: Prepare for the execution of ->restore() by carrying out any
  148. * actions required for restoring the operations of the device that need
  149. * interrupts to be disabled
  150. *
  151. * All of the above callbacks, except for @complete(), return error codes.
  152. * However, the error codes returned by the resume operations, @resume(),
  153. * @thaw(), @restore(), @resume_noirq(), @thaw_noirq(), and @restore_noirq() do
  154. * not cause the PM core to abort the resume transition during which they are
  155. * returned. The error codes returned in that cases are only printed by the PM
  156. * core to the system logs for debugging purposes. Still, it is recommended
  157. * that drivers only return error codes from their resume methods in case of an
  158. * unrecoverable failure (i.e. when the device being handled refuses to resume
  159. * and becomes unusable) to allow us to modify the PM core in the future, so
  160. * that it can avoid attempting to handle devices that failed to resume and
  161. * their children.
  162. *
  163. * It is allowed to unregister devices while the above callbacks are being
  164. * executed. However, it is not allowed to unregister a device from within any
  165. * of its own callbacks.
  166. *
  167. * There also are the following callbacks related to run-time power management
  168. * of devices:
  169. *
  170. * @runtime_suspend: Prepare the device for a condition in which it won't be
  171. * able to communicate with the CPU(s) and RAM due to power management.
  172. * This need not mean that the device should be put into a low power state.
  173. * For example, if the device is behind a link which is about to be turned
  174. * off, the device may remain at full power. If the device does go to low
  175. * power and is capable of generating run-time wake-up events, remote
  176. * wake-up (i.e., a hardware mechanism allowing the device to request a
  177. * change of its power state via a wake-up event, such as PCI PME) should
  178. * be enabled for it.
  179. *
  180. * @runtime_resume: Put the device into the fully active state in response to a
  181. * wake-up event generated by hardware or at the request of software. If
  182. * necessary, put the device into the full power state and restore its
  183. * registers, so that it is fully operational.
  184. *
  185. * @runtime_idle: Device appears to be inactive and it might be put into a low
  186. * power state if all of the necessary conditions are satisfied. Check
  187. * these conditions and handle the device as appropriate, possibly queueing
  188. * a suspend request for it. The return value is ignored by the PM core.
  189. */
  190. struct dev_pm_ops {
  191. int (*prepare)(struct device *dev);
  192. void (*complete)(struct device *dev);
  193. int (*suspend)(struct device *dev);
  194. int (*resume)(struct device *dev);
  195. int (*freeze)(struct device *dev);
  196. int (*thaw)(struct device *dev);
  197. int (*poweroff)(struct device *dev);
  198. int (*restore)(struct device *dev);
  199. int (*suspend_noirq)(struct device *dev);
  200. int (*resume_noirq)(struct device *dev);
  201. int (*freeze_noirq)(struct device *dev);
  202. int (*thaw_noirq)(struct device *dev);
  203. int (*poweroff_noirq)(struct device *dev);
  204. int (*restore_noirq)(struct device *dev);
  205. int (*runtime_suspend)(struct device *dev);
  206. int (*runtime_resume)(struct device *dev);
  207. int (*runtime_idle)(struct device *dev);
  208. };
  209. #ifdef CONFIG_PM_SLEEP
  210. #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
  211. .suspend = suspend_fn, \
  212. .resume = resume_fn, \
  213. .freeze = suspend_fn, \
  214. .thaw = resume_fn, \
  215. .poweroff = suspend_fn, \
  216. .restore = resume_fn,
  217. #else
  218. #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
  219. #endif
  220. #ifdef CONFIG_PM_RUNTIME
  221. #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
  222. .runtime_suspend = suspend_fn, \
  223. .runtime_resume = resume_fn, \
  224. .runtime_idle = idle_fn,
  225. #else
  226. #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn)
  227. #endif
  228. /*
  229. * Use this if you want to use the same suspend and resume callbacks for suspend
  230. * to RAM and hibernation.
  231. */
  232. #define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
  233. const struct dev_pm_ops name = { \
  234. SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
  235. }
  236. /*
  237. * Use this for defining a set of PM operations to be used in all situations
  238. * (sustem suspend, hibernation or runtime PM).
  239. */
  240. #define UNIVERSAL_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn) \
  241. const struct dev_pm_ops name = { \
  242. SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
  243. SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
  244. }
  245. /*
  246. * Use this for subsystems (bus types, device types, device classes) that don't
  247. * need any special suspend/resume handling in addition to invoking the PM
  248. * callbacks provided by device drivers supporting both the system sleep PM and
  249. * runtime PM, make the pm member point to generic_subsys_pm_ops.
  250. */
  251. #ifdef CONFIG_PM_OPS
  252. extern struct dev_pm_ops generic_subsys_pm_ops;
  253. #define GENERIC_SUBSYS_PM_OPS (&generic_subsys_pm_ops)
  254. #else
  255. #define GENERIC_SUBSYS_PM_OPS NULL
  256. #endif
  257. /**
  258. * PM_EVENT_ messages
  259. *
  260. * The following PM_EVENT_ messages are defined for the internal use of the PM
  261. * core, in order to provide a mechanism allowing the high level suspend and
  262. * hibernation code to convey the necessary information to the device PM core
  263. * code:
  264. *
  265. * ON No transition.
  266. *
  267. * FREEZE System is going to hibernate, call ->prepare() and ->freeze()
  268. * for all devices.
  269. *
  270. * SUSPEND System is going to suspend, call ->prepare() and ->suspend()
  271. * for all devices.
  272. *
  273. * HIBERNATE Hibernation image has been saved, call ->prepare() and
  274. * ->poweroff() for all devices.
  275. *
  276. * QUIESCE Contents of main memory are going to be restored from a (loaded)
  277. * hibernation image, call ->prepare() and ->freeze() for all
  278. * devices.
  279. *
  280. * RESUME System is resuming, call ->resume() and ->complete() for all
  281. * devices.
  282. *
  283. * THAW Hibernation image has been created, call ->thaw() and
  284. * ->complete() for all devices.
  285. *
  286. * RESTORE Contents of main memory have been restored from a hibernation
  287. * image, call ->restore() and ->complete() for all devices.
  288. *
  289. * RECOVER Creation of a hibernation image or restoration of the main
  290. * memory contents from a hibernation image has failed, call
  291. * ->thaw() and ->complete() for all devices.
  292. *
  293. * The following PM_EVENT_ messages are defined for internal use by
  294. * kernel subsystems. They are never issued by the PM core.
  295. *
  296. * USER_SUSPEND Manual selective suspend was issued by userspace.
  297. *
  298. * USER_RESUME Manual selective resume was issued by userspace.
  299. *
  300. * REMOTE_WAKEUP Remote-wakeup request was received from the device.
  301. *
  302. * AUTO_SUSPEND Automatic (device idle) runtime suspend was
  303. * initiated by the subsystem.
  304. *
  305. * AUTO_RESUME Automatic (device needed) runtime resume was
  306. * requested by a driver.
  307. */
  308. #define PM_EVENT_ON 0x0000
  309. #define PM_EVENT_FREEZE 0x0001
  310. #define PM_EVENT_SUSPEND 0x0002
  311. #define PM_EVENT_HIBERNATE 0x0004
  312. #define PM_EVENT_QUIESCE 0x0008
  313. #define PM_EVENT_RESUME 0x0010
  314. #define PM_EVENT_THAW 0x0020
  315. #define PM_EVENT_RESTORE 0x0040
  316. #define PM_EVENT_RECOVER 0x0080
  317. #define PM_EVENT_USER 0x0100
  318. #define PM_EVENT_REMOTE 0x0200
  319. #define PM_EVENT_AUTO 0x0400
  320. #define PM_EVENT_SLEEP (PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
  321. #define PM_EVENT_USER_SUSPEND (PM_EVENT_USER | PM_EVENT_SUSPEND)
  322. #define PM_EVENT_USER_RESUME (PM_EVENT_USER | PM_EVENT_RESUME)
  323. #define PM_EVENT_REMOTE_RESUME (PM_EVENT_REMOTE | PM_EVENT_RESUME)
  324. #define PM_EVENT_AUTO_SUSPEND (PM_EVENT_AUTO | PM_EVENT_SUSPEND)
  325. #define PM_EVENT_AUTO_RESUME (PM_EVENT_AUTO | PM_EVENT_RESUME)
  326. #define PMSG_ON ((struct pm_message){ .event = PM_EVENT_ON, })
  327. #define PMSG_FREEZE ((struct pm_message){ .event = PM_EVENT_FREEZE, })
  328. #define PMSG_QUIESCE ((struct pm_message){ .event = PM_EVENT_QUIESCE, })
  329. #define PMSG_SUSPEND ((struct pm_message){ .event = PM_EVENT_SUSPEND, })
  330. #define PMSG_HIBERNATE ((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
  331. #define PMSG_RESUME ((struct pm_message){ .event = PM_EVENT_RESUME, })
  332. #define PMSG_THAW ((struct pm_message){ .event = PM_EVENT_THAW, })
  333. #define PMSG_RESTORE ((struct pm_message){ .event = PM_EVENT_RESTORE, })
  334. #define PMSG_RECOVER ((struct pm_message){ .event = PM_EVENT_RECOVER, })
  335. #define PMSG_USER_SUSPEND ((struct pm_message) \
  336. { .event = PM_EVENT_USER_SUSPEND, })
  337. #define PMSG_USER_RESUME ((struct pm_message) \
  338. { .event = PM_EVENT_USER_RESUME, })
  339. #define PMSG_REMOTE_RESUME ((struct pm_message) \
  340. { .event = PM_EVENT_REMOTE_RESUME, })
  341. #define PMSG_AUTO_SUSPEND ((struct pm_message) \
  342. { .event = PM_EVENT_AUTO_SUSPEND, })
  343. #define PMSG_AUTO_RESUME ((struct pm_message) \
  344. { .event = PM_EVENT_AUTO_RESUME, })
  345. /**
  346. * Device power management states
  347. *
  348. * These state labels are used internally by the PM core to indicate the current
  349. * status of a device with respect to the PM core operations.
  350. *
  351. * DPM_ON Device is regarded as operational. Set this way
  352. * initially and when ->complete() is about to be called.
  353. * Also set when ->prepare() fails.
  354. *
  355. * DPM_PREPARING Device is going to be prepared for a PM transition. Set
  356. * when ->prepare() is about to be called.
  357. *
  358. * DPM_RESUMING Device is going to be resumed. Set when ->resume(),
  359. * ->thaw(), or ->restore() is about to be called.
  360. *
  361. * DPM_SUSPENDING Device has been prepared for a power transition. Set
  362. * when ->prepare() has just succeeded.
  363. *
  364. * DPM_OFF Device is regarded as inactive. Set immediately after
  365. * ->suspend(), ->freeze(), or ->poweroff() has succeeded.
  366. * Also set when ->resume()_noirq, ->thaw_noirq(), or
  367. * ->restore_noirq() is about to be called.
  368. *
  369. * DPM_OFF_IRQ Device is in a "deep sleep". Set immediately after
  370. * ->suspend_noirq(), ->freeze_noirq(), or
  371. * ->poweroff_noirq() has just succeeded.
  372. */
  373. enum dpm_state {
  374. DPM_INVALID,
  375. DPM_ON,
  376. DPM_PREPARING,
  377. DPM_RESUMING,
  378. DPM_SUSPENDING,
  379. DPM_OFF,
  380. DPM_OFF_IRQ,
  381. };
  382. /**
  383. * Device run-time power management status.
  384. *
  385. * These status labels are used internally by the PM core to indicate the
  386. * current status of a device with respect to the PM core operations. They do
  387. * not reflect the actual power state of the device or its status as seen by the
  388. * driver.
  389. *
  390. * RPM_ACTIVE Device is fully operational. Indicates that the device
  391. * bus type's ->runtime_resume() callback has completed
  392. * successfully.
  393. *
  394. * RPM_SUSPENDED Device bus type's ->runtime_suspend() callback has
  395. * completed successfully. The device is regarded as
  396. * suspended.
  397. *
  398. * RPM_RESUMING Device bus type's ->runtime_resume() callback is being
  399. * executed.
  400. *
  401. * RPM_SUSPENDING Device bus type's ->runtime_suspend() callback is being
  402. * executed.
  403. */
  404. enum rpm_status {
  405. RPM_ACTIVE = 0,
  406. RPM_RESUMING,
  407. RPM_SUSPENDED,
  408. RPM_SUSPENDING,
  409. };
  410. /**
  411. * Device run-time power management request types.
  412. *
  413. * RPM_REQ_NONE Do nothing.
  414. *
  415. * RPM_REQ_IDLE Run the device bus type's ->runtime_idle() callback
  416. *
  417. * RPM_REQ_SUSPEND Run the device bus type's ->runtime_suspend() callback
  418. *
  419. * RPM_REQ_RESUME Run the device bus type's ->runtime_resume() callback
  420. */
  421. enum rpm_request {
  422. RPM_REQ_NONE = 0,
  423. RPM_REQ_IDLE,
  424. RPM_REQ_SUSPEND,
  425. RPM_REQ_RESUME,
  426. };
  427. struct wakeup_source;
  428. struct dev_pm_info {
  429. pm_message_t power_state;
  430. unsigned int can_wakeup:1;
  431. unsigned async_suspend:1;
  432. enum dpm_state status; /* Owned by the PM core */
  433. spinlock_t lock;
  434. #ifdef CONFIG_PM_SLEEP
  435. struct list_head entry;
  436. struct completion completion;
  437. struct wakeup_source *wakeup;
  438. #endif
  439. #ifdef CONFIG_PM_RUNTIME
  440. struct timer_list suspend_timer;
  441. unsigned long timer_expires;
  442. struct work_struct work;
  443. wait_queue_head_t wait_queue;
  444. atomic_t usage_count;
  445. atomic_t child_count;
  446. unsigned int disable_depth:3;
  447. unsigned int ignore_children:1;
  448. unsigned int idle_notification:1;
  449. unsigned int request_pending:1;
  450. unsigned int deferred_resume:1;
  451. unsigned int run_wake:1;
  452. unsigned int runtime_auto:1;
  453. enum rpm_request request;
  454. enum rpm_status runtime_status;
  455. int runtime_error;
  456. unsigned long active_jiffies;
  457. unsigned long suspended_jiffies;
  458. unsigned long accounting_timestamp;
  459. #endif
  460. };
  461. extern void update_pm_runtime_accounting(struct device *dev);
  462. /*
  463. * The PM_EVENT_ messages are also used by drivers implementing the legacy
  464. * suspend framework, based on the ->suspend() and ->resume() callbacks common
  465. * for suspend and hibernation transitions, according to the rules below.
  466. */
  467. /* Necessary, because several drivers use PM_EVENT_PRETHAW */
  468. #define PM_EVENT_PRETHAW PM_EVENT_QUIESCE
  469. /*
  470. * One transition is triggered by resume(), after a suspend() call; the
  471. * message is implicit:
  472. *
  473. * ON Driver starts working again, responding to hardware events
  474. * and software requests. The hardware may have gone through
  475. * a power-off reset, or it may have maintained state from the
  476. * previous suspend() which the driver will rely on while
  477. * resuming. On most platforms, there are no restrictions on
  478. * availability of resources like clocks during resume().
  479. *
  480. * Other transitions are triggered by messages sent using suspend(). All
  481. * these transitions quiesce the driver, so that I/O queues are inactive.
  482. * That commonly entails turning off IRQs and DMA; there may be rules
  483. * about how to quiesce that are specific to the bus or the device's type.
  484. * (For example, network drivers mark the link state.) Other details may
  485. * differ according to the message:
  486. *
  487. * SUSPEND Quiesce, enter a low power device state appropriate for
  488. * the upcoming system state (such as PCI_D3hot), and enable
  489. * wakeup events as appropriate.
  490. *
  491. * HIBERNATE Enter a low power device state appropriate for the hibernation
  492. * state (eg. ACPI S4) and enable wakeup events as appropriate.
  493. *
  494. * FREEZE Quiesce operations so that a consistent image can be saved;
  495. * but do NOT otherwise enter a low power device state, and do
  496. * NOT emit system wakeup events.
  497. *
  498. * PRETHAW Quiesce as if for FREEZE; additionally, prepare for restoring
  499. * the system from a snapshot taken after an earlier FREEZE.
  500. * Some drivers will need to reset their hardware state instead
  501. * of preserving it, to ensure that it's never mistaken for the
  502. * state which that earlier snapshot had set up.
  503. *
  504. * A minimally power-aware driver treats all messages as SUSPEND, fully
  505. * reinitializes its device during resume() -- whether or not it was reset
  506. * during the suspend/resume cycle -- and can't issue wakeup events.
  507. *
  508. * More power-aware drivers may also use low power states at runtime as
  509. * well as during system sleep states like PM_SUSPEND_STANDBY. They may
  510. * be able to use wakeup events to exit from runtime low-power states,
  511. * or from system low-power states such as standby or suspend-to-RAM.
  512. */
  513. #ifdef CONFIG_PM_SLEEP
  514. extern void device_pm_lock(void);
  515. extern int sysdev_resume(void);
  516. extern void dpm_resume_noirq(pm_message_t state);
  517. extern void dpm_resume_end(pm_message_t state);
  518. extern void device_pm_unlock(void);
  519. extern int sysdev_suspend(pm_message_t state);
  520. extern int dpm_suspend_noirq(pm_message_t state);
  521. extern int dpm_suspend_start(pm_message_t state);
  522. extern void __suspend_report_result(const char *function, void *fn, int ret);
  523. #define suspend_report_result(fn, ret) \
  524. do { \
  525. __suspend_report_result(__func__, fn, ret); \
  526. } while (0)
  527. extern void device_pm_wait_for_dev(struct device *sub, struct device *dev);
  528. #else /* !CONFIG_PM_SLEEP */
  529. #define device_pm_lock() do {} while (0)
  530. #define device_pm_unlock() do {} while (0)
  531. static inline int dpm_suspend_start(pm_message_t state)
  532. {
  533. return 0;
  534. }
  535. #define suspend_report_result(fn, ret) do {} while (0)
  536. static inline void device_pm_wait_for_dev(struct device *a, struct device *b) {}
  537. #endif /* !CONFIG_PM_SLEEP */
  538. /* How to reorder dpm_list after device_move() */
  539. enum dpm_order {
  540. DPM_ORDER_NONE,
  541. DPM_ORDER_DEV_AFTER_PARENT,
  542. DPM_ORDER_PARENT_BEFORE_DEV,
  543. DPM_ORDER_DEV_LAST,
  544. };
  545. /*
  546. * Global Power Management flags
  547. * Used to keep APM and ACPI from both being active
  548. */
  549. extern unsigned int pm_flags;
  550. #define PM_APM 1
  551. #define PM_ACPI 2
  552. #endif /* _LINUX_PM_H */