2 * Devices PM QoS constraints management
4 * Copyright (C) 2011 Texas Instruments, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 * This module exposes the interface to kernel space for specifying
12 * per-device PM QoS dependencies. It provides infrastructure for registration
15 * Dependents on a QoS value : register requests
16 * Watchers of QoS value : get notified when target QoS value changes
18 * This QoS design is best effort based. Dependents register their QoS needs.
19 * Watchers register to keep track of the current QoS needs of the system.
20 * Watchers can register different types of notification callbacks:
21 * . a per-device notification callback using the dev_pm_qos_*_notifier API.
22 * The notification chain data is stored in the per-device constraint
24 * . a system-wide notification callback using the dev_pm_qos_*_global_notifier
25 * API. The notification chain data is stored in a static variable.
27 * Note about the per-device constraint data struct allocation:
28 * . The per-device constraints data struct ptr is tored into the device
30 * . To minimize the data usage by the per-device constraints, the data struct
31 * is only allocated at the first call to dev_pm_qos_add_request.
32 * . The data is later free'd when the device is removed from the system.
33 * . A global mutex protects the constraints users from the data being
34 * allocated and free'd.
37 #include <linux/pm_qos.h>
38 #include <linux/spinlock.h>
39 #include <linux/slab.h>
40 #include <linux/device.h>
41 #include <linux/mutex.h>
42 #include <linux/export.h>
43 #include <linux/pm_runtime.h>
44 #include <linux/err.h>
45 #include <trace/events/power.h>
49 static DEFINE_MUTEX(dev_pm_qos_mtx
);
50 static DEFINE_MUTEX(dev_pm_qos_sysfs_mtx
);
52 static BLOCKING_NOTIFIER_HEAD(dev_pm_notifiers
);
55 * __dev_pm_qos_flags - Check PM QoS flags for a given device.
56 * @dev: Device to check the PM QoS flags for.
57 * @mask: Flags to check against.
59 * This routine must be called with dev->power.lock held.
61 enum pm_qos_flags_status
__dev_pm_qos_flags(struct device
*dev
, s32 mask
)
63 struct dev_pm_qos
*qos
= dev
->power
.qos
;
64 struct pm_qos_flags
*pqf
;
67 lockdep_assert_held(&dev
->power
.lock
);
69 if (IS_ERR_OR_NULL(qos
))
70 return PM_QOS_FLAGS_UNDEFINED
;
73 if (list_empty(&pqf
->list
))
74 return PM_QOS_FLAGS_UNDEFINED
;
76 val
= pqf
->effective_flags
& mask
;
78 return (val
== mask
) ? PM_QOS_FLAGS_ALL
: PM_QOS_FLAGS_SOME
;
80 return PM_QOS_FLAGS_NONE
;
84 * dev_pm_qos_flags - Check PM QoS flags for a given device (locked).
85 * @dev: Device to check the PM QoS flags for.
86 * @mask: Flags to check against.
88 enum pm_qos_flags_status
dev_pm_qos_flags(struct device
*dev
, s32 mask
)
90 unsigned long irqflags
;
91 enum pm_qos_flags_status ret
;
93 spin_lock_irqsave(&dev
->power
.lock
, irqflags
);
94 ret
= __dev_pm_qos_flags(dev
, mask
);
95 spin_unlock_irqrestore(&dev
->power
.lock
, irqflags
);
99 EXPORT_SYMBOL_GPL(dev_pm_qos_flags
);
102 * __dev_pm_qos_read_value - Get PM QoS constraint for a given device.
103 * @dev: Device to get the PM QoS constraint value for.
105 * This routine must be called with dev->power.lock held.
107 s32
__dev_pm_qos_read_value(struct device
*dev
)
109 lockdep_assert_held(&dev
->power
.lock
);
111 return IS_ERR_OR_NULL(dev
->power
.qos
) ?
112 0 : pm_qos_read_value(&dev
->power
.qos
->resume_latency
);
116 * dev_pm_qos_read_value - Get PM QoS constraint for a given device (locked).
117 * @dev: Device to get the PM QoS constraint value for.
119 s32
dev_pm_qos_read_value(struct device
*dev
)
124 spin_lock_irqsave(&dev
->power
.lock
, flags
);
125 ret
= __dev_pm_qos_read_value(dev
);
126 spin_unlock_irqrestore(&dev
->power
.lock
, flags
);
132 * apply_constraint - Add/modify/remove device PM QoS request.
133 * @req: Constraint request to apply
134 * @action: Action to perform (add/update/remove).
135 * @value: Value to assign to the QoS request.
137 * Internal function to update the constraints list using the PM QoS core
138 * code and if needed call the per-device and the global notification
141 static int apply_constraint(struct dev_pm_qos_request
*req
,
142 enum pm_qos_req_action action
, s32 value
)
144 struct dev_pm_qos
*qos
= req
->dev
->power
.qos
;
148 case DEV_PM_QOS_RESUME_LATENCY
:
149 ret
= pm_qos_update_target(&qos
->resume_latency
,
150 &req
->data
.pnode
, action
, value
);
152 value
= pm_qos_read_value(&qos
->resume_latency
);
153 blocking_notifier_call_chain(&dev_pm_notifiers
,
154 (unsigned long)value
,
158 case DEV_PM_QOS_LATENCY_TOLERANCE
:
159 ret
= pm_qos_update_target(&qos
->latency_tolerance
,
160 &req
->data
.pnode
, action
, value
);
162 value
= pm_qos_read_value(&qos
->latency_tolerance
);
163 req
->dev
->power
.set_latency_tolerance(req
->dev
, value
);
166 case DEV_PM_QOS_FLAGS
:
167 ret
= pm_qos_update_flags(&qos
->flags
, &req
->data
.flr
,
178 * dev_pm_qos_constraints_allocate
179 * @dev: device to allocate data for
181 * Called at the first call to add_request, for constraint data allocation
182 * Must be called with the dev_pm_qos_mtx mutex held
184 static int dev_pm_qos_constraints_allocate(struct device
*dev
)
186 struct dev_pm_qos
*qos
;
187 struct pm_qos_constraints
*c
;
188 struct blocking_notifier_head
*n
;
190 qos
= kzalloc(sizeof(*qos
), GFP_KERNEL
);
194 n
= kzalloc(sizeof(*n
), GFP_KERNEL
);
199 BLOCKING_INIT_NOTIFIER_HEAD(n
);
201 c
= &qos
->resume_latency
;
202 plist_head_init(&c
->list
);
203 c
->target_value
= PM_QOS_RESUME_LATENCY_DEFAULT_VALUE
;
204 c
->default_value
= PM_QOS_RESUME_LATENCY_DEFAULT_VALUE
;
205 c
->no_constraint_value
= PM_QOS_RESUME_LATENCY_DEFAULT_VALUE
;
206 c
->type
= PM_QOS_MIN
;
209 c
= &qos
->latency_tolerance
;
210 plist_head_init(&c
->list
);
211 c
->target_value
= PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE
;
212 c
->default_value
= PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE
;
213 c
->no_constraint_value
= PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT
;
214 c
->type
= PM_QOS_MIN
;
216 INIT_LIST_HEAD(&qos
->flags
.list
);
218 spin_lock_irq(&dev
->power
.lock
);
219 dev
->power
.qos
= qos
;
220 spin_unlock_irq(&dev
->power
.lock
);
225 static void __dev_pm_qos_hide_latency_limit(struct device
*dev
);
226 static void __dev_pm_qos_hide_flags(struct device
*dev
);
229 * dev_pm_qos_constraints_destroy
230 * @dev: target device
232 * Called from the device PM subsystem on device removal under device_pm_lock().
234 void dev_pm_qos_constraints_destroy(struct device
*dev
)
236 struct dev_pm_qos
*qos
;
237 struct dev_pm_qos_request
*req
, *tmp
;
238 struct pm_qos_constraints
*c
;
239 struct pm_qos_flags
*f
;
241 mutex_lock(&dev_pm_qos_sysfs_mtx
);
244 * If the device's PM QoS resume latency limit or PM QoS flags have been
245 * exposed to user space, they have to be hidden at this point.
247 pm_qos_sysfs_remove_resume_latency(dev
);
248 pm_qos_sysfs_remove_flags(dev
);
250 mutex_lock(&dev_pm_qos_mtx
);
252 __dev_pm_qos_hide_latency_limit(dev
);
253 __dev_pm_qos_hide_flags(dev
);
255 qos
= dev
->power
.qos
;
259 /* Flush the constraints lists for the device. */
260 c
= &qos
->resume_latency
;
261 plist_for_each_entry_safe(req
, tmp
, &c
->list
, data
.pnode
) {
263 * Update constraints list and call the notification
264 * callbacks if needed
266 apply_constraint(req
, PM_QOS_REMOVE_REQ
, PM_QOS_DEFAULT_VALUE
);
267 memset(req
, 0, sizeof(*req
));
269 c
= &qos
->latency_tolerance
;
270 plist_for_each_entry_safe(req
, tmp
, &c
->list
, data
.pnode
) {
271 apply_constraint(req
, PM_QOS_REMOVE_REQ
, PM_QOS_DEFAULT_VALUE
);
272 memset(req
, 0, sizeof(*req
));
275 list_for_each_entry_safe(req
, tmp
, &f
->list
, data
.flr
.node
) {
276 apply_constraint(req
, PM_QOS_REMOVE_REQ
, PM_QOS_DEFAULT_VALUE
);
277 memset(req
, 0, sizeof(*req
));
280 spin_lock_irq(&dev
->power
.lock
);
281 dev
->power
.qos
= ERR_PTR(-ENODEV
);
282 spin_unlock_irq(&dev
->power
.lock
);
288 mutex_unlock(&dev_pm_qos_mtx
);
290 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
293 static bool dev_pm_qos_invalid_request(struct device
*dev
,
294 struct dev_pm_qos_request
*req
)
296 return !req
|| (req
->type
== DEV_PM_QOS_LATENCY_TOLERANCE
297 && !dev
->power
.set_latency_tolerance
);
300 static int __dev_pm_qos_add_request(struct device
*dev
,
301 struct dev_pm_qos_request
*req
,
302 enum dev_pm_qos_req_type type
, s32 value
)
306 if (!dev
|| dev_pm_qos_invalid_request(dev
, req
))
309 if (WARN(dev_pm_qos_request_active(req
),
310 "%s() called for already added request\n", __func__
))
313 if (IS_ERR(dev
->power
.qos
))
315 else if (!dev
->power
.qos
)
316 ret
= dev_pm_qos_constraints_allocate(dev
);
318 trace_dev_pm_qos_add_request(dev_name(dev
), type
, value
);
322 ret
= apply_constraint(req
, PM_QOS_ADD_REQ
, value
);
328 * dev_pm_qos_add_request - inserts new qos request into the list
329 * @dev: target device for the constraint
330 * @req: pointer to a preallocated handle
331 * @type: type of the request
332 * @value: defines the qos request
334 * This function inserts a new entry in the device constraints list of
335 * requested qos performance characteristics. It recomputes the aggregate
336 * QoS expectations of parameters and initializes the dev_pm_qos_request
337 * handle. Caller needs to save this handle for later use in updates and
340 * Returns 1 if the aggregated constraint value has changed,
341 * 0 if the aggregated constraint value has not changed,
342 * -EINVAL in case of wrong parameters, -ENOMEM if there's not enough memory
343 * to allocate for data structures, -ENODEV if the device has just been removed
346 * Callers should ensure that the target device is not RPM_SUSPENDED before
347 * using this function for requests of type DEV_PM_QOS_FLAGS.
349 int dev_pm_qos_add_request(struct device
*dev
, struct dev_pm_qos_request
*req
,
350 enum dev_pm_qos_req_type type
, s32 value
)
354 mutex_lock(&dev_pm_qos_mtx
);
355 ret
= __dev_pm_qos_add_request(dev
, req
, type
, value
);
356 mutex_unlock(&dev_pm_qos_mtx
);
359 EXPORT_SYMBOL_GPL(dev_pm_qos_add_request
);
362 * __dev_pm_qos_update_request - Modify an existing device PM QoS request.
363 * @req : PM QoS request to modify.
364 * @new_value: New value to request.
366 static int __dev_pm_qos_update_request(struct dev_pm_qos_request
*req
,
372 if (!req
) /*guard against callers passing in null */
375 if (WARN(!dev_pm_qos_request_active(req
),
376 "%s() called for unknown object\n", __func__
))
379 if (IS_ERR_OR_NULL(req
->dev
->power
.qos
))
383 case DEV_PM_QOS_RESUME_LATENCY
:
384 case DEV_PM_QOS_LATENCY_TOLERANCE
:
385 curr_value
= req
->data
.pnode
.prio
;
387 case DEV_PM_QOS_FLAGS
:
388 curr_value
= req
->data
.flr
.flags
;
394 trace_dev_pm_qos_update_request(dev_name(req
->dev
), req
->type
,
396 if (curr_value
!= new_value
)
397 ret
= apply_constraint(req
, PM_QOS_UPDATE_REQ
, new_value
);
403 * dev_pm_qos_update_request - modifies an existing qos request
404 * @req : handle to list element holding a dev_pm_qos request to use
405 * @new_value: defines the qos request
407 * Updates an existing dev PM qos request along with updating the
410 * Attempts are made to make this code callable on hot code paths.
412 * Returns 1 if the aggregated constraint value has changed,
413 * 0 if the aggregated constraint value has not changed,
414 * -EINVAL in case of wrong parameters, -ENODEV if the device has been
415 * removed from the system
417 * Callers should ensure that the target device is not RPM_SUSPENDED before
418 * using this function for requests of type DEV_PM_QOS_FLAGS.
420 int dev_pm_qos_update_request(struct dev_pm_qos_request
*req
, s32 new_value
)
424 mutex_lock(&dev_pm_qos_mtx
);
425 ret
= __dev_pm_qos_update_request(req
, new_value
);
426 mutex_unlock(&dev_pm_qos_mtx
);
429 EXPORT_SYMBOL_GPL(dev_pm_qos_update_request
);
431 static int __dev_pm_qos_remove_request(struct dev_pm_qos_request
*req
)
435 if (!req
) /*guard against callers passing in null */
438 if (WARN(!dev_pm_qos_request_active(req
),
439 "%s() called for unknown object\n", __func__
))
442 if (IS_ERR_OR_NULL(req
->dev
->power
.qos
))
445 trace_dev_pm_qos_remove_request(dev_name(req
->dev
), req
->type
,
446 PM_QOS_DEFAULT_VALUE
);
447 ret
= apply_constraint(req
, PM_QOS_REMOVE_REQ
, PM_QOS_DEFAULT_VALUE
);
448 memset(req
, 0, sizeof(*req
));
453 * dev_pm_qos_remove_request - modifies an existing qos request
454 * @req: handle to request list element
456 * Will remove pm qos request from the list of constraints and
457 * recompute the current target value. Call this on slow code paths.
459 * Returns 1 if the aggregated constraint value has changed,
460 * 0 if the aggregated constraint value has not changed,
461 * -EINVAL in case of wrong parameters, -ENODEV if the device has been
462 * removed from the system
464 * Callers should ensure that the target device is not RPM_SUSPENDED before
465 * using this function for requests of type DEV_PM_QOS_FLAGS.
467 int dev_pm_qos_remove_request(struct dev_pm_qos_request
*req
)
471 mutex_lock(&dev_pm_qos_mtx
);
472 ret
= __dev_pm_qos_remove_request(req
);
473 mutex_unlock(&dev_pm_qos_mtx
);
476 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_request
);
479 * dev_pm_qos_add_notifier - sets notification entry for changes to target value
480 * of per-device PM QoS constraints
482 * @dev: target device for the constraint
483 * @notifier: notifier block managed by caller.
485 * Will register the notifier into a notification chain that gets called
486 * upon changes to the target value for the device.
488 * If the device's constraints object doesn't exist when this routine is called,
489 * it will be created (or error code will be returned if that fails).
491 int dev_pm_qos_add_notifier(struct device
*dev
, struct notifier_block
*notifier
)
495 mutex_lock(&dev_pm_qos_mtx
);
497 if (IS_ERR(dev
->power
.qos
))
499 else if (!dev
->power
.qos
)
500 ret
= dev_pm_qos_constraints_allocate(dev
);
503 ret
= blocking_notifier_chain_register(dev
->power
.qos
->resume_latency
.notifiers
,
506 mutex_unlock(&dev_pm_qos_mtx
);
509 EXPORT_SYMBOL_GPL(dev_pm_qos_add_notifier
);
512 * dev_pm_qos_remove_notifier - deletes notification for changes to target value
513 * of per-device PM QoS constraints
515 * @dev: target device for the constraint
516 * @notifier: notifier block to be removed.
518 * Will remove the notifier from the notification chain that gets called
519 * upon changes to the target value.
521 int dev_pm_qos_remove_notifier(struct device
*dev
,
522 struct notifier_block
*notifier
)
526 mutex_lock(&dev_pm_qos_mtx
);
528 /* Silently return if the constraints object is not present. */
529 if (!IS_ERR_OR_NULL(dev
->power
.qos
))
530 retval
= blocking_notifier_chain_unregister(dev
->power
.qos
->resume_latency
.notifiers
,
533 mutex_unlock(&dev_pm_qos_mtx
);
536 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_notifier
);
539 * dev_pm_qos_add_global_notifier - sets notification entry for changes to
540 * target value of the PM QoS constraints for any device
542 * @notifier: notifier block managed by caller.
544 * Will register the notifier into a notification chain that gets called
545 * upon changes to the target value for any device.
547 int dev_pm_qos_add_global_notifier(struct notifier_block
*notifier
)
549 return blocking_notifier_chain_register(&dev_pm_notifiers
, notifier
);
551 EXPORT_SYMBOL_GPL(dev_pm_qos_add_global_notifier
);
554 * dev_pm_qos_remove_global_notifier - deletes notification for changes to
555 * target value of PM QoS constraints for any device
557 * @notifier: notifier block to be removed.
559 * Will remove the notifier from the notification chain that gets called
560 * upon changes to the target value for any device.
562 int dev_pm_qos_remove_global_notifier(struct notifier_block
*notifier
)
564 return blocking_notifier_chain_unregister(&dev_pm_notifiers
, notifier
);
566 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_global_notifier
);
569 * dev_pm_qos_add_ancestor_request - Add PM QoS request for device's ancestor.
570 * @dev: Device whose ancestor to add the request for.
571 * @req: Pointer to the preallocated handle.
572 * @type: Type of the request.
573 * @value: Constraint latency value.
575 int dev_pm_qos_add_ancestor_request(struct device
*dev
,
576 struct dev_pm_qos_request
*req
,
577 enum dev_pm_qos_req_type type
, s32 value
)
579 struct device
*ancestor
= dev
->parent
;
583 case DEV_PM_QOS_RESUME_LATENCY
:
584 while (ancestor
&& !ancestor
->power
.ignore_children
)
585 ancestor
= ancestor
->parent
;
588 case DEV_PM_QOS_LATENCY_TOLERANCE
:
589 while (ancestor
&& !ancestor
->power
.set_latency_tolerance
)
590 ancestor
= ancestor
->parent
;
597 ret
= dev_pm_qos_add_request(ancestor
, req
, type
, value
);
604 EXPORT_SYMBOL_GPL(dev_pm_qos_add_ancestor_request
);
606 static void __dev_pm_qos_drop_user_request(struct device
*dev
,
607 enum dev_pm_qos_req_type type
)
609 struct dev_pm_qos_request
*req
= NULL
;
612 case DEV_PM_QOS_RESUME_LATENCY
:
613 req
= dev
->power
.qos
->resume_latency_req
;
614 dev
->power
.qos
->resume_latency_req
= NULL
;
616 case DEV_PM_QOS_LATENCY_TOLERANCE
:
617 req
= dev
->power
.qos
->latency_tolerance_req
;
618 dev
->power
.qos
->latency_tolerance_req
= NULL
;
620 case DEV_PM_QOS_FLAGS
:
621 req
= dev
->power
.qos
->flags_req
;
622 dev
->power
.qos
->flags_req
= NULL
;
625 __dev_pm_qos_remove_request(req
);
629 static void dev_pm_qos_drop_user_request(struct device
*dev
,
630 enum dev_pm_qos_req_type type
)
632 mutex_lock(&dev_pm_qos_mtx
);
633 __dev_pm_qos_drop_user_request(dev
, type
);
634 mutex_unlock(&dev_pm_qos_mtx
);
638 * dev_pm_qos_expose_latency_limit - Expose PM QoS latency limit to user space.
639 * @dev: Device whose PM QoS latency limit is to be exposed to user space.
640 * @value: Initial value of the latency limit.
642 int dev_pm_qos_expose_latency_limit(struct device
*dev
, s32 value
)
644 struct dev_pm_qos_request
*req
;
647 if (!device_is_registered(dev
) || value
< 0)
650 req
= kzalloc(sizeof(*req
), GFP_KERNEL
);
654 ret
= dev_pm_qos_add_request(dev
, req
, DEV_PM_QOS_RESUME_LATENCY
, value
);
660 mutex_lock(&dev_pm_qos_sysfs_mtx
);
662 mutex_lock(&dev_pm_qos_mtx
);
664 if (IS_ERR_OR_NULL(dev
->power
.qos
))
666 else if (dev
->power
.qos
->resume_latency_req
)
670 __dev_pm_qos_remove_request(req
);
672 mutex_unlock(&dev_pm_qos_mtx
);
675 dev
->power
.qos
->resume_latency_req
= req
;
677 mutex_unlock(&dev_pm_qos_mtx
);
679 ret
= pm_qos_sysfs_add_resume_latency(dev
);
681 dev_pm_qos_drop_user_request(dev
, DEV_PM_QOS_RESUME_LATENCY
);
684 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
687 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_latency_limit
);
689 static void __dev_pm_qos_hide_latency_limit(struct device
*dev
)
691 if (!IS_ERR_OR_NULL(dev
->power
.qos
) && dev
->power
.qos
->resume_latency_req
)
692 __dev_pm_qos_drop_user_request(dev
, DEV_PM_QOS_RESUME_LATENCY
);
696 * dev_pm_qos_hide_latency_limit - Hide PM QoS latency limit from user space.
697 * @dev: Device whose PM QoS latency limit is to be hidden from user space.
699 void dev_pm_qos_hide_latency_limit(struct device
*dev
)
701 mutex_lock(&dev_pm_qos_sysfs_mtx
);
703 pm_qos_sysfs_remove_resume_latency(dev
);
705 mutex_lock(&dev_pm_qos_mtx
);
706 __dev_pm_qos_hide_latency_limit(dev
);
707 mutex_unlock(&dev_pm_qos_mtx
);
709 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
711 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_latency_limit
);
714 * dev_pm_qos_expose_flags - Expose PM QoS flags of a device to user space.
715 * @dev: Device whose PM QoS flags are to be exposed to user space.
716 * @val: Initial values of the flags.
718 int dev_pm_qos_expose_flags(struct device
*dev
, s32 val
)
720 struct dev_pm_qos_request
*req
;
723 if (!device_is_registered(dev
))
726 req
= kzalloc(sizeof(*req
), GFP_KERNEL
);
730 ret
= dev_pm_qos_add_request(dev
, req
, DEV_PM_QOS_FLAGS
, val
);
736 pm_runtime_get_sync(dev
);
737 mutex_lock(&dev_pm_qos_sysfs_mtx
);
739 mutex_lock(&dev_pm_qos_mtx
);
741 if (IS_ERR_OR_NULL(dev
->power
.qos
))
743 else if (dev
->power
.qos
->flags_req
)
747 __dev_pm_qos_remove_request(req
);
749 mutex_unlock(&dev_pm_qos_mtx
);
752 dev
->power
.qos
->flags_req
= req
;
754 mutex_unlock(&dev_pm_qos_mtx
);
756 ret
= pm_qos_sysfs_add_flags(dev
);
758 dev_pm_qos_drop_user_request(dev
, DEV_PM_QOS_FLAGS
);
761 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
765 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_flags
);
767 static void __dev_pm_qos_hide_flags(struct device
*dev
)
769 if (!IS_ERR_OR_NULL(dev
->power
.qos
) && dev
->power
.qos
->flags_req
)
770 __dev_pm_qos_drop_user_request(dev
, DEV_PM_QOS_FLAGS
);
774 * dev_pm_qos_hide_flags - Hide PM QoS flags of a device from user space.
775 * @dev: Device whose PM QoS flags are to be hidden from user space.
777 void dev_pm_qos_hide_flags(struct device
*dev
)
779 pm_runtime_get_sync(dev
);
780 mutex_lock(&dev_pm_qos_sysfs_mtx
);
782 pm_qos_sysfs_remove_flags(dev
);
784 mutex_lock(&dev_pm_qos_mtx
);
785 __dev_pm_qos_hide_flags(dev
);
786 mutex_unlock(&dev_pm_qos_mtx
);
788 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
791 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_flags
);
794 * dev_pm_qos_update_flags - Update PM QoS flags request owned by user space.
795 * @dev: Device to update the PM QoS flags request for.
796 * @mask: Flags to set/clear.
797 * @set: Whether to set or clear the flags (true means set).
799 int dev_pm_qos_update_flags(struct device
*dev
, s32 mask
, bool set
)
804 pm_runtime_get_sync(dev
);
805 mutex_lock(&dev_pm_qos_mtx
);
807 if (IS_ERR_OR_NULL(dev
->power
.qos
) || !dev
->power
.qos
->flags_req
) {
812 value
= dev_pm_qos_requested_flags(dev
);
818 ret
= __dev_pm_qos_update_request(dev
->power
.qos
->flags_req
, value
);
821 mutex_unlock(&dev_pm_qos_mtx
);
827 * dev_pm_qos_get_user_latency_tolerance - Get user space latency tolerance.
828 * @dev: Device to obtain the user space latency tolerance for.
830 s32
dev_pm_qos_get_user_latency_tolerance(struct device
*dev
)
834 mutex_lock(&dev_pm_qos_mtx
);
835 ret
= IS_ERR_OR_NULL(dev
->power
.qos
)
836 || !dev
->power
.qos
->latency_tolerance_req
?
837 PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT
:
838 dev
->power
.qos
->latency_tolerance_req
->data
.pnode
.prio
;
839 mutex_unlock(&dev_pm_qos_mtx
);
844 * dev_pm_qos_update_user_latency_tolerance - Update user space latency tolerance.
845 * @dev: Device to update the user space latency tolerance for.
846 * @val: New user space latency tolerance for @dev (negative values disable).
848 int dev_pm_qos_update_user_latency_tolerance(struct device
*dev
, s32 val
)
852 mutex_lock(&dev_pm_qos_mtx
);
854 if (IS_ERR_OR_NULL(dev
->power
.qos
)
855 || !dev
->power
.qos
->latency_tolerance_req
) {
856 struct dev_pm_qos_request
*req
;
862 req
= kzalloc(sizeof(*req
), GFP_KERNEL
);
867 ret
= __dev_pm_qos_add_request(dev
, req
, DEV_PM_QOS_LATENCY_TOLERANCE
, val
);
872 dev
->power
.qos
->latency_tolerance_req
= req
;
875 __dev_pm_qos_drop_user_request(dev
, DEV_PM_QOS_LATENCY_TOLERANCE
);
878 ret
= __dev_pm_qos_update_request(dev
->power
.qos
->latency_tolerance_req
, val
);
883 mutex_unlock(&dev_pm_qos_mtx
);