]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - include/linux/pm.h
pm: remove definition of struct pm_dev
[linux-2.6-omap-h63xx.git] / include / linux / pm.h
1 /*
2  *  pm.h - Power management interface
3  *
4  *  Copyright (C) 2000 Andrew Henroid
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #ifndef _LINUX_PM_H
22 #define _LINUX_PM_H
23
24 #include <linux/list.h>
25 #include <asm/atomic.h>
26 #include <asm/errno.h>
27
28 /*
29  * Power management requests... these are passed to pm_send_all() and friends.
30  *
31  * these functions are old and deprecated, see below.
32  */
33 typedef int __bitwise pm_request_t;
34
35 #define PM_SUSPEND      ((__force pm_request_t) 1)      /* enter D1-D3 */
36 #define PM_RESUME       ((__force pm_request_t) 2)      /* enter D0 */
37
38
39 /*
40  * Device types... these are passed to pm_register
41  */
42 typedef int __bitwise pm_dev_t;
43
44 #define PM_UNKNOWN_DEV  ((__force pm_dev_t) 0)  /* generic */
45 #define PM_SYS_DEV      ((__force pm_dev_t) 1)  /* system device (fan, KB controller, ...) */
46 #define PM_PCI_DEV      ((__force pm_dev_t) 2)  /* PCI device */
47 #define PM_USB_DEV      ((__force pm_dev_t) 3)  /* USB device */
48 #define PM_SCSI_DEV     ((__force pm_dev_t) 4)  /* SCSI device */
49 #define PM_ISA_DEV      ((__force pm_dev_t) 5)  /* ISA device */
50 #define PM_MTD_DEV      ((__force pm_dev_t) 6)  /* Memory Technology Device */
51
52 /*
53  * System device hardware ID (PnP) values
54  */
55 enum
56 {
57         PM_SYS_UNKNOWN = 0x00000000, /* generic */
58         PM_SYS_KBC =     0x41d00303, /* keyboard controller */
59         PM_SYS_COM =     0x41d00500, /* serial port */
60         PM_SYS_IRDA =    0x41d00510, /* IRDA controller */
61         PM_SYS_FDC =     0x41d00700, /* floppy controller */
62         PM_SYS_VGA =     0x41d00900, /* VGA controller */
63         PM_SYS_PCMCIA =  0x41d00e00, /* PCMCIA controller */
64 };
65
66 /*
67  * Device identifier
68  */
69 #define PM_PCI_ID(dev) ((dev)->bus->number << 16 | (dev)->devfn)
70
71 /* Functions above this comment are list-based old-style power
72  * management. Please avoid using them.  */
73
74 /*
75  * Callbacks for platform drivers to implement.
76  */
77 extern void (*pm_idle)(void);
78 extern void (*pm_power_off)(void);
79 extern void (*pm_power_off_prepare)(void);
80
81 /*
82  * Device power management
83  */
84
85 struct device;
86
87 typedef struct pm_message {
88         int event;
89 } pm_message_t;
90
91 /**
92  * struct pm_ops - device PM callbacks
93  *
94  * Several driver power state transitions are externally visible, affecting
95  * the state of pending I/O queues and (for drivers that touch hardware)
96  * interrupts, wakeups, DMA, and other hardware state.  There may also be
97  * internal transitions to various low power modes, which are transparent
98  * to the rest of the driver stack (such as a driver that's ON gating off
99  * clocks which are not in active use).
100  *
101  * The externally visible transitions are handled with the help of the following
102  * callbacks included in this structure:
103  *
104  * @prepare: Prepare the device for the upcoming transition, but do NOT change
105  *      its hardware state.  Prevent new children of the device from being
106  *      registered after @prepare() returns (the driver's subsystem and
107  *      generally the rest of the kernel is supposed to prevent new calls to the
108  *      probe method from being made too once @prepare() has succeeded).  If
109  *      @prepare() detects a situation it cannot handle (e.g. registration of a
110  *      child already in progress), it may return -EAGAIN, so that the PM core
111  *      can execute it once again (e.g. after the new child has been registered)
112  *      to recover from the race condition.  This method is executed for all
113  *      kinds of suspend transitions and is followed by one of the suspend
114  *      callbacks: @suspend(), @freeze(), or @poweroff().
115  *      The PM core executes @prepare() for all devices before starting to
116  *      execute suspend callbacks for any of them, so drivers may assume all of
117  *      the other devices to be present and functional while @prepare() is being
118  *      executed.  In particular, it is safe to make GFP_KERNEL memory
119  *      allocations from within @prepare().  However, drivers may NOT assume
120  *      anything about the availability of the user space at that time and it
121  *      is not correct to request firmware from within @prepare() (it's too
122  *      late to do that).  [To work around this limitation, drivers may
123  *      register suspend and hibernation notifiers that are executed before the
124  *      freezing of tasks.]
125  *
126  * @complete: Undo the changes made by @prepare().  This method is executed for
127  *      all kinds of resume transitions, following one of the resume callbacks:
128  *      @resume(), @thaw(), @restore().  Also called if the state transition
129  *      fails before the driver's suspend callback (@suspend(), @freeze(),
130  *      @poweroff()) can be executed (e.g. if the suspend callback fails for one
131  *      of the other devices that the PM core has unsuccessfully attempted to
132  *      suspend earlier).
133  *      The PM core executes @complete() after it has executed the appropriate
134  *      resume callback for all devices.
135  *
136  * @suspend: Executed before putting the system into a sleep state in which the
137  *      contents of main memory are preserved.  Quiesce the device, put it into
138  *      a low power state appropriate for the upcoming system state (such as
139  *      PCI_D3hot), and enable wakeup events as appropriate.
140  *
141  * @resume: Executed after waking the system up from a sleep state in which the
142  *      contents of main memory were preserved.  Put the device into the
143  *      appropriate state, according to the information saved in memory by the
144  *      preceding @suspend().  The driver starts working again, responding to
145  *      hardware events and software requests.  The hardware may have gone
146  *      through a power-off reset, or it may have maintained state from the
147  *      previous suspend() which the driver may rely on while resuming.  On most
148  *      platforms, there are no restrictions on availability of resources like
149  *      clocks during @resume().
150  *
151  * @freeze: Hibernation-specific, executed before creating a hibernation image.
152  *      Quiesce operations so that a consistent image can be created, but do NOT
153  *      otherwise put the device into a low power device state and do NOT emit
154  *      system wakeup events.  Save in main memory the device settings to be
155  *      used by @restore() during the subsequent resume from hibernation or by
156  *      the subsequent @thaw(), if the creation of the image or the restoration
157  *      of main memory contents from it fails.
158  *
159  * @thaw: Hibernation-specific, executed after creating a hibernation image OR
160  *      if the creation of the image fails.  Also executed after a failing
161  *      attempt to restore the contents of main memory from such an image.
162  *      Undo the changes made by the preceding @freeze(), so the device can be
163  *      operated in the same way as immediately before the call to @freeze().
164  *
165  * @poweroff: Hibernation-specific, executed after saving a hibernation image.
166  *      Quiesce the device, put it into a low power state appropriate for the
167  *      upcoming system state (such as PCI_D3hot), and enable wakeup events as
168  *      appropriate.
169  *
170  * @restore: Hibernation-specific, executed after restoring the contents of main
171  *      memory from a hibernation image.  Driver starts working again,
172  *      responding to hardware events and software requests.  Drivers may NOT
173  *      make ANY assumptions about the hardware state right prior to @restore().
174  *      On most platforms, there are no restrictions on availability of
175  *      resources like clocks during @restore().
176  *
177  * All of the above callbacks, except for @complete(), return error codes.
178  * However, the error codes returned by the resume operations, @resume(),
179  * @thaw(), and @restore(), do not cause the PM core to abort the resume
180  * transition during which they are returned.  The error codes returned in
181  * that cases are only printed by the PM core to the system logs for debugging
182  * purposes.  Still, it is recommended that drivers only return error codes
183  * from their resume methods in case of an unrecoverable failure (i.e. when the
184  * device being handled refuses to resume and becomes unusable) to allow us to
185  * modify the PM core in the future, so that it can avoid attempting to handle
186  * devices that failed to resume and their children.
187  *
188  * It is allowed to unregister devices while the above callbacks are being
189  * executed.  However, it is not allowed to unregister a device from within any
190  * of its own callbacks.
191  */
192
193 struct pm_ops {
194         int (*prepare)(struct device *dev);
195         void (*complete)(struct device *dev);
196         int (*suspend)(struct device *dev);
197         int (*resume)(struct device *dev);
198         int (*freeze)(struct device *dev);
199         int (*thaw)(struct device *dev);
200         int (*poweroff)(struct device *dev);
201         int (*restore)(struct device *dev);
202 };
203
204 /**
205  * struct pm_ext_ops - extended device PM callbacks
206  *
207  * Some devices require certain operations related to suspend and hibernation
208  * to be carried out with interrupts disabled.  Thus, 'struct pm_ext_ops' below
209  * is defined, adding callbacks to be executed with interrupts disabled to
210  * 'struct pm_ops'.
211  *
212  * The following callbacks included in 'struct pm_ext_ops' are executed with
213  * the nonboot CPUs switched off and with interrupts disabled on the only
214  * functional CPU.  They also are executed with the PM core list of devices
215  * locked, so they must NOT unregister any devices.
216  *
217  * @suspend_noirq: Complete the operations of ->suspend() by carrying out any
218  *      actions required for suspending the device that need interrupts to be
219  *      disabled
220  *
221  * @resume_noirq: Prepare for the execution of ->resume() by carrying out any
222  *      actions required for resuming the device that need interrupts to be
223  *      disabled
224  *
225  * @freeze_noirq: Complete the operations of ->freeze() by carrying out any
226  *      actions required for freezing the device that need interrupts to be
227  *      disabled
228  *
229  * @thaw_noirq: Prepare for the execution of ->thaw() by carrying out any
230  *      actions required for thawing the device that need interrupts to be
231  *      disabled
232  *
233  * @poweroff_noirq: Complete the operations of ->poweroff() by carrying out any
234  *      actions required for handling the device that need interrupts to be
235  *      disabled
236  *
237  * @restore_noirq: Prepare for the execution of ->restore() by carrying out any
238  *      actions required for restoring the operations of the device that need
239  *      interrupts to be disabled
240  *
241  * All of the above callbacks return error codes, but the error codes returned
242  * by the resume operations, @resume_noirq(), @thaw_noirq(), and
243  * @restore_noirq(), do not cause the PM core to abort the resume transition
244  * during which they are returned.  The error codes returned in that cases are
245  * only printed by the PM core to the system logs for debugging purposes.
246  * Still, as stated above, it is recommended that drivers only return error
247  * codes from their resume methods if the device being handled fails to resume
248  * and is not usable any more.
249  */
250
251 struct pm_ext_ops {
252         struct pm_ops base;
253         int (*suspend_noirq)(struct device *dev);
254         int (*resume_noirq)(struct device *dev);
255         int (*freeze_noirq)(struct device *dev);
256         int (*thaw_noirq)(struct device *dev);
257         int (*poweroff_noirq)(struct device *dev);
258         int (*restore_noirq)(struct device *dev);
259 };
260
261 /**
262  * PM_EVENT_ messages
263  *
264  * The following PM_EVENT_ messages are defined for the internal use of the PM
265  * core, in order to provide a mechanism allowing the high level suspend and
266  * hibernation code to convey the necessary information to the device PM core
267  * code:
268  *
269  * ON           No transition.
270  *
271  * FREEZE       System is going to hibernate, call ->prepare() and ->freeze()
272  *              for all devices.
273  *
274  * SUSPEND      System is going to suspend, call ->prepare() and ->suspend()
275  *              for all devices.
276  *
277  * HIBERNATE    Hibernation image has been saved, call ->prepare() and
278  *              ->poweroff() for all devices.
279  *
280  * QUIESCE      Contents of main memory are going to be restored from a (loaded)
281  *              hibernation image, call ->prepare() and ->freeze() for all
282  *              devices.
283  *
284  * RESUME       System is resuming, call ->resume() and ->complete() for all
285  *              devices.
286  *
287  * THAW         Hibernation image has been created, call ->thaw() and
288  *              ->complete() for all devices.
289  *
290  * RESTORE      Contents of main memory have been restored from a hibernation
291  *              image, call ->restore() and ->complete() for all devices.
292  *
293  * RECOVER      Creation of a hibernation image or restoration of the main
294  *              memory contents from a hibernation image has failed, call
295  *              ->thaw() and ->complete() for all devices.
296  */
297
298 #define PM_EVENT_ON             0x0000
299 #define PM_EVENT_FREEZE         0x0001
300 #define PM_EVENT_SUSPEND        0x0002
301 #define PM_EVENT_HIBERNATE      0x0004
302 #define PM_EVENT_QUIESCE        0x0008
303 #define PM_EVENT_RESUME         0x0010
304 #define PM_EVENT_THAW           0x0020
305 #define PM_EVENT_RESTORE        0x0040
306 #define PM_EVENT_RECOVER        0x0080
307
308 #define PM_EVENT_SLEEP  (PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
309
310 #define PMSG_FREEZE     ((struct pm_message){ .event = PM_EVENT_FREEZE, })
311 #define PMSG_QUIESCE    ((struct pm_message){ .event = PM_EVENT_QUIESCE, })
312 #define PMSG_SUSPEND    ((struct pm_message){ .event = PM_EVENT_SUSPEND, })
313 #define PMSG_HIBERNATE  ((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
314 #define PMSG_RESUME     ((struct pm_message){ .event = PM_EVENT_RESUME, })
315 #define PMSG_THAW       ((struct pm_message){ .event = PM_EVENT_THAW, })
316 #define PMSG_RESTORE    ((struct pm_message){ .event = PM_EVENT_RESTORE, })
317 #define PMSG_RECOVER    ((struct pm_message){ .event = PM_EVENT_RECOVER, })
318 #define PMSG_ON         ((struct pm_message){ .event = PM_EVENT_ON, })
319
320 /**
321  * Device power management states
322  *
323  * These state labels are used internally by the PM core to indicate the current
324  * status of a device with respect to the PM core operations.
325  *
326  * DPM_ON               Device is regarded as operational.  Set this way
327  *                      initially and when ->complete() is about to be called.
328  *                      Also set when ->prepare() fails.
329  *
330  * DPM_PREPARING        Device is going to be prepared for a PM transition.  Set
331  *                      when ->prepare() is about to be called.
332  *
333  * DPM_RESUMING         Device is going to be resumed.  Set when ->resume(),
334  *                      ->thaw(), or ->restore() is about to be called.
335  *
336  * DPM_SUSPENDING       Device has been prepared for a power transition.  Set
337  *                      when ->prepare() has just succeeded.
338  *
339  * DPM_OFF              Device is regarded as inactive.  Set immediately after
340  *                      ->suspend(), ->freeze(), or ->poweroff() has succeeded.
341  *                      Also set when ->resume()_noirq, ->thaw_noirq(), or
342  *                      ->restore_noirq() is about to be called.
343  *
344  * DPM_OFF_IRQ          Device is in a "deep sleep".  Set immediately after
345  *                      ->suspend_noirq(), ->freeze_noirq(), or
346  *                      ->poweroff_noirq() has just succeeded.
347  */
348
349 enum dpm_state {
350         DPM_INVALID,
351         DPM_ON,
352         DPM_PREPARING,
353         DPM_RESUMING,
354         DPM_SUSPENDING,
355         DPM_OFF,
356         DPM_OFF_IRQ,
357 };
358
359 struct dev_pm_info {
360         pm_message_t            power_state;
361         unsigned                can_wakeup:1;
362         unsigned                should_wakeup:1;
363         enum dpm_state          status;         /* Owned by the PM core */
364 #ifdef  CONFIG_PM_SLEEP
365         struct list_head        entry;
366 #endif
367 };
368
369 /*
370  * The PM_EVENT_ messages are also used by drivers implementing the legacy
371  * suspend framework, based on the ->suspend() and ->resume() callbacks common
372  * for suspend and hibernation transitions, according to the rules below.
373  */
374
375 /* Necessary, because several drivers use PM_EVENT_PRETHAW */
376 #define PM_EVENT_PRETHAW PM_EVENT_QUIESCE
377
378 /*
379  * One transition is triggered by resume(), after a suspend() call; the
380  * message is implicit:
381  *
382  * ON           Driver starts working again, responding to hardware events
383  *              and software requests.  The hardware may have gone through
384  *              a power-off reset, or it may have maintained state from the
385  *              previous suspend() which the driver will rely on while
386  *              resuming.  On most platforms, there are no restrictions on
387  *              availability of resources like clocks during resume().
388  *
389  * Other transitions are triggered by messages sent using suspend().  All
390  * these transitions quiesce the driver, so that I/O queues are inactive.
391  * That commonly entails turning off IRQs and DMA; there may be rules
392  * about how to quiesce that are specific to the bus or the device's type.
393  * (For example, network drivers mark the link state.)  Other details may
394  * differ according to the message:
395  *
396  * SUSPEND      Quiesce, enter a low power device state appropriate for
397  *              the upcoming system state (such as PCI_D3hot), and enable
398  *              wakeup events as appropriate.
399  *
400  * HIBERNATE    Enter a low power device state appropriate for the hibernation
401  *              state (eg. ACPI S4) and enable wakeup events as appropriate.
402  *
403  * FREEZE       Quiesce operations so that a consistent image can be saved;
404  *              but do NOT otherwise enter a low power device state, and do
405  *              NOT emit system wakeup events.
406  *
407  * PRETHAW      Quiesce as if for FREEZE; additionally, prepare for restoring
408  *              the system from a snapshot taken after an earlier FREEZE.
409  *              Some drivers will need to reset their hardware state instead
410  *              of preserving it, to ensure that it's never mistaken for the
411  *              state which that earlier snapshot had set up.
412  *
413  * A minimally power-aware driver treats all messages as SUSPEND, fully
414  * reinitializes its device during resume() -- whether or not it was reset
415  * during the suspend/resume cycle -- and can't issue wakeup events.
416  *
417  * More power-aware drivers may also use low power states at runtime as
418  * well as during system sleep states like PM_SUSPEND_STANDBY.  They may
419  * be able to use wakeup events to exit from runtime low-power states,
420  * or from system low-power states such as standby or suspend-to-RAM.
421  */
422
423 #ifdef CONFIG_PM_SLEEP
424 extern void device_pm_lock(void);
425 extern void device_power_up(pm_message_t state);
426 extern void device_resume(pm_message_t state);
427
428 extern void device_pm_unlock(void);
429 extern int device_power_down(pm_message_t state);
430 extern int device_suspend(pm_message_t state);
431 extern int device_prepare_suspend(pm_message_t state);
432
433 extern void __suspend_report_result(const char *function, void *fn, int ret);
434
435 #define suspend_report_result(fn, ret)                                  \
436         do {                                                            \
437                 __suspend_report_result(__FUNCTION__, fn, ret);         \
438         } while (0)
439
440 #else /* !CONFIG_PM_SLEEP */
441
442 static inline int device_suspend(pm_message_t state)
443 {
444         return 0;
445 }
446
447 #define suspend_report_result(fn, ret)          do {} while (0)
448
449 #endif /* !CONFIG_PM_SLEEP */
450
451 /*
452  * Global Power Management flags
453  * Used to keep APM and ACPI from both being active
454  */
455 extern unsigned int     pm_flags;
456
457 #define PM_APM  1
458 #define PM_ACPI 2
459
460 #endif /* _LINUX_PM_H */