File Index
Files and directories
Sign in
FILE

pm_qos.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/pm_qos.h C
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/*
  3 * Definitions related to Power Management Quality of Service (PM QoS).
  4 *
  5 * Copyright (C) 2020 Intel Corporation
  6 *
  7 * Authors:
  8 *	Mark Gross <mgross@linux.intel.com>
  9 *	Rafael J. Wysocki <rafael.j.wysocki@intel.com>
 10 */
 11
 12#ifndef _LINUX_PM_QOS_H
 13#define _LINUX_PM_QOS_H
 14
 15#include <linux/plist.h>
 16#include <linux/notifier.h>
 17#include <linux/device.h>
 18
 19enum pm_qos_flags_status {
 20	PM_QOS_FLAGS_UNDEFINED = -1,
 21	PM_QOS_FLAGS_NONE,
 22	PM_QOS_FLAGS_SOME,
 23	PM_QOS_FLAGS_ALL,
 24};
 25
 26#define PM_QOS_DEFAULT_VALUE	(-1)
 27#define PM_QOS_LATENCY_ANY	S32_MAX
 28#define PM_QOS_LATENCY_ANY_NS	((s64)PM_QOS_LATENCY_ANY * NSEC_PER_USEC)
 29
 30#define PM_QOS_CPU_LATENCY_DEFAULT_VALUE	(2000 * USEC_PER_SEC)
 31#define PM_QOS_RESUME_LATENCY_DEFAULT_VALUE	PM_QOS_LATENCY_ANY
 32#define PM_QOS_RESUME_LATENCY_NO_CONSTRAINT	PM_QOS_LATENCY_ANY
 33#define PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS	PM_QOS_LATENCY_ANY_NS
 34#define PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE	0
 35#define PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE	0
 36#define PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE	FREQ_QOS_MAX_DEFAULT_VALUE
 37#define PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT	(-1)
 38
 39#define PM_QOS_FLAG_NO_POWER_OFF	(1 << 0)
 40
 41enum pm_qos_type {
 42	PM_QOS_UNITIALIZED,
 43	PM_QOS_MAX,		/* return the largest value */
 44	PM_QOS_MIN,		/* return the smallest value */
 45};
 46
 47/*
 48 * Note: The lockless read path depends on the CPU accessing target_value
 49 * or effective_flags atomically.  Atomic access is only guaranteed on all CPU
 50 * types linux supports for 32 bit quantites
 51 */
 52struct pm_qos_constraints {
 53	struct plist_head list;
 54	s32 target_value;	/* Do not change to 64 bit */
 55	s32 default_value;
 56	s32 no_constraint_value;
 57	enum pm_qos_type type;
 58	struct blocking_notifier_head *notifiers;
 59};
 60
 61struct pm_qos_request {
 62	struct plist_node node;
 63	struct pm_qos_constraints *qos;
 64};
 65
 66struct pm_qos_flags_request {
 67	struct list_head node;
 68	s32 flags;	/* Do not change to 64 bit */
 69};
 70
 71struct pm_qos_flags {
 72	struct list_head list;
 73	s32 effective_flags;	/* Do not change to 64 bit */
 74};
 75
 76
 77#define FREQ_QOS_MIN_DEFAULT_VALUE	0
 78#define FREQ_QOS_MAX_DEFAULT_VALUE	S32_MAX
 79
 80enum freq_qos_req_type {
 81	FREQ_QOS_MIN = 1,
 82	FREQ_QOS_MAX,
 83};
 84
 85struct freq_constraints {
 86	struct pm_qos_constraints min_freq;
 87	struct blocking_notifier_head min_freq_notifiers;
 88	struct pm_qos_constraints max_freq;
 89	struct blocking_notifier_head max_freq_notifiers;
 90};
 91
 92struct freq_qos_request {
 93	enum freq_qos_req_type type;
 94	struct plist_node pnode;
 95	struct freq_constraints *qos;
 96};
 97
 98
 99enum dev_pm_qos_req_type {
100	DEV_PM_QOS_RESUME_LATENCY = 1,
101	DEV_PM_QOS_LATENCY_TOLERANCE,
102	DEV_PM_QOS_MIN_FREQUENCY,
103	DEV_PM_QOS_MAX_FREQUENCY,
104	DEV_PM_QOS_FLAGS,
105};
106
107struct dev_pm_qos_request {
108	enum dev_pm_qos_req_type type;
109	union {
110		struct plist_node pnode;
111		struct pm_qos_flags_request flr;
112		struct freq_qos_request freq;
113	} data;
114	struct device *dev;
115};
116
117struct dev_pm_qos {
118	struct pm_qos_constraints resume_latency;
119	struct pm_qos_constraints latency_tolerance;
120	struct freq_constraints freq;
121	struct pm_qos_flags flags;
122	struct dev_pm_qos_request *resume_latency_req;
123	struct dev_pm_qos_request *latency_tolerance_req;
124	struct dev_pm_qos_request *flags_req;
125};
126
127/* Action requested to pm_qos_update_target */
128enum pm_qos_req_action {
129	PM_QOS_ADD_REQ,		/* Add a new request */
130	PM_QOS_UPDATE_REQ,	/* Update an existing request */
131	PM_QOS_REMOVE_REQ	/* Remove an existing request */
132};
133
134static inline int dev_pm_qos_request_active(struct dev_pm_qos_request *req)
135{
136	return req->dev != NULL;
137}
138
139s32 pm_qos_read_value(struct pm_qos_constraints *c);
140int pm_qos_update_target(struct pm_qos_constraints *c, struct plist_node *node,
141			 enum pm_qos_req_action action, int value);
142bool pm_qos_update_flags(struct pm_qos_flags *pqf,
143			 struct pm_qos_flags_request *req,
144			 enum pm_qos_req_action action, s32 val);
145
146#ifdef CONFIG_CPU_IDLE
147s32 cpu_latency_qos_limit(void);
148bool cpu_latency_qos_request_active(struct pm_qos_request *req);
149void cpu_latency_qos_add_request(struct pm_qos_request *req, s32 value);
150void cpu_latency_qos_update_request(struct pm_qos_request *req, s32 new_value);
151void cpu_latency_qos_remove_request(struct pm_qos_request *req);
152#else
153static inline s32 cpu_latency_qos_limit(void) { return INT_MAX; }
154static inline bool cpu_latency_qos_request_active(struct pm_qos_request *req)
155{
156	return false;
157}
158static inline void cpu_latency_qos_add_request(struct pm_qos_request *req,
159					       s32 value) {}
160static inline void cpu_latency_qos_update_request(struct pm_qos_request *req,
161						  s32 new_value) {}
162static inline void cpu_latency_qos_remove_request(struct pm_qos_request *req) {}
163#endif
164
165#ifdef CONFIG_PM_QOS_CPU_SYSTEM_WAKEUP
166s32 cpu_wakeup_latency_qos_limit(void);
167#else
168static inline s32 cpu_wakeup_latency_qos_limit(void)
169{
170	return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
171}
172#endif
173
174#ifdef CONFIG_PM
175enum pm_qos_flags_status __dev_pm_qos_flags(struct device *dev, s32 mask);
176enum pm_qos_flags_status dev_pm_qos_flags(struct device *dev, s32 mask);
177s32 __dev_pm_qos_resume_latency(struct device *dev);
178s32 dev_pm_qos_read_value(struct device *dev, enum dev_pm_qos_req_type type);
179int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
180			   enum dev_pm_qos_req_type type, s32 value);
181int dev_pm_qos_update_request(struct dev_pm_qos_request *req, s32 new_value);
182int dev_pm_qos_remove_request(struct dev_pm_qos_request *req);
183int dev_pm_qos_add_notifier(struct device *dev,
184			    struct notifier_block *notifier,
185			    enum dev_pm_qos_req_type type);
186int dev_pm_qos_remove_notifier(struct device *dev,
187			       struct notifier_block *notifier,
188			       enum dev_pm_qos_req_type type);
189void dev_pm_qos_constraints_init(struct device *dev);
190void dev_pm_qos_constraints_destroy(struct device *dev);
191int dev_pm_qos_add_ancestor_request(struct device *dev,
192				    struct dev_pm_qos_request *req,
193				    enum dev_pm_qos_req_type type, s32 value);
194int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value);
195void dev_pm_qos_hide_latency_limit(struct device *dev);
196int dev_pm_qos_expose_flags(struct device *dev, s32 value);
197void dev_pm_qos_hide_flags(struct device *dev);
198int dev_pm_qos_update_flags(struct device *dev, s32 mask, bool set);
199s32 dev_pm_qos_get_user_latency_tolerance(struct device *dev);
200int dev_pm_qos_update_user_latency_tolerance(struct device *dev, s32 val);
201int dev_pm_qos_expose_latency_tolerance(struct device *dev);
202void dev_pm_qos_hide_latency_tolerance(struct device *dev);
203
204static inline s32 dev_pm_qos_requested_resume_latency(struct device *dev)
205{
206	return dev->power.qos->resume_latency_req->data.pnode.prio;
207}
208
209static inline s32 dev_pm_qos_requested_flags(struct device *dev)
210{
211	return dev->power.qos->flags_req->data.flr.flags;
212}
213
214static inline s32 dev_pm_qos_raw_resume_latency(struct device *dev)
215{
216	return IS_ERR_OR_NULL(dev->power.qos) ?
217		PM_QOS_RESUME_LATENCY_NO_CONSTRAINT :
218		pm_qos_read_value(&dev->power.qos->resume_latency);
219}
220#else
221static inline enum pm_qos_flags_status __dev_pm_qos_flags(struct device *dev,
222							  s32 mask)
223			{ return PM_QOS_FLAGS_UNDEFINED; }
224static inline enum pm_qos_flags_status dev_pm_qos_flags(struct device *dev,
225							s32 mask)
226			{ return PM_QOS_FLAGS_UNDEFINED; }
227static inline s32 __dev_pm_qos_resume_latency(struct device *dev)
228			{ return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; }
229static inline s32 dev_pm_qos_read_value(struct device *dev,
230					enum dev_pm_qos_req_type type)
231{
232	switch (type) {
233	case DEV_PM_QOS_RESUME_LATENCY:
234		return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
235	case DEV_PM_QOS_MIN_FREQUENCY:
236		return PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE;
237	case DEV_PM_QOS_MAX_FREQUENCY:
238		return PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE;
239	default:
240		WARN_ON(1);
241		return 0;
242	}
243}
244
245static inline int dev_pm_qos_add_request(struct device *dev,
246					 struct dev_pm_qos_request *req,
247					 enum dev_pm_qos_req_type type,
248					 s32 value)
249			{ return 0; }
250static inline int dev_pm_qos_update_request(struct dev_pm_qos_request *req,
251					    s32 new_value)
252			{ return 0; }
253static inline int dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
254			{ return 0; }
255static inline int dev_pm_qos_add_notifier(struct device *dev,
256					  struct notifier_block *notifier,
257					  enum dev_pm_qos_req_type type)
258			{ return 0; }
259static inline int dev_pm_qos_remove_notifier(struct device *dev,
260					     struct notifier_block *notifier,
261					     enum dev_pm_qos_req_type type)
262			{ return 0; }
263static inline void dev_pm_qos_constraints_init(struct device *dev)
264{
265	dev->power.power_state = PMSG_ON;
266}
267static inline void dev_pm_qos_constraints_destroy(struct device *dev)
268{
269	dev->power.power_state = PMSG_INVALID;
270}
271static inline int dev_pm_qos_add_ancestor_request(struct device *dev,
272						  struct dev_pm_qos_request *req,
273						  enum dev_pm_qos_req_type type,
274						  s32 value)
275			{ return 0; }
276static inline int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value)
277			{ return 0; }
278static inline void dev_pm_qos_hide_latency_limit(struct device *dev) {}
279static inline int dev_pm_qos_expose_flags(struct device *dev, s32 value)
280			{ return 0; }
281static inline void dev_pm_qos_hide_flags(struct device *dev) {}
282static inline int dev_pm_qos_update_flags(struct device *dev, s32 m, bool set)
283			{ return 0; }
284static inline s32 dev_pm_qos_get_user_latency_tolerance(struct device *dev)
285			{ return PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT; }
286static inline int dev_pm_qos_update_user_latency_tolerance(struct device *dev, s32 val)
287			{ return 0; }
288static inline int dev_pm_qos_expose_latency_tolerance(struct device *dev)
289			{ return 0; }
290static inline void dev_pm_qos_hide_latency_tolerance(struct device *dev) {}
291
292static inline s32 dev_pm_qos_requested_resume_latency(struct device *dev)
293{
294	return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
295}
296static inline s32 dev_pm_qos_requested_flags(struct device *dev) { return 0; }
297static inline s32 dev_pm_qos_raw_resume_latency(struct device *dev)
298{
299	return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
300}
301#endif
302
303static inline int freq_qos_request_active(struct freq_qos_request *req)
304{
305	return !IS_ERR_OR_NULL(req->qos);
306}
307
308void freq_constraints_init(struct freq_constraints *qos);
309
310s32 freq_qos_read_value(struct freq_constraints *qos,
311			enum freq_qos_req_type type);
312
313int freq_qos_add_request(struct freq_constraints *qos,
314			 struct freq_qos_request *req,
315			 enum freq_qos_req_type type, s32 value);
316int freq_qos_update_request(struct freq_qos_request *req, s32 new_value);
317int freq_qos_remove_request(struct freq_qos_request *req);
318int freq_qos_apply(struct freq_qos_request *req,
319		   enum pm_qos_req_action action, s32 value);
320
321int freq_qos_add_notifier(struct freq_constraints *qos,
322			  enum freq_qos_req_type type,
323			  struct notifier_block *notifier);
324int freq_qos_remove_notifier(struct freq_constraints *qos,
325			     enum freq_qos_req_type type,
326			     struct notifier_block *notifier);
327
328#endif
~/ Read-only file preview.