pm_qos.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. #define PM_QOS_DEFAULT_VALUE -1
  21. #define PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE (2000 * USEC_PER_SEC)
  22. #define PM_QOS_NETWORK_LAT_DEFAULT_VALUE (2000 * USEC_PER_SEC)
  23. #define PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE 0
  24. #define PM_QOS_DEV_LAT_DEFAULT_VALUE 0
  25. struct pm_qos_request {
  26. struct plist_node node;
  27. int pm_qos_class;
  28. struct delayed_work work; /* for pm_qos_update_request_timeout */
  29. };
  30. struct pm_qos_flags_request {
  31. struct list_head node;
  32. s32 flags; /* Do not change to 64 bit */
  33. };
  34. struct dev_pm_qos_request {
  35. struct plist_node node;
  36. struct device *dev;
  37. };
  38. enum pm_qos_type {
  39. PM_QOS_UNITIALIZED,
  40. PM_QOS_MAX, /* return the largest value */
  41. PM_QOS_MIN /* return the smallest value */
  42. };
  43. /*
  44. * Note: The lockless read path depends on the CPU accessing target_value
  45. * or effective_flags atomically. Atomic access is only guaranteed on all CPU
  46. * types linux supports for 32 bit quantites
  47. */
  48. struct pm_qos_constraints {
  49. struct plist_head list;
  50. s32 target_value; /* Do not change to 64 bit */
  51. s32 default_value;
  52. enum pm_qos_type type;
  53. struct blocking_notifier_head *notifiers;
  54. };
  55. struct pm_qos_flags {
  56. struct list_head list;
  57. s32 effective_flags; /* Do not change to 64 bit */
  58. };
  59. struct dev_pm_qos {
  60. struct pm_qos_constraints latency;
  61. };
  62. /* Action requested to pm_qos_update_target */
  63. enum pm_qos_req_action {
  64. PM_QOS_ADD_REQ, /* Add a new request */
  65. PM_QOS_UPDATE_REQ, /* Update an existing request */
  66. PM_QOS_REMOVE_REQ /* Remove an existing request */
  67. };
  68. static inline int dev_pm_qos_request_active(struct dev_pm_qos_request *req)
  69. {
  70. return req->dev != NULL;
  71. }
  72. int pm_qos_update_target(struct pm_qos_constraints *c, struct plist_node *node,
  73. enum pm_qos_req_action action, int value);
  74. bool pm_qos_update_flags(struct pm_qos_flags *pqf,
  75. struct pm_qos_flags_request *req,
  76. enum pm_qos_req_action action, s32 val);
  77. void pm_qos_add_request(struct pm_qos_request *req, int pm_qos_class,
  78. s32 value);
  79. void pm_qos_update_request(struct pm_qos_request *req,
  80. s32 new_value);
  81. void pm_qos_update_request_timeout(struct pm_qos_request *req,
  82. s32 new_value, unsigned long timeout_us);
  83. void pm_qos_remove_request(struct pm_qos_request *req);
  84. int pm_qos_request(int pm_qos_class);
  85. int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier);
  86. int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier);
  87. int pm_qos_request_active(struct pm_qos_request *req);
  88. s32 pm_qos_read_value(struct pm_qos_constraints *c);
  89. #ifdef CONFIG_PM
  90. s32 __dev_pm_qos_read_value(struct device *dev);
  91. s32 dev_pm_qos_read_value(struct device *dev);
  92. int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
  93. s32 value);
  94. int dev_pm_qos_update_request(struct dev_pm_qos_request *req, s32 new_value);
  95. int dev_pm_qos_remove_request(struct dev_pm_qos_request *req);
  96. int dev_pm_qos_add_notifier(struct device *dev,
  97. struct notifier_block *notifier);
  98. int dev_pm_qos_remove_notifier(struct device *dev,
  99. struct notifier_block *notifier);
  100. int dev_pm_qos_add_global_notifier(struct notifier_block *notifier);
  101. int dev_pm_qos_remove_global_notifier(struct notifier_block *notifier);
  102. void dev_pm_qos_constraints_init(struct device *dev);
  103. void dev_pm_qos_constraints_destroy(struct device *dev);
  104. int dev_pm_qos_add_ancestor_request(struct device *dev,
  105. struct dev_pm_qos_request *req, s32 value);
  106. #else
  107. static inline s32 __dev_pm_qos_read_value(struct device *dev)
  108. { return 0; }
  109. static inline s32 dev_pm_qos_read_value(struct device *dev)
  110. { return 0; }
  111. static inline int dev_pm_qos_add_request(struct device *dev,
  112. struct dev_pm_qos_request *req,
  113. s32 value)
  114. { return 0; }
  115. static inline int dev_pm_qos_update_request(struct dev_pm_qos_request *req,
  116. s32 new_value)
  117. { return 0; }
  118. static inline int dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
  119. { return 0; }
  120. static inline int dev_pm_qos_add_notifier(struct device *dev,
  121. struct notifier_block *notifier)
  122. { return 0; }
  123. static inline int dev_pm_qos_remove_notifier(struct device *dev,
  124. struct notifier_block *notifier)
  125. { return 0; }
  126. static inline int dev_pm_qos_add_global_notifier(
  127. struct notifier_block *notifier)
  128. { return 0; }
  129. static inline int dev_pm_qos_remove_global_notifier(
  130. struct notifier_block *notifier)
  131. { return 0; }
  132. static inline void dev_pm_qos_constraints_init(struct device *dev)
  133. {
  134. dev->power.power_state = PMSG_ON;
  135. }
  136. static inline void dev_pm_qos_constraints_destroy(struct device *dev)
  137. {
  138. dev->power.power_state = PMSG_INVALID;
  139. }
  140. static inline int dev_pm_qos_add_ancestor_request(struct device *dev,
  141. struct dev_pm_qos_request *req, s32 value)
  142. { return 0; }
  143. #endif
  144. #ifdef CONFIG_PM_RUNTIME
  145. int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value);
  146. void dev_pm_qos_hide_latency_limit(struct device *dev);
  147. #else
  148. static inline int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value)
  149. { return 0; }
  150. static inline void dev_pm_qos_hide_latency_limit(struct device *dev) {}
  151. #endif
  152. #endif