1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Power Management Quality of Service (PM QoS) support base.
4 *
5 * Copyright (C) 2020 Intel Corporation
6 *
7 * Authors:
8 * Mark Gross <mgross@linux.intel.com>
9 * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
10 *
11 * Provided here is an interface for specifying PM QoS dependencies. It allows
12 * entities depending on QoS constraints to register their requests which are
13 * aggregated as appropriate to produce effective constraints (target values)
14 * that can be monitored by entities needing to respect them, either by polling
15 * or through a built-in notification mechanism.
16 *
17 * In addition to the basic functionality, more specific interfaces for managing
18 * global CPU latency QoS requests and frequency QoS requests are provided.
19 */
20
21 /*#define DEBUG*/
22
23 #include <linux/pm_qos.h>
24 #include <linux/sched.h>
25 #include <linux/spinlock.h>
26 #include <linux/slab.h>
27 #include <linux/time.h>
28 #include <linux/fs.h>
29 #include <linux/device.h>
30 #include <linux/miscdevice.h>
31 #include <linux/string.h>
32 #include <linux/platform_device.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/debugfs.h>
36 #include <linux/seq_file.h>
37
38 #include <linux/uaccess.h>
39 #include <linux/export.h>
40 #include <trace/events/power.h>
41 #include <trace/hooks/power.h>
42
43 /*
44 * locking rule: all changes to constraints or notifiers lists
45 * or pm_qos_object list and pm_qos_objects need to happen with pm_qos_lock
46 * held, taken with _irqsave. One lock to rule them all
47 */
48 static DEFINE_SPINLOCK(pm_qos_lock);
49
50 /**
51 * pm_qos_read_value - Return the current effective constraint value.
52 * @c: List of PM QoS constraint requests.
53 */
pm_qos_read_value(struct pm_qos_constraints * c)54 s32 pm_qos_read_value(struct pm_qos_constraints *c)
55 {
56 return READ_ONCE(c->target_value);
57 }
58
pm_qos_get_value(struct pm_qos_constraints * c)59 static int pm_qos_get_value(struct pm_qos_constraints *c)
60 {
61 if (plist_head_empty(&c->list))
62 return c->no_constraint_value;
63
64 switch (c->type) {
65 case PM_QOS_MIN:
66 return plist_first(&c->list)->prio;
67
68 case PM_QOS_MAX:
69 return plist_last(&c->list)->prio;
70
71 default:
72 WARN(1, "Unknown PM QoS type in %s\n", __func__);
73 return PM_QOS_DEFAULT_VALUE;
74 }
75 }
76
pm_qos_set_value(struct pm_qos_constraints * c,s32 value)77 static void pm_qos_set_value(struct pm_qos_constraints *c, s32 value)
78 {
79 WRITE_ONCE(c->target_value, value);
80 }
81
82 /**
83 * pm_qos_update_target - Update a list of PM QoS constraint requests.
84 * @c: List of PM QoS requests.
85 * @node: Target list entry.
86 * @action: Action to carry out (add, update or remove).
87 * @value: New request value for the target list entry.
88 *
89 * Update the given list of PM QoS constraint requests, @c, by carrying an
90 * @action involving the @node list entry and @value on it.
91 *
92 * The recognized values of @action are PM_QOS_ADD_REQ (store @value in @node
93 * and add it to the list), PM_QOS_UPDATE_REQ (remove @node from the list, store
94 * @value in it and add it to the list again), and PM_QOS_REMOVE_REQ (remove
95 * @node from the list, ignore @value).
96 *
97 * Return: 1 if the aggregate constraint value has changed, 0 otherwise.
98 */
pm_qos_update_target(struct pm_qos_constraints * c,struct plist_node * node,enum pm_qos_req_action action,int value)99 int pm_qos_update_target(struct pm_qos_constraints *c, struct plist_node *node,
100 enum pm_qos_req_action action, int value)
101 {
102 int prev_value, curr_value, new_value;
103 unsigned long flags;
104
105 spin_lock_irqsave(&pm_qos_lock, flags);
106
107 prev_value = pm_qos_get_value(c);
108 if (value == PM_QOS_DEFAULT_VALUE)
109 new_value = c->default_value;
110 else
111 new_value = value;
112
113 switch (action) {
114 case PM_QOS_REMOVE_REQ:
115 plist_del(node, &c->list);
116 break;
117 case PM_QOS_UPDATE_REQ:
118 /*
119 * To change the list, atomically remove, reinit with new value
120 * and add, then see if the aggregate has changed.
121 */
122 plist_del(node, &c->list);
123 fallthrough;
124 case PM_QOS_ADD_REQ:
125 plist_node_init(node, new_value);
126 plist_add(node, &c->list);
127 break;
128 default:
129 /* no action */
130 ;
131 }
132
133 curr_value = pm_qos_get_value(c);
134 pm_qos_set_value(c, curr_value);
135
136 spin_unlock_irqrestore(&pm_qos_lock, flags);
137
138 trace_pm_qos_update_target(action, prev_value, curr_value);
139
140 if (prev_value == curr_value)
141 return 0;
142
143 if (c->notifiers)
144 blocking_notifier_call_chain(c->notifiers, curr_value, NULL);
145
146 return 1;
147 }
148
149 /**
150 * pm_qos_flags_remove_req - Remove device PM QoS flags request.
151 * @pqf: Device PM QoS flags set to remove the request from.
152 * @req: Request to remove from the set.
153 */
pm_qos_flags_remove_req(struct pm_qos_flags * pqf,struct pm_qos_flags_request * req)154 static void pm_qos_flags_remove_req(struct pm_qos_flags *pqf,
155 struct pm_qos_flags_request *req)
156 {
157 s32 val = 0;
158
159 list_del(&req->node);
160 list_for_each_entry(req, &pqf->list, node)
161 val |= req->flags;
162
163 pqf->effective_flags = val;
164 }
165
166 /**
167 * pm_qos_update_flags - Update a set of PM QoS flags.
168 * @pqf: Set of PM QoS flags to update.
169 * @req: Request to add to the set, to modify, or to remove from the set.
170 * @action: Action to take on the set.
171 * @val: Value of the request to add or modify.
172 *
173 * Return: 1 if the aggregate constraint value has changed, 0 otherwise.
174 */
pm_qos_update_flags(struct pm_qos_flags * pqf,struct pm_qos_flags_request * req,enum pm_qos_req_action action,s32 val)175 bool pm_qos_update_flags(struct pm_qos_flags *pqf,
176 struct pm_qos_flags_request *req,
177 enum pm_qos_req_action action, s32 val)
178 {
179 unsigned long irqflags;
180 s32 prev_value, curr_value;
181
182 spin_lock_irqsave(&pm_qos_lock, irqflags);
183
184 prev_value = list_empty(&pqf->list) ? 0 : pqf->effective_flags;
185
186 switch (action) {
187 case PM_QOS_REMOVE_REQ:
188 pm_qos_flags_remove_req(pqf, req);
189 break;
190 case PM_QOS_UPDATE_REQ:
191 pm_qos_flags_remove_req(pqf, req);
192 fallthrough;
193 case PM_QOS_ADD_REQ:
194 req->flags = val;
195 INIT_LIST_HEAD(&req->node);
196 list_add_tail(&req->node, &pqf->list);
197 pqf->effective_flags |= val;
198 break;
199 default:
200 /* no action */
201 ;
202 }
203
204 curr_value = list_empty(&pqf->list) ? 0 : pqf->effective_flags;
205
206 spin_unlock_irqrestore(&pm_qos_lock, irqflags);
207
208 trace_pm_qos_update_flags(action, prev_value, curr_value);
209
210 return prev_value != curr_value;
211 }
212
213 #ifdef CONFIG_CPU_IDLE
214 /* Definitions related to the CPU latency QoS. */
215
216 static struct pm_qos_constraints cpu_latency_constraints = {
217 .list = PLIST_HEAD_INIT(cpu_latency_constraints.list),
218 .target_value = PM_QOS_CPU_LATENCY_DEFAULT_VALUE,
219 .default_value = PM_QOS_CPU_LATENCY_DEFAULT_VALUE,
220 .no_constraint_value = PM_QOS_CPU_LATENCY_DEFAULT_VALUE,
221 .type = PM_QOS_MIN,
222 };
223
cpu_latency_qos_value_invalid(s32 value)224 static inline bool cpu_latency_qos_value_invalid(s32 value)
225 {
226 return value < 0 && value != PM_QOS_DEFAULT_VALUE;
227 }
228
229 /**
230 * cpu_latency_qos_limit - Return current system-wide CPU latency QoS limit.
231 */
cpu_latency_qos_limit(void)232 s32 cpu_latency_qos_limit(void)
233 {
234 return pm_qos_read_value(&cpu_latency_constraints);
235 }
236
237 /**
238 * cpu_latency_qos_request_active - Check the given PM QoS request.
239 * @req: PM QoS request to check.
240 *
241 * Return: 'true' if @req has been added to the CPU latency QoS list, 'false'
242 * otherwise.
243 */
cpu_latency_qos_request_active(struct pm_qos_request * req)244 bool cpu_latency_qos_request_active(struct pm_qos_request *req)
245 {
246 return req->qos == &cpu_latency_constraints;
247 }
248 EXPORT_SYMBOL_GPL(cpu_latency_qos_request_active);
249
cpu_latency_qos_apply(struct pm_qos_request * req,enum pm_qos_req_action action,s32 value)250 static void cpu_latency_qos_apply(struct pm_qos_request *req,
251 enum pm_qos_req_action action, s32 value)
252 {
253 int ret = pm_qos_update_target(req->qos, &req->node, action, value);
254 if (ret > 0)
255 wake_up_all_idle_cpus();
256 }
257
258 /**
259 * cpu_latency_qos_add_request - Add new CPU latency QoS request.
260 * @req: Pointer to a preallocated handle.
261 * @value: Requested constraint value.
262 *
263 * Use @value to initialize the request handle pointed to by @req, insert it as
264 * a new entry to the CPU latency QoS list and recompute the effective QoS
265 * constraint for that list.
266 *
267 * Callers need to save the handle for later use in updates and removal of the
268 * QoS request represented by it.
269 */
cpu_latency_qos_add_request(struct pm_qos_request * req,s32 value)270 void cpu_latency_qos_add_request(struct pm_qos_request *req, s32 value)
271 {
272 if (!req || cpu_latency_qos_value_invalid(value))
273 return;
274
275 if (cpu_latency_qos_request_active(req)) {
276 WARN(1, KERN_ERR "%s called for already added request\n", __func__);
277 return;
278 }
279
280 trace_pm_qos_add_request(value);
281
282 req->qos = &cpu_latency_constraints;
283 cpu_latency_qos_apply(req, PM_QOS_ADD_REQ, value);
284 }
285 EXPORT_SYMBOL_GPL(cpu_latency_qos_add_request);
286
287 /**
288 * cpu_latency_qos_update_request - Modify existing CPU latency QoS request.
289 * @req : QoS request to update.
290 * @new_value: New requested constraint value.
291 *
292 * Use @new_value to update the QoS request represented by @req in the CPU
293 * latency QoS list along with updating the effective constraint value for that
294 * list.
295 */
cpu_latency_qos_update_request(struct pm_qos_request * req,s32 new_value)296 void cpu_latency_qos_update_request(struct pm_qos_request *req, s32 new_value)
297 {
298 if (!req || cpu_latency_qos_value_invalid(new_value))
299 return;
300
301 if (!cpu_latency_qos_request_active(req)) {
302 WARN(1, KERN_ERR "%s called for unknown object\n", __func__);
303 return;
304 }
305
306 trace_pm_qos_update_request(new_value);
307
308 if (new_value == req->node.prio)
309 return;
310
311 cpu_latency_qos_apply(req, PM_QOS_UPDATE_REQ, new_value);
312 }
313 EXPORT_SYMBOL_GPL(cpu_latency_qos_update_request);
314
315 /**
316 * cpu_latency_qos_remove_request - Remove existing CPU latency QoS request.
317 * @req: QoS request to remove.
318 *
319 * Remove the CPU latency QoS request represented by @req from the CPU latency
320 * QoS list along with updating the effective constraint value for that list.
321 */
cpu_latency_qos_remove_request(struct pm_qos_request * req)322 void cpu_latency_qos_remove_request(struct pm_qos_request *req)
323 {
324 if (!req)
325 return;
326
327 if (!cpu_latency_qos_request_active(req)) {
328 WARN(1, KERN_ERR "%s called for unknown object\n", __func__);
329 return;
330 }
331
332 trace_pm_qos_remove_request(PM_QOS_DEFAULT_VALUE);
333
334 cpu_latency_qos_apply(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
335 memset(req, 0, sizeof(*req));
336 }
337 EXPORT_SYMBOL_GPL(cpu_latency_qos_remove_request);
338
339 /* User space interface to the CPU latency QoS via misc device. */
340
cpu_latency_qos_open(struct inode * inode,struct file * filp)341 static int cpu_latency_qos_open(struct inode *inode, struct file *filp)
342 {
343 struct pm_qos_request *req;
344
345 req = kzalloc(sizeof(*req), GFP_KERNEL);
346 if (!req)
347 return -ENOMEM;
348
349 cpu_latency_qos_add_request(req, PM_QOS_DEFAULT_VALUE);
350 filp->private_data = req;
351
352 return 0;
353 }
354
cpu_latency_qos_release(struct inode * inode,struct file * filp)355 static int cpu_latency_qos_release(struct inode *inode, struct file *filp)
356 {
357 struct pm_qos_request *req = filp->private_data;
358
359 filp->private_data = NULL;
360
361 cpu_latency_qos_remove_request(req);
362 kfree(req);
363
364 return 0;
365 }
366
cpu_latency_qos_read(struct file * filp,char __user * buf,size_t count,loff_t * f_pos)367 static ssize_t cpu_latency_qos_read(struct file *filp, char __user *buf,
368 size_t count, loff_t *f_pos)
369 {
370 struct pm_qos_request *req = filp->private_data;
371 unsigned long flags;
372 s32 value;
373
374 if (!req || !cpu_latency_qos_request_active(req))
375 return -EINVAL;
376
377 spin_lock_irqsave(&pm_qos_lock, flags);
378 value = pm_qos_get_value(&cpu_latency_constraints);
379 spin_unlock_irqrestore(&pm_qos_lock, flags);
380
381 return simple_read_from_buffer(buf, count, f_pos, &value, sizeof(s32));
382 }
383
cpu_latency_qos_write(struct file * filp,const char __user * buf,size_t count,loff_t * f_pos)384 static ssize_t cpu_latency_qos_write(struct file *filp, const char __user *buf,
385 size_t count, loff_t *f_pos)
386 {
387 s32 value;
388
389 if (count == sizeof(s32)) {
390 if (copy_from_user(&value, buf, sizeof(s32)))
391 return -EFAULT;
392 } else {
393 int ret;
394
395 ret = kstrtos32_from_user(buf, count, 16, &value);
396 if (ret)
397 return ret;
398 }
399
400 cpu_latency_qos_update_request(filp->private_data, value);
401
402 return count;
403 }
404
405 static const struct file_operations cpu_latency_qos_fops = {
406 .write = cpu_latency_qos_write,
407 .read = cpu_latency_qos_read,
408 .open = cpu_latency_qos_open,
409 .release = cpu_latency_qos_release,
410 .llseek = noop_llseek,
411 };
412
413 static struct miscdevice cpu_latency_qos_miscdev = {
414 .minor = MISC_DYNAMIC_MINOR,
415 .name = "cpu_dma_latency",
416 .fops = &cpu_latency_qos_fops,
417 };
418
cpu_latency_qos_init(void)419 static int __init cpu_latency_qos_init(void)
420 {
421 int ret;
422
423 ret = misc_register(&cpu_latency_qos_miscdev);
424 if (ret < 0)
425 pr_err("%s: %s setup failed\n", __func__,
426 cpu_latency_qos_miscdev.name);
427
428 return ret;
429 }
430 late_initcall(cpu_latency_qos_init);
431 #endif /* CONFIG_CPU_IDLE */
432
433 /* Definitions related to the frequency QoS below. */
434
freq_qos_value_invalid(s32 value)435 static inline bool freq_qos_value_invalid(s32 value)
436 {
437 return value < 0 && value != PM_QOS_DEFAULT_VALUE;
438 }
439
440 /**
441 * freq_constraints_init - Initialize frequency QoS constraints.
442 * @qos: Frequency QoS constraints to initialize.
443 */
freq_constraints_init(struct freq_constraints * qos)444 void freq_constraints_init(struct freq_constraints *qos)
445 {
446 struct pm_qos_constraints *c;
447
448 c = &qos->min_freq;
449 plist_head_init(&c->list);
450 c->target_value = FREQ_QOS_MIN_DEFAULT_VALUE;
451 c->default_value = FREQ_QOS_MIN_DEFAULT_VALUE;
452 c->no_constraint_value = FREQ_QOS_MIN_DEFAULT_VALUE;
453 c->type = PM_QOS_MAX;
454 c->notifiers = &qos->min_freq_notifiers;
455 BLOCKING_INIT_NOTIFIER_HEAD(c->notifiers);
456
457 c = &qos->max_freq;
458 plist_head_init(&c->list);
459 c->target_value = FREQ_QOS_MAX_DEFAULT_VALUE;
460 c->default_value = FREQ_QOS_MAX_DEFAULT_VALUE;
461 c->no_constraint_value = FREQ_QOS_MAX_DEFAULT_VALUE;
462 c->type = PM_QOS_MIN;
463 c->notifiers = &qos->max_freq_notifiers;
464 BLOCKING_INIT_NOTIFIER_HEAD(c->notifiers);
465 }
466
467 /**
468 * freq_qos_read_value - Get frequency QoS constraint for a given list.
469 * @qos: Constraints to evaluate.
470 * @type: QoS request type.
471 */
freq_qos_read_value(struct freq_constraints * qos,enum freq_qos_req_type type)472 s32 freq_qos_read_value(struct freq_constraints *qos,
473 enum freq_qos_req_type type)
474 {
475 s32 ret;
476
477 switch (type) {
478 case FREQ_QOS_MIN:
479 ret = IS_ERR_OR_NULL(qos) ?
480 FREQ_QOS_MIN_DEFAULT_VALUE :
481 pm_qos_read_value(&qos->min_freq);
482 break;
483 case FREQ_QOS_MAX:
484 ret = IS_ERR_OR_NULL(qos) ?
485 FREQ_QOS_MAX_DEFAULT_VALUE :
486 pm_qos_read_value(&qos->max_freq);
487 break;
488 default:
489 WARN_ON(1);
490 ret = 0;
491 }
492
493 return ret;
494 }
495
496 /**
497 * freq_qos_apply - Add/modify/remove frequency QoS request.
498 * @req: Constraint request to apply.
499 * @action: Action to perform (add/update/remove).
500 * @value: Value to assign to the QoS request.
501 *
502 * This is only meant to be called from inside pm_qos, not drivers.
503 */
freq_qos_apply(struct freq_qos_request * req,enum pm_qos_req_action action,s32 value)504 int freq_qos_apply(struct freq_qos_request *req,
505 enum pm_qos_req_action action, s32 value)
506 {
507 int ret;
508
509 switch(req->type) {
510 case FREQ_QOS_MIN:
511 ret = pm_qos_update_target(&req->qos->min_freq, &req->pnode,
512 action, value);
513 break;
514 case FREQ_QOS_MAX:
515 ret = pm_qos_update_target(&req->qos->max_freq, &req->pnode,
516 action, value);
517 break;
518 default:
519 ret = -EINVAL;
520 }
521
522 return ret;
523 }
524
525 /**
526 * freq_qos_add_request - Insert new frequency QoS request into a given list.
527 * @qos: Constraints to update.
528 * @req: Preallocated request object.
529 * @type: Request type.
530 * @value: Request value.
531 *
532 * Insert a new entry into the @qos list of requests, recompute the effective
533 * QoS constraint value for that list and initialize the @req object. The
534 * caller needs to save that object for later use in updates and removal.
535 *
536 * Return 1 if the effective constraint value has changed, 0 if the effective
537 * constraint value has not changed, or a negative error code on failures.
538 */
freq_qos_add_request(struct freq_constraints * qos,struct freq_qos_request * req,enum freq_qos_req_type type,s32 value)539 int freq_qos_add_request(struct freq_constraints *qos,
540 struct freq_qos_request *req,
541 enum freq_qos_req_type type, s32 value)
542 {
543 int ret;
544
545 if (IS_ERR_OR_NULL(qos) || !req || freq_qos_value_invalid(value))
546 return -EINVAL;
547
548 if (WARN(freq_qos_request_active(req),
549 "%s() called for active request\n", __func__))
550 return -EINVAL;
551
552 req->qos = qos;
553 req->type = type;
554 ret = freq_qos_apply(req, PM_QOS_ADD_REQ, value);
555 if (ret < 0) {
556 req->qos = NULL;
557 req->type = 0;
558 }
559
560 trace_android_vh_freq_qos_add_request(qos, req, type, value, ret);
561 return ret;
562 }
563 EXPORT_SYMBOL_GPL(freq_qos_add_request);
564
565 /**
566 * freq_qos_update_request - Modify existing frequency QoS request.
567 * @req: Request to modify.
568 * @new_value: New request value.
569 *
570 * Update an existing frequency QoS request along with the effective constraint
571 * value for the list of requests it belongs to.
572 *
573 * Return 1 if the effective constraint value has changed, 0 if the effective
574 * constraint value has not changed, or a negative error code on failures.
575 */
freq_qos_update_request(struct freq_qos_request * req,s32 new_value)576 int freq_qos_update_request(struct freq_qos_request *req, s32 new_value)
577 {
578 if (!req || freq_qos_value_invalid(new_value))
579 return -EINVAL;
580
581 if (WARN(!freq_qos_request_active(req),
582 "%s() called for unknown object\n", __func__))
583 return -EINVAL;
584
585 trace_android_vh_freq_qos_update_request(req, new_value);
586 if (req->pnode.prio == new_value)
587 return 0;
588
589 return freq_qos_apply(req, PM_QOS_UPDATE_REQ, new_value);
590 }
591 EXPORT_SYMBOL_GPL(freq_qos_update_request);
592
593 /**
594 * freq_qos_remove_request - Remove frequency QoS request from its list.
595 * @req: Request to remove.
596 *
597 * Remove the given frequency QoS request from the list of constraints it
598 * belongs to and recompute the effective constraint value for that list.
599 *
600 * Return 1 if the effective constraint value has changed, 0 if the effective
601 * constraint value has not changed, or a negative error code on failures.
602 */
freq_qos_remove_request(struct freq_qos_request * req)603 int freq_qos_remove_request(struct freq_qos_request *req)
604 {
605 int ret;
606
607 if (!req)
608 return -EINVAL;
609
610 if (WARN(!freq_qos_request_active(req),
611 "%s() called for unknown object\n", __func__))
612 return -EINVAL;
613
614 trace_android_vh_freq_qos_remove_request(req);
615 ret = freq_qos_apply(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
616 req->qos = NULL;
617 req->type = 0;
618
619 return ret;
620 }
621 EXPORT_SYMBOL_GPL(freq_qos_remove_request);
622
623 /**
624 * freq_qos_add_notifier - Add frequency QoS change notifier.
625 * @qos: List of requests to add the notifier to.
626 * @type: Request type.
627 * @notifier: Notifier block to add.
628 */
freq_qos_add_notifier(struct freq_constraints * qos,enum freq_qos_req_type type,struct notifier_block * notifier)629 int freq_qos_add_notifier(struct freq_constraints *qos,
630 enum freq_qos_req_type type,
631 struct notifier_block *notifier)
632 {
633 int ret;
634
635 if (IS_ERR_OR_NULL(qos) || !notifier)
636 return -EINVAL;
637
638 switch (type) {
639 case FREQ_QOS_MIN:
640 ret = blocking_notifier_chain_register(qos->min_freq.notifiers,
641 notifier);
642 break;
643 case FREQ_QOS_MAX:
644 ret = blocking_notifier_chain_register(qos->max_freq.notifiers,
645 notifier);
646 break;
647 default:
648 WARN_ON(1);
649 ret = -EINVAL;
650 }
651
652 return ret;
653 }
654 EXPORT_SYMBOL_GPL(freq_qos_add_notifier);
655
656 /**
657 * freq_qos_remove_notifier - Remove frequency QoS change notifier.
658 * @qos: List of requests to remove the notifier from.
659 * @type: Request type.
660 * @notifier: Notifier block to remove.
661 */
freq_qos_remove_notifier(struct freq_constraints * qos,enum freq_qos_req_type type,struct notifier_block * notifier)662 int freq_qos_remove_notifier(struct freq_constraints *qos,
663 enum freq_qos_req_type type,
664 struct notifier_block *notifier)
665 {
666 int ret;
667
668 if (IS_ERR_OR_NULL(qos) || !notifier)
669 return -EINVAL;
670
671 switch (type) {
672 case FREQ_QOS_MIN:
673 ret = blocking_notifier_chain_unregister(qos->min_freq.notifiers,
674 notifier);
675 break;
676 case FREQ_QOS_MAX:
677 ret = blocking_notifier_chain_unregister(qos->max_freq.notifiers,
678 notifier);
679 break;
680 default:
681 WARN_ON(1);
682 ret = -EINVAL;
683 }
684
685 return ret;
686 }
687 EXPORT_SYMBOL_GPL(freq_qos_remove_notifier);
688