pm_qos.h 5.0 KB

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