1 // SPDX-License-Identifier: GPL-2.0
3 * Devices PM QoS constraints management
5 * Copyright (C) 2011 Texas Instruments, Inc.
7 * This module exposes the interface to kernel space for specifying
8 * per-device PM QoS dependencies. It provides infrastructure for registration
11 * Dependents on a QoS value : register requests
12 * Watchers of QoS value : get notified when target QoS value changes
14 * This QoS design is best effort based. Dependents register their QoS needs.
15 * Watchers register to keep track of the current QoS needs of the system.
16 * Watchers can register a per-device notification callback using the
17 * dev_pm_qos_*_notifier API. The notification chain data is stored in the
18 * per-device constraint data struct.
20 * Note about the per-device constraint data struct allocation:
21 * . The per-device constraints data struct ptr is stored into the device
23 * . To minimize the data usage by the per-device constraints, the data struct
24 * is only allocated at the first call to dev_pm_qos_add_request.
25 * . The data is later free'd when the device is removed from the system.
26 * . A global mutex protects the constraints users from the data being
27 * allocated and free'd.
30 #include <linux/pm_qos.h>
31 #include <linux/spinlock.h>
32 #include <linux/slab.h>
33 #include <linux/device.h>
34 #include <linux/mutex.h>
35 #include <linux/export.h>
36 #include <linux/pm_runtime.h>
37 #include <linux/err.h>
38 #include <trace/events/power.h>
42 static DEFINE_MUTEX(dev_pm_qos_mtx);
43 static DEFINE_MUTEX(dev_pm_qos_sysfs_mtx);
46 * __dev_pm_qos_flags - Check PM QoS flags for a given device.
47 * @dev: Device to check the PM QoS flags for.
48 * @mask: Flags to check against.
50 * This routine must be called with dev->power.lock held.
52 enum pm_qos_flags_status __dev_pm_qos_flags(struct device *dev, s32 mask)
54 struct dev_pm_qos *qos = dev->power.qos;
55 struct pm_qos_flags *pqf;
58 lockdep_assert_held(&dev->power.lock);
60 if (IS_ERR_OR_NULL(qos))
61 return PM_QOS_FLAGS_UNDEFINED;
64 if (list_empty(&pqf->list))
65 return PM_QOS_FLAGS_UNDEFINED;
67 val = pqf->effective_flags & mask;
69 return (val == mask) ? PM_QOS_FLAGS_ALL : PM_QOS_FLAGS_SOME;
71 return PM_QOS_FLAGS_NONE;
75 * dev_pm_qos_flags - Check PM QoS flags for a given device (locked).
76 * @dev: Device to check the PM QoS flags for.
77 * @mask: Flags to check against.
79 enum pm_qos_flags_status dev_pm_qos_flags(struct device *dev, s32 mask)
81 unsigned long irqflags;
82 enum pm_qos_flags_status ret;
84 spin_lock_irqsave(&dev->power.lock, irqflags);
85 ret = __dev_pm_qos_flags(dev, mask);
86 spin_unlock_irqrestore(&dev->power.lock, irqflags);
90 EXPORT_SYMBOL_GPL(dev_pm_qos_flags);
93 * __dev_pm_qos_resume_latency - Get resume latency constraint for a given device.
94 * @dev: Device to get the PM QoS constraint value for.
96 * This routine must be called with dev->power.lock held.
98 s32 __dev_pm_qos_resume_latency(struct device *dev)
100 lockdep_assert_held(&dev->power.lock);
102 return dev_pm_qos_raw_resume_latency(dev);
106 * dev_pm_qos_read_value - Get PM QoS constraint for a given device (locked).
107 * @dev: Device to get the PM QoS constraint value for.
108 * @type: QoS request type.
110 s32 dev_pm_qos_read_value(struct device *dev, enum dev_pm_qos_req_type type)
112 struct dev_pm_qos *qos = dev->power.qos;
116 spin_lock_irqsave(&dev->power.lock, flags);
118 if (type == DEV_PM_QOS_RESUME_LATENCY) {
119 ret = IS_ERR_OR_NULL(qos) ? PM_QOS_RESUME_LATENCY_NO_CONSTRAINT
120 : pm_qos_read_value(&qos->resume_latency);
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 callbacks.
140 static int apply_constraint(struct dev_pm_qos_request *req,
141 enum pm_qos_req_action action, s32 value)
143 struct dev_pm_qos *qos = req->dev->power.qos;
147 case DEV_PM_QOS_RESUME_LATENCY:
148 if (WARN_ON(action != PM_QOS_REMOVE_REQ && value < 0))
151 ret = pm_qos_update_target(&qos->resume_latency,
152 &req->data.pnode, action, value);
154 case DEV_PM_QOS_LATENCY_TOLERANCE:
155 ret = pm_qos_update_target(&qos->latency_tolerance,
156 &req->data.pnode, action, value);
158 value = pm_qos_read_value(&qos->latency_tolerance);
159 req->dev->power.set_latency_tolerance(req->dev, value);
162 case DEV_PM_QOS_FLAGS:
163 ret = pm_qos_update_flags(&qos->flags, &req->data.flr,
174 * dev_pm_qos_constraints_allocate
175 * @dev: device to allocate data for
177 * Called at the first call to add_request, for constraint data allocation
178 * Must be called with the dev_pm_qos_mtx mutex held
180 static int dev_pm_qos_constraints_allocate(struct device *dev)
182 struct dev_pm_qos *qos;
183 struct pm_qos_constraints *c;
184 struct blocking_notifier_head *n;
186 qos = kzalloc(sizeof(*qos), GFP_KERNEL);
190 n = kzalloc(3 * sizeof(*n), GFP_KERNEL);
196 c = &qos->resume_latency;
197 plist_head_init(&c->list);
198 c->target_value = PM_QOS_RESUME_LATENCY_DEFAULT_VALUE;
199 c->default_value = PM_QOS_RESUME_LATENCY_DEFAULT_VALUE;
200 c->no_constraint_value = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
201 c->type = PM_QOS_MIN;
203 BLOCKING_INIT_NOTIFIER_HEAD(n);
205 c = &qos->latency_tolerance;
206 plist_head_init(&c->list);
207 c->target_value = PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE;
208 c->default_value = PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE;
209 c->no_constraint_value = PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT;
210 c->type = PM_QOS_MIN;
212 INIT_LIST_HEAD(&qos->flags.list);
214 spin_lock_irq(&dev->power.lock);
215 dev->power.qos = qos;
216 spin_unlock_irq(&dev->power.lock);
221 static void __dev_pm_qos_hide_latency_limit(struct device *dev);
222 static void __dev_pm_qos_hide_flags(struct device *dev);
225 * dev_pm_qos_constraints_destroy
226 * @dev: target device
228 * Called from the device PM subsystem on device removal under device_pm_lock().
230 void dev_pm_qos_constraints_destroy(struct device *dev)
232 struct dev_pm_qos *qos;
233 struct dev_pm_qos_request *req, *tmp;
234 struct pm_qos_constraints *c;
235 struct pm_qos_flags *f;
237 mutex_lock(&dev_pm_qos_sysfs_mtx);
240 * If the device's PM QoS resume latency limit or PM QoS flags have been
241 * exposed to user space, they have to be hidden at this point.
243 pm_qos_sysfs_remove_resume_latency(dev);
244 pm_qos_sysfs_remove_flags(dev);
246 mutex_lock(&dev_pm_qos_mtx);
248 __dev_pm_qos_hide_latency_limit(dev);
249 __dev_pm_qos_hide_flags(dev);
251 qos = dev->power.qos;
255 /* Flush the constraints lists for the device. */
256 c = &qos->resume_latency;
257 plist_for_each_entry_safe(req, tmp, &c->list, data.pnode) {
259 * Update constraints list and call the notification
260 * callbacks if needed
262 apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
263 memset(req, 0, sizeof(*req));
266 c = &qos->latency_tolerance;
267 plist_for_each_entry_safe(req, tmp, &c->list, data.pnode) {
268 apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
269 memset(req, 0, sizeof(*req));
273 list_for_each_entry_safe(req, tmp, &f->list, data.flr.node) {
274 apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
275 memset(req, 0, sizeof(*req));
278 spin_lock_irq(&dev->power.lock);
279 dev->power.qos = ERR_PTR(-ENODEV);
280 spin_unlock_irq(&dev->power.lock);
282 kfree(qos->resume_latency.notifiers);
286 mutex_unlock(&dev_pm_qos_mtx);
288 mutex_unlock(&dev_pm_qos_sysfs_mtx);
291 static bool dev_pm_qos_invalid_req_type(struct device *dev,
292 enum dev_pm_qos_req_type type)
294 return type == DEV_PM_QOS_LATENCY_TOLERANCE &&
295 !dev->power.set_latency_tolerance;
298 static int __dev_pm_qos_add_request(struct device *dev,
299 struct dev_pm_qos_request *req,
300 enum dev_pm_qos_req_type type, s32 value)
304 if (!dev || !req || dev_pm_qos_invalid_req_type(dev, type))
307 if (WARN(dev_pm_qos_request_active(req),
308 "%s() called for already added request\n", __func__))
311 if (IS_ERR(dev->power.qos))
313 else if (!dev->power.qos)
314 ret = dev_pm_qos_constraints_allocate(dev);
316 trace_dev_pm_qos_add_request(dev_name(dev), type, value);
320 ret = apply_constraint(req, PM_QOS_ADD_REQ, value);
326 * dev_pm_qos_add_request - inserts new qos request into the list
327 * @dev: target device for the constraint
328 * @req: pointer to a preallocated handle
329 * @type: type of the request
330 * @value: defines the qos request
332 * This function inserts a new entry in the device constraints list of
333 * requested qos performance characteristics. It recomputes the aggregate
334 * QoS expectations of parameters and initializes the dev_pm_qos_request
335 * handle. Caller needs to save this handle for later use in updates and
338 * Returns 1 if the aggregated constraint value has changed,
339 * 0 if the aggregated constraint value has not changed,
340 * -EINVAL in case of wrong parameters, -ENOMEM if there's not enough memory
341 * to allocate for data structures, -ENODEV if the device has just been removed
344 * Callers should ensure that the target device is not RPM_SUSPENDED before
345 * using this function for requests of type DEV_PM_QOS_FLAGS.
347 int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
348 enum dev_pm_qos_req_type type, s32 value)
352 mutex_lock(&dev_pm_qos_mtx);
353 ret = __dev_pm_qos_add_request(dev, req, type, value);
354 mutex_unlock(&dev_pm_qos_mtx);
357 EXPORT_SYMBOL_GPL(dev_pm_qos_add_request);
360 * __dev_pm_qos_update_request - Modify an existing device PM QoS request.
361 * @req : PM QoS request to modify.
362 * @new_value: New value to request.
364 static int __dev_pm_qos_update_request(struct dev_pm_qos_request *req,
370 if (!req) /*guard against callers passing in null */
373 if (WARN(!dev_pm_qos_request_active(req),
374 "%s() called for unknown object\n", __func__))
377 if (IS_ERR_OR_NULL(req->dev->power.qos))
381 case DEV_PM_QOS_RESUME_LATENCY:
382 case DEV_PM_QOS_LATENCY_TOLERANCE:
383 curr_value = req->data.pnode.prio;
385 case DEV_PM_QOS_FLAGS:
386 curr_value = req->data.flr.flags;
392 trace_dev_pm_qos_update_request(dev_name(req->dev), req->type,
394 if (curr_value != new_value)
395 ret = apply_constraint(req, PM_QOS_UPDATE_REQ, new_value);
401 * dev_pm_qos_update_request - modifies an existing qos request
402 * @req : handle to list element holding a dev_pm_qos request to use
403 * @new_value: defines the qos request
405 * Updates an existing dev PM qos request along with updating the
408 * Attempts are made to make this code callable on hot code paths.
410 * Returns 1 if the aggregated constraint value has changed,
411 * 0 if the aggregated constraint value has not changed,
412 * -EINVAL in case of wrong parameters, -ENODEV if the device has been
413 * removed from the system
415 * Callers should ensure that the target device is not RPM_SUSPENDED before
416 * using this function for requests of type DEV_PM_QOS_FLAGS.
418 int dev_pm_qos_update_request(struct dev_pm_qos_request *req, s32 new_value)
422 mutex_lock(&dev_pm_qos_mtx);
423 ret = __dev_pm_qos_update_request(req, new_value);
424 mutex_unlock(&dev_pm_qos_mtx);
427 EXPORT_SYMBOL_GPL(dev_pm_qos_update_request);
429 static int __dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
433 if (!req) /*guard against callers passing in null */
436 if (WARN(!dev_pm_qos_request_active(req),
437 "%s() called for unknown object\n", __func__))
440 if (IS_ERR_OR_NULL(req->dev->power.qos))
443 trace_dev_pm_qos_remove_request(dev_name(req->dev), req->type,
444 PM_QOS_DEFAULT_VALUE);
445 ret = apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
446 memset(req, 0, sizeof(*req));
451 * dev_pm_qos_remove_request - modifies an existing qos request
452 * @req: handle to request list element
454 * Will remove pm qos request from the list of constraints and
455 * recompute the current target value. Call this on slow code paths.
457 * Returns 1 if the aggregated constraint value has changed,
458 * 0 if the aggregated constraint value has not changed,
459 * -EINVAL in case of wrong parameters, -ENODEV if the device has been
460 * removed from the system
462 * Callers should ensure that the target device is not RPM_SUSPENDED before
463 * using this function for requests of type DEV_PM_QOS_FLAGS.
465 int dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
469 mutex_lock(&dev_pm_qos_mtx);
470 ret = __dev_pm_qos_remove_request(req);
471 mutex_unlock(&dev_pm_qos_mtx);
474 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_request);
477 * dev_pm_qos_add_notifier - sets notification entry for changes to target value
478 * of per-device PM QoS constraints
480 * @dev: target device for the constraint
481 * @notifier: notifier block managed by caller.
482 * @type: request type.
484 * Will register the notifier into a notification chain that gets called
485 * upon changes to the target value for the device.
487 * If the device's constraints object doesn't exist when this routine is called,
488 * it will be created (or error code will be returned if that fails).
490 int dev_pm_qos_add_notifier(struct device *dev, struct notifier_block *notifier,
491 enum dev_pm_qos_req_type type)
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);
506 case DEV_PM_QOS_RESUME_LATENCY:
507 ret = blocking_notifier_chain_register(dev->power.qos->resume_latency.notifiers,
516 mutex_unlock(&dev_pm_qos_mtx);
519 EXPORT_SYMBOL_GPL(dev_pm_qos_add_notifier);
522 * dev_pm_qos_remove_notifier - deletes notification for changes to target value
523 * of per-device PM QoS constraints
525 * @dev: target device for the constraint
526 * @notifier: notifier block to be removed.
527 * @type: request type.
529 * Will remove the notifier from the notification chain that gets called
530 * upon changes to the target value.
532 int dev_pm_qos_remove_notifier(struct device *dev,
533 struct notifier_block *notifier,
534 enum dev_pm_qos_req_type type)
538 mutex_lock(&dev_pm_qos_mtx);
540 /* Silently return if the constraints object is not present. */
541 if (IS_ERR_OR_NULL(dev->power.qos))
545 case DEV_PM_QOS_RESUME_LATENCY:
546 ret = blocking_notifier_chain_unregister(dev->power.qos->resume_latency.notifiers,
555 mutex_unlock(&dev_pm_qos_mtx);
558 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_notifier);
561 * dev_pm_qos_add_ancestor_request - Add PM QoS request for device's ancestor.
562 * @dev: Device whose ancestor to add the request for.
563 * @req: Pointer to the preallocated handle.
564 * @type: Type of the request.
565 * @value: Constraint latency value.
567 int dev_pm_qos_add_ancestor_request(struct device *dev,
568 struct dev_pm_qos_request *req,
569 enum dev_pm_qos_req_type type, s32 value)
571 struct device *ancestor = dev->parent;
575 case DEV_PM_QOS_RESUME_LATENCY:
576 while (ancestor && !ancestor->power.ignore_children)
577 ancestor = ancestor->parent;
580 case DEV_PM_QOS_LATENCY_TOLERANCE:
581 while (ancestor && !ancestor->power.set_latency_tolerance)
582 ancestor = ancestor->parent;
589 ret = dev_pm_qos_add_request(ancestor, req, type, value);
596 EXPORT_SYMBOL_GPL(dev_pm_qos_add_ancestor_request);
598 static void __dev_pm_qos_drop_user_request(struct device *dev,
599 enum dev_pm_qos_req_type type)
601 struct dev_pm_qos_request *req = NULL;
604 case DEV_PM_QOS_RESUME_LATENCY:
605 req = dev->power.qos->resume_latency_req;
606 dev->power.qos->resume_latency_req = NULL;
608 case DEV_PM_QOS_LATENCY_TOLERANCE:
609 req = dev->power.qos->latency_tolerance_req;
610 dev->power.qos->latency_tolerance_req = NULL;
612 case DEV_PM_QOS_FLAGS:
613 req = dev->power.qos->flags_req;
614 dev->power.qos->flags_req = NULL;
620 __dev_pm_qos_remove_request(req);
624 static void dev_pm_qos_drop_user_request(struct device *dev,
625 enum dev_pm_qos_req_type type)
627 mutex_lock(&dev_pm_qos_mtx);
628 __dev_pm_qos_drop_user_request(dev, type);
629 mutex_unlock(&dev_pm_qos_mtx);
633 * dev_pm_qos_expose_latency_limit - Expose PM QoS latency limit to user space.
634 * @dev: Device whose PM QoS latency limit is to be exposed to user space.
635 * @value: Initial value of the latency limit.
637 int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value)
639 struct dev_pm_qos_request *req;
642 if (!device_is_registered(dev) || value < 0)
645 req = kzalloc(sizeof(*req), GFP_KERNEL);
649 ret = dev_pm_qos_add_request(dev, req, DEV_PM_QOS_RESUME_LATENCY, value);
655 mutex_lock(&dev_pm_qos_sysfs_mtx);
657 mutex_lock(&dev_pm_qos_mtx);
659 if (IS_ERR_OR_NULL(dev->power.qos))
661 else if (dev->power.qos->resume_latency_req)
665 __dev_pm_qos_remove_request(req);
667 mutex_unlock(&dev_pm_qos_mtx);
670 dev->power.qos->resume_latency_req = req;
672 mutex_unlock(&dev_pm_qos_mtx);
674 ret = pm_qos_sysfs_add_resume_latency(dev);
676 dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_RESUME_LATENCY);
679 mutex_unlock(&dev_pm_qos_sysfs_mtx);
682 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_latency_limit);
684 static void __dev_pm_qos_hide_latency_limit(struct device *dev)
686 if (!IS_ERR_OR_NULL(dev->power.qos) && dev->power.qos->resume_latency_req)
687 __dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_RESUME_LATENCY);
691 * dev_pm_qos_hide_latency_limit - Hide PM QoS latency limit from user space.
692 * @dev: Device whose PM QoS latency limit is to be hidden from user space.
694 void dev_pm_qos_hide_latency_limit(struct device *dev)
696 mutex_lock(&dev_pm_qos_sysfs_mtx);
698 pm_qos_sysfs_remove_resume_latency(dev);
700 mutex_lock(&dev_pm_qos_mtx);
701 __dev_pm_qos_hide_latency_limit(dev);
702 mutex_unlock(&dev_pm_qos_mtx);
704 mutex_unlock(&dev_pm_qos_sysfs_mtx);
706 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_latency_limit);
709 * dev_pm_qos_expose_flags - Expose PM QoS flags of a device to user space.
710 * @dev: Device whose PM QoS flags are to be exposed to user space.
711 * @val: Initial values of the flags.
713 int dev_pm_qos_expose_flags(struct device *dev, s32 val)
715 struct dev_pm_qos_request *req;
718 if (!device_is_registered(dev))
721 req = kzalloc(sizeof(*req), GFP_KERNEL);
725 ret = dev_pm_qos_add_request(dev, req, DEV_PM_QOS_FLAGS, val);
731 pm_runtime_get_sync(dev);
732 mutex_lock(&dev_pm_qos_sysfs_mtx);
734 mutex_lock(&dev_pm_qos_mtx);
736 if (IS_ERR_OR_NULL(dev->power.qos))
738 else if (dev->power.qos->flags_req)
742 __dev_pm_qos_remove_request(req);
744 mutex_unlock(&dev_pm_qos_mtx);
747 dev->power.qos->flags_req = req;
749 mutex_unlock(&dev_pm_qos_mtx);
751 ret = pm_qos_sysfs_add_flags(dev);
753 dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_FLAGS);
756 mutex_unlock(&dev_pm_qos_sysfs_mtx);
760 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_flags);
762 static void __dev_pm_qos_hide_flags(struct device *dev)
764 if (!IS_ERR_OR_NULL(dev->power.qos) && dev->power.qos->flags_req)
765 __dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_FLAGS);
769 * dev_pm_qos_hide_flags - Hide PM QoS flags of a device from user space.
770 * @dev: Device whose PM QoS flags are to be hidden from user space.
772 void dev_pm_qos_hide_flags(struct device *dev)
774 pm_runtime_get_sync(dev);
775 mutex_lock(&dev_pm_qos_sysfs_mtx);
777 pm_qos_sysfs_remove_flags(dev);
779 mutex_lock(&dev_pm_qos_mtx);
780 __dev_pm_qos_hide_flags(dev);
781 mutex_unlock(&dev_pm_qos_mtx);
783 mutex_unlock(&dev_pm_qos_sysfs_mtx);
786 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_flags);
789 * dev_pm_qos_update_flags - Update PM QoS flags request owned by user space.
790 * @dev: Device to update the PM QoS flags request for.
791 * @mask: Flags to set/clear.
792 * @set: Whether to set or clear the flags (true means set).
794 int dev_pm_qos_update_flags(struct device *dev, s32 mask, bool set)
799 pm_runtime_get_sync(dev);
800 mutex_lock(&dev_pm_qos_mtx);
802 if (IS_ERR_OR_NULL(dev->power.qos) || !dev->power.qos->flags_req) {
807 value = dev_pm_qos_requested_flags(dev);
813 ret = __dev_pm_qos_update_request(dev->power.qos->flags_req, value);
816 mutex_unlock(&dev_pm_qos_mtx);
822 * dev_pm_qos_get_user_latency_tolerance - Get user space latency tolerance.
823 * @dev: Device to obtain the user space latency tolerance for.
825 s32 dev_pm_qos_get_user_latency_tolerance(struct device *dev)
829 mutex_lock(&dev_pm_qos_mtx);
830 ret = IS_ERR_OR_NULL(dev->power.qos)
831 || !dev->power.qos->latency_tolerance_req ?
832 PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT :
833 dev->power.qos->latency_tolerance_req->data.pnode.prio;
834 mutex_unlock(&dev_pm_qos_mtx);
839 * dev_pm_qos_update_user_latency_tolerance - Update user space latency tolerance.
840 * @dev: Device to update the user space latency tolerance for.
841 * @val: New user space latency tolerance for @dev (negative values disable).
843 int dev_pm_qos_update_user_latency_tolerance(struct device *dev, s32 val)
847 mutex_lock(&dev_pm_qos_mtx);
849 if (IS_ERR_OR_NULL(dev->power.qos)
850 || !dev->power.qos->latency_tolerance_req) {
851 struct dev_pm_qos_request *req;
854 if (val == PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT)
860 req = kzalloc(sizeof(*req), GFP_KERNEL);
865 ret = __dev_pm_qos_add_request(dev, req, DEV_PM_QOS_LATENCY_TOLERANCE, val);
870 dev->power.qos->latency_tolerance_req = req;
873 __dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_LATENCY_TOLERANCE);
876 ret = __dev_pm_qos_update_request(dev->power.qos->latency_tolerance_req, val);
881 mutex_unlock(&dev_pm_qos_mtx);
884 EXPORT_SYMBOL_GPL(dev_pm_qos_update_user_latency_tolerance);
887 * dev_pm_qos_expose_latency_tolerance - Expose latency tolerance to userspace
888 * @dev: Device whose latency tolerance to expose
890 int dev_pm_qos_expose_latency_tolerance(struct device *dev)
894 if (!dev->power.set_latency_tolerance)
897 mutex_lock(&dev_pm_qos_sysfs_mtx);
898 ret = pm_qos_sysfs_add_latency_tolerance(dev);
899 mutex_unlock(&dev_pm_qos_sysfs_mtx);
903 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_latency_tolerance);
906 * dev_pm_qos_hide_latency_tolerance - Hide latency tolerance from userspace
907 * @dev: Device whose latency tolerance to hide
909 void dev_pm_qos_hide_latency_tolerance(struct device *dev)
911 mutex_lock(&dev_pm_qos_sysfs_mtx);
912 pm_qos_sysfs_remove_latency_tolerance(dev);
913 mutex_unlock(&dev_pm_qos_sysfs_mtx);
915 /* Remove the request from user space now */
916 pm_runtime_get_sync(dev);
917 dev_pm_qos_update_user_latency_tolerance(dev,
918 PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT);
921 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_latency_tolerance);