cpuidle.h 4.9 KB

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