cpuidle.h 6.1 KB

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