cpuidle.h 4.9 KB

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