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.
6 * Mark Gross <mgross@linux.intel.com>
8 #include <linux/plist.h>
9 #include <linux/notifier.h>
10 #include <linux/device.h>
11 #include <linux/workqueue.h>
15 PM_QOS_CPU_DMA_LATENCY
,
17 /* insert new class ID */
21 enum pm_qos_flags_status
{
22 PM_QOS_FLAGS_UNDEFINED
= -1,
28 #define PM_QOS_DEFAULT_VALUE (-1)
29 #define PM_QOS_LATENCY_ANY S32_MAX
30 #define PM_QOS_LATENCY_ANY_NS ((s64)PM_QOS_LATENCY_ANY * NSEC_PER_USEC)
32 #define PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE (2000 * USEC_PER_SEC)
33 #define PM_QOS_RESUME_LATENCY_DEFAULT_VALUE PM_QOS_LATENCY_ANY
34 #define PM_QOS_RESUME_LATENCY_NO_CONSTRAINT PM_QOS_LATENCY_ANY
35 #define PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS PM_QOS_LATENCY_ANY_NS
36 #define PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE 0
37 #define PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE 0
38 #define PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE FREQ_QOS_MAX_DEFAULT_VALUE
39 #define PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT (-1)
41 #define PM_QOS_FLAG_NO_POWER_OFF (1 << 0)
43 struct pm_qos_request
{
44 struct plist_node node
;
46 struct delayed_work work
; /* for pm_qos_update_request_timeout */
49 struct pm_qos_flags_request
{
50 struct list_head node
;
51 s32 flags
; /* Do not change to 64 bit */
56 PM_QOS_MAX
, /* return the largest value */
57 PM_QOS_MIN
, /* return the smallest value */
58 PM_QOS_SUM
/* return the sum */
62 * Note: The lockless read path depends on the CPU accessing target_value
63 * or effective_flags atomically. Atomic access is only guaranteed on all CPU
64 * types linux supports for 32 bit quantites
66 struct pm_qos_constraints
{
67 struct plist_head list
;
68 s32 target_value
; /* Do not change to 64 bit */
70 s32 no_constraint_value
;
71 enum pm_qos_type type
;
72 struct blocking_notifier_head
*notifiers
;
76 struct list_head list
;
77 s32 effective_flags
; /* Do not change to 64 bit */
81 #define FREQ_QOS_MIN_DEFAULT_VALUE 0
82 #define FREQ_QOS_MAX_DEFAULT_VALUE S32_MAX
84 enum freq_qos_req_type
{
89 struct freq_constraints
{
90 struct pm_qos_constraints min_freq
;
91 struct blocking_notifier_head min_freq_notifiers
;
92 struct pm_qos_constraints max_freq
;
93 struct blocking_notifier_head max_freq_notifiers
;
96 struct freq_qos_request
{
97 enum freq_qos_req_type type
;
98 struct plist_node pnode
;
99 struct freq_constraints
*qos
;
103 enum dev_pm_qos_req_type
{
104 DEV_PM_QOS_RESUME_LATENCY
= 1,
105 DEV_PM_QOS_LATENCY_TOLERANCE
,
106 DEV_PM_QOS_MIN_FREQUENCY
,
107 DEV_PM_QOS_MAX_FREQUENCY
,
111 struct dev_pm_qos_request
{
112 enum dev_pm_qos_req_type type
;
114 struct plist_node pnode
;
115 struct pm_qos_flags_request flr
;
116 struct freq_qos_request freq
;
122 struct pm_qos_constraints resume_latency
;
123 struct pm_qos_constraints latency_tolerance
;
124 struct freq_constraints freq
;
125 struct pm_qos_flags flags
;
126 struct dev_pm_qos_request
*resume_latency_req
;
127 struct dev_pm_qos_request
*latency_tolerance_req
;
128 struct dev_pm_qos_request
*flags_req
;
131 /* Action requested to pm_qos_update_target */
132 enum pm_qos_req_action
{
133 PM_QOS_ADD_REQ
, /* Add a new request */
134 PM_QOS_UPDATE_REQ
, /* Update an existing request */
135 PM_QOS_REMOVE_REQ
/* Remove an existing request */
138 static inline int dev_pm_qos_request_active(struct dev_pm_qos_request
*req
)
140 return req
->dev
!= NULL
;
143 int pm_qos_update_target(struct pm_qos_constraints
*c
, struct plist_node
*node
,
144 enum pm_qos_req_action action
, int value
);
145 bool pm_qos_update_flags(struct pm_qos_flags
*pqf
,
146 struct pm_qos_flags_request
*req
,
147 enum pm_qos_req_action action
, s32 val
);
148 void pm_qos_add_request(struct pm_qos_request
*req
, int pm_qos_class
,
150 void pm_qos_update_request(struct pm_qos_request
*req
,
152 void pm_qos_update_request_timeout(struct pm_qos_request
*req
,
153 s32 new_value
, unsigned long timeout_us
);
154 void pm_qos_remove_request(struct pm_qos_request
*req
);
156 int pm_qos_request(int pm_qos_class
);
157 int pm_qos_add_notifier(int pm_qos_class
, struct notifier_block
*notifier
);
158 int pm_qos_remove_notifier(int pm_qos_class
, struct notifier_block
*notifier
);
159 int pm_qos_request_active(struct pm_qos_request
*req
);
160 s32
pm_qos_read_value(struct pm_qos_constraints
*c
);
163 enum pm_qos_flags_status
__dev_pm_qos_flags(struct device
*dev
, s32 mask
);
164 enum pm_qos_flags_status
dev_pm_qos_flags(struct device
*dev
, s32 mask
);
165 s32
__dev_pm_qos_resume_latency(struct device
*dev
);
166 s32
dev_pm_qos_read_value(struct device
*dev
, enum dev_pm_qos_req_type type
);
167 int dev_pm_qos_add_request(struct device
*dev
, struct dev_pm_qos_request
*req
,
168 enum dev_pm_qos_req_type type
, s32 value
);
169 int dev_pm_qos_update_request(struct dev_pm_qos_request
*req
, s32 new_value
);
170 int dev_pm_qos_remove_request(struct dev_pm_qos_request
*req
);
171 int dev_pm_qos_add_notifier(struct device
*dev
,
172 struct notifier_block
*notifier
,
173 enum dev_pm_qos_req_type type
);
174 int dev_pm_qos_remove_notifier(struct device
*dev
,
175 struct notifier_block
*notifier
,
176 enum dev_pm_qos_req_type type
);
177 void dev_pm_qos_constraints_init(struct device
*dev
);
178 void dev_pm_qos_constraints_destroy(struct device
*dev
);
179 int dev_pm_qos_add_ancestor_request(struct device
*dev
,
180 struct dev_pm_qos_request
*req
,
181 enum dev_pm_qos_req_type type
, s32 value
);
182 int dev_pm_qos_expose_latency_limit(struct device
*dev
, s32 value
);
183 void dev_pm_qos_hide_latency_limit(struct device
*dev
);
184 int dev_pm_qos_expose_flags(struct device
*dev
, s32 value
);
185 void dev_pm_qos_hide_flags(struct device
*dev
);
186 int dev_pm_qos_update_flags(struct device
*dev
, s32 mask
, bool set
);
187 s32
dev_pm_qos_get_user_latency_tolerance(struct device
*dev
);
188 int dev_pm_qos_update_user_latency_tolerance(struct device
*dev
, s32 val
);
189 int dev_pm_qos_expose_latency_tolerance(struct device
*dev
);
190 void dev_pm_qos_hide_latency_tolerance(struct device
*dev
);
192 static inline s32
dev_pm_qos_requested_resume_latency(struct device
*dev
)
194 return dev
->power
.qos
->resume_latency_req
->data
.pnode
.prio
;
197 static inline s32
dev_pm_qos_requested_flags(struct device
*dev
)
199 return dev
->power
.qos
->flags_req
->data
.flr
.flags
;
202 static inline s32
dev_pm_qos_raw_resume_latency(struct device
*dev
)
204 return IS_ERR_OR_NULL(dev
->power
.qos
) ?
205 PM_QOS_RESUME_LATENCY_NO_CONSTRAINT
:
206 pm_qos_read_value(&dev
->power
.qos
->resume_latency
);
209 static inline enum pm_qos_flags_status
__dev_pm_qos_flags(struct device
*dev
,
211 { return PM_QOS_FLAGS_UNDEFINED
; }
212 static inline enum pm_qos_flags_status
dev_pm_qos_flags(struct device
*dev
,
214 { return PM_QOS_FLAGS_UNDEFINED
; }
215 static inline s32
__dev_pm_qos_resume_latency(struct device
*dev
)
216 { return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT
; }
217 static inline s32
dev_pm_qos_read_value(struct device
*dev
,
218 enum dev_pm_qos_req_type type
)
221 case DEV_PM_QOS_RESUME_LATENCY
:
222 return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT
;
223 case DEV_PM_QOS_MIN_FREQUENCY
:
224 return PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE
;
225 case DEV_PM_QOS_MAX_FREQUENCY
:
226 return PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE
;
233 static inline int dev_pm_qos_add_request(struct device
*dev
,
234 struct dev_pm_qos_request
*req
,
235 enum dev_pm_qos_req_type type
,
238 static inline int dev_pm_qos_update_request(struct dev_pm_qos_request
*req
,
241 static inline int dev_pm_qos_remove_request(struct dev_pm_qos_request
*req
)
243 static inline int dev_pm_qos_add_notifier(struct device
*dev
,
244 struct notifier_block
*notifier
,
245 enum dev_pm_qos_req_type type
)
247 static inline int dev_pm_qos_remove_notifier(struct device
*dev
,
248 struct notifier_block
*notifier
,
249 enum dev_pm_qos_req_type type
)
251 static inline void dev_pm_qos_constraints_init(struct device
*dev
)
253 dev
->power
.power_state
= PMSG_ON
;
255 static inline void dev_pm_qos_constraints_destroy(struct device
*dev
)
257 dev
->power
.power_state
= PMSG_INVALID
;
259 static inline int dev_pm_qos_add_ancestor_request(struct device
*dev
,
260 struct dev_pm_qos_request
*req
,
261 enum dev_pm_qos_req_type type
,
264 static inline int dev_pm_qos_expose_latency_limit(struct device
*dev
, s32 value
)
266 static inline void dev_pm_qos_hide_latency_limit(struct device
*dev
) {}
267 static inline int dev_pm_qos_expose_flags(struct device
*dev
, s32 value
)
269 static inline void dev_pm_qos_hide_flags(struct device
*dev
) {}
270 static inline int dev_pm_qos_update_flags(struct device
*dev
, s32 m
, bool set
)
272 static inline s32
dev_pm_qos_get_user_latency_tolerance(struct device
*dev
)
273 { return PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT
; }
274 static inline int dev_pm_qos_update_user_latency_tolerance(struct device
*dev
, s32 val
)
276 static inline int dev_pm_qos_expose_latency_tolerance(struct device
*dev
)
278 static inline void dev_pm_qos_hide_latency_tolerance(struct device
*dev
) {}
280 static inline s32
dev_pm_qos_requested_resume_latency(struct device
*dev
)
282 return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT
;
284 static inline s32
dev_pm_qos_requested_flags(struct device
*dev
) { return 0; }
285 static inline s32
dev_pm_qos_raw_resume_latency(struct device
*dev
)
287 return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT
;
291 static inline int freq_qos_request_active(struct freq_qos_request
*req
)
293 return !IS_ERR_OR_NULL(req
->qos
);
296 void freq_constraints_init(struct freq_constraints
*qos
);
298 s32
freq_qos_read_value(struct freq_constraints
*qos
,
299 enum freq_qos_req_type type
);
301 int freq_qos_add_request(struct freq_constraints
*qos
,
302 struct freq_qos_request
*req
,
303 enum freq_qos_req_type type
, s32 value
);
304 int freq_qos_update_request(struct freq_qos_request
*req
, s32 new_value
);
305 int freq_qos_remove_request(struct freq_qos_request
*req
);
306 int freq_qos_apply(struct freq_qos_request
*req
,
307 enum pm_qos_req_action action
, s32 value
);
309 int freq_qos_add_notifier(struct freq_constraints
*qos
,
310 enum freq_qos_req_type type
,
311 struct notifier_block
*notifier
);
312 int freq_qos_remove_notifier(struct freq_constraints
*qos
,
313 enum freq_qos_req_type type
,
314 struct notifier_block
*notifier
);