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