pm_qos.h 5.4 KB

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