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 a per-device notification callback using the
21 * dev_pm_qos_*_notifier API. The notification chain data is stored in the
22 * per-device constraint data struct.
24 * Note about the per-device constraint data struct allocation:
25 * . The per-device constraints data struct ptr is tored into the device
27 * . To minimize the data usage by the per-device constraints, the data struct
28 * is only allocated at the first call to dev_pm_qos_add_request.
29 * . The data is later free'd when the device is removed from the system.
30 * . A global mutex protects the constraints users from the data being
31 * allocated and free'd.
34 #include <linux/pm_qos.h>
35 #include <linux/spinlock.h>
36 #include <linux/slab.h>
37 #include <linux/device.h>
38 #include <linux/mutex.h>
39 #include <linux/export.h>
40 #include <linux/pm_runtime.h>
41 #include <linux/err.h>
42 #include <trace/events/power.h>
46 static DEFINE_MUTEX(dev_pm_qos_mtx
);
47 static DEFINE_MUTEX(dev_pm_qos_sysfs_mtx
);
50 * __dev_pm_qos_flags - Check PM QoS flags for a given device.
51 * @dev: Device to check the PM QoS flags for.
52 * @mask: Flags to check against.
54 * This routine must be called with dev->power.lock held.
56 enum pm_qos_flags_status
__dev_pm_qos_flags(struct device
*dev
, s32 mask
)
58 struct dev_pm_qos
*qos
= dev
->power
.qos
;
59 struct pm_qos_flags
*pqf
;
62 lockdep_assert_held(&dev
->power
.lock
);
64 if (IS_ERR_OR_NULL(qos
))
65 return PM_QOS_FLAGS_UNDEFINED
;
68 if (list_empty(&pqf
->list
))
69 return PM_QOS_FLAGS_UNDEFINED
;
71 val
= pqf
->effective_flags
& mask
;
73 return (val
== mask
) ? PM_QOS_FLAGS_ALL
: PM_QOS_FLAGS_SOME
;
75 return PM_QOS_FLAGS_NONE
;
79 * dev_pm_qos_flags - Check PM QoS flags for a given device (locked).
80 * @dev: Device to check the PM QoS flags for.
81 * @mask: Flags to check against.
83 enum pm_qos_flags_status
dev_pm_qos_flags(struct device
*dev
, s32 mask
)
85 unsigned long irqflags
;
86 enum pm_qos_flags_status ret
;
88 spin_lock_irqsave(&dev
->power
.lock
, irqflags
);
89 ret
= __dev_pm_qos_flags(dev
, mask
);
90 spin_unlock_irqrestore(&dev
->power
.lock
, irqflags
);
94 EXPORT_SYMBOL_GPL(dev_pm_qos_flags
);
97 * __dev_pm_qos_read_value - Get PM QoS constraint for a given device.
98 * @dev: Device to get the PM QoS constraint value for.
100 * This routine must be called with dev->power.lock held.
102 s32
__dev_pm_qos_read_value(struct device
*dev
)
104 lockdep_assert_held(&dev
->power
.lock
);
106 return dev_pm_qos_raw_read_value(dev
);
110 * dev_pm_qos_read_value - Get PM QoS constraint for a given device (locked).
111 * @dev: Device to get the PM QoS constraint value for.
113 s32
dev_pm_qos_read_value(struct device
*dev
)
118 spin_lock_irqsave(&dev
->power
.lock
, flags
);
119 ret
= __dev_pm_qos_read_value(dev
);
120 spin_unlock_irqrestore(&dev
->power
.lock
, flags
);
126 * apply_constraint - Add/modify/remove device PM QoS request.
127 * @req: Constraint request to apply
128 * @action: Action to perform (add/update/remove).
129 * @value: Value to assign to the QoS request.
131 * Internal function to update the constraints list using the PM QoS core
132 * code and if needed call the per-device callbacks.
134 static int apply_constraint(struct dev_pm_qos_request
*req
,
135 enum pm_qos_req_action action
, s32 value
)
137 struct dev_pm_qos
*qos
= req
->dev
->power
.qos
;
141 case DEV_PM_QOS_RESUME_LATENCY
:
142 if (WARN_ON(action
!= PM_QOS_REMOVE_REQ
&& value
< 0))
145 ret
= pm_qos_update_target(&qos
->resume_latency
,
146 &req
->data
.pnode
, action
, value
);
148 case DEV_PM_QOS_LATENCY_TOLERANCE
:
149 ret
= pm_qos_update_target(&qos
->latency_tolerance
,
150 &req
->data
.pnode
, action
, value
);
152 value
= pm_qos_read_value(&qos
->latency_tolerance
);
153 req
->dev
->power
.set_latency_tolerance(req
->dev
, value
);
156 case DEV_PM_QOS_FLAGS
:
157 ret
= pm_qos_update_flags(&qos
->flags
, &req
->data
.flr
,
168 * dev_pm_qos_constraints_allocate
169 * @dev: device to allocate data for
171 * Called at the first call to add_request, for constraint data allocation
172 * Must be called with the dev_pm_qos_mtx mutex held
174 static int dev_pm_qos_constraints_allocate(struct device
*dev
)
176 struct dev_pm_qos
*qos
;
177 struct pm_qos_constraints
*c
;
178 struct blocking_notifier_head
*n
;
180 qos
= kzalloc(sizeof(*qos
), GFP_KERNEL
);
184 n
= kzalloc(sizeof(*n
), GFP_KERNEL
);
189 BLOCKING_INIT_NOTIFIER_HEAD(n
);
191 c
= &qos
->resume_latency
;
192 plist_head_init(&c
->list
);
193 c
->target_value
= PM_QOS_RESUME_LATENCY_DEFAULT_VALUE
;
194 c
->default_value
= PM_QOS_RESUME_LATENCY_DEFAULT_VALUE
;
195 c
->no_constraint_value
= PM_QOS_RESUME_LATENCY_NO_CONSTRAINT
;
196 c
->type
= PM_QOS_MIN
;
199 c
= &qos
->latency_tolerance
;
200 plist_head_init(&c
->list
);
201 c
->target_value
= PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE
;
202 c
->default_value
= PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE
;
203 c
->no_constraint_value
= PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT
;
204 c
->type
= PM_QOS_MIN
;
206 INIT_LIST_HEAD(&qos
->flags
.list
);
208 spin_lock_irq(&dev
->power
.lock
);
209 dev
->power
.qos
= qos
;
210 spin_unlock_irq(&dev
->power
.lock
);
215 static void __dev_pm_qos_hide_latency_limit(struct device
*dev
);
216 static void __dev_pm_qos_hide_flags(struct device
*dev
);
219 * dev_pm_qos_constraints_destroy
220 * @dev: target device
222 * Called from the device PM subsystem on device removal under device_pm_lock().
224 void dev_pm_qos_constraints_destroy(struct device
*dev
)
226 struct dev_pm_qos
*qos
;
227 struct dev_pm_qos_request
*req
, *tmp
;
228 struct pm_qos_constraints
*c
;
229 struct pm_qos_flags
*f
;
231 mutex_lock(&dev_pm_qos_sysfs_mtx
);
234 * If the device's PM QoS resume latency limit or PM QoS flags have been
235 * exposed to user space, they have to be hidden at this point.
237 pm_qos_sysfs_remove_resume_latency(dev
);
238 pm_qos_sysfs_remove_flags(dev
);
240 mutex_lock(&dev_pm_qos_mtx
);
242 __dev_pm_qos_hide_latency_limit(dev
);
243 __dev_pm_qos_hide_flags(dev
);
245 qos
= dev
->power
.qos
;
249 /* Flush the constraints lists for the device. */
250 c
= &qos
->resume_latency
;
251 plist_for_each_entry_safe(req
, tmp
, &c
->list
, data
.pnode
) {
253 * Update constraints list and call the notification
254 * callbacks if needed
256 apply_constraint(req
, PM_QOS_REMOVE_REQ
, PM_QOS_DEFAULT_VALUE
);
257 memset(req
, 0, sizeof(*req
));
259 c
= &qos
->latency_tolerance
;
260 plist_for_each_entry_safe(req
, tmp
, &c
->list
, data
.pnode
) {
261 apply_constraint(req
, PM_QOS_REMOVE_REQ
, PM_QOS_DEFAULT_VALUE
);
262 memset(req
, 0, sizeof(*req
));
265 list_for_each_entry_safe(req
, tmp
, &f
->list
, data
.flr
.node
) {
266 apply_constraint(req
, PM_QOS_REMOVE_REQ
, PM_QOS_DEFAULT_VALUE
);
267 memset(req
, 0, sizeof(*req
));
270 spin_lock_irq(&dev
->power
.lock
);
271 dev
->power
.qos
= ERR_PTR(-ENODEV
);
272 spin_unlock_irq(&dev
->power
.lock
);
274 kfree(qos
->resume_latency
.notifiers
);
278 mutex_unlock(&dev_pm_qos_mtx
);
280 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
283 static bool dev_pm_qos_invalid_req_type(struct device
*dev
,
284 enum dev_pm_qos_req_type type
)
286 return type
== DEV_PM_QOS_LATENCY_TOLERANCE
&&
287 !dev
->power
.set_latency_tolerance
;
290 static int __dev_pm_qos_add_request(struct device
*dev
,
291 struct dev_pm_qos_request
*req
,
292 enum dev_pm_qos_req_type type
, s32 value
)
296 if (!dev
|| !req
|| dev_pm_qos_invalid_req_type(dev
, type
))
299 if (WARN(dev_pm_qos_request_active(req
),
300 "%s() called for already added request\n", __func__
))
303 if (IS_ERR(dev
->power
.qos
))
305 else if (!dev
->power
.qos
)
306 ret
= dev_pm_qos_constraints_allocate(dev
);
308 trace_dev_pm_qos_add_request(dev_name(dev
), type
, value
);
312 ret
= apply_constraint(req
, PM_QOS_ADD_REQ
, value
);
318 * dev_pm_qos_add_request - inserts new qos request into the list
319 * @dev: target device for the constraint
320 * @req: pointer to a preallocated handle
321 * @type: type of the request
322 * @value: defines the qos request
324 * This function inserts a new entry in the device constraints list of
325 * requested qos performance characteristics. It recomputes the aggregate
326 * QoS expectations of parameters and initializes the dev_pm_qos_request
327 * handle. Caller needs to save this handle for later use in updates and
330 * Returns 1 if the aggregated constraint value has changed,
331 * 0 if the aggregated constraint value has not changed,
332 * -EINVAL in case of wrong parameters, -ENOMEM if there's not enough memory
333 * to allocate for data structures, -ENODEV if the device has just been removed
336 * Callers should ensure that the target device is not RPM_SUSPENDED before
337 * using this function for requests of type DEV_PM_QOS_FLAGS.
339 int dev_pm_qos_add_request(struct device
*dev
, struct dev_pm_qos_request
*req
,
340 enum dev_pm_qos_req_type type
, s32 value
)
344 mutex_lock(&dev_pm_qos_mtx
);
345 ret
= __dev_pm_qos_add_request(dev
, req
, type
, value
);
346 mutex_unlock(&dev_pm_qos_mtx
);
349 EXPORT_SYMBOL_GPL(dev_pm_qos_add_request
);
352 * __dev_pm_qos_update_request - Modify an existing device PM QoS request.
353 * @req : PM QoS request to modify.
354 * @new_value: New value to request.
356 static int __dev_pm_qos_update_request(struct dev_pm_qos_request
*req
,
362 if (!req
) /*guard against callers passing in null */
365 if (WARN(!dev_pm_qos_request_active(req
),
366 "%s() called for unknown object\n", __func__
))
369 if (IS_ERR_OR_NULL(req
->dev
->power
.qos
))
373 case DEV_PM_QOS_RESUME_LATENCY
:
374 case DEV_PM_QOS_LATENCY_TOLERANCE
:
375 curr_value
= req
->data
.pnode
.prio
;
377 case DEV_PM_QOS_FLAGS
:
378 curr_value
= req
->data
.flr
.flags
;
384 trace_dev_pm_qos_update_request(dev_name(req
->dev
), req
->type
,
386 if (curr_value
!= new_value
)
387 ret
= apply_constraint(req
, PM_QOS_UPDATE_REQ
, new_value
);
393 * dev_pm_qos_update_request - modifies an existing qos request
394 * @req : handle to list element holding a dev_pm_qos request to use
395 * @new_value: defines the qos request
397 * Updates an existing dev PM qos request along with updating the
400 * Attempts are made to make this code callable on hot code paths.
402 * Returns 1 if the aggregated constraint value has changed,
403 * 0 if the aggregated constraint value has not changed,
404 * -EINVAL in case of wrong parameters, -ENODEV if the device has been
405 * removed from the system
407 * Callers should ensure that the target device is not RPM_SUSPENDED before
408 * using this function for requests of type DEV_PM_QOS_FLAGS.
410 int dev_pm_qos_update_request(struct dev_pm_qos_request
*req
, s32 new_value
)
414 mutex_lock(&dev_pm_qos_mtx
);
415 ret
= __dev_pm_qos_update_request(req
, new_value
);
416 mutex_unlock(&dev_pm_qos_mtx
);
419 EXPORT_SYMBOL_GPL(dev_pm_qos_update_request
);
421 static int __dev_pm_qos_remove_request(struct dev_pm_qos_request
*req
)
425 if (!req
) /*guard against callers passing in null */
428 if (WARN(!dev_pm_qos_request_active(req
),
429 "%s() called for unknown object\n", __func__
))
432 if (IS_ERR_OR_NULL(req
->dev
->power
.qos
))
435 trace_dev_pm_qos_remove_request(dev_name(req
->dev
), req
->type
,
436 PM_QOS_DEFAULT_VALUE
);
437 ret
= apply_constraint(req
, PM_QOS_REMOVE_REQ
, PM_QOS_DEFAULT_VALUE
);
438 memset(req
, 0, sizeof(*req
));
443 * dev_pm_qos_remove_request - modifies an existing qos request
444 * @req: handle to request list element
446 * Will remove pm qos request from the list of constraints and
447 * recompute the current target value. Call this on slow code paths.
449 * Returns 1 if the aggregated constraint value has changed,
450 * 0 if the aggregated constraint value has not changed,
451 * -EINVAL in case of wrong parameters, -ENODEV if the device has been
452 * removed from the system
454 * Callers should ensure that the target device is not RPM_SUSPENDED before
455 * using this function for requests of type DEV_PM_QOS_FLAGS.
457 int dev_pm_qos_remove_request(struct dev_pm_qos_request
*req
)
461 mutex_lock(&dev_pm_qos_mtx
);
462 ret
= __dev_pm_qos_remove_request(req
);
463 mutex_unlock(&dev_pm_qos_mtx
);
466 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_request
);
469 * dev_pm_qos_add_notifier - sets notification entry for changes to target value
470 * of per-device PM QoS constraints
472 * @dev: target device for the constraint
473 * @notifier: notifier block managed by caller.
475 * Will register the notifier into a notification chain that gets called
476 * upon changes to the target value for the device.
478 * If the device's constraints object doesn't exist when this routine is called,
479 * it will be created (or error code will be returned if that fails).
481 int dev_pm_qos_add_notifier(struct device
*dev
, struct notifier_block
*notifier
)
485 mutex_lock(&dev_pm_qos_mtx
);
487 if (IS_ERR(dev
->power
.qos
))
489 else if (!dev
->power
.qos
)
490 ret
= dev_pm_qos_constraints_allocate(dev
);
493 ret
= blocking_notifier_chain_register(dev
->power
.qos
->resume_latency
.notifiers
,
496 mutex_unlock(&dev_pm_qos_mtx
);
499 EXPORT_SYMBOL_GPL(dev_pm_qos_add_notifier
);
502 * dev_pm_qos_remove_notifier - deletes notification for changes to target value
503 * of per-device PM QoS constraints
505 * @dev: target device for the constraint
506 * @notifier: notifier block to be removed.
508 * Will remove the notifier from the notification chain that gets called
509 * upon changes to the target value.
511 int dev_pm_qos_remove_notifier(struct device
*dev
,
512 struct notifier_block
*notifier
)
516 mutex_lock(&dev_pm_qos_mtx
);
518 /* Silently return if the constraints object is not present. */
519 if (!IS_ERR_OR_NULL(dev
->power
.qos
))
520 retval
= blocking_notifier_chain_unregister(dev
->power
.qos
->resume_latency
.notifiers
,
523 mutex_unlock(&dev_pm_qos_mtx
);
526 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_notifier
);
529 * dev_pm_qos_add_ancestor_request - Add PM QoS request for device's ancestor.
530 * @dev: Device whose ancestor to add the request for.
531 * @req: Pointer to the preallocated handle.
532 * @type: Type of the request.
533 * @value: Constraint latency value.
535 int dev_pm_qos_add_ancestor_request(struct device
*dev
,
536 struct dev_pm_qos_request
*req
,
537 enum dev_pm_qos_req_type type
, s32 value
)
539 struct device
*ancestor
= dev
->parent
;
543 case DEV_PM_QOS_RESUME_LATENCY
:
544 while (ancestor
&& !ancestor
->power
.ignore_children
)
545 ancestor
= ancestor
->parent
;
548 case DEV_PM_QOS_LATENCY_TOLERANCE
:
549 while (ancestor
&& !ancestor
->power
.set_latency_tolerance
)
550 ancestor
= ancestor
->parent
;
557 ret
= dev_pm_qos_add_request(ancestor
, req
, type
, value
);
564 EXPORT_SYMBOL_GPL(dev_pm_qos_add_ancestor_request
);
566 static void __dev_pm_qos_drop_user_request(struct device
*dev
,
567 enum dev_pm_qos_req_type type
)
569 struct dev_pm_qos_request
*req
= NULL
;
572 case DEV_PM_QOS_RESUME_LATENCY
:
573 req
= dev
->power
.qos
->resume_latency_req
;
574 dev
->power
.qos
->resume_latency_req
= NULL
;
576 case DEV_PM_QOS_LATENCY_TOLERANCE
:
577 req
= dev
->power
.qos
->latency_tolerance_req
;
578 dev
->power
.qos
->latency_tolerance_req
= NULL
;
580 case DEV_PM_QOS_FLAGS
:
581 req
= dev
->power
.qos
->flags_req
;
582 dev
->power
.qos
->flags_req
= NULL
;
585 __dev_pm_qos_remove_request(req
);
589 static void dev_pm_qos_drop_user_request(struct device
*dev
,
590 enum dev_pm_qos_req_type type
)
592 mutex_lock(&dev_pm_qos_mtx
);
593 __dev_pm_qos_drop_user_request(dev
, type
);
594 mutex_unlock(&dev_pm_qos_mtx
);
598 * dev_pm_qos_expose_latency_limit - Expose PM QoS latency limit to user space.
599 * @dev: Device whose PM QoS latency limit is to be exposed to user space.
600 * @value: Initial value of the latency limit.
602 int dev_pm_qos_expose_latency_limit(struct device
*dev
, s32 value
)
604 struct dev_pm_qos_request
*req
;
607 if (!device_is_registered(dev
) || value
< 0)
610 req
= kzalloc(sizeof(*req
), GFP_KERNEL
);
614 ret
= dev_pm_qos_add_request(dev
, req
, DEV_PM_QOS_RESUME_LATENCY
, value
);
620 mutex_lock(&dev_pm_qos_sysfs_mtx
);
622 mutex_lock(&dev_pm_qos_mtx
);
624 if (IS_ERR_OR_NULL(dev
->power
.qos
))
626 else if (dev
->power
.qos
->resume_latency_req
)
630 __dev_pm_qos_remove_request(req
);
632 mutex_unlock(&dev_pm_qos_mtx
);
635 dev
->power
.qos
->resume_latency_req
= req
;
637 mutex_unlock(&dev_pm_qos_mtx
);
639 ret
= pm_qos_sysfs_add_resume_latency(dev
);
641 dev_pm_qos_drop_user_request(dev
, DEV_PM_QOS_RESUME_LATENCY
);
644 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
647 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_latency_limit
);
649 static void __dev_pm_qos_hide_latency_limit(struct device
*dev
)
651 if (!IS_ERR_OR_NULL(dev
->power
.qos
) && dev
->power
.qos
->resume_latency_req
)
652 __dev_pm_qos_drop_user_request(dev
, DEV_PM_QOS_RESUME_LATENCY
);
656 * dev_pm_qos_hide_latency_limit - Hide PM QoS latency limit from user space.
657 * @dev: Device whose PM QoS latency limit is to be hidden from user space.
659 void dev_pm_qos_hide_latency_limit(struct device
*dev
)
661 mutex_lock(&dev_pm_qos_sysfs_mtx
);
663 pm_qos_sysfs_remove_resume_latency(dev
);
665 mutex_lock(&dev_pm_qos_mtx
);
666 __dev_pm_qos_hide_latency_limit(dev
);
667 mutex_unlock(&dev_pm_qos_mtx
);
669 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
671 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_latency_limit
);
674 * dev_pm_qos_expose_flags - Expose PM QoS flags of a device to user space.
675 * @dev: Device whose PM QoS flags are to be exposed to user space.
676 * @val: Initial values of the flags.
678 int dev_pm_qos_expose_flags(struct device
*dev
, s32 val
)
680 struct dev_pm_qos_request
*req
;
683 if (!device_is_registered(dev
))
686 req
= kzalloc(sizeof(*req
), GFP_KERNEL
);
690 ret
= dev_pm_qos_add_request(dev
, req
, DEV_PM_QOS_FLAGS
, val
);
696 pm_runtime_get_sync(dev
);
697 mutex_lock(&dev_pm_qos_sysfs_mtx
);
699 mutex_lock(&dev_pm_qos_mtx
);
701 if (IS_ERR_OR_NULL(dev
->power
.qos
))
703 else if (dev
->power
.qos
->flags_req
)
707 __dev_pm_qos_remove_request(req
);
709 mutex_unlock(&dev_pm_qos_mtx
);
712 dev
->power
.qos
->flags_req
= req
;
714 mutex_unlock(&dev_pm_qos_mtx
);
716 ret
= pm_qos_sysfs_add_flags(dev
);
718 dev_pm_qos_drop_user_request(dev
, DEV_PM_QOS_FLAGS
);
721 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
725 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_flags
);
727 static void __dev_pm_qos_hide_flags(struct device
*dev
)
729 if (!IS_ERR_OR_NULL(dev
->power
.qos
) && dev
->power
.qos
->flags_req
)
730 __dev_pm_qos_drop_user_request(dev
, DEV_PM_QOS_FLAGS
);
734 * dev_pm_qos_hide_flags - Hide PM QoS flags of a device from user space.
735 * @dev: Device whose PM QoS flags are to be hidden from user space.
737 void dev_pm_qos_hide_flags(struct device
*dev
)
739 pm_runtime_get_sync(dev
);
740 mutex_lock(&dev_pm_qos_sysfs_mtx
);
742 pm_qos_sysfs_remove_flags(dev
);
744 mutex_lock(&dev_pm_qos_mtx
);
745 __dev_pm_qos_hide_flags(dev
);
746 mutex_unlock(&dev_pm_qos_mtx
);
748 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
751 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_flags
);
754 * dev_pm_qos_update_flags - Update PM QoS flags request owned by user space.
755 * @dev: Device to update the PM QoS flags request for.
756 * @mask: Flags to set/clear.
757 * @set: Whether to set or clear the flags (true means set).
759 int dev_pm_qos_update_flags(struct device
*dev
, s32 mask
, bool set
)
764 pm_runtime_get_sync(dev
);
765 mutex_lock(&dev_pm_qos_mtx
);
767 if (IS_ERR_OR_NULL(dev
->power
.qos
) || !dev
->power
.qos
->flags_req
) {
772 value
= dev_pm_qos_requested_flags(dev
);
778 ret
= __dev_pm_qos_update_request(dev
->power
.qos
->flags_req
, value
);
781 mutex_unlock(&dev_pm_qos_mtx
);
787 * dev_pm_qos_get_user_latency_tolerance - Get user space latency tolerance.
788 * @dev: Device to obtain the user space latency tolerance for.
790 s32
dev_pm_qos_get_user_latency_tolerance(struct device
*dev
)
794 mutex_lock(&dev_pm_qos_mtx
);
795 ret
= IS_ERR_OR_NULL(dev
->power
.qos
)
796 || !dev
->power
.qos
->latency_tolerance_req
?
797 PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT
:
798 dev
->power
.qos
->latency_tolerance_req
->data
.pnode
.prio
;
799 mutex_unlock(&dev_pm_qos_mtx
);
804 * dev_pm_qos_update_user_latency_tolerance - Update user space latency tolerance.
805 * @dev: Device to update the user space latency tolerance for.
806 * @val: New user space latency tolerance for @dev (negative values disable).
808 int dev_pm_qos_update_user_latency_tolerance(struct device
*dev
, s32 val
)
812 mutex_lock(&dev_pm_qos_mtx
);
814 if (IS_ERR_OR_NULL(dev
->power
.qos
)
815 || !dev
->power
.qos
->latency_tolerance_req
) {
816 struct dev_pm_qos_request
*req
;
819 if (val
== PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT
)
825 req
= kzalloc(sizeof(*req
), GFP_KERNEL
);
830 ret
= __dev_pm_qos_add_request(dev
, req
, DEV_PM_QOS_LATENCY_TOLERANCE
, val
);
835 dev
->power
.qos
->latency_tolerance_req
= req
;
838 __dev_pm_qos_drop_user_request(dev
, DEV_PM_QOS_LATENCY_TOLERANCE
);
841 ret
= __dev_pm_qos_update_request(dev
->power
.qos
->latency_tolerance_req
, val
);
846 mutex_unlock(&dev_pm_qos_mtx
);
849 EXPORT_SYMBOL_GPL(dev_pm_qos_update_user_latency_tolerance
);
852 * dev_pm_qos_expose_latency_tolerance - Expose latency tolerance to userspace
853 * @dev: Device whose latency tolerance to expose
855 int dev_pm_qos_expose_latency_tolerance(struct device
*dev
)
859 if (!dev
->power
.set_latency_tolerance
)
862 mutex_lock(&dev_pm_qos_sysfs_mtx
);
863 ret
= pm_qos_sysfs_add_latency_tolerance(dev
);
864 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
868 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_latency_tolerance
);
871 * dev_pm_qos_hide_latency_tolerance - Hide latency tolerance from userspace
872 * @dev: Device whose latency tolerance to hide
874 void dev_pm_qos_hide_latency_tolerance(struct device
*dev
)
876 mutex_lock(&dev_pm_qos_sysfs_mtx
);
877 pm_qos_sysfs_remove_latency_tolerance(dev
);
878 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
880 /* Remove the request from user space now */
881 pm_runtime_get_sync(dev
);
882 dev_pm_qos_update_user_latency_tolerance(dev
,
883 PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT
);
886 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_latency_tolerance
);