cpuidle.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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/module.h>
  15. #include <linux/kobject.h>
  16. #include <linux/completion.h>
  17. #define CPUIDLE_STATE_MAX 8
  18. #define CPUIDLE_NAME_LEN 16
  19. #define CPUIDLE_DESC_LEN 32
  20. struct cpuidle_device;
  21. /****************************
  22. * CPUIDLE DEVICE INTERFACE *
  23. ****************************/
  24. struct cpuidle_state {
  25. char name[CPUIDLE_NAME_LEN];
  26. char desc[CPUIDLE_DESC_LEN];
  27. void *driver_data;
  28. unsigned int flags;
  29. unsigned int exit_latency; /* in US */
  30. unsigned int power_usage; /* in mW */
  31. unsigned int target_residency; /* in US */
  32. unsigned long long usage;
  33. unsigned long long time; /* in US */
  34. int (*enter) (struct cpuidle_device *dev,
  35. struct cpuidle_state *state);
  36. };
  37. /* Idle State Flags */
  38. #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
  39. #define CPUIDLE_FLAG_CHECK_BM (0x02) /* BM activity will exit state */
  40. #define CPUIDLE_FLAG_POLL (0x10) /* no latency, no savings */
  41. #define CPUIDLE_FLAG_SHALLOW (0x20) /* low latency, minimal savings */
  42. #define CPUIDLE_FLAG_BALANCED (0x40) /* medium latency, moderate savings */
  43. #define CPUIDLE_FLAG_DEEP (0x80) /* high latency, large savings */
  44. #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
  45. /**
  46. * cpuidle_get_statedata - retrieves private driver state data
  47. * @state: the state
  48. */
  49. static inline void * cpuidle_get_statedata(struct cpuidle_state *state)
  50. {
  51. return state->driver_data;
  52. }
  53. /**
  54. * cpuidle_set_statedata - stores private driver state data
  55. * @state: the state
  56. * @data: the private data
  57. */
  58. static inline void
  59. cpuidle_set_statedata(struct cpuidle_state *state, void *data)
  60. {
  61. state->driver_data = data;
  62. }
  63. struct cpuidle_state_kobj {
  64. struct cpuidle_state *state;
  65. struct completion kobj_unregister;
  66. struct kobject kobj;
  67. };
  68. struct cpuidle_device {
  69. unsigned int enabled:1;
  70. unsigned int cpu;
  71. int last_residency;
  72. int state_count;
  73. struct cpuidle_state states[CPUIDLE_STATE_MAX];
  74. struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
  75. struct cpuidle_state *last_state;
  76. struct list_head device_list;
  77. struct kobject kobj;
  78. struct completion kobj_unregister;
  79. void *governor_data;
  80. struct cpuidle_state *safe_state;
  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. };
  100. #ifdef CONFIG_CPU_IDLE
  101. extern int cpuidle_register_driver(struct cpuidle_driver *drv);
  102. extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
  103. extern int cpuidle_register_device(struct cpuidle_device *dev);
  104. extern void cpuidle_unregister_device(struct cpuidle_device *dev);
  105. extern void cpuidle_pause_and_lock(void);
  106. extern void cpuidle_resume_and_unlock(void);
  107. extern int cpuidle_enable_device(struct cpuidle_device *dev);
  108. extern void cpuidle_disable_device(struct cpuidle_device *dev);
  109. #else
  110. static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
  111. {return 0;}
  112. static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
  113. static inline int cpuidle_register_device(struct cpuidle_device *dev)
  114. {return 0;}
  115. static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
  116. static inline void cpuidle_pause_and_lock(void) { }
  117. static inline void cpuidle_resume_and_unlock(void) { }
  118. static inline int cpuidle_enable_device(struct cpuidle_device *dev)
  119. {return 0;}
  120. static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
  121. #endif
  122. /******************************
  123. * CPUIDLE GOVERNOR INTERFACE *
  124. ******************************/
  125. struct cpuidle_governor {
  126. char name[CPUIDLE_NAME_LEN];
  127. struct list_head governor_list;
  128. unsigned int rating;
  129. int (*enable) (struct cpuidle_device *dev);
  130. void (*disable) (struct cpuidle_device *dev);
  131. int (*select) (struct cpuidle_device *dev);
  132. void (*reflect) (struct cpuidle_device *dev);
  133. struct module *owner;
  134. };
  135. #ifdef CONFIG_CPU_IDLE
  136. extern int cpuidle_register_governor(struct cpuidle_governor *gov);
  137. extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
  138. #else
  139. static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
  140. {return 0;}
  141. static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { }
  142. #endif
  143. #ifdef CONFIG_ARCH_HAS_CPU_RELAX
  144. #define CPUIDLE_DRIVER_STATE_START 1
  145. #else
  146. #define CPUIDLE_DRIVER_STATE_START 0
  147. #endif
  148. #endif /* _LINUX_CPUIDLE_H */