pm_qos.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #ifndef _LINUX_PM_QOS_H
  2. #define _LINUX_PM_QOS_H
  3. /* interface for the pm_qos_power infrastructure of the linux kernel.
  4. *
  5. * Mark Gross <mgross@linux.intel.com>
  6. */
  7. #include <linux/plist.h>
  8. #include <linux/notifier.h>
  9. #include <linux/miscdevice.h>
  10. #include <linux/device.h>
  11. #include <linux/workqueue.h>
  12. enum {
  13. PM_QOS_RESERVED = 0,
  14. PM_QOS_CPU_DMA_LATENCY,
  15. PM_QOS_NETWORK_LATENCY,
  16. PM_QOS_NETWORK_THROUGHPUT,
  17. /* insert new class ID */
  18. PM_QOS_NUM_CLASSES,
  19. };
  20. enum pm_qos_flags_status {
  21. PM_QOS_FLAGS_UNDEFINED = -1,
  22. PM_QOS_FLAGS_NONE,
  23. PM_QOS_FLAGS_SOME,
  24. PM_QOS_FLAGS_ALL,
  25. };
  26. #define PM_QOS_DEFAULT_VALUE -1
  27. #define PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE (2000 * USEC_PER_SEC)
  28. #define PM_QOS_NETWORK_LAT_DEFAULT_VALUE (2000 * USEC_PER_SEC)
  29. #define PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE 0
  30. #define PM_QOS_RESUME_LATENCY_DEFAULT_VALUE 0
  31. #define PM_QOS_FLAG_NO_POWER_OFF (1 << 0)
  32. #define PM_QOS_FLAG_REMOTE_WAKEUP (1 << 1)
  33. struct pm_qos_request {
  34. struct plist_node node;
  35. int pm_qos_class;
  36. struct delayed_work work; /* for pm_qos_update_request_timeout */
  37. };
  38. struct pm_qos_flags_request {
  39. struct list_head node;
  40. s32 flags; /* Do not change to 64 bit */
  41. };
  42. enum dev_pm_qos_req_type {
  43. DEV_PM_QOS_RESUME_LATENCY = 1,
  44. DEV_PM_QOS_FLAGS,
  45. };
  46. struct dev_pm_qos_request {
  47. enum dev_pm_qos_req_type type;
  48. union {
  49. struct plist_node pnode;
  50. struct pm_qos_flags_request flr;
  51. } data;
  52. struct device *dev;
  53. };
  54. enum pm_qos_type {
  55. PM_QOS_UNITIALIZED,
  56. PM_QOS_MAX, /* return the largest value */
  57. PM_QOS_MIN /* return the smallest value */
  58. };
  59. /*
  60. * Note: The lockless read path depends on the CPU accessing target_value
  61. * or effective_flags atomically. Atomic access is only guaranteed on all CPU
  62. * types linux supports for 32 bit quantites
  63. */
  64. struct pm_qos_constraints {
  65. struct plist_head list;
  66. s32 target_value; /* Do not change to 64 bit */
  67. s32 default_value;
  68. s32 no_constraint_value;
  69. enum pm_qos_type type;
  70. struct blocking_notifier_head *notifiers;
  71. };
  72. struct pm_qos_flags {
  73. struct list_head list;
  74. s32 effective_flags; /* Do not change to 64 bit */
  75. };
  76. struct dev_pm_qos {
  77. struct pm_qos_constraints resume_latency;
  78. struct pm_qos_flags flags;
  79. struct dev_pm_qos_request *resume_latency_req;
  80. struct dev_pm_qos_request *flags_req;
  81. };
  82. /* Action requested to pm_qos_update_target */
  83. enum pm_qos_req_action {
  84. PM_QOS_ADD_REQ, /* Add a new request */
  85. PM_QOS_UPDATE_REQ, /* Update an existing request */
  86. PM_QOS_REMOVE_REQ /* Remove an existing request */
  87. };
  88. static inline int dev_pm_qos_request_active(struct dev_pm_qos_request *req)
  89. {
  90. return req->dev != NULL;
  91. }
  92. int pm_qos_update_target(struct pm_qos_constraints *c, struct plist_node *node,
  93. enum pm_qos_req_action action, int value);
  94. bool pm_qos_update_flags(struct pm_qos_flags *pqf,
  95. struct pm_qos_flags_request *req,
  96. enum pm_qos_req_action action, s32 val);
  97. void pm_qos_add_request(struct pm_qos_request *req, int pm_qos_class,
  98. s32 value);
  99. void pm_qos_update_request(struct pm_qos_request *req,
  100. s32 new_value);
  101. void pm_qos_update_request_timeout(struct pm_qos_request *req,
  102. s32 new_value, unsigned long timeout_us);
  103. void pm_qos_remove_request(struct pm_qos_request *req);
  104. int pm_qos_request(int pm_qos_class);
  105. int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier);
  106. int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier);
  107. int pm_qos_request_active(struct pm_qos_request *req);
  108. s32 pm_qos_read_value(struct pm_qos_constraints *c);
  109. #ifdef CONFIG_PM
  110. enum pm_qos_flags_status __dev_pm_qos_flags(struct device *dev, s32 mask);
  111. enum pm_qos_flags_status dev_pm_qos_flags(struct device *dev, s32 mask);
  112. s32 __dev_pm_qos_read_value(struct device *dev);
  113. s32 dev_pm_qos_read_value(struct device *dev);
  114. int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
  115. enum dev_pm_qos_req_type type, s32 value);
  116. int dev_pm_qos_update_request(struct dev_pm_qos_request *req, s32 new_value);
  117. int dev_pm_qos_remove_request(struct dev_pm_qos_request *req);
  118. int dev_pm_qos_add_notifier(struct device *dev,
  119. struct notifier_block *notifier);
  120. int dev_pm_qos_remove_notifier(struct device *dev,
  121. struct notifier_block *notifier);
  122. int dev_pm_qos_add_global_notifier(struct notifier_block *notifier);
  123. int dev_pm_qos_remove_global_notifier(struct notifier_block *notifier);
  124. void dev_pm_qos_constraints_init(struct device *dev);
  125. void dev_pm_qos_constraints_destroy(struct device *dev);
  126. int dev_pm_qos_add_ancestor_request(struct device *dev,
  127. struct dev_pm_qos_request *req, s32 value);
  128. #else
  129. static inline enum pm_qos_flags_status __dev_pm_qos_flags(struct device *dev,
  130. s32 mask)
  131. { return PM_QOS_FLAGS_UNDEFINED; }
  132. static inline enum pm_qos_flags_status dev_pm_qos_flags(struct device *dev,
  133. s32 mask)
  134. { return PM_QOS_FLAGS_UNDEFINED; }
  135. static inline s32 __dev_pm_qos_read_value(struct device *dev)
  136. { return 0; }
  137. static inline s32 dev_pm_qos_read_value(struct device *dev)
  138. { return 0; }
  139. static inline int dev_pm_qos_add_request(struct device *dev,
  140. struct dev_pm_qos_request *req,
  141. enum dev_pm_qos_req_type type,
  142. s32 value)
  143. { return 0; }
  144. static inline int dev_pm_qos_update_request(struct dev_pm_qos_request *req,
  145. s32 new_value)
  146. { return 0; }
  147. static inline int dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
  148. { return 0; }
  149. static inline int dev_pm_qos_add_notifier(struct device *dev,
  150. struct notifier_block *notifier)
  151. { return 0; }
  152. static inline int dev_pm_qos_remove_notifier(struct device *dev,
  153. struct notifier_block *notifier)
  154. { return 0; }
  155. static inline int dev_pm_qos_add_global_notifier(
  156. struct notifier_block *notifier)
  157. { return 0; }
  158. static inline int dev_pm_qos_remove_global_notifier(
  159. struct notifier_block *notifier)
  160. { return 0; }
  161. static inline void dev_pm_qos_constraints_init(struct device *dev)
  162. {
  163. dev->power.power_state = PMSG_ON;
  164. }
  165. static inline void dev_pm_qos_constraints_destroy(struct device *dev)
  166. {
  167. dev->power.power_state = PMSG_INVALID;
  168. }
  169. static inline int dev_pm_qos_add_ancestor_request(struct device *dev,
  170. struct dev_pm_qos_request *req, s32 value)
  171. { return 0; }
  172. #endif
  173. #ifdef CONFIG_PM_RUNTIME
  174. int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value);
  175. void dev_pm_qos_hide_latency_limit(struct device *dev);
  176. int dev_pm_qos_expose_flags(struct device *dev, s32 value);
  177. void dev_pm_qos_hide_flags(struct device *dev);
  178. int dev_pm_qos_update_flags(struct device *dev, s32 mask, bool set);
  179. static inline s32 dev_pm_qos_requested_resume_latency(struct device *dev)
  180. {
  181. return dev->power.qos->resume_latency_req->data.pnode.prio;
  182. }
  183. static inline s32 dev_pm_qos_requested_flags(struct device *dev)
  184. {
  185. return dev->power.qos->flags_req->data.flr.flags;
  186. }
  187. #else
  188. static inline int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value)
  189. { return 0; }
  190. static inline void dev_pm_qos_hide_latency_limit(struct device *dev) {}
  191. static inline int dev_pm_qos_expose_flags(struct device *dev, s32 value)
  192. { return 0; }
  193. static inline void dev_pm_qos_hide_flags(struct device *dev) {}
  194. static inline int dev_pm_qos_update_flags(struct device *dev, s32 m, bool set)
  195. { return 0; }
  196. static inline s32 dev_pm_qos_requested_resume_latency(struct device *dev) { return 0; }
  197. static inline s32 dev_pm_qos_requested_flags(struct device *dev) { return 0; }
  198. #endif
  199. #endif