cpuidle.h 5.1 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/kobject.h>
  15. #include <linux/completion.h>
  16. #define CPUIDLE_STATE_MAX 8
  17. #define CPUIDLE_NAME_LEN 16
  18. #define CPUIDLE_DESC_LEN 32
  19. struct module;
  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_IGNORE (0x100) /* ignore during this idle period */
  40. #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
  41. /**
  42. * cpuidle_get_statedata - retrieves private driver state data
  43. * @state: the state
  44. */
  45. static inline void * cpuidle_get_statedata(struct cpuidle_state *state)
  46. {
  47. return state->driver_data;
  48. }
  49. /**
  50. * cpuidle_set_statedata - stores private driver state data
  51. * @state: the state
  52. * @data: the private data
  53. */
  54. static inline void
  55. cpuidle_set_statedata(struct cpuidle_state *state, void *data)
  56. {
  57. state->driver_data = data;
  58. }
  59. struct cpuidle_state_kobj {
  60. struct cpuidle_state *state;
  61. struct completion kobj_unregister;
  62. struct kobject kobj;
  63. };
  64. struct cpuidle_device {
  65. unsigned int registered:1;
  66. unsigned int enabled:1;
  67. unsigned int power_specified: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. int (*prepare) (struct cpuidle_device *dev);
  80. };
  81. DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
  82. /**
  83. * cpuidle_get_last_residency - retrieves the last state's residency time
  84. * @dev: the target CPU
  85. *
  86. * NOTE: this value is invalid if CPUIDLE_FLAG_TIME_VALID isn't set
  87. */
  88. static inline int cpuidle_get_last_residency(struct cpuidle_device *dev)
  89. {
  90. return dev->last_residency;
  91. }
  92. /****************************
  93. * CPUIDLE DRIVER INTERFACE *
  94. ****************************/
  95. struct cpuidle_driver {
  96. char name[CPUIDLE_NAME_LEN];
  97. struct module *owner;
  98. };
  99. #ifdef CONFIG_CPU_IDLE
  100. extern void disable_cpuidle(void);
  101. extern int cpuidle_idle_call(void);
  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 void disable_cpuidle(void) { }
  113. static inline int cpuidle_idle_call(void) { return -ENODEV; }
  114. static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
  115. {return -ENODEV; }
  116. static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
  117. static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
  118. static inline int cpuidle_register_device(struct cpuidle_device *dev)
  119. {return -ENODEV; }
  120. static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
  121. static inline void cpuidle_pause_and_lock(void) { }
  122. static inline void cpuidle_resume_and_unlock(void) { }
  123. static inline int cpuidle_enable_device(struct cpuidle_device *dev)
  124. {return -ENODEV; }
  125. static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
  126. #endif
  127. /******************************
  128. * CPUIDLE GOVERNOR INTERFACE *
  129. ******************************/
  130. struct cpuidle_governor {
  131. char name[CPUIDLE_NAME_LEN];
  132. struct list_head governor_list;
  133. unsigned int rating;
  134. int (*enable) (struct cpuidle_device *dev);
  135. void (*disable) (struct cpuidle_device *dev);
  136. int (*select) (struct cpuidle_device *dev);
  137. void (*reflect) (struct cpuidle_device *dev);
  138. struct module *owner;
  139. };
  140. #ifdef CONFIG_CPU_IDLE
  141. extern int cpuidle_register_governor(struct cpuidle_governor *gov);
  142. extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
  143. #else
  144. static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
  145. {return 0;}
  146. static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { }
  147. #endif
  148. #ifdef CONFIG_ARCH_HAS_CPU_RELAX
  149. #define CPUIDLE_DRIVER_STATE_START 1
  150. #else
  151. #define CPUIDLE_DRIVER_STATE_START 0
  152. #endif
  153. #endif /* _LINUX_CPUIDLE_H */