pm_qos.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. /* Action requested to pm_qos_update_target */
  52. enum pm_qos_req_action {
  53. PM_QOS_ADD_REQ, /* Add a new request */
  54. PM_QOS_UPDATE_REQ, /* Update an existing request */
  55. PM_QOS_REMOVE_REQ /* Remove an existing request */
  56. };
  57. static inline int dev_pm_qos_request_active(struct dev_pm_qos_request *req)
  58. {
  59. return req->dev != 0;
  60. }
  61. int pm_qos_update_target(struct pm_qos_constraints *c, struct plist_node *node,
  62. enum pm_qos_req_action action, int value);
  63. void pm_qos_add_request(struct pm_qos_request *req, int pm_qos_class,
  64. s32 value);
  65. void pm_qos_update_request(struct pm_qos_request *req,
  66. s32 new_value);
  67. void pm_qos_update_request_timeout(struct pm_qos_request *req,
  68. s32 new_value, unsigned long timeout_us);
  69. void pm_qos_remove_request(struct pm_qos_request *req);
  70. int pm_qos_request(int pm_qos_class);
  71. int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier);
  72. int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier);
  73. int pm_qos_request_active(struct pm_qos_request *req);
  74. s32 pm_qos_read_value(struct pm_qos_constraints *c);
  75. #ifdef CONFIG_PM
  76. s32 __dev_pm_qos_read_value(struct device *dev);
  77. s32 dev_pm_qos_read_value(struct device *dev);
  78. int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
  79. s32 value);
  80. int dev_pm_qos_update_request(struct dev_pm_qos_request *req, s32 new_value);
  81. int dev_pm_qos_remove_request(struct dev_pm_qos_request *req);
  82. int dev_pm_qos_add_notifier(struct device *dev,
  83. struct notifier_block *notifier);
  84. int dev_pm_qos_remove_notifier(struct device *dev,
  85. struct notifier_block *notifier);
  86. int dev_pm_qos_add_global_notifier(struct notifier_block *notifier);
  87. int dev_pm_qos_remove_global_notifier(struct notifier_block *notifier);
  88. void dev_pm_qos_constraints_init(struct device *dev);
  89. void dev_pm_qos_constraints_destroy(struct device *dev);
  90. int dev_pm_qos_add_ancestor_request(struct device *dev,
  91. struct dev_pm_qos_request *req, s32 value);
  92. #else
  93. static inline s32 __dev_pm_qos_read_value(struct device *dev)
  94. { return 0; }
  95. static inline s32 dev_pm_qos_read_value(struct device *dev)
  96. { return 0; }
  97. static inline int dev_pm_qos_add_request(struct device *dev,
  98. struct dev_pm_qos_request *req,
  99. s32 value)
  100. { return 0; }
  101. static inline int dev_pm_qos_update_request(struct dev_pm_qos_request *req,
  102. s32 new_value)
  103. { return 0; }
  104. static inline int dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
  105. { return 0; }
  106. static inline int dev_pm_qos_add_notifier(struct device *dev,
  107. struct notifier_block *notifier)
  108. { return 0; }
  109. static inline int dev_pm_qos_remove_notifier(struct device *dev,
  110. struct notifier_block *notifier)
  111. { return 0; }
  112. static inline int dev_pm_qos_add_global_notifier(
  113. struct notifier_block *notifier)
  114. { return 0; }
  115. static inline int dev_pm_qos_remove_global_notifier(
  116. struct notifier_block *notifier)
  117. { return 0; }
  118. static inline void dev_pm_qos_constraints_init(struct device *dev)
  119. {
  120. dev->power.power_state = PMSG_ON;
  121. }
  122. static inline void dev_pm_qos_constraints_destroy(struct device *dev)
  123. {
  124. dev->power.power_state = PMSG_INVALID;
  125. }
  126. static inline int dev_pm_qos_add_ancestor_request(struct device *dev,
  127. struct dev_pm_qos_request *req, s32 value)
  128. { return 0; }
  129. #endif
  130. #ifdef CONFIG_PM_RUNTIME
  131. int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value);
  132. void dev_pm_qos_hide_latency_limit(struct device *dev);
  133. #else
  134. static inline int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value)
  135. { return 0; }
  136. static inline void dev_pm_qos_hide_latency_limit(struct device *dev) {}
  137. #endif
  138. #endif