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 usage;
  29. unsigned long long time; /* in US */
  30. };
  31. struct cpuidle_state {
  32. char name[CPUIDLE_NAME_LEN];
  33. char desc[CPUIDLE_DESC_LEN];
  34. unsigned int flags;
  35. unsigned int exit_latency; /* in US */
  36. int power_usage; /* in mW */
  37. unsigned int target_residency; /* in US */
  38. unsigned int disable;
  39. int (*enter) (struct cpuidle_device *dev,
  40. struct cpuidle_driver *drv,
  41. int index);
  42. int (*enter_dead) (struct cpuidle_device *dev, int index);
  43. };
  44. /* Idle State Flags */
  45. #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
  46. #define CPUIDLE_FLAG_COUPLED (0x02) /* state applies to multiple cpus */
  47. #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
  48. /**
  49. * cpuidle_get_statedata - retrieves private driver state data
  50. * @st_usage: the state usage statistics
  51. */
  52. static inline void *cpuidle_get_statedata(struct cpuidle_state_usage *st_usage)
  53. {
  54. return st_usage->driver_data;
  55. }
  56. /**
  57. * cpuidle_set_statedata - stores private driver state data
  58. * @st_usage: the state usage statistics
  59. * @data: the private data
  60. */
  61. static inline void
  62. cpuidle_set_statedata(struct cpuidle_state_usage *st_usage, void *data)
  63. {
  64. st_usage->driver_data = data;
  65. }
  66. struct cpuidle_state_kobj {
  67. struct cpuidle_state *state;
  68. struct cpuidle_state_usage *state_usage;
  69. struct completion kobj_unregister;
  70. struct kobject kobj;
  71. };
  72. struct cpuidle_device {
  73. unsigned int registered:1;
  74. unsigned int enabled:1;
  75. unsigned int cpu;
  76. int last_residency;
  77. int state_count;
  78. struct cpuidle_state_usage states_usage[CPUIDLE_STATE_MAX];
  79. struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
  80. struct list_head device_list;
  81. struct kobject kobj;
  82. struct completion kobj_unregister;
  83. #ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
  84. int safe_state_index;
  85. cpumask_t coupled_cpus;
  86. struct cpuidle_coupled *coupled;
  87. #endif
  88. };
  89. DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
  90. /**
  91. * cpuidle_get_last_residency - retrieves the last state's residency time
  92. * @dev: the target CPU
  93. *
  94. * NOTE: this value is invalid if CPUIDLE_FLAG_TIME_VALID isn't set
  95. */
  96. static inline int cpuidle_get_last_residency(struct cpuidle_device *dev)
  97. {
  98. return dev->last_residency;
  99. }
  100. /****************************
  101. * CPUIDLE DRIVER INTERFACE *
  102. ****************************/
  103. struct cpuidle_driver {
  104. const char *name;
  105. struct module *owner;
  106. unsigned int power_specified:1;
  107. /* set to 1 to use the core cpuidle time keeping (for all states). */
  108. unsigned int en_core_tk_irqen:1;
  109. struct cpuidle_state states[CPUIDLE_STATE_MAX];
  110. int state_count;
  111. int safe_state_index;
  112. };
  113. #ifdef CONFIG_CPU_IDLE
  114. extern void disable_cpuidle(void);
  115. extern int cpuidle_idle_call(void);
  116. extern int cpuidle_register_driver(struct cpuidle_driver *drv);
  117. struct cpuidle_driver *cpuidle_get_driver(void);
  118. extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
  119. extern int cpuidle_register_device(struct cpuidle_device *dev);
  120. extern void cpuidle_unregister_device(struct cpuidle_device *dev);
  121. extern int cpuidle_register(struct cpuidle_driver *drv,
  122. const struct cpumask *const coupled_cpus);
  123. extern void cpuidle_unregister(struct cpuidle_driver *drv);
  124. extern void cpuidle_pause_and_lock(void);
  125. extern void cpuidle_resume_and_unlock(void);
  126. extern int cpuidle_enable_device(struct cpuidle_device *dev);
  127. extern void cpuidle_disable_device(struct cpuidle_device *dev);
  128. extern int cpuidle_wrap_enter(struct cpuidle_device *dev,
  129. struct cpuidle_driver *drv, int index,
  130. int (*enter)(struct cpuidle_device *dev,
  131. struct cpuidle_driver *drv, int index));
  132. extern int cpuidle_play_dead(void);
  133. #else
  134. static inline void disable_cpuidle(void) { }
  135. static inline int cpuidle_idle_call(void) { return -ENODEV; }
  136. static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
  137. {return -ENODEV; }
  138. static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
  139. static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
  140. static inline int cpuidle_register_device(struct cpuidle_device *dev)
  141. {return -ENODEV; }
  142. static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
  143. static inline int cpuidle_register(struct cpuidle_driver *drv,
  144. const struct cpumask *const coupled_cpus)
  145. {return -ENODEV; }
  146. static inline void cpuidle_unregister(struct cpuidle_driver *drv) { }
  147. static inline void cpuidle_pause_and_lock(void) { }
  148. static inline void cpuidle_resume_and_unlock(void) { }
  149. static inline int cpuidle_enable_device(struct cpuidle_device *dev)
  150. {return -ENODEV; }
  151. static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
  152. static inline int cpuidle_wrap_enter(struct cpuidle_device *dev,
  153. struct cpuidle_driver *drv, int index,
  154. int (*enter)(struct cpuidle_device *dev,
  155. struct cpuidle_driver *drv, int index))
  156. { return -ENODEV; }
  157. static inline int cpuidle_play_dead(void) {return -ENODEV; }
  158. #endif
  159. #ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
  160. void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev, atomic_t *a);
  161. #endif
  162. /******************************
  163. * CPUIDLE GOVERNOR INTERFACE *
  164. ******************************/
  165. struct cpuidle_governor {
  166. char name[CPUIDLE_NAME_LEN];
  167. struct list_head governor_list;
  168. unsigned int rating;
  169. int (*enable) (struct cpuidle_driver *drv,
  170. struct cpuidle_device *dev);
  171. void (*disable) (struct cpuidle_driver *drv,
  172. struct cpuidle_device *dev);
  173. int (*select) (struct cpuidle_driver *drv,
  174. struct cpuidle_device *dev);
  175. void (*reflect) (struct cpuidle_device *dev, int index);
  176. struct module *owner;
  177. };
  178. #ifdef CONFIG_CPU_IDLE
  179. extern int cpuidle_register_governor(struct cpuidle_governor *gov);
  180. extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
  181. #ifdef CONFIG_INTEL_IDLE
  182. extern int intel_idle_cpu_init(int cpu);
  183. #else
  184. static inline int intel_idle_cpu_init(int cpu) { return -1; }
  185. #endif
  186. #else
  187. static inline int intel_idle_cpu_init(int cpu) { return -1; }
  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 */