Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pm.h
Go to the documentation of this file.
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 <linux/workqueue.h>
26 #include <linux/spinlock.h>
27 #include <linux/wait.h>
28 #include <linux/timer.h>
29 #include <linux/completion.h>
30 
31 /*
32  * Callbacks for platform drivers to implement.
33  */
34 extern void (*pm_idle)(void);
35 extern void (*pm_power_off)(void);
36 extern void (*pm_power_off_prepare)(void);
37 
38 /*
39  * Device power management
40  */
41 
42 struct device;
43 
44 #ifdef CONFIG_PM
45 extern const char power_group_name[]; /* = "power" */
46 #else
47 #define power_group_name NULL
48 #endif
49 
50 typedef struct pm_message {
51  int event;
52 } pm_message_t;
53 
264 struct dev_pm_ops {
265  int (*prepare)(struct device *dev);
266  void (*complete)(struct device *dev);
267  int (*suspend)(struct device *dev);
268  int (*resume)(struct device *dev);
269  int (*freeze)(struct device *dev);
270  int (*thaw)(struct device *dev);
271  int (*poweroff)(struct device *dev);
272  int (*restore)(struct device *dev);
273  int (*suspend_late)(struct device *dev);
274  int (*resume_early)(struct device *dev);
275  int (*freeze_late)(struct device *dev);
276  int (*thaw_early)(struct device *dev);
280  int (*resume_noirq)(struct device *dev);
281  int (*freeze_noirq)(struct device *dev);
282  int (*thaw_noirq)(struct device *dev);
287  int (*runtime_idle)(struct device *dev);
288 };
289 
290 #ifdef CONFIG_PM_SLEEP
291 #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
292  .suspend = suspend_fn, \
293  .resume = resume_fn, \
294  .freeze = suspend_fn, \
295  .thaw = resume_fn, \
296  .poweroff = suspend_fn, \
297  .restore = resume_fn,
298 #else
299 #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
300 #endif
301 
302 #ifdef CONFIG_PM_RUNTIME
303 #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
304  .runtime_suspend = suspend_fn, \
305  .runtime_resume = resume_fn, \
306  .runtime_idle = idle_fn,
307 #else
308 #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn)
309 #endif
310 
311 /*
312  * Use this if you want to use the same suspend and resume callbacks for suspend
313  * to RAM and hibernation.
314  */
315 #define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
316 const struct dev_pm_ops name = { \
317  SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
318 }
319 
320 /*
321  * Use this for defining a set of PM operations to be used in all situations
322  * (sustem suspend, hibernation or runtime PM).
323  * NOTE: In general, system suspend callbacks, .suspend() and .resume(), should
324  * be different from the corresponding runtime PM callbacks, .runtime_suspend(),
325  * and .runtime_resume(), because .runtime_suspend() always works on an already
326  * quiescent device, while .suspend() should assume that the device may be doing
327  * something when it is called (it should ensure that the device will be
328  * quiescent after it has returned). Therefore it's better to point the "late"
329  * suspend and "early" resume callback pointers, .suspend_late() and
330  * .resume_early(), to the same routines as .runtime_suspend() and
331  * .runtime_resume(), respectively (and analogously for hibernation).
332  */
333 #define UNIVERSAL_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn) \
334 const struct dev_pm_ops name = { \
335  SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
336  SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
337 }
338 
391 #define PM_EVENT_INVALID (-1)
392 #define PM_EVENT_ON 0x0000
393 #define PM_EVENT_FREEZE 0x0001
394 #define PM_EVENT_SUSPEND 0x0002
395 #define PM_EVENT_HIBERNATE 0x0004
396 #define PM_EVENT_QUIESCE 0x0008
397 #define PM_EVENT_RESUME 0x0010
398 #define PM_EVENT_THAW 0x0020
399 #define PM_EVENT_RESTORE 0x0040
400 #define PM_EVENT_RECOVER 0x0080
401 #define PM_EVENT_USER 0x0100
402 #define PM_EVENT_REMOTE 0x0200
403 #define PM_EVENT_AUTO 0x0400
404 
405 #define PM_EVENT_SLEEP (PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
406 #define PM_EVENT_USER_SUSPEND (PM_EVENT_USER | PM_EVENT_SUSPEND)
407 #define PM_EVENT_USER_RESUME (PM_EVENT_USER | PM_EVENT_RESUME)
408 #define PM_EVENT_REMOTE_RESUME (PM_EVENT_REMOTE | PM_EVENT_RESUME)
409 #define PM_EVENT_AUTO_SUSPEND (PM_EVENT_AUTO | PM_EVENT_SUSPEND)
410 #define PM_EVENT_AUTO_RESUME (PM_EVENT_AUTO | PM_EVENT_RESUME)
411 
412 #define PMSG_INVALID ((struct pm_message){ .event = PM_EVENT_INVALID, })
413 #define PMSG_ON ((struct pm_message){ .event = PM_EVENT_ON, })
414 #define PMSG_FREEZE ((struct pm_message){ .event = PM_EVENT_FREEZE, })
415 #define PMSG_QUIESCE ((struct pm_message){ .event = PM_EVENT_QUIESCE, })
416 #define PMSG_SUSPEND ((struct pm_message){ .event = PM_EVENT_SUSPEND, })
417 #define PMSG_HIBERNATE ((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
418 #define PMSG_RESUME ((struct pm_message){ .event = PM_EVENT_RESUME, })
419 #define PMSG_THAW ((struct pm_message){ .event = PM_EVENT_THAW, })
420 #define PMSG_RESTORE ((struct pm_message){ .event = PM_EVENT_RESTORE, })
421 #define PMSG_RECOVER ((struct pm_message){ .event = PM_EVENT_RECOVER, })
422 #define PMSG_USER_SUSPEND ((struct pm_message) \
423  { .event = PM_EVENT_USER_SUSPEND, })
424 #define PMSG_USER_RESUME ((struct pm_message) \
425  { .event = PM_EVENT_USER_RESUME, })
426 #define PMSG_REMOTE_RESUME ((struct pm_message) \
427  { .event = PM_EVENT_REMOTE_RESUME, })
428 #define PMSG_AUTO_SUSPEND ((struct pm_message) \
429  { .event = PM_EVENT_AUTO_SUSPEND, })
430 #define PMSG_AUTO_RESUME ((struct pm_message) \
431  { .event = PM_EVENT_AUTO_RESUME, })
432 
433 #define PMSG_IS_AUTO(msg) (((msg).event & PM_EVENT_AUTO) != 0)
434 
463 };
464 
486 };
487 
488 struct wakeup_source;
489 
492  struct device *dev;
493 };
494 
497  unsigned int refcount;
498 #ifdef CONFIG_PM_CLK
499  struct list_head clock_list;
500 #endif
501 #ifdef CONFIG_PM_GENERIC_DOMAINS
502  struct pm_domain_data *domain_data;
503 #endif
504 };
505 
506 struct dev_pm_info {
508  unsigned int can_wakeup:1;
509  unsigned int async_suspend:1;
510  bool is_prepared:1; /* Owned by the PM core */
511  bool is_suspended:1; /* Ditto */
513  bool early_init:1; /* Owned by the PM core */
515 #ifdef CONFIG_PM_SLEEP
516  struct list_head entry;
517  struct completion completion;
518  struct wakeup_source *wakeup;
519  bool wakeup_path:1;
520  bool syscore:1;
521 #else
522  unsigned int should_wakeup:1;
523 #endif
524 #ifdef CONFIG_PM_RUNTIME
525  struct timer_list suspend_timer;
526  unsigned long timer_expires;
527  struct work_struct work;
528  wait_queue_head_t wait_queue;
529  atomic_t usage_count;
530  atomic_t child_count;
531  unsigned int disable_depth:3;
532  unsigned int idle_notification:1;
533  unsigned int request_pending:1;
534  unsigned int deferred_resume:1;
535  unsigned int run_wake:1;
536  unsigned int runtime_auto:1;
537  unsigned int no_callbacks:1;
538  unsigned int irq_safe:1;
539  unsigned int use_autosuspend:1;
540  unsigned int timer_autosuspends:1;
541  enum rpm_request request;
542  enum rpm_status runtime_status;
543  int runtime_error;
544  int autosuspend_delay;
545  unsigned long last_busy;
546  unsigned long active_jiffies;
547  unsigned long suspended_jiffies;
548  unsigned long accounting_timestamp;
549  struct dev_pm_qos_request *pq_req;
550 #endif
551  struct pm_subsys_data *subsys_data; /* Owned by the subsystem. */
553 };
554 
555 extern void update_pm_runtime_accounting(struct device *dev);
556 extern int dev_pm_get_subsys_data(struct device *dev);
557 extern int dev_pm_put_subsys_data(struct device *dev);
558 
559 /*
560  * Power domains provide callbacks that are executed during system suspend,
561  * hibernation, system resume and during runtime PM transitions along with
562  * subsystem-level and driver-level callbacks.
563  */
565  struct dev_pm_ops ops;
566 };
567 
568 /*
569  * The PM_EVENT_ messages are also used by drivers implementing the legacy
570  * suspend framework, based on the ->suspend() and ->resume() callbacks common
571  * for suspend and hibernation transitions, according to the rules below.
572  */
573 
574 /* Necessary, because several drivers use PM_EVENT_PRETHAW */
575 #define PM_EVENT_PRETHAW PM_EVENT_QUIESCE
576 
577 /*
578  * One transition is triggered by resume(), after a suspend() call; the
579  * message is implicit:
580  *
581  * ON Driver starts working again, responding to hardware events
582  * and software requests. The hardware may have gone through
583  * a power-off reset, or it may have maintained state from the
584  * previous suspend() which the driver will rely on while
585  * resuming. On most platforms, there are no restrictions on
586  * availability of resources like clocks during resume().
587  *
588  * Other transitions are triggered by messages sent using suspend(). All
589  * these transitions quiesce the driver, so that I/O queues are inactive.
590  * That commonly entails turning off IRQs and DMA; there may be rules
591  * about how to quiesce that are specific to the bus or the device's type.
592  * (For example, network drivers mark the link state.) Other details may
593  * differ according to the message:
594  *
595  * SUSPEND Quiesce, enter a low power device state appropriate for
596  * the upcoming system state (such as PCI_D3hot), and enable
597  * wakeup events as appropriate.
598  *
599  * HIBERNATE Enter a low power device state appropriate for the hibernation
600  * state (eg. ACPI S4) and enable wakeup events as appropriate.
601  *
602  * FREEZE Quiesce operations so that a consistent image can be saved;
603  * but do NOT otherwise enter a low power device state, and do
604  * NOT emit system wakeup events.
605  *
606  * PRETHAW Quiesce as if for FREEZE; additionally, prepare for restoring
607  * the system from a snapshot taken after an earlier FREEZE.
608  * Some drivers will need to reset their hardware state instead
609  * of preserving it, to ensure that it's never mistaken for the
610  * state which that earlier snapshot had set up.
611  *
612  * A minimally power-aware driver treats all messages as SUSPEND, fully
613  * reinitializes its device during resume() -- whether or not it was reset
614  * during the suspend/resume cycle -- and can't issue wakeup events.
615  *
616  * More power-aware drivers may also use low power states at runtime as
617  * well as during system sleep states like PM_SUSPEND_STANDBY. They may
618  * be able to use wakeup events to exit from runtime low-power states,
619  * or from system low-power states such as standby or suspend-to-RAM.
620  */
621 
622 #ifdef CONFIG_PM_SLEEP
623 extern void device_pm_lock(void);
624 extern void dpm_resume_start(pm_message_t state);
625 extern void dpm_resume_end(pm_message_t state);
626 extern void dpm_resume(pm_message_t state);
627 extern void dpm_complete(pm_message_t state);
628 
629 extern void device_pm_unlock(void);
632 extern int dpm_suspend(pm_message_t state);
633 extern int dpm_prepare(pm_message_t state);
634 
635 extern void __suspend_report_result(const char *function, void *fn, int ret);
636 
637 #define suspend_report_result(fn, ret) \
638  do { \
639  __suspend_report_result(__func__, fn, ret); \
640  } while (0)
641 
642 extern int device_pm_wait_for_dev(struct device *sub, struct device *dev);
643 extern void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *));
644 
645 extern int pm_generic_prepare(struct device *dev);
646 extern int pm_generic_suspend_late(struct device *dev);
647 extern int pm_generic_suspend_noirq(struct device *dev);
648 extern int pm_generic_suspend(struct device *dev);
649 extern int pm_generic_resume_early(struct device *dev);
650 extern int pm_generic_resume_noirq(struct device *dev);
651 extern int pm_generic_resume(struct device *dev);
652 extern int pm_generic_freeze_noirq(struct device *dev);
653 extern int pm_generic_freeze_late(struct device *dev);
654 extern int pm_generic_freeze(struct device *dev);
655 extern int pm_generic_thaw_noirq(struct device *dev);
656 extern int pm_generic_thaw_early(struct device *dev);
657 extern int pm_generic_thaw(struct device *dev);
658 extern int pm_generic_restore_noirq(struct device *dev);
659 extern int pm_generic_restore_early(struct device *dev);
660 extern int pm_generic_restore(struct device *dev);
661 extern int pm_generic_poweroff_noirq(struct device *dev);
662 extern int pm_generic_poweroff_late(struct device *dev);
663 extern int pm_generic_poweroff(struct device *dev);
664 extern void pm_generic_complete(struct device *dev);
665 
666 #else /* !CONFIG_PM_SLEEP */
667 
668 #define device_pm_lock() do {} while (0)
669 #define device_pm_unlock() do {} while (0)
670 
671 static inline int dpm_suspend_start(pm_message_t state)
672 {
673  return 0;
674 }
675 
676 #define suspend_report_result(fn, ret) do {} while (0)
677 
678 static inline int device_pm_wait_for_dev(struct device *a, struct device *b)
679 {
680  return 0;
681 }
682 
683 static inline void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *))
684 {
685 }
686 
687 #define pm_generic_prepare NULL
688 #define pm_generic_suspend NULL
689 #define pm_generic_resume NULL
690 #define pm_generic_freeze NULL
691 #define pm_generic_thaw NULL
692 #define pm_generic_restore NULL
693 #define pm_generic_poweroff NULL
694 #define pm_generic_complete NULL
695 #endif /* !CONFIG_PM_SLEEP */
696 
697 /* How to reorder dpm_list after device_move() */
698 enum dpm_order {
703 };
704 
705 #endif /* _LINUX_PM_H */