pm_qos.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. s32 dev_pm_qos_read_value(struct device *dev);
  71. int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
  72. s32 value);
  73. int dev_pm_qos_update_request(struct dev_pm_qos_request *req, s32 new_value);
  74. int dev_pm_qos_remove_request(struct dev_pm_qos_request *req);
  75. int dev_pm_qos_add_notifier(struct device *dev,
  76. struct notifier_block *notifier);
  77. int dev_pm_qos_remove_notifier(struct device *dev,
  78. struct notifier_block *notifier);
  79. int dev_pm_qos_add_global_notifier(struct notifier_block *notifier);
  80. int dev_pm_qos_remove_global_notifier(struct notifier_block *notifier);
  81. void dev_pm_qos_constraints_init(struct device *dev);
  82. void dev_pm_qos_constraints_destroy(struct device *dev);
  83. #else
  84. static inline int pm_qos_update_target(struct pm_qos_constraints *c,
  85. struct plist_node *node,
  86. enum pm_qos_req_action action,
  87. int value)
  88. { return 0; }
  89. static inline void pm_qos_add_request(struct pm_qos_request *req,
  90. int pm_qos_class, s32 value)
  91. { return; }
  92. static inline void pm_qos_update_request(struct pm_qos_request *req,
  93. s32 new_value)
  94. { return; }
  95. static inline void pm_qos_remove_request(struct pm_qos_request *req)
  96. { return; }
  97. static inline int pm_qos_request(int pm_qos_class)
  98. { return 0; }
  99. static inline int pm_qos_add_notifier(int pm_qos_class,
  100. struct notifier_block *notifier)
  101. { return 0; }
  102. static inline int pm_qos_remove_notifier(int pm_qos_class,
  103. struct notifier_block *notifier)
  104. { return 0; }
  105. static inline int pm_qos_request_active(struct pm_qos_request *req)
  106. { return 0; }
  107. static inline s32 pm_qos_read_value(struct pm_qos_constraints *c)
  108. { return 0; }
  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. #endif
  143. #endif