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.c69
1 files changed, 37 insertions, 32 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 02d534da22dd..16d7b4ac94be 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -828,6 +828,12 @@ 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
@@ -845,8 +851,7 @@ static void cpufreq_init_policy(struct cpufreq_policy *policy)
845 851
846#ifdef CONFIG_HOTPLUG_CPU 852#ifdef CONFIG_HOTPLUG_CPU
847static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, 853static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy,
848 unsigned int cpu, struct device *dev, 854 unsigned int cpu, struct device *dev)
849 bool frozen)
850{ 855{
851 int ret = 0; 856 int ret = 0;
852 unsigned long flags; 857 unsigned long flags;
@@ -877,11 +882,7 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy,
877 } 882 }
878 } 883 }
879 884
880 /* Don't touch sysfs links during light-weight init */ 885 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} 886}
886#endif 887#endif
887 888
@@ -926,6 +927,27 @@ err_free_policy:
926 return NULL; 927 return NULL;
927} 928}
928 929
930static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy)
931{
932 struct kobject *kobj;
933 struct completion *cmp;
934
935 down_read(&policy->rwsem);
936 kobj = &policy->kobj;
937 cmp = &policy->kobj_unregister;
938 up_read(&policy->rwsem);
939 kobject_put(kobj);
940
941 /*
942 * We need to make sure that the underlying kobj is
943 * actually not referenced anymore by anybody before we
944 * proceed with unloading.
945 */
946 pr_debug("waiting for dropping of refcount\n");
947 wait_for_completion(cmp);
948 pr_debug("wait complete\n");
949}
950
929static void cpufreq_policy_free(struct cpufreq_policy *policy) 951static void cpufreq_policy_free(struct cpufreq_policy *policy)
930{ 952{
931 free_cpumask_var(policy->related_cpus); 953 free_cpumask_var(policy->related_cpus);
@@ -986,7 +1008,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
986 list_for_each_entry(tpolicy, &cpufreq_policy_list, policy_list) { 1008 list_for_each_entry(tpolicy, &cpufreq_policy_list, policy_list) {
987 if (cpumask_test_cpu(cpu, tpolicy->related_cpus)) { 1009 if (cpumask_test_cpu(cpu, tpolicy->related_cpus)) {
988 read_unlock_irqrestore(&cpufreq_driver_lock, flags); 1010 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
989 ret = cpufreq_add_policy_cpu(tpolicy, cpu, dev, frozen); 1011 ret = cpufreq_add_policy_cpu(tpolicy, cpu, dev);
990 up_read(&cpufreq_rwsem); 1012 up_read(&cpufreq_rwsem);
991 return ret; 1013 return ret;
992 } 1014 }
@@ -1096,7 +1118,10 @@ err_get_freq:
1096 if (cpufreq_driver->exit) 1118 if (cpufreq_driver->exit)
1097 cpufreq_driver->exit(policy); 1119 cpufreq_driver->exit(policy);
1098err_set_policy_cpu: 1120err_set_policy_cpu:
1121 if (frozen)
1122 cpufreq_policy_put_kobj(policy);
1099 cpufreq_policy_free(policy); 1123 cpufreq_policy_free(policy);
1124
1100nomem_out: 1125nomem_out:
1101 up_read(&cpufreq_rwsem); 1126 up_read(&cpufreq_rwsem);
1102 1127
@@ -1118,7 +1143,7 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
1118} 1143}
1119 1144
1120static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy, 1145static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy,
1121 unsigned int old_cpu, bool frozen) 1146 unsigned int old_cpu)
1122{ 1147{
1123 struct device *cpu_dev; 1148 struct device *cpu_dev;
1124 int ret; 1149 int ret;
@@ -1126,10 +1151,6 @@ static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy,
1126 /* first sibling now owns the new sysfs dir */ 1151 /* first sibling now owns the new sysfs dir */
1127 cpu_dev = get_cpu_device(cpumask_any_but(policy->cpus, old_cpu)); 1152 cpu_dev = get_cpu_device(cpumask_any_but(policy->cpus, old_cpu));
1128 1153
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"); 1154 sysfs_remove_link(&cpu_dev->kobj, "cpufreq");
1134 ret = kobject_move(&policy->kobj, &cpu_dev->kobj); 1155 ret = kobject_move(&policy->kobj, &cpu_dev->kobj);
1135 if (ret) { 1156 if (ret) {
@@ -1196,7 +1217,7 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
1196 if (!frozen) 1217 if (!frozen)
1197 sysfs_remove_link(&dev->kobj, "cpufreq"); 1218 sysfs_remove_link(&dev->kobj, "cpufreq");
1198 } else if (cpus > 1) { 1219 } else if (cpus > 1) {
1199 new_cpu = cpufreq_nominate_new_policy_cpu(policy, cpu, frozen); 1220 new_cpu = cpufreq_nominate_new_policy_cpu(policy, cpu);
1200 if (new_cpu >= 0) { 1221 if (new_cpu >= 0) {
1201 update_policy_cpu(policy, new_cpu); 1222 update_policy_cpu(policy, new_cpu);
1202 1223
@@ -1218,8 +1239,6 @@ static int __cpufreq_remove_dev_finish(struct device *dev,
1218 int ret; 1239 int ret;
1219 unsigned long flags; 1240 unsigned long flags;
1220 struct cpufreq_policy *policy; 1241 struct cpufreq_policy *policy;
1221 struct kobject *kobj;
1222 struct completion *cmp;
1223 1242
1224 read_lock_irqsave(&cpufreq_driver_lock, flags); 1243 read_lock_irqsave(&cpufreq_driver_lock, flags);
1225 policy = per_cpu(cpufreq_cpu_data, cpu); 1244 policy = per_cpu(cpufreq_cpu_data, cpu);
@@ -1249,22 +1268,8 @@ static int __cpufreq_remove_dev_finish(struct device *dev,
1249 } 1268 }
1250 } 1269 }
1251 1270
1252 if (!frozen) { 1271 if (!frozen)
1253 down_read(&policy->rwsem); 1272 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 1273
1269 /* 1274 /*
1270 * Perform the ->exit() even during light-weight tear-down, 1275 * Perform the ->exit() even during light-weight tear-down,