pm_qos.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. #else
  83. static inline int pm_qos_update_target(struct pm_qos_constraints *c,
  84. struct plist_node *node,
  85. enum pm_qos_req_action action,
  86. int value)
  87. { return 0; }
  88. static inline void pm_qos_add_request(struct pm_qos_request *req,
  89. int pm_qos_class, s32 value)
  90. { return; }
  91. static inline void pm_qos_update_request(struct pm_qos_request *req,
  92. s32 new_value)
  93. { return; }
  94. static inline void pm_qos_remove_request(struct pm_qos_request *req)
  95. { return; }
  96. static inline int pm_qos_request(int pm_qos_class)
  97. { return 0; }
  98. static inline int pm_qos_add_notifier(int pm_qos_class,
  99. struct notifier_block *notifier)
  100. { return 0; }
  101. static inline int pm_qos_remove_notifier(int pm_qos_class,
  102. struct notifier_block *notifier)
  103. { return 0; }
  104. static inline int pm_qos_request_active(struct pm_qos_request *req)
  105. { return 0; }
  106. static inline s32 pm_qos_read_value(struct pm_qos_constraints *c)
  107. { return 0; }
  108. static inline s32 dev_pm_qos_read_value(struct device *dev)
  109. { return 0; }
  110. static inline int dev_pm_qos_add_request(struct device *dev,
  111. struct dev_pm_qos_request *req,
  112. s32 value)
  113. { return 0; }
  114. static inline int dev_pm_qos_update_request(struct dev_pm_qos_request *req,
  115. s32 new_value)
  116. { return 0; }
  117. static inline int dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
  118. { return 0; }
  119. static inline int dev_pm_qos_add_notifier(struct device *dev,
  120. struct notifier_block *notifier)
  121. { return 0; }
  122. static inline int dev_pm_qos_remove_notifier(struct device *dev,
  123. struct notifier_block *notifier)
  124. { return 0; }
  125. static inline int dev_pm_qos_add_global_notifier(
  126. struct notifier_block *notifier)
  127. { return 0; }
  128. static inline int dev_pm_qos_remove_global_notifier(
  129. struct notifier_block *notifier)
  130. { return 0; }
  131. static inline void dev_pm_qos_constraints_init(struct device *dev)
  132. {
  133. dev->power.power_state = PMSG_ON;
  134. }
  135. static inline void dev_pm_qos_constraints_destroy(struct device *dev)
  136. {
  137. dev->power.power_state = PMSG_INVALID;
  138. }
  139. #endif
  140. #endif