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 ret
= pm_qos_update_target(&qos
->resume_latency
,
143 &req
->data
.pnode
, action
, value
);
145 case DEV_PM_QOS_LATENCY_TOLERANCE
:
146 ret
= pm_qos_update_target(&qos
->latency_tolerance
,
147 &req
->data
.pnode
, action
, value
);
149 value
= pm_qos_read_value(&qos
->latency_tolerance
);
150 req
->dev
->power
.set_latency_tolerance(req
->dev
, value
);
153 case DEV_PM_QOS_FLAGS
:
154 ret
= pm_qos_update_flags(&qos
->flags
, &req
->data
.flr
,
165 * dev_pm_qos_constraints_allocate
166 * @dev: device to allocate data for
168 * Called at the first call to add_request, for constraint data allocation
169 * Must be called with the dev_pm_qos_mtx mutex held
171 static int dev_pm_qos_constraints_allocate(struct device
*dev
)
173 struct dev_pm_qos
*qos
;
174 struct pm_qos_constraints
*c
;
175 struct blocking_notifier_head
*n
;
177 qos
= kzalloc(sizeof(*qos
), GFP_KERNEL
);
181 n
= kzalloc(sizeof(*n
), GFP_KERNEL
);
186 BLOCKING_INIT_NOTIFIER_HEAD(n
);
188 c
= &qos
->resume_latency
;
189 plist_head_init(&c
->list
);
190 c
->target_value
= PM_QOS_RESUME_LATENCY_DEFAULT_VALUE
;
191 c
->default_value
= PM_QOS_RESUME_LATENCY_DEFAULT_VALUE
;
192 c
->no_constraint_value
= PM_QOS_RESUME_LATENCY_DEFAULT_VALUE
;
193 c
->type
= PM_QOS_MIN
;
196 c
= &qos
->latency_tolerance
;
197 plist_head_init(&c
->list
);
198 c
->target_value
= PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE
;
199 c
->default_value
= PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE
;
200 c
->no_constraint_value
= PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT
;
201 c
->type
= PM_QOS_MIN
;
203 INIT_LIST_HEAD(&qos
->flags
.list
);
205 spin_lock_irq(&dev
->power
.lock
);
206 dev
->power
.qos
= qos
;
207 spin_unlock_irq(&dev
->power
.lock
);
212 static void __dev_pm_qos_hide_latency_limit(struct device
*dev
);
213 static void __dev_pm_qos_hide_flags(struct device
*dev
);
216 * dev_pm_qos_constraints_destroy
217 * @dev: target device
219 * Called from the device PM subsystem on device removal under device_pm_lock().
221 void dev_pm_qos_constraints_destroy(struct device
*dev
)
223 struct dev_pm_qos
*qos
;
224 struct dev_pm_qos_request
*req
, *tmp
;
225 struct pm_qos_constraints
*c
;
226 struct pm_qos_flags
*f
;
228 mutex_lock(&dev_pm_qos_sysfs_mtx
);
231 * If the device's PM QoS resume latency limit or PM QoS flags have been
232 * exposed to user space, they have to be hidden at this point.
234 pm_qos_sysfs_remove_resume_latency(dev
);
235 pm_qos_sysfs_remove_flags(dev
);
237 mutex_lock(&dev_pm_qos_mtx
);
239 __dev_pm_qos_hide_latency_limit(dev
);
240 __dev_pm_qos_hide_flags(dev
);
242 qos
= dev
->power
.qos
;
246 /* Flush the constraints lists for the device. */
247 c
= &qos
->resume_latency
;
248 plist_for_each_entry_safe(req
, tmp
, &c
->list
, data
.pnode
) {
250 * Update constraints list and call the notification
251 * callbacks if needed
253 apply_constraint(req
, PM_QOS_REMOVE_REQ
, PM_QOS_DEFAULT_VALUE
);
254 memset(req
, 0, sizeof(*req
));
256 c
= &qos
->latency_tolerance
;
257 plist_for_each_entry_safe(req
, tmp
, &c
->list
, data
.pnode
) {
258 apply_constraint(req
, PM_QOS_REMOVE_REQ
, PM_QOS_DEFAULT_VALUE
);
259 memset(req
, 0, sizeof(*req
));
262 list_for_each_entry_safe(req
, tmp
, &f
->list
, data
.flr
.node
) {
263 apply_constraint(req
, PM_QOS_REMOVE_REQ
, PM_QOS_DEFAULT_VALUE
);
264 memset(req
, 0, sizeof(*req
));
267 spin_lock_irq(&dev
->power
.lock
);
268 dev
->power
.qos
= ERR_PTR(-ENODEV
);
269 spin_unlock_irq(&dev
->power
.lock
);
271 kfree(qos
->resume_latency
.notifiers
);
275 mutex_unlock(&dev_pm_qos_mtx
);
277 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
280 static bool dev_pm_qos_invalid_request(struct device
*dev
,
281 struct dev_pm_qos_request
*req
)
283 return !req
|| (req
->type
== DEV_PM_QOS_LATENCY_TOLERANCE
284 && !dev
->power
.set_latency_tolerance
);
287 static int __dev_pm_qos_add_request(struct device
*dev
,
288 struct dev_pm_qos_request
*req
,
289 enum dev_pm_qos_req_type type
, s32 value
)
293 if (!dev
|| dev_pm_qos_invalid_request(dev
, req
))
296 if (WARN(dev_pm_qos_request_active(req
),
297 "%s() called for already added request\n", __func__
))
300 if (IS_ERR(dev
->power
.qos
))
302 else if (!dev
->power
.qos
)
303 ret
= dev_pm_qos_constraints_allocate(dev
);
305 trace_dev_pm_qos_add_request(dev_name(dev
), type
, value
);
309 ret
= apply_constraint(req
, PM_QOS_ADD_REQ
, value
);
315 * dev_pm_qos_add_request - inserts new qos request into the list
316 * @dev: target device for the constraint
317 * @req: pointer to a preallocated handle
318 * @type: type of the request
319 * @value: defines the qos request
321 * This function inserts a new entry in the device constraints list of
322 * requested qos performance characteristics. It recomputes the aggregate
323 * QoS expectations of parameters and initializes the dev_pm_qos_request
324 * handle. Caller needs to save this handle for later use in updates and
327 * Returns 1 if the aggregated constraint value has changed,
328 * 0 if the aggregated constraint value has not changed,
329 * -EINVAL in case of wrong parameters, -ENOMEM if there's not enough memory
330 * to allocate for data structures, -ENODEV if the device has just been removed
333 * Callers should ensure that the target device is not RPM_SUSPENDED before
334 * using this function for requests of type DEV_PM_QOS_FLAGS.
336 int dev_pm_qos_add_request(struct device
*dev
, struct dev_pm_qos_request
*req
,
337 enum dev_pm_qos_req_type type
, s32 value
)
341 mutex_lock(&dev_pm_qos_mtx
);
342 ret
= __dev_pm_qos_add_request(dev
, req
, type
, value
);
343 mutex_unlock(&dev_pm_qos_mtx
);
346 EXPORT_SYMBOL_GPL(dev_pm_qos_add_request
);
349 * __dev_pm_qos_update_request - Modify an existing device PM QoS request.
350 * @req : PM QoS request to modify.
351 * @new_value: New value to request.
353 static int __dev_pm_qos_update_request(struct dev_pm_qos_request
*req
,
359 if (!req
) /*guard against callers passing in null */
362 if (WARN(!dev_pm_qos_request_active(req
),
363 "%s() called for unknown object\n", __func__
))
366 if (IS_ERR_OR_NULL(req
->dev
->power
.qos
))
370 case DEV_PM_QOS_RESUME_LATENCY
:
371 case DEV_PM_QOS_LATENCY_TOLERANCE
:
372 curr_value
= req
->data
.pnode
.prio
;
374 case DEV_PM_QOS_FLAGS
:
375 curr_value
= req
->data
.flr
.flags
;
381 trace_dev_pm_qos_update_request(dev_name(req
->dev
), req
->type
,
383 if (curr_value
!= new_value
)
384 ret
= apply_constraint(req
, PM_QOS_UPDATE_REQ
, new_value
);
390 * dev_pm_qos_update_request - modifies an existing qos request
391 * @req : handle to list element holding a dev_pm_qos request to use
392 * @new_value: defines the qos request
394 * Updates an existing dev PM qos request along with updating the
397 * Attempts are made to make this code callable on hot code paths.
399 * Returns 1 if the aggregated constraint value has changed,
400 * 0 if the aggregated constraint value has not changed,
401 * -EINVAL in case of wrong parameters, -ENODEV if the device has been
402 * removed from the system
404 * Callers should ensure that the target device is not RPM_SUSPENDED before
405 * using this function for requests of type DEV_PM_QOS_FLAGS.
407 int dev_pm_qos_update_request(struct dev_pm_qos_request
*req
, s32 new_value
)
411 mutex_lock(&dev_pm_qos_mtx
);
412 ret
= __dev_pm_qos_update_request(req
, new_value
);
413 mutex_unlock(&dev_pm_qos_mtx
);
416 EXPORT_SYMBOL_GPL(dev_pm_qos_update_request
);
418 static int __dev_pm_qos_remove_request(struct dev_pm_qos_request
*req
)
422 if (!req
) /*guard against callers passing in null */
425 if (WARN(!dev_pm_qos_request_active(req
),
426 "%s() called for unknown object\n", __func__
))
429 if (IS_ERR_OR_NULL(req
->dev
->power
.qos
))
432 trace_dev_pm_qos_remove_request(dev_name(req
->dev
), req
->type
,
433 PM_QOS_DEFAULT_VALUE
);
434 ret
= apply_constraint(req
, PM_QOS_REMOVE_REQ
, PM_QOS_DEFAULT_VALUE
);
435 memset(req
, 0, sizeof(*req
));
440 * dev_pm_qos_remove_request - modifies an existing qos request
441 * @req: handle to request list element
443 * Will remove pm qos request from the list of constraints and
444 * recompute the current target value. Call this on slow code paths.
446 * Returns 1 if the aggregated constraint value has changed,
447 * 0 if the aggregated constraint value has not changed,
448 * -EINVAL in case of wrong parameters, -ENODEV if the device has been
449 * removed from the system
451 * Callers should ensure that the target device is not RPM_SUSPENDED before
452 * using this function for requests of type DEV_PM_QOS_FLAGS.
454 int dev_pm_qos_remove_request(struct dev_pm_qos_request
*req
)
458 mutex_lock(&dev_pm_qos_mtx
);
459 ret
= __dev_pm_qos_remove_request(req
);
460 mutex_unlock(&dev_pm_qos_mtx
);
463 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_request
);
466 * dev_pm_qos_add_notifier - sets notification entry for changes to target value
467 * of per-device PM QoS constraints
469 * @dev: target device for the constraint
470 * @notifier: notifier block managed by caller.
472 * Will register the notifier into a notification chain that gets called
473 * upon changes to the target value for the device.
475 * If the device's constraints object doesn't exist when this routine is called,
476 * it will be created (or error code will be returned if that fails).
478 int dev_pm_qos_add_notifier(struct device
*dev
, struct notifier_block
*notifier
)
482 mutex_lock(&dev_pm_qos_mtx
);
484 if (IS_ERR(dev
->power
.qos
))
486 else if (!dev
->power
.qos
)
487 ret
= dev_pm_qos_constraints_allocate(dev
);
490 ret
= blocking_notifier_chain_register(dev
->power
.qos
->resume_latency
.notifiers
,
493 mutex_unlock(&dev_pm_qos_mtx
);
496 EXPORT_SYMBOL_GPL(dev_pm_qos_add_notifier
);
499 * dev_pm_qos_remove_notifier - deletes notification for changes to target value
500 * of per-device PM QoS constraints
502 * @dev: target device for the constraint
503 * @notifier: notifier block to be removed.
505 * Will remove the notifier from the notification chain that gets called
506 * upon changes to the target value.
508 int dev_pm_qos_remove_notifier(struct device
*dev
,
509 struct notifier_block
*notifier
)
513 mutex_lock(&dev_pm_qos_mtx
);
515 /* Silently return if the constraints object is not present. */
516 if (!IS_ERR_OR_NULL(dev
->power
.qos
))
517 retval
= blocking_notifier_chain_unregister(dev
->power
.qos
->resume_latency
.notifiers
,
520 mutex_unlock(&dev_pm_qos_mtx
);
523 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_notifier
);
526 * dev_pm_qos_add_ancestor_request - Add PM QoS request for device's ancestor.
527 * @dev: Device whose ancestor to add the request for.
528 * @req: Pointer to the preallocated handle.
529 * @type: Type of the request.
530 * @value: Constraint latency value.
532 int dev_pm_qos_add_ancestor_request(struct device
*dev
,
533 struct dev_pm_qos_request
*req
,
534 enum dev_pm_qos_req_type type
, s32 value
)
536 struct device
*ancestor
= dev
->parent
;
540 case DEV_PM_QOS_RESUME_LATENCY
:
541 while (ancestor
&& !ancestor
->power
.ignore_children
)
542 ancestor
= ancestor
->parent
;
545 case DEV_PM_QOS_LATENCY_TOLERANCE
:
546 while (ancestor
&& !ancestor
->power
.set_latency_tolerance
)
547 ancestor
= ancestor
->parent
;
554 ret
= dev_pm_qos_add_request(ancestor
, req
, type
, value
);
561 EXPORT_SYMBOL_GPL(dev_pm_qos_add_ancestor_request
);
563 static void __dev_pm_qos_drop_user_request(struct device
*dev
,
564 enum dev_pm_qos_req_type type
)
566 struct dev_pm_qos_request
*req
= NULL
;
569 case DEV_PM_QOS_RESUME_LATENCY
:
570 req
= dev
->power
.qos
->resume_latency_req
;
571 dev
->power
.qos
->resume_latency_req
= NULL
;
573 case DEV_PM_QOS_LATENCY_TOLERANCE
:
574 req
= dev
->power
.qos
->latency_tolerance_req
;
575 dev
->power
.qos
->latency_tolerance_req
= NULL
;
577 case DEV_PM_QOS_FLAGS
:
578 req
= dev
->power
.qos
->flags_req
;
579 dev
->power
.qos
->flags_req
= NULL
;
582 __dev_pm_qos_remove_request(req
);
586 static void dev_pm_qos_drop_user_request(struct device
*dev
,
587 enum dev_pm_qos_req_type type
)
589 mutex_lock(&dev_pm_qos_mtx
);
590 __dev_pm_qos_drop_user_request(dev
, type
);
591 mutex_unlock(&dev_pm_qos_mtx
);
595 * dev_pm_qos_expose_latency_limit - Expose PM QoS latency limit to user space.
596 * @dev: Device whose PM QoS latency limit is to be exposed to user space.
597 * @value: Initial value of the latency limit.
599 int dev_pm_qos_expose_latency_limit(struct device
*dev
, s32 value
)
601 struct dev_pm_qos_request
*req
;
604 if (!device_is_registered(dev
) || value
< 0)
607 req
= kzalloc(sizeof(*req
), GFP_KERNEL
);
611 ret
= dev_pm_qos_add_request(dev
, req
, DEV_PM_QOS_RESUME_LATENCY
, value
);
617 mutex_lock(&dev_pm_qos_sysfs_mtx
);
619 mutex_lock(&dev_pm_qos_mtx
);
621 if (IS_ERR_OR_NULL(dev
->power
.qos
))
623 else if (dev
->power
.qos
->resume_latency_req
)
627 __dev_pm_qos_remove_request(req
);
629 mutex_unlock(&dev_pm_qos_mtx
);
632 dev
->power
.qos
->resume_latency_req
= req
;
634 mutex_unlock(&dev_pm_qos_mtx
);
636 ret
= pm_qos_sysfs_add_resume_latency(dev
);
638 dev_pm_qos_drop_user_request(dev
, DEV_PM_QOS_RESUME_LATENCY
);
641 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
644 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_latency_limit
);
646 static void __dev_pm_qos_hide_latency_limit(struct device
*dev
)
648 if (!IS_ERR_OR_NULL(dev
->power
.qos
) && dev
->power
.qos
->resume_latency_req
)
649 __dev_pm_qos_drop_user_request(dev
, DEV_PM_QOS_RESUME_LATENCY
);
653 * dev_pm_qos_hide_latency_limit - Hide PM QoS latency limit from user space.
654 * @dev: Device whose PM QoS latency limit is to be hidden from user space.
656 void dev_pm_qos_hide_latency_limit(struct device
*dev
)
658 mutex_lock(&dev_pm_qos_sysfs_mtx
);
660 pm_qos_sysfs_remove_resume_latency(dev
);
662 mutex_lock(&dev_pm_qos_mtx
);
663 __dev_pm_qos_hide_latency_limit(dev
);
664 mutex_unlock(&dev_pm_qos_mtx
);
666 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
668 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_latency_limit
);
671 * dev_pm_qos_expose_flags - Expose PM QoS flags of a device to user space.
672 * @dev: Device whose PM QoS flags are to be exposed to user space.
673 * @val: Initial values of the flags.
675 int dev_pm_qos_expose_flags(struct device
*dev
, s32 val
)
677 struct dev_pm_qos_request
*req
;
680 if (!device_is_registered(dev
))
683 req
= kzalloc(sizeof(*req
), GFP_KERNEL
);
687 ret
= dev_pm_qos_add_request(dev
, req
, DEV_PM_QOS_FLAGS
, val
);
693 pm_runtime_get_sync(dev
);
694 mutex_lock(&dev_pm_qos_sysfs_mtx
);
696 mutex_lock(&dev_pm_qos_mtx
);
698 if (IS_ERR_OR_NULL(dev
->power
.qos
))
700 else if (dev
->power
.qos
->flags_req
)
704 __dev_pm_qos_remove_request(req
);
706 mutex_unlock(&dev_pm_qos_mtx
);
709 dev
->power
.qos
->flags_req
= req
;
711 mutex_unlock(&dev_pm_qos_mtx
);
713 ret
= pm_qos_sysfs_add_flags(dev
);
715 dev_pm_qos_drop_user_request(dev
, DEV_PM_QOS_FLAGS
);
718 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
722 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_flags
);
724 static void __dev_pm_qos_hide_flags(struct device
*dev
)
726 if (!IS_ERR_OR_NULL(dev
->power
.qos
) && dev
->power
.qos
->flags_req
)
727 __dev_pm_qos_drop_user_request(dev
, DEV_PM_QOS_FLAGS
);
731 * dev_pm_qos_hide_flags - Hide PM QoS flags of a device from user space.
732 * @dev: Device whose PM QoS flags are to be hidden from user space.
734 void dev_pm_qos_hide_flags(struct device
*dev
)
736 pm_runtime_get_sync(dev
);
737 mutex_lock(&dev_pm_qos_sysfs_mtx
);
739 pm_qos_sysfs_remove_flags(dev
);
741 mutex_lock(&dev_pm_qos_mtx
);
742 __dev_pm_qos_hide_flags(dev
);
743 mutex_unlock(&dev_pm_qos_mtx
);
745 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
748 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_flags
);
751 * dev_pm_qos_update_flags - Update PM QoS flags request owned by user space.
752 * @dev: Device to update the PM QoS flags request for.
753 * @mask: Flags to set/clear.
754 * @set: Whether to set or clear the flags (true means set).
756 int dev_pm_qos_update_flags(struct device
*dev
, s32 mask
, bool set
)
761 pm_runtime_get_sync(dev
);
762 mutex_lock(&dev_pm_qos_mtx
);
764 if (IS_ERR_OR_NULL(dev
->power
.qos
) || !dev
->power
.qos
->flags_req
) {
769 value
= dev_pm_qos_requested_flags(dev
);
775 ret
= __dev_pm_qos_update_request(dev
->power
.qos
->flags_req
, value
);
778 mutex_unlock(&dev_pm_qos_mtx
);
784 * dev_pm_qos_get_user_latency_tolerance - Get user space latency tolerance.
785 * @dev: Device to obtain the user space latency tolerance for.
787 s32
dev_pm_qos_get_user_latency_tolerance(struct device
*dev
)
791 mutex_lock(&dev_pm_qos_mtx
);
792 ret
= IS_ERR_OR_NULL(dev
->power
.qos
)
793 || !dev
->power
.qos
->latency_tolerance_req
?
794 PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT
:
795 dev
->power
.qos
->latency_tolerance_req
->data
.pnode
.prio
;
796 mutex_unlock(&dev_pm_qos_mtx
);
801 * dev_pm_qos_update_user_latency_tolerance - Update user space latency tolerance.
802 * @dev: Device to update the user space latency tolerance for.
803 * @val: New user space latency tolerance for @dev (negative values disable).
805 int dev_pm_qos_update_user_latency_tolerance(struct device
*dev
, s32 val
)
809 mutex_lock(&dev_pm_qos_mtx
);
811 if (IS_ERR_OR_NULL(dev
->power
.qos
)
812 || !dev
->power
.qos
->latency_tolerance_req
) {
813 struct dev_pm_qos_request
*req
;
816 if (val
== PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT
)
822 req
= kzalloc(sizeof(*req
), GFP_KERNEL
);
827 ret
= __dev_pm_qos_add_request(dev
, req
, DEV_PM_QOS_LATENCY_TOLERANCE
, val
);
832 dev
->power
.qos
->latency_tolerance_req
= req
;
835 __dev_pm_qos_drop_user_request(dev
, DEV_PM_QOS_LATENCY_TOLERANCE
);
838 ret
= __dev_pm_qos_update_request(dev
->power
.qos
->latency_tolerance_req
, val
);
843 mutex_unlock(&dev_pm_qos_mtx
);
846 EXPORT_SYMBOL_GPL(dev_pm_qos_update_user_latency_tolerance
);
849 * dev_pm_qos_expose_latency_tolerance - Expose latency tolerance to userspace
850 * @dev: Device whose latency tolerance to expose
852 int dev_pm_qos_expose_latency_tolerance(struct device
*dev
)
856 if (!dev
->power
.set_latency_tolerance
)
859 mutex_lock(&dev_pm_qos_sysfs_mtx
);
860 ret
= pm_qos_sysfs_add_latency_tolerance(dev
);
861 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
865 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_latency_tolerance
);
868 * dev_pm_qos_hide_latency_tolerance - Hide latency tolerance from userspace
869 * @dev: Device whose latency tolerance to hide
871 void dev_pm_qos_hide_latency_tolerance(struct device
*dev
)
873 mutex_lock(&dev_pm_qos_sysfs_mtx
);
874 pm_qos_sysfs_remove_latency_tolerance(dev
);
875 mutex_unlock(&dev_pm_qos_sysfs_mtx
);
877 /* Remove the request from user space now */
878 pm_runtime_get_sync(dev
);
879 dev_pm_qos_update_user_latency_tolerance(dev
,
880 PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT
);
883 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_latency_tolerance
);