cpuidle.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * cpuidle.h - a generic framework for CPU idle power management
  3. *
  4. * (C) 2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
  5. * Shaohua Li <shaohua.li@intel.com>
  6. * Adam Belay <abelay@novell.com>
  7. *
  8. * This code is licenced under the GPL.
  9. */
  10. #ifndef _LINUX_CPUIDLE_H
  11. #define _LINUX_CPUIDLE_H
  12. #include <linux/percpu.h>
  13. #include <linux/list.h>
  14. #include <linux/module.h>
  15. #include <linux/kobject.h>
  16. #include <linux/completion.h>
  17. #define CPUIDLE_STATE_MAX 8
  18. #define CPUIDLE_NAME_LEN 16
  19. struct cpuidle_device;
  20. /****************************
  21. * CPUIDLE DEVICE INTERFACE *
  22. ****************************/
  23. struct cpuidle_state {
  24. char name[CPUIDLE_NAME_LEN];
  25. void *driver_data;
  26. unsigned int flags;
  27. unsigned int exit_latency; /* in US */
  28. unsigned int power_usage; /* in mW */
  29. unsigned int target_residency; /* in US */
  30. unsigned int usage;
  31. unsigned int time; /* in US */
  32. int (*enter) (struct cpuidle_device *dev,
  33. struct cpuidle_state *state);
  34. };
  35. /* Idle State Flags */
  36. #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
  37. #define CPUIDLE_FLAG_CHECK_BM (0x02) /* BM activity will exit state */
  38. #define CPUIDLE_FLAG_SHALLOW (0x10) /* low latency, minimal savings */
  39. #define CPUIDLE_FLAG_BALANCED (0x20) /* medium latency, moderate savings */
  40. #define CPUIDLE_FLAG_DEEP (0x40) /* high latency, large savings */
  41. #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
  42. /**
  43. * cpuidle_get_statedata - retrieves private driver state data
  44. * @state: the state
  45. */
  46. static inline void * cpuidle_get_statedata(struct cpuidle_state *state)
  47. {
  48. return state->driver_data;
  49. }
  50. /**
  51. * cpuidle_set_statedata - stores private driver state data
  52. * @state: the state
  53. * @data: the private data
  54. */
  55. static inline void
  56. cpuidle_set_statedata(struct cpuidle_state *state, void *data)
  57. {
  58. state->driver_data = data;
  59. }
  60. #ifdef CONFIG_SMP
  61. #ifdef CONFIG_ARCH_HAS_CPU_IDLE_WAIT
  62. static inline void cpuidle_kick_cpus(void)
  63. {
  64. cpu_idle_wait();
  65. }
  66. #else /* !CONFIG_ARCH_HAS_CPU_IDLE_WAIT */
  67. #error "Arch needs cpu_idle_wait() equivalent here"
  68. #endif /* !CONFIG_ARCH_HAS_CPU_IDLE_WAIT */
  69. #else /* !CONFIG_SMP */
  70. static inline void cpuidle_kick_cpus(void) {}
  71. #endif /* !CONFIG_SMP */
  72. struct cpuidle_state_kobj {
  73. struct cpuidle_state *state;
  74. struct completion kobj_unregister;
  75. struct kobject kobj;
  76. };
  77. struct cpuidle_device {
  78. int enabled:1;
  79. unsigned int cpu;
  80. int last_residency;
  81. int state_count;
  82. struct cpuidle_state states[CPUIDLE_STATE_MAX];
  83. struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
  84. struct cpuidle_state *last_state;
  85. struct list_head device_list;
  86. struct kobject kobj;
  87. struct completion kobj_unregister;
  88. void *governor_data;
  89. };
  90. DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
  91. /**
  92. * cpuidle_get_last_residency - retrieves the last state's residency time
  93. * @dev: the target CPU
  94. *
  95. * NOTE: this value is invalid if CPUIDLE_FLAG_TIME_VALID isn't set
  96. */
  97. static inline int cpuidle_get_last_residency(struct cpuidle_device *dev)
  98. {
  99. return dev->last_residency;
  100. }
  101. /****************************
  102. * CPUIDLE DRIVER INTERFACE *
  103. ****************************/
  104. struct cpuidle_driver {
  105. char name[CPUIDLE_NAME_LEN];
  106. struct module *owner;
  107. };
  108. #ifdef CONFIG_CPU_IDLE
  109. extern int cpuidle_register_driver(struct cpuidle_driver *drv);
  110. extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
  111. extern int cpuidle_register_device(struct cpuidle_device *dev);
  112. extern void cpuidle_unregister_device(struct cpuidle_device *dev);
  113. extern void cpuidle_pause_and_lock(void);
  114. extern void cpuidle_resume_and_unlock(void);
  115. extern int cpuidle_enable_device(struct cpuidle_device *dev);
  116. extern void cpuidle_disable_device(struct cpuidle_device *dev);
  117. #else
  118. static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
  119. {return 0;}
  120. static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
  121. static inline int cpuidle_register_device(struct cpuidle_device *dev)
  122. {return 0;}
  123. static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
  124. static inline void cpuidle_pause_and_lock(void) { }
  125. static inline void cpuidle_resume_and_unlock(void) { }
  126. static inline int cpuidle_enable_device(struct cpuidle_device *dev)
  127. {return 0;}
  128. static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
  129. #endif
  130. /******************************
  131. * CPUIDLE GOVERNOR INTERFACE *
  132. ******************************/
  133. struct cpuidle_governor {
  134. char name[CPUIDLE_NAME_LEN];
  135. struct list_head governor_list;
  136. unsigned int rating;
  137. int (*enable) (struct cpuidle_device *dev);
  138. void (*disable) (struct cpuidle_device *dev);
  139. int (*select) (struct cpuidle_device *dev);
  140. void (*reflect) (struct cpuidle_device *dev);
  141. struct module *owner;
  142. };
  143. #ifdef CONFIG_CPU_IDLE
  144. extern int cpuidle_register_governor(struct cpuidle_governor *gov);
  145. extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
  146. #else
  147. static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
  148. {return 0;}
  149. static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { }
  150. #endif
  151. #endif /* _LINUX_CPUIDLE_H */