pm.h 26 KB

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