devices.txt 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. Device Power Management
  2. Copyright (c) 2010-2011 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
  3. Copyright (c) 2010 Alan Stern <stern@rowland.harvard.edu>
  4. Most of the code in Linux is device drivers, so most of the Linux power
  5. management (PM) code is also driver-specific. Most drivers will do very
  6. little; others, especially for platforms with small batteries (like cell
  7. phones), will do a lot.
  8. This writeup gives an overview of how drivers interact with system-wide
  9. power management goals, emphasizing the models and interfaces that are
  10. shared by everything that hooks up to the driver model core. Read it as
  11. background for the domain-specific work you'd do with any specific driver.
  12. Two Models for Device Power Management
  13. ======================================
  14. Drivers will use one or both of these models to put devices into low-power
  15. states:
  16. System Sleep model:
  17. Drivers can enter low-power states as part of entering system-wide
  18. low-power states like "suspend" (also known as "suspend-to-RAM"), or
  19. (mostly for systems with disks) "hibernation" (also known as
  20. "suspend-to-disk").
  21. This is something that device, bus, and class drivers collaborate on
  22. by implementing various role-specific suspend and resume methods to
  23. cleanly power down hardware and software subsystems, then reactivate
  24. them without loss of data.
  25. Some drivers can manage hardware wakeup events, which make the system
  26. leave the low-power state. This feature may be enabled or disabled
  27. using the relevant /sys/devices/.../power/wakeup file (for Ethernet
  28. drivers the ioctl interface used by ethtool may also be used for this
  29. purpose); enabling it may cost some power usage, but let the whole
  30. system enter low-power states more often.
  31. Runtime Power Management model:
  32. Devices may also be put into low-power states while the system is
  33. running, independently of other power management activity in principle.
  34. However, devices are not generally independent of each other (for
  35. example, a parent device cannot be suspended unless all of its child
  36. devices have been suspended). Moreover, depending on the bus type the
  37. device is on, it may be necessary to carry out some bus-specific
  38. operations on the device for this purpose. Devices put into low power
  39. states at run time may require special handling during system-wide power
  40. transitions (suspend or hibernation).
  41. For these reasons not only the device driver itself, but also the
  42. appropriate subsystem (bus type, device type or device class) driver and
  43. the PM core are involved in runtime power management. As in the system
  44. sleep power management case, they need to collaborate by implementing
  45. various role-specific suspend and resume methods, so that the hardware
  46. is cleanly powered down and reactivated without data or service loss.
  47. There's not a lot to be said about those low-power states except that they are
  48. very system-specific, and often device-specific. Also, that if enough devices
  49. have been put into low-power states (at runtime), the effect may be very similar
  50. to entering some system-wide low-power state (system sleep) ... and that
  51. synergies exist, so that several drivers using runtime PM might put the system
  52. into a state where even deeper power saving options are available.
  53. Most suspended devices will have quiesced all I/O: no more DMA or IRQs (except
  54. for wakeup events), no more data read or written, and requests from upstream
  55. drivers are no longer accepted. A given bus or platform may have different
  56. requirements though.
  57. Examples of hardware wakeup events include an alarm from a real time clock,
  58. network wake-on-LAN packets, keyboard or mouse activity, and media insertion
  59. or removal (for PCMCIA, MMC/SD, USB, and so on).
  60. Interfaces for Entering System Sleep States
  61. ===========================================
  62. There are programming interfaces provided for subsystems (bus type, device type,
  63. device class) and device drivers to allow them to participate in the power
  64. management of devices they are concerned with. These interfaces cover both
  65. system sleep and runtime power management.
  66. Device Power Management Operations
  67. ----------------------------------
  68. Device power management operations, at the subsystem level as well as at the
  69. device driver level, are implemented by defining and populating objects of type
  70. struct dev_pm_ops:
  71. struct dev_pm_ops {
  72. int (*prepare)(struct device *dev);
  73. void (*complete)(struct device *dev);
  74. int (*suspend)(struct device *dev);
  75. int (*resume)(struct device *dev);
  76. int (*freeze)(struct device *dev);
  77. int (*thaw)(struct device *dev);
  78. int (*poweroff)(struct device *dev);
  79. int (*restore)(struct device *dev);
  80. int (*suspend_noirq)(struct device *dev);
  81. int (*resume_noirq)(struct device *dev);
  82. int (*freeze_noirq)(struct device *dev);
  83. int (*thaw_noirq)(struct device *dev);
  84. int (*poweroff_noirq)(struct device *dev);
  85. int (*restore_noirq)(struct device *dev);
  86. int (*runtime_suspend)(struct device *dev);
  87. int (*runtime_resume)(struct device *dev);
  88. int (*runtime_idle)(struct device *dev);
  89. };
  90. This structure is defined in include/linux/pm.h and the methods included in it
  91. are also described in that file. Their roles will be explained in what follows.
  92. For now, it should be sufficient to remember that the last three methods are
  93. specific to runtime power management while the remaining ones are used during
  94. system-wide power transitions.
  95. There also is a deprecated "old" or "legacy" interface for power management
  96. operations available at least for some subsystems. This approach does not use
  97. struct dev_pm_ops objects and it is suitable only for implementing system sleep
  98. power management methods. Therefore it is not described in this document, so
  99. please refer directly to the source code for more information about it.
  100. Subsystem-Level Methods
  101. -----------------------
  102. The core methods to suspend and resume devices reside in struct dev_pm_ops
  103. pointed to by the ops member of struct dev_pm_domain, or by the pm member of
  104. struct bus_type, struct device_type and struct class. They are mostly of
  105. interest to the people writing infrastructure for platforms and buses, like PCI
  106. or USB, or device type and device class drivers.
  107. Bus drivers implement these methods as appropriate for the hardware and the
  108. drivers using it; PCI works differently from USB, and so on. Not many people
  109. write subsystem-level drivers; most driver code is a "device driver" that builds
  110. on top of bus-specific framework code.
  111. For more information on these driver calls, see the description later;
  112. they are called in phases for every device, respecting the parent-child
  113. sequencing in the driver model tree.
  114. /sys/devices/.../power/wakeup files
  115. -----------------------------------
  116. All device objects in the driver model contain fields that control the handling
  117. of system wakeup events (hardware signals that can force the system out of a
  118. sleep state). These fields are initialized by bus or device driver code using
  119. device_set_wakeup_capable() and device_set_wakeup_enable(), defined in
  120. include/linux/pm_wakeup.h.
  121. The "power.can_wakeup" flag just records whether the device (and its driver) can
  122. physically support wakeup events. The device_set_wakeup_capable() routine
  123. affects this flag. The "power.wakeup" field is a pointer to an object of type
  124. struct wakeup_source used for controlling whether or not the device should use
  125. its system wakeup mechanism and for notifying the PM core of system wakeup
  126. events signaled by the device. This object is only present for wakeup-capable
  127. devices (i.e. devices whose "can_wakeup" flags are set) and is created (or
  128. removed) by device_set_wakeup_capable().
  129. Whether or not a device is capable of issuing wakeup events is a hardware
  130. matter, and the kernel is responsible for keeping track of it. By contrast,
  131. whether or not a wakeup-capable device should issue wakeup events is a policy
  132. decision, and it is managed by user space through a sysfs attribute: the
  133. "power/wakeup" file. User space can write the strings "enabled" or "disabled"
  134. to it to indicate whether or not, respectively, the device is supposed to signal
  135. system wakeup. This file is only present if the "power.wakeup" object exists
  136. for the given device and is created (or removed) along with that object, by
  137. device_set_wakeup_capable(). Reads from the file will return the corresponding
  138. string.
  139. The "power/wakeup" file is supposed to contain the "disabled" string initially
  140. for the majority of devices; the major exceptions are power buttons, keyboards,
  141. and Ethernet adapters whose WoL (wake-on-LAN) feature has been set up with
  142. ethtool. It should also default to "enabled" for devices that don't generate
  143. wakeup requests on their own but merely forward wakeup requests from one bus to
  144. another (like PCI Express ports).
  145. The device_may_wakeup() routine returns true only if the "power.wakeup" object
  146. exists and the corresponding "power/wakeup" file contains the string "enabled".
  147. This information is used by subsystems, like the PCI bus type code, to see
  148. whether or not to enable the devices' wakeup mechanisms. If device wakeup
  149. mechanisms are enabled or disabled directly by drivers, they also should use
  150. device_may_wakeup() to decide what to do during a system sleep transition.
  151. Device drivers, however, are not supposed to call device_set_wakeup_enable()
  152. directly in any case.
  153. It ought to be noted that system wakeup is conceptually different from "remote
  154. wakeup" used by runtime power management, although it may be supported by the
  155. same physical mechanism. Remote wakeup is a feature allowing devices in
  156. low-power states to trigger specific interrupts to signal conditions in which
  157. they should be put into the full-power state. Those interrupts may or may not
  158. be used to signal system wakeup events, depending on the hardware design. On
  159. some systems it is impossible to trigger them from system sleep states. In any
  160. case, remote wakeup should always be enabled for runtime power management for
  161. all devices and drivers that support it.
  162. /sys/devices/.../power/control files
  163. ------------------------------------
  164. Each device in the driver model has a flag to control whether it is subject to
  165. runtime power management. This flag, called runtime_auto, is initialized by the
  166. bus type (or generally subsystem) code using pm_runtime_allow() or
  167. pm_runtime_forbid(); the default is to allow runtime power management.
  168. The setting can be adjusted by user space by writing either "on" or "auto" to
  169. the device's power/control sysfs file. Writing "auto" calls pm_runtime_allow(),
  170. setting the flag and allowing the device to be runtime power-managed by its
  171. driver. Writing "on" calls pm_runtime_forbid(), clearing the flag, returning
  172. the device to full power if it was in a low-power state, and preventing the
  173. device from being runtime power-managed. User space can check the current value
  174. of the runtime_auto flag by reading the file.
  175. The device's runtime_auto flag has no effect on the handling of system-wide
  176. power transitions. In particular, the device can (and in the majority of cases
  177. should and will) be put into a low-power state during a system-wide transition
  178. to a sleep state even though its runtime_auto flag is clear.
  179. For more information about the runtime power management framework, refer to
  180. Documentation/power/runtime_pm.txt.
  181. Calling Drivers to Enter and Leave System Sleep States
  182. ======================================================
  183. When the system goes into a sleep state, each device's driver is asked to
  184. suspend the device by putting it into a state compatible with the target
  185. system state. That's usually some version of "off", but the details are
  186. system-specific. Also, wakeup-enabled devices will usually stay partly
  187. functional in order to wake the system.
  188. When the system leaves that low-power state, the device's driver is asked to
  189. resume it by returning it to full power. The suspend and resume operations
  190. always go together, and both are multi-phase operations.
  191. For simple drivers, suspend might quiesce the device using class code
  192. and then turn its hardware as "off" as possible during suspend_noirq. The
  193. matching resume calls would then completely reinitialize the hardware
  194. before reactivating its class I/O queues.
  195. More power-aware drivers might prepare the devices for triggering system wakeup
  196. events.
  197. Call Sequence Guarantees
  198. ------------------------
  199. To ensure that bridges and similar links needing to talk to a device are
  200. available when the device is suspended or resumed, the device tree is
  201. walked in a bottom-up order to suspend devices. A top-down order is
  202. used to resume those devices.
  203. The ordering of the device tree is defined by the order in which devices
  204. get registered: a child can never be registered, probed or resumed before
  205. its parent; and can't be removed or suspended after that parent.
  206. The policy is that the device tree should match hardware bus topology.
  207. (Or at least the control bus, for devices which use multiple busses.)
  208. In particular, this means that a device registration may fail if the parent of
  209. the device is suspending (i.e. has been chosen by the PM core as the next
  210. device to suspend) or has already suspended, as well as after all of the other
  211. devices have been suspended. Device drivers must be prepared to cope with such
  212. situations.
  213. System Power Management Phases
  214. ------------------------------
  215. Suspending or resuming the system is done in several phases. Different phases
  216. are used for standby or memory sleep states ("suspend-to-RAM") and the
  217. hibernation state ("suspend-to-disk"). Each phase involves executing callbacks
  218. for every device before the next phase begins. Not all busses or classes
  219. support all these callbacks and not all drivers use all the callbacks. The
  220. various phases always run after tasks have been frozen and before they are
  221. unfrozen. Furthermore, the *_noirq phases run at a time when IRQ handlers have
  222. been disabled (except for those marked with the IRQF_NO_SUSPEND flag).
  223. All phases use PM domain, bus, type, or class callbacks (that is, methods
  224. defined in dev->pm_domain->ops, dev->bus->pm, dev->type->pm, or dev->class->pm).
  225. These callbacks are regarded by the PM core as mutually exclusive. Moreover,
  226. PM domain callbacks always take precedence over bus, type and class callbacks,
  227. while type callbacks take precedence over bus and class callbacks, and class
  228. callbacks take precedence over bus callbacks. To be precise, the following
  229. rules are used to determine which callback to execute in the given phase:
  230. 1. If dev->pm_domain is present, the PM core will attempt to execute the
  231. callback included in dev->pm_domain->ops. If that callback is not
  232. present, no action will be carried out for the given device.
  233. 2. Otherwise, if both dev->type and dev->type->pm are present, the callback
  234. included in dev->type->pm will be executed.
  235. 3. Otherwise, if both dev->class and dev->class->pm are present, the
  236. callback included in dev->class->pm will be executed.
  237. 4. Otherwise, if both dev->bus and dev->bus->pm are present, the callback
  238. included in dev->bus->pm will be executed.
  239. This allows PM domains and device types to override callbacks provided by bus
  240. types or device classes if necessary.
  241. These callbacks may in turn invoke device- or driver-specific methods stored in
  242. dev->driver->pm, but they don't have to.
  243. Entering System Suspend
  244. -----------------------
  245. When the system goes into the standby or memory sleep state, the phases are:
  246. prepare, suspend, suspend_noirq.
  247. 1. The prepare phase is meant to prevent races by preventing new devices
  248. from being registered; the PM core would never know that all the
  249. children of a device had been suspended if new children could be
  250. registered at will. (By contrast, devices may be unregistered at any
  251. time.) Unlike the other suspend-related phases, during the prepare
  252. phase the device tree is traversed top-down.
  253. After the prepare callback method returns, no new children may be
  254. registered below the device. The method may also prepare the device or
  255. driver in some way for the upcoming system power transition, but it
  256. should not put the device into a low-power state.
  257. 2. The suspend methods should quiesce the device to stop it from performing
  258. I/O. They also may save the device registers and put it into the
  259. appropriate low-power state, depending on the bus type the device is on,
  260. and they may enable wakeup events.
  261. 3. The suspend_noirq phase occurs after IRQ handlers have been disabled,
  262. which means that the driver's interrupt handler will not be called while
  263. the callback method is running. The methods should save the values of
  264. the device's registers that weren't saved previously and finally put the
  265. device into the appropriate low-power state.
  266. The majority of subsystems and device drivers need not implement this
  267. callback. However, bus types allowing devices to share interrupt
  268. vectors, like PCI, generally need it; otherwise a driver might encounter
  269. an error during the suspend phase by fielding a shared interrupt
  270. generated by some other device after its own device had been set to low
  271. power.
  272. At the end of these phases, drivers should have stopped all I/O transactions
  273. (DMA, IRQs), saved enough state that they can re-initialize or restore previous
  274. state (as needed by the hardware), and placed the device into a low-power state.
  275. On many platforms they will gate off one or more clock sources; sometimes they
  276. will also switch off power supplies or reduce voltages. (Drivers supporting
  277. runtime PM may already have performed some or all of these steps.)
  278. If device_may_wakeup(dev) returns true, the device should be prepared for
  279. generating hardware wakeup signals to trigger a system wakeup event when the
  280. system is in the sleep state. For example, enable_irq_wake() might identify
  281. GPIO signals hooked up to a switch or other external hardware, and
  282. pci_enable_wake() does something similar for the PCI PME signal.
  283. If any of these callbacks returns an error, the system won't enter the desired
  284. low-power state. Instead the PM core will unwind its actions by resuming all
  285. the devices that were suspended.
  286. Leaving System Suspend
  287. ----------------------
  288. When resuming from standby or memory sleep, the phases are:
  289. resume_noirq, resume, complete.
  290. 1. The resume_noirq callback methods should perform any actions needed
  291. before the driver's interrupt handlers are invoked. This generally
  292. means undoing the actions of the suspend_noirq phase. If the bus type
  293. permits devices to share interrupt vectors, like PCI, the method should
  294. bring the device and its driver into a state in which the driver can
  295. recognize if the device is the source of incoming interrupts, if any,
  296. and handle them correctly.
  297. For example, the PCI bus type's ->pm.resume_noirq() puts the device into
  298. the full-power state (D0 in the PCI terminology) and restores the
  299. standard configuration registers of the device. Then it calls the
  300. device driver's ->pm.resume_noirq() method to perform device-specific
  301. actions.
  302. 2. The resume methods should bring the the device back to its operating
  303. state, so that it can perform normal I/O. This generally involves
  304. undoing the actions of the suspend phase.
  305. 3. The complete phase uses only a bus callback. The method should undo the
  306. actions of the prepare phase. Note, however, that new children may be
  307. registered below the device as soon as the resume callbacks occur; it's
  308. not necessary to wait until the complete phase.
  309. At the end of these phases, drivers should be as functional as they were before
  310. suspending: I/O can be performed using DMA and IRQs, and the relevant clocks are
  311. gated on. Even if the device was in a low-power state before the system sleep
  312. because of runtime power management, afterwards it should be back in its
  313. full-power state. There are multiple reasons why it's best to do this; they are
  314. discussed in more detail in Documentation/power/runtime_pm.txt.
  315. However, the details here may again be platform-specific. For example,
  316. some systems support multiple "run" states, and the mode in effect at
  317. the end of resume might not be the one which preceded suspension.
  318. That means availability of certain clocks or power supplies changed,
  319. which could easily affect how a driver works.
  320. Drivers need to be able to handle hardware which has been reset since the
  321. suspend methods were called, for example by complete reinitialization.
  322. This may be the hardest part, and the one most protected by NDA'd documents
  323. and chip errata. It's simplest if the hardware state hasn't changed since
  324. the suspend was carried out, but that can't be guaranteed (in fact, it usually
  325. is not the case).
  326. Drivers must also be prepared to notice that the device has been removed
  327. while the system was powered down, whenever that's physically possible.
  328. PCMCIA, MMC, USB, Firewire, SCSI, and even IDE are common examples of busses
  329. where common Linux platforms will see such removal. Details of how drivers
  330. will notice and handle such removals are currently bus-specific, and often
  331. involve a separate thread.
  332. These callbacks may return an error value, but the PM core will ignore such
  333. errors since there's nothing it can do about them other than printing them in
  334. the system log.
  335. Entering Hibernation
  336. --------------------
  337. Hibernating the system is more complicated than putting it into the standby or
  338. memory sleep state, because it involves creating and saving a system image.
  339. Therefore there are more phases for hibernation, with a different set of
  340. callbacks. These phases always run after tasks have been frozen and memory has
  341. been freed.
  342. The general procedure for hibernation is to quiesce all devices (freeze), create
  343. an image of the system memory while everything is stable, reactivate all
  344. devices (thaw), write the image to permanent storage, and finally shut down the
  345. system (poweroff). The phases used to accomplish this are:
  346. prepare, freeze, freeze_noirq, thaw_noirq, thaw, complete,
  347. prepare, poweroff, poweroff_noirq
  348. 1. The prepare phase is discussed in the "Entering System Suspend" section
  349. above.
  350. 2. The freeze methods should quiesce the device so that it doesn't generate
  351. IRQs or DMA, and they may need to save the values of device registers.
  352. However the device does not have to be put in a low-power state, and to
  353. save time it's best not to do so. Also, the device should not be
  354. prepared to generate wakeup events.
  355. 3. The freeze_noirq phase is analogous to the suspend_noirq phase discussed
  356. above, except again that the device should not be put in a low-power
  357. state and should not be allowed to generate wakeup events.
  358. At this point the system image is created. All devices should be inactive and
  359. the contents of memory should remain undisturbed while this happens, so that the
  360. image forms an atomic snapshot of the system state.
  361. 4. The thaw_noirq phase is analogous to the resume_noirq phase discussed
  362. above. The main difference is that its methods can assume the device is
  363. in the same state as at the end of the freeze_noirq phase.
  364. 5. The thaw phase is analogous to the resume phase discussed above. Its
  365. methods should bring the device back to an operating state, so that it
  366. can be used for saving the image if necessary.
  367. 6. The complete phase is discussed in the "Leaving System Suspend" section
  368. above.
  369. At this point the system image is saved, and the devices then need to be
  370. prepared for the upcoming system shutdown. This is much like suspending them
  371. before putting the system into the standby or memory sleep state, and the phases
  372. are similar.
  373. 7. The prepare phase is discussed above.
  374. 8. The poweroff phase is analogous to the suspend phase.
  375. 9. The poweroff_noirq phase is analogous to the suspend_noirq phase.
  376. The poweroff and poweroff_noirq callbacks should do essentially the same things
  377. as the suspend and suspend_noirq callbacks. The only notable difference is that
  378. they need not store the device register values, because the registers should
  379. already have been stored during the freeze or freeze_noirq phases.
  380. Leaving Hibernation
  381. -------------------
  382. Resuming from hibernation is, again, more complicated than resuming from a sleep
  383. state in which the contents of main memory are preserved, because it requires
  384. a system image to be loaded into memory and the pre-hibernation memory contents
  385. to be restored before control can be passed back to the image kernel.
  386. Although in principle, the image might be loaded into memory and the
  387. pre-hibernation memory contents restored by the boot loader, in practice this
  388. can't be done because boot loaders aren't smart enough and there is no
  389. established protocol for passing the necessary information. So instead, the
  390. boot loader loads a fresh instance of the kernel, called the boot kernel, into
  391. memory and passes control to it in the usual way. Then the boot kernel reads
  392. the system image, restores the pre-hibernation memory contents, and passes
  393. control to the image kernel. Thus two different kernels are involved in
  394. resuming from hibernation. In fact, the boot kernel may be completely different
  395. from the image kernel: a different configuration and even a different version.
  396. This has important consequences for device drivers and their subsystems.
  397. To be able to load the system image into memory, the boot kernel needs to
  398. include at least a subset of device drivers allowing it to access the storage
  399. medium containing the image, although it doesn't need to include all of the
  400. drivers present in the image kernel. After the image has been loaded, the
  401. devices managed by the boot kernel need to be prepared for passing control back
  402. to the image kernel. This is very similar to the initial steps involved in
  403. creating a system image, and it is accomplished in the same way, using prepare,
  404. freeze, and freeze_noirq phases. However the devices affected by these phases
  405. are only those having drivers in the boot kernel; other devices will still be in
  406. whatever state the boot loader left them.
  407. Should the restoration of the pre-hibernation memory contents fail, the boot
  408. kernel would go through the "thawing" procedure described above, using the
  409. thaw_noirq, thaw, and complete phases, and then continue running normally. This
  410. happens only rarely. Most often the pre-hibernation memory contents are
  411. restored successfully and control is passed to the image kernel, which then
  412. becomes responsible for bringing the system back to the working state.
  413. To achieve this, the image kernel must restore the devices' pre-hibernation
  414. functionality. The operation is much like waking up from the memory sleep
  415. state, although it involves different phases:
  416. restore_noirq, restore, complete
  417. 1. The restore_noirq phase is analogous to the resume_noirq phase.
  418. 2. The restore phase is analogous to the resume phase.
  419. 3. The complete phase is discussed above.
  420. The main difference from resume[_noirq] is that restore[_noirq] must assume the
  421. device has been accessed and reconfigured by the boot loader or the boot kernel.
  422. Consequently the state of the device may be different from the state remembered
  423. from the freeze and freeze_noirq phases. The device may even need to be reset
  424. and completely re-initialized. In many cases this difference doesn't matter, so
  425. the resume[_noirq] and restore[_norq] method pointers can be set to the same
  426. routines. Nevertheless, different callback pointers are used in case there is a
  427. situation where it actually matters.
  428. Device Power Management Domains
  429. -------------------------------
  430. Sometimes devices share reference clocks or other power resources. In those
  431. cases it generally is not possible to put devices into low-power states
  432. individually. Instead, a set of devices sharing a power resource can be put
  433. into a low-power state together at the same time by turning off the shared
  434. power resource. Of course, they also need to be put into the full-power state
  435. together, by turning the shared power resource on. A set of devices with this
  436. property is often referred to as a power domain.
  437. Support for power domains is provided through the pm_domain field of struct
  438. device. This field is a pointer to an object of type struct dev_pm_domain,
  439. defined in include/linux/pm.h, providing a set of power management callbacks
  440. analogous to the subsystem-level and device driver callbacks that are executed
  441. for the given device during all power transitions, instead of the respective
  442. subsystem-level callbacks. Specifically, if a device's pm_domain pointer is
  443. not NULL, the ->suspend() callback from the object pointed to by it will be
  444. executed instead of its subsystem's (e.g. bus type's) ->suspend() callback and
  445. anlogously for all of the remaining callbacks. In other words, power management
  446. domain callbacks, if defined for the given device, always take precedence over
  447. the callbacks provided by the device's subsystem (e.g. bus type).
  448. The support for device power management domains is only relevant to platforms
  449. needing to use the same device driver power management callbacks in many
  450. different power domain configurations and wanting to avoid incorporating the
  451. support for power domains into subsystem-level callbacks, for example by
  452. modifying the platform bus type. Other platforms need not implement it or take
  453. it into account in any way.
  454. Device Low Power (suspend) States
  455. ---------------------------------
  456. Device low-power states aren't standard. One device might only handle
  457. "on" and "off, while another might support a dozen different versions of
  458. "on" (how many engines are active?), plus a state that gets back to "on"
  459. faster than from a full "off".
  460. Some busses define rules about what different suspend states mean. PCI
  461. gives one example: after the suspend sequence completes, a non-legacy
  462. PCI device may not perform DMA or issue IRQs, and any wakeup events it
  463. issues would be issued through the PME# bus signal. Plus, there are
  464. several PCI-standard device states, some of which are optional.
  465. In contrast, integrated system-on-chip processors often use IRQs as the
  466. wakeup event sources (so drivers would call enable_irq_wake) and might
  467. be able to treat DMA completion as a wakeup event (sometimes DMA can stay
  468. active too, it'd only be the CPU and some peripherals that sleep).
  469. Some details here may be platform-specific. Systems may have devices that
  470. can be fully active in certain sleep states, such as an LCD display that's
  471. refreshed using DMA while most of the system is sleeping lightly ... and
  472. its frame buffer might even be updated by a DSP or other non-Linux CPU while
  473. the Linux control processor stays idle.
  474. Moreover, the specific actions taken may depend on the target system state.
  475. One target system state might allow a given device to be very operational;
  476. another might require a hard shut down with re-initialization on resume.
  477. And two different target systems might use the same device in different
  478. ways; the aforementioned LCD might be active in one product's "standby",
  479. but a different product using the same SOC might work differently.
  480. Power Management Notifiers
  481. --------------------------
  482. There are some operations that cannot be carried out by the power management
  483. callbacks discussed above, because the callbacks occur too late or too early.
  484. To handle these cases, subsystems and device drivers may register power
  485. management notifiers that are called before tasks are frozen and after they have
  486. been thawed. Generally speaking, the PM notifiers are suitable for performing
  487. actions that either require user space to be available, or at least won't
  488. interfere with user space.
  489. For details refer to Documentation/power/notifiers.txt.
  490. Runtime Power Management
  491. ========================
  492. Many devices are able to dynamically power down while the system is still
  493. running. This feature is useful for devices that are not being used, and
  494. can offer significant power savings on a running system. These devices
  495. often support a range of runtime power states, which might use names such
  496. as "off", "sleep", "idle", "active", and so on. Those states will in some
  497. cases (like PCI) be partially constrained by the bus the device uses, and will
  498. usually include hardware states that are also used in system sleep states.
  499. A system-wide power transition can be started while some devices are in low
  500. power states due to runtime power management. The system sleep PM callbacks
  501. should recognize such situations and react to them appropriately, but the
  502. necessary actions are subsystem-specific.
  503. In some cases the decision may be made at the subsystem level while in other
  504. cases the device driver may be left to decide. In some cases it may be
  505. desirable to leave a suspended device in that state during a system-wide power
  506. transition, but in other cases the device must be put back into the full-power
  507. state temporarily, for example so that its system wakeup capability can be
  508. disabled. This all depends on the hardware and the design of the subsystem and
  509. device driver in question.
  510. During system-wide resume from a sleep state it's easiest to put devices into
  511. the full-power state, as explained in Documentation/power/runtime_pm.txt. Refer
  512. to that document for more information regarding this particular issue as well as
  513. for information on the device runtime power management framework in general.