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 IS_ERR_OR_NULL(dev->power.qos) ?
107 0 : pm_qos_read_value(&dev->power.qos->resume_latency);
111 * dev_pm_qos_read_value - Get PM QoS constraint for a given device (locked).
112 * @dev: Device to get the PM QoS constraint value for.
114 s32 dev_pm_qos_read_value(struct device *dev)
119 spin_lock_irqsave(&dev->power.lock, flags);
120 ret = __dev_pm_qos_read_value(dev);
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 ret = pm_qos_update_target(&qos->resume_latency,
144 &req->data.pnode, action, value);
146 case DEV_PM_QOS_LATENCY_TOLERANCE:
147 ret = pm_qos_update_target(&qos->latency_tolerance,
148 &req->data.pnode, action, value);
150 value = pm_qos_read_value(&qos->latency_tolerance);
151 req->dev->power.set_latency_tolerance(req->dev, value);
154 case DEV_PM_QOS_FLAGS:
155 ret = pm_qos_update_flags(&qos->flags, &req->data.flr,
166 * dev_pm_qos_constraints_allocate
167 * @dev: device to allocate data for
169 * Called at the first call to add_request, for constraint data allocation
170 * Must be called with the dev_pm_qos_mtx mutex held
172 static int dev_pm_qos_constraints_allocate(struct device *dev)
174 struct dev_pm_qos *qos;
175 struct pm_qos_constraints *c;
176 struct blocking_notifier_head *n;
178 qos = kzalloc(sizeof(*qos), GFP_KERNEL);
182 n = kzalloc(sizeof(*n), GFP_KERNEL);
187 BLOCKING_INIT_NOTIFIER_HEAD(n);
189 c = &qos->resume_latency;
190 plist_head_init(&c->list);
191 c->target_value = PM_QOS_RESUME_LATENCY_DEFAULT_VALUE;
192 c->default_value = PM_QOS_RESUME_LATENCY_DEFAULT_VALUE;
193 c->no_constraint_value = PM_QOS_RESUME_LATENCY_DEFAULT_VALUE;
194 c->type = PM_QOS_MIN;
197 c = &qos->latency_tolerance;
198 plist_head_init(&c->list);
199 c->target_value = PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE;
200 c->default_value = PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE;
201 c->no_constraint_value = PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT;
202 c->type = PM_QOS_MIN;
204 INIT_LIST_HEAD(&qos->flags.list);
206 spin_lock_irq(&dev->power.lock);
207 dev->power.qos = qos;
208 spin_unlock_irq(&dev->power.lock);
213 static void __dev_pm_qos_hide_latency_limit(struct device *dev);
214 static void __dev_pm_qos_hide_flags(struct device *dev);
217 * dev_pm_qos_constraints_destroy
218 * @dev: target device
220 * Called from the device PM subsystem on device removal under device_pm_lock().
222 void dev_pm_qos_constraints_destroy(struct device *dev)
224 struct dev_pm_qos *qos;
225 struct dev_pm_qos_request *req, *tmp;
226 struct pm_qos_constraints *c;
227 struct pm_qos_flags *f;
229 mutex_lock(&dev_pm_qos_sysfs_mtx);
232 * If the device's PM QoS resume latency limit or PM QoS flags have been
233 * exposed to user space, they have to be hidden at this point.
235 pm_qos_sysfs_remove_resume_latency(dev);
236 pm_qos_sysfs_remove_flags(dev);
238 mutex_lock(&dev_pm_qos_mtx);
240 __dev_pm_qos_hide_latency_limit(dev);
241 __dev_pm_qos_hide_flags(dev);
243 qos = dev->power.qos;
247 /* Flush the constraints lists for the device. */
248 c = &qos->resume_latency;
249 plist_for_each_entry_safe(req, tmp, &c->list, data.pnode) {
251 * Update constraints list and call the notification
252 * callbacks if needed
254 apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
255 memset(req, 0, sizeof(*req));
257 c = &qos->latency_tolerance;
258 plist_for_each_entry_safe(req, tmp, &c->list, data.pnode) {
259 apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
260 memset(req, 0, sizeof(*req));
263 list_for_each_entry_safe(req, tmp, &f->list, data.flr.node) {
264 apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
265 memset(req, 0, sizeof(*req));
268 spin_lock_irq(&dev->power.lock);
269 dev->power.qos = ERR_PTR(-ENODEV);
270 spin_unlock_irq(&dev->power.lock);
272 kfree(qos->resume_latency.notifiers);
276 mutex_unlock(&dev_pm_qos_mtx);
278 mutex_unlock(&dev_pm_qos_sysfs_mtx);
281 static bool dev_pm_qos_invalid_request(struct device *dev,
282 struct dev_pm_qos_request *req)
284 return !req || (req->type == DEV_PM_QOS_LATENCY_TOLERANCE
285 && !dev->power.set_latency_tolerance);
288 static int __dev_pm_qos_add_request(struct device *dev,
289 struct dev_pm_qos_request *req,
290 enum dev_pm_qos_req_type type, s32 value)
294 if (!dev || dev_pm_qos_invalid_request(dev, req))
297 if (WARN(dev_pm_qos_request_active(req),
298 "%s() called for already added request\n", __func__))
301 if (IS_ERR(dev->power.qos))
303 else if (!dev->power.qos)
304 ret = dev_pm_qos_constraints_allocate(dev);
306 trace_dev_pm_qos_add_request(dev_name(dev), type, value);
310 ret = apply_constraint(req, PM_QOS_ADD_REQ, value);
316 * dev_pm_qos_add_request - inserts new qos request into the list
317 * @dev: target device for the constraint
318 * @req: pointer to a preallocated handle
319 * @type: type of the request
320 * @value: defines the qos request
322 * This function inserts a new entry in the device constraints list of
323 * requested qos performance characteristics. It recomputes the aggregate
324 * QoS expectations of parameters and initializes the dev_pm_qos_request
325 * handle. Caller needs to save this handle for later use in updates and
328 * Returns 1 if the aggregated constraint value has changed,
329 * 0 if the aggregated constraint value has not changed,
330 * -EINVAL in case of wrong parameters, -ENOMEM if there's not enough memory
331 * to allocate for data structures, -ENODEV if the device has just been removed
334 * Callers should ensure that the target device is not RPM_SUSPENDED before
335 * using this function for requests of type DEV_PM_QOS_FLAGS.
337 int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
338 enum dev_pm_qos_req_type type, s32 value)
342 mutex_lock(&dev_pm_qos_mtx);
343 ret = __dev_pm_qos_add_request(dev, req, type, value);
344 mutex_unlock(&dev_pm_qos_mtx);
347 EXPORT_SYMBOL_GPL(dev_pm_qos_add_request);
350 * __dev_pm_qos_update_request - Modify an existing device PM QoS request.
351 * @req : PM QoS request to modify.
352 * @new_value: New value to request.
354 static int __dev_pm_qos_update_request(struct dev_pm_qos_request *req,
360 if (!req) /*guard against callers passing in null */
363 if (WARN(!dev_pm_qos_request_active(req),
364 "%s() called for unknown object\n", __func__))
367 if (IS_ERR_OR_NULL(req->dev->power.qos))
371 case DEV_PM_QOS_RESUME_LATENCY:
372 case DEV_PM_QOS_LATENCY_TOLERANCE:
373 curr_value = req->data.pnode.prio;
375 case DEV_PM_QOS_FLAGS:
376 curr_value = req->data.flr.flags;
382 trace_dev_pm_qos_update_request(dev_name(req->dev), req->type,
384 if (curr_value != new_value)
385 ret = apply_constraint(req, PM_QOS_UPDATE_REQ, new_value);
391 * dev_pm_qos_update_request - modifies an existing qos request
392 * @req : handle to list element holding a dev_pm_qos request to use
393 * @new_value: defines the qos request
395 * Updates an existing dev PM qos request along with updating the
398 * Attempts are made to make this code callable on hot code paths.
400 * Returns 1 if the aggregated constraint value has changed,
401 * 0 if the aggregated constraint value has not changed,
402 * -EINVAL in case of wrong parameters, -ENODEV if the device has been
403 * removed from the system
405 * Callers should ensure that the target device is not RPM_SUSPENDED before
406 * using this function for requests of type DEV_PM_QOS_FLAGS.
408 int dev_pm_qos_update_request(struct dev_pm_qos_request *req, s32 new_value)
412 mutex_lock(&dev_pm_qos_mtx);
413 ret = __dev_pm_qos_update_request(req, new_value);
414 mutex_unlock(&dev_pm_qos_mtx);
417 EXPORT_SYMBOL_GPL(dev_pm_qos_update_request);
419 static int __dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
423 if (!req) /*guard against callers passing in null */
426 if (WARN(!dev_pm_qos_request_active(req),
427 "%s() called for unknown object\n", __func__))
430 if (IS_ERR_OR_NULL(req->dev->power.qos))
433 trace_dev_pm_qos_remove_request(dev_name(req->dev), req->type,
434 PM_QOS_DEFAULT_VALUE);
435 ret = apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
436 memset(req, 0, sizeof(*req));
441 * dev_pm_qos_remove_request - modifies an existing qos request
442 * @req: handle to request list element
444 * Will remove pm qos request from the list of constraints and
445 * recompute the current target value. Call this on slow code paths.
447 * Returns 1 if the aggregated constraint value has changed,
448 * 0 if the aggregated constraint value has not changed,
449 * -EINVAL in case of wrong parameters, -ENODEV if the device has been
450 * removed from the system
452 * Callers should ensure that the target device is not RPM_SUSPENDED before
453 * using this function for requests of type DEV_PM_QOS_FLAGS.
455 int dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
459 mutex_lock(&dev_pm_qos_mtx);
460 ret = __dev_pm_qos_remove_request(req);
461 mutex_unlock(&dev_pm_qos_mtx);
464 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_request);
467 * dev_pm_qos_add_notifier - sets notification entry for changes to target value
468 * of per-device PM QoS constraints
470 * @dev: target device for the constraint
471 * @notifier: notifier block managed by caller.
473 * Will register the notifier into a notification chain that gets called
474 * upon changes to the target value for the device.
476 * If the device's constraints object doesn't exist when this routine is called,
477 * it will be created (or error code will be returned if that fails).
479 int dev_pm_qos_add_notifier(struct device *dev, struct notifier_block *notifier)
483 mutex_lock(&dev_pm_qos_mtx);
485 if (IS_ERR(dev->power.qos))
487 else if (!dev->power.qos)
488 ret = dev_pm_qos_constraints_allocate(dev);
491 ret = blocking_notifier_chain_register(dev->power.qos->resume_latency.notifiers,
494 mutex_unlock(&dev_pm_qos_mtx);
497 EXPORT_SYMBOL_GPL(dev_pm_qos_add_notifier);
500 * dev_pm_qos_remove_notifier - deletes notification for changes to target value
501 * of per-device PM QoS constraints
503 * @dev: target device for the constraint
504 * @notifier: notifier block to be removed.
506 * Will remove the notifier from the notification chain that gets called
507 * upon changes to the target value.
509 int dev_pm_qos_remove_notifier(struct device *dev,
510 struct notifier_block *notifier)
514 mutex_lock(&dev_pm_qos_mtx);
516 /* Silently return if the constraints object is not present. */
517 if (!IS_ERR_OR_NULL(dev->power.qos))
518 retval = blocking_notifier_chain_unregister(dev->power.qos->resume_latency.notifiers,
521 mutex_unlock(&dev_pm_qos_mtx);
524 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_notifier);
527 * dev_pm_qos_add_ancestor_request - Add PM QoS request for device's ancestor.
528 * @dev: Device whose ancestor to add the request for.
529 * @req: Pointer to the preallocated handle.
530 * @type: Type of the request.
531 * @value: Constraint latency value.
533 int dev_pm_qos_add_ancestor_request(struct device *dev,
534 struct dev_pm_qos_request *req,
535 enum dev_pm_qos_req_type type, s32 value)
537 struct device *ancestor = dev->parent;
541 case DEV_PM_QOS_RESUME_LATENCY:
542 while (ancestor && !ancestor->power.ignore_children)
543 ancestor = ancestor->parent;
546 case DEV_PM_QOS_LATENCY_TOLERANCE:
547 while (ancestor && !ancestor->power.set_latency_tolerance)
548 ancestor = ancestor->parent;
555 ret = dev_pm_qos_add_request(ancestor, req, type, value);
562 EXPORT_SYMBOL_GPL(dev_pm_qos_add_ancestor_request);
564 static void __dev_pm_qos_drop_user_request(struct device *dev,
565 enum dev_pm_qos_req_type type)
567 struct dev_pm_qos_request *req = NULL;
570 case DEV_PM_QOS_RESUME_LATENCY:
571 req = dev->power.qos->resume_latency_req;
572 dev->power.qos->resume_latency_req = NULL;
574 case DEV_PM_QOS_LATENCY_TOLERANCE:
575 req = dev->power.qos->latency_tolerance_req;
576 dev->power.qos->latency_tolerance_req = NULL;
578 case DEV_PM_QOS_FLAGS:
579 req = dev->power.qos->flags_req;
580 dev->power.qos->flags_req = NULL;
583 __dev_pm_qos_remove_request(req);
587 static void dev_pm_qos_drop_user_request(struct device *dev,
588 enum dev_pm_qos_req_type type)
590 mutex_lock(&dev_pm_qos_mtx);
591 __dev_pm_qos_drop_user_request(dev, type);
592 mutex_unlock(&dev_pm_qos_mtx);
596 * dev_pm_qos_expose_latency_limit - Expose PM QoS latency limit to user space.
597 * @dev: Device whose PM QoS latency limit is to be exposed to user space.
598 * @value: Initial value of the latency limit.
600 int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value)
602 struct dev_pm_qos_request *req;
605 if (!device_is_registered(dev) || value < 0)
608 req = kzalloc(sizeof(*req), GFP_KERNEL);
612 ret = dev_pm_qos_add_request(dev, req, DEV_PM_QOS_RESUME_LATENCY, value);
618 mutex_lock(&dev_pm_qos_sysfs_mtx);
620 mutex_lock(&dev_pm_qos_mtx);
622 if (IS_ERR_OR_NULL(dev->power.qos))
624 else if (dev->power.qos->resume_latency_req)
628 __dev_pm_qos_remove_request(req);
630 mutex_unlock(&dev_pm_qos_mtx);
633 dev->power.qos->resume_latency_req = req;
635 mutex_unlock(&dev_pm_qos_mtx);
637 ret = pm_qos_sysfs_add_resume_latency(dev);
639 dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_RESUME_LATENCY);
642 mutex_unlock(&dev_pm_qos_sysfs_mtx);
645 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_latency_limit);
647 static void __dev_pm_qos_hide_latency_limit(struct device *dev)
649 if (!IS_ERR_OR_NULL(dev->power.qos) && dev->power.qos->resume_latency_req)
650 __dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_RESUME_LATENCY);
654 * dev_pm_qos_hide_latency_limit - Hide PM QoS latency limit from user space.
655 * @dev: Device whose PM QoS latency limit is to be hidden from user space.
657 void dev_pm_qos_hide_latency_limit(struct device *dev)
659 mutex_lock(&dev_pm_qos_sysfs_mtx);
661 pm_qos_sysfs_remove_resume_latency(dev);
663 mutex_lock(&dev_pm_qos_mtx);
664 __dev_pm_qos_hide_latency_limit(dev);
665 mutex_unlock(&dev_pm_qos_mtx);
667 mutex_unlock(&dev_pm_qos_sysfs_mtx);
669 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_latency_limit);
672 * dev_pm_qos_expose_flags - Expose PM QoS flags of a device to user space.
673 * @dev: Device whose PM QoS flags are to be exposed to user space.
674 * @val: Initial values of the flags.
676 int dev_pm_qos_expose_flags(struct device *dev, s32 val)
678 struct dev_pm_qos_request *req;
681 if (!device_is_registered(dev))
684 req = kzalloc(sizeof(*req), GFP_KERNEL);
688 ret = dev_pm_qos_add_request(dev, req, DEV_PM_QOS_FLAGS, val);
694 pm_runtime_get_sync(dev);
695 mutex_lock(&dev_pm_qos_sysfs_mtx);
697 mutex_lock(&dev_pm_qos_mtx);
699 if (IS_ERR_OR_NULL(dev->power.qos))
701 else if (dev->power.qos->flags_req)
705 __dev_pm_qos_remove_request(req);
707 mutex_unlock(&dev_pm_qos_mtx);
710 dev->power.qos->flags_req = req;
712 mutex_unlock(&dev_pm_qos_mtx);
714 ret = pm_qos_sysfs_add_flags(dev);
716 dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_FLAGS);
719 mutex_unlock(&dev_pm_qos_sysfs_mtx);
723 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_flags);
725 static void __dev_pm_qos_hide_flags(struct device *dev)
727 if (!IS_ERR_OR_NULL(dev->power.qos) && dev->power.qos->flags_req)
728 __dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_FLAGS);
732 * dev_pm_qos_hide_flags - Hide PM QoS flags of a device from user space.
733 * @dev: Device whose PM QoS flags are to be hidden from user space.
735 void dev_pm_qos_hide_flags(struct device *dev)
737 pm_runtime_get_sync(dev);
738 mutex_lock(&dev_pm_qos_sysfs_mtx);
740 pm_qos_sysfs_remove_flags(dev);
742 mutex_lock(&dev_pm_qos_mtx);
743 __dev_pm_qos_hide_flags(dev);
744 mutex_unlock(&dev_pm_qos_mtx);
746 mutex_unlock(&dev_pm_qos_sysfs_mtx);
749 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_flags);
752 * dev_pm_qos_update_flags - Update PM QoS flags request owned by user space.
753 * @dev: Device to update the PM QoS flags request for.
754 * @mask: Flags to set/clear.
755 * @set: Whether to set or clear the flags (true means set).
757 int dev_pm_qos_update_flags(struct device *dev, s32 mask, bool set)
762 pm_runtime_get_sync(dev);
763 mutex_lock(&dev_pm_qos_mtx);
765 if (IS_ERR_OR_NULL(dev->power.qos) || !dev->power.qos->flags_req) {
770 value = dev_pm_qos_requested_flags(dev);
776 ret = __dev_pm_qos_update_request(dev->power.qos->flags_req, value);
779 mutex_unlock(&dev_pm_qos_mtx);
785 * dev_pm_qos_get_user_latency_tolerance - Get user space latency tolerance.
786 * @dev: Device to obtain the user space latency tolerance for.
788 s32 dev_pm_qos_get_user_latency_tolerance(struct device *dev)
792 mutex_lock(&dev_pm_qos_mtx);
793 ret = IS_ERR_OR_NULL(dev->power.qos)
794 || !dev->power.qos->latency_tolerance_req ?
795 PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT :
796 dev->power.qos->latency_tolerance_req->data.pnode.prio;
797 mutex_unlock(&dev_pm_qos_mtx);
802 * dev_pm_qos_update_user_latency_tolerance - Update user space latency tolerance.
803 * @dev: Device to update the user space latency tolerance for.
804 * @val: New user space latency tolerance for @dev (negative values disable).
806 int dev_pm_qos_update_user_latency_tolerance(struct device *dev, s32 val)
810 mutex_lock(&dev_pm_qos_mtx);
812 if (IS_ERR_OR_NULL(dev->power.qos)
813 || !dev->power.qos->latency_tolerance_req) {
814 struct dev_pm_qos_request *req;
817 if (val == PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT)
823 req = kzalloc(sizeof(*req), GFP_KERNEL);
828 ret = __dev_pm_qos_add_request(dev, req, DEV_PM_QOS_LATENCY_TOLERANCE, val);
833 dev->power.qos->latency_tolerance_req = req;
836 __dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_LATENCY_TOLERANCE);
839 ret = __dev_pm_qos_update_request(dev->power.qos->latency_tolerance_req, val);
844 mutex_unlock(&dev_pm_qos_mtx);
847 EXPORT_SYMBOL_GPL(dev_pm_qos_update_user_latency_tolerance);
850 * dev_pm_qos_expose_latency_tolerance - Expose latency tolerance to userspace
851 * @dev: Device whose latency tolerance to expose
853 int dev_pm_qos_expose_latency_tolerance(struct device *dev)
857 if (!dev->power.set_latency_tolerance)
860 mutex_lock(&dev_pm_qos_sysfs_mtx);
861 ret = pm_qos_sysfs_add_latency_tolerance(dev);
862 mutex_unlock(&dev_pm_qos_sysfs_mtx);
866 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_latency_tolerance);
869 * dev_pm_qos_hide_latency_tolerance - Hide latency tolerance from userspace
870 * @dev: Device whose latency tolerance to hide
872 void dev_pm_qos_hide_latency_tolerance(struct device *dev)
874 mutex_lock(&dev_pm_qos_sysfs_mtx);
875 pm_qos_sysfs_remove_latency_tolerance(dev);
876 mutex_unlock(&dev_pm_qos_sysfs_mtx);
878 /* Remove the request from user space now */
879 pm_runtime_get_sync(dev);
880 dev_pm_qos_update_user_latency_tolerance(dev,
881 PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT);
884 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_latency_tolerance);