pm_qos.h 4.8 KB

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