pm_qos.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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_DEV_LAT_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_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. enum pm_qos_type type;
  69. struct blocking_notifier_head *notifiers;
  70. };
  71. struct pm_qos_flags {
  72. struct list_head list;
  73. s32 effective_flags; /* Do not change to 64 bit */
  74. };
  75. struct dev_pm_qos {
  76. struct pm_qos_constraints latency;
  77. struct pm_qos_flags flags;
  78. struct dev_pm_qos_request *latency_req;
  79. struct dev_pm_qos_request *flags_req;
  80. };
  81. /* Action requested to pm_qos_update_target */
  82. enum pm_qos_req_action {
  83. PM_QOS_ADD_REQ, /* Add a new request */
  84. PM_QOS_UPDATE_REQ, /* Update an existing request */
  85. PM_QOS_REMOVE_REQ /* Remove an existing request */
  86. };
  87. static inline int dev_pm_qos_request_active(struct dev_pm_qos_request *req)
  88. {
  89. return req->dev != NULL;
  90. }
  91. int pm_qos_update_target(struct pm_qos_constraints *c, struct plist_node *node,
  92. enum pm_qos_req_action action, int value);
  93. bool pm_qos_update_flags(struct pm_qos_flags *pqf,
  94. struct pm_qos_flags_request *req,
  95. enum pm_qos_req_action action, s32 val);
  96. void pm_qos_add_request(struct pm_qos_request *req, int pm_qos_class,
  97. s32 value);
  98. void pm_qos_update_request(struct pm_qos_request *req,
  99. s32 new_value);
  100. void pm_qos_update_request_timeout(struct pm_qos_request *req,
  101. s32 new_value, unsigned long timeout_us);
  102. void pm_qos_remove_request(struct pm_qos_request *req);
  103. int pm_qos_request(int pm_qos_class);
  104. int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier);
  105. int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier);
  106. int pm_qos_request_active(struct pm_qos_request *req);
  107. s32 pm_qos_read_value(struct pm_qos_constraints *c);
  108. #ifdef CONFIG_PM
  109. enum pm_qos_flags_status __dev_pm_qos_flags(struct device *dev, s32 mask);
  110. enum pm_qos_flags_status dev_pm_qos_flags(struct device *dev, s32 mask);
  111. s32 __dev_pm_qos_read_value(struct device *dev);
  112. s32 dev_pm_qos_read_value(struct device *dev);
  113. int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
  114. enum dev_pm_qos_req_type type, s32 value);
  115. int dev_pm_qos_update_request(struct dev_pm_qos_request *req, s32 new_value);
  116. int dev_pm_qos_remove_request(struct dev_pm_qos_request *req);
  117. int dev_pm_qos_add_notifier(struct device *dev,
  118. struct notifier_block *notifier);
  119. int dev_pm_qos_remove_notifier(struct device *dev,
  120. struct notifier_block *notifier);
  121. int dev_pm_qos_add_global_notifier(struct notifier_block *notifier);
  122. int dev_pm_qos_remove_global_notifier(struct notifier_block *notifier);
  123. void dev_pm_qos_constraints_init(struct device *dev);
  124. void dev_pm_qos_constraints_destroy(struct device *dev);
  125. int dev_pm_qos_add_ancestor_request(struct device *dev,
  126. struct dev_pm_qos_request *req, s32 value);
  127. #else
  128. static inline enum pm_qos_flags_status __dev_pm_qos_flags(struct device *dev,
  129. s32 mask)
  130. { return PM_QOS_FLAGS_UNDEFINED; }
  131. static inline enum pm_qos_flags_status dev_pm_qos_flags(struct device *dev,
  132. s32 mask)
  133. { return PM_QOS_FLAGS_UNDEFINED; }
  134. static inline s32 __dev_pm_qos_read_value(struct device *dev)
  135. { return 0; }
  136. static inline s32 dev_pm_qos_read_value(struct device *dev)
  137. { return 0; }
  138. static inline int dev_pm_qos_add_request(struct device *dev,
  139. struct dev_pm_qos_request *req,
  140. enum dev_pm_qos_req_type type,
  141. s32 value)
  142. { return 0; }
  143. static inline int dev_pm_qos_update_request(struct dev_pm_qos_request *req,
  144. s32 new_value)
  145. { return 0; }
  146. static inline int dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
  147. { return 0; }
  148. static inline int dev_pm_qos_add_notifier(struct device *dev,
  149. struct notifier_block *notifier)
  150. { return 0; }
  151. static inline int dev_pm_qos_remove_notifier(struct device *dev,
  152. struct notifier_block *notifier)
  153. { return 0; }
  154. static inline int dev_pm_qos_add_global_notifier(
  155. struct notifier_block *notifier)
  156. { return 0; }
  157. static inline int dev_pm_qos_remove_global_notifier(
  158. struct notifier_block *notifier)
  159. { return 0; }
  160. static inline void dev_pm_qos_constraints_init(struct device *dev)
  161. {
  162. dev->power.power_state = PMSG_ON;
  163. }
  164. static inline void dev_pm_qos_constraints_destroy(struct device *dev)
  165. {
  166. dev->power.power_state = PMSG_INVALID;
  167. }
  168. static inline int dev_pm_qos_add_ancestor_request(struct device *dev,
  169. struct dev_pm_qos_request *req, s32 value)
  170. { return 0; }
  171. #endif
  172. #ifdef CONFIG_PM_RUNTIME
  173. int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value);
  174. void dev_pm_qos_hide_latency_limit(struct device *dev);
  175. int dev_pm_qos_expose_flags(struct device *dev, s32 value);
  176. void dev_pm_qos_hide_flags(struct device *dev);
  177. int dev_pm_qos_update_flags(struct device *dev, s32 mask, bool set);
  178. static inline s32 dev_pm_qos_requested_latency(struct device *dev)
  179. {
  180. return dev->power.qos->latency_req->data.pnode.prio;
  181. }
  182. static inline s32 dev_pm_qos_requested_flags(struct device *dev)
  183. {
  184. return dev->power.qos->flags_req->data.flr.flags;
  185. }
  186. #else
  187. static inline int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value)
  188. { return 0; }
  189. static inline void dev_pm_qos_hide_latency_limit(struct device *dev) {}
  190. static inline int dev_pm_qos_expose_flags(struct device *dev, s32 value)
  191. { return 0; }
  192. static inline void dev_pm_qos_hide_flags(struct device *dev) {}
  193. static inline int dev_pm_qos_update_flags(struct device *dev, s32 m, bool set)
  194. { return 0; }
  195. static inline s32 dev_pm_qos_requested_latency(struct device *dev) { return 0; }
  196. static inline s32 dev_pm_qos_requested_flags(struct device *dev) { return 0; }
  197. #endif
  198. #endif