cpuidle.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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_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. };
  84. DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
  85. /**
  86. * cpuidle_get_last_residency - retrieves the last state's residency time
  87. * @dev: the target CPU
  88. *
  89. * NOTE: this value is invalid if CPUIDLE_FLAG_TIME_VALID isn't set
  90. */
  91. static inline int cpuidle_get_last_residency(struct cpuidle_device *dev)
  92. {
  93. return dev->last_residency;
  94. }
  95. /****************************
  96. * CPUIDLE DRIVER INTERFACE *
  97. ****************************/
  98. struct cpuidle_driver {
  99. const char *name;
  100. struct module *owner;
  101. unsigned int power_specified:1;
  102. /* set to 1 to use the core cpuidle time keeping (for all states). */
  103. unsigned int en_core_tk_irqen:1;
  104. struct cpuidle_state states[CPUIDLE_STATE_MAX];
  105. int state_count;
  106. int safe_state_index;
  107. };
  108. #ifdef CONFIG_CPU_IDLE
  109. extern void disable_cpuidle(void);
  110. extern int cpuidle_idle_call(void);
  111. extern int cpuidle_register_driver(struct cpuidle_driver *drv);
  112. extern struct cpuidle_driver *cpuidle_get_driver(void);
  113. extern struct cpuidle_driver *cpuidle_driver_ref(void);
  114. extern void cpuidle_driver_unref(void);
  115. extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
  116. extern int cpuidle_register_device(struct cpuidle_device *dev);
  117. extern void cpuidle_unregister_device(struct cpuidle_device *dev);
  118. extern void cpuidle_pause_and_lock(void);
  119. extern void cpuidle_resume_and_unlock(void);
  120. extern int cpuidle_enable_device(struct cpuidle_device *dev);
  121. extern void cpuidle_disable_device(struct cpuidle_device *dev);
  122. extern int cpuidle_wrap_enter(struct cpuidle_device *dev,
  123. struct cpuidle_driver *drv, int index,
  124. int (*enter)(struct cpuidle_device *dev,
  125. struct cpuidle_driver *drv, int index));
  126. extern int cpuidle_play_dead(void);
  127. #else
  128. static inline void disable_cpuidle(void) { }
  129. static inline int cpuidle_idle_call(void) { return -ENODEV; }
  130. static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
  131. {return -ENODEV; }
  132. static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
  133. static inline struct cpuidle_driver *cpuidle_driver_ref(void) {return NULL; }
  134. static inline void cpuidle_driver_unref(void) {}
  135. static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
  136. static inline int cpuidle_register_device(struct cpuidle_device *dev)
  137. {return -ENODEV; }
  138. static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
  139. static inline void cpuidle_pause_and_lock(void) { }
  140. static inline void cpuidle_resume_and_unlock(void) { }
  141. static inline int cpuidle_enable_device(struct cpuidle_device *dev)
  142. {return -ENODEV; }
  143. static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
  144. static inline int cpuidle_wrap_enter(struct cpuidle_device *dev,
  145. struct cpuidle_driver *drv, int index,
  146. int (*enter)(struct cpuidle_device *dev,
  147. struct cpuidle_driver *drv, int index))
  148. { return -ENODEV; }
  149. static inline int cpuidle_play_dead(void) {return -ENODEV; }
  150. #endif
  151. /******************************
  152. * CPUIDLE GOVERNOR INTERFACE *
  153. ******************************/
  154. struct cpuidle_governor {
  155. char name[CPUIDLE_NAME_LEN];
  156. struct list_head governor_list;
  157. unsigned int rating;
  158. int (*enable) (struct cpuidle_driver *drv,
  159. struct cpuidle_device *dev);
  160. void (*disable) (struct cpuidle_driver *drv,
  161. struct cpuidle_device *dev);
  162. int (*select) (struct cpuidle_driver *drv,
  163. struct cpuidle_device *dev);
  164. void (*reflect) (struct cpuidle_device *dev, int index);
  165. struct module *owner;
  166. };
  167. #ifdef CONFIG_CPU_IDLE
  168. extern int cpuidle_register_governor(struct cpuidle_governor *gov);
  169. extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
  170. #ifdef CONFIG_INTEL_IDLE
  171. extern int intel_idle_cpu_init(int cpu);
  172. #else
  173. static inline int intel_idle_cpu_init(int cpu) { return -1; }
  174. #endif
  175. #else
  176. static inline int intel_idle_cpu_init(int cpu) { return -1; }
  177. static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
  178. {return 0;}
  179. static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { }
  180. #endif
  181. #ifdef CONFIG_ARCH_HAS_CPU_RELAX
  182. #define CPUIDLE_DRIVER_STATE_START 1
  183. #else
  184. #define CPUIDLE_DRIVER_STATE_START 0
  185. #endif
  186. #endif /* _LINUX_CPUIDLE_H */