pm_qos.h 5.4 KB

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