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