~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/pm_qos.h

Version: ~ [ linux-5.12-rc7 ] ~ [ linux-5.11.13 ] ~ [ linux-5.10.29 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.111 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.186 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.230 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.266 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.266 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _LINUX_PM_QOS_H
  3 #define _LINUX_PM_QOS_H
  4 /* interface for the pm_qos_power infrastructure of the linux kernel.
  5  *
  6  * Mark Gross <mgross@linux.intel.com>
  7  */
  8 #include <linux/plist.h>
  9 #include <linux/notifier.h>
 10 #include <linux/device.h>
 11 #include <linux/workqueue.h>
 12 
 13 enum {
 14         PM_QOS_RESERVED = 0,
 15         PM_QOS_CPU_DMA_LATENCY,
 16         PM_QOS_NETWORK_LATENCY,
 17         PM_QOS_NETWORK_THROUGHPUT,
 18         PM_QOS_MEMORY_BANDWIDTH,
 19 
 20         /* insert new class ID */
 21         PM_QOS_NUM_CLASSES,
 22 };
 23 
 24 enum pm_qos_flags_status {
 25         PM_QOS_FLAGS_UNDEFINED = -1,
 26         PM_QOS_FLAGS_NONE,
 27         PM_QOS_FLAGS_SOME,
 28         PM_QOS_FLAGS_ALL,
 29 };
 30 
 31 #define PM_QOS_DEFAULT_VALUE    (-1)
 32 #define PM_QOS_LATENCY_ANY      S32_MAX
 33 #define PM_QOS_LATENCY_ANY_NS   ((s64)PM_QOS_LATENCY_ANY * NSEC_PER_USEC)
 34 
 35 #define PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE        (2000 * USEC_PER_SEC)
 36 #define PM_QOS_NETWORK_LAT_DEFAULT_VALUE        (2000 * USEC_PER_SEC)
 37 #define PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE 0
 38 #define PM_QOS_MEMORY_BANDWIDTH_DEFAULT_VALUE   0
 39 #define PM_QOS_RESUME_LATENCY_DEFAULT_VALUE     PM_QOS_LATENCY_ANY
 40 #define PM_QOS_RESUME_LATENCY_NO_CONSTRAINT     PM_QOS_LATENCY_ANY
 41 #define PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS  PM_QOS_LATENCY_ANY_NS
 42 #define PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE  0
 43 #define PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE      0
 44 #define PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE      (-1)
 45 #define PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT  (-1)
 46 
 47 #define PM_QOS_FLAG_NO_POWER_OFF        (1 << 0)
 48 
 49 struct pm_qos_request {
 50         struct plist_node node;
 51         int pm_qos_class;
 52         struct delayed_work work; /* for pm_qos_update_request_timeout */
 53 };
 54 
 55 struct pm_qos_flags_request {
 56         struct list_head node;
 57         s32 flags;      /* Do not change to 64 bit */
 58 };
 59 
 60 enum dev_pm_qos_req_type {
 61         DEV_PM_QOS_RESUME_LATENCY = 1,
 62         DEV_PM_QOS_LATENCY_TOLERANCE,
 63         DEV_PM_QOS_MIN_FREQUENCY,
 64         DEV_PM_QOS_MAX_FREQUENCY,
 65         DEV_PM_QOS_FLAGS,
 66 };
 67 
 68 struct dev_pm_qos_request {
 69         enum dev_pm_qos_req_type type;
 70         union {
 71                 struct plist_node pnode;
 72                 struct pm_qos_flags_request flr;
 73         } data;
 74         struct device *dev;
 75 };
 76 
 77 enum pm_qos_type {
 78         PM_QOS_UNITIALIZED,
 79         PM_QOS_MAX,             /* return the largest value */
 80         PM_QOS_MIN,             /* return the smallest value */
 81         PM_QOS_SUM              /* return the sum */
 82 };
 83 
 84 /*
 85  * Note: The lockless read path depends on the CPU accessing target_value
 86  * or effective_flags atomically.  Atomic access is only guaranteed on all CPU
 87  * types linux supports for 32 bit quantites
 88  */
 89 struct pm_qos_constraints {
 90         struct plist_head list;
 91         s32 target_value;       /* Do not change to 64 bit */
 92         s32 default_value;
 93         s32 no_constraint_value;
 94         enum pm_qos_type type;
 95         struct blocking_notifier_head *notifiers;
 96 };
 97 
 98 struct pm_qos_flags {
 99         struct list_head list;
100         s32 effective_flags;    /* Do not change to 64 bit */
101 };
102 
103 struct dev_pm_qos {
104         struct pm_qos_constraints resume_latency;
105         struct pm_qos_constraints latency_tolerance;
106         struct pm_qos_constraints min_frequency;
107         struct pm_qos_constraints max_frequency;
108         struct pm_qos_flags flags;
109         struct dev_pm_qos_request *resume_latency_req;
110         struct dev_pm_qos_request *latency_tolerance_req;
111         struct dev_pm_qos_request *flags_req;
112         struct dev_pm_qos_request *min_frequency_req;
113         struct dev_pm_qos_request *max_frequency_req;
114 };
115 
116 /* Action requested to pm_qos_update_target */
117 enum pm_qos_req_action {
118         PM_QOS_ADD_REQ,         /* Add a new request */
119         PM_QOS_UPDATE_REQ,      /* Update an existing request */
120         PM_QOS_REMOVE_REQ       /* Remove an existing request */
121 };
122 
123 static inline int dev_pm_qos_request_active(struct dev_pm_qos_request *req)
124 {
125         return req->dev != NULL;
126 }
127 
128 int pm_qos_update_target(struct pm_qos_constraints *c, struct plist_node *node,
129                          enum pm_qos_req_action action, int value);
130 bool pm_qos_update_flags(struct pm_qos_flags *pqf,
131                          struct pm_qos_flags_request *req,
132                          enum pm_qos_req_action action, s32 val);
133 void pm_qos_add_request(struct pm_qos_request *req, int pm_qos_class,
134                         s32 value);
135 void pm_qos_update_request(struct pm_qos_request *req,
136                            s32 new_value);
137 void pm_qos_update_request_timeout(struct pm_qos_request *req,
138                                    s32 new_value, unsigned long timeout_us);
139 void pm_qos_remove_request(struct pm_qos_request *req);
140 
141 int pm_qos_request(int pm_qos_class);
142 int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier);
143 int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier);
144 int pm_qos_request_active(struct pm_qos_request *req);
145 s32 pm_qos_read_value(struct pm_qos_constraints *c);
146 
147 #ifdef CONFIG_PM
148 enum pm_qos_flags_status __dev_pm_qos_flags(struct device *dev, s32 mask);
149 enum pm_qos_flags_status dev_pm_qos_flags(struct device *dev, s32 mask);
150 s32 __dev_pm_qos_resume_latency(struct device *dev);
151 s32 dev_pm_qos_read_value(struct device *dev, enum dev_pm_qos_req_type type);
152 int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
153                            enum dev_pm_qos_req_type type, s32 value);
154 int dev_pm_qos_update_request(struct dev_pm_qos_request *req, s32 new_value);
155 int dev_pm_qos_remove_request(struct dev_pm_qos_request *req);
156 int dev_pm_qos_add_notifier(struct device *dev,
157                             struct notifier_block *notifier,
158                             enum dev_pm_qos_req_type type);
159 int dev_pm_qos_remove_notifier(struct device *dev,
160                                struct notifier_block *notifier,
161                                enum dev_pm_qos_req_type type);
162 void dev_pm_qos_constraints_init(struct device *dev);
163 void dev_pm_qos_constraints_destroy(struct device *dev);
164 int dev_pm_qos_add_ancestor_request(struct device *dev,
165                                     struct dev_pm_qos_request *req,
166                                     enum dev_pm_qos_req_type type, s32 value);
167 int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value);
168 void dev_pm_qos_hide_latency_limit(struct device *dev);
169 int dev_pm_qos_expose_flags(struct device *dev, s32 value);
170 void dev_pm_qos_hide_flags(struct device *dev);
171 int dev_pm_qos_update_flags(struct device *dev, s32 mask, bool set);
172 s32 dev_pm_qos_get_user_latency_tolerance(struct device *dev);
173 int dev_pm_qos_update_user_latency_tolerance(struct device *dev, s32 val);
174 int dev_pm_qos_expose_latency_tolerance(struct device *dev);
175 void dev_pm_qos_hide_latency_tolerance(struct device *dev);
176 
177 static inline s32 dev_pm_qos_requested_resume_latency(struct device *dev)
178 {
179         return dev->power.qos->resume_latency_req->data.pnode.prio;
180 }
181 
182 static inline s32 dev_pm_qos_requested_flags(struct device *dev)
183 {
184         return dev->power.qos->flags_req->data.flr.flags;
185 }
186 
187 static inline s32 dev_pm_qos_raw_resume_latency(struct device *dev)
188 {
189         return IS_ERR_OR_NULL(dev->power.qos) ?
190                 PM_QOS_RESUME_LATENCY_NO_CONSTRAINT :
191                 pm_qos_read_value(&dev->power.qos->resume_latency);
192 }
193 #else
194 static inline enum pm_qos_flags_status __dev_pm_qos_flags(struct device *dev,
195                                                           s32 mask)
196                         { return PM_QOS_FLAGS_UNDEFINED; }
197 static inline enum pm_qos_flags_status dev_pm_qos_flags(struct device *dev,
198                                                         s32 mask)
199                         { return PM_QOS_FLAGS_UNDEFINED; }
200 static inline s32 __dev_pm_qos_resume_latency(struct device *dev)
201                         { return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; }
202 static inline s32 dev_pm_qos_read_value(struct device *dev,
203                                         enum dev_pm_qos_req_type type)
204 {
205         switch (type) {
206         case DEV_PM_QOS_RESUME_LATENCY:
207                 return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
208         case DEV_PM_QOS_MIN_FREQUENCY:
209                 return PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE;
210         case DEV_PM_QOS_MAX_FREQUENCY:
211                 return PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE;
212         default:
213                 WARN_ON(1);
214                 return 0;
215         }
216 }
217 
218 static inline int dev_pm_qos_add_request(struct device *dev,
219                                          struct dev_pm_qos_request *req,
220                                          enum dev_pm_qos_req_type type,
221                                          s32 value)
222                         { return 0; }
223 static inline int dev_pm_qos_update_request(struct dev_pm_qos_request *req,
224                                             s32 new_value)
225                         { return 0; }
226 static inline int dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
227                         { return 0; }
228 static inline int dev_pm_qos_add_notifier(struct device *dev,
229                                           struct notifier_block *notifier,
230                                           enum dev_pm_qos_req_type type)
231                         { return 0; }
232 static inline int dev_pm_qos_remove_notifier(struct device *dev,
233                                              struct notifier_block *notifier,
234                                              enum dev_pm_qos_req_type type)
235                         { return 0; }
236 static inline void dev_pm_qos_constraints_init(struct device *dev)
237 {
238         dev->power.power_state = PMSG_ON;
239 }
240 static inline void dev_pm_qos_constraints_destroy(struct device *dev)
241 {
242         dev->power.power_state = PMSG_INVALID;
243 }
244 static inline int dev_pm_qos_add_ancestor_request(struct device *dev,
245                                                   struct dev_pm_qos_request *req,
246                                                   enum dev_pm_qos_req_type type,
247                                                   s32 value)
248                         { return 0; }
249 static inline int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value)
250                         { return 0; }
251 static inline void dev_pm_qos_hide_latency_limit(struct device *dev) {}
252 static inline int dev_pm_qos_expose_flags(struct device *dev, s32 value)
253                         { return 0; }
254 static inline void dev_pm_qos_hide_flags(struct device *dev) {}
255 static inline int dev_pm_qos_update_flags(struct device *dev, s32 m, bool set)
256                         { return 0; }
257 static inline s32 dev_pm_qos_get_user_latency_tolerance(struct device *dev)
258                         { return PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT; }
259 static inline int dev_pm_qos_update_user_latency_tolerance(struct device *dev, s32 val)
260                         { return 0; }
261 static inline int dev_pm_qos_expose_latency_tolerance(struct device *dev)
262                         { return 0; }
263 static inline void dev_pm_qos_hide_latency_tolerance(struct device *dev) {}
264 
265 static inline s32 dev_pm_qos_requested_resume_latency(struct device *dev)
266 {
267         return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
268 }
269 static inline s32 dev_pm_qos_requested_flags(struct device *dev) { return 0; }
270 static inline s32 dev_pm_qos_raw_resume_latency(struct device *dev)
271 {
272         return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
273 }
274 #endif
275 
276 #endif
277 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp