pm.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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_power_off)(void);
  32. extern void (*pm_power_off_prepare)(void);
  33. /*
  34. * Device power management
  35. */
  36. struct device;
  37. #ifdef CONFIG_PM
  38. extern const char power_group_name[]; /* = "power" */
  39. #else
  40. #define power_group_name NULL
  41. #endif
  42. typedef struct pm_message {
  43. int event;
  44. } pm_message_t;
  45. /**
  46. * struct dev_pm_ops - device PM callbacks
  47. *
  48. * Several device power state transitions are externally visible, affecting
  49. * the state of pending I/O queues and (for drivers that touch hardware)
  50. * interrupts, wakeups, DMA, and other hardware state. There may also be
  51. * internal transitions to various low-power modes which are transparent
  52. * to the rest of the driver stack (such as a driver that's ON gating off
  53. * clocks which are not in active use).
  54. *
  55. * The externally visible transitions are handled with the help of callbacks
  56. * included in this structure in such a way that two levels of callbacks are
  57. * involved. First, the PM core executes callbacks provided by PM domains,
  58. * device types, classes and bus types. They are the subsystem-level callbacks
  59. * supposed to execute callbacks provided by device drivers, although they may
  60. * choose not to do that. If the driver callbacks are executed, they have to
  61. * collaborate with the subsystem-level callbacks to achieve the goals
  62. * appropriate for the given system transition, given transition phase and the
  63. * subsystem the device belongs to.
  64. *
  65. * @prepare: The principal role of this callback is to prevent new children of
  66. * the device from being registered after it has returned (the driver's
  67. * subsystem and generally the rest of the kernel is supposed to prevent
  68. * new calls to the probe method from being made too once @prepare() has
  69. * succeeded). If @prepare() detects a situation it cannot handle (e.g.
  70. * registration of a child already in progress), it may return -EAGAIN, so
  71. * that the PM core can execute it once again (e.g. after a new child has
  72. * been registered) to recover from the race condition.
  73. * This method is executed for all kinds of suspend transitions and is
  74. * followed by one of the suspend callbacks: @suspend(), @freeze(), or
  75. * @poweroff(). The PM core executes subsystem-level @prepare() for all
  76. * devices before starting to invoke suspend callbacks for any of them, so
  77. * generally devices may be assumed to be functional or to respond to
  78. * runtime resume requests while @prepare() is being executed. However,
  79. * device drivers may NOT assume anything about the availability of user
  80. * space at that time and it is NOT valid to request firmware from within
  81. * @prepare() (it's too late to do that). It also is NOT valid to allocate
  82. * substantial amounts of memory from @prepare() in the GFP_KERNEL mode.
  83. * [To work around these limitations, drivers may register suspend and
  84. * hibernation notifiers to be executed before the freezing of tasks.]
  85. *
  86. * @complete: Undo the changes made by @prepare(). This method is executed for
  87. * all kinds of resume transitions, following one of the resume callbacks:
  88. * @resume(), @thaw(), @restore(). Also called if the state transition
  89. * fails before the driver's suspend callback: @suspend(), @freeze() or
  90. * @poweroff(), can be executed (e.g. if the suspend callback fails for one
  91. * of the other devices that the PM core has unsuccessfully attempted to
  92. * suspend earlier).
  93. * The PM core executes subsystem-level @complete() after it has executed
  94. * the appropriate resume callbacks for all devices.
  95. *
  96. * @suspend: Executed before putting the system into a sleep state in which the
  97. * contents of main memory are preserved. The exact action to perform
  98. * depends on the device's subsystem (PM domain, device type, class or bus
  99. * type), but generally the device must be quiescent after subsystem-level
  100. * @suspend() has returned, so that it doesn't do any I/O or DMA.
  101. * Subsystem-level @suspend() is executed for all devices after invoking
  102. * subsystem-level @prepare() for all of them.
  103. *
  104. * @suspend_late: Continue operations started by @suspend(). For a number of
  105. * devices @suspend_late() may point to the same callback routine as the
  106. * runtime suspend callback.
  107. *
  108. * @resume: Executed after waking the system up from a sleep state in which the
  109. * contents of main memory were preserved. The exact action to perform
  110. * depends on the device's subsystem, but generally the driver is expected
  111. * to start working again, responding to hardware events and software
  112. * requests (the device itself may be left in a low-power state, waiting
  113. * for a runtime resume to occur). The state of the device at the time its
  114. * driver's @resume() callback is run depends on the platform and subsystem
  115. * the device belongs to. On most platforms, there are no restrictions on
  116. * availability of resources like clocks during @resume().
  117. * Subsystem-level @resume() is executed for all devices after invoking
  118. * subsystem-level @resume_noirq() for all of them.
  119. *
  120. * @resume_early: Prepare to execute @resume(). For a number of devices
  121. * @resume_early() may point to the same callback routine as the runtime
  122. * resume callback.
  123. *
  124. * @freeze: Hibernation-specific, executed before creating a hibernation image.
  125. * Analogous to @suspend(), but it should not enable the device to signal
  126. * wakeup events or change its power state. The majority of subsystems
  127. * (with the notable exception of the PCI bus type) expect the driver-level
  128. * @freeze() to save the device settings in memory to be used by @restore()
  129. * during the subsequent resume from hibernation.
  130. * Subsystem-level @freeze() is executed for all devices after invoking
  131. * subsystem-level @prepare() for all of them.
  132. *
  133. * @freeze_late: Continue operations started by @freeze(). Analogous to
  134. * @suspend_late(), but it should not enable the device to signal wakeup
  135. * events or change its power state.
  136. *
  137. * @thaw: Hibernation-specific, executed after creating a hibernation image OR
  138. * if the creation of an image has failed. Also executed after a failing
  139. * attempt to restore the contents of main memory from such an image.
  140. * Undo the changes made by the preceding @freeze(), so the device can be
  141. * operated in the same way as immediately before the call to @freeze().
  142. * Subsystem-level @thaw() is executed for all devices after invoking
  143. * subsystem-level @thaw_noirq() for all of them. It also may be executed
  144. * directly after @freeze() in case of a transition error.
  145. *
  146. * @thaw_early: Prepare to execute @thaw(). Undo the changes made by the
  147. * preceding @freeze_late().
  148. *
  149. * @poweroff: Hibernation-specific, executed after saving a hibernation image.
  150. * Analogous to @suspend(), but it need not save the device's settings in
  151. * memory.
  152. * Subsystem-level @poweroff() is executed for all devices after invoking
  153. * subsystem-level @prepare() for all of them.
  154. *
  155. * @poweroff_late: Continue operations started by @poweroff(). Analogous to
  156. * @suspend_late(), but it need not save the device's settings in memory.
  157. *
  158. * @restore: Hibernation-specific, executed after restoring the contents of main
  159. * memory from a hibernation image, analogous to @resume().
  160. *
  161. * @restore_early: Prepare to execute @restore(), analogous to @resume_early().
  162. *
  163. * @suspend_noirq: Complete the actions started by @suspend(). Carry out any
  164. * additional operations required for suspending the device that might be
  165. * racing with its driver's interrupt handler, which is guaranteed not to
  166. * run while @suspend_noirq() is being executed.
  167. * It generally is expected that the device will be in a low-power state
  168. * (appropriate for the target system sleep state) after subsystem-level
  169. * @suspend_noirq() has returned successfully. If the device can generate
  170. * system wakeup signals and is enabled to wake up the system, it should be
  171. * configured to do so at that time. However, depending on the platform
  172. * and device's subsystem, @suspend() or @suspend_late() may be allowed to
  173. * put the device into the low-power state and configure it to generate
  174. * wakeup signals, in which case it generally is not necessary to define
  175. * @suspend_noirq().
  176. *
  177. * @resume_noirq: Prepare for the execution of @resume() by carrying out any
  178. * operations required for resuming the device that might be racing with
  179. * its driver's interrupt handler, which is guaranteed not to run while
  180. * @resume_noirq() is being executed.
  181. *
  182. * @freeze_noirq: Complete the actions started by @freeze(). Carry out any
  183. * additional operations required for freezing the device that might be
  184. * racing with its driver's interrupt handler, which is guaranteed not to
  185. * run while @freeze_noirq() is being executed.
  186. * The power state of the device should not be changed by either @freeze(),
  187. * or @freeze_late(), or @freeze_noirq() and it should not be configured to
  188. * signal system wakeup by any of these callbacks.
  189. *
  190. * @thaw_noirq: Prepare for the execution of @thaw() by carrying out any
  191. * operations required for thawing the device that might be racing with its
  192. * driver's interrupt handler, which is guaranteed not to run while
  193. * @thaw_noirq() is being executed.
  194. *
  195. * @poweroff_noirq: Complete the actions started by @poweroff(). Analogous to
  196. * @suspend_noirq(), but it need not save the device's settings in memory.
  197. *
  198. * @restore_noirq: Prepare for the execution of @restore() by carrying out any
  199. * operations required for thawing the device that might be racing with its
  200. * driver's interrupt handler, which is guaranteed not to run while
  201. * @restore_noirq() is being executed. Analogous to @resume_noirq().
  202. *
  203. * All of the above callbacks, except for @complete(), return error codes.
  204. * However, the error codes returned by the resume operations, @resume(),
  205. * @thaw(), @restore(), @resume_noirq(), @thaw_noirq(), and @restore_noirq(), do
  206. * not cause the PM core to abort the resume transition during which they are
  207. * returned. The error codes returned in those cases are only printed by the PM
  208. * core to the system logs for debugging purposes. Still, it is recommended
  209. * that drivers only return error codes from their resume methods in case of an
  210. * unrecoverable failure (i.e. when the device being handled refuses to resume
  211. * and becomes unusable) to allow us to modify the PM core in the future, so
  212. * that it can avoid attempting to handle devices that failed to resume and
  213. * their children.
  214. *
  215. * It is allowed to unregister devices while the above callbacks are being
  216. * executed. However, a callback routine must NOT try to unregister the device
  217. * it was called for, although it may unregister children of that device (for
  218. * example, if it detects that a child was unplugged while the system was
  219. * asleep).
  220. *
  221. * Refer to Documentation/power/devices.txt for more information about the role
  222. * of the above callbacks in the system suspend process.
  223. *
  224. * There also are callbacks related to runtime power management of devices.
  225. * Again, these callbacks are executed by the PM core only for subsystems
  226. * (PM domains, device types, classes and bus types) and the subsystem-level
  227. * callbacks are supposed to invoke the driver callbacks. Moreover, the exact
  228. * actions to be performed by a device driver's callbacks generally depend on
  229. * the platform and subsystem the device belongs to.
  230. *
  231. * @runtime_suspend: Prepare the device for a condition in which it won't be
  232. * able to communicate with the CPU(s) and RAM due to power management.
  233. * This need not mean that the device should be put into a low-power state.
  234. * For example, if the device is behind a link which is about to be turned
  235. * off, the device may remain at full power. If the device does go to low
  236. * power and is capable of generating runtime wakeup events, remote wakeup
  237. * (i.e., a hardware mechanism allowing the device to request a change of
  238. * its power state via an interrupt) should be enabled for it.
  239. *
  240. * @runtime_resume: Put the device into the fully active state in response to a
  241. * wakeup event generated by hardware or at the request of software. If
  242. * necessary, put the device into the full-power state and restore its
  243. * registers, so that it is fully operational.
  244. *
  245. * @runtime_idle: Device appears to be inactive and it might be put into a
  246. * low-power state if all of the necessary conditions are satisfied. Check
  247. * these conditions and handle the device as appropriate, possibly queueing
  248. * a suspend request for it. The return value is ignored by the PM core.
  249. *
  250. * Refer to Documentation/power/runtime_pm.txt for more information about the
  251. * role of the above callbacks in device runtime power management.
  252. *
  253. */
  254. struct dev_pm_ops {
  255. int (*prepare)(struct device *dev);
  256. void (*complete)(struct device *dev);
  257. int (*suspend)(struct device *dev);
  258. int (*resume)(struct device *dev);
  259. int (*freeze)(struct device *dev);
  260. int (*thaw)(struct device *dev);
  261. int (*poweroff)(struct device *dev);
  262. int (*restore)(struct device *dev);
  263. int (*suspend_late)(struct device *dev);
  264. int (*resume_early)(struct device *dev);
  265. int (*freeze_late)(struct device *dev);
  266. int (*thaw_early)(struct device *dev);
  267. int (*poweroff_late)(struct device *dev);
  268. int (*restore_early)(struct device *dev);
  269. int (*suspend_noirq)(struct device *dev);
  270. int (*resume_noirq)(struct device *dev);
  271. int (*freeze_noirq)(struct device *dev);
  272. int (*thaw_noirq)(struct device *dev);
  273. int (*poweroff_noirq)(struct device *dev);
  274. int (*restore_noirq)(struct device *dev);
  275. int (*runtime_suspend)(struct device *dev);
  276. int (*runtime_resume)(struct device *dev);
  277. int (*runtime_idle)(struct device *dev);
  278. };
  279. #ifdef CONFIG_PM_SLEEP
  280. #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
  281. .suspend = suspend_fn, \
  282. .resume = resume_fn, \
  283. .freeze = suspend_fn, \
  284. .thaw = resume_fn, \
  285. .poweroff = suspend_fn, \
  286. .restore = resume_fn,
  287. #else
  288. #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
  289. #endif
  290. #ifdef CONFIG_PM_RUNTIME
  291. #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
  292. .runtime_suspend = suspend_fn, \
  293. .runtime_resume = resume_fn, \
  294. .runtime_idle = idle_fn,
  295. #else
  296. #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn)
  297. #endif
  298. /*
  299. * Use this if you want to use the same suspend and resume callbacks for suspend
  300. * to RAM and hibernation.
  301. */
  302. #define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
  303. const struct dev_pm_ops name = { \
  304. SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
  305. }
  306. /*
  307. * Use this for defining a set of PM operations to be used in all situations
  308. * (sustem suspend, hibernation or runtime PM).
  309. * NOTE: In general, system suspend callbacks, .suspend() and .resume(), should
  310. * be different from the corresponding runtime PM callbacks, .runtime_suspend(),
  311. * and .runtime_resume(), because .runtime_suspend() always works on an already
  312. * quiescent device, while .suspend() should assume that the device may be doing
  313. * something when it is called (it should ensure that the device will be
  314. * quiescent after it has returned). Therefore it's better to point the "late"
  315. * suspend and "early" resume callback pointers, .suspend_late() and
  316. * .resume_early(), to the same routines as .runtime_suspend() and
  317. * .runtime_resume(), respectively (and analogously for hibernation).
  318. */
  319. #define UNIVERSAL_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn) \
  320. const struct dev_pm_ops name = { \
  321. SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
  322. SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
  323. }
  324. /**
  325. * PM_EVENT_ messages
  326. *
  327. * The following PM_EVENT_ messages are defined for the internal use of the PM
  328. * core, in order to provide a mechanism allowing the high level suspend and
  329. * hibernation code to convey the necessary information to the device PM core
  330. * code:
  331. *
  332. * ON No transition.
  333. *
  334. * FREEZE System is going to hibernate, call ->prepare() and ->freeze()
  335. * for all devices.
  336. *
  337. * SUSPEND System is going to suspend, call ->prepare() and ->suspend()
  338. * for all devices.
  339. *
  340. * HIBERNATE Hibernation image has been saved, call ->prepare() and
  341. * ->poweroff() for all devices.
  342. *
  343. * QUIESCE Contents of main memory are going to be restored from a (loaded)
  344. * hibernation image, call ->prepare() and ->freeze() for all
  345. * devices.
  346. *
  347. * RESUME System is resuming, call ->resume() and ->complete() for all
  348. * devices.
  349. *
  350. * THAW Hibernation image has been created, call ->thaw() and
  351. * ->complete() for all devices.
  352. *
  353. * RESTORE Contents of main memory have been restored from a hibernation
  354. * image, call ->restore() and ->complete() for all devices.
  355. *
  356. * RECOVER Creation of a hibernation image or restoration of the main
  357. * memory contents from a hibernation image has failed, call
  358. * ->thaw() and ->complete() for all devices.
  359. *
  360. * The following PM_EVENT_ messages are defined for internal use by
  361. * kernel subsystems. They are never issued by the PM core.
  362. *
  363. * USER_SUSPEND Manual selective suspend was issued by userspace.
  364. *
  365. * USER_RESUME Manual selective resume was issued by userspace.
  366. *
  367. * REMOTE_WAKEUP Remote-wakeup request was received from the device.
  368. *
  369. * AUTO_SUSPEND Automatic (device idle) runtime suspend was
  370. * initiated by the subsystem.
  371. *
  372. * AUTO_RESUME Automatic (device needed) runtime resume was
  373. * requested by a driver.
  374. */
  375. #define PM_EVENT_INVALID (-1)
  376. #define PM_EVENT_ON 0x0000
  377. #define PM_EVENT_FREEZE 0x0001
  378. #define PM_EVENT_SUSPEND 0x0002
  379. #define PM_EVENT_HIBERNATE 0x0004
  380. #define PM_EVENT_QUIESCE 0x0008
  381. #define PM_EVENT_RESUME 0x0010
  382. #define PM_EVENT_THAW 0x0020
  383. #define PM_EVENT_RESTORE 0x0040
  384. #define PM_EVENT_RECOVER 0x0080
  385. #define PM_EVENT_USER 0x0100
  386. #define PM_EVENT_REMOTE 0x0200
  387. #define PM_EVENT_AUTO 0x0400
  388. #define PM_EVENT_SLEEP (PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
  389. #define PM_EVENT_USER_SUSPEND (PM_EVENT_USER | PM_EVENT_SUSPEND)
  390. #define PM_EVENT_USER_RESUME (PM_EVENT_USER | PM_EVENT_RESUME)
  391. #define PM_EVENT_REMOTE_RESUME (PM_EVENT_REMOTE | PM_EVENT_RESUME)
  392. #define PM_EVENT_AUTO_SUSPEND (PM_EVENT_AUTO | PM_EVENT_SUSPEND)
  393. #define PM_EVENT_AUTO_RESUME (PM_EVENT_AUTO | PM_EVENT_RESUME)
  394. #define PMSG_INVALID ((struct pm_message){ .event = PM_EVENT_INVALID, })
  395. #define PMSG_ON ((struct pm_message){ .event = PM_EVENT_ON, })
  396. #define PMSG_FREEZE ((struct pm_message){ .event = PM_EVENT_FREEZE, })
  397. #define PMSG_QUIESCE ((struct pm_message){ .event = PM_EVENT_QUIESCE, })
  398. #define PMSG_SUSPEND ((struct pm_message){ .event = PM_EVENT_SUSPEND, })
  399. #define PMSG_HIBERNATE ((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
  400. #define PMSG_RESUME ((struct pm_message){ .event = PM_EVENT_RESUME, })
  401. #define PMSG_THAW ((struct pm_message){ .event = PM_EVENT_THAW, })
  402. #define PMSG_RESTORE ((struct pm_message){ .event = PM_EVENT_RESTORE, })
  403. #define PMSG_RECOVER ((struct pm_message){ .event = PM_EVENT_RECOVER, })
  404. #define PMSG_USER_SUSPEND ((struct pm_message) \
  405. { .event = PM_EVENT_USER_SUSPEND, })
  406. #define PMSG_USER_RESUME ((struct pm_message) \
  407. { .event = PM_EVENT_USER_RESUME, })
  408. #define PMSG_REMOTE_RESUME ((struct pm_message) \
  409. { .event = PM_EVENT_REMOTE_RESUME, })
  410. #define PMSG_AUTO_SUSPEND ((struct pm_message) \
  411. { .event = PM_EVENT_AUTO_SUSPEND, })
  412. #define PMSG_AUTO_RESUME ((struct pm_message) \
  413. { .event = PM_EVENT_AUTO_RESUME, })
  414. #define PMSG_IS_AUTO(msg) (((msg).event & PM_EVENT_AUTO) != 0)
  415. /**
  416. * Device run-time power management status.
  417. *
  418. * These status labels are used internally by the PM core to indicate the
  419. * current status of a device with respect to the PM core operations. They do
  420. * not reflect the actual power state of the device or its status as seen by the
  421. * driver.
  422. *
  423. * RPM_ACTIVE Device is fully operational. Indicates that the device
  424. * bus type's ->runtime_resume() callback has completed
  425. * successfully.
  426. *
  427. * RPM_SUSPENDED Device bus type's ->runtime_suspend() callback has
  428. * completed successfully. The device is regarded as
  429. * suspended.
  430. *
  431. * RPM_RESUMING Device bus type's ->runtime_resume() callback is being
  432. * executed.
  433. *
  434. * RPM_SUSPENDING Device bus type's ->runtime_suspend() callback is being
  435. * executed.
  436. */
  437. enum rpm_status {
  438. RPM_ACTIVE = 0,
  439. RPM_RESUMING,
  440. RPM_SUSPENDED,
  441. RPM_SUSPENDING,
  442. };
  443. /**
  444. * Device run-time power management request types.
  445. *
  446. * RPM_REQ_NONE Do nothing.
  447. *
  448. * RPM_REQ_IDLE Run the device bus type's ->runtime_idle() callback
  449. *
  450. * RPM_REQ_SUSPEND Run the device bus type's ->runtime_suspend() callback
  451. *
  452. * RPM_REQ_AUTOSUSPEND Same as RPM_REQ_SUSPEND, but not until the device has
  453. * been inactive for as long as power.autosuspend_delay
  454. *
  455. * RPM_REQ_RESUME Run the device bus type's ->runtime_resume() callback
  456. */
  457. enum rpm_request {
  458. RPM_REQ_NONE = 0,
  459. RPM_REQ_IDLE,
  460. RPM_REQ_SUSPEND,
  461. RPM_REQ_AUTOSUSPEND,
  462. RPM_REQ_RESUME,
  463. };
  464. struct wakeup_source;
  465. struct pm_domain_data {
  466. struct list_head list_node;
  467. struct device *dev;
  468. };
  469. struct pm_subsys_data {
  470. spinlock_t lock;
  471. unsigned int refcount;
  472. #ifdef CONFIG_PM_CLK
  473. struct list_head clock_list;
  474. #endif
  475. #ifdef CONFIG_PM_GENERIC_DOMAINS
  476. struct pm_domain_data *domain_data;
  477. #endif
  478. };
  479. struct dev_pm_info {
  480. pm_message_t power_state;
  481. unsigned int can_wakeup:1;
  482. unsigned int async_suspend:1;
  483. bool is_prepared:1; /* Owned by the PM core */
  484. bool is_suspended:1; /* Ditto */
  485. bool ignore_children:1;
  486. bool early_init:1; /* Owned by the PM core */
  487. spinlock_t lock;
  488. #ifdef CONFIG_PM_SLEEP
  489. struct list_head entry;
  490. struct completion completion;
  491. struct wakeup_source *wakeup;
  492. bool wakeup_path:1;
  493. bool syscore:1;
  494. #else
  495. unsigned int should_wakeup:1;
  496. #endif
  497. #ifdef CONFIG_PM_RUNTIME
  498. struct timer_list suspend_timer;
  499. unsigned long timer_expires;
  500. struct work_struct work;
  501. wait_queue_head_t wait_queue;
  502. atomic_t usage_count;
  503. atomic_t child_count;
  504. unsigned int disable_depth:3;
  505. unsigned int idle_notification:1;
  506. unsigned int request_pending:1;
  507. unsigned int deferred_resume:1;
  508. unsigned int run_wake:1;
  509. unsigned int runtime_auto:1;
  510. unsigned int no_callbacks:1;
  511. unsigned int irq_safe:1;
  512. unsigned int use_autosuspend:1;
  513. unsigned int timer_autosuspends:1;
  514. enum rpm_request request;
  515. enum rpm_status runtime_status;
  516. int runtime_error;
  517. int autosuspend_delay;
  518. unsigned long last_busy;
  519. unsigned long active_jiffies;
  520. unsigned long suspended_jiffies;
  521. unsigned long accounting_timestamp;
  522. #endif
  523. struct pm_subsys_data *subsys_data; /* Owned by the subsystem. */
  524. struct dev_pm_qos *qos;
  525. };
  526. extern void update_pm_runtime_accounting(struct device *dev);
  527. extern int dev_pm_get_subsys_data(struct device *dev);
  528. extern int dev_pm_put_subsys_data(struct device *dev);
  529. /*
  530. * Power domains provide callbacks that are executed during system suspend,
  531. * hibernation, system resume and during runtime PM transitions along with
  532. * subsystem-level and driver-level callbacks.
  533. */
  534. struct dev_pm_domain {
  535. struct dev_pm_ops ops;
  536. };
  537. /*
  538. * The PM_EVENT_ messages are also used by drivers implementing the legacy
  539. * suspend framework, based on the ->suspend() and ->resume() callbacks common
  540. * for suspend and hibernation transitions, according to the rules below.
  541. */
  542. /* Necessary, because several drivers use PM_EVENT_PRETHAW */
  543. #define PM_EVENT_PRETHAW PM_EVENT_QUIESCE
  544. /*
  545. * One transition is triggered by resume(), after a suspend() call; the
  546. * message is implicit:
  547. *
  548. * ON Driver starts working again, responding to hardware events
  549. * and software requests. The hardware may have gone through
  550. * a power-off reset, or it may have maintained state from the
  551. * previous suspend() which the driver will rely on while
  552. * resuming. On most platforms, there are no restrictions on
  553. * availability of resources like clocks during resume().
  554. *
  555. * Other transitions are triggered by messages sent using suspend(). All
  556. * these transitions quiesce the driver, so that I/O queues are inactive.
  557. * That commonly entails turning off IRQs and DMA; there may be rules
  558. * about how to quiesce that are specific to the bus or the device's type.
  559. * (For example, network drivers mark the link state.) Other details may
  560. * differ according to the message:
  561. *
  562. * SUSPEND Quiesce, enter a low power device state appropriate for
  563. * the upcoming system state (such as PCI_D3hot), and enable
  564. * wakeup events as appropriate.
  565. *
  566. * HIBERNATE Enter a low power device state appropriate for the hibernation
  567. * state (eg. ACPI S4) and enable wakeup events as appropriate.
  568. *
  569. * FREEZE Quiesce operations so that a consistent image can be saved;
  570. * but do NOT otherwise enter a low power device state, and do
  571. * NOT emit system wakeup events.
  572. *
  573. * PRETHAW Quiesce as if for FREEZE; additionally, prepare for restoring
  574. * the system from a snapshot taken after an earlier FREEZE.
  575. * Some drivers will need to reset their hardware state instead
  576. * of preserving it, to ensure that it's never mistaken for the
  577. * state which that earlier snapshot had set up.
  578. *
  579. * A minimally power-aware driver treats all messages as SUSPEND, fully
  580. * reinitializes its device during resume() -- whether or not it was reset
  581. * during the suspend/resume cycle -- and can't issue wakeup events.
  582. *
  583. * More power-aware drivers may also use low power states at runtime as
  584. * well as during system sleep states like PM_SUSPEND_STANDBY. They may
  585. * be able to use wakeup events to exit from runtime low-power states,
  586. * or from system low-power states such as standby or suspend-to-RAM.
  587. */
  588. #ifdef CONFIG_PM_SLEEP
  589. extern void device_pm_lock(void);
  590. extern void dpm_resume_start(pm_message_t state);
  591. extern void dpm_resume_end(pm_message_t state);
  592. extern void dpm_resume(pm_message_t state);
  593. extern void dpm_complete(pm_message_t state);
  594. extern void device_pm_unlock(void);
  595. extern int dpm_suspend_end(pm_message_t state);
  596. extern int dpm_suspend_start(pm_message_t state);
  597. extern int dpm_suspend(pm_message_t state);
  598. extern int dpm_prepare(pm_message_t state);
  599. extern void __suspend_report_result(const char *function, void *fn, int ret);
  600. #define suspend_report_result(fn, ret) \
  601. do { \
  602. __suspend_report_result(__func__, fn, ret); \
  603. } while (0)
  604. extern int device_pm_wait_for_dev(struct device *sub, struct device *dev);
  605. extern void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *));
  606. extern int pm_generic_prepare(struct device *dev);
  607. extern int pm_generic_suspend_late(struct device *dev);
  608. extern int pm_generic_suspend_noirq(struct device *dev);
  609. extern int pm_generic_suspend(struct device *dev);
  610. extern int pm_generic_resume_early(struct device *dev);
  611. extern int pm_generic_resume_noirq(struct device *dev);
  612. extern int pm_generic_resume(struct device *dev);
  613. extern int pm_generic_freeze_noirq(struct device *dev);
  614. extern int pm_generic_freeze_late(struct device *dev);
  615. extern int pm_generic_freeze(struct device *dev);
  616. extern int pm_generic_thaw_noirq(struct device *dev);
  617. extern int pm_generic_thaw_early(struct device *dev);
  618. extern int pm_generic_thaw(struct device *dev);
  619. extern int pm_generic_restore_noirq(struct device *dev);
  620. extern int pm_generic_restore_early(struct device *dev);
  621. extern int pm_generic_restore(struct device *dev);
  622. extern int pm_generic_poweroff_noirq(struct device *dev);
  623. extern int pm_generic_poweroff_late(struct device *dev);
  624. extern int pm_generic_poweroff(struct device *dev);
  625. extern void pm_generic_complete(struct device *dev);
  626. #else /* !CONFIG_PM_SLEEP */
  627. #define device_pm_lock() do {} while (0)
  628. #define device_pm_unlock() do {} while (0)
  629. static inline int dpm_suspend_start(pm_message_t state)
  630. {
  631. return 0;
  632. }
  633. #define suspend_report_result(fn, ret) do {} while (0)
  634. static inline int device_pm_wait_for_dev(struct device *a, struct device *b)
  635. {
  636. return 0;
  637. }
  638. static inline void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *))
  639. {
  640. }
  641. #define pm_generic_prepare NULL
  642. #define pm_generic_suspend NULL
  643. #define pm_generic_resume NULL
  644. #define pm_generic_freeze NULL
  645. #define pm_generic_thaw NULL
  646. #define pm_generic_restore NULL
  647. #define pm_generic_poweroff NULL
  648. #define pm_generic_complete NULL
  649. #endif /* !CONFIG_PM_SLEEP */
  650. /* How to reorder dpm_list after device_move() */
  651. enum dpm_order {
  652. DPM_ORDER_NONE,
  653. DPM_ORDER_DEV_AFTER_PARENT,
  654. DPM_ORDER_PARENT_BEFORE_DEV,
  655. DPM_ORDER_DEV_LAST,
  656. };
  657. #endif /* _LINUX_PM_H */