Lines Matching +full:boost +full:- +full:low +full:- +full:freq
1 // SPDX-License-Identifier: GPL-2.0-only
6 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
9 * Oct 2005 - Ashok Raj <ashok.raj@intel.com>
11 * Feb 2006 - Jacob Shin <jacob.shin@amd.com>
12 * Fix handling for CPU hotplug -- affected CPUs
56 * The "cpufreq driver" - the arch- or hardware-dependent low
75 return cpufreq_driver->target_index || cpufreq_driver->target; in has_target()
110 return !!(cpufreq_driver->flags & CPUFREQ_HAVE_GOVERNOR_PER_POLICY); in have_governor_per_policy()
119 return &policy->kobj; in get_governor_parent_kobj()
143 idle_time = cur_wall_time - busy_time; in get_cpu_idle_time_jiffy()
154 if (idle_time == -1ULL) in get_cpu_idle_time()
166 * - validate & show freq table passed
167 * - set policies transition latency
168 * - policy->cpus with all possible CPUs
174 policy->freq_table = table; in cpufreq_generic_init()
175 policy->cpuinfo.transition_latency = transition_latency; in cpufreq_generic_init()
181 cpumask_setall(policy->cpus); in cpufreq_generic_init()
189 return policy && cpumask_test_cpu(cpu, policy->cpus) ? policy : NULL; in cpufreq_cpu_get_raw()
197 if (!policy || IS_ERR(policy->clk)) { in cpufreq_generic_get()
203 return clk_get_rate(policy->clk) / 1000; in cpufreq_generic_get()
208 * cpufreq_cpu_get - Return policy for a CPU and mark it as busy.
233 kobject_get(&policy->kobj); in cpufreq_cpu_get()
243 * cpufreq_cpu_put - Decrement kobject usage counter for cpufreq policy.
248 kobject_put(&policy->kobj); in cpufreq_cpu_put()
253 * cpufreq_cpu_release - Unlock a policy and decrement its usage counter.
261 lockdep_assert_held(&policy->rwsem); in cpufreq_cpu_release()
263 up_write(&policy->rwsem); in cpufreq_cpu_release()
269 * cpufreq_cpu_acquire - Find policy for a CPU, mark it as busy and lock it.
287 down_write(&policy->rwsem); in cpufreq_cpu_acquire()
302 * adjust_jiffies - adjust the system "loops_per_jiffy"
307 * per-CPU loops_per_jiffy value wherever possible.
315 if (ci->flags & CPUFREQ_CONST_LOOPS) in adjust_jiffies()
320 l_p_j_ref_freq = ci->old; in adjust_jiffies()
321 pr_debug("saving %lu as reference value for loops_per_jiffy; freq is %u kHz\n", in adjust_jiffies()
324 if (val == CPUFREQ_POSTCHANGE && ci->old != ci->new) { in adjust_jiffies()
326 ci->new); in adjust_jiffies()
328 loops_per_jiffy, ci->new); in adjust_jiffies()
334 * cpufreq_notify_transition - Notify frequency transition and adjust_jiffies.
354 freqs->policy = policy; in cpufreq_notify_transition()
355 freqs->flags = cpufreq_driver->flags; in cpufreq_notify_transition()
357 state, freqs->new); in cpufreq_notify_transition()
366 if (policy->cur && policy->cur != freqs->old) { in cpufreq_notify_transition()
368 freqs->old, policy->cur); in cpufreq_notify_transition()
369 freqs->old = policy->cur; in cpufreq_notify_transition()
380 pr_debug("FREQ: %u - CPUs: %*pbl\n", freqs->new, in cpufreq_notify_transition()
381 cpumask_pr_args(policy->cpus)); in cpufreq_notify_transition()
383 for_each_cpu(cpu, policy->cpus) in cpufreq_notify_transition()
384 trace_cpu_frequency(freqs->new, cpu); in cpufreq_notify_transition()
389 cpufreq_stats_record_transition(policy, freqs->new); in cpufreq_notify_transition()
390 policy->cur = freqs->new; in cpufreq_notify_transition()
402 swap(freqs->old, freqs->new); in cpufreq_notify_post_transition()
412 * Catch double invocations of _begin() which lead to self-deadlock. in cpufreq_freq_transition_begin()
415 * double invocations are very low. Moreover, there are scenarios in cpufreq_freq_transition_begin()
416 * where these checks can emit false-positive warnings in these in cpufreq_freq_transition_begin()
419 WARN_ON(!(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION) in cpufreq_freq_transition_begin()
420 && current == policy->transition_task); in cpufreq_freq_transition_begin()
423 wait_event(policy->transition_wait, !policy->transition_ongoing); in cpufreq_freq_transition_begin()
425 spin_lock(&policy->transition_lock); in cpufreq_freq_transition_begin()
427 if (unlikely(policy->transition_ongoing)) { in cpufreq_freq_transition_begin()
428 spin_unlock(&policy->transition_lock); in cpufreq_freq_transition_begin()
432 policy->transition_ongoing = true; in cpufreq_freq_transition_begin()
433 policy->transition_task = current; in cpufreq_freq_transition_begin()
435 spin_unlock(&policy->transition_lock); in cpufreq_freq_transition_begin()
444 if (WARN_ON(!policy->transition_ongoing)) in cpufreq_freq_transition_end()
449 arch_set_freq_scale(policy->related_cpus, in cpufreq_freq_transition_end()
450 policy->cur, in cpufreq_freq_transition_end()
451 policy->cpuinfo.max_freq); in cpufreq_freq_transition_end()
453 spin_lock(&policy->transition_lock); in cpufreq_freq_transition_end()
454 policy->transition_ongoing = false; in cpufreq_freq_transition_end()
455 policy->transition_task = NULL; in cpufreq_freq_transition_end()
456 spin_unlock(&policy->transition_lock); in cpufreq_freq_transition_end()
458 wake_up(&policy->transition_wait); in cpufreq_freq_transition_end()
477 for (nb = cpufreq_transition_notifier_list.head; nb; nb = nb->next) in cpufreq_list_transition_notifiers()
478 pr_info("%pS\n", nb->notifier_call); in cpufreq_list_transition_notifiers()
484 * cpufreq_enable_fast_switch - Enable fast frequency switching for policy.
496 lockdep_assert_held(&policy->rwsem); in cpufreq_enable_fast_switch()
498 if (!policy->fast_switch_possible) in cpufreq_enable_fast_switch()
504 policy->fast_switch_enabled = true; in cpufreq_enable_fast_switch()
507 policy->cpu); in cpufreq_enable_fast_switch()
515 * cpufreq_disable_fast_switch - Disable fast frequency switching for policy.
521 if (policy->fast_switch_enabled) { in cpufreq_disable_fast_switch()
522 policy->fast_switch_enabled = false; in cpufreq_disable_fast_switch()
524 cpufreq_fast_switch_count--; in cpufreq_disable_fast_switch()
531 * cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported
538 * Return: Lowest driver-supported frequency greater than or equal to the
544 target_freq = clamp_val(target_freq, policy->min, policy->max); in cpufreq_driver_resolve_freq()
545 policy->cached_target_freq = target_freq; in cpufreq_driver_resolve_freq()
547 if (cpufreq_driver->target_index) { in cpufreq_driver_resolve_freq()
552 policy->cached_resolved_idx = idx; in cpufreq_driver_resolve_freq()
553 return policy->freq_table[idx].frequency; in cpufreq_driver_resolve_freq()
556 if (cpufreq_driver->resolve_freq) in cpufreq_driver_resolve_freq()
557 return cpufreq_driver->resolve_freq(policy, target_freq); in cpufreq_driver_resolve_freq()
567 if (policy->transition_delay_us) in cpufreq_policy_transition_delay_us()
568 return policy->transition_delay_us; in cpufreq_policy_transition_delay_us()
570 latency = policy->cpuinfo.transition_latency / NSEC_PER_USEC; in cpufreq_policy_transition_delay_us()
595 return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled); in show_boost()
605 return -EINVAL; in store_boost()
608 pr_err("%s: Cannot %s BOOST!\n", in store_boost()
610 return -EINVAL; in store_boost()
613 pr_debug("%s: cpufreq BOOST %s\n", in store_boost()
618 define_one_global_rw(boost);
625 if (!strncasecmp(str_governor, t->name, CPUFREQ_NAME_LEN)) in find_governor()
640 if (!try_module_get(t->owner)) in get_governor()
661 * cpufreq_parse_governor - parse a governor string only for has_target()
679 * cpufreq_per_cpu_attr_read() / show_##file_name() -
682 * Write out information from cpufreq_driver->policy[cpu]; object must be
690 return sprintf(buf, "%u\n", policy->object); \
707 unsigned int freq; in show_scaling_cur_freq() local
709 freq = arch_freq_get_on_cpu(policy->cpu); in show_scaling_cur_freq()
710 if (freq) in show_scaling_cur_freq()
711 ret = sprintf(buf, "%u\n", freq); in show_scaling_cur_freq()
712 else if (cpufreq_driver->setpolicy && cpufreq_driver->get) in show_scaling_cur_freq()
713 ret = sprintf(buf, "%u\n", cpufreq_driver->get(policy->cpu)); in show_scaling_cur_freq()
715 ret = sprintf(buf, "%u\n", policy->cur); in show_scaling_cur_freq()
720 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
731 return -EINVAL; \
733 ret = freq_qos_update_request(policy->object##_freq_req, val);\
741 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
755 * show_scaling_governor - show the current policy for the specified CPU
759 if (policy->policy == CPUFREQ_POLICY_POWERSAVE) in show_scaling_governor()
761 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) in show_scaling_governor()
763 else if (policy->governor) in show_scaling_governor()
765 policy->governor->name); in show_scaling_governor()
766 return -EINVAL; in show_scaling_governor()
770 * store_scaling_governor - store policy for the specified CPU
780 return -EINVAL; in store_scaling_governor()
782 if (cpufreq_driver->setpolicy) { in store_scaling_governor()
787 return -EINVAL; in store_scaling_governor()
795 return -EINVAL; in store_scaling_governor()
800 module_put(new_gov->owner); in store_scaling_governor()
807 * show_scaling_driver - show the cpufreq driver currently loaded
811 return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name); in show_scaling_driver()
815 * show_scaling_available_governors - show the available CPUfreq governors
831 - (CPUFREQ_NAME_LEN + 2))) in show_scaling_available_governors()
833 i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name); in show_scaling_available_governors()
848 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " "); in cpufreq_show_cpus()
849 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu); in cpufreq_show_cpus()
850 if (i >= (PAGE_SIZE - 5)) in cpufreq_show_cpus()
859 * show_related_cpus - show the CPUs affected by each transition even if
864 return cpufreq_show_cpus(policy->related_cpus, buf); in show_related_cpus()
868 * show_affected_cpus - show the CPUs affected by each transition
872 return cpufreq_show_cpus(policy->cpus, buf); in show_affected_cpus()
878 unsigned int freq = 0; in store_scaling_setspeed() local
881 if (!policy->governor || !policy->governor->store_setspeed) in store_scaling_setspeed()
882 return -EINVAL; in store_scaling_setspeed()
884 ret = sscanf(buf, "%u", &freq); in store_scaling_setspeed()
886 return -EINVAL; in store_scaling_setspeed()
888 policy->governor->store_setspeed(policy, freq); in store_scaling_setspeed()
895 if (!policy->governor || !policy->governor->show_setspeed) in show_scaling_setspeed()
898 return policy->governor->show_setspeed(policy, buf); in show_scaling_setspeed()
902 * show_bios_limit - show the current cpufreq HW/BIOS limitation
908 ret = cpufreq_driver->bios_limit(policy->cpu, &limit); in show_bios_limit()
911 return sprintf(buf, "%u\n", policy->cpuinfo.max_freq); in show_bios_limit()
953 if (!fattr->show) in show()
954 return -EIO; in show()
956 down_read(&policy->rwsem); in show()
957 ret = fattr->show(policy, buf); in show()
958 up_read(&policy->rwsem); in show()
968 ssize_t ret = -EINVAL; in store()
970 if (!fattr->store) in store()
971 return -EIO; in store()
978 return -EBUSY; in store()
980 if (cpu_online(policy->cpu)) { in store()
981 down_write(&policy->rwsem); in store()
982 ret = fattr->store(policy, buf, count); in store()
983 up_write(&policy->rwsem); in store()
995 complete(&policy->kobj_unregister); in cpufreq_sysfs_release()
1015 if (cpumask_test_and_set_cpu(cpu, policy->real_cpus)) in add_cpu_dev_symlink()
1019 if (sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq")) in add_cpu_dev_symlink()
1027 sysfs_remove_link(&dev->kobj, "cpufreq"); in remove_cpu_dev_symlink()
1036 drv_attr = cpufreq_driver->attr; in cpufreq_add_dev_interface()
1038 ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr)); in cpufreq_add_dev_interface()
1043 if (cpufreq_driver->get) { in cpufreq_add_dev_interface()
1044 ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr); in cpufreq_add_dev_interface()
1049 ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr); in cpufreq_add_dev_interface()
1053 if (cpufreq_driver->bios_limit) { in cpufreq_add_dev_interface()
1054 ret = sysfs_create_file(&policy->kobj, &bios_limit.attr); in cpufreq_add_dev_interface()
1070 gov = get_governor(policy->last_governor); in cpufreq_init_policy()
1073 gov->name, policy->cpu); in cpufreq_init_policy()
1080 __module_get(gov->owner); in cpufreq_init_policy()
1086 if (policy->last_policy) { in cpufreq_init_policy()
1087 pol = policy->last_policy; in cpufreq_init_policy()
1096 pol = policy->policy; in cpufreq_init_policy()
1100 return -ENODATA; in cpufreq_init_policy()
1105 module_put(gov->owner); in cpufreq_init_policy()
1115 if (cpumask_test_cpu(cpu, policy->cpus)) in cpufreq_add_policy_cpu()
1118 down_write(&policy->rwsem); in cpufreq_add_policy_cpu()
1122 cpumask_set_cpu(cpu, policy->cpus); in cpufreq_add_policy_cpu()
1129 up_write(&policy->rwsem); in cpufreq_add_policy_cpu()
1136 pr_debug("updating policy for CPU %u\n", policy->cpu); in refresh_frequency_limits()
1138 cpufreq_set_policy(policy, policy->governor, policy->policy); in refresh_frequency_limits()
1148 pr_debug("handle_update for cpu %u called\n", policy->cpu); in handle_update()
1149 down_write(&policy->rwsem); in handle_update()
1151 up_write(&policy->rwsem); in handle_update()
1154 static int cpufreq_notifier_min(struct notifier_block *nb, unsigned long freq, in cpufreq_notifier_min() argument
1159 schedule_work(&policy->update); in cpufreq_notifier_min()
1163 static int cpufreq_notifier_max(struct notifier_block *nb, unsigned long freq, in cpufreq_notifier_max() argument
1168 schedule_work(&policy->update); in cpufreq_notifier_max()
1177 down_write(&policy->rwsem); in cpufreq_policy_put_kobj()
1179 kobj = &policy->kobj; in cpufreq_policy_put_kobj()
1180 cmp = &policy->kobj_unregister; in cpufreq_policy_put_kobj()
1181 up_write(&policy->rwsem); in cpufreq_policy_put_kobj()
1207 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1210 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1213 if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1216 init_completion(&policy->kobj_unregister); in cpufreq_policy_alloc()
1217 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, in cpufreq_policy_alloc()
1220 dev_err(dev, "%s: failed to init policy->kobj: %d\n", __func__, ret); in cpufreq_policy_alloc()
1226 kobject_put(&policy->kobj); in cpufreq_policy_alloc()
1230 freq_constraints_init(&policy->constraints); in cpufreq_policy_alloc()
1232 policy->nb_min.notifier_call = cpufreq_notifier_min; in cpufreq_policy_alloc()
1233 policy->nb_max.notifier_call = cpufreq_notifier_max; in cpufreq_policy_alloc()
1235 ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_alloc()
1236 &policy->nb_min); in cpufreq_policy_alloc()
1239 ret, cpumask_pr_args(policy->cpus)); in cpufreq_policy_alloc()
1243 ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MAX, in cpufreq_policy_alloc()
1244 &policy->nb_max); in cpufreq_policy_alloc()
1247 ret, cpumask_pr_args(policy->cpus)); in cpufreq_policy_alloc()
1251 INIT_LIST_HEAD(&policy->policy_list); in cpufreq_policy_alloc()
1252 init_rwsem(&policy->rwsem); in cpufreq_policy_alloc()
1253 spin_lock_init(&policy->transition_lock); in cpufreq_policy_alloc()
1254 init_waitqueue_head(&policy->transition_wait); in cpufreq_policy_alloc()
1255 INIT_WORK(&policy->update, handle_update); in cpufreq_policy_alloc()
1257 policy->cpu = cpu; in cpufreq_policy_alloc()
1261 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_alloc()
1262 &policy->nb_min); in cpufreq_policy_alloc()
1266 free_cpumask_var(policy->real_cpus); in cpufreq_policy_alloc()
1268 free_cpumask_var(policy->related_cpus); in cpufreq_policy_alloc()
1270 free_cpumask_var(policy->cpus); in cpufreq_policy_alloc()
1284 list_del(&policy->policy_list); in cpufreq_policy_free()
1286 for_each_cpu(cpu, policy->related_cpus) in cpufreq_policy_free()
1290 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MAX, in cpufreq_policy_free()
1291 &policy->nb_max); in cpufreq_policy_free()
1292 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_free()
1293 &policy->nb_min); in cpufreq_policy_free()
1295 /* Cancel any pending policy->update work before freeing the policy. */ in cpufreq_policy_free()
1296 cancel_work_sync(&policy->update); in cpufreq_policy_free()
1298 if (policy->max_freq_req) { in cpufreq_policy_free()
1305 freq_qos_remove_request(policy->max_freq_req); in cpufreq_policy_free()
1308 freq_qos_remove_request(policy->min_freq_req); in cpufreq_policy_free()
1309 kfree(policy->min_freq_req); in cpufreq_policy_free()
1312 free_cpumask_var(policy->real_cpus); in cpufreq_policy_free()
1313 free_cpumask_var(policy->related_cpus); in cpufreq_policy_free()
1314 free_cpumask_var(policy->cpus); in cpufreq_policy_free()
1331 WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus)); in cpufreq_online()
1337 down_write(&policy->rwsem); in cpufreq_online()
1338 policy->cpu = cpu; in cpufreq_online()
1339 policy->governor = NULL; in cpufreq_online()
1340 up_write(&policy->rwsem); in cpufreq_online()
1345 return -ENOMEM; in cpufreq_online()
1348 if (!new_policy && cpufreq_driver->online) { in cpufreq_online()
1349 ret = cpufreq_driver->online(policy); in cpufreq_online()
1356 /* Recover policy->cpus using related_cpus */ in cpufreq_online()
1357 cpumask_copy(policy->cpus, policy->related_cpus); in cpufreq_online()
1359 cpumask_copy(policy->cpus, cpumask_of(cpu)); in cpufreq_online()
1363 * to accept all calls to ->verify and ->setpolicy for this CPU. in cpufreq_online()
1365 ret = cpufreq_driver->init(policy); in cpufreq_online()
1381 /* related_cpus should at least include policy->cpus. */ in cpufreq_online()
1382 cpumask_copy(policy->related_cpus, policy->cpus); in cpufreq_online()
1385 down_write(&policy->rwsem); in cpufreq_online()
1390 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); in cpufreq_online()
1393 for_each_cpu(j, policy->related_cpus) { in cpufreq_online()
1398 policy->min_freq_req = kzalloc(2 * sizeof(*policy->min_freq_req), in cpufreq_online()
1400 if (!policy->min_freq_req) in cpufreq_online()
1403 ret = freq_qos_add_request(&policy->constraints, in cpufreq_online()
1404 policy->min_freq_req, FREQ_QOS_MIN, in cpufreq_online()
1411 kfree(policy->min_freq_req); in cpufreq_online()
1412 policy->min_freq_req = NULL; in cpufreq_online()
1421 policy->max_freq_req = policy->min_freq_req + 1; in cpufreq_online()
1423 ret = freq_qos_add_request(&policy->constraints, in cpufreq_online()
1424 policy->max_freq_req, FREQ_QOS_MAX, in cpufreq_online()
1427 policy->max_freq_req = NULL; in cpufreq_online()
1435 if (cpufreq_driver->get && has_target()) { in cpufreq_online()
1436 policy->cur = cpufreq_driver->get(policy->cpu); in cpufreq_online()
1437 if (!policy->cur) { in cpufreq_online()
1438 pr_err("%s: ->get() failed\n", __func__); in cpufreq_online()
1448 * freq-table. This also makes cpufreq stats inconsistent as in cpufreq_online()
1449 * cpufreq-stats would fail to register because current frequency of CPU in cpufreq_online()
1450 * isn't found in freq-table. in cpufreq_online()
1453 * for the next freq which is >= policy->cur ('cur' must be set by now, in cpufreq_online()
1454 * otherwise we will end up setting freq to lowest of the table as 'cur' in cpufreq_online()
1457 * We are passing target-freq as "policy->cur - 1" otherwise in cpufreq_online()
1458 * __cpufreq_driver_target() would simply fail, as policy->cur will be in cpufreq_online()
1459 * equal to target-freq. in cpufreq_online()
1461 if ((cpufreq_driver->flags & CPUFREQ_NEED_INITIAL_FREQ_CHECK) in cpufreq_online()
1463 unsigned int old_freq = policy->cur; in cpufreq_online()
1467 if (ret == -EINVAL) { in cpufreq_online()
1468 ret = __cpufreq_driver_target(policy, old_freq - 1, in cpufreq_online()
1478 __func__, policy->cpu, old_freq, policy->cur); in cpufreq_online()
1490 list_add(&policy->policy_list, &cpufreq_policy_list); in cpufreq_online()
1501 up_write(&policy->rwsem); in cpufreq_online()
1503 kobject_uevent(&policy->kobj, KOBJ_ADD); in cpufreq_online()
1506 if (cpufreq_driver->ready) in cpufreq_online()
1507 cpufreq_driver->ready(policy); in cpufreq_online()
1510 policy->cdev = of_cpufreq_cooling_register(policy); in cpufreq_online()
1517 for_each_cpu(j, policy->real_cpus) in cpufreq_online()
1520 up_write(&policy->rwsem); in cpufreq_online()
1523 if (cpufreq_driver->offline) in cpufreq_online()
1524 cpufreq_driver->offline(policy); in cpufreq_online()
1527 if (cpufreq_driver->exit) in cpufreq_online()
1528 cpufreq_driver->exit(policy); in cpufreq_online()
1536 * cpufreq_add_dev - the cpufreq interface for a CPU device.
1543 unsigned cpu = dev->id; in cpufreq_add_dev()
1569 cpumask_clear_cpu(cpu, policy->cpus); in __cpufreq_offline()
1573 if (cpu == policy->cpu) in __cpufreq_offline()
1574 policy->cpu = cpumask_any(policy->cpus); in __cpufreq_offline()
1587 strncpy(policy->last_governor, policy->governor->name, in __cpufreq_offline()
1590 policy->last_policy = policy->policy; in __cpufreq_offline()
1593 cpufreq_cooling_unregister(policy->cdev); in __cpufreq_offline()
1594 policy->cdev = NULL; in __cpufreq_offline()
1597 if (cpufreq_driver->stop_cpu) in __cpufreq_offline()
1598 cpufreq_driver->stop_cpu(policy); in __cpufreq_offline()
1604 * Perform the ->offline() during light-weight tear-down, as in __cpufreq_offline()
1607 if (cpufreq_driver->offline) { in __cpufreq_offline()
1608 cpufreq_driver->offline(policy); in __cpufreq_offline()
1612 if (cpufreq_driver->exit) in __cpufreq_offline()
1613 cpufreq_driver->exit(policy); in __cpufreq_offline()
1615 policy->freq_table = NULL; in __cpufreq_offline()
1630 down_write(&policy->rwsem); in cpufreq_offline()
1634 up_write(&policy->rwsem); in cpufreq_offline()
1639 * cpufreq_remove_dev - remove a CPU device
1645 unsigned int cpu = dev->id; in cpufreq_remove_dev()
1651 down_write(&policy->rwsem); in cpufreq_remove_dev()
1656 cpumask_clear_cpu(cpu, policy->real_cpus); in cpufreq_remove_dev()
1659 if (!cpumask_empty(policy->real_cpus)) { in cpufreq_remove_dev()
1660 up_write(&policy->rwsem); in cpufreq_remove_dev()
1664 /* We did light-weight exit earlier, do full tear down now */ in cpufreq_remove_dev()
1665 if (cpufreq_driver->offline && cpufreq_driver->exit) in cpufreq_remove_dev()
1666 cpufreq_driver->exit(policy); in cpufreq_remove_dev()
1668 up_write(&policy->rwsem); in cpufreq_remove_dev()
1674 * cpufreq_out_of_sync - If actual and saved CPU frequency differs, we're
1688 policy->cur, new_freq); in cpufreq_out_of_sync()
1690 freqs.old = policy->cur; in cpufreq_out_of_sync()
1701 new_freq = cpufreq_driver->get(policy->cpu); in cpufreq_verify_current_freq()
1707 * against policy->cur is pointless, so skip it in that case. in cpufreq_verify_current_freq()
1709 if (policy->fast_switch_enabled || !has_target()) in cpufreq_verify_current_freq()
1712 if (policy->cur != new_freq) { in cpufreq_verify_current_freq()
1715 schedule_work(&policy->update); in cpufreq_verify_current_freq()
1722 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
1725 * This is the last known freq, without actually getting it from the driver.
1736 if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) { in cpufreq_quick_get()
1737 ret_freq = cpufreq_driver->get(cpu); in cpufreq_quick_get()
1746 ret_freq = policy->cur; in cpufreq_quick_get()
1755 * cpufreq_quick_get_max - get the max reported CPU frequency for this CPU
1766 ret_freq = policy->max; in cpufreq_quick_get_max()
1775 * cpufreq_get_hw_max_freq - get the max hardware frequency of the CPU
1786 ret_freq = policy->cpuinfo.max_freq; in cpufreq_get_hw_max_freq()
1803 * cpufreq_get - get the current CPU frequency (in kHz)
1814 down_read(&policy->rwsem); in cpufreq_get()
1815 if (cpufreq_driver->get) in cpufreq_get()
1817 up_read(&policy->rwsem); in cpufreq_get()
1841 if (!policy->suspend_freq) { in cpufreq_generic_suspend()
1846 pr_debug("%s: Setting suspend-freq: %u\n", __func__, in cpufreq_generic_suspend()
1847 policy->suspend_freq); in cpufreq_generic_suspend()
1849 ret = __cpufreq_driver_target(policy, policy->suspend_freq, in cpufreq_generic_suspend()
1852 pr_err("%s: unable to set suspend-freq: %u. err: %d\n", in cpufreq_generic_suspend()
1853 __func__, policy->suspend_freq, ret); in cpufreq_generic_suspend()
1860 * cpufreq_suspend() - Suspend CPUFreq governors
1874 if (!has_target() && !cpufreq_driver->suspend) in cpufreq_suspend()
1881 down_write(&policy->rwsem); in cpufreq_suspend()
1883 up_write(&policy->rwsem); in cpufreq_suspend()
1886 if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy)) in cpufreq_suspend()
1888 cpufreq_driver->name); in cpufreq_suspend()
1896 * cpufreq_resume() - Resume CPUFreq governors
1914 if (!has_target() && !cpufreq_driver->resume) in cpufreq_resume()
1920 if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) { in cpufreq_resume()
1924 down_write(&policy->rwsem); in cpufreq_resume()
1926 up_write(&policy->rwsem); in cpufreq_resume()
1936 * cpufreq_driver_test_flags - Test cpufreq driver's flags against given ones.
1944 return !!(cpufreq_driver->flags & flags); in cpufreq_driver_test_flags()
1948 * cpufreq_get_current_driver - return current driver's name
1956 return cpufreq_driver->name; in cpufreq_get_current_driver()
1963 * cpufreq_get_driver_data - return current driver data
1971 return cpufreq_driver->driver_data; in cpufreq_get_driver_data()
1982 * cpufreq_register_notifier - register a driver with cpufreq
1999 return -EINVAL; in cpufreq_register_notifier()
2007 return -EBUSY; in cpufreq_register_notifier()
2012 cpufreq_fast_switch_count--; in cpufreq_register_notifier()
2021 ret = -EINVAL; in cpufreq_register_notifier()
2029 * cpufreq_unregister_notifier - unregister a driver with cpufreq
2043 return -EINVAL; in cpufreq_unregister_notifier()
2061 ret = -EINVAL; in cpufreq_unregister_notifier()
2074 * cpufreq_driver_fast_switch - Carry out a fast CPU frequency switch.
2080 * The driver's ->fast_switch() callback invoked by this function must be
2081 * suitable for being called from within RCU-sched read-side critical sections
2085 * This function must not be called if policy->fast_switch_enabled is unset.
2089 * parallel with either ->target() or ->target_index() for the same policy.
2093 * If 0 is returned by the driver's ->fast_switch() callback to indicate an
2099 unsigned int freq; in cpufreq_driver_fast_switch() local
2102 target_freq = clamp_val(target_freq, policy->min, policy->max); in cpufreq_driver_fast_switch()
2103 freq = cpufreq_driver->fast_switch(policy, target_freq); in cpufreq_driver_fast_switch()
2105 if (!freq) in cpufreq_driver_fast_switch()
2108 policy->cur = freq; in cpufreq_driver_fast_switch()
2109 arch_set_freq_scale(policy->related_cpus, freq, in cpufreq_driver_fast_switch()
2110 policy->cpuinfo.max_freq); in cpufreq_driver_fast_switch()
2111 cpufreq_stats_record_transition(policy, freq); in cpufreq_driver_fast_switch()
2114 for_each_cpu(cpu, policy->cpus) in cpufreq_driver_fast_switch()
2115 trace_cpu_frequency(freq, cpu); in cpufreq_driver_fast_switch()
2118 return freq; in cpufreq_driver_fast_switch()
2122 /* Must set freqs->new to intermediate frequency */
2128 freqs->new = cpufreq_driver->get_intermediate(policy, index); in __target_intermediate()
2130 /* We don't need to switch to intermediate freq */ in __target_intermediate()
2131 if (!freqs->new) in __target_intermediate()
2134 pr_debug("%s: cpu: %d, switching to intermediate freq: oldfreq: %u, intermediate freq: %u\n", in __target_intermediate()
2135 __func__, policy->cpu, freqs->old, freqs->new); in __target_intermediate()
2138 ret = cpufreq_driver->target_intermediate(policy, index); in __target_intermediate()
2150 struct cpufreq_freqs freqs = {.old = policy->cur, .flags = 0}; in __target_index()
2152 unsigned int newfreq = policy->freq_table[index].frequency; in __target_index()
2153 int retval = -EINVAL; in __target_index()
2156 if (newfreq == policy->cur) in __target_index()
2159 notify = !(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION); in __target_index()
2162 if (cpufreq_driver->get_intermediate) { in __target_index()
2168 /* Set old freq to intermediate */ in __target_index()
2174 pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n", in __target_index()
2175 __func__, policy->cpu, freqs.old, freqs.new); in __target_index()
2180 retval = cpufreq_driver->target_index(policy, index); in __target_index()
2189 * Failed after setting to intermediate freq? Driver should have in __target_index()
2192 * case we haven't switched to intermediate freq at all. in __target_index()
2196 freqs.new = policy->restore_freq; in __target_index()
2213 return -ENODEV; in __cpufreq_driver_target()
2216 target_freq = clamp_val(target_freq, policy->min, policy->max); in __cpufreq_driver_target()
2219 policy->cpu, target_freq, relation, old_target_freq); in __cpufreq_driver_target()
2224 * exactly same freq is called again and so we can save on few function in __cpufreq_driver_target()
2227 if (target_freq == policy->cur && in __cpufreq_driver_target()
2228 !(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS)) in __cpufreq_driver_target()
2232 policy->restore_freq = policy->cur; in __cpufreq_driver_target()
2234 if (cpufreq_driver->target) in __cpufreq_driver_target()
2235 return cpufreq_driver->target(policy, target_freq, relation); in __cpufreq_driver_target()
2237 if (!cpufreq_driver->target_index) in __cpufreq_driver_target()
2238 return -EINVAL; in __cpufreq_driver_target()
2252 down_write(&policy->rwsem); in cpufreq_driver_target()
2256 up_write(&policy->rwsem); in cpufreq_driver_target()
2278 if (!policy->governor) in cpufreq_init_governor()
2279 return -EINVAL; in cpufreq_init_governor()
2282 if (policy->governor->flags & CPUFREQ_GOV_DYNAMIC_SWITCHING && in cpufreq_init_governor()
2283 cpufreq_driver->flags & CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING) { in cpufreq_init_governor()
2288 policy->governor->name, gov->name); in cpufreq_init_governor()
2289 policy->governor = gov; in cpufreq_init_governor()
2291 return -EINVAL; in cpufreq_init_governor()
2295 if (!try_module_get(policy->governor->owner)) in cpufreq_init_governor()
2296 return -EINVAL; in cpufreq_init_governor()
2298 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_init_governor()
2300 if (policy->governor->init) { in cpufreq_init_governor()
2301 ret = policy->governor->init(policy); in cpufreq_init_governor()
2303 module_put(policy->governor->owner); in cpufreq_init_governor()
2308 policy->strict_target = !!(policy->governor->flags & CPUFREQ_GOV_STRICT_TARGET); in cpufreq_init_governor()
2315 if (cpufreq_suspended || !policy->governor) in cpufreq_exit_governor()
2318 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_exit_governor()
2320 if (policy->governor->exit) in cpufreq_exit_governor()
2321 policy->governor->exit(policy); in cpufreq_exit_governor()
2323 module_put(policy->governor->owner); in cpufreq_exit_governor()
2333 if (!policy->governor) in cpufreq_start_governor()
2334 return -EINVAL; in cpufreq_start_governor()
2336 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_start_governor()
2338 if (cpufreq_driver->get) in cpufreq_start_governor()
2341 if (policy->governor->start) { in cpufreq_start_governor()
2342 ret = policy->governor->start(policy); in cpufreq_start_governor()
2347 if (policy->governor->limits) in cpufreq_start_governor()
2348 policy->governor->limits(policy); in cpufreq_start_governor()
2355 if (cpufreq_suspended || !policy->governor) in cpufreq_stop_governor()
2358 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_stop_governor()
2360 if (policy->governor->stop) in cpufreq_stop_governor()
2361 policy->governor->stop(policy); in cpufreq_stop_governor()
2366 if (cpufreq_suspended || !policy->governor) in cpufreq_governor_limits()
2369 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_governor_limits()
2371 if (policy->governor->limits) in cpufreq_governor_limits()
2372 policy->governor->limits(policy); in cpufreq_governor_limits()
2380 return -EINVAL; in cpufreq_register_governor()
2383 return -ENODEV; in cpufreq_register_governor()
2387 err = -EBUSY; in cpufreq_register_governor()
2388 if (!find_governor(governor->name)) { in cpufreq_register_governor()
2390 list_add(&governor->governor_list, &cpufreq_governor_list); in cpufreq_register_governor()
2412 if (!strcmp(policy->last_governor, governor->name)) { in cpufreq_unregister_governor()
2413 policy->governor = NULL; in cpufreq_unregister_governor()
2414 strcpy(policy->last_governor, "\0"); in cpufreq_unregister_governor()
2420 list_del(&governor->governor_list); in cpufreq_unregister_governor()
2431 * cpufreq_get_policy - get the current cpufreq_policy
2442 return -EINVAL; in cpufreq_get_policy()
2446 return -EINVAL; in cpufreq_get_policy()
2456 * cpufreq_set_policy - Modify cpufreq policy parameters.
2459 * @new_pol: Policy value (for drivers with built-in governors).
2461 * Invoke the cpufreq driver's ->verify() callback to sanity-check the frequency
2463 * values and either invoke the driver's ->setpolicy() callback (if present) or
2465 * ->limits() callback (if @new_gov points to the same object as the one in
2478 memcpy(&new_data.cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo)); in cpufreq_set_policy()
2479 new_data.freq_table = policy->freq_table; in cpufreq_set_policy()
2480 new_data.cpu = policy->cpu; in cpufreq_set_policy()
2485 new_data.min = freq_qos_read_value(&policy->constraints, FREQ_QOS_MIN); in cpufreq_set_policy()
2486 new_data.max = freq_qos_read_value(&policy->constraints, FREQ_QOS_MAX); in cpufreq_set_policy()
2488 pr_debug("setting new policy for CPU %u: %u - %u kHz\n", in cpufreq_set_policy()
2495 ret = cpufreq_driver->verify(&new_data); in cpufreq_set_policy()
2499 policy->min = new_data.min; in cpufreq_set_policy()
2500 policy->max = new_data.max; in cpufreq_set_policy()
2503 policy->cached_target_freq = UINT_MAX; in cpufreq_set_policy()
2505 pr_debug("new min and max freqs are %u - %u kHz\n", in cpufreq_set_policy()
2506 policy->min, policy->max); in cpufreq_set_policy()
2508 if (cpufreq_driver->setpolicy) { in cpufreq_set_policy()
2509 policy->policy = new_pol; in cpufreq_set_policy()
2511 return cpufreq_driver->setpolicy(policy); in cpufreq_set_policy()
2514 if (new_gov == policy->governor) { in cpufreq_set_policy()
2523 old_gov = policy->governor; in cpufreq_set_policy()
2531 policy->governor = new_gov; in cpufreq_set_policy()
2543 /* new governor failed, so re-start old one */ in cpufreq_set_policy()
2544 pr_debug("starting governor %s failed\n", policy->governor->name); in cpufreq_set_policy()
2546 policy->governor = old_gov; in cpufreq_set_policy()
2548 policy->governor = NULL; in cpufreq_set_policy()
2557 * cpufreq_update_policy - Re-evaluate an existing cpufreq policy.
2558 * @cpu: CPU to re-evaluate the policy for.
2561 * cpufreq_set_policy() to re-apply the min and max limits, which triggers the
2562 * evaluation of policy notifiers and the cpufreq driver's ->verify() callback
2573 * BIOS might change freq behind our back in cpufreq_update_policy()
2574 * -> ask driver for current freq and notify governors about a change in cpufreq_update_policy()
2576 if (cpufreq_driver->get && has_target() && in cpufreq_update_policy()
2588 * cpufreq_update_limits - Update policy limits for a given CPU.
2591 * Invoke the driver's ->update_limits callback if present or call
2596 if (cpufreq_driver->update_limits) in cpufreq_update_limits()
2597 cpufreq_driver->update_limits(cpu); in cpufreq_update_limits()
2604 * BOOST *
2610 if (!policy->freq_table) in cpufreq_boost_set_sw()
2611 return -ENXIO; in cpufreq_boost_set_sw()
2613 ret = cpufreq_frequency_table_cpuinfo(policy, policy->freq_table); in cpufreq_boost_set_sw()
2619 ret = freq_qos_update_request(policy->max_freq_req, policy->max); in cpufreq_boost_set_sw()
2632 if (cpufreq_driver->boost_enabled == state) in cpufreq_boost_trigger_state()
2636 cpufreq_driver->boost_enabled = state; in cpufreq_boost_trigger_state()
2641 ret = cpufreq_driver->set_boost(policy, state); in cpufreq_boost_trigger_state()
2653 cpufreq_driver->boost_enabled = !state; in cpufreq_boost_trigger_state()
2656 pr_err("%s: Cannot %s BOOST\n", in cpufreq_boost_trigger_state()
2664 return cpufreq_driver->set_boost; in cpufreq_boost_supported()
2671 ret = sysfs_create_file(cpufreq_global_kobject, &boost.attr); in create_boost_sysfs_file()
2673 pr_err("%s: cannot register global BOOST sysfs file\n", in create_boost_sysfs_file()
2682 sysfs_remove_file(cpufreq_global_kobject, &boost.attr); in remove_boost_sysfs_file()
2688 return -EINVAL; in cpufreq_enable_boost_support()
2693 cpufreq_driver->set_boost = cpufreq_boost_set_sw; in cpufreq_enable_boost_support()
2702 return cpufreq_driver->boost_enabled; in cpufreq_boost_enabled()
2726 * cpufreq_register_driver - register a CPU Frequency driver
2731 * returns zero on success, -EEXIST when another driver got here first
2741 return -ENODEV; in cpufreq_register_driver()
2748 return -EPROBE_DEFER; in cpufreq_register_driver()
2750 if (!driver_data || !driver_data->verify || !driver_data->init || in cpufreq_register_driver()
2751 !(driver_data->setpolicy || driver_data->target_index || in cpufreq_register_driver()
2752 driver_data->target) || in cpufreq_register_driver()
2753 (driver_data->setpolicy && (driver_data->target_index || in cpufreq_register_driver()
2754 driver_data->target)) || in cpufreq_register_driver()
2755 (!driver_data->get_intermediate != !driver_data->target_intermediate) || in cpufreq_register_driver()
2756 (!driver_data->online != !driver_data->offline)) in cpufreq_register_driver()
2757 return -EINVAL; in cpufreq_register_driver()
2759 pr_debug("trying to register driver %s\n", driver_data->name); in cpufreq_register_driver()
2767 ret = -EEXIST; in cpufreq_register_driver()
2777 if (!cpufreq_driver->setpolicy) { in cpufreq_register_driver()
2782 if (driver_data->setpolicy) in cpufreq_register_driver()
2783 driver_data->flags |= CPUFREQ_CONST_LOOPS; in cpufreq_register_driver()
2795 if (!(cpufreq_driver->flags & CPUFREQ_STICKY) && in cpufreq_register_driver()
2797 /* if all ->init() calls failed, unregister */ in cpufreq_register_driver()
2798 ret = -ENODEV; in cpufreq_register_driver()
2800 driver_data->name); in cpufreq_register_driver()
2813 pr_debug("driver %s up and running\n", driver_data->name); in cpufreq_register_driver()
2831 * cpufreq_unregister_driver - unregister the current CPUFreq driver
2835 * Returns zero if successful, and -EINVAL if the cpufreq_driver is
2843 return -EINVAL; in cpufreq_unregister_driver()
2845 pr_debug("unregistering driver %s\n", driver->name); in cpufreq_unregister_driver()
2870 return -ENODEV; in cpufreq_core_init()
2872 cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj); in cpufreq_core_init()
2876 strncpy(default_governor, gov->name, CPUFREQ_NAME_LEN); in cpufreq_core_init()