pm_qos.h 5.3 KB

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