x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / base / power / qos.c
blob5c1361a9e5dd58049c3835d414f42607cdb46411
1 /*
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
13 * of:
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 different types of notification callbacks:
21 * . a per-device notification callback using the dev_pm_qos_*_notifier API.
22 * The notification chain data is stored in the per-device constraint
23 * data struct.
24 * . a system-wide notification callback using the dev_pm_qos_*_global_notifier
25 * API. The notification chain data is stored in a static variable.
27 * Note about the per-device constraint data struct allocation:
28 * . The per-device constraints data struct ptr is tored into the device
29 * dev_pm_info.
30 * . To minimize the data usage by the per-device constraints, the data struct
31 * is only allocated at the first call to dev_pm_qos_add_request.
32 * . The data is later free'd when the device is removed from the system.
33 * . A global mutex protects the constraints users from the data being
34 * allocated and free'd.
37 #include <linux/pm_qos.h>
38 #include <linux/spinlock.h>
39 #include <linux/slab.h>
40 #include <linux/device.h>
41 #include <linux/mutex.h>
42 #include <linux/export.h>
43 #include <linux/pm_runtime.h>
44 #include <linux/err.h>
45 #include <trace/events/power.h>
47 #include "power.h"
49 static DEFINE_MUTEX(dev_pm_qos_mtx);
50 static DEFINE_MUTEX(dev_pm_qos_sysfs_mtx);
52 static BLOCKING_NOTIFIER_HEAD(dev_pm_notifiers);
54 /**
55 * __dev_pm_qos_flags - Check PM QoS flags for a given device.
56 * @dev: Device to check the PM QoS flags for.
57 * @mask: Flags to check against.
59 * This routine must be called with dev->power.lock held.
61 enum pm_qos_flags_status __dev_pm_qos_flags(struct device *dev, s32 mask)
63 struct dev_pm_qos *qos = dev->power.qos;
64 struct pm_qos_flags *pqf;
65 s32 val;
67 if (IS_ERR_OR_NULL(qos))
68 return PM_QOS_FLAGS_UNDEFINED;
70 pqf = &qos->flags;
71 if (list_empty(&pqf->list))
72 return PM_QOS_FLAGS_UNDEFINED;
74 val = pqf->effective_flags & mask;
75 if (val)
76 return (val == mask) ? PM_QOS_FLAGS_ALL : PM_QOS_FLAGS_SOME;
78 return PM_QOS_FLAGS_NONE;
81 /**
82 * dev_pm_qos_flags - Check PM QoS flags for a given device (locked).
83 * @dev: Device to check the PM QoS flags for.
84 * @mask: Flags to check against.
86 enum pm_qos_flags_status dev_pm_qos_flags(struct device *dev, s32 mask)
88 unsigned long irqflags;
89 enum pm_qos_flags_status ret;
91 spin_lock_irqsave(&dev->power.lock, irqflags);
92 ret = __dev_pm_qos_flags(dev, mask);
93 spin_unlock_irqrestore(&dev->power.lock, irqflags);
95 return ret;
97 EXPORT_SYMBOL_GPL(dev_pm_qos_flags);
99 /**
100 * __dev_pm_qos_read_value - Get PM QoS constraint for a given device.
101 * @dev: Device to get the PM QoS constraint value for.
103 * This routine must be called with dev->power.lock held.
105 s32 __dev_pm_qos_read_value(struct device *dev)
107 return IS_ERR_OR_NULL(dev->power.qos) ?
108 0 : pm_qos_read_value(&dev->power.qos->latency);
112 * dev_pm_qos_read_value - Get PM QoS constraint for a given device (locked).
113 * @dev: Device to get the PM QoS constraint value for.
115 s32 dev_pm_qos_read_value(struct device *dev)
117 unsigned long flags;
118 s32 ret;
120 spin_lock_irqsave(&dev->power.lock, flags);
121 ret = __dev_pm_qos_read_value(dev);
122 spin_unlock_irqrestore(&dev->power.lock, flags);
124 return ret;
128 * apply_constraint - Add/modify/remove device PM QoS request.
129 * @req: Constraint request to apply
130 * @action: Action to perform (add/update/remove).
131 * @value: Value to assign to the QoS request.
133 * Internal function to update the constraints list using the PM QoS core
134 * code and if needed call the per-device and the global notification
135 * callbacks
137 static int apply_constraint(struct dev_pm_qos_request *req,
138 enum pm_qos_req_action action, s32 value)
140 struct dev_pm_qos *qos = req->dev->power.qos;
141 int ret;
143 switch(req->type) {
144 case DEV_PM_QOS_LATENCY:
145 ret = pm_qos_update_target(&qos->latency, &req->data.pnode,
146 action, value);
147 if (ret) {
148 value = pm_qos_read_value(&qos->latency);
149 blocking_notifier_call_chain(&dev_pm_notifiers,
150 (unsigned long)value,
151 req);
153 break;
154 case DEV_PM_QOS_FLAGS:
155 ret = pm_qos_update_flags(&qos->flags, &req->data.flr,
156 action, value);
157 break;
158 default:
159 ret = -EINVAL;
162 return ret;
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);
179 if (!qos)
180 return -ENOMEM;
182 n = kzalloc(sizeof(*n), GFP_KERNEL);
183 if (!n) {
184 kfree(qos);
185 return -ENOMEM;
187 BLOCKING_INIT_NOTIFIER_HEAD(n);
189 c = &qos->latency;
190 plist_head_init(&c->list);
191 c->target_value = PM_QOS_DEV_LAT_DEFAULT_VALUE;
192 c->default_value = PM_QOS_DEV_LAT_DEFAULT_VALUE;
193 c->type = PM_QOS_MIN;
194 c->notifiers = n;
196 INIT_LIST_HEAD(&qos->flags.list);
198 spin_lock_irq(&dev->power.lock);
199 dev->power.qos = qos;
200 spin_unlock_irq(&dev->power.lock);
202 return 0;
205 static void __dev_pm_qos_hide_latency_limit(struct device *dev);
206 static void __dev_pm_qos_hide_flags(struct device *dev);
209 * dev_pm_qos_constraints_destroy
210 * @dev: target device
212 * Called from the device PM subsystem on device removal under device_pm_lock().
214 void dev_pm_qos_constraints_destroy(struct device *dev)
216 struct dev_pm_qos *qos;
217 struct dev_pm_qos_request *req, *tmp;
218 struct pm_qos_constraints *c;
219 struct pm_qos_flags *f;
221 mutex_lock(&dev_pm_qos_sysfs_mtx);
224 * If the device's PM QoS resume latency limit or PM QoS flags have been
225 * exposed to user space, they have to be hidden at this point.
227 pm_qos_sysfs_remove_latency(dev);
228 pm_qos_sysfs_remove_flags(dev);
230 mutex_lock(&dev_pm_qos_mtx);
232 __dev_pm_qos_hide_latency_limit(dev);
233 __dev_pm_qos_hide_flags(dev);
235 qos = dev->power.qos;
236 if (!qos)
237 goto out;
239 /* Flush the constraints lists for the device. */
240 c = &qos->latency;
241 plist_for_each_entry_safe(req, tmp, &c->list, data.pnode) {
243 * Update constraints list and call the notification
244 * callbacks if needed
246 apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
247 memset(req, 0, sizeof(*req));
249 f = &qos->flags;
250 list_for_each_entry_safe(req, tmp, &f->list, data.flr.node) {
251 apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
252 memset(req, 0, sizeof(*req));
255 spin_lock_irq(&dev->power.lock);
256 dev->power.qos = ERR_PTR(-ENODEV);
257 spin_unlock_irq(&dev->power.lock);
259 kfree(c->notifiers);
260 kfree(qos);
262 out:
263 mutex_unlock(&dev_pm_qos_mtx);
265 mutex_unlock(&dev_pm_qos_sysfs_mtx);
269 * dev_pm_qos_add_request - inserts new qos request into the list
270 * @dev: target device for the constraint
271 * @req: pointer to a preallocated handle
272 * @type: type of the request
273 * @value: defines the qos request
275 * This function inserts a new entry in the device constraints list of
276 * requested qos performance characteristics. It recomputes the aggregate
277 * QoS expectations of parameters and initializes the dev_pm_qos_request
278 * handle. Caller needs to save this handle for later use in updates and
279 * removal.
281 * Returns 1 if the aggregated constraint value has changed,
282 * 0 if the aggregated constraint value has not changed,
283 * -EINVAL in case of wrong parameters, -ENOMEM if there's not enough memory
284 * to allocate for data structures, -ENODEV if the device has just been removed
285 * from the system.
287 * Callers should ensure that the target device is not RPM_SUSPENDED before
288 * using this function for requests of type DEV_PM_QOS_FLAGS.
290 int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
291 enum dev_pm_qos_req_type type, s32 value)
293 int ret = 0;
295 if (!dev || !req) /*guard against callers passing in null */
296 return -EINVAL;
298 if (WARN(dev_pm_qos_request_active(req),
299 "%s() called for already added request\n", __func__))
300 return -EINVAL;
302 mutex_lock(&dev_pm_qos_mtx);
304 if (IS_ERR(dev->power.qos))
305 ret = -ENODEV;
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);
310 if (!ret) {
311 req->dev = dev;
312 req->type = type;
313 ret = apply_constraint(req, PM_QOS_ADD_REQ, value);
316 mutex_unlock(&dev_pm_qos_mtx);
318 return ret;
320 EXPORT_SYMBOL_GPL(dev_pm_qos_add_request);
323 * __dev_pm_qos_update_request - Modify an existing device PM QoS request.
324 * @req : PM QoS request to modify.
325 * @new_value: New value to request.
327 static int __dev_pm_qos_update_request(struct dev_pm_qos_request *req,
328 s32 new_value)
330 s32 curr_value;
331 int ret = 0;
333 if (!req) /*guard against callers passing in null */
334 return -EINVAL;
336 if (WARN(!dev_pm_qos_request_active(req),
337 "%s() called for unknown object\n", __func__))
338 return -EINVAL;
340 if (IS_ERR_OR_NULL(req->dev->power.qos))
341 return -ENODEV;
343 switch(req->type) {
344 case DEV_PM_QOS_LATENCY:
345 curr_value = req->data.pnode.prio;
346 break;
347 case DEV_PM_QOS_FLAGS:
348 curr_value = req->data.flr.flags;
349 break;
350 default:
351 return -EINVAL;
354 trace_dev_pm_qos_update_request(dev_name(req->dev), req->type,
355 new_value);
356 if (curr_value != new_value)
357 ret = apply_constraint(req, PM_QOS_UPDATE_REQ, new_value);
359 return ret;
363 * dev_pm_qos_update_request - modifies an existing qos request
364 * @req : handle to list element holding a dev_pm_qos request to use
365 * @new_value: defines the qos request
367 * Updates an existing dev PM qos request along with updating the
368 * target value.
370 * Attempts are made to make this code callable on hot code paths.
372 * Returns 1 if the aggregated constraint value has changed,
373 * 0 if the aggregated constraint value has not changed,
374 * -EINVAL in case of wrong parameters, -ENODEV if the device has been
375 * removed from the system
377 * Callers should ensure that the target device is not RPM_SUSPENDED before
378 * using this function for requests of type DEV_PM_QOS_FLAGS.
380 int dev_pm_qos_update_request(struct dev_pm_qos_request *req, s32 new_value)
382 int ret;
384 mutex_lock(&dev_pm_qos_mtx);
385 ret = __dev_pm_qos_update_request(req, new_value);
386 mutex_unlock(&dev_pm_qos_mtx);
387 return ret;
389 EXPORT_SYMBOL_GPL(dev_pm_qos_update_request);
391 static int __dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
393 int ret;
395 if (!req) /*guard against callers passing in null */
396 return -EINVAL;
398 if (WARN(!dev_pm_qos_request_active(req),
399 "%s() called for unknown object\n", __func__))
400 return -EINVAL;
402 if (IS_ERR_OR_NULL(req->dev->power.qos))
403 return -ENODEV;
405 trace_dev_pm_qos_remove_request(dev_name(req->dev), req->type,
406 PM_QOS_DEFAULT_VALUE);
407 ret = apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
408 memset(req, 0, sizeof(*req));
409 return ret;
413 * dev_pm_qos_remove_request - modifies an existing qos request
414 * @req: handle to request list element
416 * Will remove pm qos request from the list of constraints and
417 * recompute the current target value. Call this on slow code paths.
419 * Returns 1 if the aggregated constraint value has changed,
420 * 0 if the aggregated constraint value has not changed,
421 * -EINVAL in case of wrong parameters, -ENODEV if the device has been
422 * removed from the system
424 * Callers should ensure that the target device is not RPM_SUSPENDED before
425 * using this function for requests of type DEV_PM_QOS_FLAGS.
427 int dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
429 int ret;
431 mutex_lock(&dev_pm_qos_mtx);
432 ret = __dev_pm_qos_remove_request(req);
433 mutex_unlock(&dev_pm_qos_mtx);
434 return ret;
436 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_request);
439 * dev_pm_qos_add_notifier - sets notification entry for changes to target value
440 * of per-device PM QoS constraints
442 * @dev: target device for the constraint
443 * @notifier: notifier block managed by caller.
445 * Will register the notifier into a notification chain that gets called
446 * upon changes to the target value for the device.
448 * If the device's constraints object doesn't exist when this routine is called,
449 * it will be created (or error code will be returned if that fails).
451 int dev_pm_qos_add_notifier(struct device *dev, struct notifier_block *notifier)
453 int ret = 0;
455 mutex_lock(&dev_pm_qos_mtx);
457 if (IS_ERR(dev->power.qos))
458 ret = -ENODEV;
459 else if (!dev->power.qos)
460 ret = dev_pm_qos_constraints_allocate(dev);
462 if (!ret)
463 ret = blocking_notifier_chain_register(
464 dev->power.qos->latency.notifiers, notifier);
466 mutex_unlock(&dev_pm_qos_mtx);
467 return ret;
469 EXPORT_SYMBOL_GPL(dev_pm_qos_add_notifier);
472 * dev_pm_qos_remove_notifier - deletes notification for changes to target value
473 * of per-device PM QoS constraints
475 * @dev: target device for the constraint
476 * @notifier: notifier block to be removed.
478 * Will remove the notifier from the notification chain that gets called
479 * upon changes to the target value.
481 int dev_pm_qos_remove_notifier(struct device *dev,
482 struct notifier_block *notifier)
484 int retval = 0;
486 mutex_lock(&dev_pm_qos_mtx);
488 /* Silently return if the constraints object is not present. */
489 if (!IS_ERR_OR_NULL(dev->power.qos))
490 retval = blocking_notifier_chain_unregister(
491 dev->power.qos->latency.notifiers,
492 notifier);
494 mutex_unlock(&dev_pm_qos_mtx);
495 return retval;
497 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_notifier);
500 * dev_pm_qos_add_global_notifier - sets notification entry for changes to
501 * target value of the PM QoS constraints for any device
503 * @notifier: notifier block managed by caller.
505 * Will register the notifier into a notification chain that gets called
506 * upon changes to the target value for any device.
508 int dev_pm_qos_add_global_notifier(struct notifier_block *notifier)
510 return blocking_notifier_chain_register(&dev_pm_notifiers, notifier);
512 EXPORT_SYMBOL_GPL(dev_pm_qos_add_global_notifier);
515 * dev_pm_qos_remove_global_notifier - deletes notification for changes to
516 * target value of PM QoS constraints for any device
518 * @notifier: notifier block to be removed.
520 * Will remove the notifier from the notification chain that gets called
521 * upon changes to the target value for any device.
523 int dev_pm_qos_remove_global_notifier(struct notifier_block *notifier)
525 return blocking_notifier_chain_unregister(&dev_pm_notifiers, notifier);
527 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_global_notifier);
530 * dev_pm_qos_add_ancestor_request - Add PM QoS request for device's ancestor.
531 * @dev: Device whose ancestor to add the request for.
532 * @req: Pointer to the preallocated handle.
533 * @value: Constraint latency value.
535 int dev_pm_qos_add_ancestor_request(struct device *dev,
536 struct dev_pm_qos_request *req, s32 value)
538 struct device *ancestor = dev->parent;
539 int ret = -ENODEV;
541 while (ancestor && !ancestor->power.ignore_children)
542 ancestor = ancestor->parent;
544 if (ancestor)
545 ret = dev_pm_qos_add_request(ancestor, req,
546 DEV_PM_QOS_LATENCY, value);
548 if (ret < 0)
549 req->dev = NULL;
551 return ret;
553 EXPORT_SYMBOL_GPL(dev_pm_qos_add_ancestor_request);
555 #ifdef CONFIG_PM_RUNTIME
556 static void __dev_pm_qos_drop_user_request(struct device *dev,
557 enum dev_pm_qos_req_type type)
559 struct dev_pm_qos_request *req = NULL;
561 switch(type) {
562 case DEV_PM_QOS_LATENCY:
563 req = dev->power.qos->latency_req;
564 dev->power.qos->latency_req = NULL;
565 break;
566 case DEV_PM_QOS_FLAGS:
567 req = dev->power.qos->flags_req;
568 dev->power.qos->flags_req = NULL;
569 break;
571 __dev_pm_qos_remove_request(req);
572 kfree(req);
575 static void dev_pm_qos_drop_user_request(struct device *dev,
576 enum dev_pm_qos_req_type type)
578 mutex_lock(&dev_pm_qos_mtx);
579 __dev_pm_qos_drop_user_request(dev, type);
580 mutex_unlock(&dev_pm_qos_mtx);
584 * dev_pm_qos_expose_latency_limit - Expose PM QoS latency limit to user space.
585 * @dev: Device whose PM QoS latency limit is to be exposed to user space.
586 * @value: Initial value of the latency limit.
588 int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value)
590 struct dev_pm_qos_request *req;
591 int ret;
593 if (!device_is_registered(dev) || value < 0)
594 return -EINVAL;
596 req = kzalloc(sizeof(*req), GFP_KERNEL);
597 if (!req)
598 return -ENOMEM;
600 ret = dev_pm_qos_add_request(dev, req, DEV_PM_QOS_LATENCY, value);
601 if (ret < 0) {
602 kfree(req);
603 return ret;
606 mutex_lock(&dev_pm_qos_sysfs_mtx);
608 mutex_lock(&dev_pm_qos_mtx);
610 if (IS_ERR_OR_NULL(dev->power.qos))
611 ret = -ENODEV;
612 else if (dev->power.qos->latency_req)
613 ret = -EEXIST;
615 if (ret < 0) {
616 __dev_pm_qos_remove_request(req);
617 kfree(req);
618 mutex_unlock(&dev_pm_qos_mtx);
619 goto out;
621 dev->power.qos->latency_req = req;
623 mutex_unlock(&dev_pm_qos_mtx);
625 ret = pm_qos_sysfs_add_latency(dev);
626 if (ret)
627 dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_LATENCY);
629 out:
630 mutex_unlock(&dev_pm_qos_sysfs_mtx);
631 return ret;
633 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_latency_limit);
635 static void __dev_pm_qos_hide_latency_limit(struct device *dev)
637 if (!IS_ERR_OR_NULL(dev->power.qos) && dev->power.qos->latency_req)
638 __dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_LATENCY);
642 * dev_pm_qos_hide_latency_limit - Hide PM QoS latency limit from user space.
643 * @dev: Device whose PM QoS latency limit is to be hidden from user space.
645 void dev_pm_qos_hide_latency_limit(struct device *dev)
647 mutex_lock(&dev_pm_qos_sysfs_mtx);
649 pm_qos_sysfs_remove_latency(dev);
651 mutex_lock(&dev_pm_qos_mtx);
652 __dev_pm_qos_hide_latency_limit(dev);
653 mutex_unlock(&dev_pm_qos_mtx);
655 mutex_unlock(&dev_pm_qos_sysfs_mtx);
657 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_latency_limit);
660 * dev_pm_qos_expose_flags - Expose PM QoS flags of a device to user space.
661 * @dev: Device whose PM QoS flags are to be exposed to user space.
662 * @val: Initial values of the flags.
664 int dev_pm_qos_expose_flags(struct device *dev, s32 val)
666 struct dev_pm_qos_request *req;
667 int ret;
669 if (!device_is_registered(dev))
670 return -EINVAL;
672 req = kzalloc(sizeof(*req), GFP_KERNEL);
673 if (!req)
674 return -ENOMEM;
676 ret = dev_pm_qos_add_request(dev, req, DEV_PM_QOS_FLAGS, val);
677 if (ret < 0) {
678 kfree(req);
679 return ret;
682 pm_runtime_get_sync(dev);
683 mutex_lock(&dev_pm_qos_sysfs_mtx);
685 mutex_lock(&dev_pm_qos_mtx);
687 if (IS_ERR_OR_NULL(dev->power.qos))
688 ret = -ENODEV;
689 else if (dev->power.qos->flags_req)
690 ret = -EEXIST;
692 if (ret < 0) {
693 __dev_pm_qos_remove_request(req);
694 kfree(req);
695 mutex_unlock(&dev_pm_qos_mtx);
696 goto out;
698 dev->power.qos->flags_req = req;
700 mutex_unlock(&dev_pm_qos_mtx);
702 ret = pm_qos_sysfs_add_flags(dev);
703 if (ret)
704 dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_FLAGS);
706 out:
707 mutex_unlock(&dev_pm_qos_sysfs_mtx);
708 pm_runtime_put(dev);
709 return ret;
711 EXPORT_SYMBOL_GPL(dev_pm_qos_expose_flags);
713 static void __dev_pm_qos_hide_flags(struct device *dev)
715 if (!IS_ERR_OR_NULL(dev->power.qos) && dev->power.qos->flags_req)
716 __dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_FLAGS);
720 * dev_pm_qos_hide_flags - Hide PM QoS flags of a device from user space.
721 * @dev: Device whose PM QoS flags are to be hidden from user space.
723 void dev_pm_qos_hide_flags(struct device *dev)
725 pm_runtime_get_sync(dev);
726 mutex_lock(&dev_pm_qos_sysfs_mtx);
728 pm_qos_sysfs_remove_flags(dev);
730 mutex_lock(&dev_pm_qos_mtx);
731 __dev_pm_qos_hide_flags(dev);
732 mutex_unlock(&dev_pm_qos_mtx);
734 mutex_unlock(&dev_pm_qos_sysfs_mtx);
735 pm_runtime_put(dev);
737 EXPORT_SYMBOL_GPL(dev_pm_qos_hide_flags);
740 * dev_pm_qos_update_flags - Update PM QoS flags request owned by user space.
741 * @dev: Device to update the PM QoS flags request for.
742 * @mask: Flags to set/clear.
743 * @set: Whether to set or clear the flags (true means set).
745 int dev_pm_qos_update_flags(struct device *dev, s32 mask, bool set)
747 s32 value;
748 int ret;
750 pm_runtime_get_sync(dev);
751 mutex_lock(&dev_pm_qos_mtx);
753 if (IS_ERR_OR_NULL(dev->power.qos) || !dev->power.qos->flags_req) {
754 ret = -EINVAL;
755 goto out;
758 value = dev_pm_qos_requested_flags(dev);
759 if (set)
760 value |= mask;
761 else
762 value &= ~mask;
764 ret = __dev_pm_qos_update_request(dev->power.qos->flags_req, value);
766 out:
767 mutex_unlock(&dev_pm_qos_mtx);
768 pm_runtime_put(dev);
769 return ret;
771 #else /* !CONFIG_PM_RUNTIME */
772 static void __dev_pm_qos_hide_latency_limit(struct device *dev) {}
773 static void __dev_pm_qos_hide_flags(struct device *dev) {}
774 #endif /* CONFIG_PM_RUNTIME */