cpuidle.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. 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. };
  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 int cpuidle_register_driver(struct cpuidle_driver *drv);
  98. extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
  99. extern int cpuidle_register_device(struct cpuidle_device *dev);
  100. extern void cpuidle_unregister_device(struct cpuidle_device *dev);
  101. extern void cpuidle_pause_and_lock(void);
  102. extern void cpuidle_resume_and_unlock(void);
  103. extern int cpuidle_enable_device(struct cpuidle_device *dev);
  104. extern void cpuidle_disable_device(struct cpuidle_device *dev);
  105. #else
  106. static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
  107. {return 0;}
  108. static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
  109. static inline int cpuidle_register_device(struct cpuidle_device *dev)
  110. {return 0;}
  111. static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
  112. static inline void cpuidle_pause_and_lock(void) { }
  113. static inline void cpuidle_resume_and_unlock(void) { }
  114. static inline int cpuidle_enable_device(struct cpuidle_device *dev)
  115. {return 0;}
  116. static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
  117. #endif
  118. /******************************
  119. * CPUIDLE GOVERNOR INTERFACE *
  120. ******************************/
  121. struct cpuidle_governor {
  122. char name[CPUIDLE_NAME_LEN];
  123. struct list_head governor_list;
  124. unsigned int rating;
  125. int (*enable) (struct cpuidle_device *dev);
  126. void (*disable) (struct cpuidle_device *dev);
  127. int (*select) (struct cpuidle_device *dev);
  128. void (*reflect) (struct cpuidle_device *dev);
  129. struct module *owner;
  130. };
  131. #ifdef CONFIG_CPU_IDLE
  132. extern int cpuidle_register_governor(struct cpuidle_governor *gov);
  133. extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
  134. #else
  135. static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
  136. {return 0;}
  137. static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { }
  138. #endif
  139. #endif /* _LINUX_CPUIDLE_H */