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.
109 s32 dev_pm_qos_read_value(struct device *dev)
114 spin_lock_irqsave(&dev->power.lock, flags);
116 if (IS_ERR_OR_NULL(dev->power.qos))
117 ret = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
119 ret = pm_qos_read_value(&dev->power.qos->resume_latency);
121 spin_unlock_irqrestore(&dev->power.lock, flags);
127 * apply_constraint - Add/modify/remove device PM QoS request.
128 * @req: Constraint request to apply
129 * @action: Action to perform (add/update/remove).
130 * @value: Value to assign to the QoS request.
132 * Internal function to update the constraints list using the PM QoS core
133 * code and if needed call the per-device callbacks.
135 static int apply_constraint(struct dev_pm_qos_request *req,
136 enum pm_qos_req_action action, s32 value)
138 struct dev_pm_qos *qos = req->dev->power.qos;
142 case DEV_PM_QOS_RESUME_LATENCY:
143 if (WARN_ON(action != PM_QOS_REMOVE_REQ && value < 0))
146 ret = pm_qos_update_target(&qos->resume_latency,
147 &req->data.pnode, action, value);
149 case DEV_PM_QOS_LATENCY_TOLERANCE:
150 ret = pm_qos_update_target(&qos->latency_tolerance,
151 &req->data.pnode, action, value);
153 value = pm_qos_read_value(&qos->latency_tolerance);
154 req->dev->power.set_latency_tolerance(req->dev, value);
157 case DEV_PM_QOS_FLAGS:
158 ret = pm_qos_update_flags(&qos->flags, &req->data.flr,
169 * dev_pm_qos_constraints_allocate
170 * @dev: device to allocate data for
172 * Called at the first call to add_request, for constraint data allocation
173 * Must be called with the dev_pm_qos_mtx mutex held
175 static int dev_pm_qos_constraints_allocate(struct device *dev)
177 struct dev_pm_qos *qos;
178 struct pm_qos_constraints *c;
179 struct blocking_notifier_head *n;
181 qos = kzalloc(sizeof(*qos), GFP_KERNEL);
185 n = kzalloc(sizeof(*n), GFP_KERNEL);
190 BLOCKING_INIT_NOTIFIER_HEAD(n);
192 c = &qos->resume_latency;
193 plist_head_init(&c->list);
194 c->target_value = PM_QOS_RESUME_LATENCY_DEFAULT_VALUE;
195 c->default_value = PM_QOS_RESUME_LATENCY_DEFAULT_VALUE;
196 c->no_constraint_value = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
197 c->type = PM_QOS_MIN;
200 c = &qos->latency_tolerance;
201 plist_head_init(&c->list);
202 c->target_value = PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE;
203 c->default_value = PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE;
204 c->no_constraint_value = PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT;
205 c->type = PM_QOS_MIN;
207 INIT_LIST_HEAD(&qos->flags.list);
209 spin_lock_irq(&dev->power.lock);
210 dev->power.qos = qos;
211 spin_unlock_irq(&dev->power.lock);
216 static void __dev_pm_qos_hide_latency_limit(struct device *dev);
217 static void __dev_pm_qos_hide_flags(struct device *dev);
220 * dev_pm_qos_constraints_destroy
221 * @dev: target device
223 * Called from the device PM subsystem on device removal under device_pm_lock().
225 void dev_pm_qos_constraints_destroy(struct device *dev)
227 struct dev_pm_qos *qos;
228 struct dev_pm_qos_request *req, *tmp;
229 struct pm_qos_constraints *c;
230 struct pm_qos_flags *f;
232 mutex_lock(&dev_pm_qos_sysfs_mtx);
235 * If the device's PM QoS resume latency limit or PM QoS flags have been
236 * exposed to user space, they have to be hidden at this point.
238 pm_qos_sysfs_remove_resume_latency(dev);
239 pm_qos_sysfs_remove_flags(dev);
241 mutex_lock(&dev_pm_qos_mtx);
243 __dev_pm_qos_hide_latency_limit(dev);
244 __dev_pm_qos_hide_flags(dev);
246 qos = dev->power.qos;
250 /* Flush the constraints lists for the device. */
251 c = &qos->resume_latency;
252 plist_for_each_entry_safe(req, tmp, &c->list, data.pnode) {
254 * Update constraints list and call the notification
255 * callbacks if needed
257 apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
258 memset(req, 0, sizeof(*req));
260 c = &qos->latency_tolerance;
261 plist_for_each_entry_safe(req, tmp, &c->list, data.pnode) {
262 apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
263 memset(req, 0, sizeof(*req));
266 list_for_each_entry_safe(req, tmp, &f->list, data.flr.node) {
267 apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
268 memset(req, 0, sizeof(*req));
271 spin_lock_irq(&dev->power.lock);
272 dev->power.qos = ERR_PTR(-ENODEV);
273 spin_unlock_irq(&dev->power.lock);
275 kfree(qos->resume_latency.notifiers);
279 mutex_unlock(&dev_pm_qos_mtx);
281 mutex_unlock(&dev_pm_qos_sysfs_mtx);
284 static bool dev_pm_qos_invalid_req_type(struct device *dev,
285 enum dev_pm_qos_req_type type)
287 return type == DEV_PM_QOS_LATENCY_TOLERANCE &&
288 !dev->power.set_latency_tolerance;
291 static int __dev_pm_qos_add_request(struct device *dev,
292 struct dev_pm_qos_request *req,
293 enum dev_pm_qos_req_type type, s32 value)
297 if (!dev || !req || dev_pm_qos_invalid_req_type(dev, type))
300 if (WARN(dev_pm_qos_request_active(req),
301 "%s() called for already added request\n", __func__))
304 if (IS_ERR(dev->power.qos))
306 else if (!dev->power.qos)
307 ret = dev_pm_qos_constraints_allocate(dev);
309 trace_dev_pm_qos_add_request(dev_name(dev), type, value);
313 ret = apply_constraint(req, PM_QOS_ADD_REQ, value);
319 * dev_pm_qos_add_request - inserts new qos request into the list
320 * @dev: target device for the constraint
321 * @req: pointer to a preallocated handle
322 * @type: type of the request
323 * @value: defines the qos request
325 * This function inserts a new entry in the device constraints list of
326 * requested qos performance characteristics. It recomputes the aggregate
327 * QoS expectations of parameters and initializes the dev_pm_qos_request
328 * handle. Caller needs to save this handle for later use in updates and
331 * Returns 1 if the aggregated constraint value has changed,
332 * 0 if the aggregated constraint value has not changed,
333 * -EINVAL in case of wrong parameters, -ENOMEM if there's not enough memory
334 * to allocate for data structures, -ENODEV if the device has just been removed
337 * Callers should ensure that the target device is not RPM_SUSPENDED before
338 * using this function for requests of type DEV_PM_QOS_FLAGS.
340 int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
341 enum dev_pm_qos_req_type type, s32 value)
345 mutex_lock(&dev_pm_qos_mtx);
346 ret = __dev_pm_qos_add_request(dev, req, type, value);
347 mutex_unlock(&dev_pm_qos_mtx);
350 EXPORT_SYMBOL_GPL(dev_pm_qos_add_request);
353 * __dev_pm_qos_update_request - Modify an existing device PM QoS request.
354 * @req : PM QoS request to modify.
355 * @new_value: New value to request.
357 static int __dev_pm_qos_update_request(struct dev_pm_qos_request *req,
363 if (!req) /*guard against callers passing in null */
366 if (WARN(!dev_pm_qos_request_active(req),
367 "%s() called for unknown object\n", __func__))
370 if (IS_ERR_OR_NULL(req->dev->power.qos))
374 case DEV_PM_QOS_RESUME_LATENCY:
375 case DEV_PM_QOS_LATENCY_TOLERANCE:
376 curr_value = req->data.pnode.prio;
378 case DEV_PM_QOS_FLAGS:
379 curr_value = req->data.flr.flags;
385 trace_dev_pm_qos_update_request(dev_name(req->dev), req->type,
387 if (curr_value != new_value)
388 ret = apply_constraint(req, PM_QOS_UPDATE_REQ, new_value);
394 * dev_pm_qos_update_request - modifies an existing qos request
395 * @req : handle to list element holding a dev_pm_qos request to use
396 * @new_value: defines the qos request
398 * Updates an existing dev PM qos request along with updating the
401 * Attempts are made to make this code callable on hot code paths.
403 * Returns 1 if the aggregated constraint value has changed,
404 * 0 if the aggregated constraint value has not changed,
405 * -EINVAL in case of wrong parameters, -ENODEV if the device has been
406 * removed from the system
408 * Callers should ensure that the target device is not RPM_SUSPENDED before
409 * using this function for requests of type DEV_PM_QOS_FLAGS.
411 int dev_pm_qos_update_request(struct dev_pm_qos_request *req, s32 new_value)
415 mutex_lock(&dev_pm_qos_mtx);
416 ret = __dev_pm_qos_update_request(req, new_value);
417 mutex_unlock(&dev_pm_qos_mtx);
420 EXPORT_SYMBOL_GPL(dev_pm_qos_update_request);
422 static int __dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
426 if (!req) /*guard against callers passing in null */
429 if (WARN(!dev_pm_qos_request_active(req),
430 "%s() called for unknown object\n", __func__))
433 if (IS_ERR_OR_NULL(req->dev->power.qos))
436 trace_dev_pm_qos_remove_request(dev_name(req->dev), req->type,
437 PM_QOS_DEFAULT_VALUE);
438 ret = apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
439 memset(req, 0, sizeof(*req));
444 * dev_pm_qos_remove_request - modifies an existing qos request
445 * @req: handle to request list element
447 * Will remove pm qos request from the list of constraints and
448 * recompute the current target value. Call this on slow code paths.
450 * Returns 1 if the aggregated constraint value has changed,
451 * 0 if the aggregated constraint value has not changed,
452 * -EINVAL in case of wrong parameters, -ENODEV if the device has been
453 * removed from the system
455 * Callers should ensure that the target device is not RPM_SUSPENDED before
456 * using this function for requests of type DEV_PM_QOS_FLAGS.
458 int dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
462 mutex_lock(&dev_pm_qos_mtx);
463 ret = __dev_pm_qos_remove_request(req);
464 mutex_unlock(&dev_pm_qos_mtx);
467 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_request);
470 * dev_pm_qos_add_notifier - sets notification entry for changes to target value
471 * of per-device PM QoS constraints
473 * @dev: target device for the constraint
474 * @notifier: notifier block managed by caller.
475 * @type: request type.
477 * Will register the notifier into a notification chain that gets called
478 * upon changes to the target value for the device.
480 * If the device's constraints object doesn't exist when this routine is called,
481 * it will be created (or error code will be returned if that fails).
483 int dev_pm_qos_add_notifier(struct device *dev, struct notifier_block *notifier,
484 enum dev_pm_qos_req_type type)
488 if (WARN_ON(type != DEV_PM_QOS_RESUME_LATENCY))
491 mutex_lock(&dev_pm_qos_mtx);
493 if (IS_ERR(dev->power.qos))
495 else if (!dev->power.qos)
496 ret = dev_pm_qos_constraints_allocate(dev);
499 ret = blocking_notifier_chain_register(dev->power.qos->resume_latency.notifiers,
502 mutex_unlock(&dev_pm_qos_mtx);
505 EXPORT_SYMBOL_GPL(dev_pm_qos_add_notifier);
508 * dev_pm_qos_remove_notifier - deletes notification for changes to target value
509 * of per-device PM QoS constraints
511 * @dev: target device for the constraint
512 * @notifier: notifier block to be removed.
513 * @type: request type.
515 * Will remove the notifier from the notification chain that gets called
516 * upon changes to the target value.
518 int dev_pm_qos_remove_notifier(struct device *dev,
519 struct notifier_block *notifier,
520 enum dev_pm_qos_req_type type)
524 if (WARN_ON(type != DEV_PM_QOS_RESUME_LATENCY))
527 mutex_lock(&dev_pm_qos_mtx);
529 /* Silently return if the constraints object is not present. */
530 if (!IS_ERR_OR_NULL(dev->power.qos))
531 retval = blocking_notifier_chain_unregister(dev->power.qos->resume_latency.notifiers,
534 mutex_unlock(&dev_pm_qos_mtx);
537 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_notifier);
540 * dev_pm_qos_add_ancestor_request - Add PM QoS request for device's ancestor.
541 * @dev: Device whose ancestor to add the request for.
542 * @req: Pointer to the preallocated handle.
543 * @type: Type of the request.
544 * @value: Constraint latency value.
546 int dev_pm_qos_add_ancestor_request(struct device *dev,
547 struct dev_pm_qos_request *req,
548 enum dev_pm_qos_req_type type, s32 value)
550 struct device *ancestor = dev->parent;
554 case DEV_PM_QOS_RESUME_LATENCY:
555 while (ancestor && !ancestor->power.ignore_children)
556 ancestor = ancestor->parent;
559 case DEV_PM_QOS_LATENCY_TOLERANCE:
560 while (ancestor && !ancestor->power.set_latency_tolerance)
561 ancestor = ancestor->parent;
568 ret = dev_pm_qos_add_request(ancestor, req, type, value);
575 EXPORT_SYMBOL_GPL(dev_pm_qos_add_ancestor_request);
577 static void __dev_pm_qos_drop_user_request(struct device *dev,
578 enum dev_pm_qos_req_type type)
580 struct dev_pm_qos_request *req = NULL;
583 case DEV_PM_QOS_RESUME_LATENCY:
584 req = dev->power.qos->resume_latency_req;
585 dev->power.qos->resume_latency_req = NULL;
587 case DEV_PM_QOS_LATENCY_TOLERANCE:
588 req = dev->power.qos->latency_tolerance_req;
589 dev->power.qos->latency_tolerance_req = NULL;
591 case DEV_PM_QOS_FLAGS:
592 req = dev->power.qos->flags_req;
593 dev->power.qos->flags_req = NULL;
596 __dev_pm_qos_remove_request(req);
600 static void dev_pm_qos_drop_user_request(struct device *dev,
601 enum dev_pm_qos_req_type type)
603 mutex_lock(&dev_pm_qos_mtx);
604 __dev_pm_qos_drop_user_request(dev, type);
605 mutex_unlock(&dev_pm_qos_mtx);
609 * dev_pm_qos_expose_latency_limit - Expose PM QoS latency limit to user space.
610 * @dev: Device whose PM QoS latency limit is to be exposed to user space.
611 * @value: Initial value of the latency limit.
613 int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value)
615 struct dev_pm_qos_request *req;
618 if (!device_is_registered(dev) || value < 0)
621 req = kzalloc(sizeof(*req), GFP_KERNEL);
625 ret = dev_pm_qos_add_request(dev, req, DEV_PM_QOS_RESUME_LATENCY, value);
631 mutex_lock(&dev_pm_qos_sysfs_mtx);
633 mutex_lock(&dev_pm_qos_mtx);
635 if (IS_ERR_OR_NULL(dev->power.qos))
637 else if (dev->power.qos->resume_latency_req)
641 __dev_pm_qos_remove_request(req);
643 mutex_unlock(&dev_pm_qos_mtx);
646 dev->power.qos->resume_latency_req = req;
648 mutex_unlock(&dev_pm_qos_mtx);
650 ret = pm_qos_sysfs_add_resume_latency(dev);
652 dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_RESUME_LATENCY);
655 mutex_unlock(&dev_pm_qos_sysfs_mtx);
658 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_latency_limit);
660 static void __dev_pm_qos_hide_latency_limit(struct device *dev)
662 if (!IS_ERR_OR_NULL(dev->power.qos) && dev->power.qos->resume_latency_req)
663 __dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_RESUME_LATENCY);
667 * dev_pm_qos_hide_latency_limit - Hide PM QoS latency limit from user space.
668 * @dev: Device whose PM QoS latency limit is to be hidden from user space.
670 void dev_pm_qos_hide_latency_limit(struct device *dev)
672 mutex_lock(&dev_pm_qos_sysfs_mtx);
674 pm_qos_sysfs_remove_resume_latency(dev);
676 mutex_lock(&dev_pm_qos_mtx);
677 __dev_pm_qos_hide_latency_limit(dev);
678 mutex_unlock(&dev_pm_qos_mtx);
680 mutex_unlock(&dev_pm_qos_sysfs_mtx);
682 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_latency_limit);
685 * dev_pm_qos_expose_flags - Expose PM QoS flags of a device to user space.
686 * @dev: Device whose PM QoS flags are to be exposed to user space.
687 * @val: Initial values of the flags.
689 int dev_pm_qos_expose_flags(struct device *dev, s32 val)
691 struct dev_pm_qos_request *req;
694 if (!device_is_registered(dev))
697 req = kzalloc(sizeof(*req), GFP_KERNEL);
701 ret = dev_pm_qos_add_request(dev, req, DEV_PM_QOS_FLAGS, val);
707 pm_runtime_get_sync(dev);
708 mutex_lock(&dev_pm_qos_sysfs_mtx);
710 mutex_lock(&dev_pm_qos_mtx);
712 if (IS_ERR_OR_NULL(dev->power.qos))
714 else if (dev->power.qos->flags_req)
718 __dev_pm_qos_remove_request(req);
720 mutex_unlock(&dev_pm_qos_mtx);
723 dev->power.qos->flags_req = req;
725 mutex_unlock(&dev_pm_qos_mtx);
727 ret = pm_qos_sysfs_add_flags(dev);
729 dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_FLAGS);
732 mutex_unlock(&dev_pm_qos_sysfs_mtx);
736 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_flags);
738 static void __dev_pm_qos_hide_flags(struct device *dev)
740 if (!IS_ERR_OR_NULL(dev->power.qos) && dev->power.qos->flags_req)
741 __dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_FLAGS);
745 * dev_pm_qos_hide_flags - Hide PM QoS flags of a device from user space.
746 * @dev: Device whose PM QoS flags are to be hidden from user space.
748 void dev_pm_qos_hide_flags(struct device *dev)
750 pm_runtime_get_sync(dev);
751 mutex_lock(&dev_pm_qos_sysfs_mtx);
753 pm_qos_sysfs_remove_flags(dev);
755 mutex_lock(&dev_pm_qos_mtx);
756 __dev_pm_qos_hide_flags(dev);
757 mutex_unlock(&dev_pm_qos_mtx);
759 mutex_unlock(&dev_pm_qos_sysfs_mtx);
762 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_flags);
765 * dev_pm_qos_update_flags - Update PM QoS flags request owned by user space.
766 * @dev: Device to update the PM QoS flags request for.
767 * @mask: Flags to set/clear.
768 * @set: Whether to set or clear the flags (true means set).
770 int dev_pm_qos_update_flags(struct device *dev, s32 mask, bool set)
775 pm_runtime_get_sync(dev);
776 mutex_lock(&dev_pm_qos_mtx);
778 if (IS_ERR_OR_NULL(dev->power.qos) || !dev->power.qos->flags_req) {
783 value = dev_pm_qos_requested_flags(dev);
789 ret = __dev_pm_qos_update_request(dev->power.qos->flags_req, value);
792 mutex_unlock(&dev_pm_qos_mtx);
798 * dev_pm_qos_get_user_latency_tolerance - Get user space latency tolerance.
799 * @dev: Device to obtain the user space latency tolerance for.
801 s32 dev_pm_qos_get_user_latency_tolerance(struct device *dev)
805 mutex_lock(&dev_pm_qos_mtx);
806 ret = IS_ERR_OR_NULL(dev->power.qos)
807 || !dev->power.qos->latency_tolerance_req ?
808 PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT :
809 dev->power.qos->latency_tolerance_req->data.pnode.prio;
810 mutex_unlock(&dev_pm_qos_mtx);
815 * dev_pm_qos_update_user_latency_tolerance - Update user space latency tolerance.
816 * @dev: Device to update the user space latency tolerance for.
817 * @val: New user space latency tolerance for @dev (negative values disable).
819 int dev_pm_qos_update_user_latency_tolerance(struct device *dev, s32 val)
823 mutex_lock(&dev_pm_qos_mtx);
825 if (IS_ERR_OR_NULL(dev->power.qos)
826 || !dev->power.qos->latency_tolerance_req) {
827 struct dev_pm_qos_request *req;
830 if (val == PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT)
836 req = kzalloc(sizeof(*req), GFP_KERNEL);
841 ret = __dev_pm_qos_add_request(dev, req, DEV_PM_QOS_LATENCY_TOLERANCE, val);
846 dev->power.qos->latency_tolerance_req = req;
849 __dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_LATENCY_TOLERANCE);
852 ret = __dev_pm_qos_update_request(dev->power.qos->latency_tolerance_req, val);
857 mutex_unlock(&dev_pm_qos_mtx);
860 EXPORT_SYMBOL_GPL(dev_pm_qos_update_user_latency_tolerance);
863 * dev_pm_qos_expose_latency_tolerance - Expose latency tolerance to userspace
864 * @dev: Device whose latency tolerance to expose
866 int dev_pm_qos_expose_latency_tolerance(struct device *dev)
870 if (!dev->power.set_latency_tolerance)
873 mutex_lock(&dev_pm_qos_sysfs_mtx);
874 ret = pm_qos_sysfs_add_latency_tolerance(dev);
875 mutex_unlock(&dev_pm_qos_sysfs_mtx);
879 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_latency_tolerance);
882 * dev_pm_qos_hide_latency_tolerance - Hide latency tolerance from userspace
883 * @dev: Device whose latency tolerance to hide
885 void dev_pm_qos_hide_latency_tolerance(struct device *dev)
887 mutex_lock(&dev_pm_qos_sysfs_mtx);
888 pm_qos_sysfs_remove_latency_tolerance(dev);
889 mutex_unlock(&dev_pm_qos_sysfs_mtx);
891 /* Remove the request from user space now */
892 pm_runtime_get_sync(dev);
893 dev_pm_qos_update_user_latency_tolerance(dev,
894 PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT);
897 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_latency_tolerance);