Blame view

include/linux/pm.h 11.7 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  /*
   *  pm.h - Power management interface
   *
   *  Copyright (C) 2000 Andrew Henroid
   *
   *  This program is free software; you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation; either version 2 of the License, or
   *  (at your option) any later version.
   *
   *  This program is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details.
   *
   *  You should have received a copy of the GNU General Public License
   *  along with this program; if not, write to the Free Software
   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
  
  #ifndef _LINUX_PM_H
  #define _LINUX_PM_H
  
  #ifdef __KERNEL__
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
  #include <linux/list.h>
  #include <asm/atomic.h>
  
  /*
   * Power management requests... these are passed to pm_send_all() and friends.
   *
   * these functions are old and deprecated, see below.
   */
  typedef int __bitwise pm_request_t;
  
  #define PM_SUSPEND	((__force pm_request_t) 1)	/* enter D1-D3 */
  #define PM_RESUME	((__force pm_request_t) 2)	/* enter D0 */
  
  
  /*
   * Device types... these are passed to pm_register
   */
  typedef int __bitwise pm_dev_t;
  
  #define PM_UNKNOWN_DEV	((__force pm_dev_t) 0)	/* generic */
  #define PM_SYS_DEV	((__force pm_dev_t) 1)	/* system device (fan, KB controller, ...) */
  #define PM_PCI_DEV	((__force pm_dev_t) 2)	/* PCI device */
  #define PM_USB_DEV	((__force pm_dev_t) 3)	/* USB device */
  #define PM_SCSI_DEV	((__force pm_dev_t) 4)	/* SCSI device */
  #define PM_ISA_DEV	((__force pm_dev_t) 5)	/* ISA device */
  #define	PM_MTD_DEV	((__force pm_dev_t) 6)	/* Memory Technology Device */
  
  /*
   * System device hardware ID (PnP) values
   */
  enum
  {
  	PM_SYS_UNKNOWN = 0x00000000, /* generic */
  	PM_SYS_KBC =	 0x41d00303, /* keyboard controller */
  	PM_SYS_COM =	 0x41d00500, /* serial port */
  	PM_SYS_IRDA =	 0x41d00510, /* IRDA controller */
  	PM_SYS_FDC =	 0x41d00700, /* floppy controller */
  	PM_SYS_VGA =	 0x41d00900, /* VGA controller */
  	PM_SYS_PCMCIA =	 0x41d00e00, /* PCMCIA controller */
  };
  
  /*
   * Device identifier
   */
  #define PM_PCI_ID(dev) ((dev)->bus->number << 16 | (dev)->devfn)
  
  /*
   * Request handler callback
   */
  struct pm_dev;
  
  typedef int (*pm_callback)(struct pm_dev *dev, pm_request_t rqst, void *data);
  
  /*
   * Dynamic device information
   */
  struct pm_dev
  {
  	pm_dev_t	 type;
  	unsigned long	 id;
  	pm_callback	 callback;
  	void		*data;
  
  	unsigned long	 flags;
  	unsigned long	 state;
  	unsigned long	 prev_state;
  
  	struct list_head entry;
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94
95
96
97
98
99
100
101
  /* Functions above this comment are list-based old-style power
   * managment. Please avoid using them.  */
  
  /*
   * Callbacks for platform drivers to implement.
   */
  extern void (*pm_idle)(void);
  extern void (*pm_power_off)(void);
bd804eba1   Rafael J. Wysocki   PM: Introduce pm_...
102
  extern void (*pm_power_off_prepare)(void);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
104
105
106
107
108
  
  typedef int __bitwise suspend_state_t;
  
  #define PM_SUSPEND_ON		((__force suspend_state_t) 0)
  #define PM_SUSPEND_STANDBY	((__force suspend_state_t) 1)
  #define PM_SUSPEND_MEM		((__force suspend_state_t) 3)
a3d25c275   Rafael J. Wysocki   PM: Separate hibe...
109
  #define PM_SUSPEND_MAX		((__force suspend_state_t) 4)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110

2a9df4945   Johannes Berg   power management:...
111
  /**
2391dae3e   Rafael J. Wysocki   PM: introduce set...
112
113
   * struct pm_ops - Callbacks for managing platform dependent system sleep
   *	states.
2a9df4945   Johannes Berg   power management:...
114
   *
2391dae3e   Rafael J. Wysocki   PM: introduce set...
115
116
117
118
119
120
121
   * @valid: Callback to determine if given system sleep state is supported by
   *	the platform.
   *	Valid (ie. supported) states are advertised in /sys/power/state.  Note
   *	that it still may be impossible to enter given system sleep state if the
   *	conditions aren't right.
   *	There is the %pm_valid_only_mem function available that can be assigned
   *	to this if the platform only supports mem sleep.
2a9df4945   Johannes Berg   power management:...
122
   *
2391dae3e   Rafael J. Wysocki   PM: introduce set...
123
124
125
126
127
128
129
130
131
132
   * @set_target: Tell the platform which system sleep state is going to be
   *	entered.
   *	@set_target() is executed right prior to suspending devices.  The
   *	information conveyed to the platform code by @set_target() should be
   *	disregarded by the platform as soon as @finish() is executed and if
   *	@prepare() fails.  If @set_target() fails (ie. returns nonzero),
   *	@prepare(), @enter() and @finish() will not be called by the PM core.
   *	This callback is optional.  However, if it is implemented, the argument
   *	passed to @prepare(), @enter() and @finish() is meaningless and should
   *	be ignored.
2a9df4945   Johannes Berg   power management:...
133
   *
2391dae3e   Rafael J. Wysocki   PM: introduce set...
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
   * @prepare: Prepare the platform for entering the system sleep state indicated
   *	by @set_target() or represented by the argument if @set_target() is not
   *	implemented.
   *	@prepare() is called right after devices have been suspended (ie. the
   *	appropriate .suspend() method has been executed for each device) and
   *	before the nonboot CPUs are disabled (it is executed with IRQs enabled).
   *	This callback is optional.  It returns 0 on success or a negative
   *	error code otherwise, in which case the system cannot enter the desired
   *	sleep state (@enter() and @finish() will not be called in that case).
   *
   * @enter: Enter the system sleep state indicated by @set_target() or
   *	represented by the argument if @set_target() is not implemented.
   *	This callback is mandatory.  It returns 0 on success or a negative
   *	error code otherwise, in which case the system cannot enter the desired
   *	sleep state.
   *
   * @finish: Called when the system has just left a sleep state, right after
   *	the nonboot CPUs have been enabled and before devices are resumed (it is
   *	executed with IRQs enabled).  If @set_target() is not implemented, the
   *	argument represents the sleep state being left.
   *	This callback is optional, but should be implemented by the platforms
   *	that implement @prepare().  If implemented, it is always called after
   *	@enter() (even if @enter() fails).
2a9df4945   Johannes Berg   power management:...
157
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
158
  struct pm_ops {
eb9289eb2   Shaohua Li   [PATCH] introduce...
159
  	int (*valid)(suspend_state_t state);
2391dae3e   Rafael J. Wysocki   PM: introduce set...
160
  	int (*set_target)(suspend_state_t state);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
161
162
163
164
  	int (*prepare)(suspend_state_t state);
  	int (*enter)(suspend_state_t state);
  	int (*finish)(suspend_state_t state);
  };
296699de6   Rafael J. Wysocki   Introduce CONFIG_...
165
  #ifdef CONFIG_SUSPEND
2391dae3e   Rafael J. Wysocki   PM: introduce set...
166
  extern struct pm_ops *pm_ops;
2a9df4945   Johannes Berg   power management:...
167
168
169
170
171
  /**
   * pm_set_ops - set platform dependent power management ops
   * @pm_ops: The new power management operations to set.
   */
  extern void pm_set_ops(struct pm_ops *pm_ops);
e8c9c5026   Johannes Berg   power management:...
172
  extern int pm_valid_only_mem(suspend_state_t state);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
173

a53c46dc8   Johannes Berg   s2ram: add arch i...
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
  /**
   * arch_suspend_disable_irqs - disable IRQs for suspend
   *
   * Disables IRQs (in the default case). This is a weak symbol in the common
   * code and thus allows architectures to override it if more needs to be
   * done. Not called for suspend to disk.
   */
  extern void arch_suspend_disable_irqs(void);
  
  /**
   * arch_suspend_enable_irqs - enable IRQs after suspend
   *
   * Enables IRQs (in the default case). This is a weak symbol in the common
   * code and thus allows architectures to override it if more needs to be
   * done. Not called for suspend to disk.
   */
  extern void arch_suspend_enable_irqs(void);
2391dae3e   Rafael J. Wysocki   PM: introduce set...
191
  extern int pm_suspend(suspend_state_t state);
296699de6   Rafael J. Wysocki   Introduce CONFIG_...
192
193
194
195
196
197
  #else /* !CONFIG_SUSPEND */
  #define suspend_valid_only_mem	NULL
  
  static inline void pm_set_ops(struct pm_ops *pm_ops) {}
  static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
  #endif /* !CONFIG_SUSPEND */
2391dae3e   Rafael J. Wysocki   PM: introduce set...
198

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
199
200
201
202
203
  /*
   * Device power management
   */
  
  struct device;
ca078bae8   Pavel Machek   [PATCH] swsusp: s...
204
205
206
  typedef struct pm_message {
  	int event;
  } pm_message_t;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
207
208
  
  /*
82bb67f2c   David Brownell   PM: define PM_EVE...
209
210
211
212
213
214
   * Several driver power state transitions are externally visible, affecting
   * the state of pending I/O queues and (for drivers that touch hardware)
   * interrupts, wakeups, DMA, and other hardware state.  There may also be
   * internal transitions to various low power modes, which are transparent
   * to the rest of the driver stack (such as a driver that's ON gating off
   * clocks which are not in active use).
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
215
   *
82bb67f2c   David Brownell   PM: define PM_EVE...
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
   * One transition is triggered by resume(), after a suspend() call; the
   * message is implicit:
   *
   * ON		Driver starts working again, responding to hardware events
   * 		and software requests.  The hardware may have gone through
   * 		a power-off reset, or it may have maintained state from the
   * 		previous suspend() which the driver will rely on while
   * 		resuming.  On most platforms, there are no restrictions on
   * 		availability of resources like clocks during resume().
   *
   * Other transitions are triggered by messages sent using suspend().  All
   * these transitions quiesce the driver, so that I/O queues are inactive.
   * That commonly entails turning off IRQs and DMA; there may be rules
   * about how to quiesce that are specific to the bus or the device's type.
   * (For example, network drivers mark the link state.)  Other details may
   * differ according to the message:
   *
   * SUSPEND	Quiesce, enter a low power device state appropriate for
   * 		the upcoming system state (such as PCI_D3hot), and enable
   * 		wakeup events as appropriate.
   *
   * FREEZE	Quiesce operations so that a consistent image can be saved;
   * 		but do NOT otherwise enter a low power device state, and do
   * 		NOT emit system wakeup events.
   *
   * PRETHAW	Quiesce as if for FREEZE; additionally, prepare for restoring
   * 		the system from a snapshot taken after an earlier FREEZE.
   * 		Some drivers will need to reset their hardware state instead
   * 		of preserving it, to ensure that it's never mistaken for the
   * 		state which that earlier snapshot had set up.
   *
   * A minimally power-aware driver treats all messages as SUSPEND, fully
   * reinitializes its device during resume() -- whether or not it was reset
   * during the suspend/resume cycle -- and can't issue wakeup events.
   *
   * More power-aware drivers may also use low power states at runtime as
   * well as during system sleep states like PM_SUSPEND_STANDBY.  They may
   * be able to use wakeup events to exit from runtime low-power states,
   * or from system low-power states such as standby or suspend-to-RAM.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
255
   */
ca078bae8   Pavel Machek   [PATCH] swsusp: s...
256
257
258
  #define PM_EVENT_ON 0
  #define PM_EVENT_FREEZE 1
  #define PM_EVENT_SUSPEND 2
82bb67f2c   David Brownell   PM: define PM_EVE...
259
  #define PM_EVENT_PRETHAW 3
ca078bae8   Pavel Machek   [PATCH] swsusp: s...
260
261
  
  #define PMSG_FREEZE	((struct pm_message){ .event = PM_EVENT_FREEZE, })
82bb67f2c   David Brownell   PM: define PM_EVE...
262
  #define PMSG_PRETHAW	((struct pm_message){ .event = PM_EVENT_PRETHAW, })
ca078bae8   Pavel Machek   [PATCH] swsusp: s...
263
264
  #define PMSG_SUSPEND	((struct pm_message){ .event = PM_EVENT_SUSPEND, })
  #define PMSG_ON		((struct pm_message){ .event = PM_EVENT_ON, })
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
265
266
267
  
  struct dev_pm_info {
  	pm_message_t		power_state;
0ac85241e   David Brownell   [PATCH] driver mo...
268
  	unsigned		can_wakeup:1;
296699de6   Rafael J. Wysocki   Introduce CONFIG_...
269
  #ifdef	CONFIG_PM_SLEEP
0ac85241e   David Brownell   [PATCH] driver mo...
270
  	unsigned		should_wakeup:1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
271
272
273
  	struct list_head	entry;
  #endif
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
274
275
276
  extern int device_power_down(pm_message_t state);
  extern void device_power_up(void);
  extern void device_resume(void);
296699de6   Rafael J. Wysocki   Introduce CONFIG_...
277
  #ifdef CONFIG_PM_SLEEP
620b03276   Pavel Machek   [PATCH] properly ...
278
  extern int device_suspend(pm_message_t state);
7c8265f51   Linus Torvalds   Suspend infrastru...
279
  extern int device_prepare_suspend(pm_message_t state);
0ac85241e   David Brownell   [PATCH] driver mo...
280
281
282
283
284
  
  #define device_set_wakeup_enable(dev,val) \
  	((dev)->power.should_wakeup = !!(val))
  #define device_may_wakeup(dev) \
  	(device_can_wakeup(dev) && (dev)->power.should_wakeup)
026694920   Andrew Morton   [PATCH] pm: print...
285
286
287
288
289
290
  extern void __suspend_report_result(const char *function, void *fn, int ret);
  
  #define suspend_report_result(fn, ret)					\
  	do {								\
  		__suspend_report_result(__FUNCTION__, fn, ret);		\
  	} while (0)
9a7834d06   Andrew Morton   [PATCH] USB: fix ...
291

075c17715   David Brownell   define platform w...
292
293
294
295
296
297
298
299
300
301
302
303
304
  /*
   * Platform hook to activate device wakeup capability, if that's not already
   * handled by enable_irq_wake() etc.
   * Returns zero on success, else negative errno
   */
  extern int (*platform_enable_wakeup)(struct device *dev, int is_on);
  
  static inline int call_platform_enable_wakeup(struct device *dev, int is_on)
  {
  	if (platform_enable_wakeup)
  		return (*platform_enable_wakeup)(dev, is_on);
  	return 0;
  }
296699de6   Rafael J. Wysocki   Introduce CONFIG_...
305
  #else /* !CONFIG_PM_SLEEP */
0ac85241e   David Brownell   [PATCH] driver mo...
306

620b03276   Pavel Machek   [PATCH] properly ...
307
308
309
310
  static inline int device_suspend(pm_message_t state)
  {
  	return 0;
  }
0ac85241e   David Brownell   [PATCH] driver mo...
311
312
313
  
  #define device_set_wakeup_enable(dev,val)	do{}while(0)
  #define device_may_wakeup(dev)			(0)
026694920   Andrew Morton   [PATCH] pm: print...
314
  #define suspend_report_result(fn, ret) do { } while (0)
075c17715   David Brownell   define platform w...
315
316
  static inline int call_platform_enable_wakeup(struct device *dev, int is_on)
  {
14e38ac82   David Rientjes   pm: include EIO f...
317
  	return 0;
075c17715   David Brownell   define platform w...
318
  }
296699de6   Rafael J. Wysocki   Introduce CONFIG_...
319
  #endif /* !CONFIG_PM_SLEEP */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
320

0ac85241e   David Brownell   [PATCH] driver mo...
321
322
323
324
325
326
327
328
329
330
  /* changes to device_may_wakeup take effect on the next pm state change.
   * by default, devices should wakeup if they can.
   */
  #define device_can_wakeup(dev) \
  	((dev)->power.can_wakeup)
  #define device_init_wakeup(dev,val) \
  	do { \
  		device_can_wakeup(dev) = !!(val); \
  		device_set_wakeup_enable(dev,val); \
  	} while(0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
331
332
333
  #endif /* __KERNEL__ */
  
  #endif /* _LINUX_PM_H */