aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq/cpufreq.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/cpufreq/cpufreq.c')
-rw-r--r--drivers/cpufreq/cpufreq.c104
1 files changed, 59 insertions, 45 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 02d534da22dd..8d19f7c06010 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -828,14 +828,17 @@ static void cpufreq_init_policy(struct cpufreq_policy *policy)
828 int ret = 0; 828 int ret = 0;
829 829
830 memcpy(&new_policy, policy, sizeof(*policy)); 830 memcpy(&new_policy, policy, sizeof(*policy));
831
832 /* Use the default policy if its valid. */
833 if (cpufreq_driver->setpolicy)
834 cpufreq_parse_governor(policy->governor->name,
835 &new_policy.policy, NULL);
836
831 /* assure that the starting sequence is run in cpufreq_set_policy */ 837 /* assure that the starting sequence is run in cpufreq_set_policy */
832 policy->governor = NULL; 838 policy->governor = NULL;
833 839
834 /* set default policy */ 840 /* set default policy */
835 ret = cpufreq_set_policy(policy, &new_policy); 841 ret = cpufreq_set_policy(policy, &new_policy);
836 policy->user_policy.policy = policy->policy;
837 policy->user_policy.governor = policy->governor;
838
839 if (ret) { 842 if (ret) {
840 pr_debug("setting policy failed\n"); 843 pr_debug("setting policy failed\n");
841 if (cpufreq_driver->exit) 844 if (cpufreq_driver->exit)
@@ -845,8 +848,7 @@ static void cpufreq_init_policy(struct cpufreq_policy *policy)
845 848
846#ifdef CONFIG_HOTPLUG_CPU 849#ifdef CONFIG_HOTPLUG_CPU
847static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, 850static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy,
848 unsigned int cpu, struct device *dev, 851 unsigned int cpu, struct device *dev)
849 bool frozen)
850{ 852{
851 int ret = 0; 853 int ret = 0;
852 unsigned long flags; 854 unsigned long flags;
@@ -877,11 +879,7 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy,
877 } 879 }
878 } 880 }
879 881
880 /* Don't touch sysfs links during light-weight init */ 882 return sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq");
881 if (!frozen)
882 ret = sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq");
883
884 return ret;
885} 883}
886#endif 884#endif
887 885
@@ -926,6 +924,27 @@ err_free_policy:
926 return NULL; 924 return NULL;
927} 925}
928 926
927static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy)
928{
929 struct kobject *kobj;
930 struct completion *cmp;
931
932 down_read(&policy->rwsem);
933 kobj = &policy->kobj;
934 cmp = &policy->kobj_unregister;
935 up_read(&policy->rwsem);
936 kobject_put(kobj);
937
938 /*
939 * We need to make sure that the underlying kobj is
940 * actually not referenced anymore by anybody before we
941 * proceed with unloading.
942 */
943 pr_debug("waiting for dropping of refcount\n");
944 wait_for_completion(cmp);
945 pr_debug("wait complete\n");
946}
947
929static void cpufreq_policy_free(struct cpufreq_policy *policy) 948static void cpufreq_policy_free(struct cpufreq_policy *policy)
930{ 949{
931 free_cpumask_var(policy->related_cpus); 950 free_cpumask_var(policy->related_cpus);
@@ -986,7 +1005,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
986 list_for_each_entry(tpolicy, &cpufreq_policy_list, policy_list) { 1005 list_for_each_entry(tpolicy, &cpufreq_policy_list, policy_list) {
987 if (cpumask_test_cpu(cpu, tpolicy->related_cpus)) { 1006 if (cpumask_test_cpu(cpu, tpolicy->related_cpus)) {
988 read_unlock_irqrestore(&cpufreq_driver_lock, flags); 1007 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
989 ret = cpufreq_add_policy_cpu(tpolicy, cpu, dev, frozen); 1008 ret = cpufreq_add_policy_cpu(tpolicy, cpu, dev);
990 up_read(&cpufreq_rwsem); 1009 up_read(&cpufreq_rwsem);
991 return ret; 1010 return ret;
992 } 1011 }
@@ -994,15 +1013,17 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
994 read_unlock_irqrestore(&cpufreq_driver_lock, flags); 1013 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
995#endif 1014#endif
996 1015
997 if (frozen) 1016 /*
998 /* Restore the saved policy when doing light-weight init */ 1017 * Restore the saved policy when doing light-weight init and fall back
999 policy = cpufreq_policy_restore(cpu); 1018 * to the full init if that fails.
1000 else 1019 */
1020 policy = frozen ? cpufreq_policy_restore(cpu) : NULL;
1021 if (!policy) {
1022 frozen = false;
1001 policy = cpufreq_policy_alloc(); 1023 policy = cpufreq_policy_alloc();
1002 1024 if (!policy)
1003 if (!policy) 1025 goto nomem_out;
1004 goto nomem_out; 1026 }
1005
1006 1027
1007 /* 1028 /*
1008 * In the resume path, since we restore a saved policy, the assignment 1029 * In the resume path, since we restore a saved policy, the assignment
@@ -1047,8 +1068,10 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1047 */ 1068 */
1048 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); 1069 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
1049 1070
1050 policy->user_policy.min = policy->min; 1071 if (!frozen) {
1051 policy->user_policy.max = policy->max; 1072 policy->user_policy.min = policy->min;
1073 policy->user_policy.max = policy->max;
1074 }
1052 1075
1053 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1076 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1054 CPUFREQ_START, policy); 1077 CPUFREQ_START, policy);
@@ -1079,6 +1102,11 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1079 1102
1080 cpufreq_init_policy(policy); 1103 cpufreq_init_policy(policy);
1081 1104
1105 if (!frozen) {
1106 policy->user_policy.policy = policy->policy;
1107 policy->user_policy.governor = policy->governor;
1108 }
1109
1082 kobject_uevent(&policy->kobj, KOBJ_ADD); 1110 kobject_uevent(&policy->kobj, KOBJ_ADD);
1083 up_read(&cpufreq_rwsem); 1111 up_read(&cpufreq_rwsem);
1084 1112
@@ -1096,7 +1124,13 @@ err_get_freq:
1096 if (cpufreq_driver->exit) 1124 if (cpufreq_driver->exit)
1097 cpufreq_driver->exit(policy); 1125 cpufreq_driver->exit(policy);
1098err_set_policy_cpu: 1126err_set_policy_cpu:
1127 if (frozen) {
1128 /* Do not leave stale fallback data behind. */
1129 per_cpu(cpufreq_cpu_data_fallback, cpu) = NULL;
1130 cpufreq_policy_put_kobj(policy);
1131 }
1099 cpufreq_policy_free(policy); 1132 cpufreq_policy_free(policy);
1133
1100nomem_out: 1134nomem_out:
1101 up_read(&cpufreq_rwsem); 1135 up_read(&cpufreq_rwsem);
1102 1136
@@ -1118,7 +1152,7 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
1118} 1152}
1119 1153
1120static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy, 1154static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy,
1121 unsigned int old_cpu, bool frozen) 1155 unsigned int old_cpu)
1122{ 1156{
1123 struct device *cpu_dev; 1157 struct device *cpu_dev;
1124 int ret; 1158 int ret;
@@ -1126,10 +1160,6 @@ static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy,
1126 /* first sibling now owns the new sysfs dir */ 1160 /* first sibling now owns the new sysfs dir */
1127 cpu_dev = get_cpu_device(cpumask_any_but(policy->cpus, old_cpu)); 1161 cpu_dev = get_cpu_device(cpumask_any_but(policy->cpus, old_cpu));
1128 1162
1129 /* Don't touch sysfs files during light-weight tear-down */
1130 if (frozen)
1131 return cpu_dev->id;
1132
1133 sysfs_remove_link(&cpu_dev->kobj, "cpufreq"); 1163 sysfs_remove_link(&cpu_dev->kobj, "cpufreq");
1134 ret = kobject_move(&policy->kobj, &cpu_dev->kobj); 1164 ret = kobject_move(&policy->kobj, &cpu_dev->kobj);
1135 if (ret) { 1165 if (ret) {
@@ -1196,7 +1226,7 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
1196 if (!frozen) 1226 if (!frozen)
1197 sysfs_remove_link(&dev->kobj, "cpufreq"); 1227 sysfs_remove_link(&dev->kobj, "cpufreq");
1198 } else if (cpus > 1) { 1228 } else if (cpus > 1) {
1199 new_cpu = cpufreq_nominate_new_policy_cpu(policy, cpu, frozen); 1229 new_cpu = cpufreq_nominate_new_policy_cpu(policy, cpu);
1200 if (new_cpu >= 0) { 1230 if (new_cpu >= 0) {
1201 update_policy_cpu(policy, new_cpu); 1231 update_policy_cpu(policy, new_cpu);
1202 1232
@@ -1218,8 +1248,6 @@ static int __cpufreq_remove_dev_finish(struct device *dev,
1218 int ret; 1248 int ret;
1219 unsigned long flags; 1249 unsigned long flags;
1220 struct cpufreq_policy *policy; 1250 struct cpufreq_policy *policy;
1221 struct kobject *kobj;
1222 struct completion *cmp;
1223 1251
1224 read_lock_irqsave(&cpufreq_driver_lock, flags); 1252 read_lock_irqsave(&cpufreq_driver_lock, flags);
1225 policy = per_cpu(cpufreq_cpu_data, cpu); 1253 policy = per_cpu(cpufreq_cpu_data, cpu);
@@ -1249,22 +1277,8 @@ static int __cpufreq_remove_dev_finish(struct device *dev,
1249 } 1277 }
1250 } 1278 }
1251 1279
1252 if (!frozen) { 1280 if (!frozen)
1253 down_read(&policy->rwsem); 1281 cpufreq_policy_put_kobj(policy);
1254 kobj = &policy->kobj;
1255 cmp = &policy->kobj_unregister;
1256 up_read(&policy->rwsem);
1257 kobject_put(kobj);
1258
1259 /*
1260 * We need to make sure that the underlying kobj is
1261 * actually not referenced anymore by anybody before we
1262 * proceed with unloading.
1263 */
1264 pr_debug("waiting for dropping of refcount\n");
1265 wait_for_completion(cmp);
1266 pr_debug("wait complete\n");
1267 }
1268 1282
1269 /* 1283 /*
1270 * Perform the ->exit() even during light-weight tear-down, 1284 * Perform the ->exit() even during light-weight tear-down,