cpuidle.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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/kobject.h>
  15. #include <linux/completion.h>
  16. #include <linux/hrtimer.h>
  17. #define CPUIDLE_STATE_MAX 8
  18. #define CPUIDLE_NAME_LEN 16
  19. #define CPUIDLE_DESC_LEN 32
  20. struct module;
  21. struct cpuidle_device;
  22. struct cpuidle_driver;
  23. /****************************
  24. * CPUIDLE DEVICE INTERFACE *
  25. ****************************/
  26. struct cpuidle_state_usage {
  27. void *driver_data;
  28. unsigned long long disable;
  29. unsigned long long usage;
  30. unsigned long long time; /* in US */
  31. };
  32. struct cpuidle_state {
  33. char name[CPUIDLE_NAME_LEN];
  34. char desc[CPUIDLE_DESC_LEN];
  35. unsigned int flags;
  36. unsigned int exit_latency; /* in US */
  37. int power_usage; /* in mW */
  38. unsigned int target_residency; /* in US */
  39. bool disabled; /* disabled on all CPUs */
  40. int (*enter) (struct cpuidle_device *dev,
  41. struct cpuidle_driver *drv,
  42. int index);
  43. int (*enter_dead) (struct cpuidle_device *dev, int index);
  44. };
  45. /* Idle State Flags */
  46. #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
  47. #define CPUIDLE_FLAG_COUPLED (0x02) /* state applies to multiple cpus */
  48. #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
  49. /**
  50. * cpuidle_get_statedata - retrieves private driver state data
  51. * @st_usage: the state usage statistics
  52. */
  53. static inline void *cpuidle_get_statedata(struct cpuidle_state_usage *st_usage)
  54. {
  55. return st_usage->driver_data;
  56. }
  57. /**
  58. * cpuidle_set_statedata - stores private driver state data
  59. * @st_usage: the state usage statistics
  60. * @data: the private data
  61. */
  62. static inline void
  63. cpuidle_set_statedata(struct cpuidle_state_usage *st_usage, void *data)
  64. {
  65. st_usage->driver_data = data;
  66. }
  67. struct cpuidle_state_kobj {
  68. struct cpuidle_state *state;
  69. struct cpuidle_state_usage *state_usage;
  70. struct completion kobj_unregister;
  71. struct kobject kobj;
  72. };
  73. struct cpuidle_device {
  74. unsigned int registered:1;
  75. unsigned int enabled:1;
  76. unsigned int cpu;
  77. int last_residency;
  78. int state_count;
  79. struct cpuidle_state_usage states_usage[CPUIDLE_STATE_MAX];
  80. struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
  81. struct list_head device_list;
  82. struct kobject kobj;
  83. struct completion kobj_unregister;
  84. #ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
  85. int safe_state_index;
  86. cpumask_t coupled_cpus;
  87. struct cpuidle_coupled *coupled;
  88. #endif
  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. const char *name;
  106. struct module *owner;
  107. unsigned int power_specified:1;
  108. /* set to 1 to use the core cpuidle time keeping (for all states). */
  109. unsigned int en_core_tk_irqen:1;
  110. struct cpuidle_state states[CPUIDLE_STATE_MAX];
  111. int state_count;
  112. int safe_state_index;
  113. };
  114. #ifdef CONFIG_CPU_IDLE
  115. extern void disable_cpuidle(void);
  116. extern int cpuidle_idle_call(void);
  117. extern int cpuidle_register_driver(struct cpuidle_driver *drv);
  118. extern struct cpuidle_driver *cpuidle_get_driver(void);
  119. extern struct cpuidle_driver *cpuidle_driver_ref(void);
  120. extern void cpuidle_driver_unref(void);
  121. extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
  122. extern int cpuidle_register_device(struct cpuidle_device *dev);
  123. extern void cpuidle_unregister_device(struct cpuidle_device *dev);
  124. extern void cpuidle_pause_and_lock(void);
  125. extern void cpuidle_resume_and_unlock(void);
  126. extern void cpuidle_pause(void);
  127. extern void cpuidle_resume(void);
  128. extern int cpuidle_enable_device(struct cpuidle_device *dev);
  129. extern void cpuidle_disable_device(struct cpuidle_device *dev);
  130. extern int cpuidle_wrap_enter(struct cpuidle_device *dev,
  131. struct cpuidle_driver *drv, int index,
  132. int (*enter)(struct cpuidle_device *dev,
  133. struct cpuidle_driver *drv, int index));
  134. extern int cpuidle_play_dead(void);
  135. #else
  136. static inline void disable_cpuidle(void) { }
  137. static inline int cpuidle_idle_call(void) { return -ENODEV; }
  138. static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
  139. {return -ENODEV; }
  140. static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
  141. static inline struct cpuidle_driver *cpuidle_driver_ref(void) {return NULL; }
  142. static inline void cpuidle_driver_unref(void) {}
  143. static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
  144. static inline int cpuidle_register_device(struct cpuidle_device *dev)
  145. {return -ENODEV; }
  146. static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
  147. static inline void cpuidle_pause_and_lock(void) { }
  148. static inline void cpuidle_resume_and_unlock(void) { }
  149. static inline void cpuidle_pause(void) { }
  150. static inline void cpuidle_resume(void) { }
  151. static inline int cpuidle_enable_device(struct cpuidle_device *dev)
  152. {return -ENODEV; }
  153. static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
  154. static inline int cpuidle_wrap_enter(struct cpuidle_device *dev,
  155. struct cpuidle_driver *drv, int index,
  156. int (*enter)(struct cpuidle_device *dev,
  157. struct cpuidle_driver *drv, int index))
  158. { return -ENODEV; }
  159. static inline int cpuidle_play_dead(void) {return -ENODEV; }
  160. #endif
  161. #ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
  162. void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev, atomic_t *a);
  163. #else
  164. static inline void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev, atomic_t *a)
  165. {
  166. }
  167. #endif
  168. /******************************
  169. * CPUIDLE GOVERNOR INTERFACE *
  170. ******************************/
  171. struct cpuidle_governor {
  172. char name[CPUIDLE_NAME_LEN];
  173. struct list_head governor_list;
  174. unsigned int rating;
  175. int (*enable) (struct cpuidle_driver *drv,
  176. struct cpuidle_device *dev);
  177. void (*disable) (struct cpuidle_driver *drv,
  178. struct cpuidle_device *dev);
  179. int (*select) (struct cpuidle_driver *drv,
  180. struct cpuidle_device *dev);
  181. void (*reflect) (struct cpuidle_device *dev, int index);
  182. struct module *owner;
  183. };
  184. #ifdef CONFIG_CPU_IDLE
  185. extern int cpuidle_register_governor(struct cpuidle_governor *gov);
  186. extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
  187. #else
  188. static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
  189. {return 0;}
  190. static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { }
  191. #endif
  192. #ifdef CONFIG_ARCH_HAS_CPU_RELAX
  193. #define CPUIDLE_DRIVER_STATE_START 1
  194. #else
  195. #define CPUIDLE_DRIVER_STATE_START 0
  196. #endif
  197. #endif /* _LINUX_CPUIDLE_H */