cpuidle.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 registered:1;
  70. unsigned int enabled:1;
  71. unsigned int cpu;
  72. int last_residency;
  73. int state_count;
  74. struct cpuidle_state states[CPUIDLE_STATE_MAX];
  75. struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
  76. struct cpuidle_state *last_state;
  77. struct list_head device_list;
  78. struct kobject kobj;
  79. struct completion kobj_unregister;
  80. void *governor_data;
  81. struct cpuidle_state *safe_state;
  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. char name[CPUIDLE_NAME_LEN];
  99. struct module *owner;
  100. };
  101. #ifdef CONFIG_CPU_IDLE
  102. extern int cpuidle_register_driver(struct cpuidle_driver *drv);
  103. struct cpuidle_driver *cpuidle_get_driver(void);
  104. extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
  105. extern int cpuidle_register_device(struct cpuidle_device *dev);
  106. extern void cpuidle_unregister_device(struct cpuidle_device *dev);
  107. extern void cpuidle_pause_and_lock(void);
  108. extern void cpuidle_resume_and_unlock(void);
  109. extern int cpuidle_enable_device(struct cpuidle_device *dev);
  110. extern void cpuidle_disable_device(struct cpuidle_device *dev);
  111. #else
  112. static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
  113. {return -ENODEV; }
  114. static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
  115. static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
  116. static inline int cpuidle_register_device(struct cpuidle_device *dev)
  117. {return -ENODEV; }
  118. static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
  119. static inline void cpuidle_pause_and_lock(void) { }
  120. static inline void cpuidle_resume_and_unlock(void) { }
  121. static inline int cpuidle_enable_device(struct cpuidle_device *dev)
  122. {return -ENODEV; }
  123. static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
  124. #endif
  125. /******************************
  126. * CPUIDLE GOVERNOR INTERFACE *
  127. ******************************/
  128. struct cpuidle_governor {
  129. char name[CPUIDLE_NAME_LEN];
  130. struct list_head governor_list;
  131. unsigned int rating;
  132. int (*enable) (struct cpuidle_device *dev);
  133. void (*disable) (struct cpuidle_device *dev);
  134. int (*select) (struct cpuidle_device *dev);
  135. void (*reflect) (struct cpuidle_device *dev);
  136. struct module *owner;
  137. };
  138. #ifdef CONFIG_CPU_IDLE
  139. extern int cpuidle_register_governor(struct cpuidle_governor *gov);
  140. extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
  141. #else
  142. static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
  143. {return 0;}
  144. static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { }
  145. #endif
  146. #ifdef CONFIG_ARCH_HAS_CPU_RELAX
  147. #define CPUIDLE_DRIVER_STATE_START 1
  148. #else
  149. #define CPUIDLE_DRIVER_STATE_START 0
  150. #endif
  151. #endif /* _LINUX_CPUIDLE_H */