cpuidle.h 6.0 KB

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