aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/power/pci.txt
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /Documentation/power/pci.txt
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'Documentation/power/pci.txt')
-rw-r--r--Documentation/power/pci.txt332
1 files changed, 332 insertions, 0 deletions
diff --git a/Documentation/power/pci.txt b/Documentation/power/pci.txt
new file mode 100644
index 000000000000..c85428e7ad92
--- /dev/null
+++ b/Documentation/power/pci.txt
@@ -0,0 +1,332 @@
1
2PCI Power Management
3~~~~~~~~~~~~~~~~~~~~
4
5An overview of the concepts and the related functions in the Linux kernel
6
7Patrick Mochel <mochel@transmeta.com>
8(and others)
9
10---------------------------------------------------------------------------
11
121. Overview
132. How the PCI Subsystem Does Power Management
143. PCI Utility Functions
154. PCI Device Drivers
165. Resources
17
181. Overview
19~~~~~~~~~~~
20
21The PCI Power Management Specification was introduced between the PCI 2.1 and
22PCI 2.2 Specifications. It a standard interface for controlling various
23power management operations.
24
25Implementation of the PCI PM Spec is optional, as are several sub-components of
26it. If a device supports the PCI PM Spec, the device will have an 8 byte
27capability field in its PCI configuration space. This field is used to describe
28and control the standard PCI power management features.
29
30The PCI PM spec defines 4 operating states for devices (D0 - D3) and for buses
31(B0 - B3). The higher the number, the less power the device consumes. However,
32the higher the number, the longer the latency is for the device to return to
33an operational state (D0).
34
35There are actually two D3 states. When someone talks about D3, they usually
36mean D3hot, which corresponds to an ACPI D2 state (power is reduced, the
37device may lose some context). But they may also mean D3cold, which is an
38ACPI D3 state (power is fully off, all state was discarded); or both.
39
40Bus power management is not covered in this version of this document.
41
42Note that all PCI devices support D0 and D3cold by default, regardless of
43whether or not they implement any of the PCI PM spec.
44
45The possible state transitions that a device can undergo are:
46
47+---------------------------+
48| Current State | New State |
49+---------------------------+
50| D0 | D1, D2, D3|
51+---------------------------+
52| D1 | D2, D3 |
53+---------------------------+
54| D2 | D3 |
55+---------------------------+
56| D1, D2, D3 | D0 |
57+---------------------------+
58
59Note that when the system is entering a global suspend state, all devices will
60be placed into D3 and when resuming, all devices will be placed into D0.
61However, when the system is running, other state transitions are possible.
62
632. How The PCI Subsystem Handles Power Management
64~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65
66The PCI suspend/resume functionality is accessed indirectly via the Power
67Management subsystem. At boot, the PCI driver registers a power management
68callback with that layer. Upon entering a suspend state, the PM layer iterates
69through all of its registered callbacks. This currently takes place only during
70APM state transitions.
71
72Upon going to sleep, the PCI subsystem walks its device tree twice. Both times,
73it does a depth first walk of the device tree. The first walk saves each of the
74device's state and checks for devices that will prevent the system from entering
75a global power state. The next walk then places the devices in a low power
76state.
77
78The first walk allows a graceful recovery in the event of a failure, since none
79of the devices have actually been powered down.
80
81In both walks, in particular the second, all children of a bridge are touched
82before the actual bridge itself. This allows the bridge to retain power while
83its children are being accessed.
84
85Upon resuming from sleep, just the opposite must be true: all bridges must be
86powered on and restored before their children are powered on. This is easily
87accomplished with a breadth-first walk of the PCI device tree.
88
89
903. PCI Utility Functions
91~~~~~~~~~~~~~~~~~~~~~~~~
92
93These are helper functions designed to be called by individual device drivers.
94Assuming that a device behaves as advertised, these should be applicable in most
95cases. However, results may vary.
96
97Note that these functions are never implicitly called for the driver. The driver
98is always responsible for deciding when and if to call these.
99
100
101pci_save_state
102--------------
103
104Usage:
105 pci_save_state(dev, buffer);
106
107Description:
108 Save first 64 bytes of PCI config space. Buffer must be allocated by
109 caller.
110
111
112pci_restore_state
113-----------------
114
115Usage:
116 pci_restore_state(dev, buffer);
117
118Description:
119 Restore previously saved config space. (First 64 bytes only);
120
121 If buffer is NULL, then restore what information we know about the
122 device from bootup: BARs and interrupt line.
123
124
125pci_set_power_state
126-------------------
127
128Usage:
129 pci_set_power_state(dev, state);
130
131Description:
132 Transition device to low power state using PCI PM Capabilities
133 registers.
134
135 Will fail under one of the following conditions:
136 - If state is less than current state, but not D0 (illegal transition)
137 - Device doesn't support PM Capabilities
138 - Device does not support requested state
139
140
141pci_enable_wake
142---------------
143
144Usage:
145 pci_enable_wake(dev, state, enable);
146
147Description:
148 Enable device to generate PME# during low power state using PCI PM
149 Capabilities.
150
151 Checks whether if device supports generating PME# from requested state
152 and fail if it does not, unless enable == 0 (request is to disable wake
153 events, which is implicit if it doesn't even support it in the first
154 place).
155
156 Note that the PMC Register in the device's PM Capabilties has a bitmask
157 of the states it supports generating PME# from. D3hot is bit 3 and
158 D3cold is bit 4. So, while a value of 4 as the state may not seem
159 semantically correct, it is.
160
161
1624. PCI Device Drivers
163~~~~~~~~~~~~~~~~~~~~~
164
165These functions are intended for use by individual drivers, and are defined in
166struct pci_driver:
167
168 int (*save_state) (struct pci_dev *dev, u32 state);
169 int (*suspend) (struct pci_dev *dev, u32 state);
170 int (*resume) (struct pci_dev *dev);
171 int (*enable_wake) (struct pci_dev *dev, u32 state, int enable);
172
173
174save_state
175----------
176
177Usage:
178
179if (dev->driver && dev->driver->save_state)
180 dev->driver->save_state(dev,state);
181
182The driver should use this callback to save device state. It should take into
183account the current state of the device and the requested state in order to
184avoid any unnecessary operations.
185
186For example, a video card that supports all 4 states (D0-D3), all controller
187context is preserved when entering D1, but the screen is placed into a low power
188state (blanked).
189
190The driver can also interpret this function as a notification that it may be
191entering a sleep state in the near future. If it knows that the device cannot
192enter the requested state, either because of lack of support for it, or because
193the device is middle of some critical operation, then it should fail.
194
195This function should not be used to set any state in the device or the driver
196because the device may not actually enter the sleep state (e.g. another driver
197later causes causes a global state transition to fail).
198
199Note that in intermediate low power states, a device's I/O and memory spaces may
200be disabled and may not be available in subsequent transitions to lower power
201states.
202
203
204suspend
205-------
206
207Usage:
208
209if (dev->driver && dev->driver->suspend)
210 dev->driver->suspend(dev,state);
211
212A driver uses this function to actually transition the device into a low power
213state. This should include disabling I/O, IRQs, and bus-mastering, as well as
214physically transitioning the device to a lower power state; it may also include
215calls to pci_enable_wake().
216
217Bus mastering may be disabled by doing:
218
219pci_disable_device(dev);
220
221For devices that support the PCI PM Spec, this may be used to set the device's
222power state to match the suspend() parameter:
223
224pci_set_power_state(dev,state);
225
226The driver is also responsible for disabling any other device-specific features
227(e.g blanking screen, turning off on-card memory, etc).
228
229The driver should be sure to track the current state of the device, as it may
230obviate the need for some operations.
231
232The driver should update the current_state field in its pci_dev structure in
233this function, except for PM-capable devices when pci_set_power_state is used.
234
235resume
236------
237
238Usage:
239
240if (dev->driver && dev->driver->suspend)
241 dev->driver->resume(dev)
242
243The resume callback may be called from any power state, and is always meant to
244transition the device to the D0 state.
245
246The driver is responsible for reenabling any features of the device that had
247been disabled during previous suspend calls, such as IRQs and bus mastering,
248as well as calling pci_restore_state().
249
250If the device is currently in D3, it may need to be reinitialized in resume().
251
252 * Some types of devices, like bus controllers, will preserve context in D3hot
253 (using Vcc power). Their drivers will often want to avoid re-initializing
254 them after re-entering D0 (perhaps to avoid resetting downstream devices).
255
256 * Other kinds of devices in D3hot will discard device context as part of a
257 soft reset when re-entering the D0 state.
258
259 * Devices resuming from D3cold always go through a power-on reset. Some
260 device context can also be preserved using Vaux power.
261
262 * Some systems hide D3cold resume paths from drivers. For example, on PCs
263 the resume path for suspend-to-disk often runs BIOS powerup code, which
264 will sometimes re-initialize the device.
265
266To handle resets during D3 to D0 transitions, it may be convenient to share
267device initialization code between probe() and resume(). Device parameters
268can also be saved before the driver suspends into D3, avoiding re-probe.
269
270If the device supports the PCI PM Spec, it can use this to physically transition
271the device to D0:
272
273pci_set_power_state(dev,0);
274
275Note that if the entire system is transitioning out of a global sleep state, all
276devices will be placed in the D0 state, so this is not necessary. However, in
277the event that the device is placed in the D3 state during normal operation,
278this call is necessary. It is impossible to determine which of the two events is
279taking place in the driver, so it is always a good idea to make that call.
280
281The driver should take note of the state that it is resuming from in order to
282ensure correct (and speedy) operation.
283
284The driver should update the current_state field in its pci_dev structure in
285this function, except for PM-capable devices when pci_set_power_state is used.
286
287
288enable_wake
289-----------
290
291Usage:
292
293if (dev->driver && dev->driver->enable_wake)
294 dev->driver->enable_wake(dev,state,enable);
295
296This callback is generally only relevant for devices that support the PCI PM
297spec and have the ability to generate a PME# (Power Management Event Signal)
298to wake the system up. (However, it is possible that a device may support
299some non-standard way of generating a wake event on sleep.)
300
301Bits 15:11 of the PMC (Power Mgmt Capabilities) Register in a device's
302PM Capabilties describe what power states the device supports generating a
303wake event from:
304
305+------------------+
306| Bit | State |
307+------------------+
308| 11 | D0 |
309| 12 | D1 |
310| 13 | D2 |
311| 14 | D3hot |
312| 15 | D3cold |
313+------------------+
314
315A device can use this to enable wake events:
316
317 pci_enable_wake(dev,state,enable);
318
319Note that to enable PME# from D3cold, a value of 4 should be passed to
320pci_enable_wake (since it uses an index into a bitmask). If a driver gets
321a request to enable wake events from D3, two calls should be made to
322pci_enable_wake (one for both D3hot and D3cold).
323
324
3255. Resources
326~~~~~~~~~~~~
327
328PCI Local Bus Specification
329PCI Bus Power Management Interface Specification
330
331 http://pcisig.org
332