cpuidle.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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_FLAG_IGNORE (0x100) /* ignore during this idle period */
  45. #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
  46. /**
  47. * cpuidle_get_statedata - retrieves private driver state data
  48. * @state: the state
  49. */
  50. static inline void * cpuidle_get_statedata(struct cpuidle_state *state)
  51. {
  52. return state->driver_data;
  53. }
  54. /**
  55. * cpuidle_set_statedata - stores private driver state data
  56. * @state: the state
  57. * @data: the private data
  58. */
  59. static inline void
  60. cpuidle_set_statedata(struct cpuidle_state *state, void *data)
  61. {
  62. state->driver_data = data;
  63. }
  64. struct cpuidle_state_kobj {
  65. struct cpuidle_state *state;
  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 power_specified:1;
  73. unsigned int cpu;
  74. int last_residency;
  75. int state_count;
  76. struct cpuidle_state states[CPUIDLE_STATE_MAX];
  77. struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
  78. struct cpuidle_state *last_state;
  79. struct list_head device_list;
  80. struct kobject kobj;
  81. struct completion kobj_unregister;
  82. void *governor_data;
  83. struct cpuidle_state *safe_state;
  84. int (*prepare) (struct cpuidle_device *dev);
  85. };
  86. DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
  87. /**
  88. * cpuidle_get_last_residency - retrieves the last state's residency time
  89. * @dev: the target CPU
  90. *
  91. * NOTE: this value is invalid if CPUIDLE_FLAG_TIME_VALID isn't set
  92. */
  93. static inline int cpuidle_get_last_residency(struct cpuidle_device *dev)
  94. {
  95. return dev->last_residency;
  96. }
  97. /****************************
  98. * CPUIDLE DRIVER INTERFACE *
  99. ****************************/
  100. struct cpuidle_driver {
  101. char name[CPUIDLE_NAME_LEN];
  102. struct module *owner;
  103. };
  104. #ifdef CONFIG_CPU_IDLE
  105. extern int cpuidle_register_driver(struct cpuidle_driver *drv);
  106. struct cpuidle_driver *cpuidle_get_driver(void);
  107. extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
  108. extern int cpuidle_register_device(struct cpuidle_device *dev);
  109. extern void cpuidle_unregister_device(struct cpuidle_device *dev);
  110. extern void cpuidle_pause_and_lock(void);
  111. extern void cpuidle_resume_and_unlock(void);
  112. extern int cpuidle_enable_device(struct cpuidle_device *dev);
  113. extern void cpuidle_disable_device(struct cpuidle_device *dev);
  114. #else
  115. static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
  116. {return -ENODEV; }
  117. static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
  118. static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
  119. static inline int cpuidle_register_device(struct cpuidle_device *dev)
  120. {return -ENODEV; }
  121. static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
  122. static inline void cpuidle_pause_and_lock(void) { }
  123. static inline void cpuidle_resume_and_unlock(void) { }
  124. static inline int cpuidle_enable_device(struct cpuidle_device *dev)
  125. {return -ENODEV; }
  126. static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
  127. #endif
  128. /******************************
  129. * CPUIDLE GOVERNOR INTERFACE *
  130. ******************************/
  131. struct cpuidle_governor {
  132. char name[CPUIDLE_NAME_LEN];
  133. struct list_head governor_list;
  134. unsigned int rating;
  135. int (*enable) (struct cpuidle_device *dev);
  136. void (*disable) (struct cpuidle_device *dev);
  137. int (*select) (struct cpuidle_device *dev);
  138. void (*reflect) (struct cpuidle_device *dev);
  139. struct module *owner;
  140. };
  141. #ifdef CONFIG_CPU_IDLE
  142. extern int cpuidle_register_governor(struct cpuidle_governor *gov);
  143. extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
  144. #else
  145. static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
  146. {return 0;}
  147. static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { }
  148. #endif
  149. #ifdef CONFIG_ARCH_HAS_CPU_RELAX
  150. #define CPUIDLE_DRIVER_STATE_START 1
  151. #else
  152. #define CPUIDLE_DRIVER_STATE_START 0
  153. #endif
  154. #endif /* _LINUX_CPUIDLE_H */