xref: /openbmc/linux/kernel/power/qos.c (revision 151f4e2b)
1 /*
2  * This module exposes the interface to kernel space for specifying
3  * QoS dependencies.  It provides infrastructure for registration of:
4  *
5  * Dependents on a QoS value : register requests
6  * Watchers of QoS value : get notified when target QoS value changes
7  *
8  * This QoS design is best effort based.  Dependents register their QoS needs.
9  * Watchers register to keep track of the current QoS needs of the system.
10  *
11  * There are 3 basic classes of QoS parameter: latency, timeout, throughput
12  * each have defined units:
13  * latency: usec
14  * timeout: usec <-- currently not used.
15  * throughput: kbs (kilo byte / sec)
16  *
17  * There are lists of pm_qos_objects each one wrapping requests, notifiers
18  *
19  * User mode requests on a QOS parameter register themselves to the
20  * subsystem by opening the device node /dev/... and writing there request to
21  * the node.  As long as the process holds a file handle open to the node the
22  * client continues to be accounted for.  Upon file release the usermode
23  * request is removed and a new qos target is computed.  This way when the
24  * request that the application has is cleaned up when closes the file
25  * pointer or exits the pm_qos_object will get an opportunity to clean up.
26  *
27  * Mark Gross <mgross@linux.intel.com>
28  */
29 
30 /*#define DEBUG*/
31 
32 #include <linux/pm_qos.h>
33 #include <linux/sched.h>
34 #include <linux/spinlock.h>
35 #include <linux/slab.h>
36 #include <linux/time.h>
37 #include <linux/fs.h>
38 #include <linux/device.h>
39 #include <linux/miscdevice.h>
40 #include <linux/string.h>
41 #include <linux/platform_device.h>
42 #include <linux/init.h>
43 #include <linux/kernel.h>
44 #include <linux/debugfs.h>
45 #include <linux/seq_file.h>
46 
47 #include <linux/uaccess.h>
48 #include <linux/export.h>
49 #include <trace/events/power.h>
50 
51 /*
52  * locking rule: all changes to constraints or notifiers lists
53  * or pm_qos_object list and pm_qos_objects need to happen with pm_qos_lock
54  * held, taken with _irqsave.  One lock to rule them all
55  */
56 struct pm_qos_object {
57 	struct pm_qos_constraints *constraints;
58 	struct miscdevice pm_qos_power_miscdev;
59 	char *name;
60 };
61 
62 static DEFINE_SPINLOCK(pm_qos_lock);
63 
64 static struct pm_qos_object null_pm_qos;
65 
66 static BLOCKING_NOTIFIER_HEAD(cpu_dma_lat_notifier);
67 static struct pm_qos_constraints cpu_dma_constraints = {
68 	.list = PLIST_HEAD_INIT(cpu_dma_constraints.list),
69 	.target_value = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE,
70 	.default_value = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE,
71 	.no_constraint_value = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE,
72 	.type = PM_QOS_MIN,
73 	.notifiers = &cpu_dma_lat_notifier,
74 };
75 static struct pm_qos_object cpu_dma_pm_qos = {
76 	.constraints = &cpu_dma_constraints,
77 	.name = "cpu_dma_latency",
78 };
79 
80 static BLOCKING_NOTIFIER_HEAD(network_lat_notifier);
81 static struct pm_qos_constraints network_lat_constraints = {
82 	.list = PLIST_HEAD_INIT(network_lat_constraints.list),
83 	.target_value = PM_QOS_NETWORK_LAT_DEFAULT_VALUE,
84 	.default_value = PM_QOS_NETWORK_LAT_DEFAULT_VALUE,
85 	.no_constraint_value = PM_QOS_NETWORK_LAT_DEFAULT_VALUE,
86 	.type = PM_QOS_MIN,
87 	.notifiers = &network_lat_notifier,
88 };
89 static struct pm_qos_object network_lat_pm_qos = {
90 	.constraints = &network_lat_constraints,
91 	.name = "network_latency",
92 };
93 
94 
95 static BLOCKING_NOTIFIER_HEAD(network_throughput_notifier);
96 static struct pm_qos_constraints network_tput_constraints = {
97 	.list = PLIST_HEAD_INIT(network_tput_constraints.list),
98 	.target_value = PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE,
99 	.default_value = PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE,
100 	.no_constraint_value = PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE,
101 	.type = PM_QOS_MAX,
102 	.notifiers = &network_throughput_notifier,
103 };
104 static struct pm_qos_object network_throughput_pm_qos = {
105 	.constraints = &network_tput_constraints,
106 	.name = "network_throughput",
107 };
108 
109 
110 static BLOCKING_NOTIFIER_HEAD(memory_bandwidth_notifier);
111 static struct pm_qos_constraints memory_bw_constraints = {
112 	.list = PLIST_HEAD_INIT(memory_bw_constraints.list),
113 	.target_value = PM_QOS_MEMORY_BANDWIDTH_DEFAULT_VALUE,
114 	.default_value = PM_QOS_MEMORY_BANDWIDTH_DEFAULT_VALUE,
115 	.no_constraint_value = PM_QOS_MEMORY_BANDWIDTH_DEFAULT_VALUE,
116 	.type = PM_QOS_SUM,
117 	.notifiers = &memory_bandwidth_notifier,
118 };
119 static struct pm_qos_object memory_bandwidth_pm_qos = {
120 	.constraints = &memory_bw_constraints,
121 	.name = "memory_bandwidth",
122 };
123 
124 
125 static struct pm_qos_object *pm_qos_array[] = {
126 	&null_pm_qos,
127 	&cpu_dma_pm_qos,
128 	&network_lat_pm_qos,
129 	&network_throughput_pm_qos,
130 	&memory_bandwidth_pm_qos,
131 };
132 
133 static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf,
134 		size_t count, loff_t *f_pos);
135 static ssize_t pm_qos_power_read(struct file *filp, char __user *buf,
136 		size_t count, loff_t *f_pos);
137 static int pm_qos_power_open(struct inode *inode, struct file *filp);
138 static int pm_qos_power_release(struct inode *inode, struct file *filp);
139 
140 static const struct file_operations pm_qos_power_fops = {
141 	.write = pm_qos_power_write,
142 	.read = pm_qos_power_read,
143 	.open = pm_qos_power_open,
144 	.release = pm_qos_power_release,
145 	.llseek = noop_llseek,
146 };
147 
148 /* unlocked internal variant */
149 static inline int pm_qos_get_value(struct pm_qos_constraints *c)
150 {
151 	struct plist_node *node;
152 	int total_value = 0;
153 
154 	if (plist_head_empty(&c->list))
155 		return c->no_constraint_value;
156 
157 	switch (c->type) {
158 	case PM_QOS_MIN:
159 		return plist_first(&c->list)->prio;
160 
161 	case PM_QOS_MAX:
162 		return plist_last(&c->list)->prio;
163 
164 	case PM_QOS_SUM:
165 		plist_for_each(node, &c->list)
166 			total_value += node->prio;
167 
168 		return total_value;
169 
170 	default:
171 		/* runtime check for not using enum */
172 		BUG();
173 		return PM_QOS_DEFAULT_VALUE;
174 	}
175 }
176 
177 s32 pm_qos_read_value(struct pm_qos_constraints *c)
178 {
179 	return c->target_value;
180 }
181 
182 static inline void pm_qos_set_value(struct pm_qos_constraints *c, s32 value)
183 {
184 	c->target_value = value;
185 }
186 
187 static int pm_qos_debug_show(struct seq_file *s, void *unused)
188 {
189 	struct pm_qos_object *qos = (struct pm_qos_object *)s->private;
190 	struct pm_qos_constraints *c;
191 	struct pm_qos_request *req;
192 	char *type;
193 	unsigned long flags;
194 	int tot_reqs = 0;
195 	int active_reqs = 0;
196 
197 	if (IS_ERR_OR_NULL(qos)) {
198 		pr_err("%s: bad qos param!\n", __func__);
199 		return -EINVAL;
200 	}
201 	c = qos->constraints;
202 	if (IS_ERR_OR_NULL(c)) {
203 		pr_err("%s: Bad constraints on qos?\n", __func__);
204 		return -EINVAL;
205 	}
206 
207 	/* Lock to ensure we have a snapshot */
208 	spin_lock_irqsave(&pm_qos_lock, flags);
209 	if (plist_head_empty(&c->list)) {
210 		seq_puts(s, "Empty!\n");
211 		goto out;
212 	}
213 
214 	switch (c->type) {
215 	case PM_QOS_MIN:
216 		type = "Minimum";
217 		break;
218 	case PM_QOS_MAX:
219 		type = "Maximum";
220 		break;
221 	case PM_QOS_SUM:
222 		type = "Sum";
223 		break;
224 	default:
225 		type = "Unknown";
226 	}
227 
228 	plist_for_each_entry(req, &c->list, node) {
229 		char *state = "Default";
230 
231 		if ((req->node).prio != c->default_value) {
232 			active_reqs++;
233 			state = "Active";
234 		}
235 		tot_reqs++;
236 		seq_printf(s, "%d: %d: %s\n", tot_reqs,
237 			   (req->node).prio, state);
238 	}
239 
240 	seq_printf(s, "Type=%s, Value=%d, Requests: active=%d / total=%d\n",
241 		   type, pm_qos_get_value(c), active_reqs, tot_reqs);
242 
243 out:
244 	spin_unlock_irqrestore(&pm_qos_lock, flags);
245 	return 0;
246 }
247 
248 DEFINE_SHOW_ATTRIBUTE(pm_qos_debug);
249 
250 /**
251  * pm_qos_update_target - manages the constraints list and calls the notifiers
252  *  if needed
253  * @c: constraints data struct
254  * @node: request to add to the list, to update or to remove
255  * @action: action to take on the constraints list
256  * @value: value of the request to add or update
257  *
258  * This function returns 1 if the aggregated constraint value has changed, 0
259  *  otherwise.
260  */
261 int pm_qos_update_target(struct pm_qos_constraints *c, struct plist_node *node,
262 			 enum pm_qos_req_action action, int value)
263 {
264 	unsigned long flags;
265 	int prev_value, curr_value, new_value;
266 	int ret;
267 
268 	spin_lock_irqsave(&pm_qos_lock, flags);
269 	prev_value = pm_qos_get_value(c);
270 	if (value == PM_QOS_DEFAULT_VALUE)
271 		new_value = c->default_value;
272 	else
273 		new_value = value;
274 
275 	switch (action) {
276 	case PM_QOS_REMOVE_REQ:
277 		plist_del(node, &c->list);
278 		break;
279 	case PM_QOS_UPDATE_REQ:
280 		/*
281 		 * to change the list, we atomically remove, reinit
282 		 * with new value and add, then see if the extremal
283 		 * changed
284 		 */
285 		plist_del(node, &c->list);
286 		/* fall through */
287 	case PM_QOS_ADD_REQ:
288 		plist_node_init(node, new_value);
289 		plist_add(node, &c->list);
290 		break;
291 	default:
292 		/* no action */
293 		;
294 	}
295 
296 	curr_value = pm_qos_get_value(c);
297 	pm_qos_set_value(c, curr_value);
298 
299 	spin_unlock_irqrestore(&pm_qos_lock, flags);
300 
301 	trace_pm_qos_update_target(action, prev_value, curr_value);
302 	if (prev_value != curr_value) {
303 		ret = 1;
304 		if (c->notifiers)
305 			blocking_notifier_call_chain(c->notifiers,
306 						     (unsigned long)curr_value,
307 						     NULL);
308 	} else {
309 		ret = 0;
310 	}
311 	return ret;
312 }
313 
314 /**
315  * pm_qos_flags_remove_req - Remove device PM QoS flags request.
316  * @pqf: Device PM QoS flags set to remove the request from.
317  * @req: Request to remove from the set.
318  */
319 static void pm_qos_flags_remove_req(struct pm_qos_flags *pqf,
320 				    struct pm_qos_flags_request *req)
321 {
322 	s32 val = 0;
323 
324 	list_del(&req->node);
325 	list_for_each_entry(req, &pqf->list, node)
326 		val |= req->flags;
327 
328 	pqf->effective_flags = val;
329 }
330 
331 /**
332  * pm_qos_update_flags - Update a set of PM QoS flags.
333  * @pqf: Set of flags to update.
334  * @req: Request to add to the set, to modify, or to remove from the set.
335  * @action: Action to take on the set.
336  * @val: Value of the request to add or modify.
337  *
338  * Update the given set of PM QoS flags and call notifiers if the aggregate
339  * value has changed.  Returns 1 if the aggregate constraint value has changed,
340  * 0 otherwise.
341  */
342 bool pm_qos_update_flags(struct pm_qos_flags *pqf,
343 			 struct pm_qos_flags_request *req,
344 			 enum pm_qos_req_action action, s32 val)
345 {
346 	unsigned long irqflags;
347 	s32 prev_value, curr_value;
348 
349 	spin_lock_irqsave(&pm_qos_lock, irqflags);
350 
351 	prev_value = list_empty(&pqf->list) ? 0 : pqf->effective_flags;
352 
353 	switch (action) {
354 	case PM_QOS_REMOVE_REQ:
355 		pm_qos_flags_remove_req(pqf, req);
356 		break;
357 	case PM_QOS_UPDATE_REQ:
358 		pm_qos_flags_remove_req(pqf, req);
359 		/* fall through */
360 	case PM_QOS_ADD_REQ:
361 		req->flags = val;
362 		INIT_LIST_HEAD(&req->node);
363 		list_add_tail(&req->node, &pqf->list);
364 		pqf->effective_flags |= val;
365 		break;
366 	default:
367 		/* no action */
368 		;
369 	}
370 
371 	curr_value = list_empty(&pqf->list) ? 0 : pqf->effective_flags;
372 
373 	spin_unlock_irqrestore(&pm_qos_lock, irqflags);
374 
375 	trace_pm_qos_update_flags(action, prev_value, curr_value);
376 	return prev_value != curr_value;
377 }
378 
379 /**
380  * pm_qos_request - returns current system wide qos expectation
381  * @pm_qos_class: identification of which qos value is requested
382  *
383  * This function returns the current target value.
384  */
385 int pm_qos_request(int pm_qos_class)
386 {
387 	return pm_qos_read_value(pm_qos_array[pm_qos_class]->constraints);
388 }
389 EXPORT_SYMBOL_GPL(pm_qos_request);
390 
391 int pm_qos_request_active(struct pm_qos_request *req)
392 {
393 	return req->pm_qos_class != 0;
394 }
395 EXPORT_SYMBOL_GPL(pm_qos_request_active);
396 
397 static void __pm_qos_update_request(struct pm_qos_request *req,
398 			   s32 new_value)
399 {
400 	trace_pm_qos_update_request(req->pm_qos_class, new_value);
401 
402 	if (new_value != req->node.prio)
403 		pm_qos_update_target(
404 			pm_qos_array[req->pm_qos_class]->constraints,
405 			&req->node, PM_QOS_UPDATE_REQ, new_value);
406 }
407 
408 /**
409  * pm_qos_work_fn - the timeout handler of pm_qos_update_request_timeout
410  * @work: work struct for the delayed work (timeout)
411  *
412  * This cancels the timeout request by falling back to the default at timeout.
413  */
414 static void pm_qos_work_fn(struct work_struct *work)
415 {
416 	struct pm_qos_request *req = container_of(to_delayed_work(work),
417 						  struct pm_qos_request,
418 						  work);
419 
420 	__pm_qos_update_request(req, PM_QOS_DEFAULT_VALUE);
421 }
422 
423 /**
424  * pm_qos_add_request - inserts new qos request into the list
425  * @req: pointer to a preallocated handle
426  * @pm_qos_class: identifies which list of qos request to use
427  * @value: defines the qos request
428  *
429  * This function inserts a new entry in the pm_qos_class list of requested qos
430  * performance characteristics.  It recomputes the aggregate QoS expectations
431  * for the pm_qos_class of parameters and initializes the pm_qos_request
432  * handle.  Caller needs to save this handle for later use in updates and
433  * removal.
434  */
435 
436 void pm_qos_add_request(struct pm_qos_request *req,
437 			int pm_qos_class, s32 value)
438 {
439 	if (!req) /*guard against callers passing in null */
440 		return;
441 
442 	if (pm_qos_request_active(req)) {
443 		WARN(1, KERN_ERR "pm_qos_add_request() called for already added request\n");
444 		return;
445 	}
446 	req->pm_qos_class = pm_qos_class;
447 	INIT_DELAYED_WORK(&req->work, pm_qos_work_fn);
448 	trace_pm_qos_add_request(pm_qos_class, value);
449 	pm_qos_update_target(pm_qos_array[pm_qos_class]->constraints,
450 			     &req->node, PM_QOS_ADD_REQ, value);
451 }
452 EXPORT_SYMBOL_GPL(pm_qos_add_request);
453 
454 /**
455  * pm_qos_update_request - modifies an existing qos request
456  * @req : handle to list element holding a pm_qos request to use
457  * @value: defines the qos request
458  *
459  * Updates an existing qos request for the pm_qos_class of parameters along
460  * with updating the target pm_qos_class value.
461  *
462  * Attempts are made to make this code callable on hot code paths.
463  */
464 void pm_qos_update_request(struct pm_qos_request *req,
465 			   s32 new_value)
466 {
467 	if (!req) /*guard against callers passing in null */
468 		return;
469 
470 	if (!pm_qos_request_active(req)) {
471 		WARN(1, KERN_ERR "pm_qos_update_request() called for unknown object\n");
472 		return;
473 	}
474 
475 	cancel_delayed_work_sync(&req->work);
476 	__pm_qos_update_request(req, new_value);
477 }
478 EXPORT_SYMBOL_GPL(pm_qos_update_request);
479 
480 /**
481  * pm_qos_update_request_timeout - modifies an existing qos request temporarily.
482  * @req : handle to list element holding a pm_qos request to use
483  * @new_value: defines the temporal qos request
484  * @timeout_us: the effective duration of this qos request in usecs.
485  *
486  * After timeout_us, this qos request is cancelled automatically.
487  */
488 void pm_qos_update_request_timeout(struct pm_qos_request *req, s32 new_value,
489 				   unsigned long timeout_us)
490 {
491 	if (!req)
492 		return;
493 	if (WARN(!pm_qos_request_active(req),
494 		 "%s called for unknown object.", __func__))
495 		return;
496 
497 	cancel_delayed_work_sync(&req->work);
498 
499 	trace_pm_qos_update_request_timeout(req->pm_qos_class,
500 					    new_value, timeout_us);
501 	if (new_value != req->node.prio)
502 		pm_qos_update_target(
503 			pm_qos_array[req->pm_qos_class]->constraints,
504 			&req->node, PM_QOS_UPDATE_REQ, new_value);
505 
506 	schedule_delayed_work(&req->work, usecs_to_jiffies(timeout_us));
507 }
508 
509 /**
510  * pm_qos_remove_request - modifies an existing qos request
511  * @req: handle to request list element
512  *
513  * Will remove pm qos request from the list of constraints and
514  * recompute the current target value for the pm_qos_class.  Call this
515  * on slow code paths.
516  */
517 void pm_qos_remove_request(struct pm_qos_request *req)
518 {
519 	if (!req) /*guard against callers passing in null */
520 		return;
521 		/* silent return to keep pcm code cleaner */
522 
523 	if (!pm_qos_request_active(req)) {
524 		WARN(1, KERN_ERR "pm_qos_remove_request() called for unknown object\n");
525 		return;
526 	}
527 
528 	cancel_delayed_work_sync(&req->work);
529 
530 	trace_pm_qos_remove_request(req->pm_qos_class, PM_QOS_DEFAULT_VALUE);
531 	pm_qos_update_target(pm_qos_array[req->pm_qos_class]->constraints,
532 			     &req->node, PM_QOS_REMOVE_REQ,
533 			     PM_QOS_DEFAULT_VALUE);
534 	memset(req, 0, sizeof(*req));
535 }
536 EXPORT_SYMBOL_GPL(pm_qos_remove_request);
537 
538 /**
539  * pm_qos_add_notifier - sets notification entry for changes to target value
540  * @pm_qos_class: identifies which qos target changes should be notified.
541  * @notifier: notifier block managed by caller.
542  *
543  * will register the notifier into a notification chain that gets called
544  * upon changes to the pm_qos_class target value.
545  */
546 int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier)
547 {
548 	int retval;
549 
550 	retval = blocking_notifier_chain_register(
551 			pm_qos_array[pm_qos_class]->constraints->notifiers,
552 			notifier);
553 
554 	return retval;
555 }
556 EXPORT_SYMBOL_GPL(pm_qos_add_notifier);
557 
558 /**
559  * pm_qos_remove_notifier - deletes notification entry from chain.
560  * @pm_qos_class: identifies which qos target changes are notified.
561  * @notifier: notifier block to be removed.
562  *
563  * will remove the notifier from the notification chain that gets called
564  * upon changes to the pm_qos_class target value.
565  */
566 int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier)
567 {
568 	int retval;
569 
570 	retval = blocking_notifier_chain_unregister(
571 			pm_qos_array[pm_qos_class]->constraints->notifiers,
572 			notifier);
573 
574 	return retval;
575 }
576 EXPORT_SYMBOL_GPL(pm_qos_remove_notifier);
577 
578 /* User space interface to PM QoS classes via misc devices */
579 static int register_pm_qos_misc(struct pm_qos_object *qos, struct dentry *d)
580 {
581 	qos->pm_qos_power_miscdev.minor = MISC_DYNAMIC_MINOR;
582 	qos->pm_qos_power_miscdev.name = qos->name;
583 	qos->pm_qos_power_miscdev.fops = &pm_qos_power_fops;
584 
585 	debugfs_create_file(qos->name, S_IRUGO, d, (void *)qos,
586 			    &pm_qos_debug_fops);
587 
588 	return misc_register(&qos->pm_qos_power_miscdev);
589 }
590 
591 static int find_pm_qos_object_by_minor(int minor)
592 {
593 	int pm_qos_class;
594 
595 	for (pm_qos_class = PM_QOS_CPU_DMA_LATENCY;
596 		pm_qos_class < PM_QOS_NUM_CLASSES; pm_qos_class++) {
597 		if (minor ==
598 			pm_qos_array[pm_qos_class]->pm_qos_power_miscdev.minor)
599 			return pm_qos_class;
600 	}
601 	return -1;
602 }
603 
604 static int pm_qos_power_open(struct inode *inode, struct file *filp)
605 {
606 	long pm_qos_class;
607 
608 	pm_qos_class = find_pm_qos_object_by_minor(iminor(inode));
609 	if (pm_qos_class >= PM_QOS_CPU_DMA_LATENCY) {
610 		struct pm_qos_request *req = kzalloc(sizeof(*req), GFP_KERNEL);
611 		if (!req)
612 			return -ENOMEM;
613 
614 		pm_qos_add_request(req, pm_qos_class, PM_QOS_DEFAULT_VALUE);
615 		filp->private_data = req;
616 
617 		return 0;
618 	}
619 	return -EPERM;
620 }
621 
622 static int pm_qos_power_release(struct inode *inode, struct file *filp)
623 {
624 	struct pm_qos_request *req;
625 
626 	req = filp->private_data;
627 	pm_qos_remove_request(req);
628 	kfree(req);
629 
630 	return 0;
631 }
632 
633 
634 static ssize_t pm_qos_power_read(struct file *filp, char __user *buf,
635 		size_t count, loff_t *f_pos)
636 {
637 	s32 value;
638 	unsigned long flags;
639 	struct pm_qos_request *req = filp->private_data;
640 
641 	if (!req)
642 		return -EINVAL;
643 	if (!pm_qos_request_active(req))
644 		return -EINVAL;
645 
646 	spin_lock_irqsave(&pm_qos_lock, flags);
647 	value = pm_qos_get_value(pm_qos_array[req->pm_qos_class]->constraints);
648 	spin_unlock_irqrestore(&pm_qos_lock, flags);
649 
650 	return simple_read_from_buffer(buf, count, f_pos, &value, sizeof(s32));
651 }
652 
653 static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf,
654 		size_t count, loff_t *f_pos)
655 {
656 	s32 value;
657 	struct pm_qos_request *req;
658 
659 	if (count == sizeof(s32)) {
660 		if (copy_from_user(&value, buf, sizeof(s32)))
661 			return -EFAULT;
662 	} else {
663 		int ret;
664 
665 		ret = kstrtos32_from_user(buf, count, 16, &value);
666 		if (ret)
667 			return ret;
668 	}
669 
670 	req = filp->private_data;
671 	pm_qos_update_request(req, value);
672 
673 	return count;
674 }
675 
676 
677 static int __init pm_qos_power_init(void)
678 {
679 	int ret = 0;
680 	int i;
681 	struct dentry *d;
682 
683 	BUILD_BUG_ON(ARRAY_SIZE(pm_qos_array) != PM_QOS_NUM_CLASSES);
684 
685 	d = debugfs_create_dir("pm_qos", NULL);
686 
687 	for (i = PM_QOS_CPU_DMA_LATENCY; i < PM_QOS_NUM_CLASSES; i++) {
688 		ret = register_pm_qos_misc(pm_qos_array[i], d);
689 		if (ret < 0) {
690 			pr_err("%s: %s setup failed\n",
691 			       __func__, pm_qos_array[i]->name);
692 			return ret;
693 		}
694 	}
695 
696 	return ret;
697 }
698 
699 late_initcall(pm_qos_power_init);
700