cpuidle.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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_SHALLOW (0x10) /* low latency, minimal savings */
  39. #define CPUIDLE_FLAG_BALANCED (0x20) /* medium latency, moderate savings */
  40. #define CPUIDLE_FLAG_DEEP (0x40) /* high latency, large savings */
  41. #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
  42. /**
  43. * cpuidle_get_statedata - retrieves private driver state data
  44. * @state: the state
  45. */
  46. static inline void * cpuidle_get_statedata(struct cpuidle_state *state)
  47. {
  48. return state->driver_data;
  49. }
  50. /**
  51. * cpuidle_set_statedata - stores private driver state data
  52. * @state: the state
  53. * @data: the private data
  54. */
  55. static inline void
  56. cpuidle_set_statedata(struct cpuidle_state *state, void *data)
  57. {
  58. state->driver_data = data;
  59. }
  60. struct cpuidle_state_kobj {
  61. struct cpuidle_state *state;
  62. struct completion kobj_unregister;
  63. struct kobject kobj;
  64. };
  65. struct cpuidle_device {
  66. unsigned int enabled: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 cpuidle_state *last_state;
  73. struct list_head device_list;
  74. struct kobject kobj;
  75. struct completion kobj_unregister;
  76. void *governor_data;
  77. struct cpuidle_state *safe_state;
  78. };
  79. DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
  80. /**
  81. * cpuidle_get_last_residency - retrieves the last state's residency time
  82. * @dev: the target CPU
  83. *
  84. * NOTE: this value is invalid if CPUIDLE_FLAG_TIME_VALID isn't set
  85. */
  86. static inline int cpuidle_get_last_residency(struct cpuidle_device *dev)
  87. {
  88. return dev->last_residency;
  89. }
  90. /****************************
  91. * CPUIDLE DRIVER INTERFACE *
  92. ****************************/
  93. struct cpuidle_driver {
  94. char name[CPUIDLE_NAME_LEN];
  95. struct module *owner;
  96. };
  97. #ifdef CONFIG_CPU_IDLE
  98. extern int cpuidle_register_driver(struct cpuidle_driver *drv);
  99. extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
  100. extern int cpuidle_register_device(struct cpuidle_device *dev);
  101. extern void cpuidle_unregister_device(struct cpuidle_device *dev);
  102. extern void cpuidle_pause_and_lock(void);
  103. extern void cpuidle_resume_and_unlock(void);
  104. extern int cpuidle_enable_device(struct cpuidle_device *dev);
  105. extern void cpuidle_disable_device(struct cpuidle_device *dev);
  106. #else
  107. static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
  108. {return 0;}
  109. static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
  110. static inline int cpuidle_register_device(struct cpuidle_device *dev)
  111. {return 0;}
  112. static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
  113. static inline void cpuidle_pause_and_lock(void) { }
  114. static inline void cpuidle_resume_and_unlock(void) { }
  115. static inline int cpuidle_enable_device(struct cpuidle_device *dev)
  116. {return 0;}
  117. static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
  118. #endif
  119. /******************************
  120. * CPUIDLE GOVERNOR INTERFACE *
  121. ******************************/
  122. struct cpuidle_governor {
  123. char name[CPUIDLE_NAME_LEN];
  124. struct list_head governor_list;
  125. unsigned int rating;
  126. int (*enable) (struct cpuidle_device *dev);
  127. void (*disable) (struct cpuidle_device *dev);
  128. int (*select) (struct cpuidle_device *dev);
  129. void (*reflect) (struct cpuidle_device *dev);
  130. struct module *owner;
  131. };
  132. #ifdef CONFIG_CPU_IDLE
  133. extern int cpuidle_register_governor(struct cpuidle_governor *gov);
  134. extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
  135. #else
  136. static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
  137. {return 0;}
  138. static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { }
  139. #endif
  140. #endif /* _LINUX_CPUIDLE_H */