2 * linux/drivers/cpufreq/cpufreq.c
4 * Copyright (C) 2001 Russell King
5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
6 * (C) 2013 Viresh Kumar <viresh.kumar@linaro.org>
8 * Oct 2005 - Ashok Raj <ashok.raj@intel.com>
9 * Added handling for CPU hotplug
10 * Feb 2006 - Jacob Shin <jacob.shin@amd.com>
11 * Fix handling for CPU hotplug -- affected CPUs
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/cpu.h>
21 #include <linux/cpufreq.h>
22 #include <linux/delay.h>
23 #include <linux/device.h>
24 #include <linux/init.h>
25 #include <linux/kernel_stat.h>
26 #include <linux/module.h>
27 #include <linux/mutex.h>
28 #include <linux/slab.h>
29 #include <linux/suspend.h>
30 #include <linux/syscore_ops.h>
31 #include <linux/tick.h>
32 #include <trace/events/power.h>
34 static LIST_HEAD(cpufreq_policy_list);
36 static inline bool policy_is_inactive(struct cpufreq_policy *policy)
38 return cpumask_empty(policy->cpus);
41 /* Macros to iterate over CPU policies */
42 #define for_each_suitable_policy(__policy, __active) \
43 list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) \
44 if ((__active) == !policy_is_inactive(__policy))
46 #define for_each_active_policy(__policy) \
47 for_each_suitable_policy(__policy, true)
48 #define for_each_inactive_policy(__policy) \
49 for_each_suitable_policy(__policy, false)
51 #define for_each_policy(__policy) \
52 list_for_each_entry(__policy, &cpufreq_policy_list, policy_list)
54 /* Iterate over governors */
55 static LIST_HEAD(cpufreq_governor_list);
56 #define for_each_governor(__governor) \
57 list_for_each_entry(__governor, &cpufreq_governor_list, governor_list)
60 * The "cpufreq driver" - the arch- or hardware-dependent low
61 * level driver of CPUFreq support, and its spinlock. This lock
62 * also protects the cpufreq_cpu_data array.
64 static struct cpufreq_driver *cpufreq_driver;
65 static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data);
66 static DEFINE_RWLOCK(cpufreq_driver_lock);
68 /* Flag to suspend/resume CPUFreq governors */
69 static bool cpufreq_suspended;
71 static inline bool has_target(void)
73 return cpufreq_driver->target_index || cpufreq_driver->target;
76 /* internal prototypes */
77 static int cpufreq_governor(struct cpufreq_policy *policy, unsigned int event);
78 static unsigned int __cpufreq_get(struct cpufreq_policy *policy);
79 static int cpufreq_start_governor(struct cpufreq_policy *policy);
80 static int cpufreq_exit_governor(struct cpufreq_policy *policy);
83 * Two notifier lists: the "policy" list is involved in the
84 * validation process for a new CPU frequency policy; the
85 * "transition" list for kernel code that needs to handle
86 * changes to devices when the CPU clock speed changes.
87 * The mutex locks both lists.
89 static BLOCKING_NOTIFIER_HEAD(cpufreq_policy_notifier_list);
90 static struct srcu_notifier_head cpufreq_transition_notifier_list;
92 static bool init_cpufreq_transition_notifier_list_called;
93 static int __init init_cpufreq_transition_notifier_list(void)
95 srcu_init_notifier_head(&cpufreq_transition_notifier_list);
96 init_cpufreq_transition_notifier_list_called = true;
99 pure_initcall(init_cpufreq_transition_notifier_list);
101 static int off __read_mostly;
102 static int cpufreq_disabled(void)
106 void disable_cpufreq(void)
110 static DEFINE_MUTEX(cpufreq_governor_mutex);
112 bool have_governor_per_policy(void)
114 return !!(cpufreq_driver->flags & CPUFREQ_HAVE_GOVERNOR_PER_POLICY);
116 EXPORT_SYMBOL_GPL(have_governor_per_policy);
118 struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy)
120 if (have_governor_per_policy())
121 return &policy->kobj;
123 return cpufreq_global_kobject;
125 EXPORT_SYMBOL_GPL(get_governor_parent_kobj);
127 struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu)
129 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
131 return policy && !policy_is_inactive(policy) ?
132 policy->freq_table : NULL;
134 EXPORT_SYMBOL_GPL(cpufreq_frequency_get_table);
136 static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall)
142 cur_wall_time = jiffies64_to_cputime64(get_jiffies_64());
144 busy_time = kcpustat_cpu(cpu).cpustat[CPUTIME_USER];
145 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SYSTEM];
146 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_IRQ];
147 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SOFTIRQ];
148 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL];
149 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_NICE];
151 idle_time = cur_wall_time - busy_time;
153 *wall = cputime_to_usecs(cur_wall_time);
155 return cputime_to_usecs(idle_time);
158 u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy)
160 u64 idle_time = get_cpu_idle_time_us(cpu, io_busy ? wall : NULL);
162 if (idle_time == -1ULL)
163 return get_cpu_idle_time_jiffy(cpu, wall);
165 idle_time += get_cpu_iowait_time_us(cpu, wall);
169 EXPORT_SYMBOL_GPL(get_cpu_idle_time);
172 * This is a generic cpufreq init() routine which can be used by cpufreq
173 * drivers of SMP systems. It will do following:
174 * - validate & show freq table passed
175 * - set policies transition latency
176 * - policy->cpus with all possible CPUs
178 int cpufreq_generic_init(struct cpufreq_policy *policy,
179 struct cpufreq_frequency_table *table,
180 unsigned int transition_latency)
184 ret = cpufreq_table_validate_and_show(policy, table);
186 pr_err("%s: invalid frequency table: %d\n", __func__, ret);
190 policy->cpuinfo.transition_latency = transition_latency;
193 * The driver only supports the SMP configuration where all processors
194 * share the clock and voltage and clock.
196 cpumask_setall(policy->cpus);
200 EXPORT_SYMBOL_GPL(cpufreq_generic_init);
202 struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu)
204 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
206 return policy && cpumask_test_cpu(cpu, policy->cpus) ? policy : NULL;
208 EXPORT_SYMBOL_GPL(cpufreq_cpu_get_raw);
210 unsigned int cpufreq_generic_get(unsigned int cpu)
212 struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
214 if (!policy || IS_ERR(policy->clk)) {
215 pr_err("%s: No %s associated to cpu: %d\n",
216 __func__, policy ? "clk" : "policy", cpu);
220 return clk_get_rate(policy->clk) / 1000;
222 EXPORT_SYMBOL_GPL(cpufreq_generic_get);
225 * cpufreq_cpu_get: returns policy for a cpu and marks it busy.
227 * @cpu: cpu to find policy for.
229 * This returns policy for 'cpu', returns NULL if it doesn't exist.
230 * It also increments the kobject reference count to mark it busy and so would
231 * require a corresponding call to cpufreq_cpu_put() to decrement it back.
232 * If corresponding call cpufreq_cpu_put() isn't made, the policy wouldn't be
233 * freed as that depends on the kobj count.
235 * Return: A valid policy on success, otherwise NULL on failure.
237 struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
239 struct cpufreq_policy *policy = NULL;
242 if (WARN_ON(cpu >= nr_cpu_ids))
245 /* get the cpufreq driver */
246 read_lock_irqsave(&cpufreq_driver_lock, flags);
248 if (cpufreq_driver) {
250 policy = cpufreq_cpu_get_raw(cpu);
252 kobject_get(&policy->kobj);
255 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
259 EXPORT_SYMBOL_GPL(cpufreq_cpu_get);
262 * cpufreq_cpu_put: Decrements the usage count of a policy
264 * @policy: policy earlier returned by cpufreq_cpu_get().
266 * This decrements the kobject reference count incremented earlier by calling
269 void cpufreq_cpu_put(struct cpufreq_policy *policy)
271 kobject_put(&policy->kobj);
273 EXPORT_SYMBOL_GPL(cpufreq_cpu_put);
275 /*********************************************************************
276 * EXTERNALLY AFFECTING FREQUENCY CHANGES *
277 *********************************************************************/
280 * adjust_jiffies - adjust the system "loops_per_jiffy"
282 * This function alters the system "loops_per_jiffy" for the clock
283 * speed change. Note that loops_per_jiffy cannot be updated on SMP
284 * systems as each CPU might be scaled differently. So, use the arch
285 * per-CPU loops_per_jiffy value wherever possible.
287 static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
290 static unsigned long l_p_j_ref;
291 static unsigned int l_p_j_ref_freq;
293 if (ci->flags & CPUFREQ_CONST_LOOPS)
296 if (!l_p_j_ref_freq) {
297 l_p_j_ref = loops_per_jiffy;
298 l_p_j_ref_freq = ci->old;
299 pr_debug("saving %lu as reference value for loops_per_jiffy; freq is %u kHz\n",
300 l_p_j_ref, l_p_j_ref_freq);
302 if (val == CPUFREQ_POSTCHANGE && ci->old != ci->new) {
303 loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq,
305 pr_debug("scaling loops_per_jiffy to %lu for frequency %u kHz\n",
306 loops_per_jiffy, ci->new);
311 static void __cpufreq_notify_transition(struct cpufreq_policy *policy,
312 struct cpufreq_freqs *freqs, unsigned int state)
314 BUG_ON(irqs_disabled());
316 if (cpufreq_disabled())
319 freqs->flags = cpufreq_driver->flags;
320 pr_debug("notification %u of frequency transition to %u kHz\n",
325 case CPUFREQ_PRECHANGE:
326 /* detect if the driver reported a value as "old frequency"
327 * which is not equal to what the cpufreq core thinks is
330 if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
331 if ((policy) && (policy->cpu == freqs->cpu) &&
332 (policy->cur) && (policy->cur != freqs->old)) {
333 pr_debug("Warning: CPU frequency is %u, cpufreq assumed %u kHz\n",
334 freqs->old, policy->cur);
335 freqs->old = policy->cur;
338 srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
339 CPUFREQ_PRECHANGE, freqs);
340 adjust_jiffies(CPUFREQ_PRECHANGE, freqs);
343 case CPUFREQ_POSTCHANGE:
344 adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);
345 pr_debug("FREQ: %lu - CPU: %lu\n",
346 (unsigned long)freqs->new, (unsigned long)freqs->cpu);
347 trace_cpu_frequency(freqs->new, freqs->cpu);
348 srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
349 CPUFREQ_POSTCHANGE, freqs);
350 if (likely(policy) && likely(policy->cpu == freqs->cpu))
351 policy->cur = freqs->new;
357 * cpufreq_notify_transition - call notifier chain and adjust_jiffies
358 * on frequency transition.
360 * This function calls the transition notifiers and the "adjust_jiffies"
361 * function. It is called twice on all CPU frequency changes that have
364 static void cpufreq_notify_transition(struct cpufreq_policy *policy,
365 struct cpufreq_freqs *freqs, unsigned int state)
367 for_each_cpu(freqs->cpu, policy->cpus)
368 __cpufreq_notify_transition(policy, freqs, state);
371 /* Do post notifications when there are chances that transition has failed */
372 static void cpufreq_notify_post_transition(struct cpufreq_policy *policy,
373 struct cpufreq_freqs *freqs, int transition_failed)
375 cpufreq_notify_transition(policy, freqs, CPUFREQ_POSTCHANGE);
376 if (!transition_failed)
379 swap(freqs->old, freqs->new);
380 cpufreq_notify_transition(policy, freqs, CPUFREQ_PRECHANGE);
381 cpufreq_notify_transition(policy, freqs, CPUFREQ_POSTCHANGE);
384 void cpufreq_freq_transition_begin(struct cpufreq_policy *policy,
385 struct cpufreq_freqs *freqs)
389 * Catch double invocations of _begin() which lead to self-deadlock.
390 * ASYNC_NOTIFICATION drivers are left out because the cpufreq core
391 * doesn't invoke _begin() on their behalf, and hence the chances of
392 * double invocations are very low. Moreover, there are scenarios
393 * where these checks can emit false-positive warnings in these
394 * drivers; so we avoid that by skipping them altogether.
396 WARN_ON(!(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION)
397 && current == policy->transition_task);
400 wait_event(policy->transition_wait, !policy->transition_ongoing);
402 spin_lock(&policy->transition_lock);
404 if (unlikely(policy->transition_ongoing)) {
405 spin_unlock(&policy->transition_lock);
409 policy->transition_ongoing = true;
410 policy->transition_task = current;
412 spin_unlock(&policy->transition_lock);
414 cpufreq_notify_transition(policy, freqs, CPUFREQ_PRECHANGE);
416 EXPORT_SYMBOL_GPL(cpufreq_freq_transition_begin);
418 void cpufreq_freq_transition_end(struct cpufreq_policy *policy,
419 struct cpufreq_freqs *freqs, int transition_failed)
421 if (unlikely(WARN_ON(!policy->transition_ongoing)))
424 cpufreq_notify_post_transition(policy, freqs, transition_failed);
426 policy->transition_ongoing = false;
427 policy->transition_task = NULL;
429 wake_up(&policy->transition_wait);
431 EXPORT_SYMBOL_GPL(cpufreq_freq_transition_end);
434 * Fast frequency switching status count. Positive means "enabled", negative
435 * means "disabled" and 0 means "not decided yet".
437 static int cpufreq_fast_switch_count;
438 static DEFINE_MUTEX(cpufreq_fast_switch_lock);
440 static void cpufreq_list_transition_notifiers(void)
442 struct notifier_block *nb;
444 pr_info("Registered transition notifiers:\n");
446 mutex_lock(&cpufreq_transition_notifier_list.mutex);
448 for (nb = cpufreq_transition_notifier_list.head; nb; nb = nb->next)
449 pr_info("%pF\n", nb->notifier_call);
451 mutex_unlock(&cpufreq_transition_notifier_list.mutex);
455 * cpufreq_enable_fast_switch - Enable fast frequency switching for policy.
456 * @policy: cpufreq policy to enable fast frequency switching for.
458 * Try to enable fast frequency switching for @policy.
460 * The attempt will fail if there is at least one transition notifier registered
461 * at this point, as fast frequency switching is quite fundamentally at odds
462 * with transition notifiers. Thus if successful, it will make registration of
463 * transition notifiers fail going forward.
465 void cpufreq_enable_fast_switch(struct cpufreq_policy *policy)
467 lockdep_assert_held(&policy->rwsem);
469 if (!policy->fast_switch_possible)
472 mutex_lock(&cpufreq_fast_switch_lock);
473 if (cpufreq_fast_switch_count >= 0) {
474 cpufreq_fast_switch_count++;
475 policy->fast_switch_enabled = true;
477 pr_warn("CPU%u: Fast frequency switching not enabled\n",
479 cpufreq_list_transition_notifiers();
481 mutex_unlock(&cpufreq_fast_switch_lock);
483 EXPORT_SYMBOL_GPL(cpufreq_enable_fast_switch);
485 static void cpufreq_disable_fast_switch(struct cpufreq_policy *policy)
487 mutex_lock(&cpufreq_fast_switch_lock);
488 if (policy->fast_switch_enabled) {
489 policy->fast_switch_enabled = false;
490 if (!WARN_ON(cpufreq_fast_switch_count <= 0))
491 cpufreq_fast_switch_count--;
493 mutex_unlock(&cpufreq_fast_switch_lock);
496 /*********************************************************************
498 *********************************************************************/
499 static ssize_t show_boost(struct kobject *kobj,
500 struct attribute *attr, char *buf)
502 return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled);
505 static ssize_t store_boost(struct kobject *kobj, struct attribute *attr,
506 const char *buf, size_t count)
510 ret = sscanf(buf, "%d", &enable);
511 if (ret != 1 || enable < 0 || enable > 1)
514 if (cpufreq_boost_trigger_state(enable)) {
515 pr_err("%s: Cannot %s BOOST!\n",
516 __func__, enable ? "enable" : "disable");
520 pr_debug("%s: cpufreq BOOST %s\n",
521 __func__, enable ? "enabled" : "disabled");
525 define_one_global_rw(boost);
527 static struct cpufreq_governor *find_governor(const char *str_governor)
529 struct cpufreq_governor *t;
532 if (!strncasecmp(str_governor, t->name, CPUFREQ_NAME_LEN))
539 * cpufreq_parse_governor - parse a governor string
541 static int cpufreq_parse_governor(char *str_governor, unsigned int *policy,
542 struct cpufreq_governor **governor)
546 if (cpufreq_driver->setpolicy) {
547 if (!strncasecmp(str_governor, "performance", CPUFREQ_NAME_LEN)) {
548 *policy = CPUFREQ_POLICY_PERFORMANCE;
550 } else if (!strncasecmp(str_governor, "powersave",
552 *policy = CPUFREQ_POLICY_POWERSAVE;
556 struct cpufreq_governor *t;
558 mutex_lock(&cpufreq_governor_mutex);
560 t = find_governor(str_governor);
565 mutex_unlock(&cpufreq_governor_mutex);
566 ret = request_module("cpufreq_%s", str_governor);
567 mutex_lock(&cpufreq_governor_mutex);
570 t = find_governor(str_governor);
578 mutex_unlock(&cpufreq_governor_mutex);
584 * cpufreq_per_cpu_attr_read() / show_##file_name() -
585 * print out cpufreq information
587 * Write out information from cpufreq_driver->policy[cpu]; object must be
591 #define show_one(file_name, object) \
592 static ssize_t show_##file_name \
593 (struct cpufreq_policy *policy, char *buf) \
595 return sprintf(buf, "%u\n", policy->object); \
598 show_one(cpuinfo_min_freq, cpuinfo.min_freq);
599 show_one(cpuinfo_max_freq, cpuinfo.max_freq);
600 show_one(cpuinfo_transition_latency, cpuinfo.transition_latency);
601 show_one(scaling_min_freq, min);
602 show_one(scaling_max_freq, max);
604 static ssize_t show_scaling_cur_freq(struct cpufreq_policy *policy, char *buf)
608 if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get)
609 ret = sprintf(buf, "%u\n", cpufreq_driver->get(policy->cpu));
611 ret = sprintf(buf, "%u\n", policy->cur);
615 static int cpufreq_set_policy(struct cpufreq_policy *policy,
616 struct cpufreq_policy *new_policy);
619 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
621 #define store_one(file_name, object) \
622 static ssize_t store_##file_name \
623 (struct cpufreq_policy *policy, const char *buf, size_t count) \
626 struct cpufreq_policy new_policy; \
628 memcpy(&new_policy, policy, sizeof(*policy)); \
630 ret = sscanf(buf, "%u", &new_policy.object); \
634 temp = new_policy.object; \
635 ret = cpufreq_set_policy(policy, &new_policy); \
637 policy->user_policy.object = temp; \
639 return ret ? ret : count; \
642 store_one(scaling_min_freq, min);
643 store_one(scaling_max_freq, max);
646 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
648 static ssize_t show_cpuinfo_cur_freq(struct cpufreq_policy *policy,
651 unsigned int cur_freq = __cpufreq_get(policy);
653 return sprintf(buf, "<unknown>");
654 return sprintf(buf, "%u\n", cur_freq);
658 * show_scaling_governor - show the current policy for the specified CPU
660 static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
662 if (policy->policy == CPUFREQ_POLICY_POWERSAVE)
663 return sprintf(buf, "powersave\n");
664 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE)
665 return sprintf(buf, "performance\n");
666 else if (policy->governor)
667 return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n",
668 policy->governor->name);
673 * store_scaling_governor - store policy for the specified CPU
675 static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
676 const char *buf, size_t count)
679 char str_governor[16];
680 struct cpufreq_policy new_policy;
682 memcpy(&new_policy, policy, sizeof(*policy));
684 ret = sscanf(buf, "%15s", str_governor);
688 if (cpufreq_parse_governor(str_governor, &new_policy.policy,
689 &new_policy.governor))
692 ret = cpufreq_set_policy(policy, &new_policy);
693 return ret ? ret : count;
697 * show_scaling_driver - show the cpufreq driver currently loaded
699 static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf)
701 return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name);
705 * show_scaling_available_governors - show the available CPUfreq governors
707 static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy,
711 struct cpufreq_governor *t;
714 i += sprintf(buf, "performance powersave");
718 for_each_governor(t) {
719 if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char))
720 - (CPUFREQ_NAME_LEN + 2)))
722 i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name);
725 i += sprintf(&buf[i], "\n");
729 ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf)
734 for_each_cpu(cpu, mask) {
736 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " ");
737 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu);
738 if (i >= (PAGE_SIZE - 5))
741 i += sprintf(&buf[i], "\n");
744 EXPORT_SYMBOL_GPL(cpufreq_show_cpus);
747 * show_related_cpus - show the CPUs affected by each transition even if
748 * hw coordination is in use
750 static ssize_t show_related_cpus(struct cpufreq_policy *policy, char *buf)
752 return cpufreq_show_cpus(policy->related_cpus, buf);
756 * show_affected_cpus - show the CPUs affected by each transition
758 static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)
760 return cpufreq_show_cpus(policy->cpus, buf);
763 static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
764 const char *buf, size_t count)
766 unsigned int freq = 0;
769 if (!policy->governor || !policy->governor->store_setspeed)
772 ret = sscanf(buf, "%u", &freq);
776 policy->governor->store_setspeed(policy, freq);
781 static ssize_t show_scaling_setspeed(struct cpufreq_policy *policy, char *buf)
783 if (!policy->governor || !policy->governor->show_setspeed)
784 return sprintf(buf, "<unsupported>\n");
786 return policy->governor->show_setspeed(policy, buf);
790 * show_bios_limit - show the current cpufreq HW/BIOS limitation
792 static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
796 if (cpufreq_driver->bios_limit) {
797 ret = cpufreq_driver->bios_limit(policy->cpu, &limit);
799 return sprintf(buf, "%u\n", limit);
801 return sprintf(buf, "%u\n", policy->cpuinfo.max_freq);
804 cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0400);
805 cpufreq_freq_attr_ro(cpuinfo_min_freq);
806 cpufreq_freq_attr_ro(cpuinfo_max_freq);
807 cpufreq_freq_attr_ro(cpuinfo_transition_latency);
808 cpufreq_freq_attr_ro(scaling_available_governors);
809 cpufreq_freq_attr_ro(scaling_driver);
810 cpufreq_freq_attr_ro(scaling_cur_freq);
811 cpufreq_freq_attr_ro(bios_limit);
812 cpufreq_freq_attr_ro(related_cpus);
813 cpufreq_freq_attr_ro(affected_cpus);
814 cpufreq_freq_attr_rw(scaling_min_freq);
815 cpufreq_freq_attr_rw(scaling_max_freq);
816 cpufreq_freq_attr_rw(scaling_governor);
817 cpufreq_freq_attr_rw(scaling_setspeed);
819 static struct attribute *default_attrs[] = {
820 &cpuinfo_min_freq.attr,
821 &cpuinfo_max_freq.attr,
822 &cpuinfo_transition_latency.attr,
823 &scaling_min_freq.attr,
824 &scaling_max_freq.attr,
827 &scaling_governor.attr,
828 &scaling_driver.attr,
829 &scaling_available_governors.attr,
830 &scaling_setspeed.attr,
834 #define to_policy(k) container_of(k, struct cpufreq_policy, kobj)
835 #define to_attr(a) container_of(a, struct freq_attr, attr)
837 static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
839 struct cpufreq_policy *policy = to_policy(kobj);
840 struct freq_attr *fattr = to_attr(attr);
843 down_read(&policy->rwsem);
844 ret = fattr->show(policy, buf);
845 up_read(&policy->rwsem);
850 static ssize_t store(struct kobject *kobj, struct attribute *attr,
851 const char *buf, size_t count)
853 struct cpufreq_policy *policy = to_policy(kobj);
854 struct freq_attr *fattr = to_attr(attr);
855 ssize_t ret = -EINVAL;
859 if (cpu_online(policy->cpu)) {
860 down_write(&policy->rwsem);
861 ret = fattr->store(policy, buf, count);
862 up_write(&policy->rwsem);
870 static void cpufreq_sysfs_release(struct kobject *kobj)
872 struct cpufreq_policy *policy = to_policy(kobj);
873 pr_debug("last reference is dropped\n");
874 complete(&policy->kobj_unregister);
877 static const struct sysfs_ops sysfs_ops = {
882 static struct kobj_type ktype_cpufreq = {
883 .sysfs_ops = &sysfs_ops,
884 .default_attrs = default_attrs,
885 .release = cpufreq_sysfs_release,
888 static int add_cpu_dev_symlink(struct cpufreq_policy *policy, int cpu)
890 struct device *cpu_dev;
892 pr_debug("%s: Adding symlink for CPU: %u\n", __func__, cpu);
897 cpu_dev = get_cpu_device(cpu);
898 if (WARN_ON(!cpu_dev))
901 return sysfs_create_link(&cpu_dev->kobj, &policy->kobj, "cpufreq");
904 static void remove_cpu_dev_symlink(struct cpufreq_policy *policy, int cpu)
906 struct device *cpu_dev;
908 pr_debug("%s: Removing symlink for CPU: %u\n", __func__, cpu);
910 cpu_dev = get_cpu_device(cpu);
911 if (WARN_ON(!cpu_dev))
914 sysfs_remove_link(&cpu_dev->kobj, "cpufreq");
917 /* Add/remove symlinks for all related CPUs */
918 static int cpufreq_add_dev_symlink(struct cpufreq_policy *policy)
923 /* Some related CPUs might not be present (physically hotplugged) */
924 for_each_cpu(j, policy->real_cpus) {
925 ret = add_cpu_dev_symlink(policy, j);
933 static void cpufreq_remove_dev_symlink(struct cpufreq_policy *policy)
937 /* Some related CPUs might not be present (physically hotplugged) */
938 for_each_cpu(j, policy->real_cpus)
939 remove_cpu_dev_symlink(policy, j);
942 static int cpufreq_add_dev_interface(struct cpufreq_policy *policy)
944 struct freq_attr **drv_attr;
947 /* set up files for this cpu device */
948 drv_attr = cpufreq_driver->attr;
949 while (drv_attr && *drv_attr) {
950 ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr));
955 if (cpufreq_driver->get) {
956 ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr);
961 ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr);
965 if (cpufreq_driver->bios_limit) {
966 ret = sysfs_create_file(&policy->kobj, &bios_limit.attr);
971 return cpufreq_add_dev_symlink(policy);
974 __weak struct cpufreq_governor *cpufreq_default_governor(void)
979 static int cpufreq_init_policy(struct cpufreq_policy *policy)
981 struct cpufreq_governor *gov = NULL;
982 struct cpufreq_policy new_policy;
984 memcpy(&new_policy, policy, sizeof(*policy));
986 /* Update governor of new_policy to the governor used before hotplug */
987 gov = find_governor(policy->last_governor);
989 pr_debug("Restoring governor %s for cpu %d\n",
990 policy->governor->name, policy->cpu);
992 gov = cpufreq_default_governor();
997 new_policy.governor = gov;
999 /* Use the default policy if there is no last_policy. */
1000 if (cpufreq_driver->setpolicy) {
1001 if (policy->last_policy)
1002 new_policy.policy = policy->last_policy;
1004 cpufreq_parse_governor(gov->name, &new_policy.policy,
1007 /* set default policy */
1008 return cpufreq_set_policy(policy, &new_policy);
1011 static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
1015 /* Has this CPU been taken care of already? */
1016 if (cpumask_test_cpu(cpu, policy->cpus))
1019 down_write(&policy->rwsem);
1021 ret = cpufreq_governor(policy, CPUFREQ_GOV_STOP);
1023 pr_err("%s: Failed to stop governor\n", __func__);
1028 cpumask_set_cpu(cpu, policy->cpus);
1031 ret = cpufreq_start_governor(policy);
1033 pr_err("%s: Failed to start governor\n", __func__);
1037 up_write(&policy->rwsem);
1041 static void handle_update(struct work_struct *work)
1043 struct cpufreq_policy *policy =
1044 container_of(work, struct cpufreq_policy, update);
1045 unsigned int cpu = policy->cpu;
1046 pr_debug("handle_update for cpu %u called\n", cpu);
1047 cpufreq_update_policy(cpu);
1050 static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
1052 struct device *dev = get_cpu_device(cpu);
1053 struct cpufreq_policy *policy;
1059 policy = kzalloc(sizeof(*policy), GFP_KERNEL);
1063 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL))
1064 goto err_free_policy;
1066 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL))
1067 goto err_free_cpumask;
1069 if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL))
1070 goto err_free_rcpumask;
1072 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq,
1073 cpufreq_global_kobject, "policy%u", cpu);
1075 pr_err("%s: failed to init policy->kobj: %d\n", __func__, ret);
1076 goto err_free_real_cpus;
1079 INIT_LIST_HEAD(&policy->policy_list);
1080 init_rwsem(&policy->rwsem);
1081 spin_lock_init(&policy->transition_lock);
1082 init_waitqueue_head(&policy->transition_wait);
1083 init_completion(&policy->kobj_unregister);
1084 INIT_WORK(&policy->update, handle_update);
1090 free_cpumask_var(policy->real_cpus);
1092 free_cpumask_var(policy->related_cpus);
1094 free_cpumask_var(policy->cpus);
1101 static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy, bool notify)
1103 struct kobject *kobj;
1104 struct completion *cmp;
1107 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1108 CPUFREQ_REMOVE_POLICY, policy);
1110 down_write(&policy->rwsem);
1111 cpufreq_remove_dev_symlink(policy);
1112 kobj = &policy->kobj;
1113 cmp = &policy->kobj_unregister;
1114 up_write(&policy->rwsem);
1118 * We need to make sure that the underlying kobj is
1119 * actually not referenced anymore by anybody before we
1120 * proceed with unloading.
1122 pr_debug("waiting for dropping of refcount\n");
1123 wait_for_completion(cmp);
1124 pr_debug("wait complete\n");
1127 static void cpufreq_policy_free(struct cpufreq_policy *policy, bool notify)
1129 unsigned long flags;
1132 /* Remove policy from list */
1133 write_lock_irqsave(&cpufreq_driver_lock, flags);
1134 list_del(&policy->policy_list);
1136 for_each_cpu(cpu, policy->related_cpus)
1137 per_cpu(cpufreq_cpu_data, cpu) = NULL;
1138 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1140 cpufreq_policy_put_kobj(policy, notify);
1141 free_cpumask_var(policy->real_cpus);
1142 free_cpumask_var(policy->related_cpus);
1143 free_cpumask_var(policy->cpus);
1147 static int cpufreq_online(unsigned int cpu)
1149 struct cpufreq_policy *policy;
1151 unsigned long flags;
1155 pr_debug("%s: bringing CPU%u online\n", __func__, cpu);
1157 /* Check if this CPU already has a policy to manage it */
1158 policy = per_cpu(cpufreq_cpu_data, cpu);
1160 WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus));
1161 if (!policy_is_inactive(policy))
1162 return cpufreq_add_policy_cpu(policy, cpu);
1164 /* This is the only online CPU for the policy. Start over. */
1166 down_write(&policy->rwsem);
1168 policy->governor = NULL;
1169 up_write(&policy->rwsem);
1172 policy = cpufreq_policy_alloc(cpu);
1177 cpumask_copy(policy->cpus, cpumask_of(cpu));
1179 /* call driver. From then on the cpufreq must be able
1180 * to accept all calls to ->verify and ->setpolicy for this CPU
1182 ret = cpufreq_driver->init(policy);
1184 pr_debug("initialization failed\n");
1185 goto out_free_policy;
1188 down_write(&policy->rwsem);
1191 /* related_cpus should at least include policy->cpus. */
1192 cpumask_copy(policy->related_cpus, policy->cpus);
1193 /* Remember CPUs present at the policy creation time. */
1194 cpumask_and(policy->real_cpus, policy->cpus, cpu_present_mask);
1198 * affected cpus must always be the one, which are online. We aren't
1199 * managing offline cpus here.
1201 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
1204 policy->user_policy.min = policy->min;
1205 policy->user_policy.max = policy->max;
1207 write_lock_irqsave(&cpufreq_driver_lock, flags);
1208 for_each_cpu(j, policy->related_cpus)
1209 per_cpu(cpufreq_cpu_data, j) = policy;
1210 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1213 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
1214 policy->cur = cpufreq_driver->get(policy->cpu);
1216 pr_err("%s: ->get() failed\n", __func__);
1217 goto out_exit_policy;
1222 * Sometimes boot loaders set CPU frequency to a value outside of
1223 * frequency table present with cpufreq core. In such cases CPU might be
1224 * unstable if it has to run on that frequency for long duration of time
1225 * and so its better to set it to a frequency which is specified in
1226 * freq-table. This also makes cpufreq stats inconsistent as
1227 * cpufreq-stats would fail to register because current frequency of CPU
1228 * isn't found in freq-table.
1230 * Because we don't want this change to effect boot process badly, we go
1231 * for the next freq which is >= policy->cur ('cur' must be set by now,
1232 * otherwise we will end up setting freq to lowest of the table as 'cur'
1233 * is initialized to zero).
1235 * We are passing target-freq as "policy->cur - 1" otherwise
1236 * __cpufreq_driver_target() would simply fail, as policy->cur will be
1237 * equal to target-freq.
1239 if ((cpufreq_driver->flags & CPUFREQ_NEED_INITIAL_FREQ_CHECK)
1241 /* Are we running at unknown frequency ? */
1242 ret = cpufreq_frequency_table_get_index(policy, policy->cur);
1243 if (ret == -EINVAL) {
1244 /* Warn user and fix it */
1245 pr_warn("%s: CPU%d: Running at unlisted freq: %u KHz\n",
1246 __func__, policy->cpu, policy->cur);
1247 ret = __cpufreq_driver_target(policy, policy->cur - 1,
1248 CPUFREQ_RELATION_L);
1251 * Reaching here after boot in a few seconds may not
1252 * mean that system will remain stable at "unknown"
1253 * frequency for longer duration. Hence, a BUG_ON().
1256 pr_warn("%s: CPU%d: Unlisted initial frequency changed to: %u KHz\n",
1257 __func__, policy->cpu, policy->cur);
1261 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1262 CPUFREQ_START, policy);
1265 ret = cpufreq_add_dev_interface(policy);
1267 goto out_exit_policy;
1268 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1269 CPUFREQ_CREATE_POLICY, policy);
1271 write_lock_irqsave(&cpufreq_driver_lock, flags);
1272 list_add(&policy->policy_list, &cpufreq_policy_list);
1273 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1276 ret = cpufreq_init_policy(policy);
1278 pr_err("%s: Failed to initialize policy for cpu: %d (%d)\n",
1279 __func__, cpu, ret);
1280 /* cpufreq_policy_free() will notify based on this */
1282 goto out_exit_policy;
1285 up_write(&policy->rwsem);
1287 kobject_uevent(&policy->kobj, KOBJ_ADD);
1289 /* Callback for handling stuff after policy is ready */
1290 if (cpufreq_driver->ready)
1291 cpufreq_driver->ready(policy);
1293 pr_debug("initialization complete\n");
1298 up_write(&policy->rwsem);
1300 if (cpufreq_driver->exit)
1301 cpufreq_driver->exit(policy);
1303 cpufreq_policy_free(policy, !new_policy);
1308 * cpufreq_add_dev - the cpufreq interface for a CPU device.
1310 * @sif: Subsystem interface structure pointer (not used)
1312 static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
1314 unsigned cpu = dev->id;
1317 dev_dbg(dev, "%s: adding CPU%u\n", __func__, cpu);
1319 if (cpu_online(cpu)) {
1320 ret = cpufreq_online(cpu);
1323 * A hotplug notifier will follow and we will handle it as CPU
1324 * online then. For now, just create the sysfs link, unless
1325 * there is no policy or the link is already present.
1327 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
1329 ret = policy && !cpumask_test_and_set_cpu(cpu, policy->real_cpus)
1330 ? add_cpu_dev_symlink(policy, cpu) : 0;
1336 static void cpufreq_offline(unsigned int cpu)
1338 struct cpufreq_policy *policy;
1341 pr_debug("%s: unregistering CPU %u\n", __func__, cpu);
1343 policy = cpufreq_cpu_get_raw(cpu);
1345 pr_debug("%s: No cpu_data found\n", __func__);
1349 down_write(&policy->rwsem);
1351 ret = cpufreq_governor(policy, CPUFREQ_GOV_STOP);
1353 pr_err("%s: Failed to stop governor\n", __func__);
1356 cpumask_clear_cpu(cpu, policy->cpus);
1358 if (policy_is_inactive(policy)) {
1360 strncpy(policy->last_governor, policy->governor->name,
1363 policy->last_policy = policy->policy;
1364 } else if (cpu == policy->cpu) {
1365 /* Nominate new CPU */
1366 policy->cpu = cpumask_any(policy->cpus);
1369 /* Start governor again for active policy */
1370 if (!policy_is_inactive(policy)) {
1372 ret = cpufreq_start_governor(policy);
1374 pr_err("%s: Failed to start governor\n", __func__);
1380 if (cpufreq_driver->stop_cpu)
1381 cpufreq_driver->stop_cpu(policy);
1383 /* If cpu is last user of policy, free policy */
1385 ret = cpufreq_exit_governor(policy);
1387 pr_err("%s: Failed to exit governor\n", __func__);
1391 * Perform the ->exit() even during light-weight tear-down,
1392 * since this is a core component, and is essential for the
1393 * subsequent light-weight ->init() to succeed.
1395 if (cpufreq_driver->exit) {
1396 cpufreq_driver->exit(policy);
1397 policy->freq_table = NULL;
1401 up_write(&policy->rwsem);
1405 * cpufreq_remove_dev - remove a CPU device
1407 * Removes the cpufreq interface for a CPU device.
1409 static void cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)
1411 unsigned int cpu = dev->id;
1412 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
1417 if (cpu_online(cpu))
1418 cpufreq_offline(cpu);
1420 cpumask_clear_cpu(cpu, policy->real_cpus);
1421 remove_cpu_dev_symlink(policy, cpu);
1423 if (cpumask_empty(policy->real_cpus))
1424 cpufreq_policy_free(policy, true);
1428 * cpufreq_out_of_sync - If actual and saved CPU frequency differs, we're
1430 * @policy: policy managing CPUs
1431 * @new_freq: CPU frequency the CPU actually runs at
1433 * We adjust to current frequency first, and need to clean up later.
1434 * So either call to cpufreq_update_policy() or schedule handle_update()).
1436 static void cpufreq_out_of_sync(struct cpufreq_policy *policy,
1437 unsigned int new_freq)
1439 struct cpufreq_freqs freqs;
1441 pr_debug("Warning: CPU frequency out of sync: cpufreq and timing core thinks of %u, is %u kHz\n",
1442 policy->cur, new_freq);
1444 freqs.old = policy->cur;
1445 freqs.new = new_freq;
1447 cpufreq_freq_transition_begin(policy, &freqs);
1448 cpufreq_freq_transition_end(policy, &freqs, 0);
1452 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
1455 * This is the last known freq, without actually getting it from the driver.
1456 * Return value will be same as what is shown in scaling_cur_freq in sysfs.
1458 unsigned int cpufreq_quick_get(unsigned int cpu)
1460 struct cpufreq_policy *policy;
1461 unsigned int ret_freq = 0;
1462 unsigned long flags;
1464 read_lock_irqsave(&cpufreq_driver_lock, flags);
1466 if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) {
1467 ret_freq = cpufreq_driver->get(cpu);
1468 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
1472 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
1474 policy = cpufreq_cpu_get(cpu);
1476 ret_freq = policy->cur;
1477 cpufreq_cpu_put(policy);
1482 EXPORT_SYMBOL(cpufreq_quick_get);
1485 * cpufreq_quick_get_max - get the max reported CPU frequency for this CPU
1488 * Just return the max possible frequency for a given CPU.
1490 unsigned int cpufreq_quick_get_max(unsigned int cpu)
1492 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1493 unsigned int ret_freq = 0;
1496 ret_freq = policy->max;
1497 cpufreq_cpu_put(policy);
1502 EXPORT_SYMBOL(cpufreq_quick_get_max);
1504 static unsigned int __cpufreq_get(struct cpufreq_policy *policy)
1506 unsigned int ret_freq = 0;
1508 if (!cpufreq_driver->get)
1511 ret_freq = cpufreq_driver->get(policy->cpu);
1514 * Updating inactive policies is invalid, so avoid doing that. Also
1515 * if fast frequency switching is used with the given policy, the check
1516 * against policy->cur is pointless, so skip it in that case too.
1518 if (unlikely(policy_is_inactive(policy)) || policy->fast_switch_enabled)
1521 if (ret_freq && policy->cur &&
1522 !(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
1523 /* verify no discrepancy between actual and
1524 saved value exists */
1525 if (unlikely(ret_freq != policy->cur)) {
1526 cpufreq_out_of_sync(policy, ret_freq);
1527 schedule_work(&policy->update);
1535 * cpufreq_get - get the current CPU frequency (in kHz)
1538 * Get the CPU current (static) CPU frequency
1540 unsigned int cpufreq_get(unsigned int cpu)
1542 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1543 unsigned int ret_freq = 0;
1546 down_read(&policy->rwsem);
1547 ret_freq = __cpufreq_get(policy);
1548 up_read(&policy->rwsem);
1550 cpufreq_cpu_put(policy);
1555 EXPORT_SYMBOL(cpufreq_get);
1557 static unsigned int cpufreq_update_current_freq(struct cpufreq_policy *policy)
1559 unsigned int new_freq;
1561 new_freq = cpufreq_driver->get(policy->cpu);
1566 pr_debug("cpufreq: Driver did not initialize current freq\n");
1567 policy->cur = new_freq;
1568 } else if (policy->cur != new_freq && has_target()) {
1569 cpufreq_out_of_sync(policy, new_freq);
1575 static struct subsys_interface cpufreq_interface = {
1577 .subsys = &cpu_subsys,
1578 .add_dev = cpufreq_add_dev,
1579 .remove_dev = cpufreq_remove_dev,
1583 * In case platform wants some specific frequency to be configured
1586 int cpufreq_generic_suspend(struct cpufreq_policy *policy)
1590 if (!policy->suspend_freq) {
1591 pr_debug("%s: suspend_freq not defined\n", __func__);
1595 pr_debug("%s: Setting suspend-freq: %u\n", __func__,
1596 policy->suspend_freq);
1598 ret = __cpufreq_driver_target(policy, policy->suspend_freq,
1599 CPUFREQ_RELATION_H);
1601 pr_err("%s: unable to set suspend-freq: %u. err: %d\n",
1602 __func__, policy->suspend_freq, ret);
1606 EXPORT_SYMBOL(cpufreq_generic_suspend);
1609 * cpufreq_suspend() - Suspend CPUFreq governors
1611 * Called during system wide Suspend/Hibernate cycles for suspending governors
1612 * as some platforms can't change frequency after this point in suspend cycle.
1613 * Because some of the devices (like: i2c, regulators, etc) they use for
1614 * changing frequency are suspended quickly after this point.
1616 void cpufreq_suspend(void)
1618 struct cpufreq_policy *policy;
1621 if (!cpufreq_driver)
1627 pr_debug("%s: Suspending Governors\n", __func__);
1629 for_each_active_policy(policy) {
1630 down_write(&policy->rwsem);
1631 ret = cpufreq_governor(policy, CPUFREQ_GOV_STOP);
1632 up_write(&policy->rwsem);
1635 pr_err("%s: Failed to stop governor for policy: %p\n",
1637 else if (cpufreq_driver->suspend
1638 && cpufreq_driver->suspend(policy))
1639 pr_err("%s: Failed to suspend driver: %p\n", __func__,
1644 cpufreq_suspended = true;
1648 * cpufreq_resume() - Resume CPUFreq governors
1650 * Called during system wide Suspend/Hibernate cycle for resuming governors that
1651 * are suspended with cpufreq_suspend().
1653 void cpufreq_resume(void)
1655 struct cpufreq_policy *policy;
1658 if (!cpufreq_driver)
1661 cpufreq_suspended = false;
1666 pr_debug("%s: Resuming Governors\n", __func__);
1668 for_each_active_policy(policy) {
1669 if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) {
1670 pr_err("%s: Failed to resume driver: %p\n", __func__,
1673 down_write(&policy->rwsem);
1674 ret = cpufreq_start_governor(policy);
1675 up_write(&policy->rwsem);
1678 pr_err("%s: Failed to start governor for policy: %p\n",
1685 * cpufreq_get_current_driver - return current driver's name
1687 * Return the name string of the currently loaded cpufreq driver
1690 const char *cpufreq_get_current_driver(void)
1693 return cpufreq_driver->name;
1697 EXPORT_SYMBOL_GPL(cpufreq_get_current_driver);
1700 * cpufreq_get_driver_data - return current driver data
1702 * Return the private data of the currently loaded cpufreq
1703 * driver, or NULL if no cpufreq driver is loaded.
1705 void *cpufreq_get_driver_data(void)
1708 return cpufreq_driver->driver_data;
1712 EXPORT_SYMBOL_GPL(cpufreq_get_driver_data);
1714 /*********************************************************************
1715 * NOTIFIER LISTS INTERFACE *
1716 *********************************************************************/
1719 * cpufreq_register_notifier - register a driver with cpufreq
1720 * @nb: notifier function to register
1721 * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER
1723 * Add a driver to one of two lists: either a list of drivers that
1724 * are notified about clock rate changes (once before and once after
1725 * the transition), or a list of drivers that are notified about
1726 * changes in cpufreq policy.
1728 * This function may sleep, and has the same return conditions as
1729 * blocking_notifier_chain_register.
1731 int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list)
1735 if (cpufreq_disabled())
1738 WARN_ON(!init_cpufreq_transition_notifier_list_called);
1741 case CPUFREQ_TRANSITION_NOTIFIER:
1742 mutex_lock(&cpufreq_fast_switch_lock);
1744 if (cpufreq_fast_switch_count > 0) {
1745 mutex_unlock(&cpufreq_fast_switch_lock);
1748 ret = srcu_notifier_chain_register(
1749 &cpufreq_transition_notifier_list, nb);
1751 cpufreq_fast_switch_count--;
1753 mutex_unlock(&cpufreq_fast_switch_lock);
1755 case CPUFREQ_POLICY_NOTIFIER:
1756 ret = blocking_notifier_chain_register(
1757 &cpufreq_policy_notifier_list, nb);
1765 EXPORT_SYMBOL(cpufreq_register_notifier);
1768 * cpufreq_unregister_notifier - unregister a driver with cpufreq
1769 * @nb: notifier block to be unregistered
1770 * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER
1772 * Remove a driver from the CPU frequency notifier list.
1774 * This function may sleep, and has the same return conditions as
1775 * blocking_notifier_chain_unregister.
1777 int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list)
1781 if (cpufreq_disabled())
1785 case CPUFREQ_TRANSITION_NOTIFIER:
1786 mutex_lock(&cpufreq_fast_switch_lock);
1788 ret = srcu_notifier_chain_unregister(
1789 &cpufreq_transition_notifier_list, nb);
1790 if (!ret && !WARN_ON(cpufreq_fast_switch_count >= 0))
1791 cpufreq_fast_switch_count++;
1793 mutex_unlock(&cpufreq_fast_switch_lock);
1795 case CPUFREQ_POLICY_NOTIFIER:
1796 ret = blocking_notifier_chain_unregister(
1797 &cpufreq_policy_notifier_list, nb);
1805 EXPORT_SYMBOL(cpufreq_unregister_notifier);
1808 /*********************************************************************
1810 *********************************************************************/
1813 * cpufreq_driver_fast_switch - Carry out a fast CPU frequency switch.
1814 * @policy: cpufreq policy to switch the frequency for.
1815 * @target_freq: New frequency to set (may be approximate).
1817 * Carry out a fast frequency switch without sleeping.
1819 * The driver's ->fast_switch() callback invoked by this function must be
1820 * suitable for being called from within RCU-sched read-side critical sections
1821 * and it is expected to select the minimum available frequency greater than or
1822 * equal to @target_freq (CPUFREQ_RELATION_L).
1824 * This function must not be called if policy->fast_switch_enabled is unset.
1826 * Governors calling this function must guarantee that it will never be invoked
1827 * twice in parallel for the same policy and that it will never be called in
1828 * parallel with either ->target() or ->target_index() for the same policy.
1830 * If CPUFREQ_ENTRY_INVALID is returned by the driver's ->fast_switch()
1831 * callback to indicate an error condition, the hardware configuration must be
1834 unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy,
1835 unsigned int target_freq)
1837 clamp_val(target_freq, policy->min, policy->max);
1839 return cpufreq_driver->fast_switch(policy, target_freq);
1841 EXPORT_SYMBOL_GPL(cpufreq_driver_fast_switch);
1843 /* Must set freqs->new to intermediate frequency */
1844 static int __target_intermediate(struct cpufreq_policy *policy,
1845 struct cpufreq_freqs *freqs, int index)
1849 freqs->new = cpufreq_driver->get_intermediate(policy, index);
1851 /* We don't need to switch to intermediate freq */
1855 pr_debug("%s: cpu: %d, switching to intermediate freq: oldfreq: %u, intermediate freq: %u\n",
1856 __func__, policy->cpu, freqs->old, freqs->new);
1858 cpufreq_freq_transition_begin(policy, freqs);
1859 ret = cpufreq_driver->target_intermediate(policy, index);
1860 cpufreq_freq_transition_end(policy, freqs, ret);
1863 pr_err("%s: Failed to change to intermediate frequency: %d\n",
1869 static int __target_index(struct cpufreq_policy *policy,
1870 struct cpufreq_frequency_table *freq_table, int index)
1872 struct cpufreq_freqs freqs = {.old = policy->cur, .flags = 0};
1873 unsigned int intermediate_freq = 0;
1874 int retval = -EINVAL;
1877 notify = !(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION);
1879 /* Handle switching to intermediate frequency */
1880 if (cpufreq_driver->get_intermediate) {
1881 retval = __target_intermediate(policy, &freqs, index);
1885 intermediate_freq = freqs.new;
1886 /* Set old freq to intermediate */
1887 if (intermediate_freq)
1888 freqs.old = freqs.new;
1891 freqs.new = freq_table[index].frequency;
1892 pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n",
1893 __func__, policy->cpu, freqs.old, freqs.new);
1895 cpufreq_freq_transition_begin(policy, &freqs);
1898 retval = cpufreq_driver->target_index(policy, index);
1900 pr_err("%s: Failed to change cpu frequency: %d\n", __func__,
1904 cpufreq_freq_transition_end(policy, &freqs, retval);
1907 * Failed after setting to intermediate freq? Driver should have
1908 * reverted back to initial frequency and so should we. Check
1909 * here for intermediate_freq instead of get_intermediate, in
1910 * case we haven't switched to intermediate freq at all.
1912 if (unlikely(retval && intermediate_freq)) {
1913 freqs.old = intermediate_freq;
1914 freqs.new = policy->restore_freq;
1915 cpufreq_freq_transition_begin(policy, &freqs);
1916 cpufreq_freq_transition_end(policy, &freqs, 0);
1923 int __cpufreq_driver_target(struct cpufreq_policy *policy,
1924 unsigned int target_freq,
1925 unsigned int relation)
1927 unsigned int old_target_freq = target_freq;
1928 struct cpufreq_frequency_table *freq_table;
1931 if (cpufreq_disabled())
1934 /* Make sure that target_freq is within supported range */
1935 if (target_freq > policy->max)
1936 target_freq = policy->max;
1937 if (target_freq < policy->min)
1938 target_freq = policy->min;
1940 pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n",
1941 policy->cpu, target_freq, relation, old_target_freq);
1944 * This might look like a redundant call as we are checking it again
1945 * after finding index. But it is left intentionally for cases where
1946 * exactly same freq is called again and so we can save on few function
1949 if (target_freq == policy->cur)
1952 /* Save last value to restore later on errors */
1953 policy->restore_freq = policy->cur;
1955 if (cpufreq_driver->target)
1956 return cpufreq_driver->target(policy, target_freq, relation);
1958 if (!cpufreq_driver->target_index)
1961 freq_table = cpufreq_frequency_get_table(policy->cpu);
1962 if (unlikely(!freq_table)) {
1963 pr_err("%s: Unable to find freq_table\n", __func__);
1967 retval = cpufreq_frequency_table_target(policy, freq_table, target_freq,
1969 if (unlikely(retval)) {
1970 pr_err("%s: Unable to find matching freq\n", __func__);
1974 if (freq_table[index].frequency == policy->cur)
1977 return __target_index(policy, freq_table, index);
1979 EXPORT_SYMBOL_GPL(__cpufreq_driver_target);
1981 int cpufreq_driver_target(struct cpufreq_policy *policy,
1982 unsigned int target_freq,
1983 unsigned int relation)
1987 down_write(&policy->rwsem);
1989 ret = __cpufreq_driver_target(policy, target_freq, relation);
1991 up_write(&policy->rwsem);
1995 EXPORT_SYMBOL_GPL(cpufreq_driver_target);
1997 __weak struct cpufreq_governor *cpufreq_fallback_governor(void)
2002 static int cpufreq_governor(struct cpufreq_policy *policy, unsigned int event)
2006 /* Don't start any governor operations if we are entering suspend */
2007 if (cpufreq_suspended)
2010 * Governor might not be initiated here if ACPI _PPC changed
2011 * notification happened, so check it.
2013 if (!policy->governor)
2016 if (policy->governor->max_transition_latency &&
2017 policy->cpuinfo.transition_latency >
2018 policy->governor->max_transition_latency) {
2019 struct cpufreq_governor *gov = cpufreq_fallback_governor();
2022 pr_warn("%s governor failed, too long transition latency of HW, fallback to %s governor\n",
2023 policy->governor->name, gov->name);
2024 policy->governor = gov;
2030 if (event == CPUFREQ_GOV_POLICY_INIT)
2031 if (!try_module_get(policy->governor->owner))
2034 pr_debug("%s: for CPU %u, event %u\n", __func__, policy->cpu, event);
2036 ret = policy->governor->governor(policy, event);
2039 if (event == CPUFREQ_GOV_POLICY_INIT)
2040 policy->governor->initialized++;
2041 else if (event == CPUFREQ_GOV_POLICY_EXIT)
2042 policy->governor->initialized--;
2045 if (((event == CPUFREQ_GOV_POLICY_INIT) && ret) ||
2046 ((event == CPUFREQ_GOV_POLICY_EXIT) && !ret))
2047 module_put(policy->governor->owner);
2052 static int cpufreq_start_governor(struct cpufreq_policy *policy)
2056 if (cpufreq_driver->get && !cpufreq_driver->setpolicy)
2057 cpufreq_update_current_freq(policy);
2059 ret = cpufreq_governor(policy, CPUFREQ_GOV_START);
2060 return ret ? ret : cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
2063 static int cpufreq_exit_governor(struct cpufreq_policy *policy)
2065 cpufreq_disable_fast_switch(policy);
2066 return cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT);
2069 int cpufreq_register_governor(struct cpufreq_governor *governor)
2076 if (cpufreq_disabled())
2079 mutex_lock(&cpufreq_governor_mutex);
2081 governor->initialized = 0;
2083 if (!find_governor(governor->name)) {
2085 list_add(&governor->governor_list, &cpufreq_governor_list);
2088 mutex_unlock(&cpufreq_governor_mutex);
2091 EXPORT_SYMBOL_GPL(cpufreq_register_governor);
2093 void cpufreq_unregister_governor(struct cpufreq_governor *governor)
2095 struct cpufreq_policy *policy;
2096 unsigned long flags;
2101 if (cpufreq_disabled())
2104 /* clear last_governor for all inactive policies */
2105 read_lock_irqsave(&cpufreq_driver_lock, flags);
2106 for_each_inactive_policy(policy) {
2107 if (!strcmp(policy->last_governor, governor->name)) {
2108 policy->governor = NULL;
2109 strcpy(policy->last_governor, "\0");
2112 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
2114 mutex_lock(&cpufreq_governor_mutex);
2115 list_del(&governor->governor_list);
2116 mutex_unlock(&cpufreq_governor_mutex);
2119 EXPORT_SYMBOL_GPL(cpufreq_unregister_governor);
2122 /*********************************************************************
2123 * POLICY INTERFACE *
2124 *********************************************************************/
2127 * cpufreq_get_policy - get the current cpufreq_policy
2128 * @policy: struct cpufreq_policy into which the current cpufreq_policy
2131 * Reads the current cpufreq policy.
2133 int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
2135 struct cpufreq_policy *cpu_policy;
2139 cpu_policy = cpufreq_cpu_get(cpu);
2143 memcpy(policy, cpu_policy, sizeof(*policy));
2145 cpufreq_cpu_put(cpu_policy);
2148 EXPORT_SYMBOL(cpufreq_get_policy);
2151 * policy : current policy.
2152 * new_policy: policy to be set.
2154 static int cpufreq_set_policy(struct cpufreq_policy *policy,
2155 struct cpufreq_policy *new_policy)
2157 struct cpufreq_governor *old_gov;
2160 pr_debug("setting new policy for CPU %u: %u - %u kHz\n",
2161 new_policy->cpu, new_policy->min, new_policy->max);
2163 memcpy(&new_policy->cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo));
2166 * This check works well when we store new min/max freq attributes,
2167 * because new_policy is a copy of policy with one field updated.
2169 if (new_policy->min > new_policy->max)
2172 /* verify the cpu speed can be set within this limit */
2173 ret = cpufreq_driver->verify(new_policy);
2177 /* adjust if necessary - all reasons */
2178 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
2179 CPUFREQ_ADJUST, new_policy);
2182 * verify the cpu speed can be set within this limit, which might be
2183 * different to the first one
2185 ret = cpufreq_driver->verify(new_policy);
2189 /* notification of the new policy */
2190 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
2191 CPUFREQ_NOTIFY, new_policy);
2193 policy->min = new_policy->min;
2194 policy->max = new_policy->max;
2196 pr_debug("new min and max freqs are %u - %u kHz\n",
2197 policy->min, policy->max);
2199 if (cpufreq_driver->setpolicy) {
2200 policy->policy = new_policy->policy;
2201 pr_debug("setting range\n");
2202 return cpufreq_driver->setpolicy(new_policy);
2205 if (new_policy->governor == policy->governor) {
2206 pr_debug("cpufreq: governor limits update\n");
2207 return cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
2210 pr_debug("governor switch\n");
2212 /* save old, working values */
2213 old_gov = policy->governor;
2214 /* end old governor */
2216 ret = cpufreq_governor(policy, CPUFREQ_GOV_STOP);
2218 /* This can happen due to race with other operations */
2219 pr_debug("%s: Failed to Stop Governor: %s (%d)\n",
2220 __func__, old_gov->name, ret);
2224 ret = cpufreq_exit_governor(policy);
2226 pr_err("%s: Failed to Exit Governor: %s (%d)\n",
2227 __func__, old_gov->name, ret);
2232 /* start new governor */
2233 policy->governor = new_policy->governor;
2234 ret = cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT);
2236 ret = cpufreq_start_governor(policy);
2238 pr_debug("cpufreq: governor change\n");
2241 cpufreq_exit_governor(policy);
2244 /* new governor failed, so re-start old one */
2245 pr_debug("starting governor %s failed\n", policy->governor->name);
2247 policy->governor = old_gov;
2248 if (cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT))
2249 policy->governor = NULL;
2251 cpufreq_start_governor(policy);
2258 * cpufreq_update_policy - re-evaluate an existing cpufreq policy
2259 * @cpu: CPU which shall be re-evaluated
2261 * Useful for policy notifiers which have different necessities
2262 * at different times.
2264 int cpufreq_update_policy(unsigned int cpu)
2266 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
2267 struct cpufreq_policy new_policy;
2273 down_write(&policy->rwsem);
2275 pr_debug("updating policy for CPU %u\n", cpu);
2276 memcpy(&new_policy, policy, sizeof(*policy));
2277 new_policy.min = policy->user_policy.min;
2278 new_policy.max = policy->user_policy.max;
2281 * BIOS might change freq behind our back
2282 * -> ask driver for current freq and notify governors about a change
2284 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
2285 new_policy.cur = cpufreq_update_current_freq(policy);
2286 if (WARN_ON(!new_policy.cur)) {
2292 ret = cpufreq_set_policy(policy, &new_policy);
2295 up_write(&policy->rwsem);
2297 cpufreq_cpu_put(policy);
2300 EXPORT_SYMBOL(cpufreq_update_policy);
2302 static int cpufreq_cpu_callback(struct notifier_block *nfb,
2303 unsigned long action, void *hcpu)
2305 unsigned int cpu = (unsigned long)hcpu;
2307 switch (action & ~CPU_TASKS_FROZEN) {
2309 cpufreq_online(cpu);
2312 case CPU_DOWN_PREPARE:
2313 cpufreq_offline(cpu);
2316 case CPU_DOWN_FAILED:
2317 cpufreq_online(cpu);
2323 static struct notifier_block __refdata cpufreq_cpu_notifier = {
2324 .notifier_call = cpufreq_cpu_callback,
2327 /*********************************************************************
2329 *********************************************************************/
2330 static int cpufreq_boost_set_sw(int state)
2332 struct cpufreq_frequency_table *freq_table;
2333 struct cpufreq_policy *policy;
2336 for_each_active_policy(policy) {
2337 freq_table = cpufreq_frequency_get_table(policy->cpu);
2339 ret = cpufreq_frequency_table_cpuinfo(policy,
2342 pr_err("%s: Policy frequency update failed\n",
2347 down_write(&policy->rwsem);
2348 policy->user_policy.max = policy->max;
2349 cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
2350 up_write(&policy->rwsem);
2357 int cpufreq_boost_trigger_state(int state)
2359 unsigned long flags;
2362 if (cpufreq_driver->boost_enabled == state)
2365 write_lock_irqsave(&cpufreq_driver_lock, flags);
2366 cpufreq_driver->boost_enabled = state;
2367 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2369 ret = cpufreq_driver->set_boost(state);
2371 write_lock_irqsave(&cpufreq_driver_lock, flags);
2372 cpufreq_driver->boost_enabled = !state;
2373 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2375 pr_err("%s: Cannot %s BOOST\n",
2376 __func__, state ? "enable" : "disable");
2382 static bool cpufreq_boost_supported(void)
2384 return likely(cpufreq_driver) && cpufreq_driver->set_boost;
2387 static int create_boost_sysfs_file(void)
2391 ret = sysfs_create_file(cpufreq_global_kobject, &boost.attr);
2393 pr_err("%s: cannot register global BOOST sysfs file\n",
2399 static void remove_boost_sysfs_file(void)
2401 if (cpufreq_boost_supported())
2402 sysfs_remove_file(cpufreq_global_kobject, &boost.attr);
2405 int cpufreq_enable_boost_support(void)
2407 if (!cpufreq_driver)
2410 if (cpufreq_boost_supported())
2413 cpufreq_driver->set_boost = cpufreq_boost_set_sw;
2415 /* This will get removed on driver unregister */
2416 return create_boost_sysfs_file();
2418 EXPORT_SYMBOL_GPL(cpufreq_enable_boost_support);
2420 int cpufreq_boost_enabled(void)
2422 return cpufreq_driver->boost_enabled;
2424 EXPORT_SYMBOL_GPL(cpufreq_boost_enabled);
2426 /*********************************************************************
2427 * REGISTER / UNREGISTER CPUFREQ DRIVER *
2428 *********************************************************************/
2431 * cpufreq_register_driver - register a CPU Frequency driver
2432 * @driver_data: A struct cpufreq_driver containing the values#
2433 * submitted by the CPU Frequency driver.
2435 * Registers a CPU Frequency driver to this core code. This code
2436 * returns zero on success, -EEXIST when another driver got here first
2437 * (and isn't unregistered in the meantime).
2440 int cpufreq_register_driver(struct cpufreq_driver *driver_data)
2442 unsigned long flags;
2445 if (cpufreq_disabled())
2448 if (!driver_data || !driver_data->verify || !driver_data->init ||
2449 !(driver_data->setpolicy || driver_data->target_index ||
2450 driver_data->target) ||
2451 (driver_data->setpolicy && (driver_data->target_index ||
2452 driver_data->target)) ||
2453 (!!driver_data->get_intermediate != !!driver_data->target_intermediate))
2456 pr_debug("trying to register driver %s\n", driver_data->name);
2458 /* Protect against concurrent CPU online/offline. */
2461 write_lock_irqsave(&cpufreq_driver_lock, flags);
2462 if (cpufreq_driver) {
2463 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2467 cpufreq_driver = driver_data;
2468 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2470 if (driver_data->setpolicy)
2471 driver_data->flags |= CPUFREQ_CONST_LOOPS;
2473 if (cpufreq_boost_supported()) {
2474 ret = create_boost_sysfs_file();
2476 goto err_null_driver;
2479 ret = subsys_interface_register(&cpufreq_interface);
2481 goto err_boost_unreg;
2483 if (!(cpufreq_driver->flags & CPUFREQ_STICKY) &&
2484 list_empty(&cpufreq_policy_list)) {
2485 /* if all ->init() calls failed, unregister */
2486 pr_debug("%s: No CPU initialized for driver %s\n", __func__,
2491 register_hotcpu_notifier(&cpufreq_cpu_notifier);
2492 pr_debug("driver %s up and running\n", driver_data->name);
2499 subsys_interface_unregister(&cpufreq_interface);
2501 remove_boost_sysfs_file();
2503 write_lock_irqsave(&cpufreq_driver_lock, flags);
2504 cpufreq_driver = NULL;
2505 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2508 EXPORT_SYMBOL_GPL(cpufreq_register_driver);
2511 * cpufreq_unregister_driver - unregister the current CPUFreq driver
2513 * Unregister the current CPUFreq driver. Only call this if you have
2514 * the right to do so, i.e. if you have succeeded in initialising before!
2515 * Returns zero if successful, and -EINVAL if the cpufreq_driver is
2516 * currently not initialised.
2518 int cpufreq_unregister_driver(struct cpufreq_driver *driver)
2520 unsigned long flags;
2522 if (!cpufreq_driver || (driver != cpufreq_driver))
2525 pr_debug("unregistering driver %s\n", driver->name);
2527 /* Protect against concurrent cpu hotplug */
2529 subsys_interface_unregister(&cpufreq_interface);
2530 remove_boost_sysfs_file();
2531 unregister_hotcpu_notifier(&cpufreq_cpu_notifier);
2533 write_lock_irqsave(&cpufreq_driver_lock, flags);
2535 cpufreq_driver = NULL;
2537 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2542 EXPORT_SYMBOL_GPL(cpufreq_unregister_driver);
2545 * Stop cpufreq at shutdown to make sure it isn't holding any locks
2546 * or mutexes when secondary CPUs are halted.
2548 static struct syscore_ops cpufreq_syscore_ops = {
2549 .shutdown = cpufreq_suspend,
2552 struct kobject *cpufreq_global_kobject;
2553 EXPORT_SYMBOL(cpufreq_global_kobject);
2555 static int __init cpufreq_core_init(void)
2557 if (cpufreq_disabled())
2560 cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj);
2561 BUG_ON(!cpufreq_global_kobject);
2563 register_syscore_ops(&cpufreq_syscore_ops);
2567 core_initcall(cpufreq_core_init);