pci.txt 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  1. PCI Power Management
  2. Copyright (c) 2010 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
  3. An overview of concepts and the Linux kernel's interfaces related to PCI power
  4. management. Based on previous work by Patrick Mochel <mochel@transmeta.com>
  5. (and others).
  6. This document only covers the aspects of power management specific to PCI
  7. devices. For general description of the kernel's interfaces related to device
  8. power management refer to Documentation/power/devices.txt and
  9. Documentation/power/runtime_pm.txt.
  10. ---------------------------------------------------------------------------
  11. 1. Hardware and Platform Support for PCI Power Management
  12. 2. PCI Subsystem and Device Power Management
  13. 3. PCI Device Drivers and Power Management
  14. 4. Resources
  15. 1. Hardware and Platform Support for PCI Power Management
  16. =========================================================
  17. 1.1. Native and Platform-Based Power Management
  18. -----------------------------------------------
  19. In general, power management is a feature allowing one to save energy by putting
  20. devices into states in which they draw less power (low-power states) at the
  21. price of reduced functionality or performance.
  22. Usually, a device is put into a low-power state when it is underutilized or
  23. completely inactive. However, when it is necessary to use the device once
  24. again, it has to be put back into the "fully functional" state (full-power
  25. state). This may happen when there are some data for the device to handle or
  26. as a result of an external event requiring the device to be active, which may
  27. be signaled by the device itself.
  28. PCI devices may be put into low-power states in two ways, by using the device
  29. capabilities introduced by the PCI Bus Power Management Interface Specification,
  30. or with the help of platform firmware, such as an ACPI BIOS. In the first
  31. approach, that is referred to as the native PCI power management (native PCI PM)
  32. in what follows, the device power state is changed as a result of writing a
  33. specific value into one of its standard configuration registers. The second
  34. approach requires the platform firmware to provide special methods that may be
  35. used by the kernel to change the device's power state.
  36. Devices supporting the native PCI PM usually can generate wakeup signals called
  37. Power Management Events (PMEs) to let the kernel know about external events
  38. requiring the device to be active. After receiving a PME the kernel is supposed
  39. to put the device that sent it into the full-power state. However, the PCI Bus
  40. Power Management Interface Specification doesn't define any standard method of
  41. delivering the PME from the device to the CPU and the operating system kernel.
  42. It is assumed that the platform firmware will perform this task and therefore,
  43. even though a PCI device is set up to generate PMEs, it also may be necessary to
  44. prepare the platform firmware for notifying the CPU of the PMEs coming from the
  45. device (e.g. by generating interrupts).
  46. In turn, if the methods provided by the platform firmware are used for changing
  47. the power state of a device, usually the platform also provides a method for
  48. preparing the device to generate wakeup signals. In that case, however, it
  49. often also is necessary to prepare the device for generating PMEs using the
  50. native PCI PM mechanism, because the method provided by the platform depends on
  51. that.
  52. Thus in many situations both the native and the platform-based power management
  53. mechanisms have to be used simultaneously to obtain the desired result.
  54. 1.2. Native PCI Power Management
  55. --------------------------------
  56. The PCI Bus Power Management Interface Specification (PCI PM Spec) was
  57. introduced between the PCI 2.1 and PCI 2.2 Specifications. It defined a
  58. standard interface for performing various operations related to power
  59. management.
  60. The implementation of the PCI PM Spec is optional for conventional PCI devices,
  61. but it is mandatory for PCI Express devices. If a device supports the PCI PM
  62. Spec, it has an 8 byte power management capability field in its PCI
  63. configuration space. This field is used to describe and control the standard
  64. features related to the native PCI power management.
  65. The PCI PM Spec defines 4 operating states for devices (D0-D3) and for buses
  66. (B0-B3). The higher the number, the less power is drawn by the device or bus
  67. in that state. However, the higher the number, the longer the latency for
  68. the device or bus to return to the full-power state (D0 or B0, respectively).
  69. There are two variants of the D3 state defined by the specification. The first
  70. one is D3hot, referred to as the software accessible D3, because devices can be
  71. programmed to go into it. The second one, D3cold, is the state that PCI devices
  72. are in when the supply voltage (Vcc) is removed from them. It is not possible
  73. to program a PCI device to go into D3cold, although there may be a programmable
  74. interface for putting the bus the device is on into a state in which Vcc is
  75. removed from all devices on the bus.
  76. PCI bus power management, however, is not supported by the Linux kernel at the
  77. time of this writing and therefore it is not covered by this document.
  78. Note that every PCI device can be in the full-power state (D0) or in D3cold,
  79. regardless of whether or not it implements the PCI PM Spec. In addition to
  80. that, if the PCI PM Spec is implemented by the device, it must support D3hot
  81. as well as D0. The support for the D1 and D2 power states is optional.
  82. PCI devices supporting the PCI PM Spec can be programmed to go to any of the
  83. supported low-power states (except for D3cold). While in D1-D3hot the
  84. standard configuration registers of the device must be accessible to software
  85. (i.e. the device is required to respond to PCI configuration accesses), although
  86. its I/O and memory spaces are then disabled. This allows the device to be
  87. programmatically put into D0. Thus the kernel can switch the device back and
  88. forth between D0 and the supported low-power states (except for D3cold) and the
  89. possible power state transitions the device can undergo are the following:
  90. +----------------------------+
  91. | Current State | New State |
  92. +----------------------------+
  93. | D0 | D1, D2, D3 |
  94. +----------------------------+
  95. | D1 | D2, D3 |
  96. +----------------------------+
  97. | D2 | D3 |
  98. +----------------------------+
  99. | D1, D2, D3 | D0 |
  100. +----------------------------+
  101. The transition from D3cold to D0 occurs when the supply voltage is provided to
  102. the device (i.e. power is restored). In that case the device returns to D0 with
  103. a full power-on reset sequence and the power-on defaults are restored to the
  104. device by hardware just as at initial power up.
  105. PCI devices supporting the PCI PM Spec can be programmed to generate PMEs
  106. while in a low-power state (D1-D3), but they are not required to be capable
  107. of generating PMEs from all supported low-power states. In particular, the
  108. capability of generating PMEs from D3cold is optional and depends on the
  109. presence of additional voltage (3.3Vaux) allowing the device to remain
  110. sufficiently active to generate a wakeup signal.
  111. 1.3. ACPI Device Power Management
  112. ---------------------------------
  113. The platform firmware support for the power management of PCI devices is
  114. system-specific. However, if the system in question is compliant with the
  115. Advanced Configuration and Power Interface (ACPI) Specification, like the
  116. majority of x86-based systems, it is supposed to implement device power
  117. management interfaces defined by the ACPI standard.
  118. For this purpose the ACPI BIOS provides special functions called "control
  119. methods" that may be executed by the kernel to perform specific tasks, such as
  120. putting a device into a low-power state. These control methods are encoded
  121. using special byte-code language called the ACPI Machine Language (AML) and
  122. stored in the machine's BIOS. The kernel loads them from the BIOS and executes
  123. them as needed using an AML interpreter that translates the AML byte code into
  124. computations and memory or I/O space accesses. This way, in theory, a BIOS
  125. writer can provide the kernel with a means to perform actions depending
  126. on the system design in a system-specific fashion.
  127. ACPI control methods may be divided into global control methods, that are not
  128. associated with any particular devices, and device control methods, that have
  129. to be defined separately for each device supposed to be handled with the help of
  130. the platform. This means, in particular, that ACPI device control methods can
  131. only be used to handle devices that the BIOS writer knew about in advance. The
  132. ACPI methods used for device power management fall into that category.
  133. The ACPI specification assumes that devices can be in one of four power states
  134. labeled as D0, D1, D2, and D3 that roughly correspond to the native PCI PM
  135. D0-D3 states (although the difference between D3hot and D3cold is not taken
  136. into account by ACPI). Moreover, for each power state of a device there is a
  137. set of power resources that have to be enabled for the device to be put into
  138. that state. These power resources are controlled (i.e. enabled or disabled)
  139. with the help of their own control methods, _ON and _OFF, that have to be
  140. defined individually for each of them.
  141. To put a device into the ACPI power state Dx (where x is a number between 0 and
  142. 3 inclusive) the kernel is supposed to (1) enable the power resources required
  143. by the device in this state using their _ON control methods and (2) execute the
  144. _PSx control method defined for the device. In addition to that, if the device
  145. is going to be put into a low-power state (D1-D3) and is supposed to generate
  146. wakeup signals from that state, the _DSW (or _PSW, replaced with _DSW by ACPI
  147. 3.0) control method defined for it has to be executed before _PSx. Power
  148. resources that are not required by the device in the target power state and are
  149. not required any more by any other device should be disabled (by executing their
  150. _OFF control methods). If the current power state of the device is D3, it can
  151. only be put into D0 this way.
  152. However, quite often the power states of devices are changed during a
  153. system-wide transition into a sleep state or back into the working state. ACPI
  154. defines four system sleep states, S1, S2, S3, and S4, and denotes the system
  155. working state as S0. In general, the target system sleep (or working) state
  156. determines the highest power (lowest number) state the device can be put
  157. into and the kernel is supposed to obtain this information by executing the
  158. device's _SxD control method (where x is a number between 0 and 4 inclusive).
  159. If the device is required to wake up the system from the target sleep state, the
  160. lowest power (highest number) state it can be put into is also determined by the
  161. target state of the system. The kernel is then supposed to use the device's
  162. _SxW control method to obtain the number of that state. It also is supposed to
  163. use the device's _PRW control method to learn which power resources need to be
  164. enabled for the device to be able to generate wakeup signals.
  165. 1.4. Wakeup Signaling
  166. ---------------------
  167. Wakeup signals generated by PCI devices, either as native PCI PMEs, or as
  168. a result of the execution of the _DSW (or _PSW) ACPI control method before
  169. putting the device into a low-power state, have to be caught and handled as
  170. appropriate. If they are sent while the system is in the working state
  171. (ACPI S0), they should be translated into interrupts so that the kernel can
  172. put the devices generating them into the full-power state and take care of the
  173. events that triggered them. In turn, if they are sent while the system is
  174. sleeping, they should cause the system's core logic to trigger wakeup.
  175. On ACPI-based systems wakeup signals sent by conventional PCI devices are
  176. converted into ACPI General-Purpose Events (GPEs) which are hardware signals
  177. from the system core logic generated in response to various events that need to
  178. be acted upon. Every GPE is associated with one or more sources of potentially
  179. interesting events. In particular, a GPE may be associated with a PCI device
  180. capable of signaling wakeup. The information on the connections between GPEs
  181. and event sources is recorded in the system's ACPI BIOS from where it can be
  182. read by the kernel.
  183. If a PCI device known to the system's ACPI BIOS signals wakeup, the GPE
  184. associated with it (if there is one) is triggered. The GPEs associated with PCI
  185. bridges may also be triggered in response to a wakeup signal from one of the
  186. devices below the bridge (this also is the case for root bridges) and, for
  187. example, native PCI PMEs from devices unknown to the system's ACPI BIOS may be
  188. handled this way.
  189. A GPE may be triggered when the system is sleeping (i.e. when it is in one of
  190. the ACPI S1-S4 states), in which case system wakeup is started by its core logic
  191. (the device that was the source of the signal causing the system wakeup to occur
  192. may be identified later). The GPEs used in such situations are referred to as
  193. wakeup GPEs.
  194. Usually, however, GPEs are also triggered when the system is in the working
  195. state (ACPI S0) and in that case the system's core logic generates a System
  196. Control Interrupt (SCI) to notify the kernel of the event. Then, the SCI
  197. handler identifies the GPE that caused the interrupt to be generated which,
  198. in turn, allows the kernel to identify the source of the event (that may be
  199. a PCI device signaling wakeup). The GPEs used for notifying the kernel of
  200. events occurring while the system is in the working state are referred to as
  201. runtime GPEs.
  202. Unfortunately, there is no standard way of handling wakeup signals sent by
  203. conventional PCI devices on systems that are not ACPI-based, but there is one
  204. for PCI Express devices. Namely, the PCI Express Base Specification introduced
  205. a native mechanism for converting native PCI PMEs into interrupts generated by
  206. root ports. For conventional PCI devices native PMEs are out-of-band, so they
  207. are routed separately and they need not pass through bridges (in principle they
  208. may be routed directly to the system's core logic), but for PCI Express devices
  209. they are in-band messages that have to pass through the PCI Express hierarchy,
  210. including the root port on the path from the device to the Root Complex. Thus
  211. it was possible to introduce a mechanism by which a root port generates an
  212. interrupt whenever it receives a PME message from one of the devices below it.
  213. The PCI Express Requester ID of the device that sent the PME message is then
  214. recorded in one of the root port's configuration registers from where it may be
  215. read by the interrupt handler allowing the device to be identified. [PME
  216. messages sent by PCI Express endpoints integrated with the Root Complex don't
  217. pass through root ports, but instead they cause a Root Complex Event Collector
  218. (if there is one) to generate interrupts.]
  219. In principle the native PCI Express PME signaling may also be used on ACPI-based
  220. systems along with the GPEs, but to use it the kernel has to ask the system's
  221. ACPI BIOS to release control of root port configuration registers. The ACPI
  222. BIOS, however, is not required to allow the kernel to control these registers
  223. and if it doesn't do that, the kernel must not modify their contents. Of course
  224. the native PCI Express PME signaling cannot be used by the kernel in that case.
  225. 2. PCI Subsystem and Device Power Management
  226. ============================================
  227. 2.1. Device Power Management Callbacks
  228. --------------------------------------
  229. The PCI Subsystem participates in the power management of PCI devices in a
  230. number of ways. First of all, it provides an intermediate code layer between
  231. the device power management core (PM core) and PCI device drivers.
  232. Specifically, the pm field of the PCI subsystem's struct bus_type object,
  233. pci_bus_type, points to a struct dev_pm_ops object, pci_dev_pm_ops, containing
  234. pointers to several device power management callbacks:
  235. const struct dev_pm_ops pci_dev_pm_ops = {
  236. .prepare = pci_pm_prepare,
  237. .complete = pci_pm_complete,
  238. .suspend = pci_pm_suspend,
  239. .resume = pci_pm_resume,
  240. .freeze = pci_pm_freeze,
  241. .thaw = pci_pm_thaw,
  242. .poweroff = pci_pm_poweroff,
  243. .restore = pci_pm_restore,
  244. .suspend_noirq = pci_pm_suspend_noirq,
  245. .resume_noirq = pci_pm_resume_noirq,
  246. .freeze_noirq = pci_pm_freeze_noirq,
  247. .thaw_noirq = pci_pm_thaw_noirq,
  248. .poweroff_noirq = pci_pm_poweroff_noirq,
  249. .restore_noirq = pci_pm_restore_noirq,
  250. .runtime_suspend = pci_pm_runtime_suspend,
  251. .runtime_resume = pci_pm_runtime_resume,
  252. .runtime_idle = pci_pm_runtime_idle,
  253. };
  254. These callbacks are executed by the PM core in various situations related to
  255. device power management and they, in turn, execute power management callbacks
  256. provided by PCI device drivers. They also perform power management operations
  257. involving some standard configuration registers of PCI devices that device
  258. drivers need not know or care about.
  259. The structure representing a PCI device, struct pci_dev, contains several fields
  260. that these callbacks operate on:
  261. struct pci_dev {
  262. ...
  263. pci_power_t current_state; /* Current operating state. */
  264. int pm_cap; /* PM capability offset in the
  265. configuration space */
  266. unsigned int pme_support:5; /* Bitmask of states from which PME#
  267. can be generated */
  268. unsigned int pme_interrupt:1;/* Is native PCIe PME signaling used? */
  269. unsigned int d1_support:1; /* Low power state D1 is supported */
  270. unsigned int d2_support:1; /* Low power state D2 is supported */
  271. unsigned int no_d1d2:1; /* D1 and D2 are forbidden */
  272. unsigned int wakeup_prepared:1; /* Device prepared for wake up */
  273. unsigned int d3_delay; /* D3->D0 transition time in ms */
  274. ...
  275. };
  276. They also indirectly use some fields of the struct device that is embedded in
  277. struct pci_dev.
  278. 2.2. Device Initialization
  279. --------------------------
  280. The PCI subsystem's first task related to device power management is to
  281. prepare the device for power management and initialize the fields of struct
  282. pci_dev used for this purpose. This happens in two functions defined in
  283. drivers/pci/pci.c, pci_pm_init() and platform_pci_wakeup_init().
  284. The first of these functions checks if the device supports native PCI PM
  285. and if that's the case the offset of its power management capability structure
  286. in the configuration space is stored in the pm_cap field of the device's struct
  287. pci_dev object. Next, the function checks which PCI low-power states are
  288. supported by the device and from which low-power states the device can generate
  289. native PCI PMEs. The power management fields of the device's struct pci_dev and
  290. the struct device embedded in it are updated accordingly and the generation of
  291. PMEs by the device is disabled.
  292. The second function checks if the device can be prepared to signal wakeup with
  293. the help of the platform firmware, such as the ACPI BIOS. If that is the case,
  294. the function updates the wakeup fields in struct device embedded in the
  295. device's struct pci_dev and uses the firmware-provided method to prevent the
  296. device from signaling wakeup.
  297. At this point the device is ready for power management. For driverless devices,
  298. however, this functionality is limited to a few basic operations carried out
  299. during system-wide transitions to a sleep state and back to the working state.
  300. 2.3. Runtime Device Power Management
  301. ------------------------------------
  302. The PCI subsystem plays a vital role in the runtime power management of PCI
  303. devices. For this purpose it uses the general runtime power management
  304. (runtime PM) framework described in Documentation/power/runtime_pm.txt.
  305. Namely, it provides subsystem-level callbacks:
  306. pci_pm_runtime_suspend()
  307. pci_pm_runtime_resume()
  308. pci_pm_runtime_idle()
  309. that are executed by the core runtime PM routines. It also implements the
  310. entire mechanics necessary for handling runtime wakeup signals from PCI devices
  311. in low-power states, which at the time of this writing works for both the native
  312. PCI Express PME signaling and the ACPI GPE-based wakeup signaling described in
  313. Section 1.
  314. First, a PCI device is put into a low-power state, or suspended, with the help
  315. of pm_schedule_suspend() or pm_runtime_suspend() which for PCI devices call
  316. pci_pm_runtime_suspend() to do the actual job. For this to work, the device's
  317. driver has to provide a pm->runtime_suspend() callback (see below), which is
  318. run by pci_pm_runtime_suspend() as the first action. If the driver's callback
  319. returns successfully, the device's standard configuration registers are saved,
  320. the device is prepared to generate wakeup signals and, finally, it is put into
  321. the target low-power state.
  322. The low-power state to put the device into is the lowest-power (highest number)
  323. state from which it can signal wakeup. The exact method of signaling wakeup is
  324. system-dependent and is determined by the PCI subsystem on the basis of the
  325. reported capabilities of the device and the platform firmware. To prepare the
  326. device for signaling wakeup and put it into the selected low-power state, the
  327. PCI subsystem can use the platform firmware as well as the device's native PCI
  328. PM capabilities, if supported.
  329. It is expected that the device driver's pm->runtime_suspend() callback will
  330. not attempt to prepare the device for signaling wakeup or to put it into a
  331. low-power state. The driver ought to leave these tasks to the PCI subsystem
  332. that has all of the information necessary to perform them.
  333. A suspended device is brought back into the "active" state, or resumed,
  334. with the help of pm_request_resume() or pm_runtime_resume() which both call
  335. pci_pm_runtime_resume() for PCI devices. Again, this only works if the device's
  336. driver provides a pm->runtime_resume() callback (see below). However, before
  337. the driver's callback is executed, pci_pm_runtime_resume() brings the device
  338. back into the full-power state, prevents it from signaling wakeup while in that
  339. state and restores its standard configuration registers. Thus the driver's
  340. callback need not worry about the PCI-specific aspects of the device resume.
  341. Note that generally pci_pm_runtime_resume() may be called in two different
  342. situations. First, it may be called at the request of the device's driver, for
  343. example if there are some data for it to process. Second, it may be called
  344. as a result of a wakeup signal from the device itself (this sometimes is
  345. referred to as "remote wakeup"). Of course, for this purpose the wakeup signal
  346. is handled in one of the ways described in Section 1 and finally converted into
  347. a notification for the PCI subsystem after the source device has been
  348. identified.
  349. The pci_pm_runtime_idle() function, called for PCI devices by pm_runtime_idle()
  350. and pm_request_idle(), executes the device driver's pm->runtime_idle()
  351. callback, if defined, and if that callback doesn't return error code (or is not
  352. present at all), suspends the device with the help of pm_runtime_suspend().
  353. Sometimes pci_pm_runtime_idle() is called automatically by the PM core (for
  354. example, it is called right after the device has just been resumed), in which
  355. cases it is expected to suspend the device if that makes sense. Usually,
  356. however, the PCI subsystem doesn't really know if the device really can be
  357. suspended, so it lets the device's driver decide by running its
  358. pm->runtime_idle() callback.
  359. 2.4. System-Wide Power Transitions
  360. ----------------------------------
  361. There are a few different types of system-wide power transitions, described in
  362. Documentation/power/devices.txt. Each of them requires devices to be handled
  363. in a specific way and the PM core executes subsystem-level power management
  364. callbacks for this purpose. They are executed in phases such that each phase
  365. involves executing the same subsystem-level callback for every device belonging
  366. to the given subsystem before the next phase begins. These phases always run
  367. after tasks have been frozen.
  368. 2.4.1. System Suspend
  369. When the system is going into a sleep state in which the contents of memory will
  370. be preserved, such as one of the ACPI sleep states S1-S3, the phases are:
  371. prepare, suspend, suspend_noirq.
  372. The following PCI bus type's callbacks, respectively, are used in these phases:
  373. pci_pm_prepare()
  374. pci_pm_suspend()
  375. pci_pm_suspend_noirq()
  376. The pci_pm_prepare() routine first puts the device into the "fully functional"
  377. state with the help of pm_runtime_resume(). Then, it executes the device
  378. driver's pm->prepare() callback if defined (i.e. if the driver's struct
  379. dev_pm_ops object is present and the prepare pointer in that object is valid).
  380. The pci_pm_suspend() routine first checks if the device's driver implements
  381. legacy PCI suspend routines (see Section 3), in which case the driver's legacy
  382. suspend callback is executed, if present, and its result is returned. Next, if
  383. the device's driver doesn't provide a struct dev_pm_ops object (containing
  384. pointers to the driver's callbacks), pci_pm_default_suspend() is called, which
  385. simply turns off the device's bus master capability and runs
  386. pcibios_disable_device() to disable it, unless the device is a bridge (PCI
  387. bridges are ignored by this routine). Next, the device driver's pm->suspend()
  388. callback is executed, if defined, and its result is returned if it fails.
  389. Finally, pci_fixup_device() is called to apply hardware suspend quirks related
  390. to the device if necessary.
  391. Note that the suspend phase is carried out asynchronously for PCI devices, so
  392. the pci_pm_suspend() callback may be executed in parallel for any pair of PCI
  393. devices that don't depend on each other in a known way (i.e. none of the paths
  394. in the device tree from the root bridge to a leaf device contains both of them).
  395. The pci_pm_suspend_noirq() routine is executed after suspend_device_irqs() has
  396. been called, which means that the device driver's interrupt handler won't be
  397. invoked while this routine is running. It first checks if the device's driver
  398. implements legacy PCI suspends routines (Section 3), in which case the legacy
  399. late suspend routine is called and its result is returned (the standard
  400. configuration registers of the device are saved if the driver's callback hasn't
  401. done that). Second, if the device driver's struct dev_pm_ops object is not
  402. present, the device's standard configuration registers are saved and the routine
  403. returns success. Otherwise the device driver's pm->suspend_noirq() callback is
  404. executed, if present, and its result is returned if it fails. Next, if the
  405. device's standard configuration registers haven't been saved yet (one of the
  406. device driver's callbacks executed before might do that), pci_pm_suspend_noirq()
  407. saves them, prepares the device to signal wakeup (if necessary) and puts it into
  408. a low-power state.
  409. The low-power state to put the device into is the lowest-power (highest number)
  410. state from which it can signal wakeup while the system is in the target sleep
  411. state. Just like in the runtime PM case described above, the mechanism of
  412. signaling wakeup is system-dependent and determined by the PCI subsystem, which
  413. is also responsible for preparing the device to signal wakeup from the system's
  414. target sleep state as appropriate.
  415. PCI device drivers (that don't implement legacy power management callbacks) are
  416. generally not expected to prepare devices for signaling wakeup or to put them
  417. into low-power states. However, if one of the driver's suspend callbacks
  418. (pm->suspend() or pm->suspend_noirq()) saves the device's standard configuration
  419. registers, pci_pm_suspend_noirq() will assume that the device has been prepared
  420. to signal wakeup and put into a low-power state by the driver (the driver is
  421. then assumed to have used the helper functions provided by the PCI subsystem for
  422. this purpose). PCI device drivers are not encouraged to do that, but in some
  423. rare cases doing that in the driver may be the optimum approach.
  424. 2.4.2. System Resume
  425. When the system is undergoing a transition from a sleep state in which the
  426. contents of memory have been preserved, such as one of the ACPI sleep states
  427. S1-S3, into the working state (ACPI S0), the phases are:
  428. resume_noirq, resume, complete.
  429. The following PCI bus type's callbacks, respectively, are executed in these
  430. phases:
  431. pci_pm_resume_noirq()
  432. pci_pm_resume()
  433. pci_pm_complete()
  434. The pci_pm_resume_noirq() routine first puts the device into the full-power
  435. state, restores its standard configuration registers and applies early resume
  436. hardware quirks related to the device, if necessary. This is done
  437. unconditionally, regardless of whether or not the device's driver implements
  438. legacy PCI power management callbacks (this way all PCI devices are in the
  439. full-power state and their standard configuration registers have been restored
  440. when their interrupt handlers are invoked for the first time during resume,
  441. which allows the kernel to avoid problems with the handling of shared interrupts
  442. by drivers whose devices are still suspended). If legacy PCI power management
  443. callbacks (see Section 3) are implemented by the device's driver, the legacy
  444. early resume callback is executed and its result is returned. Otherwise, the
  445. device driver's pm->resume_noirq() callback is executed, if defined, and its
  446. result is returned.
  447. The pci_pm_resume() routine first checks if the device's standard configuration
  448. registers have been restored and restores them if that's not the case (this
  449. only is necessary in the error path during a failing suspend). Next, resume
  450. hardware quirks related to the device are applied, if necessary, and if the
  451. device's driver implements legacy PCI power management callbacks (see
  452. Section 3), the driver's legacy resume callback is executed and its result is
  453. returned. Otherwise, the device's wakeup signaling mechanisms are blocked and
  454. its driver's pm->resume() callback is executed, if defined (the callback's
  455. result is then returned).
  456. The resume phase is carried out asynchronously for PCI devices, like the
  457. suspend phase described above, which means that if two PCI devices don't depend
  458. on each other in a known way, the pci_pm_resume() routine may be executed for
  459. the both of them in parallel.
  460. The pci_pm_complete() routine only executes the device driver's pm->complete()
  461. callback, if defined.
  462. 2.4.3. System Hibernation
  463. System hibernation is more complicated than system suspend, because it requires
  464. a system image to be created and written into a persistent storage medium. The
  465. image is created atomically and all devices are quiesced, or frozen, before that
  466. happens.
  467. The freezing of devices is carried out after enough memory has been freed (at
  468. the time of this writing the image creation requires at least 50% of system RAM
  469. to be free) in the following three phases:
  470. prepare, freeze, freeze_noirq
  471. that correspond to the PCI bus type's callbacks:
  472. pci_pm_prepare()
  473. pci_pm_freeze()
  474. pci_pm_freeze_noirq()
  475. This means that the prepare phase is exactly the same as for system suspend.
  476. The other two phases, however, are different.
  477. The pci_pm_freeze() routine is quite similar to pci_pm_suspend(), but it runs
  478. the device driver's pm->freeze() callback, if defined, instead of pm->suspend(),
  479. and it doesn't apply the suspend-related hardware quirks. It is executed
  480. asynchronously for different PCI devices that don't depend on each other in a
  481. known way.
  482. The pci_pm_freeze_noirq() routine, in turn, is similar to
  483. pci_pm_suspend_noirq(), but it calls the device driver's pm->freeze_noirq()
  484. routine instead of pm->suspend_noirq(). It also doesn't attempt to prepare the
  485. device for signaling wakeup and put it into a low-power state. Still, it saves
  486. the device's standard configuration registers if they haven't been saved by one
  487. of the driver's callbacks.
  488. Once the image has been created, it has to be saved. However, at this point all
  489. devices are frozen and they cannot handle I/O, while their ability to handle
  490. I/O is obviously necessary for the image saving. Thus they have to be brought
  491. back to the fully functional state and this is done in the following phases:
  492. thaw_noirq, thaw, complete
  493. using the following PCI bus type's callbacks:
  494. pci_pm_thaw_noirq()
  495. pci_pm_thaw()
  496. pci_pm_complete()
  497. respectively.
  498. The first of them, pci_pm_thaw_noirq(), is analogous to pci_pm_resume_noirq(),
  499. but it doesn't put the device into the full power state and doesn't attempt to
  500. restore its standard configuration registers. It also executes the device
  501. driver's pm->thaw_noirq() callback, if defined, instead of pm->resume_noirq().
  502. The pci_pm_thaw() routine is similar to pci_pm_resume(), but it runs the device
  503. driver's pm->thaw() callback instead of pm->resume(). It is executed
  504. asynchronously for different PCI devices that don't depend on each other in a
  505. known way.
  506. The complete phase it the same as for system resume.
  507. After saving the image, devices need to be powered down before the system can
  508. enter the target sleep state (ACPI S4 for ACPI-based systems). This is done in
  509. three phases:
  510. prepare, poweroff, poweroff_noirq
  511. where the prepare phase is exactly the same as for system suspend. The other
  512. two phases are analogous to the suspend and suspend_noirq phases, respectively.
  513. The PCI subsystem-level callbacks they correspond to
  514. pci_pm_poweroff()
  515. pci_pm_poweroff_noirq()
  516. work in analogy with pci_pm_suspend() and pci_pm_poweroff_noirq(), respectively,
  517. although they don't attempt to save the device's standard configuration
  518. registers.
  519. 2.4.4. System Restore
  520. System restore requires a hibernation image to be loaded into memory and the
  521. pre-hibernation memory contents to be restored before the pre-hibernation system
  522. activity can be resumed.
  523. As described in Documentation/power/devices.txt, the hibernation image is loaded
  524. into memory by a fresh instance of the kernel, called the boot kernel, which in
  525. turn is loaded and run by a boot loader in the usual way. After the boot kernel
  526. has loaded the image, it needs to replace its own code and data with the code
  527. and data of the "hibernated" kernel stored within the image, called the image
  528. kernel. For this purpose all devices are frozen just like before creating
  529. the image during hibernation, in the
  530. prepare, freeze, freeze_noirq
  531. phases described above. However, the devices affected by these phases are only
  532. those having drivers in the boot kernel; other devices will still be in whatever
  533. state the boot loader left them.
  534. Should the restoration of the pre-hibernation memory contents fail, the boot
  535. kernel would go through the "thawing" procedure described above, using the
  536. thaw_noirq, thaw, and complete phases (that will only affect the devices having
  537. drivers in the boot kernel), and then continue running normally.
  538. If the pre-hibernation memory contents are restored successfully, which is the
  539. usual situation, control is passed to the image kernel, which then becomes
  540. responsible for bringing the system back to the working state. To achieve this,
  541. it must restore the devices' pre-hibernation functionality, which is done much
  542. like waking up from the memory sleep state, although it involves different
  543. phases:
  544. restore_noirq, restore, complete
  545. The first two of these are analogous to the resume_noirq and resume phases
  546. described above, respectively, and correspond to the following PCI subsystem
  547. callbacks:
  548. pci_pm_restore_noirq()
  549. pci_pm_restore()
  550. These callbacks work in analogy with pci_pm_resume_noirq() and pci_pm_resume(),
  551. respectively, but they execute the device driver's pm->restore_noirq() and
  552. pm->restore() callbacks, if available.
  553. The complete phase is carried out in exactly the same way as during system
  554. resume.
  555. 3. PCI Device Drivers and Power Management
  556. ==========================================
  557. 3.1. Power Management Callbacks
  558. -------------------------------
  559. PCI device drivers participate in power management by providing callbacks to be
  560. executed by the PCI subsystem's power management routines described above and by
  561. controlling the runtime power management of their devices.
  562. At the time of this writing there are two ways to define power management
  563. callbacks for a PCI device driver, the recommended one, based on using a
  564. dev_pm_ops structure described in Documentation/power/devices.txt, and the
  565. "legacy" one, in which the .suspend(), .suspend_late(), .resume_early(), and
  566. .resume() callbacks from struct pci_driver are used. The legacy approach,
  567. however, doesn't allow one to define runtime power management callbacks and is
  568. not really suitable for any new drivers. Therefore it is not covered by this
  569. document (refer to the source code to learn more about it).
  570. It is recommended that all PCI device drivers define a struct dev_pm_ops object
  571. containing pointers to power management (PM) callbacks that will be executed by
  572. the PCI subsystem's PM routines in various circumstances. A pointer to the
  573. driver's struct dev_pm_ops object has to be assigned to the driver.pm field in
  574. its struct pci_driver object. Once that has happened, the "legacy" PM callbacks
  575. in struct pci_driver are ignored (even if they are not NULL).
  576. The PM callbacks in struct dev_pm_ops are not mandatory and if they are not
  577. defined (i.e. the respective fields of struct dev_pm_ops are unset) the PCI
  578. subsystem will handle the device in a simplified default manner. If they are
  579. defined, though, they are expected to behave as described in the following
  580. subsections.
  581. 3.1.1. prepare()
  582. The prepare() callback is executed during system suspend, during hibernation
  583. (when a hibernation image is about to be created), during power-off after
  584. saving a hibernation image and during system restore, when a hibernation image
  585. has just been loaded into memory.
  586. This callback is only necessary if the driver's device has children that in
  587. general may be registered at any time. In that case the role of the prepare()
  588. callback is to prevent new children of the device from being registered until
  589. one of the resume_noirq(), thaw_noirq(), or restore_noirq() callbacks is run.
  590. In addition to that the prepare() callback may carry out some operations
  591. preparing the device to be suspended, although it should not allocate memory
  592. (if additional memory is required to suspend the device, it has to be
  593. preallocated earlier, for example in a suspend/hibernate notifier as described
  594. in Documentation/power/notifiers.txt).
  595. 3.1.2. suspend()
  596. The suspend() callback is only executed during system suspend, after prepare()
  597. callbacks have been executed for all devices in the system.
  598. This callback is expected to quiesce the device and prepare it to be put into a
  599. low-power state by the PCI subsystem. It is not required (in fact it even is
  600. not recommended) that a PCI driver's suspend() callback save the standard
  601. configuration registers of the device, prepare it for waking up the system, or
  602. put it into a low-power state. All of these operations can very well be taken
  603. care of by the PCI subsystem, without the driver's participation.
  604. However, in some rare case it is convenient to carry out these operations in
  605. a PCI driver. Then, pci_save_state(), pci_prepare_to_sleep(), and
  606. pci_set_power_state() should be used to save the device's standard configuration
  607. registers, to prepare it for system wakeup (if necessary), and to put it into a
  608. low-power state, respectively. Moreover, if the driver calls pci_save_state(),
  609. the PCI subsystem will not execute either pci_prepare_to_sleep(), or
  610. pci_set_power_state() for its device, so the driver is then responsible for
  611. handling the device as appropriate.
  612. While the suspend() callback is being executed, the driver's interrupt handler
  613. can be invoked to handle an interrupt from the device, so all suspend-related
  614. operations relying on the driver's ability to handle interrupts should be
  615. carried out in this callback.
  616. 3.1.3. suspend_noirq()
  617. The suspend_noirq() callback is only executed during system suspend, after
  618. suspend() callbacks have been executed for all devices in the system and
  619. after device interrupts have been disabled by the PM core.
  620. The difference between suspend_noirq() and suspend() is that the driver's
  621. interrupt handler will not be invoked while suspend_noirq() is running. Thus
  622. suspend_noirq() can carry out operations that would cause race conditions to
  623. arise if they were performed in suspend().
  624. 3.1.4. freeze()
  625. The freeze() callback is hibernation-specific and is executed in two situations,
  626. during hibernation, after prepare() callbacks have been executed for all devices
  627. in preparation for the creation of a system image, and during restore,
  628. after a system image has been loaded into memory from persistent storage and the
  629. prepare() callbacks have been executed for all devices.
  630. The role of this callback is analogous to the role of the suspend() callback
  631. described above. In fact, they only need to be different in the rare cases when
  632. the driver takes the responsibility for putting the device into a low-power
  633. state.
  634. In that cases the freeze() callback should not prepare the device system wakeup
  635. or put it into a low-power state. Still, either it or freeze_noirq() should
  636. save the device's standard configuration registers using pci_save_state().
  637. 3.1.5. freeze_noirq()
  638. The freeze_noirq() callback is hibernation-specific. It is executed during
  639. hibernation, after prepare() and freeze() callbacks have been executed for all
  640. devices in preparation for the creation of a system image, and during restore,
  641. after a system image has been loaded into memory and after prepare() and
  642. freeze() callbacks have been executed for all devices. It is always executed
  643. after device interrupts have been disabled by the PM core.
  644. The role of this callback is analogous to the role of the suspend_noirq()
  645. callback described above and it very rarely is necessary to define
  646. freeze_noirq().
  647. The difference between freeze_noirq() and freeze() is analogous to the
  648. difference between suspend_noirq() and suspend().
  649. 3.1.6. poweroff()
  650. The poweroff() callback is hibernation-specific. It is executed when the system
  651. is about to be powered off after saving a hibernation image to a persistent
  652. storage. prepare() callbacks are executed for all devices before poweroff() is
  653. called.
  654. The role of this callback is analogous to the role of the suspend() and freeze()
  655. callbacks described above, although it does not need to save the contents of
  656. the device's registers. In particular, if the driver wants to put the device
  657. into a low-power state itself instead of allowing the PCI subsystem to do that,
  658. the poweroff() callback should use pci_prepare_to_sleep() and
  659. pci_set_power_state() to prepare the device for system wakeup and to put it
  660. into a low-power state, respectively, but it need not save the device's standard
  661. configuration registers.
  662. 3.1.7. poweroff_noirq()
  663. The poweroff_noirq() callback is hibernation-specific. It is executed after
  664. poweroff() callbacks have been executed for all devices in the system.
  665. The role of this callback is analogous to the role of the suspend_noirq() and
  666. freeze_noirq() callbacks described above, but it does not need to save the
  667. contents of the device's registers.
  668. The difference between poweroff_noirq() and poweroff() is analogous to the
  669. difference between suspend_noirq() and suspend().
  670. 3.1.8. resume_noirq()
  671. The resume_noirq() callback is only executed during system resume, after the
  672. PM core has enabled the non-boot CPUs. The driver's interrupt handler will not
  673. be invoked while resume_noirq() is running, so this callback can carry out
  674. operations that might race with the interrupt handler.
  675. Since the PCI subsystem unconditionally puts all devices into the full power
  676. state in the resume_noirq phase of system resume and restores their standard
  677. configuration registers, resume_noirq() is usually not necessary. In general
  678. it should only be used for performing operations that would lead to race
  679. conditions if carried out by resume().
  680. 3.1.9. resume()
  681. The resume() callback is only executed during system resume, after
  682. resume_noirq() callbacks have been executed for all devices in the system and
  683. device interrupts have been enabled by the PM core.
  684. This callback is responsible for restoring the pre-suspend configuration of the
  685. device and bringing it back to the fully functional state. The device should be
  686. able to process I/O in a usual way after resume() has returned.
  687. 3.1.10. thaw_noirq()
  688. The thaw_noirq() callback is hibernation-specific. It is executed after a
  689. system image has been created and the non-boot CPUs have been enabled by the PM
  690. core, in the thaw_noirq phase of hibernation. It also may be executed if the
  691. loading of a hibernation image fails during system restore (it is then executed
  692. after enabling the non-boot CPUs). The driver's interrupt handler will not be
  693. invoked while thaw_noirq() is running.
  694. The role of this callback is analogous to the role of resume_noirq(). The
  695. difference between these two callbacks is that thaw_noirq() is executed after
  696. freeze() and freeze_noirq(), so in general it does not need to modify the
  697. contents of the device's registers.
  698. 3.1.11. thaw()
  699. The thaw() callback is hibernation-specific. It is executed after thaw_noirq()
  700. callbacks have been executed for all devices in the system and after device
  701. interrupts have been enabled by the PM core.
  702. This callback is responsible for restoring the pre-freeze configuration of
  703. the device, so that it will work in a usual way after thaw() has returned.
  704. 3.1.12. restore_noirq()
  705. The restore_noirq() callback is hibernation-specific. It is executed in the
  706. restore_noirq phase of hibernation, when the boot kernel has passed control to
  707. the image kernel and the non-boot CPUs have been enabled by the image kernel's
  708. PM core.
  709. This callback is analogous to resume_noirq() with the exception that it cannot
  710. make any assumption on the previous state of the device, even if the BIOS (or
  711. generally the platform firmware) is known to preserve that state over a
  712. suspend-resume cycle.
  713. For the vast majority of PCI device drivers there is no difference between
  714. resume_noirq() and restore_noirq().
  715. 3.1.13. restore()
  716. The restore() callback is hibernation-specific. It is executed after
  717. restore_noirq() callbacks have been executed for all devices in the system and
  718. after the PM core has enabled device drivers' interrupt handlers to be invoked.
  719. This callback is analogous to resume(), just like restore_noirq() is analogous
  720. to resume_noirq(). Consequently, the difference between restore_noirq() and
  721. restore() is analogous to the difference between resume_noirq() and resume().
  722. For the vast majority of PCI device drivers there is no difference between
  723. resume() and restore().
  724. 3.1.14. complete()
  725. The complete() callback is executed in the following situations:
  726. - during system resume, after resume() callbacks have been executed for all
  727. devices,
  728. - during hibernation, before saving the system image, after thaw() callbacks
  729. have been executed for all devices,
  730. - during system restore, when the system is going back to its pre-hibernation
  731. state, after restore() callbacks have been executed for all devices.
  732. It also may be executed if the loading of a hibernation image into memory fails
  733. (in that case it is run after thaw() callbacks have been executed for all
  734. devices that have drivers in the boot kernel).
  735. This callback is entirely optional, although it may be necessary if the
  736. prepare() callback performs operations that need to be reversed.
  737. 3.1.15. runtime_suspend()
  738. The runtime_suspend() callback is specific to device runtime power management
  739. (runtime PM). It is executed by the PM core's runtime PM framework when the
  740. device is about to be suspended (i.e. quiesced and put into a low-power state)
  741. at run time.
  742. This callback is responsible for freezing the device and preparing it to be
  743. put into a low-power state, but it must allow the PCI subsystem to perform all
  744. of the PCI-specific actions necessary for suspending the device.
  745. 3.1.16. runtime_resume()
  746. The runtime_resume() callback is specific to device runtime PM. It is executed
  747. by the PM core's runtime PM framework when the device is about to be resumed
  748. (i.e. put into the full-power state and programmed to process I/O normally) at
  749. run time.
  750. This callback is responsible for restoring the normal functionality of the
  751. device after it has been put into the full-power state by the PCI subsystem.
  752. The device is expected to be able to process I/O in the usual way after
  753. runtime_resume() has returned.
  754. 3.1.17. runtime_idle()
  755. The runtime_idle() callback is specific to device runtime PM. It is executed
  756. by the PM core's runtime PM framework whenever it may be desirable to suspend
  757. the device according to the PM core's information. In particular, it is
  758. automatically executed right after runtime_resume() has returned in case the
  759. resume of the device has happened as a result of a spurious event.
  760. This callback is optional, but if it is not implemented or if it returns 0, the
  761. PCI subsystem will call pm_runtime_suspend() for the device, which in turn will
  762. cause the driver's runtime_suspend() callback to be executed.
  763. 3.1.18. Pointing Multiple Callback Pointers to One Routine
  764. Although in principle each of the callbacks described in the previous
  765. subsections can be defined as a separate function, it often is convenient to
  766. point two or more members of struct dev_pm_ops to the same routine. There are
  767. a few convenience macros that can be used for this purpose.
  768. The SIMPLE_DEV_PM_OPS macro declares a struct dev_pm_ops object with one
  769. suspend routine pointed to by the .suspend(), .freeze(), and .poweroff()
  770. members and one resume routine pointed to by the .resume(), .thaw(), and
  771. .restore() members. The other function pointers in this struct dev_pm_ops are
  772. unset.
  773. The UNIVERSAL_DEV_PM_OPS macro is similar to SIMPLE_DEV_PM_OPS, but it
  774. additionally sets the .runtime_resume() pointer to the same value as
  775. .resume() (and .thaw(), and .restore()) and the .runtime_suspend() pointer to
  776. the same value as .suspend() (and .freeze() and .poweroff()).
  777. The SET_SYSTEM_SLEEP_PM_OPS can be used inside of a declaration of struct
  778. dev_pm_ops to indicate that one suspend routine is to be pointed to by the
  779. .suspend(), .freeze(), and .poweroff() members and one resume routine is to
  780. be pointed to by the .resume(), .thaw(), and .restore() members.
  781. 3.2. Device Runtime Power Management
  782. ------------------------------------
  783. In addition to providing device power management callbacks PCI device drivers
  784. are responsible for controlling the runtime power management (runtime PM) of
  785. their devices.
  786. The PCI device runtime PM is optional, but it is recommended that PCI device
  787. drivers implement it at least in the cases where there is a reliable way of
  788. verifying that the device is not used (like when the network cable is detached
  789. from an Ethernet adapter or there are no devices attached to a USB controller).
  790. To support the PCI runtime PM the driver first needs to implement the
  791. runtime_suspend() and runtime_resume() callbacks. It also may need to implement
  792. the runtime_idle() callback to prevent the device from being suspended again
  793. every time right after the runtime_resume() callback has returned
  794. (alternatively, the runtime_suspend() callback will have to check if the
  795. device should really be suspended and return -EAGAIN if that is not the case).
  796. The runtime PM of PCI devices is enabled by default by the PCI core. PCI
  797. device drivers do not need to enable it and should not attempt to do so.
  798. However, it is blocked by pci_pm_init() that runs the pm_runtime_forbid()
  799. helper function. In addition to that, the runtime PM usage counter of
  800. each PCI device is incremented by local_pci_probe() before executing the
  801. probe callback provided by the device's driver.
  802. If a PCI driver implements the runtime PM callbacks and intends to use the
  803. runtime PM framework provided by the PM core and the PCI subsystem, it needs
  804. to decrement the device's runtime PM usage counter in its probe callback
  805. function. If it doesn't do that, the counter will always be different from
  806. zero for the device and it will never be runtime-suspended. The simplest
  807. way to do that is by calling pm_runtime_put_noidle(), but if the driver
  808. wants to schedule an autosuspend right away, for example, it may call
  809. pm_runtime_put_autosuspend() instead for this purpose. Generally, it
  810. just needs to call a function that decrements the devices usage counter
  811. from its probe routine to make runtime PM work for the device.
  812. It is important to remember that the driver's runtime_suspend() callback
  813. may be executed right after the usage counter has been decremented, because
  814. user space may already have caused the pm_runtime_allow() helper function
  815. unblocking the runtime PM of the device to run via sysfs, so the driver must
  816. be prepared to cope with that.
  817. The driver itself should not call pm_runtime_allow(), though. Instead, it
  818. should let user space or some platform-specific code do that (user space can
  819. do it via sysfs as stated above), but it must be prepared to handle the
  820. runtime PM of the device correctly as soon as pm_runtime_allow() is called
  821. (which may happen at any time, even before the driver is loaded).
  822. When the driver's remove callback runs, it has to balance the decrementation
  823. of the device's runtime PM usage counter at the probe time. For this reason,
  824. if it has decremented the counter in its probe callback, it must run
  825. pm_runtime_get_noresume() in its remove callback. [Since the core carries
  826. out a runtime resume of the device and bumps up the device's usage counter
  827. before running the driver's remove callback, the runtime PM of the device
  828. is effectively disabled for the duration of the remove execution and all
  829. runtime PM helper functions incrementing the device's usage counter are
  830. then effectively equivalent to pm_runtime_get_noresume().]
  831. The runtime PM framework works by processing requests to suspend or resume
  832. devices, or to check if they are idle (in which cases it is reasonable to
  833. subsequently request that they be suspended). These requests are represented
  834. by work items put into the power management workqueue, pm_wq. Although there
  835. are a few situations in which power management requests are automatically
  836. queued by the PM core (for example, after processing a request to resume a
  837. device the PM core automatically queues a request to check if the device is
  838. idle), device drivers are generally responsible for queuing power management
  839. requests for their devices. For this purpose they should use the runtime PM
  840. helper functions provided by the PM core, discussed in
  841. Documentation/power/runtime_pm.txt.
  842. Devices can also be suspended and resumed synchronously, without placing a
  843. request into pm_wq. In the majority of cases this also is done by their
  844. drivers that use helper functions provided by the PM core for this purpose.
  845. For more information on the runtime PM of devices refer to
  846. Documentation/power/runtime_pm.txt.
  847. 4. Resources
  848. ============
  849. PCI Local Bus Specification, Rev. 3.0
  850. PCI Bus Power Management Interface Specification, Rev. 1.2
  851. Advanced Configuration and Power Interface (ACPI) Specification, Rev. 3.0b
  852. PCI Express Base Specification, Rev. 2.0
  853. Documentation/power/devices.txt
  854. Documentation/power/runtime_pm.txt