aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-08-22 18:55:13 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-08-22 18:55:13 -0400
commit4eb5178c9cc09295111b79a99183f555c51887b4 (patch)
tree71b8b2446558c5175e82240c07a6fbe4916a1b93
parentb36f4be3de1b123d8601de062e7dbfc904f305fb (diff)
parent5025d628c8659fbf939f929107bf76db81dcdfff (diff)
Merge back earlier 'pm-cpufreq' material.
-rw-r--r--Documentation/cpu-freq/cpu-drivers.txt2
-rw-r--r--arch/x86/include/asm/processor.h29
-rw-r--r--drivers/cpufreq/Kconfig.arm36
-rw-r--r--drivers/cpufreq/Makefile2
-rw-r--r--drivers/cpufreq/acpi-cpufreq.c12
-rw-r--r--drivers/cpufreq/at32ap-cpufreq.c1
-rw-r--r--drivers/cpufreq/blackfin-cpufreq.c1
-rw-r--r--drivers/cpufreq/cpufreq-cpu0.c9
-rw-r--r--drivers/cpufreq/cpufreq-nforce2.c1
-rw-r--r--drivers/cpufreq/cpufreq.c738
-rw-r--r--drivers/cpufreq/cpufreq_conservative.c14
-rw-r--r--drivers/cpufreq/cpufreq_governor.c16
-rw-r--r--drivers/cpufreq/cpufreq_governor.h8
-rw-r--r--drivers/cpufreq/cpufreq_ondemand.c63
-rw-r--r--drivers/cpufreq/cpufreq_performance.c3
-rw-r--r--drivers/cpufreq/cpufreq_powersave.c3
-rw-r--r--drivers/cpufreq/cpufreq_stats.c31
-rw-r--r--drivers/cpufreq/cris-artpec3-cpufreq.c1
-rw-r--r--drivers/cpufreq/cris-etraxfs-cpufreq.c1
-rw-r--r--drivers/cpufreq/e_powersaver.c5
-rw-r--r--drivers/cpufreq/elanfreq.c1
-rw-r--r--drivers/cpufreq/exynos-cpufreq.c3
-rw-r--r--drivers/cpufreq/exynos-cpufreq.h21
-rw-r--r--drivers/cpufreq/exynos5440-cpufreq.c3
-rw-r--r--drivers/cpufreq/freq_table.c4
-rw-r--r--drivers/cpufreq/gx-suspmod.c5
-rw-r--r--drivers/cpufreq/ia64-acpi-cpufreq.c5
-rw-r--r--drivers/cpufreq/intel_pstate.c1
-rw-r--r--drivers/cpufreq/kirkwood-cpufreq.c1
-rw-r--r--drivers/cpufreq/longhaul.c1
-rw-r--r--drivers/cpufreq/longrun.c1
-rw-r--r--drivers/cpufreq/loongson2_cpufreq.c1
-rw-r--r--drivers/cpufreq/maple-cpufreq.c1
-rw-r--r--drivers/cpufreq/mperf.c51
-rw-r--r--drivers/cpufreq/mperf.h9
-rw-r--r--drivers/cpufreq/p4-clockmod.c1
-rw-r--r--drivers/cpufreq/pasemi-cpufreq.c1
-rw-r--r--drivers/cpufreq/pcc-cpufreq.c1
-rw-r--r--drivers/cpufreq/pmac32-cpufreq.c1
-rw-r--r--drivers/cpufreq/pmac64-cpufreq.c6
-rw-r--r--drivers/cpufreq/powernow-k6.c1
-rw-r--r--drivers/cpufreq/powernow-k7.c14
-rw-r--r--drivers/cpufreq/powernow-k8.c7
-rw-r--r--drivers/cpufreq/ppc-corenet-cpufreq.c1
-rw-r--r--drivers/cpufreq/ppc_cbe_cpufreq.c1
-rw-r--r--drivers/cpufreq/pxa2xx-cpufreq.c4
-rw-r--r--drivers/cpufreq/pxa3xx-cpufreq.c6
-rw-r--r--drivers/cpufreq/s3c2416-cpufreq.c1
-rw-r--r--drivers/cpufreq/s3c24xx-cpufreq.c8
-rw-r--r--drivers/cpufreq/s3c64xx-cpufreq.c1
-rw-r--r--drivers/cpufreq/sc520_freq.c1
-rw-r--r--drivers/cpufreq/sh-cpufreq.c1
-rw-r--r--drivers/cpufreq/sparc-us2e-cpufreq.c6
-rw-r--r--drivers/cpufreq/sparc-us3-cpufreq.c6
-rw-r--r--drivers/cpufreq/speedstep-centrino.c1
-rw-r--r--drivers/cpufreq/speedstep-ich.c1
-rw-r--r--drivers/cpufreq/speedstep-smi.c1
-rw-r--r--drivers/cpufreq/unicore2-cpufreq.c2
-rw-r--r--include/linux/cpufreq.h388
59 files changed, 691 insertions, 854 deletions
diff --git a/Documentation/cpu-freq/cpu-drivers.txt b/Documentation/cpu-freq/cpu-drivers.txt
index 19fa98e07bf7..40282e617913 100644
--- a/Documentation/cpu-freq/cpu-drivers.txt
+++ b/Documentation/cpu-freq/cpu-drivers.txt
@@ -50,8 +50,6 @@ What shall this struct cpufreq_driver contain?
50 50
51cpufreq_driver.name - The name of this driver. 51cpufreq_driver.name - The name of this driver.
52 52
53cpufreq_driver.owner - THIS_MODULE;
54
55cpufreq_driver.init - A pointer to the per-CPU initialization 53cpufreq_driver.init - A pointer to the per-CPU initialization
56 function. 54 function.
57 55
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 24cf5aefb704..4f4a3d98c170 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -942,35 +942,6 @@ extern int set_tsc_mode(unsigned int val);
942 942
943extern u16 amd_get_nb_id(int cpu); 943extern u16 amd_get_nb_id(int cpu);
944 944
945struct aperfmperf {
946 u64 aperf, mperf;
947};
948
949static inline void get_aperfmperf(struct aperfmperf *am)
950{
951 WARN_ON_ONCE(!boot_cpu_has(X86_FEATURE_APERFMPERF));
952
953 rdmsrl(MSR_IA32_APERF, am->aperf);
954 rdmsrl(MSR_IA32_MPERF, am->mperf);
955}
956
957#define APERFMPERF_SHIFT 10
958
959static inline
960unsigned long calc_aperfmperf_ratio(struct aperfmperf *old,
961 struct aperfmperf *new)
962{
963 u64 aperf = new->aperf - old->aperf;
964 u64 mperf = new->mperf - old->mperf;
965 unsigned long ratio = aperf;
966
967 mperf >>= APERFMPERF_SHIFT;
968 if (mperf)
969 ratio = div64_u64(aperf, mperf);
970
971 return ratio;
972}
973
974extern unsigned long arch_align_stack(unsigned long sp); 945extern unsigned long arch_align_stack(unsigned long sp);
975extern void free_init_pages(char *what, unsigned long begin, unsigned long end); 946extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
976 947
diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index de4d5d93c3fd..0fa204b244bd 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -17,37 +17,47 @@ config ARM_DT_BL_CPUFREQ
17 big.LITTLE platform. This gets frequency tables from DT. 17 big.LITTLE platform. This gets frequency tables from DT.
18 18
19config ARM_EXYNOS_CPUFREQ 19config ARM_EXYNOS_CPUFREQ
20 bool "SAMSUNG EXYNOS SoCs" 20 bool
21 depends on ARCH_EXYNOS
22 select CPU_FREQ_TABLE 21 select CPU_FREQ_TABLE
23 default y
24 help
25 This adds the CPUFreq driver common part for Samsung
26 EXYNOS SoCs.
27
28 If in doubt, say N.
29 22
30config ARM_EXYNOS4210_CPUFREQ 23config ARM_EXYNOS4210_CPUFREQ
31 def_bool CPU_EXYNOS4210 24 bool "SAMSUNG EXYNOS4210"
25 depends on CPU_EXYNOS4210
26 default y
27 select ARM_EXYNOS_CPUFREQ
32 help 28 help
33 This adds the CPUFreq driver for Samsung EXYNOS4210 29 This adds the CPUFreq driver for Samsung EXYNOS4210
34 SoC (S5PV310 or S5PC210). 30 SoC (S5PV310 or S5PC210).
35 31
32 If in doubt, say N.
33
36config ARM_EXYNOS4X12_CPUFREQ 34config ARM_EXYNOS4X12_CPUFREQ
37 def_bool (SOC_EXYNOS4212 || SOC_EXYNOS4412) 35 bool "SAMSUNG EXYNOS4x12"
36 depends on (SOC_EXYNOS4212 || SOC_EXYNOS4412)
37 default y
38 select ARM_EXYNOS_CPUFREQ
38 help 39 help
39 This adds the CPUFreq driver for Samsung EXYNOS4X12 40 This adds the CPUFreq driver for Samsung EXYNOS4X12
40 SoC (EXYNOS4212 or EXYNOS4412). 41 SoC (EXYNOS4212 or EXYNOS4412).
41 42
43 If in doubt, say N.
44
42config ARM_EXYNOS5250_CPUFREQ 45config ARM_EXYNOS5250_CPUFREQ
43 def_bool SOC_EXYNOS5250 46 bool "SAMSUNG EXYNOS5250"
47 depends on SOC_EXYNOS5250
48 default y
49 select ARM_EXYNOS_CPUFREQ
44 help 50 help
45 This adds the CPUFreq driver for Samsung EXYNOS5250 51 This adds the CPUFreq driver for Samsung EXYNOS5250
46 SoC. 52 SoC.
47 53
54 If in doubt, say N.
55
48config ARM_EXYNOS5440_CPUFREQ 56config ARM_EXYNOS5440_CPUFREQ
49 def_bool SOC_EXYNOS5440 57 bool "SAMSUNG EXYNOS5440"
58 depends on SOC_EXYNOS5440
50 depends on HAVE_CLK && PM_OPP && OF 59 depends on HAVE_CLK && PM_OPP && OF
60 default y
51 select CPU_FREQ_TABLE 61 select CPU_FREQ_TABLE
52 help 62 help
53 This adds the CPUFreq driver for Samsung EXYNOS5440 63 This adds the CPUFreq driver for Samsung EXYNOS5440
@@ -55,6 +65,8 @@ config ARM_EXYNOS5440_CPUFREQ
55 different than previous exynos controllers so not using 65 different than previous exynos controllers so not using
56 the common exynos framework. 66 the common exynos framework.
57 67
68 If in doubt, say N.
69
58config ARM_HIGHBANK_CPUFREQ 70config ARM_HIGHBANK_CPUFREQ
59 tristate "Calxeda Highbank-based" 71 tristate "Calxeda Highbank-based"
60 depends on ARCH_HIGHBANK 72 depends on ARCH_HIGHBANK
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile
index d345b5a7aa71..ad5866c2ada0 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -23,7 +23,7 @@ obj-$(CONFIG_GENERIC_CPUFREQ_CPU0) += cpufreq-cpu0.o
23# powernow-k8 can load then. ACPI is preferred to all other hardware-specific drivers. 23# powernow-k8 can load then. ACPI is preferred to all other hardware-specific drivers.
24# speedstep-* is preferred over p4-clockmod. 24# speedstep-* is preferred over p4-clockmod.
25 25
26obj-$(CONFIG_X86_ACPI_CPUFREQ) += acpi-cpufreq.o mperf.o 26obj-$(CONFIG_X86_ACPI_CPUFREQ) += acpi-cpufreq.o
27obj-$(CONFIG_X86_POWERNOW_K8) += powernow-k8.o 27obj-$(CONFIG_X86_POWERNOW_K8) += powernow-k8.o
28obj-$(CONFIG_X86_PCC_CPUFREQ) += pcc-cpufreq.o 28obj-$(CONFIG_X86_PCC_CPUFREQ) += pcc-cpufreq.o
29obj-$(CONFIG_X86_POWERNOW_K6) += powernow-k6.o 29obj-$(CONFIG_X86_POWERNOW_K6) += powernow-k6.o
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index 39264020b88a..a1260b4549db 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -45,7 +45,6 @@
45#include <asm/msr.h> 45#include <asm/msr.h>
46#include <asm/processor.h> 46#include <asm/processor.h>
47#include <asm/cpufeature.h> 47#include <asm/cpufeature.h>
48#include "mperf.h"
49 48
50MODULE_AUTHOR("Paul Diefenbaugh, Dominik Brodowski"); 49MODULE_AUTHOR("Paul Diefenbaugh, Dominik Brodowski");
51MODULE_DESCRIPTION("ACPI Processor P-States Driver"); 50MODULE_DESCRIPTION("ACPI Processor P-States Driver");
@@ -198,7 +197,7 @@ static ssize_t show_cpb(struct cpufreq_policy *policy, char *buf)
198 return sprintf(buf, "%u\n", boost_enabled); 197 return sprintf(buf, "%u\n", boost_enabled);
199} 198}
200 199
201static struct freq_attr cpb = __ATTR(cpb, 0644, show_cpb, store_cpb); 200cpufreq_freq_attr_rw(cpb);
202#endif 201#endif
203 202
204static int check_est_cpu(unsigned int cpuid) 203static int check_est_cpu(unsigned int cpuid)
@@ -710,7 +709,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
710 return blacklisted; 709 return blacklisted;
711#endif 710#endif
712 711
713 data = kzalloc(sizeof(struct acpi_cpufreq_data), GFP_KERNEL); 712 data = kzalloc(sizeof(*data), GFP_KERNEL);
714 if (!data) 713 if (!data)
715 return -ENOMEM; 714 return -ENOMEM;
716 715
@@ -800,7 +799,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
800 goto err_unreg; 799 goto err_unreg;
801 } 800 }
802 801
803 data->freq_table = kmalloc(sizeof(struct cpufreq_frequency_table) * 802 data->freq_table = kmalloc(sizeof(*data->freq_table) *
804 (perf->state_count+1), GFP_KERNEL); 803 (perf->state_count+1), GFP_KERNEL);
805 if (!data->freq_table) { 804 if (!data->freq_table) {
806 result = -ENOMEM; 805 result = -ENOMEM;
@@ -861,10 +860,6 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
861 /* notify BIOS that we exist */ 860 /* notify BIOS that we exist */
862 acpi_processor_notify_smm(THIS_MODULE); 861 acpi_processor_notify_smm(THIS_MODULE);
863 862
864 /* Check for APERF/MPERF support in hardware */
865 if (boot_cpu_has(X86_FEATURE_APERFMPERF))
866 acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
867
868 pr_debug("CPU%u - ACPI performance management activated.\n", cpu); 863 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
869 for (i = 0; i < perf->state_count; i++) 864 for (i = 0; i < perf->state_count; i++)
870 pr_debug(" %cP%d: %d MHz, %d mW, %d uS\n", 865 pr_debug(" %cP%d: %d MHz, %d mW, %d uS\n",
@@ -941,7 +936,6 @@ static struct cpufreq_driver acpi_cpufreq_driver = {
941 .exit = acpi_cpufreq_cpu_exit, 936 .exit = acpi_cpufreq_cpu_exit,
942 .resume = acpi_cpufreq_resume, 937 .resume = acpi_cpufreq_resume,
943 .name = "acpi-cpufreq", 938 .name = "acpi-cpufreq",
944 .owner = THIS_MODULE,
945 .attr = acpi_cpufreq_attr, 939 .attr = acpi_cpufreq_attr,
946}; 940};
947 941
diff --git a/drivers/cpufreq/at32ap-cpufreq.c b/drivers/cpufreq/at32ap-cpufreq.c
index 654488723cb5..e0c38d938997 100644
--- a/drivers/cpufreq/at32ap-cpufreq.c
+++ b/drivers/cpufreq/at32ap-cpufreq.c
@@ -108,7 +108,6 @@ static int __init at32_cpufreq_driver_init(struct cpufreq_policy *policy)
108 108
109static struct cpufreq_driver at32_driver = { 109static struct cpufreq_driver at32_driver = {
110 .name = "at32ap", 110 .name = "at32ap",
111 .owner = THIS_MODULE,
112 .init = at32_cpufreq_driver_init, 111 .init = at32_cpufreq_driver_init,
113 .verify = at32_verify_speed, 112 .verify = at32_verify_speed,
114 .target = at32_set_target, 113 .target = at32_set_target,
diff --git a/drivers/cpufreq/blackfin-cpufreq.c b/drivers/cpufreq/blackfin-cpufreq.c
index 9cdbbd278a80..ef05978a7237 100644
--- a/drivers/cpufreq/blackfin-cpufreq.c
+++ b/drivers/cpufreq/blackfin-cpufreq.c
@@ -225,7 +225,6 @@ static struct cpufreq_driver bfin_driver = {
225 .get = bfin_getfreq_khz, 225 .get = bfin_getfreq_khz,
226 .init = __bfin_cpu_init, 226 .init = __bfin_cpu_init,
227 .name = "bfin cpufreq", 227 .name = "bfin cpufreq",
228 .owner = THIS_MODULE,
229 .attr = bfin_freq_attr, 228 .attr = bfin_freq_attr,
230}; 229};
231 230
diff --git a/drivers/cpufreq/cpufreq-cpu0.c b/drivers/cpufreq/cpufreq-cpu0.c
index ad1fde277661..09cd3a76fb2e 100644
--- a/drivers/cpufreq/cpufreq-cpu0.c
+++ b/drivers/cpufreq/cpufreq-cpu0.c
@@ -69,7 +69,7 @@ static int cpu0_set_target(struct cpufreq_policy *policy,
69 69
70 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE); 70 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
71 71
72 if (cpu_reg) { 72 if (!IS_ERR(cpu_reg)) {
73 rcu_read_lock(); 73 rcu_read_lock();
74 opp = opp_find_freq_ceil(cpu_dev, &freq_Hz); 74 opp = opp_find_freq_ceil(cpu_dev, &freq_Hz);
75 if (IS_ERR(opp)) { 75 if (IS_ERR(opp)) {
@@ -90,7 +90,7 @@ static int cpu0_set_target(struct cpufreq_policy *policy,
90 freqs.new / 1000, volt ? volt / 1000 : -1); 90 freqs.new / 1000, volt ? volt / 1000 : -1);
91 91
92 /* scaling up? scale voltage before frequency */ 92 /* scaling up? scale voltage before frequency */
93 if (cpu_reg && freqs.new > freqs.old) { 93 if (!IS_ERR(cpu_reg) && freqs.new > freqs.old) {
94 ret = regulator_set_voltage_tol(cpu_reg, volt, tol); 94 ret = regulator_set_voltage_tol(cpu_reg, volt, tol);
95 if (ret) { 95 if (ret) {
96 pr_err("failed to scale voltage up: %d\n", ret); 96 pr_err("failed to scale voltage up: %d\n", ret);
@@ -102,14 +102,14 @@ static int cpu0_set_target(struct cpufreq_policy *policy,
102 ret = clk_set_rate(cpu_clk, freq_exact); 102 ret = clk_set_rate(cpu_clk, freq_exact);
103 if (ret) { 103 if (ret) {
104 pr_err("failed to set clock rate: %d\n", ret); 104 pr_err("failed to set clock rate: %d\n", ret);
105 if (cpu_reg) 105 if (!IS_ERR(cpu_reg))
106 regulator_set_voltage_tol(cpu_reg, volt_old, tol); 106 regulator_set_voltage_tol(cpu_reg, volt_old, tol);
107 freqs.new = freqs.old; 107 freqs.new = freqs.old;
108 goto post_notify; 108 goto post_notify;
109 } 109 }
110 110
111 /* scaling down? scale voltage after frequency */ 111 /* scaling down? scale voltage after frequency */
112 if (cpu_reg && freqs.new < freqs.old) { 112 if (!IS_ERR(cpu_reg) && freqs.new < freqs.old) {
113 ret = regulator_set_voltage_tol(cpu_reg, volt, tol); 113 ret = regulator_set_voltage_tol(cpu_reg, volt, tol);
114 if (ret) { 114 if (ret) {
115 pr_err("failed to scale voltage down: %d\n", ret); 115 pr_err("failed to scale voltage down: %d\n", ret);
@@ -210,7 +210,6 @@ static int cpu0_cpufreq_probe(struct platform_device *pdev)
210 } 210 }
211 pr_warn("failed to get cpu0 regulator: %ld\n", 211 pr_warn("failed to get cpu0 regulator: %ld\n",
212 PTR_ERR(cpu_reg)); 212 PTR_ERR(cpu_reg));
213 cpu_reg = NULL;
214 } 213 }
215 214
216 cpu_clk = devm_clk_get(cpu_dev, NULL); 215 cpu_clk = devm_clk_get(cpu_dev, NULL);
diff --git a/drivers/cpufreq/cpufreq-nforce2.c b/drivers/cpufreq/cpufreq-nforce2.c
index af1542d41440..b83d45f68574 100644
--- a/drivers/cpufreq/cpufreq-nforce2.c
+++ b/drivers/cpufreq/cpufreq-nforce2.c
@@ -379,7 +379,6 @@ static struct cpufreq_driver nforce2_driver = {
379 .get = nforce2_get, 379 .get = nforce2_get,
380 .init = nforce2_cpu_init, 380 .init = nforce2_cpu_init,
381 .exit = nforce2_cpu_exit, 381 .exit = nforce2_cpu_exit,
382 .owner = THIS_MODULE,
383}; 382};
384 383
385#ifdef MODULE 384#ifdef MODULE
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index f0a5e2b0eb8a..5c75e3147a60 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -17,24 +17,17 @@
17 17
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 19
20#include <asm/cputime.h> 20#include <linux/cpu.h>
21#include <linux/kernel.h>
22#include <linux/kernel_stat.h>
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/notifier.h>
26#include <linux/cpufreq.h> 21#include <linux/cpufreq.h>
27#include <linux/delay.h> 22#include <linux/delay.h>
28#include <linux/interrupt.h>
29#include <linux/spinlock.h>
30#include <linux/tick.h>
31#include <linux/device.h> 23#include <linux/device.h>
32#include <linux/slab.h> 24#include <linux/init.h>
33#include <linux/cpu.h> 25#include <linux/kernel_stat.h>
34#include <linux/completion.h> 26#include <linux/module.h>
35#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/slab.h>
36#include <linux/syscore_ops.h> 29#include <linux/syscore_ops.h>
37 30#include <linux/tick.h>
38#include <trace/events/power.h> 31#include <trace/events/power.h>
39 32
40/** 33/**
@@ -44,8 +37,10 @@
44 */ 37 */
45static struct cpufreq_driver *cpufreq_driver; 38static struct cpufreq_driver *cpufreq_driver;
46static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data); 39static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data);
40static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data_fallback);
47static DEFINE_RWLOCK(cpufreq_driver_lock); 41static DEFINE_RWLOCK(cpufreq_driver_lock);
48static DEFINE_MUTEX(cpufreq_governor_lock); 42static DEFINE_MUTEX(cpufreq_governor_lock);
43static LIST_HEAD(cpufreq_policy_list);
49 44
50#ifdef CONFIG_HOTPLUG_CPU 45#ifdef CONFIG_HOTPLUG_CPU
51/* This one keeps track of the previously set governor of a removed CPU */ 46/* This one keeps track of the previously set governor of a removed CPU */
@@ -69,15 +64,14 @@ static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor);
69 * - Lock should not be held across 64 * - Lock should not be held across
70 * __cpufreq_governor(data, CPUFREQ_GOV_STOP); 65 * __cpufreq_governor(data, CPUFREQ_GOV_STOP);
71 */ 66 */
72static DEFINE_PER_CPU(int, cpufreq_policy_cpu);
73static DEFINE_PER_CPU(struct rw_semaphore, cpu_policy_rwsem); 67static DEFINE_PER_CPU(struct rw_semaphore, cpu_policy_rwsem);
74 68
75#define lock_policy_rwsem(mode, cpu) \ 69#define lock_policy_rwsem(mode, cpu) \
76static int lock_policy_rwsem_##mode(int cpu) \ 70static int lock_policy_rwsem_##mode(int cpu) \
77{ \ 71{ \
78 int policy_cpu = per_cpu(cpufreq_policy_cpu, cpu); \ 72 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); \
79 BUG_ON(policy_cpu == -1); \ 73 BUG_ON(!policy); \
80 down_##mode(&per_cpu(cpu_policy_rwsem, policy_cpu)); \ 74 down_##mode(&per_cpu(cpu_policy_rwsem, policy->cpu)); \
81 \ 75 \
82 return 0; \ 76 return 0; \
83} 77}
@@ -88,14 +82,20 @@ lock_policy_rwsem(write, cpu);
88#define unlock_policy_rwsem(mode, cpu) \ 82#define unlock_policy_rwsem(mode, cpu) \
89static void unlock_policy_rwsem_##mode(int cpu) \ 83static void unlock_policy_rwsem_##mode(int cpu) \
90{ \ 84{ \
91 int policy_cpu = per_cpu(cpufreq_policy_cpu, cpu); \ 85 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); \
92 BUG_ON(policy_cpu == -1); \ 86 BUG_ON(!policy); \
93 up_##mode(&per_cpu(cpu_policy_rwsem, policy_cpu)); \ 87 up_##mode(&per_cpu(cpu_policy_rwsem, policy->cpu)); \
94} 88}
95 89
96unlock_policy_rwsem(read, cpu); 90unlock_policy_rwsem(read, cpu);
97unlock_policy_rwsem(write, cpu); 91unlock_policy_rwsem(write, cpu);
98 92
93/*
94 * rwsem to guarantee that cpufreq driver module doesn't unload during critical
95 * sections
96 */
97static DECLARE_RWSEM(cpufreq_rwsem);
98
99/* internal prototypes */ 99/* internal prototypes */
100static int __cpufreq_governor(struct cpufreq_policy *policy, 100static int __cpufreq_governor(struct cpufreq_policy *policy,
101 unsigned int event); 101 unsigned int event);
@@ -183,78 +183,46 @@ u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy)
183} 183}
184EXPORT_SYMBOL_GPL(get_cpu_idle_time); 184EXPORT_SYMBOL_GPL(get_cpu_idle_time);
185 185
186static struct cpufreq_policy *__cpufreq_cpu_get(unsigned int cpu, bool sysfs) 186struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
187{ 187{
188 struct cpufreq_policy *data; 188 struct cpufreq_policy *policy = NULL;
189 unsigned long flags; 189 unsigned long flags;
190 190
191 if (cpu >= nr_cpu_ids) 191 if (cpufreq_disabled() || (cpu >= nr_cpu_ids))
192 goto err_out; 192 return NULL;
193
194 if (!down_read_trylock(&cpufreq_rwsem))
195 return NULL;
193 196
194 /* get the cpufreq driver */ 197 /* get the cpufreq driver */
195 read_lock_irqsave(&cpufreq_driver_lock, flags); 198 read_lock_irqsave(&cpufreq_driver_lock, flags);
196 199
197 if (!cpufreq_driver) 200 if (cpufreq_driver) {
198 goto err_out_unlock; 201 /* get the CPU */
199 202 policy = per_cpu(cpufreq_cpu_data, cpu);
200 if (!try_module_get(cpufreq_driver->owner)) 203 if (policy)
201 goto err_out_unlock; 204 kobject_get(&policy->kobj);
202 205 }
203 /* get the CPU */
204 data = per_cpu(cpufreq_cpu_data, cpu);
205
206 if (!data)
207 goto err_out_put_module;
208
209 if (!sysfs && !kobject_get(&data->kobj))
210 goto err_out_put_module;
211 206
212 read_unlock_irqrestore(&cpufreq_driver_lock, flags); 207 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
213 return data;
214 208
215err_out_put_module: 209 if (!policy)
216 module_put(cpufreq_driver->owner); 210 up_read(&cpufreq_rwsem);
217err_out_unlock:
218 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
219err_out:
220 return NULL;
221}
222
223struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
224{
225 if (cpufreq_disabled())
226 return NULL;
227 211
228 return __cpufreq_cpu_get(cpu, false); 212 return policy;
229} 213}
230EXPORT_SYMBOL_GPL(cpufreq_cpu_get); 214EXPORT_SYMBOL_GPL(cpufreq_cpu_get);
231 215
232static struct cpufreq_policy *cpufreq_cpu_get_sysfs(unsigned int cpu) 216void cpufreq_cpu_put(struct cpufreq_policy *policy)
233{
234 return __cpufreq_cpu_get(cpu, true);
235}
236
237static void __cpufreq_cpu_put(struct cpufreq_policy *data, bool sysfs)
238{
239 if (!sysfs)
240 kobject_put(&data->kobj);
241 module_put(cpufreq_driver->owner);
242}
243
244void cpufreq_cpu_put(struct cpufreq_policy *data)
245{ 217{
246 if (cpufreq_disabled()) 218 if (cpufreq_disabled())
247 return; 219 return;
248 220
249 __cpufreq_cpu_put(data, false); 221 kobject_put(&policy->kobj);
222 up_read(&cpufreq_rwsem);
250} 223}
251EXPORT_SYMBOL_GPL(cpufreq_cpu_put); 224EXPORT_SYMBOL_GPL(cpufreq_cpu_put);
252 225
253static void cpufreq_cpu_put_sysfs(struct cpufreq_policy *data)
254{
255 __cpufreq_cpu_put(data, true);
256}
257
258/********************************************************************* 226/*********************************************************************
259 * EXTERNALLY AFFECTING FREQUENCY CHANGES * 227 * EXTERNALLY AFFECTING FREQUENCY CHANGES *
260 *********************************************************************/ 228 *********************************************************************/
@@ -459,8 +427,8 @@ show_one(scaling_min_freq, min);
459show_one(scaling_max_freq, max); 427show_one(scaling_max_freq, max);
460show_one(scaling_cur_freq, cur); 428show_one(scaling_cur_freq, cur);
461 429
462static int __cpufreq_set_policy(struct cpufreq_policy *data, 430static int __cpufreq_set_policy(struct cpufreq_policy *policy,
463 struct cpufreq_policy *policy); 431 struct cpufreq_policy *new_policy);
464 432
465/** 433/**
466 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access 434 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
@@ -699,12 +667,12 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
699 struct cpufreq_policy *policy = to_policy(kobj); 667 struct cpufreq_policy *policy = to_policy(kobj);
700 struct freq_attr *fattr = to_attr(attr); 668 struct freq_attr *fattr = to_attr(attr);
701 ssize_t ret = -EINVAL; 669 ssize_t ret = -EINVAL;
702 policy = cpufreq_cpu_get_sysfs(policy->cpu); 670
703 if (!policy) 671 if (!down_read_trylock(&cpufreq_rwsem))
704 goto no_policy; 672 goto exit;
705 673
706 if (lock_policy_rwsem_read(policy->cpu) < 0) 674 if (lock_policy_rwsem_read(policy->cpu) < 0)
707 goto fail; 675 goto up_read;
708 676
709 if (fattr->show) 677 if (fattr->show)
710 ret = fattr->show(policy, buf); 678 ret = fattr->show(policy, buf);
@@ -712,9 +680,10 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
712 ret = -EIO; 680 ret = -EIO;
713 681
714 unlock_policy_rwsem_read(policy->cpu); 682 unlock_policy_rwsem_read(policy->cpu);
715fail: 683
716 cpufreq_cpu_put_sysfs(policy); 684up_read:
717no_policy: 685 up_read(&cpufreq_rwsem);
686exit:
718 return ret; 687 return ret;
719} 688}
720 689
@@ -724,12 +693,12 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
724 struct cpufreq_policy *policy = to_policy(kobj); 693 struct cpufreq_policy *policy = to_policy(kobj);
725 struct freq_attr *fattr = to_attr(attr); 694 struct freq_attr *fattr = to_attr(attr);
726 ssize_t ret = -EINVAL; 695 ssize_t ret = -EINVAL;
727 policy = cpufreq_cpu_get_sysfs(policy->cpu); 696
728 if (!policy) 697 if (!down_read_trylock(&cpufreq_rwsem))
729 goto no_policy; 698 goto exit;
730 699
731 if (lock_policy_rwsem_write(policy->cpu) < 0) 700 if (lock_policy_rwsem_write(policy->cpu) < 0)
732 goto fail; 701 goto up_read;
733 702
734 if (fattr->store) 703 if (fattr->store)
735 ret = fattr->store(policy, buf, count); 704 ret = fattr->store(policy, buf, count);
@@ -737,9 +706,10 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
737 ret = -EIO; 706 ret = -EIO;
738 707
739 unlock_policy_rwsem_write(policy->cpu); 708 unlock_policy_rwsem_write(policy->cpu);
740fail: 709
741 cpufreq_cpu_put_sysfs(policy); 710up_read:
742no_policy: 711 up_read(&cpufreq_rwsem);
712exit:
743 return ret; 713 return ret;
744} 714}
745 715
@@ -805,41 +775,32 @@ void cpufreq_sysfs_remove_file(const struct attribute *attr)
805EXPORT_SYMBOL(cpufreq_sysfs_remove_file); 775EXPORT_SYMBOL(cpufreq_sysfs_remove_file);
806 776
807/* symlink affected CPUs */ 777/* symlink affected CPUs */
808static int cpufreq_add_dev_symlink(unsigned int cpu, 778static int cpufreq_add_dev_symlink(struct cpufreq_policy *policy)
809 struct cpufreq_policy *policy)
810{ 779{
811 unsigned int j; 780 unsigned int j;
812 int ret = 0; 781 int ret = 0;
813 782
814 for_each_cpu(j, policy->cpus) { 783 for_each_cpu(j, policy->cpus) {
815 struct cpufreq_policy *managed_policy;
816 struct device *cpu_dev; 784 struct device *cpu_dev;
817 785
818 if (j == cpu) 786 if (j == policy->cpu)
819 continue; 787 continue;
820 788
821 pr_debug("CPU %u already managed, adding link\n", j); 789 pr_debug("Adding link for CPU: %u\n", j);
822 managed_policy = cpufreq_cpu_get(cpu);
823 cpu_dev = get_cpu_device(j); 790 cpu_dev = get_cpu_device(j);
824 ret = sysfs_create_link(&cpu_dev->kobj, &policy->kobj, 791 ret = sysfs_create_link(&cpu_dev->kobj, &policy->kobj,
825 "cpufreq"); 792 "cpufreq");
826 if (ret) { 793 if (ret)
827 cpufreq_cpu_put(managed_policy); 794 break;
828 return ret;
829 }
830 } 795 }
831 return ret; 796 return ret;
832} 797}
833 798
834static int cpufreq_add_dev_interface(unsigned int cpu, 799static int cpufreq_add_dev_interface(struct cpufreq_policy *policy,
835 struct cpufreq_policy *policy,
836 struct device *dev) 800 struct device *dev)
837{ 801{
838 struct cpufreq_policy new_policy;
839 struct freq_attr **drv_attr; 802 struct freq_attr **drv_attr;
840 unsigned long flags;
841 int ret = 0; 803 int ret = 0;
842 unsigned int j;
843 804
844 /* prepare interface data */ 805 /* prepare interface data */
845 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, 806 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq,
@@ -871,18 +832,24 @@ static int cpufreq_add_dev_interface(unsigned int cpu,
871 goto err_out_kobj_put; 832 goto err_out_kobj_put;
872 } 833 }
873 834
874 write_lock_irqsave(&cpufreq_driver_lock, flags); 835 ret = cpufreq_add_dev_symlink(policy);
875 for_each_cpu(j, policy->cpus) {
876 per_cpu(cpufreq_cpu_data, j) = policy;
877 per_cpu(cpufreq_policy_cpu, j) = policy->cpu;
878 }
879 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
880
881 ret = cpufreq_add_dev_symlink(cpu, policy);
882 if (ret) 836 if (ret)
883 goto err_out_kobj_put; 837 goto err_out_kobj_put;
884 838
885 memcpy(&new_policy, policy, sizeof(struct cpufreq_policy)); 839 return ret;
840
841err_out_kobj_put:
842 kobject_put(&policy->kobj);
843 wait_for_completion(&policy->kobj_unregister);
844 return ret;
845}
846
847static void cpufreq_init_policy(struct cpufreq_policy *policy)
848{
849 struct cpufreq_policy new_policy;
850 int ret = 0;
851
852 memcpy(&new_policy, policy, sizeof(*policy));
886 /* assure that the starting sequence is run in __cpufreq_set_policy */ 853 /* assure that the starting sequence is run in __cpufreq_set_policy */
887 policy->governor = NULL; 854 policy->governor = NULL;
888 855
@@ -896,72 +863,106 @@ static int cpufreq_add_dev_interface(unsigned int cpu,
896 if (cpufreq_driver->exit) 863 if (cpufreq_driver->exit)
897 cpufreq_driver->exit(policy); 864 cpufreq_driver->exit(policy);
898 } 865 }
899 return ret;
900
901err_out_kobj_put:
902 kobject_put(&policy->kobj);
903 wait_for_completion(&policy->kobj_unregister);
904 return ret;
905} 866}
906 867
907#ifdef CONFIG_HOTPLUG_CPU 868#ifdef CONFIG_HOTPLUG_CPU
908static int cpufreq_add_policy_cpu(unsigned int cpu, unsigned int sibling, 869static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy,
909 struct device *dev) 870 unsigned int cpu, struct device *dev,
871 bool frozen)
910{ 872{
911 struct cpufreq_policy *policy;
912 int ret = 0, has_target = !!cpufreq_driver->target; 873 int ret = 0, has_target = !!cpufreq_driver->target;
913 unsigned long flags; 874 unsigned long flags;
914 875
915 policy = cpufreq_cpu_get(sibling); 876 if (has_target) {
916 WARN_ON(!policy); 877 ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
917 878 if (ret) {
918 if (has_target) 879 pr_err("%s: Failed to stop governor\n", __func__);
919 __cpufreq_governor(policy, CPUFREQ_GOV_STOP); 880 return ret;
881 }
882 }
920 883
921 lock_policy_rwsem_write(sibling); 884 lock_policy_rwsem_write(policy->cpu);
922 885
923 write_lock_irqsave(&cpufreq_driver_lock, flags); 886 write_lock_irqsave(&cpufreq_driver_lock, flags);
924 887
925 cpumask_set_cpu(cpu, policy->cpus); 888 cpumask_set_cpu(cpu, policy->cpus);
926 per_cpu(cpufreq_policy_cpu, cpu) = policy->cpu;
927 per_cpu(cpufreq_cpu_data, cpu) = policy; 889 per_cpu(cpufreq_cpu_data, cpu) = policy;
928 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 890 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
929 891
930 unlock_policy_rwsem_write(sibling); 892 unlock_policy_rwsem_write(policy->cpu);
931 893
932 if (has_target) { 894 if (has_target) {
933 __cpufreq_governor(policy, CPUFREQ_GOV_START); 895 if ((ret = __cpufreq_governor(policy, CPUFREQ_GOV_START)) ||
934 __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS); 896 (ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))) {
897 pr_err("%s: Failed to start governor\n", __func__);
898 return ret;
899 }
935 } 900 }
936 901
937 ret = sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq"); 902 /* Don't touch sysfs links during light-weight init */
938 if (ret) { 903 if (!frozen)
939 cpufreq_cpu_put(policy); 904 ret = sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq");
940 return ret;
941 }
942 905
943 return 0; 906 return ret;
944} 907}
945#endif 908#endif
946 909
947/** 910static struct cpufreq_policy *cpufreq_policy_restore(unsigned int cpu)
948 * cpufreq_add_dev - add a CPU device 911{
949 * 912 struct cpufreq_policy *policy;
950 * Adds the cpufreq interface for a CPU device. 913 unsigned long flags;
951 * 914
952 * The Oracle says: try running cpufreq registration/unregistration concurrently 915 write_lock_irqsave(&cpufreq_driver_lock, flags);
953 * with with cpu hotplugging and all hell will break loose. Tried to clean this 916
954 * mess up, but more thorough testing is needed. - Mathieu 917 policy = per_cpu(cpufreq_cpu_data_fallback, cpu);
955 */ 918
956static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) 919 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
920
921 return policy;
922}
923
924static struct cpufreq_policy *cpufreq_policy_alloc(void)
925{
926 struct cpufreq_policy *policy;
927
928 policy = kzalloc(sizeof(*policy), GFP_KERNEL);
929 if (!policy)
930 return NULL;
931
932 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL))
933 goto err_free_policy;
934
935 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL))
936 goto err_free_cpumask;
937
938 INIT_LIST_HEAD(&policy->policy_list);
939 return policy;
940
941err_free_cpumask:
942 free_cpumask_var(policy->cpus);
943err_free_policy:
944 kfree(policy);
945
946 return NULL;
947}
948
949static void cpufreq_policy_free(struct cpufreq_policy *policy)
950{
951 free_cpumask_var(policy->related_cpus);
952 free_cpumask_var(policy->cpus);
953 kfree(policy);
954}
955
956static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
957 bool frozen)
957{ 958{
958 unsigned int j, cpu = dev->id; 959 unsigned int j, cpu = dev->id;
959 int ret = -ENOMEM; 960 int ret = -ENOMEM;
960 struct cpufreq_policy *policy; 961 struct cpufreq_policy *policy;
961 unsigned long flags; 962 unsigned long flags;
962#ifdef CONFIG_HOTPLUG_CPU 963#ifdef CONFIG_HOTPLUG_CPU
964 struct cpufreq_policy *tpolicy;
963 struct cpufreq_governor *gov; 965 struct cpufreq_governor *gov;
964 int sibling;
965#endif 966#endif
966 967
967 if (cpu_is_offline(cpu)) 968 if (cpu_is_offline(cpu))
@@ -977,43 +978,38 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
977 cpufreq_cpu_put(policy); 978 cpufreq_cpu_put(policy);
978 return 0; 979 return 0;
979 } 980 }
981#endif
982
983 if (!down_read_trylock(&cpufreq_rwsem))
984 return 0;
980 985
981#ifdef CONFIG_HOTPLUG_CPU 986#ifdef CONFIG_HOTPLUG_CPU
982 /* Check if this cpu was hot-unplugged earlier and has siblings */ 987 /* Check if this cpu was hot-unplugged earlier and has siblings */
983 read_lock_irqsave(&cpufreq_driver_lock, flags); 988 read_lock_irqsave(&cpufreq_driver_lock, flags);
984 for_each_online_cpu(sibling) { 989 list_for_each_entry(tpolicy, &cpufreq_policy_list, policy_list) {
985 struct cpufreq_policy *cp = per_cpu(cpufreq_cpu_data, sibling); 990 if (cpumask_test_cpu(cpu, tpolicy->related_cpus)) {
986 if (cp && cpumask_test_cpu(cpu, cp->related_cpus)) {
987 read_unlock_irqrestore(&cpufreq_driver_lock, flags); 991 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
988 return cpufreq_add_policy_cpu(cpu, sibling, dev); 992 ret = cpufreq_add_policy_cpu(tpolicy, cpu, dev, frozen);
993 up_read(&cpufreq_rwsem);
994 return ret;
989 } 995 }
990 } 996 }
991 read_unlock_irqrestore(&cpufreq_driver_lock, flags); 997 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
992#endif 998#endif
993#endif
994 999
995 if (!try_module_get(cpufreq_driver->owner)) { 1000 if (frozen)
996 ret = -EINVAL; 1001 /* Restore the saved policy when doing light-weight init */
997 goto module_out; 1002 policy = cpufreq_policy_restore(cpu);
998 } 1003 else
1004 policy = cpufreq_policy_alloc();
999 1005
1000 policy = kzalloc(sizeof(struct cpufreq_policy), GFP_KERNEL);
1001 if (!policy) 1006 if (!policy)
1002 goto nomem_out; 1007 goto nomem_out;
1003 1008
1004 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL))
1005 goto err_free_policy;
1006
1007 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL))
1008 goto err_free_cpumask;
1009
1010 policy->cpu = cpu; 1009 policy->cpu = cpu;
1011 policy->governor = CPUFREQ_DEFAULT_GOVERNOR; 1010 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
1012 cpumask_copy(policy->cpus, cpumask_of(cpu)); 1011 cpumask_copy(policy->cpus, cpumask_of(cpu));
1013 1012
1014 /* Initially set CPU itself as the policy_cpu */
1015 per_cpu(cpufreq_policy_cpu, cpu) = cpu;
1016
1017 init_completion(&policy->kobj_unregister); 1013 init_completion(&policy->kobj_unregister);
1018 INIT_WORK(&policy->update, handle_update); 1014 INIT_WORK(&policy->update, handle_update);
1019 1015
@@ -1050,12 +1046,26 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
1050 } 1046 }
1051#endif 1047#endif
1052 1048
1053 ret = cpufreq_add_dev_interface(cpu, policy, dev); 1049 write_lock_irqsave(&cpufreq_driver_lock, flags);
1054 if (ret) 1050 for_each_cpu(j, policy->cpus)
1055 goto err_out_unregister; 1051 per_cpu(cpufreq_cpu_data, j) = policy;
1052 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1053
1054 if (!frozen) {
1055 ret = cpufreq_add_dev_interface(policy, dev);
1056 if (ret)
1057 goto err_out_unregister;
1058 }
1059
1060 write_lock_irqsave(&cpufreq_driver_lock, flags);
1061 list_add(&policy->policy_list, &cpufreq_policy_list);
1062 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1063
1064 cpufreq_init_policy(policy);
1056 1065
1057 kobject_uevent(&policy->kobj, KOBJ_ADD); 1066 kobject_uevent(&policy->kobj, KOBJ_ADD);
1058 module_put(cpufreq_driver->owner); 1067 up_read(&cpufreq_rwsem);
1068
1059 pr_debug("initialization complete\n"); 1069 pr_debug("initialization complete\n");
1060 1070
1061 return 0; 1071 return 0;
@@ -1066,32 +1076,33 @@ err_out_unregister:
1066 per_cpu(cpufreq_cpu_data, j) = NULL; 1076 per_cpu(cpufreq_cpu_data, j) = NULL;
1067 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1077 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1068 1078
1069 kobject_put(&policy->kobj);
1070 wait_for_completion(&policy->kobj_unregister);
1071
1072err_set_policy_cpu: 1079err_set_policy_cpu:
1073 per_cpu(cpufreq_policy_cpu, cpu) = -1; 1080 cpufreq_policy_free(policy);
1074 free_cpumask_var(policy->related_cpus);
1075err_free_cpumask:
1076 free_cpumask_var(policy->cpus);
1077err_free_policy:
1078 kfree(policy);
1079nomem_out: 1081nomem_out:
1080 module_put(cpufreq_driver->owner); 1082 up_read(&cpufreq_rwsem);
1081module_out: 1083
1082 return ret; 1084 return ret;
1083} 1085}
1084 1086
1085static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu) 1087/**
1088 * cpufreq_add_dev - add a CPU device
1089 *
1090 * Adds the cpufreq interface for a CPU device.
1091 *
1092 * The Oracle says: try running cpufreq registration/unregistration concurrently
1093 * with with cpu hotplugging and all hell will break loose. Tried to clean this
1094 * mess up, but more thorough testing is needed. - Mathieu
1095 */
1096static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
1086{ 1097{
1087 int j; 1098 return __cpufreq_add_dev(dev, sif, false);
1099}
1088 1100
1101static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
1102{
1089 policy->last_cpu = policy->cpu; 1103 policy->last_cpu = policy->cpu;
1090 policy->cpu = cpu; 1104 policy->cpu = cpu;
1091 1105
1092 for_each_cpu(j, policy->cpus)
1093 per_cpu(cpufreq_policy_cpu, j) = cpu;
1094
1095#ifdef CONFIG_CPU_FREQ_TABLE 1106#ifdef CONFIG_CPU_FREQ_TABLE
1096 cpufreq_frequency_table_update_policy_cpu(policy); 1107 cpufreq_frequency_table_update_policy_cpu(policy);
1097#endif 1108#endif
@@ -1099,6 +1110,37 @@ static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
1099 CPUFREQ_UPDATE_POLICY_CPU, policy); 1110 CPUFREQ_UPDATE_POLICY_CPU, policy);
1100} 1111}
1101 1112
1113static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy,
1114 unsigned int old_cpu, bool frozen)
1115{
1116 struct device *cpu_dev;
1117 int ret;
1118
1119 /* first sibling now owns the new sysfs dir */
1120 cpu_dev = get_cpu_device(cpumask_first(policy->cpus));
1121
1122 /* Don't touch sysfs files during light-weight tear-down */
1123 if (frozen)
1124 return cpu_dev->id;
1125
1126 sysfs_remove_link(&cpu_dev->kobj, "cpufreq");
1127 ret = kobject_move(&policy->kobj, &cpu_dev->kobj);
1128 if (ret) {
1129 pr_err("%s: Failed to move kobj: %d", __func__, ret);
1130
1131 WARN_ON(lock_policy_rwsem_write(old_cpu));
1132 cpumask_set_cpu(old_cpu, policy->cpus);
1133 unlock_policy_rwsem_write(old_cpu);
1134
1135 ret = sysfs_create_link(&cpu_dev->kobj, &policy->kobj,
1136 "cpufreq");
1137
1138 return -EINVAL;
1139 }
1140
1141 return cpu_dev->id;
1142}
1143
1102/** 1144/**
1103 * __cpufreq_remove_dev - remove a CPU device 1145 * __cpufreq_remove_dev - remove a CPU device
1104 * 1146 *
@@ -1107,111 +1149,126 @@ static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
1107 * This routine frees the rwsem before returning. 1149 * This routine frees the rwsem before returning.
1108 */ 1150 */
1109static int __cpufreq_remove_dev(struct device *dev, 1151static int __cpufreq_remove_dev(struct device *dev,
1110 struct subsys_interface *sif) 1152 struct subsys_interface *sif, bool frozen)
1111{ 1153{
1112 unsigned int cpu = dev->id, ret, cpus; 1154 unsigned int cpu = dev->id, cpus;
1155 int new_cpu, ret;
1113 unsigned long flags; 1156 unsigned long flags;
1114 struct cpufreq_policy *data; 1157 struct cpufreq_policy *policy;
1115 struct kobject *kobj; 1158 struct kobject *kobj;
1116 struct completion *cmp; 1159 struct completion *cmp;
1117 struct device *cpu_dev;
1118 1160
1119 pr_debug("%s: unregistering CPU %u\n", __func__, cpu); 1161 pr_debug("%s: unregistering CPU %u\n", __func__, cpu);
1120 1162
1121 write_lock_irqsave(&cpufreq_driver_lock, flags); 1163 write_lock_irqsave(&cpufreq_driver_lock, flags);
1122 1164
1123 data = per_cpu(cpufreq_cpu_data, cpu); 1165 policy = per_cpu(cpufreq_cpu_data, cpu);
1124 per_cpu(cpufreq_cpu_data, cpu) = NULL; 1166
1167 /* Save the policy somewhere when doing a light-weight tear-down */
1168 if (frozen)
1169 per_cpu(cpufreq_cpu_data_fallback, cpu) = policy;
1125 1170
1126 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1171 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1127 1172
1128 if (!data) { 1173 if (!policy) {
1129 pr_debug("%s: No cpu_data found\n", __func__); 1174 pr_debug("%s: No cpu_data found\n", __func__);
1130 return -EINVAL; 1175 return -EINVAL;
1131 } 1176 }
1132 1177
1133 if (cpufreq_driver->target) 1178 if (cpufreq_driver->target) {
1134 __cpufreq_governor(data, CPUFREQ_GOV_STOP); 1179 ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
1180 if (ret) {
1181 pr_err("%s: Failed to stop governor\n", __func__);
1182 return ret;
1183 }
1184 }
1135 1185
1136#ifdef CONFIG_HOTPLUG_CPU 1186#ifdef CONFIG_HOTPLUG_CPU
1137 if (!cpufreq_driver->setpolicy) 1187 if (!cpufreq_driver->setpolicy)
1138 strncpy(per_cpu(cpufreq_cpu_governor, cpu), 1188 strncpy(per_cpu(cpufreq_cpu_governor, cpu),
1139 data->governor->name, CPUFREQ_NAME_LEN); 1189 policy->governor->name, CPUFREQ_NAME_LEN);
1140#endif 1190#endif
1141 1191
1142 WARN_ON(lock_policy_rwsem_write(cpu)); 1192 WARN_ON(lock_policy_rwsem_write(cpu));
1143 cpus = cpumask_weight(data->cpus); 1193 cpus = cpumask_weight(policy->cpus);
1144 1194
1145 if (cpus > 1) 1195 if (cpus > 1)
1146 cpumask_clear_cpu(cpu, data->cpus); 1196 cpumask_clear_cpu(cpu, policy->cpus);
1147 unlock_policy_rwsem_write(cpu); 1197 unlock_policy_rwsem_write(cpu);
1148 1198
1149 if (cpu != data->cpu) { 1199 if (cpu != policy->cpu && !frozen) {
1150 sysfs_remove_link(&dev->kobj, "cpufreq"); 1200 sysfs_remove_link(&dev->kobj, "cpufreq");
1151 } else if (cpus > 1) { 1201 } else if (cpus > 1) {
1152 /* first sibling now owns the new sysfs dir */
1153 cpu_dev = get_cpu_device(cpumask_first(data->cpus));
1154 sysfs_remove_link(&cpu_dev->kobj, "cpufreq");
1155 ret = kobject_move(&data->kobj, &cpu_dev->kobj);
1156 if (ret) {
1157 pr_err("%s: Failed to move kobj: %d", __func__, ret);
1158 1202
1203 new_cpu = cpufreq_nominate_new_policy_cpu(policy, cpu, frozen);
1204 if (new_cpu >= 0) {
1159 WARN_ON(lock_policy_rwsem_write(cpu)); 1205 WARN_ON(lock_policy_rwsem_write(cpu));
1160 cpumask_set_cpu(cpu, data->cpus); 1206 update_policy_cpu(policy, new_cpu);
1161
1162 write_lock_irqsave(&cpufreq_driver_lock, flags);
1163 per_cpu(cpufreq_cpu_data, cpu) = data;
1164 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1165
1166 unlock_policy_rwsem_write(cpu); 1207 unlock_policy_rwsem_write(cpu);
1167 1208
1168 ret = sysfs_create_link(&cpu_dev->kobj, &data->kobj, 1209 if (!frozen) {
1169 "cpufreq"); 1210 pr_debug("%s: policy Kobject moved to cpu: %d "
1170 return -EINVAL; 1211 "from: %d\n",__func__, new_cpu, cpu);
1212 }
1171 } 1213 }
1172
1173 WARN_ON(lock_policy_rwsem_write(cpu));
1174 update_policy_cpu(data, cpu_dev->id);
1175 unlock_policy_rwsem_write(cpu);
1176 pr_debug("%s: policy Kobject moved to cpu: %d from: %d\n",
1177 __func__, cpu_dev->id, cpu);
1178 } 1214 }
1179 1215
1180 /* If cpu is last user of policy, free policy */ 1216 /* If cpu is last user of policy, free policy */
1181 if (cpus == 1) { 1217 if (cpus == 1) {
1182 if (cpufreq_driver->target) 1218 if (cpufreq_driver->target) {
1183 __cpufreq_governor(data, CPUFREQ_GOV_POLICY_EXIT); 1219 ret = __cpufreq_governor(policy,
1184 1220 CPUFREQ_GOV_POLICY_EXIT);
1185 lock_policy_rwsem_read(cpu); 1221 if (ret) {
1186 kobj = &data->kobj; 1222 pr_err("%s: Failed to exit governor\n",
1187 cmp = &data->kobj_unregister; 1223 __func__);
1188 unlock_policy_rwsem_read(cpu); 1224 return ret;
1189 kobject_put(kobj); 1225 }
1190 1226 }
1191 /* we need to make sure that the underlying kobj is actually 1227
1192 * not referenced anymore by anybody before we proceed with 1228 if (!frozen) {
1193 * unloading. 1229 lock_policy_rwsem_read(cpu);
1194 */ 1230 kobj = &policy->kobj;
1195 pr_debug("waiting for dropping of refcount\n"); 1231 cmp = &policy->kobj_unregister;
1196 wait_for_completion(cmp); 1232 unlock_policy_rwsem_read(cpu);
1197 pr_debug("wait complete\n"); 1233 kobject_put(kobj);
1234
1235 /*
1236 * We need to make sure that the underlying kobj is
1237 * actually not referenced anymore by anybody before we
1238 * proceed with unloading.
1239 */
1240 pr_debug("waiting for dropping of refcount\n");
1241 wait_for_completion(cmp);
1242 pr_debug("wait complete\n");
1243 }
1198 1244
1245 /*
1246 * Perform the ->exit() even during light-weight tear-down,
1247 * since this is a core component, and is essential for the
1248 * subsequent light-weight ->init() to succeed.
1249 */
1199 if (cpufreq_driver->exit) 1250 if (cpufreq_driver->exit)
1200 cpufreq_driver->exit(data); 1251 cpufreq_driver->exit(policy);
1201 1252
1202 free_cpumask_var(data->related_cpus); 1253 /* Remove policy from list of active policies */
1203 free_cpumask_var(data->cpus); 1254 write_lock_irqsave(&cpufreq_driver_lock, flags);
1204 kfree(data); 1255 list_del(&policy->policy_list);
1256 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1257
1258 if (!frozen)
1259 cpufreq_policy_free(policy);
1205 } else { 1260 } else {
1206 pr_debug("%s: removing link, cpu: %d\n", __func__, cpu);
1207 cpufreq_cpu_put(data);
1208 if (cpufreq_driver->target) { 1261 if (cpufreq_driver->target) {
1209 __cpufreq_governor(data, CPUFREQ_GOV_START); 1262 if ((ret = __cpufreq_governor(policy, CPUFREQ_GOV_START)) ||
1210 __cpufreq_governor(data, CPUFREQ_GOV_LIMITS); 1263 (ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))) {
1264 pr_err("%s: Failed to start governor\n",
1265 __func__);
1266 return ret;
1267 }
1211 } 1268 }
1212 } 1269 }
1213 1270
1214 per_cpu(cpufreq_policy_cpu, cpu) = -1; 1271 per_cpu(cpufreq_cpu_data, cpu) = NULL;
1215 return 0; 1272 return 0;
1216} 1273}
1217 1274
@@ -1223,7 +1280,7 @@ static int cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)
1223 if (cpu_is_offline(cpu)) 1280 if (cpu_is_offline(cpu))
1224 return 0; 1281 return 0;
1225 1282
1226 retval = __cpufreq_remove_dev(dev, sif); 1283 retval = __cpufreq_remove_dev(dev, sif, false);
1227 return retval; 1284 return retval;
1228} 1285}
1229 1286
@@ -1344,10 +1401,9 @@ static unsigned int __cpufreq_get(unsigned int cpu)
1344unsigned int cpufreq_get(unsigned int cpu) 1401unsigned int cpufreq_get(unsigned int cpu)
1345{ 1402{
1346 unsigned int ret_freq = 0; 1403 unsigned int ret_freq = 0;
1347 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1348 1404
1349 if (!policy) 1405 if (!down_read_trylock(&cpufreq_rwsem))
1350 goto out; 1406 return 0;
1351 1407
1352 if (unlikely(lock_policy_rwsem_read(cpu))) 1408 if (unlikely(lock_policy_rwsem_read(cpu)))
1353 goto out_policy; 1409 goto out_policy;
@@ -1357,8 +1413,8 @@ unsigned int cpufreq_get(unsigned int cpu)
1357 unlock_policy_rwsem_read(cpu); 1413 unlock_policy_rwsem_read(cpu);
1358 1414
1359out_policy: 1415out_policy:
1360 cpufreq_cpu_put(policy); 1416 up_read(&cpufreq_rwsem);
1361out: 1417
1362 return ret_freq; 1418 return ret_freq;
1363} 1419}
1364EXPORT_SYMBOL(cpufreq_get); 1420EXPORT_SYMBOL(cpufreq_get);
@@ -1381,23 +1437,23 @@ static int cpufreq_bp_suspend(void)
1381 int ret = 0; 1437 int ret = 0;
1382 1438
1383 int cpu = smp_processor_id(); 1439 int cpu = smp_processor_id();
1384 struct cpufreq_policy *cpu_policy; 1440 struct cpufreq_policy *policy;
1385 1441
1386 pr_debug("suspending cpu %u\n", cpu); 1442 pr_debug("suspending cpu %u\n", cpu);
1387 1443
1388 /* If there's no policy for the boot CPU, we have nothing to do. */ 1444 /* If there's no policy for the boot CPU, we have nothing to do. */
1389 cpu_policy = cpufreq_cpu_get(cpu); 1445 policy = cpufreq_cpu_get(cpu);
1390 if (!cpu_policy) 1446 if (!policy)
1391 return 0; 1447 return 0;
1392 1448
1393 if (cpufreq_driver->suspend) { 1449 if (cpufreq_driver->suspend) {
1394 ret = cpufreq_driver->suspend(cpu_policy); 1450 ret = cpufreq_driver->suspend(policy);
1395 if (ret) 1451 if (ret)
1396 printk(KERN_ERR "cpufreq: suspend failed in ->suspend " 1452 printk(KERN_ERR "cpufreq: suspend failed in ->suspend "
1397 "step on CPU %u\n", cpu_policy->cpu); 1453 "step on CPU %u\n", policy->cpu);
1398 } 1454 }
1399 1455
1400 cpufreq_cpu_put(cpu_policy); 1456 cpufreq_cpu_put(policy);
1401 return ret; 1457 return ret;
1402} 1458}
1403 1459
@@ -1419,28 +1475,28 @@ static void cpufreq_bp_resume(void)
1419 int ret = 0; 1475 int ret = 0;
1420 1476
1421 int cpu = smp_processor_id(); 1477 int cpu = smp_processor_id();
1422 struct cpufreq_policy *cpu_policy; 1478 struct cpufreq_policy *policy;
1423 1479
1424 pr_debug("resuming cpu %u\n", cpu); 1480 pr_debug("resuming cpu %u\n", cpu);
1425 1481
1426 /* If there's no policy for the boot CPU, we have nothing to do. */ 1482 /* If there's no policy for the boot CPU, we have nothing to do. */
1427 cpu_policy = cpufreq_cpu_get(cpu); 1483 policy = cpufreq_cpu_get(cpu);
1428 if (!cpu_policy) 1484 if (!policy)
1429 return; 1485 return;
1430 1486
1431 if (cpufreq_driver->resume) { 1487 if (cpufreq_driver->resume) {
1432 ret = cpufreq_driver->resume(cpu_policy); 1488 ret = cpufreq_driver->resume(policy);
1433 if (ret) { 1489 if (ret) {
1434 printk(KERN_ERR "cpufreq: resume failed in ->resume " 1490 printk(KERN_ERR "cpufreq: resume failed in ->resume "
1435 "step on CPU %u\n", cpu_policy->cpu); 1491 "step on CPU %u\n", policy->cpu);
1436 goto fail; 1492 goto fail;
1437 } 1493 }
1438 } 1494 }
1439 1495
1440 schedule_work(&cpu_policy->update); 1496 schedule_work(&policy->update);
1441 1497
1442fail: 1498fail:
1443 cpufreq_cpu_put(cpu_policy); 1499 cpufreq_cpu_put(policy);
1444} 1500}
1445 1501
1446static struct syscore_ops cpufreq_syscore_ops = { 1502static struct syscore_ops cpufreq_syscore_ops = {
@@ -1594,18 +1650,6 @@ fail:
1594} 1650}
1595EXPORT_SYMBOL_GPL(cpufreq_driver_target); 1651EXPORT_SYMBOL_GPL(cpufreq_driver_target);
1596 1652
1597int __cpufreq_driver_getavg(struct cpufreq_policy *policy, unsigned int cpu)
1598{
1599 if (cpufreq_disabled())
1600 return 0;
1601
1602 if (!cpufreq_driver->getavg)
1603 return 0;
1604
1605 return cpufreq_driver->getavg(policy, cpu);
1606}
1607EXPORT_SYMBOL_GPL(__cpufreq_driver_getavg);
1608
1609/* 1653/*
1610 * when "event" is CPUFREQ_GOV_LIMITS 1654 * when "event" is CPUFREQ_GOV_LIMITS
1611 */ 1655 */
@@ -1640,8 +1684,9 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
1640 } 1684 }
1641 } 1685 }
1642 1686
1643 if (!try_module_get(policy->governor->owner)) 1687 if (event == CPUFREQ_GOV_POLICY_INIT)
1644 return -EINVAL; 1688 if (!try_module_get(policy->governor->owner))
1689 return -EINVAL;
1645 1690
1646 pr_debug("__cpufreq_governor for CPU %u, event %u\n", 1691 pr_debug("__cpufreq_governor for CPU %u, event %u\n",
1647 policy->cpu, event); 1692 policy->cpu, event);
@@ -1677,11 +1722,8 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
1677 mutex_unlock(&cpufreq_governor_lock); 1722 mutex_unlock(&cpufreq_governor_lock);
1678 } 1723 }
1679 1724
1680 /* we keep one module reference alive for 1725 if (((event == CPUFREQ_GOV_POLICY_INIT) && ret) ||
1681 each CPU governed by this CPU */ 1726 ((event == CPUFREQ_GOV_POLICY_EXIT) && !ret))
1682 if ((event != CPUFREQ_GOV_START) || ret)
1683 module_put(policy->governor->owner);
1684 if ((event == CPUFREQ_GOV_STOP) && !ret)
1685 module_put(policy->governor->owner); 1727 module_put(policy->governor->owner);
1686 1728
1687 return ret; 1729 return ret;
@@ -1761,7 +1803,7 @@ int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
1761 if (!cpu_policy) 1803 if (!cpu_policy)
1762 return -EINVAL; 1804 return -EINVAL;
1763 1805
1764 memcpy(policy, cpu_policy, sizeof(struct cpufreq_policy)); 1806 memcpy(policy, cpu_policy, sizeof(*policy));
1765 1807
1766 cpufreq_cpu_put(cpu_policy); 1808 cpufreq_cpu_put(cpu_policy);
1767 return 0; 1809 return 0;
@@ -1772,95 +1814,94 @@ EXPORT_SYMBOL(cpufreq_get_policy);
1772 * data : current policy. 1814 * data : current policy.
1773 * policy : policy to be set. 1815 * policy : policy to be set.
1774 */ 1816 */
1775static int __cpufreq_set_policy(struct cpufreq_policy *data, 1817static int __cpufreq_set_policy(struct cpufreq_policy *policy,
1776 struct cpufreq_policy *policy) 1818 struct cpufreq_policy *new_policy)
1777{ 1819{
1778 int ret = 0, failed = 1; 1820 int ret = 0, failed = 1;
1779 1821
1780 pr_debug("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu, 1822 pr_debug("setting new policy for CPU %u: %u - %u kHz\n", new_policy->cpu,
1781 policy->min, policy->max); 1823 new_policy->min, new_policy->max);
1782 1824
1783 memcpy(&policy->cpuinfo, &data->cpuinfo, 1825 memcpy(&new_policy->cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo));
1784 sizeof(struct cpufreq_cpuinfo));
1785 1826
1786 if (policy->min > data->max || policy->max < data->min) { 1827 if (new_policy->min > policy->max || new_policy->max < policy->min) {
1787 ret = -EINVAL; 1828 ret = -EINVAL;
1788 goto error_out; 1829 goto error_out;
1789 } 1830 }
1790 1831
1791 /* verify the cpu speed can be set within this limit */ 1832 /* verify the cpu speed can be set within this limit */
1792 ret = cpufreq_driver->verify(policy); 1833 ret = cpufreq_driver->verify(new_policy);
1793 if (ret) 1834 if (ret)
1794 goto error_out; 1835 goto error_out;
1795 1836
1796 /* adjust if necessary - all reasons */ 1837 /* adjust if necessary - all reasons */
1797 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1838 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1798 CPUFREQ_ADJUST, policy); 1839 CPUFREQ_ADJUST, new_policy);
1799 1840
1800 /* adjust if necessary - hardware incompatibility*/ 1841 /* adjust if necessary - hardware incompatibility*/
1801 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1842 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1802 CPUFREQ_INCOMPATIBLE, policy); 1843 CPUFREQ_INCOMPATIBLE, new_policy);
1803 1844
1804 /* 1845 /*
1805 * verify the cpu speed can be set within this limit, which might be 1846 * verify the cpu speed can be set within this limit, which might be
1806 * different to the first one 1847 * different to the first one
1807 */ 1848 */
1808 ret = cpufreq_driver->verify(policy); 1849 ret = cpufreq_driver->verify(new_policy);
1809 if (ret) 1850 if (ret)
1810 goto error_out; 1851 goto error_out;
1811 1852
1812 /* notification of the new policy */ 1853 /* notification of the new policy */
1813 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1854 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1814 CPUFREQ_NOTIFY, policy); 1855 CPUFREQ_NOTIFY, new_policy);
1815 1856
1816 data->min = policy->min; 1857 policy->min = new_policy->min;
1817 data->max = policy->max; 1858 policy->max = new_policy->max;
1818 1859
1819 pr_debug("new min and max freqs are %u - %u kHz\n", 1860 pr_debug("new min and max freqs are %u - %u kHz\n",
1820 data->min, data->max); 1861 policy->min, policy->max);
1821 1862
1822 if (cpufreq_driver->setpolicy) { 1863 if (cpufreq_driver->setpolicy) {
1823 data->policy = policy->policy; 1864 policy->policy = new_policy->policy;
1824 pr_debug("setting range\n"); 1865 pr_debug("setting range\n");
1825 ret = cpufreq_driver->setpolicy(policy); 1866 ret = cpufreq_driver->setpolicy(new_policy);
1826 } else { 1867 } else {
1827 if (policy->governor != data->governor) { 1868 if (new_policy->governor != policy->governor) {
1828 /* save old, working values */ 1869 /* save old, working values */
1829 struct cpufreq_governor *old_gov = data->governor; 1870 struct cpufreq_governor *old_gov = policy->governor;
1830 1871
1831 pr_debug("governor switch\n"); 1872 pr_debug("governor switch\n");
1832 1873
1833 /* end old governor */ 1874 /* end old governor */
1834 if (data->governor) { 1875 if (policy->governor) {
1835 __cpufreq_governor(data, CPUFREQ_GOV_STOP); 1876 __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
1836 unlock_policy_rwsem_write(policy->cpu); 1877 unlock_policy_rwsem_write(new_policy->cpu);
1837 __cpufreq_governor(data, 1878 __cpufreq_governor(policy,
1838 CPUFREQ_GOV_POLICY_EXIT); 1879 CPUFREQ_GOV_POLICY_EXIT);
1839 lock_policy_rwsem_write(policy->cpu); 1880 lock_policy_rwsem_write(new_policy->cpu);
1840 } 1881 }
1841 1882
1842 /* start new governor */ 1883 /* start new governor */
1843 data->governor = policy->governor; 1884 policy->governor = new_policy->governor;
1844 if (!__cpufreq_governor(data, CPUFREQ_GOV_POLICY_INIT)) { 1885 if (!__cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT)) {
1845 if (!__cpufreq_governor(data, CPUFREQ_GOV_START)) { 1886 if (!__cpufreq_governor(policy, CPUFREQ_GOV_START)) {
1846 failed = 0; 1887 failed = 0;
1847 } else { 1888 } else {
1848 unlock_policy_rwsem_write(policy->cpu); 1889 unlock_policy_rwsem_write(new_policy->cpu);
1849 __cpufreq_governor(data, 1890 __cpufreq_governor(policy,
1850 CPUFREQ_GOV_POLICY_EXIT); 1891 CPUFREQ_GOV_POLICY_EXIT);
1851 lock_policy_rwsem_write(policy->cpu); 1892 lock_policy_rwsem_write(new_policy->cpu);
1852 } 1893 }
1853 } 1894 }
1854 1895
1855 if (failed) { 1896 if (failed) {
1856 /* new governor failed, so re-start old one */ 1897 /* new governor failed, so re-start old one */
1857 pr_debug("starting governor %s failed\n", 1898 pr_debug("starting governor %s failed\n",
1858 data->governor->name); 1899 policy->governor->name);
1859 if (old_gov) { 1900 if (old_gov) {
1860 data->governor = old_gov; 1901 policy->governor = old_gov;
1861 __cpufreq_governor(data, 1902 __cpufreq_governor(policy,
1862 CPUFREQ_GOV_POLICY_INIT); 1903 CPUFREQ_GOV_POLICY_INIT);
1863 __cpufreq_governor(data, 1904 __cpufreq_governor(policy,
1864 CPUFREQ_GOV_START); 1905 CPUFREQ_GOV_START);
1865 } 1906 }
1866 ret = -EINVAL; 1907 ret = -EINVAL;
@@ -1869,7 +1910,7 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data,
1869 /* might be a policy change, too, so fall through */ 1910 /* might be a policy change, too, so fall through */
1870 } 1911 }
1871 pr_debug("governor: change or update limits\n"); 1912 pr_debug("governor: change or update limits\n");
1872 __cpufreq_governor(data, CPUFREQ_GOV_LIMITS); 1913 ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
1873 } 1914 }
1874 1915
1875error_out: 1916error_out:
@@ -1885,11 +1926,11 @@ error_out:
1885 */ 1926 */
1886int cpufreq_update_policy(unsigned int cpu) 1927int cpufreq_update_policy(unsigned int cpu)
1887{ 1928{
1888 struct cpufreq_policy *data = cpufreq_cpu_get(cpu); 1929 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1889 struct cpufreq_policy policy; 1930 struct cpufreq_policy new_policy;
1890 int ret; 1931 int ret;
1891 1932
1892 if (!data) { 1933 if (!policy) {
1893 ret = -ENODEV; 1934 ret = -ENODEV;
1894 goto no_policy; 1935 goto no_policy;
1895 } 1936 }
@@ -1900,34 +1941,34 @@ int cpufreq_update_policy(unsigned int cpu)
1900 } 1941 }
1901 1942
1902 pr_debug("updating policy for CPU %u\n", cpu); 1943 pr_debug("updating policy for CPU %u\n", cpu);
1903 memcpy(&policy, data, sizeof(struct cpufreq_policy)); 1944 memcpy(&new_policy, policy, sizeof(*policy));
1904 policy.min = data->user_policy.min; 1945 new_policy.min = policy->user_policy.min;
1905 policy.max = data->user_policy.max; 1946 new_policy.max = policy->user_policy.max;
1906 policy.policy = data->user_policy.policy; 1947 new_policy.policy = policy->user_policy.policy;
1907 policy.governor = data->user_policy.governor; 1948 new_policy.governor = policy->user_policy.governor;
1908 1949
1909 /* 1950 /*
1910 * BIOS might change freq behind our back 1951 * BIOS might change freq behind our back
1911 * -> ask driver for current freq and notify governors about a change 1952 * -> ask driver for current freq and notify governors about a change
1912 */ 1953 */
1913 if (cpufreq_driver->get) { 1954 if (cpufreq_driver->get) {
1914 policy.cur = cpufreq_driver->get(cpu); 1955 new_policy.cur = cpufreq_driver->get(cpu);
1915 if (!data->cur) { 1956 if (!policy->cur) {
1916 pr_debug("Driver did not initialize current freq"); 1957 pr_debug("Driver did not initialize current freq");
1917 data->cur = policy.cur; 1958 policy->cur = new_policy.cur;
1918 } else { 1959 } else {
1919 if (data->cur != policy.cur && cpufreq_driver->target) 1960 if (policy->cur != new_policy.cur && cpufreq_driver->target)
1920 cpufreq_out_of_sync(cpu, data->cur, 1961 cpufreq_out_of_sync(cpu, policy->cur,
1921 policy.cur); 1962 new_policy.cur);
1922 } 1963 }
1923 } 1964 }
1924 1965
1925 ret = __cpufreq_set_policy(data, &policy); 1966 ret = __cpufreq_set_policy(policy, &new_policy);
1926 1967
1927 unlock_policy_rwsem_write(cpu); 1968 unlock_policy_rwsem_write(cpu);
1928 1969
1929fail: 1970fail:
1930 cpufreq_cpu_put(data); 1971 cpufreq_cpu_put(policy);
1931no_policy: 1972no_policy:
1932 return ret; 1973 return ret;
1933} 1974}
@@ -1938,21 +1979,26 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
1938{ 1979{
1939 unsigned int cpu = (unsigned long)hcpu; 1980 unsigned int cpu = (unsigned long)hcpu;
1940 struct device *dev; 1981 struct device *dev;
1982 bool frozen = false;
1941 1983
1942 dev = get_cpu_device(cpu); 1984 dev = get_cpu_device(cpu);
1943 if (dev) { 1985 if (dev) {
1944 switch (action) { 1986
1987 if (action & CPU_TASKS_FROZEN)
1988 frozen = true;
1989
1990 switch (action & ~CPU_TASKS_FROZEN) {
1945 case CPU_ONLINE: 1991 case CPU_ONLINE:
1946 case CPU_ONLINE_FROZEN: 1992 __cpufreq_add_dev(dev, NULL, frozen);
1947 cpufreq_add_dev(dev, NULL); 1993 cpufreq_update_policy(cpu);
1948 break; 1994 break;
1995
1949 case CPU_DOWN_PREPARE: 1996 case CPU_DOWN_PREPARE:
1950 case CPU_DOWN_PREPARE_FROZEN: 1997 __cpufreq_remove_dev(dev, NULL, frozen);
1951 __cpufreq_remove_dev(dev, NULL);
1952 break; 1998 break;
1999
1953 case CPU_DOWN_FAILED: 2000 case CPU_DOWN_FAILED:
1954 case CPU_DOWN_FAILED_FROZEN: 2001 __cpufreq_add_dev(dev, NULL, frozen);
1955 cpufreq_add_dev(dev, NULL);
1956 break; 2002 break;
1957 } 2003 }
1958 } 2004 }
@@ -2059,9 +2105,13 @@ int cpufreq_unregister_driver(struct cpufreq_driver *driver)
2059 subsys_interface_unregister(&cpufreq_interface); 2105 subsys_interface_unregister(&cpufreq_interface);
2060 unregister_hotcpu_notifier(&cpufreq_cpu_notifier); 2106 unregister_hotcpu_notifier(&cpufreq_cpu_notifier);
2061 2107
2108 down_write(&cpufreq_rwsem);
2062 write_lock_irqsave(&cpufreq_driver_lock, flags); 2109 write_lock_irqsave(&cpufreq_driver_lock, flags);
2110
2063 cpufreq_driver = NULL; 2111 cpufreq_driver = NULL;
2112
2064 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 2113 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2114 up_write(&cpufreq_rwsem);
2065 2115
2066 return 0; 2116 return 0;
2067} 2117}
@@ -2074,10 +2124,8 @@ static int __init cpufreq_core_init(void)
2074 if (cpufreq_disabled()) 2124 if (cpufreq_disabled())
2075 return -ENODEV; 2125 return -ENODEV;
2076 2126
2077 for_each_possible_cpu(cpu) { 2127 for_each_possible_cpu(cpu)
2078 per_cpu(cpufreq_policy_cpu, cpu) = -1;
2079 init_rwsem(&per_cpu(cpu_policy_rwsem, cpu)); 2128 init_rwsem(&per_cpu(cpu_policy_rwsem, cpu));
2080 }
2081 2129
2082 cpufreq_global_kobject = kobject_create(); 2130 cpufreq_global_kobject = kobject_create();
2083 BUG_ON(!cpufreq_global_kobject); 2131 BUG_ON(!cpufreq_global_kobject);
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index f97cb3d8c5a2..7f67a75b3c3c 100644
--- a/drivers/cpufreq/cpufreq_conservative.c
+++ b/drivers/cpufreq/cpufreq_conservative.c
@@ -11,19 +11,7 @@
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
12 */ 12 */
13 13
14#include <linux/cpufreq.h>
15#include <linux/init.h>
16#include <linux/kernel.h>
17#include <linux/kernel_stat.h>
18#include <linux/kobject.h>
19#include <linux/module.h>
20#include <linux/mutex.h>
21#include <linux/notifier.h>
22#include <linux/percpu-defs.h>
23#include <linux/slab.h> 14#include <linux/slab.h>
24#include <linux/sysfs.h>
25#include <linux/types.h>
26
27#include "cpufreq_governor.h" 15#include "cpufreq_governor.h"
28 16
29/* Conservative governor macros */ 17/* Conservative governor macros */
@@ -329,7 +317,7 @@ static int cs_init(struct dbs_data *dbs_data)
329{ 317{
330 struct cs_dbs_tuners *tuners; 318 struct cs_dbs_tuners *tuners;
331 319
332 tuners = kzalloc(sizeof(struct cs_dbs_tuners), GFP_KERNEL); 320 tuners = kzalloc(sizeof(*tuners), GFP_KERNEL);
333 if (!tuners) { 321 if (!tuners) {
334 pr_err("%s: kzalloc failed\n", __func__); 322 pr_err("%s: kzalloc failed\n", __func__);
335 return -ENOMEM; 323 return -ENOMEM;
diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
index e59afaa9da23..87427360c77f 100644
--- a/drivers/cpufreq/cpufreq_governor.c
+++ b/drivers/cpufreq/cpufreq_governor.c
@@ -16,15 +16,9 @@
16 16
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 18
19#include <asm/cputime.h>
20#include <linux/cpufreq.h>
21#include <linux/cpumask.h>
22#include <linux/export.h> 19#include <linux/export.h>
23#include <linux/kernel_stat.h> 20#include <linux/kernel_stat.h>
24#include <linux/mutex.h>
25#include <linux/slab.h> 21#include <linux/slab.h>
26#include <linux/types.h>
27#include <linux/workqueue.h>
28 22
29#include "cpufreq_governor.h" 23#include "cpufreq_governor.h"
30 24
@@ -53,7 +47,7 @@ void dbs_check_cpu(struct dbs_data *dbs_data, int cpu)
53 47
54 policy = cdbs->cur_policy; 48 policy = cdbs->cur_policy;
55 49
56 /* Get Absolute Load (in terms of freq for ondemand gov) */ 50 /* Get Absolute Load */
57 for_each_cpu(j, policy->cpus) { 51 for_each_cpu(j, policy->cpus) {
58 struct cpu_dbs_common_info *j_cdbs; 52 struct cpu_dbs_common_info *j_cdbs;
59 u64 cur_wall_time, cur_idle_time; 53 u64 cur_wall_time, cur_idle_time;
@@ -104,14 +98,6 @@ void dbs_check_cpu(struct dbs_data *dbs_data, int cpu)
104 98
105 load = 100 * (wall_time - idle_time) / wall_time; 99 load = 100 * (wall_time - idle_time) / wall_time;
106 100
107 if (dbs_data->cdata->governor == GOV_ONDEMAND) {
108 int freq_avg = __cpufreq_driver_getavg(policy, j);
109 if (freq_avg <= 0)
110 freq_avg = policy->cur;
111
112 load *= freq_avg;
113 }
114
115 if (load > max_load) 101 if (load > max_load)
116 max_load = load; 102 max_load = load;
117 } 103 }
diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
index d5f12b4b11b8..a02d78b25898 100644
--- a/drivers/cpufreq/cpufreq_governor.h
+++ b/drivers/cpufreq/cpufreq_governor.h
@@ -18,10 +18,9 @@
18#define _CPUFREQ_GOVERNOR_H 18#define _CPUFREQ_GOVERNOR_H
19 19
20#include <linux/cpufreq.h> 20#include <linux/cpufreq.h>
21#include <linux/kobject.h> 21#include <linux/kernel_stat.h>
22#include <linux/module.h>
22#include <linux/mutex.h> 23#include <linux/mutex.h>
23#include <linux/workqueue.h>
24#include <linux/sysfs.h>
25 24
26/* 25/*
27 * The polling frequency depends on the capability of the processor. Default 26 * The polling frequency depends on the capability of the processor. Default
@@ -169,7 +168,6 @@ struct od_dbs_tuners {
169 unsigned int sampling_rate; 168 unsigned int sampling_rate;
170 unsigned int sampling_down_factor; 169 unsigned int sampling_down_factor;
171 unsigned int up_threshold; 170 unsigned int up_threshold;
172 unsigned int adj_up_threshold;
173 unsigned int powersave_bias; 171 unsigned int powersave_bias;
174 unsigned int io_is_busy; 172 unsigned int io_is_busy;
175}; 173};
@@ -223,7 +221,7 @@ struct od_ops {
223 void (*powersave_bias_init_cpu)(int cpu); 221 void (*powersave_bias_init_cpu)(int cpu);
224 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy, 222 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
225 unsigned int freq_next, unsigned int relation); 223 unsigned int freq_next, unsigned int relation);
226 void (*freq_increase)(struct cpufreq_policy *p, unsigned int freq); 224 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
227}; 225};
228 226
229struct cs_ops { 227struct cs_ops {
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index c087347d6688..87f3305e80a6 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -12,28 +12,16 @@
12 12
13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 14
15#include <linux/cpufreq.h> 15#include <linux/cpu.h>
16#include <linux/init.h>
17#include <linux/kernel.h>
18#include <linux/kernel_stat.h>
19#include <linux/kobject.h>
20#include <linux/module.h>
21#include <linux/mutex.h>
22#include <linux/percpu-defs.h> 16#include <linux/percpu-defs.h>
23#include <linux/slab.h> 17#include <linux/slab.h>
24#include <linux/sysfs.h>
25#include <linux/tick.h> 18#include <linux/tick.h>
26#include <linux/types.h>
27#include <linux/cpu.h>
28
29#include "cpufreq_governor.h" 19#include "cpufreq_governor.h"
30 20
31/* On-demand governor macros */ 21/* On-demand governor macros */
32#define DEF_FREQUENCY_DOWN_DIFFERENTIAL (10)
33#define DEF_FREQUENCY_UP_THRESHOLD (80) 22#define DEF_FREQUENCY_UP_THRESHOLD (80)
34#define DEF_SAMPLING_DOWN_FACTOR (1) 23#define DEF_SAMPLING_DOWN_FACTOR (1)
35#define MAX_SAMPLING_DOWN_FACTOR (100000) 24#define MAX_SAMPLING_DOWN_FACTOR (100000)
36#define MICRO_FREQUENCY_DOWN_DIFFERENTIAL (3)
37#define MICRO_FREQUENCY_UP_THRESHOLD (95) 25#define MICRO_FREQUENCY_UP_THRESHOLD (95)
38#define MICRO_FREQUENCY_MIN_SAMPLE_RATE (10000) 26#define MICRO_FREQUENCY_MIN_SAMPLE_RATE (10000)
39#define MIN_FREQUENCY_UP_THRESHOLD (11) 27#define MIN_FREQUENCY_UP_THRESHOLD (11)
@@ -144,31 +132,27 @@ static void ondemand_powersave_bias_init(void)
144 } 132 }
145} 133}
146 134
147static void dbs_freq_increase(struct cpufreq_policy *p, unsigned int freq) 135static void dbs_freq_increase(struct cpufreq_policy *policy, unsigned int freq)
148{ 136{
149 struct dbs_data *dbs_data = p->governor_data; 137 struct dbs_data *dbs_data = policy->governor_data;
150 struct od_dbs_tuners *od_tuners = dbs_data->tuners; 138 struct od_dbs_tuners *od_tuners = dbs_data->tuners;
151 139
152 if (od_tuners->powersave_bias) 140 if (od_tuners->powersave_bias)
153 freq = od_ops.powersave_bias_target(p, freq, 141 freq = od_ops.powersave_bias_target(policy, freq,
154 CPUFREQ_RELATION_H); 142 CPUFREQ_RELATION_H);
155 else if (p->cur == p->max) 143 else if (policy->cur == policy->max)
156 return; 144 return;
157 145
158 __cpufreq_driver_target(p, freq, od_tuners->powersave_bias ? 146 __cpufreq_driver_target(policy, freq, od_tuners->powersave_bias ?
159 CPUFREQ_RELATION_L : CPUFREQ_RELATION_H); 147 CPUFREQ_RELATION_L : CPUFREQ_RELATION_H);
160} 148}
161 149
162/* 150/*
163 * Every sampling_rate, we check, if current idle time is less than 20% 151 * Every sampling_rate, we check, if current idle time is less than 20%
164 * (default), then we try to increase frequency. Every sampling_rate, we look 152 * (default), then we try to increase frequency. Else, we adjust the frequency
165 * for the lowest frequency which can sustain the load while keeping idle time 153 * proportional to load.
166 * over 30%. If such a frequency exist, we try to decrease to this frequency.
167 *
168 * Any frequency increase takes it to the maximum frequency. Frequency reduction
169 * happens at minimum steps of 5% (default) of current frequency
170 */ 154 */
171static void od_check_cpu(int cpu, unsigned int load_freq) 155static void od_check_cpu(int cpu, unsigned int load)
172{ 156{
173 struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, cpu); 157 struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, cpu);
174 struct cpufreq_policy *policy = dbs_info->cdbs.cur_policy; 158 struct cpufreq_policy *policy = dbs_info->cdbs.cur_policy;
@@ -178,29 +162,17 @@ static void od_check_cpu(int cpu, unsigned int load_freq)
178 dbs_info->freq_lo = 0; 162 dbs_info->freq_lo = 0;
179 163
180 /* Check for frequency increase */ 164 /* Check for frequency increase */
181 if (load_freq > od_tuners->up_threshold * policy->cur) { 165 if (load > od_tuners->up_threshold) {
182 /* If switching to max speed, apply sampling_down_factor */ 166 /* If switching to max speed, apply sampling_down_factor */
183 if (policy->cur < policy->max) 167 if (policy->cur < policy->max)
184 dbs_info->rate_mult = 168 dbs_info->rate_mult =
185 od_tuners->sampling_down_factor; 169 od_tuners->sampling_down_factor;
186 dbs_freq_increase(policy, policy->max); 170 dbs_freq_increase(policy, policy->max);
187 return; 171 return;
188 } 172 } else {
189 173 /* Calculate the next frequency proportional to load */
190 /* Check for frequency decrease */
191 /* if we cannot reduce the frequency anymore, break out early */
192 if (policy->cur == policy->min)
193 return;
194
195 /*
196 * The optimal frequency is the frequency that is the lowest that can
197 * support the current CPU usage without triggering the up policy. To be
198 * safe, we focus 10 points under the threshold.
199 */
200 if (load_freq < od_tuners->adj_up_threshold
201 * policy->cur) {
202 unsigned int freq_next; 174 unsigned int freq_next;
203 freq_next = load_freq / od_tuners->adj_up_threshold; 175 freq_next = load * policy->cpuinfo.max_freq / 100;
204 176
205 /* No longer fully busy, reset rate_mult */ 177 /* No longer fully busy, reset rate_mult */
206 dbs_info->rate_mult = 1; 178 dbs_info->rate_mult = 1;
@@ -374,9 +346,6 @@ static ssize_t store_up_threshold(struct dbs_data *dbs_data, const char *buf,
374 input < MIN_FREQUENCY_UP_THRESHOLD) { 346 input < MIN_FREQUENCY_UP_THRESHOLD) {
375 return -EINVAL; 347 return -EINVAL;
376 } 348 }
377 /* Calculate the new adj_up_threshold */
378 od_tuners->adj_up_threshold += input;
379 od_tuners->adj_up_threshold -= od_tuners->up_threshold;
380 349
381 od_tuners->up_threshold = input; 350 od_tuners->up_threshold = input;
382 return count; 351 return count;
@@ -513,7 +482,7 @@ static int od_init(struct dbs_data *dbs_data)
513 u64 idle_time; 482 u64 idle_time;
514 int cpu; 483 int cpu;
515 484
516 tuners = kzalloc(sizeof(struct od_dbs_tuners), GFP_KERNEL); 485 tuners = kzalloc(sizeof(*tuners), GFP_KERNEL);
517 if (!tuners) { 486 if (!tuners) {
518 pr_err("%s: kzalloc failed\n", __func__); 487 pr_err("%s: kzalloc failed\n", __func__);
519 return -ENOMEM; 488 return -ENOMEM;
@@ -525,8 +494,6 @@ static int od_init(struct dbs_data *dbs_data)
525 if (idle_time != -1ULL) { 494 if (idle_time != -1ULL) {
526 /* Idle micro accounting is supported. Use finer thresholds */ 495 /* Idle micro accounting is supported. Use finer thresholds */
527 tuners->up_threshold = MICRO_FREQUENCY_UP_THRESHOLD; 496 tuners->up_threshold = MICRO_FREQUENCY_UP_THRESHOLD;
528 tuners->adj_up_threshold = MICRO_FREQUENCY_UP_THRESHOLD -
529 MICRO_FREQUENCY_DOWN_DIFFERENTIAL;
530 /* 497 /*
531 * In nohz/micro accounting case we set the minimum frequency 498 * In nohz/micro accounting case we set the minimum frequency
532 * not depending on HZ, but fixed (very low). The deferred 499 * not depending on HZ, but fixed (very low). The deferred
@@ -535,8 +502,6 @@ static int od_init(struct dbs_data *dbs_data)
535 dbs_data->min_sampling_rate = MICRO_FREQUENCY_MIN_SAMPLE_RATE; 502 dbs_data->min_sampling_rate = MICRO_FREQUENCY_MIN_SAMPLE_RATE;
536 } else { 503 } else {
537 tuners->up_threshold = DEF_FREQUENCY_UP_THRESHOLD; 504 tuners->up_threshold = DEF_FREQUENCY_UP_THRESHOLD;
538 tuners->adj_up_threshold = DEF_FREQUENCY_UP_THRESHOLD -
539 DEF_FREQUENCY_DOWN_DIFFERENTIAL;
540 505
541 /* For correct statistics, we need 10 ticks for each measure */ 506 /* For correct statistics, we need 10 ticks for each measure */
542 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO * 507 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
diff --git a/drivers/cpufreq/cpufreq_performance.c b/drivers/cpufreq/cpufreq_performance.c
index 9fef7d6e4e6a..cf117deb39b1 100644
--- a/drivers/cpufreq/cpufreq_performance.c
+++ b/drivers/cpufreq/cpufreq_performance.c
@@ -12,10 +12,9 @@
12 12
13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/cpufreq.h> 15#include <linux/cpufreq.h>
18#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/module.h>
19 18
20static int cpufreq_governor_performance(struct cpufreq_policy *policy, 19static int cpufreq_governor_performance(struct cpufreq_policy *policy,
21 unsigned int event) 20 unsigned int event)
diff --git a/drivers/cpufreq/cpufreq_powersave.c b/drivers/cpufreq/cpufreq_powersave.c
index 32109a14f5dc..e3b874c235ea 100644
--- a/drivers/cpufreq/cpufreq_powersave.c
+++ b/drivers/cpufreq/cpufreq_powersave.c
@@ -12,10 +12,9 @@
12 12
13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/cpufreq.h> 15#include <linux/cpufreq.h>
18#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/module.h>
19 18
20static int cpufreq_governor_powersave(struct cpufreq_policy *policy, 19static int cpufreq_governor_powersave(struct cpufreq_policy *policy,
21 unsigned int event) 20 unsigned int event)
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index d37568c5ca9c..04452f026ed0 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -9,17 +9,10 @@
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11 11
12#include <linux/kernel.h>
13#include <linux/slab.h>
14#include <linux/cpu.h> 12#include <linux/cpu.h>
15#include <linux/sysfs.h>
16#include <linux/cpufreq.h> 13#include <linux/cpufreq.h>
17#include <linux/module.h> 14#include <linux/module.h>
18#include <linux/jiffies.h> 15#include <linux/slab.h>
19#include <linux/percpu.h>
20#include <linux/kobject.h>
21#include <linux/spinlock.h>
22#include <linux/notifier.h>
23#include <asm/cputime.h> 16#include <asm/cputime.h>
24 17
25static spinlock_t cpufreq_stats_lock; 18static spinlock_t cpufreq_stats_lock;
@@ -200,22 +193,22 @@ static int cpufreq_stats_create_table(struct cpufreq_policy *policy,
200{ 193{
201 unsigned int i, j, count = 0, ret = 0; 194 unsigned int i, j, count = 0, ret = 0;
202 struct cpufreq_stats *stat; 195 struct cpufreq_stats *stat;
203 struct cpufreq_policy *data; 196 struct cpufreq_policy *current_policy;
204 unsigned int alloc_size; 197 unsigned int alloc_size;
205 unsigned int cpu = policy->cpu; 198 unsigned int cpu = policy->cpu;
206 if (per_cpu(cpufreq_stats_table, cpu)) 199 if (per_cpu(cpufreq_stats_table, cpu))
207 return -EBUSY; 200 return -EBUSY;
208 stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL); 201 stat = kzalloc(sizeof(*stat), GFP_KERNEL);
209 if ((stat) == NULL) 202 if ((stat) == NULL)
210 return -ENOMEM; 203 return -ENOMEM;
211 204
212 data = cpufreq_cpu_get(cpu); 205 current_policy = cpufreq_cpu_get(cpu);
213 if (data == NULL) { 206 if (current_policy == NULL) {
214 ret = -EINVAL; 207 ret = -EINVAL;
215 goto error_get_fail; 208 goto error_get_fail;
216 } 209 }
217 210
218 ret = sysfs_create_group(&data->kobj, &stats_attr_group); 211 ret = sysfs_create_group(&current_policy->kobj, &stats_attr_group);
219 if (ret) 212 if (ret)
220 goto error_out; 213 goto error_out;
221 214
@@ -258,10 +251,10 @@ static int cpufreq_stats_create_table(struct cpufreq_policy *policy,
258 stat->last_time = get_jiffies_64(); 251 stat->last_time = get_jiffies_64();
259 stat->last_index = freq_table_get_index(stat, policy->cur); 252 stat->last_index = freq_table_get_index(stat, policy->cur);
260 spin_unlock(&cpufreq_stats_lock); 253 spin_unlock(&cpufreq_stats_lock);
261 cpufreq_cpu_put(data); 254 cpufreq_cpu_put(current_policy);
262 return 0; 255 return 0;
263error_out: 256error_out:
264 cpufreq_cpu_put(data); 257 cpufreq_cpu_put(current_policy);
265error_get_fail: 258error_get_fail:
266 kfree(stat); 259 kfree(stat);
267 per_cpu(cpufreq_stats_table, cpu) = NULL; 260 per_cpu(cpufreq_stats_table, cpu) = NULL;
@@ -348,16 +341,10 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
348 unsigned int cpu = (unsigned long)hcpu; 341 unsigned int cpu = (unsigned long)hcpu;
349 342
350 switch (action) { 343 switch (action) {
351 case CPU_ONLINE:
352 case CPU_ONLINE_FROZEN:
353 cpufreq_update_policy(cpu);
354 break;
355 case CPU_DOWN_PREPARE: 344 case CPU_DOWN_PREPARE:
356 case CPU_DOWN_PREPARE_FROZEN:
357 cpufreq_stats_free_sysfs(cpu); 345 cpufreq_stats_free_sysfs(cpu);
358 break; 346 break;
359 case CPU_DEAD: 347 case CPU_DEAD:
360 case CPU_DEAD_FROZEN:
361 cpufreq_stats_free_table(cpu); 348 cpufreq_stats_free_table(cpu);
362 break; 349 break;
363 } 350 }
@@ -390,8 +377,6 @@ static int __init cpufreq_stats_init(void)
390 return ret; 377 return ret;
391 378
392 register_hotcpu_notifier(&cpufreq_stat_cpu_notifier); 379 register_hotcpu_notifier(&cpufreq_stat_cpu_notifier);
393 for_each_online_cpu(cpu)
394 cpufreq_update_policy(cpu);
395 380
396 ret = cpufreq_register_notifier(&notifier_trans_block, 381 ret = cpufreq_register_notifier(&notifier_trans_block,
397 CPUFREQ_TRANSITION_NOTIFIER); 382 CPUFREQ_TRANSITION_NOTIFIER);
diff --git a/drivers/cpufreq/cris-artpec3-cpufreq.c b/drivers/cpufreq/cris-artpec3-cpufreq.c
index ee142c490575..cb8276dd19ca 100644
--- a/drivers/cpufreq/cris-artpec3-cpufreq.c
+++ b/drivers/cpufreq/cris-artpec3-cpufreq.c
@@ -111,7 +111,6 @@ static struct cpufreq_driver cris_freq_driver = {
111 .init = cris_freq_cpu_init, 111 .init = cris_freq_cpu_init,
112 .exit = cris_freq_cpu_exit, 112 .exit = cris_freq_cpu_exit,
113 .name = "cris_freq", 113 .name = "cris_freq",
114 .owner = THIS_MODULE,
115 .attr = cris_freq_attr, 114 .attr = cris_freq_attr,
116}; 115};
117 116
diff --git a/drivers/cpufreq/cris-etraxfs-cpufreq.c b/drivers/cpufreq/cris-etraxfs-cpufreq.c
index 12952235d5db..72328f77dc53 100644
--- a/drivers/cpufreq/cris-etraxfs-cpufreq.c
+++ b/drivers/cpufreq/cris-etraxfs-cpufreq.c
@@ -108,7 +108,6 @@ static struct cpufreq_driver cris_freq_driver = {
108 .init = cris_freq_cpu_init, 108 .init = cris_freq_cpu_init,
109 .exit = cris_freq_cpu_exit, 109 .exit = cris_freq_cpu_exit,
110 .name = "cris_freq", 110 .name = "cris_freq",
111 .owner = THIS_MODULE,
112 .attr = cris_freq_attr, 111 .attr = cris_freq_attr,
113}; 112};
114 113
diff --git a/drivers/cpufreq/e_powersaver.c b/drivers/cpufreq/e_powersaver.c
index a60efaeb4cf8..09f64cc83019 100644
--- a/drivers/cpufreq/e_powersaver.c
+++ b/drivers/cpufreq/e_powersaver.c
@@ -54,7 +54,7 @@ static struct acpi_processor_performance *eps_acpi_cpu_perf;
54/* Minimum necessary to get acpi_processor_get_bios_limit() working */ 54/* Minimum necessary to get acpi_processor_get_bios_limit() working */
55static int eps_acpi_init(void) 55static int eps_acpi_init(void)
56{ 56{
57 eps_acpi_cpu_perf = kzalloc(sizeof(struct acpi_processor_performance), 57 eps_acpi_cpu_perf = kzalloc(sizeof(*eps_acpi_cpu_perf),
58 GFP_KERNEL); 58 GFP_KERNEL);
59 if (!eps_acpi_cpu_perf) 59 if (!eps_acpi_cpu_perf)
60 return -ENOMEM; 60 return -ENOMEM;
@@ -366,7 +366,7 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
366 states = 2; 366 states = 2;
367 367
368 /* Allocate private data and frequency table for current cpu */ 368 /* Allocate private data and frequency table for current cpu */
369 centaur = kzalloc(sizeof(struct eps_cpu_data) 369 centaur = kzalloc(sizeof(*centaur)
370 + (states + 1) * sizeof(struct cpufreq_frequency_table), 370 + (states + 1) * sizeof(struct cpufreq_frequency_table),
371 GFP_KERNEL); 371 GFP_KERNEL);
372 if (!centaur) 372 if (!centaur)
@@ -436,7 +436,6 @@ static struct cpufreq_driver eps_driver = {
436 .exit = eps_cpu_exit, 436 .exit = eps_cpu_exit,
437 .get = eps_get, 437 .get = eps_get,
438 .name = "e_powersaver", 438 .name = "e_powersaver",
439 .owner = THIS_MODULE,
440 .attr = eps_attr, 439 .attr = eps_attr,
441}; 440};
442 441
diff --git a/drivers/cpufreq/elanfreq.c b/drivers/cpufreq/elanfreq.c
index 658d860344b0..823a400d98fd 100644
--- a/drivers/cpufreq/elanfreq.c
+++ b/drivers/cpufreq/elanfreq.c
@@ -274,7 +274,6 @@ static struct cpufreq_driver elanfreq_driver = {
274 .init = elanfreq_cpu_init, 274 .init = elanfreq_cpu_init,
275 .exit = elanfreq_cpu_exit, 275 .exit = elanfreq_cpu_exit,
276 .name = "elanfreq", 276 .name = "elanfreq",
277 .owner = THIS_MODULE,
278 .attr = elanfreq_attr, 277 .attr = elanfreq_attr,
279}; 278};
280 279
diff --git a/drivers/cpufreq/exynos-cpufreq.c b/drivers/cpufreq/exynos-cpufreq.c
index 0d32f02ef4d6..0fac34439e31 100644
--- a/drivers/cpufreq/exynos-cpufreq.c
+++ b/drivers/cpufreq/exynos-cpufreq.c
@@ -289,7 +289,7 @@ static int __init exynos_cpufreq_init(void)
289{ 289{
290 int ret = -EINVAL; 290 int ret = -EINVAL;
291 291
292 exynos_info = kzalloc(sizeof(struct exynos_dvfs_info), GFP_KERNEL); 292 exynos_info = kzalloc(sizeof(*exynos_info), GFP_KERNEL);
293 if (!exynos_info) 293 if (!exynos_info)
294 return -ENOMEM; 294 return -ENOMEM;
295 295
@@ -332,7 +332,6 @@ err_cpufreq:
332 regulator_put(arm_regulator); 332 regulator_put(arm_regulator);
333err_vdd_arm: 333err_vdd_arm:
334 kfree(exynos_info); 334 kfree(exynos_info);
335 pr_debug("%s: failed initialization\n", __func__);
336 return -EINVAL; 335 return -EINVAL;
337} 336}
338late_initcall(exynos_cpufreq_init); 337late_initcall(exynos_cpufreq_init);
diff --git a/drivers/cpufreq/exynos-cpufreq.h b/drivers/cpufreq/exynos-cpufreq.h
index 92b852ee5ddc..7f25cee8cec2 100644
--- a/drivers/cpufreq/exynos-cpufreq.h
+++ b/drivers/cpufreq/exynos-cpufreq.h
@@ -43,6 +43,27 @@ struct exynos_dvfs_info {
43 bool (*need_apll_change)(unsigned int, unsigned int); 43 bool (*need_apll_change)(unsigned int, unsigned int);
44}; 44};
45 45
46#ifdef CONFIG_ARM_EXYNOS4210_CPUFREQ
46extern int exynos4210_cpufreq_init(struct exynos_dvfs_info *); 47extern int exynos4210_cpufreq_init(struct exynos_dvfs_info *);
48#else
49static inline int exynos4210_cpufreq_init(struct exynos_dvfs_info *info)
50{
51 return -EOPNOTSUPP;
52}
53#endif
54#ifdef CONFIG_ARM_EXYNOS4X12_CPUFREQ
47extern int exynos4x12_cpufreq_init(struct exynos_dvfs_info *); 55extern int exynos4x12_cpufreq_init(struct exynos_dvfs_info *);
56#else
57static inline int exynos4x12_cpufreq_init(struct exynos_dvfs_info *info)
58{
59 return -EOPNOTSUPP;
60}
61#endif
62#ifdef CONFIG_ARM_EXYNOS5250_CPUFREQ
48extern int exynos5250_cpufreq_init(struct exynos_dvfs_info *); 63extern int exynos5250_cpufreq_init(struct exynos_dvfs_info *);
64#else
65static inline int exynos5250_cpufreq_init(struct exynos_dvfs_info *info)
66{
67 return -EOPNOTSUPP;
68}
69#endif
diff --git a/drivers/cpufreq/exynos5440-cpufreq.c b/drivers/cpufreq/exynos5440-cpufreq.c
index 0c74018eda47..d514c152fd1a 100644
--- a/drivers/cpufreq/exynos5440-cpufreq.c
+++ b/drivers/cpufreq/exynos5440-cpufreq.c
@@ -238,6 +238,9 @@ static int exynos_target(struct cpufreq_policy *policy,
238 freqs.old = dvfs_info->cur_frequency; 238 freqs.old = dvfs_info->cur_frequency;
239 freqs.new = freq_table[index].frequency; 239 freqs.new = freq_table[index].frequency;
240 240
241 if (freqs.old == freqs.new)
242 goto out;
243
241 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE); 244 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
242 245
243 /* Set the target frequency in all C0_3_PSTATE register */ 246 /* Set the target frequency in all C0_3_PSTATE register */
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
index f0d87412cc91..f111454a7aea 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -11,10 +11,8 @@
11 11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/cpufreq.h> 14#include <linux/cpufreq.h>
15#include <linux/module.h>
18 16
19/********************************************************************* 17/*********************************************************************
20 * FREQUENCY TABLE HELPERS * 18 * FREQUENCY TABLE HELPERS *
diff --git a/drivers/cpufreq/gx-suspmod.c b/drivers/cpufreq/gx-suspmod.c
index 3dfc99b9ca86..70442c7b5e71 100644
--- a/drivers/cpufreq/gx-suspmod.c
+++ b/drivers/cpufreq/gx-suspmod.c
@@ -183,7 +183,7 @@ static void gx_write_byte(int reg, int value)
183 * gx_detect_chipset: 183 * gx_detect_chipset:
184 * 184 *
185 **/ 185 **/
186static __init struct pci_dev *gx_detect_chipset(void) 186static struct pci_dev * __init gx_detect_chipset(void)
187{ 187{
188 struct pci_dev *gx_pci = NULL; 188 struct pci_dev *gx_pci = NULL;
189 189
@@ -446,7 +446,6 @@ static struct cpufreq_driver gx_suspmod_driver = {
446 .target = cpufreq_gx_target, 446 .target = cpufreq_gx_target,
447 .init = cpufreq_gx_cpu_init, 447 .init = cpufreq_gx_cpu_init,
448 .name = "gx-suspmod", 448 .name = "gx-suspmod",
449 .owner = THIS_MODULE,
450}; 449};
451 450
452static int __init cpufreq_gx_init(void) 451static int __init cpufreq_gx_init(void)
@@ -466,7 +465,7 @@ static int __init cpufreq_gx_init(void)
466 465
467 pr_debug("geode suspend modulation available.\n"); 466 pr_debug("geode suspend modulation available.\n");
468 467
469 params = kzalloc(sizeof(struct gxfreq_params), GFP_KERNEL); 468 params = kzalloc(sizeof(*params), GFP_KERNEL);
470 if (params == NULL) 469 if (params == NULL)
471 return -ENOMEM; 470 return -ENOMEM;
472 471
diff --git a/drivers/cpufreq/ia64-acpi-cpufreq.c b/drivers/cpufreq/ia64-acpi-cpufreq.c
index 573c14ea802d..3e14f0317175 100644
--- a/drivers/cpufreq/ia64-acpi-cpufreq.c
+++ b/drivers/cpufreq/ia64-acpi-cpufreq.c
@@ -274,7 +274,7 @@ acpi_cpufreq_cpu_init (
274 274
275 pr_debug("acpi_cpufreq_cpu_init\n"); 275 pr_debug("acpi_cpufreq_cpu_init\n");
276 276
277 data = kzalloc(sizeof(struct cpufreq_acpi_io), GFP_KERNEL); 277 data = kzalloc(sizeof(*data), GFP_KERNEL);
278 if (!data) 278 if (!data)
279 return (-ENOMEM); 279 return (-ENOMEM);
280 280
@@ -304,7 +304,7 @@ acpi_cpufreq_cpu_init (
304 } 304 }
305 305
306 /* alloc freq_table */ 306 /* alloc freq_table */
307 data->freq_table = kmalloc(sizeof(struct cpufreq_frequency_table) * 307 data->freq_table = kmalloc(sizeof(*data->freq_table) *
308 (data->acpi_data.state_count + 1), 308 (data->acpi_data.state_count + 1),
309 GFP_KERNEL); 309 GFP_KERNEL);
310 if (!data->freq_table) { 310 if (!data->freq_table) {
@@ -409,7 +409,6 @@ static struct cpufreq_driver acpi_cpufreq_driver = {
409 .init = acpi_cpufreq_cpu_init, 409 .init = acpi_cpufreq_cpu_init,
410 .exit = acpi_cpufreq_cpu_exit, 410 .exit = acpi_cpufreq_cpu_exit,
411 .name = "acpi-cpufreq", 411 .name = "acpi-cpufreq",
412 .owner = THIS_MODULE,
413 .attr = acpi_cpufreq_attr, 412 .attr = acpi_cpufreq_attr,
414}; 413};
415 414
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 7cde885011ed..6efd96c196b2 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -665,7 +665,6 @@ static struct cpufreq_driver intel_pstate_driver = {
665 .init = intel_pstate_cpu_init, 665 .init = intel_pstate_cpu_init,
666 .exit = intel_pstate_cpu_exit, 666 .exit = intel_pstate_cpu_exit,
667 .name = "intel_pstate", 667 .name = "intel_pstate",
668 .owner = THIS_MODULE,
669}; 668};
670 669
671static int __initdata no_load; 670static int __initdata no_load;
diff --git a/drivers/cpufreq/kirkwood-cpufreq.c b/drivers/cpufreq/kirkwood-cpufreq.c
index c233ea617366..45e4d7fc261d 100644
--- a/drivers/cpufreq/kirkwood-cpufreq.c
+++ b/drivers/cpufreq/kirkwood-cpufreq.c
@@ -158,7 +158,6 @@ static struct cpufreq_driver kirkwood_cpufreq_driver = {
158 .init = kirkwood_cpufreq_cpu_init, 158 .init = kirkwood_cpufreq_cpu_init,
159 .exit = kirkwood_cpufreq_cpu_exit, 159 .exit = kirkwood_cpufreq_cpu_exit,
160 .name = "kirkwood-cpufreq", 160 .name = "kirkwood-cpufreq",
161 .owner = THIS_MODULE,
162 .attr = kirkwood_cpufreq_attr, 161 .attr = kirkwood_cpufreq_attr,
163}; 162};
164 163
diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
index 8c49261df57d..4ada1cccb052 100644
--- a/drivers/cpufreq/longhaul.c
+++ b/drivers/cpufreq/longhaul.c
@@ -948,7 +948,6 @@ static struct cpufreq_driver longhaul_driver = {
948 .init = longhaul_cpu_init, 948 .init = longhaul_cpu_init,
949 .exit = longhaul_cpu_exit, 949 .exit = longhaul_cpu_exit,
950 .name = "longhaul", 950 .name = "longhaul",
951 .owner = THIS_MODULE,
952 .attr = longhaul_attr, 951 .attr = longhaul_attr,
953}; 952};
954 953
diff --git a/drivers/cpufreq/longrun.c b/drivers/cpufreq/longrun.c
index 0fe041d1f77f..5aa031612d53 100644
--- a/drivers/cpufreq/longrun.c
+++ b/drivers/cpufreq/longrun.c
@@ -286,7 +286,6 @@ static struct cpufreq_driver longrun_driver = {
286 .get = longrun_get, 286 .get = longrun_get,
287 .init = longrun_cpu_init, 287 .init = longrun_cpu_init,
288 .name = "longrun", 288 .name = "longrun",
289 .owner = THIS_MODULE,
290}; 289};
291 290
292static const struct x86_cpu_id longrun_ids[] = { 291static const struct x86_cpu_id longrun_ids[] = {
diff --git a/drivers/cpufreq/loongson2_cpufreq.c b/drivers/cpufreq/loongson2_cpufreq.c
index 9536852c504a..7bc3c44d34e2 100644
--- a/drivers/cpufreq/loongson2_cpufreq.c
+++ b/drivers/cpufreq/loongson2_cpufreq.c
@@ -158,7 +158,6 @@ static struct freq_attr *loongson2_table_attr[] = {
158}; 158};
159 159
160static struct cpufreq_driver loongson2_cpufreq_driver = { 160static struct cpufreq_driver loongson2_cpufreq_driver = {
161 .owner = THIS_MODULE,
162 .name = "loongson2", 161 .name = "loongson2",
163 .init = loongson2_cpufreq_cpu_init, 162 .init = loongson2_cpufreq_cpu_init,
164 .verify = loongson2_cpufreq_verify, 163 .verify = loongson2_cpufreq_verify,
diff --git a/drivers/cpufreq/maple-cpufreq.c b/drivers/cpufreq/maple-cpufreq.c
index cdd62915efaf..41c601f4631e 100644
--- a/drivers/cpufreq/maple-cpufreq.c
+++ b/drivers/cpufreq/maple-cpufreq.c
@@ -190,7 +190,6 @@ static int maple_cpufreq_cpu_init(struct cpufreq_policy *policy)
190 190
191static struct cpufreq_driver maple_cpufreq_driver = { 191static struct cpufreq_driver maple_cpufreq_driver = {
192 .name = "maple", 192 .name = "maple",
193 .owner = THIS_MODULE,
194 .flags = CPUFREQ_CONST_LOOPS, 193 .flags = CPUFREQ_CONST_LOOPS,
195 .init = maple_cpufreq_cpu_init, 194 .init = maple_cpufreq_cpu_init,
196 .verify = maple_cpufreq_verify, 195 .verify = maple_cpufreq_verify,
diff --git a/drivers/cpufreq/mperf.c b/drivers/cpufreq/mperf.c
deleted file mode 100644
index 911e193018ae..000000000000
--- a/drivers/cpufreq/mperf.c
+++ /dev/null
@@ -1,51 +0,0 @@
1#include <linux/kernel.h>
2#include <linux/smp.h>
3#include <linux/module.h>
4#include <linux/init.h>
5#include <linux/cpufreq.h>
6#include <linux/slab.h>
7
8#include "mperf.h"
9
10static DEFINE_PER_CPU(struct aperfmperf, acfreq_old_perf);
11
12/* Called via smp_call_function_single(), on the target CPU */
13static void read_measured_perf_ctrs(void *_cur)
14{
15 struct aperfmperf *am = _cur;
16
17 get_aperfmperf(am);
18}
19
20/*
21 * Return the measured active (C0) frequency on this CPU since last call
22 * to this function.
23 * Input: cpu number
24 * Return: Average CPU frequency in terms of max frequency (zero on error)
25 *
26 * We use IA32_MPERF and IA32_APERF MSRs to get the measured performance
27 * over a period of time, while CPU is in C0 state.
28 * IA32_MPERF counts at the rate of max advertised frequency
29 * IA32_APERF counts at the rate of actual CPU frequency
30 * Only IA32_APERF/IA32_MPERF ratio is architecturally defined and
31 * no meaning should be associated with absolute values of these MSRs.
32 */
33unsigned int cpufreq_get_measured_perf(struct cpufreq_policy *policy,
34 unsigned int cpu)
35{
36 struct aperfmperf perf;
37 unsigned long ratio;
38 unsigned int retval;
39
40 if (smp_call_function_single(cpu, read_measured_perf_ctrs, &perf, 1))
41 return 0;
42
43 ratio = calc_aperfmperf_ratio(&per_cpu(acfreq_old_perf, cpu), &perf);
44 per_cpu(acfreq_old_perf, cpu) = perf;
45
46 retval = (policy->cpuinfo.max_freq * ratio) >> APERFMPERF_SHIFT;
47
48 return retval;
49}
50EXPORT_SYMBOL_GPL(cpufreq_get_measured_perf);
51MODULE_LICENSE("GPL");
diff --git a/drivers/cpufreq/mperf.h b/drivers/cpufreq/mperf.h
deleted file mode 100644
index 5dbf2950dc22..000000000000
--- a/drivers/cpufreq/mperf.h
+++ /dev/null
@@ -1,9 +0,0 @@
1/*
2 * (c) 2010 Advanced Micro Devices, Inc.
3 * Your use of this code is subject to the terms and conditions of the
4 * GNU general public license version 2. See "COPYING" or
5 * http://www.gnu.org/licenses/gpl.html
6 */
7
8unsigned int cpufreq_get_measured_perf(struct cpufreq_policy *policy,
9 unsigned int cpu);
diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
index 9ee78170ff86..2f0a2a65c37f 100644
--- a/drivers/cpufreq/p4-clockmod.c
+++ b/drivers/cpufreq/p4-clockmod.c
@@ -279,7 +279,6 @@ static struct cpufreq_driver p4clockmod_driver = {
279 .exit = cpufreq_p4_cpu_exit, 279 .exit = cpufreq_p4_cpu_exit,
280 .get = cpufreq_p4_get, 280 .get = cpufreq_p4_get,
281 .name = "p4-clockmod", 281 .name = "p4-clockmod",
282 .owner = THIS_MODULE,
283 .attr = p4clockmod_attr, 282 .attr = p4clockmod_attr,
284}; 283};
285 284
diff --git a/drivers/cpufreq/pasemi-cpufreq.c b/drivers/cpufreq/pasemi-cpufreq.c
index b704da404067..534e43a60d1f 100644
--- a/drivers/cpufreq/pasemi-cpufreq.c
+++ b/drivers/cpufreq/pasemi-cpufreq.c
@@ -297,7 +297,6 @@ static int pas_cpufreq_target(struct cpufreq_policy *policy,
297 297
298static struct cpufreq_driver pas_cpufreq_driver = { 298static struct cpufreq_driver pas_cpufreq_driver = {
299 .name = "pas-cpufreq", 299 .name = "pas-cpufreq",
300 .owner = THIS_MODULE,
301 .flags = CPUFREQ_CONST_LOOPS, 300 .flags = CPUFREQ_CONST_LOOPS,
302 .init = pas_cpufreq_cpu_init, 301 .init = pas_cpufreq_cpu_init,
303 .exit = pas_cpufreq_cpu_exit, 302 .exit = pas_cpufreq_cpu_exit,
diff --git a/drivers/cpufreq/pcc-cpufreq.c b/drivers/cpufreq/pcc-cpufreq.c
index 1581fcc4cf4a..d81c4e5ea0ad 100644
--- a/drivers/cpufreq/pcc-cpufreq.c
+++ b/drivers/cpufreq/pcc-cpufreq.c
@@ -587,7 +587,6 @@ static struct cpufreq_driver pcc_cpufreq_driver = {
587 .init = pcc_cpufreq_cpu_init, 587 .init = pcc_cpufreq_cpu_init,
588 .exit = pcc_cpufreq_cpu_exit, 588 .exit = pcc_cpufreq_cpu_exit,
589 .name = "pcc-cpufreq", 589 .name = "pcc-cpufreq",
590 .owner = THIS_MODULE,
591}; 590};
592 591
593static int __init pcc_cpufreq_init(void) 592static int __init pcc_cpufreq_init(void)
diff --git a/drivers/cpufreq/pmac32-cpufreq.c b/drivers/cpufreq/pmac32-cpufreq.c
index 3104fad82480..38cdc63c38da 100644
--- a/drivers/cpufreq/pmac32-cpufreq.c
+++ b/drivers/cpufreq/pmac32-cpufreq.c
@@ -477,7 +477,6 @@ static struct cpufreq_driver pmac_cpufreq_driver = {
477 .flags = CPUFREQ_PM_NO_WARN, 477 .flags = CPUFREQ_PM_NO_WARN,
478 .attr = pmac_cpu_freqs_attr, 478 .attr = pmac_cpu_freqs_attr,
479 .name = "powermac", 479 .name = "powermac",
480 .owner = THIS_MODULE,
481}; 480};
482 481
483 482
diff --git a/drivers/cpufreq/pmac64-cpufreq.c b/drivers/cpufreq/pmac64-cpufreq.c
index 7ba423431cfe..b6850d97f0d5 100644
--- a/drivers/cpufreq/pmac64-cpufreq.c
+++ b/drivers/cpufreq/pmac64-cpufreq.c
@@ -371,7 +371,6 @@ static int g5_cpufreq_cpu_init(struct cpufreq_policy *policy)
371 371
372static struct cpufreq_driver g5_cpufreq_driver = { 372static struct cpufreq_driver g5_cpufreq_driver = {
373 .name = "powermac", 373 .name = "powermac",
374 .owner = THIS_MODULE,
375 .flags = CPUFREQ_CONST_LOOPS, 374 .flags = CPUFREQ_CONST_LOOPS,
376 .init = g5_cpufreq_cpu_init, 375 .init = g5_cpufreq_cpu_init,
377 .verify = g5_cpufreq_verify, 376 .verify = g5_cpufreq_verify,
@@ -447,9 +446,8 @@ static int __init g5_neo2_cpufreq_init(struct device_node *cpus)
447 if (!shdr) 446 if (!shdr)
448 goto bail_noprops; 447 goto bail_noprops;
449 g5_fvt_table = (struct smu_sdbp_fvt *)&shdr[1]; 448 g5_fvt_table = (struct smu_sdbp_fvt *)&shdr[1];
450 ssize = (shdr->len * sizeof(u32)) - 449 ssize = (shdr->len * sizeof(u32)) - sizeof(*shdr);
451 sizeof(struct smu_sdbp_header); 450 g5_fvt_count = ssize / sizeof(*g5_fvt_table);
452 g5_fvt_count = ssize / sizeof(struct smu_sdbp_fvt);
453 g5_fvt_cur = 0; 451 g5_fvt_cur = 0;
454 452
455 /* Sanity checking */ 453 /* Sanity checking */
diff --git a/drivers/cpufreq/powernow-k6.c b/drivers/cpufreq/powernow-k6.c
index ea8e10382ec5..85f1c8c25ddc 100644
--- a/drivers/cpufreq/powernow-k6.c
+++ b/drivers/cpufreq/powernow-k6.c
@@ -207,7 +207,6 @@ static struct cpufreq_driver powernow_k6_driver = {
207 .exit = powernow_k6_cpu_exit, 207 .exit = powernow_k6_cpu_exit,
208 .get = powernow_k6_get, 208 .get = powernow_k6_get,
209 .name = "powernow-k6", 209 .name = "powernow-k6",
210 .owner = THIS_MODULE,
211 .attr = powernow_k6_attr, 210 .attr = powernow_k6_attr,
212}; 211};
213 212
diff --git a/drivers/cpufreq/powernow-k7.c b/drivers/cpufreq/powernow-k7.c
index 955870877935..14ce480be8ab 100644
--- a/drivers/cpufreq/powernow-k7.c
+++ b/drivers/cpufreq/powernow-k7.c
@@ -177,7 +177,7 @@ static int get_ranges(unsigned char *pst)
177 unsigned int speed; 177 unsigned int speed;
178 u8 fid, vid; 178 u8 fid, vid;
179 179
180 powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) * 180 powernow_table = kzalloc((sizeof(*powernow_table) *
181 (number_scales + 1)), GFP_KERNEL); 181 (number_scales + 1)), GFP_KERNEL);
182 if (!powernow_table) 182 if (!powernow_table)
183 return -ENOMEM; 183 return -ENOMEM;
@@ -309,8 +309,7 @@ static int powernow_acpi_init(void)
309 goto err0; 309 goto err0;
310 } 310 }
311 311
312 acpi_processor_perf = kzalloc(sizeof(struct acpi_processor_performance), 312 acpi_processor_perf = kzalloc(sizeof(*acpi_processor_perf), GFP_KERNEL);
313 GFP_KERNEL);
314 if (!acpi_processor_perf) { 313 if (!acpi_processor_perf) {
315 retval = -ENOMEM; 314 retval = -ENOMEM;
316 goto err0; 315 goto err0;
@@ -346,7 +345,7 @@ static int powernow_acpi_init(void)
346 goto err2; 345 goto err2;
347 } 346 }
348 347
349 powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) * 348 powernow_table = kzalloc((sizeof(*powernow_table) *
350 (number_scales + 1)), GFP_KERNEL); 349 (number_scales + 1)), GFP_KERNEL);
351 if (!powernow_table) { 350 if (!powernow_table) {
352 retval = -ENOMEM; 351 retval = -ENOMEM;
@@ -497,7 +496,7 @@ static int powernow_decode_bios(int maxfid, int startvid)
497 "relevant to this CPU).\n", 496 "relevant to this CPU).\n",
498 psb->numpst); 497 psb->numpst);
499 498
500 p += sizeof(struct psb_s); 499 p += sizeof(*psb);
501 500
502 pst = (struct pst_s *) p; 501 pst = (struct pst_s *) p;
503 502
@@ -510,12 +509,12 @@ static int powernow_decode_bios(int maxfid, int startvid)
510 (maxfid == pst->maxfid) && 509 (maxfid == pst->maxfid) &&
511 (startvid == pst->startvid)) { 510 (startvid == pst->startvid)) {
512 print_pst_entry(pst, j); 511 print_pst_entry(pst, j);
513 p = (char *)pst + sizeof(struct pst_s); 512 p = (char *)pst + sizeof(*pst);
514 ret = get_ranges(p); 513 ret = get_ranges(p);
515 return ret; 514 return ret;
516 } else { 515 } else {
517 unsigned int k; 516 unsigned int k;
518 p = (char *)pst + sizeof(struct pst_s); 517 p = (char *)pst + sizeof(*pst);
519 for (k = 0; k < number_scales; k++) 518 for (k = 0; k < number_scales; k++)
520 p += 2; 519 p += 2;
521 } 520 }
@@ -717,7 +716,6 @@ static struct cpufreq_driver powernow_driver = {
717 .init = powernow_cpu_init, 716 .init = powernow_cpu_init,
718 .exit = powernow_cpu_exit, 717 .exit = powernow_cpu_exit,
719 .name = "powernow-k7", 718 .name = "powernow-k7",
720 .owner = THIS_MODULE,
721 .attr = powernow_table_attr, 719 .attr = powernow_table_attr,
722}; 720};
723 721
diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
index c39d189217cb..2344a9ed17f3 100644
--- a/drivers/cpufreq/powernow-k8.c
+++ b/drivers/cpufreq/powernow-k8.c
@@ -623,7 +623,7 @@ static int fill_powernow_table(struct powernow_k8_data *data,
623 if (check_pst_table(data, pst, maxvid)) 623 if (check_pst_table(data, pst, maxvid))
624 return -EINVAL; 624 return -EINVAL;
625 625
626 powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table) 626 powernow_table = kmalloc((sizeof(*powernow_table)
627 * (data->numps + 1)), GFP_KERNEL); 627 * (data->numps + 1)), GFP_KERNEL);
628 if (!powernow_table) { 628 if (!powernow_table) {
629 printk(KERN_ERR PFX "powernow_table memory alloc failure\n"); 629 printk(KERN_ERR PFX "powernow_table memory alloc failure\n");
@@ -793,7 +793,7 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
793 } 793 }
794 794
795 /* fill in data->powernow_table */ 795 /* fill in data->powernow_table */
796 powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table) 796 powernow_table = kmalloc((sizeof(*powernow_table)
797 * (data->acpi_data.state_count + 1)), GFP_KERNEL); 797 * (data->acpi_data.state_count + 1)), GFP_KERNEL);
798 if (!powernow_table) { 798 if (!powernow_table) {
799 pr_debug("powernow_table memory alloc failure\n"); 799 pr_debug("powernow_table memory alloc failure\n");
@@ -1106,7 +1106,7 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
1106 if (rc) 1106 if (rc)
1107 return -ENODEV; 1107 return -ENODEV;
1108 1108
1109 data = kzalloc(sizeof(struct powernow_k8_data), GFP_KERNEL); 1109 data = kzalloc(sizeof(*data), GFP_KERNEL);
1110 if (!data) { 1110 if (!data) {
1111 printk(KERN_ERR PFX "unable to alloc powernow_k8_data"); 1111 printk(KERN_ERR PFX "unable to alloc powernow_k8_data");
1112 return -ENOMEM; 1112 return -ENOMEM;
@@ -1240,7 +1240,6 @@ static struct cpufreq_driver cpufreq_amd64_driver = {
1240 .exit = powernowk8_cpu_exit, 1240 .exit = powernowk8_cpu_exit,
1241 .get = powernowk8_get, 1241 .get = powernowk8_get,
1242 .name = "powernow-k8", 1242 .name = "powernow-k8",
1243 .owner = THIS_MODULE,
1244 .attr = powernow_k8_attr, 1243 .attr = powernow_k8_attr,
1245}; 1244};
1246 1245
diff --git a/drivers/cpufreq/ppc-corenet-cpufreq.c b/drivers/cpufreq/ppc-corenet-cpufreq.c
index 3cae4529f959..60e81d524ea8 100644
--- a/drivers/cpufreq/ppc-corenet-cpufreq.c
+++ b/drivers/cpufreq/ppc-corenet-cpufreq.c
@@ -300,7 +300,6 @@ static struct freq_attr *corenet_cpufreq_attr[] = {
300 300
301static struct cpufreq_driver ppc_corenet_cpufreq_driver = { 301static struct cpufreq_driver ppc_corenet_cpufreq_driver = {
302 .name = "ppc_cpufreq", 302 .name = "ppc_cpufreq",
303 .owner = THIS_MODULE,
304 .flags = CPUFREQ_CONST_LOOPS, 303 .flags = CPUFREQ_CONST_LOOPS,
305 .init = corenet_cpufreq_cpu_init, 304 .init = corenet_cpufreq_cpu_init,
306 .exit = __exit_p(corenet_cpufreq_cpu_exit), 305 .exit = __exit_p(corenet_cpufreq_cpu_exit),
diff --git a/drivers/cpufreq/ppc_cbe_cpufreq.c b/drivers/cpufreq/ppc_cbe_cpufreq.c
index 5936f8d6f2cc..2e448f0bbdc5 100644
--- a/drivers/cpufreq/ppc_cbe_cpufreq.c
+++ b/drivers/cpufreq/ppc_cbe_cpufreq.c
@@ -181,7 +181,6 @@ static struct cpufreq_driver cbe_cpufreq_driver = {
181 .init = cbe_cpufreq_cpu_init, 181 .init = cbe_cpufreq_cpu_init,
182 .exit = cbe_cpufreq_cpu_exit, 182 .exit = cbe_cpufreq_cpu_exit,
183 .name = "cbe-cpufreq", 183 .name = "cbe-cpufreq",
184 .owner = THIS_MODULE,
185 .flags = CPUFREQ_CONST_LOOPS, 184 .flags = CPUFREQ_CONST_LOOPS,
186}; 185};
187 186
diff --git a/drivers/cpufreq/pxa2xx-cpufreq.c b/drivers/cpufreq/pxa2xx-cpufreq.c
index fb3981ac829f..8749eaf18793 100644
--- a/drivers/cpufreq/pxa2xx-cpufreq.c
+++ b/drivers/cpufreq/pxa2xx-cpufreq.c
@@ -191,7 +191,7 @@ static int pxa_cpufreq_change_voltage(pxa_freqs_t *pxa_freq)
191 return ret; 191 return ret;
192} 192}
193 193
194static __init void pxa_cpufreq_init_voltages(void) 194static void __init pxa_cpufreq_init_voltages(void)
195{ 195{
196 vcc_core = regulator_get(NULL, "vcc_core"); 196 vcc_core = regulator_get(NULL, "vcc_core");
197 if (IS_ERR(vcc_core)) { 197 if (IS_ERR(vcc_core)) {
@@ -207,7 +207,7 @@ static int pxa_cpufreq_change_voltage(pxa_freqs_t *pxa_freq)
207 return 0; 207 return 0;
208} 208}
209 209
210static __init void pxa_cpufreq_init_voltages(void) { } 210static void __init pxa_cpufreq_init_voltages(void) { }
211#endif 211#endif
212 212
213static void find_freq_tables(struct cpufreq_frequency_table **freq_table, 213static void find_freq_tables(struct cpufreq_frequency_table **freq_table,
diff --git a/drivers/cpufreq/pxa3xx-cpufreq.c b/drivers/cpufreq/pxa3xx-cpufreq.c
index 9c92ef032a9e..d26306fb00d2 100644
--- a/drivers/cpufreq/pxa3xx-cpufreq.c
+++ b/drivers/cpufreq/pxa3xx-cpufreq.c
@@ -213,10 +213,12 @@ static int pxa3xx_cpufreq_init(struct cpufreq_policy *policy)
213 policy->cur = policy->min = policy->max; 213 policy->cur = policy->min = policy->max;
214 214
215 if (cpu_is_pxa300() || cpu_is_pxa310()) 215 if (cpu_is_pxa300() || cpu_is_pxa310())
216 ret = setup_freqs_table(policy, ARRAY_AND_SIZE(pxa300_freqs)); 216 ret = setup_freqs_table(policy, pxa300_freqs,
217 ARRAY_SIZE(pxa300_freqs));
217 218
218 if (cpu_is_pxa320()) 219 if (cpu_is_pxa320())
219 ret = setup_freqs_table(policy, ARRAY_AND_SIZE(pxa320_freqs)); 220 ret = setup_freqs_table(policy, pxa320_freqs,
221 ARRAY_SIZE(pxa320_freqs));
220 222
221 if (ret) { 223 if (ret) {
222 pr_err("failed to setup frequency table\n"); 224 pr_err("failed to setup frequency table\n");
diff --git a/drivers/cpufreq/s3c2416-cpufreq.c b/drivers/cpufreq/s3c2416-cpufreq.c
index ce5b9fca9c18..22dcb81ef9d0 100644
--- a/drivers/cpufreq/s3c2416-cpufreq.c
+++ b/drivers/cpufreq/s3c2416-cpufreq.c
@@ -524,7 +524,6 @@ static struct freq_attr *s3c2416_cpufreq_attr[] = {
524}; 524};
525 525
526static struct cpufreq_driver s3c2416_cpufreq_driver = { 526static struct cpufreq_driver s3c2416_cpufreq_driver = {
527 .owner = THIS_MODULE,
528 .flags = 0, 527 .flags = 0,
529 .verify = s3c2416_cpufreq_verify_speed, 528 .verify = s3c2416_cpufreq_verify_speed,
530 .target = s3c2416_cpufreq_set_target, 529 .target = s3c2416_cpufreq_set_target,
diff --git a/drivers/cpufreq/s3c24xx-cpufreq.c b/drivers/cpufreq/s3c24xx-cpufreq.c
index 87781eb20d6d..b0f343fcb7ee 100644
--- a/drivers/cpufreq/s3c24xx-cpufreq.c
+++ b/drivers/cpufreq/s3c24xx-cpufreq.c
@@ -392,7 +392,7 @@ static int s3c_cpufreq_init(struct cpufreq_policy *policy)
392 return 0; 392 return 0;
393} 393}
394 394
395static __init int s3c_cpufreq_initclks(void) 395static int __init s3c_cpufreq_initclks(void)
396{ 396{
397 _clk_mpll = s3c_cpufreq_clk_get(NULL, "mpll"); 397 _clk_mpll = s3c_cpufreq_clk_get(NULL, "mpll");
398 _clk_xtal = s3c_cpufreq_clk_get(NULL, "xtal"); 398 _clk_xtal = s3c_cpufreq_clk_get(NULL, "xtal");
@@ -522,7 +522,7 @@ int __init s3c_cpufreq_setboard(struct s3c_cpufreq_board *board)
522 /* Copy the board information so that each board can make this 522 /* Copy the board information so that each board can make this
523 * initdata. */ 523 * initdata. */
524 524
525 ours = kzalloc(sizeof(struct s3c_cpufreq_board), GFP_KERNEL); 525 ours = kzalloc(sizeof(*ours), GFP_KERNEL);
526 if (ours == NULL) { 526 if (ours == NULL) {
527 printk(KERN_ERR "%s: no memory\n", __func__); 527 printk(KERN_ERR "%s: no memory\n", __func__);
528 return -ENOMEM; 528 return -ENOMEM;
@@ -615,7 +615,7 @@ static int s3c_cpufreq_build_freq(void)
615 size = cpu_cur.info->calc_freqtable(&cpu_cur, NULL, 0); 615 size = cpu_cur.info->calc_freqtable(&cpu_cur, NULL, 0);
616 size++; 616 size++;
617 617
618 ftab = kmalloc(sizeof(struct cpufreq_frequency_table) * size, GFP_KERNEL); 618 ftab = kmalloc(sizeof(*ftab) * size, GFP_KERNEL);
619 if (!ftab) { 619 if (!ftab) {
620 printk(KERN_ERR "%s: no memory for tables\n", __func__); 620 printk(KERN_ERR "%s: no memory for tables\n", __func__);
621 return -ENOMEM; 621 return -ENOMEM;
@@ -691,7 +691,7 @@ int __init s3c_plltab_register(struct cpufreq_frequency_table *plls,
691 struct cpufreq_frequency_table *vals; 691 struct cpufreq_frequency_table *vals;
692 unsigned int size; 692 unsigned int size;
693 693
694 size = sizeof(struct cpufreq_frequency_table) * (plls_no + 1); 694 size = sizeof(*vals) * (plls_no + 1);
695 695
696 vals = kmalloc(size, GFP_KERNEL); 696 vals = kmalloc(size, GFP_KERNEL);
697 if (vals) { 697 if (vals) {
diff --git a/drivers/cpufreq/s3c64xx-cpufreq.c b/drivers/cpufreq/s3c64xx-cpufreq.c
index 13bb4bae64ee..8a72b0c555f8 100644
--- a/drivers/cpufreq/s3c64xx-cpufreq.c
+++ b/drivers/cpufreq/s3c64xx-cpufreq.c
@@ -263,7 +263,6 @@ static int s3c64xx_cpufreq_driver_init(struct cpufreq_policy *policy)
263} 263}
264 264
265static struct cpufreq_driver s3c64xx_cpufreq_driver = { 265static struct cpufreq_driver s3c64xx_cpufreq_driver = {
266 .owner = THIS_MODULE,
267 .flags = 0, 266 .flags = 0,
268 .verify = s3c64xx_cpufreq_verify_speed, 267 .verify = s3c64xx_cpufreq_verify_speed,
269 .target = s3c64xx_cpufreq_set_target, 268 .target = s3c64xx_cpufreq_set_target,
diff --git a/drivers/cpufreq/sc520_freq.c b/drivers/cpufreq/sc520_freq.c
index 77a210975fc4..d6f6c6f4efa7 100644
--- a/drivers/cpufreq/sc520_freq.c
+++ b/drivers/cpufreq/sc520_freq.c
@@ -147,7 +147,6 @@ static struct cpufreq_driver sc520_freq_driver = {
147 .init = sc520_freq_cpu_init, 147 .init = sc520_freq_cpu_init,
148 .exit = sc520_freq_cpu_exit, 148 .exit = sc520_freq_cpu_exit,
149 .name = "sc520_freq", 149 .name = "sc520_freq",
150 .owner = THIS_MODULE,
151 .attr = sc520_freq_attr, 150 .attr = sc520_freq_attr,
152}; 151};
153 152
diff --git a/drivers/cpufreq/sh-cpufreq.c b/drivers/cpufreq/sh-cpufreq.c
index 73adb64651e8..ffc6d24b0cfb 100644
--- a/drivers/cpufreq/sh-cpufreq.c
+++ b/drivers/cpufreq/sh-cpufreq.c
@@ -160,7 +160,6 @@ static struct freq_attr *sh_freq_attr[] = {
160}; 160};
161 161
162static struct cpufreq_driver sh_cpufreq_driver = { 162static struct cpufreq_driver sh_cpufreq_driver = {
163 .owner = THIS_MODULE,
164 .name = "sh", 163 .name = "sh",
165 .get = sh_cpufreq_get, 164 .get = sh_cpufreq_get,
166 .target = sh_cpufreq_target, 165 .target = sh_cpufreq_target,
diff --git a/drivers/cpufreq/sparc-us2e-cpufreq.c b/drivers/cpufreq/sparc-us2e-cpufreq.c
index 93061a408773..cf5bc2ca16fa 100644
--- a/drivers/cpufreq/sparc-us2e-cpufreq.c
+++ b/drivers/cpufreq/sparc-us2e-cpufreq.c
@@ -351,12 +351,11 @@ static int __init us2e_freq_init(void)
351 struct cpufreq_driver *driver; 351 struct cpufreq_driver *driver;
352 352
353 ret = -ENOMEM; 353 ret = -ENOMEM;
354 driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL); 354 driver = kzalloc(sizeof(*driver), GFP_KERNEL);
355 if (!driver) 355 if (!driver)
356 goto err_out; 356 goto err_out;
357 357
358 us2e_freq_table = kzalloc( 358 us2e_freq_table = kzalloc((NR_CPUS * sizeof(*us2e_freq_table)),
359 (NR_CPUS * sizeof(struct us2e_freq_percpu_info)),
360 GFP_KERNEL); 359 GFP_KERNEL);
361 if (!us2e_freq_table) 360 if (!us2e_freq_table)
362 goto err_out; 361 goto err_out;
@@ -366,7 +365,6 @@ static int __init us2e_freq_init(void)
366 driver->target = us2e_freq_target; 365 driver->target = us2e_freq_target;
367 driver->get = us2e_freq_get; 366 driver->get = us2e_freq_get;
368 driver->exit = us2e_freq_cpu_exit; 367 driver->exit = us2e_freq_cpu_exit;
369 driver->owner = THIS_MODULE,
370 strcpy(driver->name, "UltraSPARC-IIe"); 368 strcpy(driver->name, "UltraSPARC-IIe");
371 369
372 cpufreq_us2e_driver = driver; 370 cpufreq_us2e_driver = driver;
diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
index 880ee293d61e..ac76b489979d 100644
--- a/drivers/cpufreq/sparc-us3-cpufreq.c
+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
@@ -212,12 +212,11 @@ static int __init us3_freq_init(void)
212 struct cpufreq_driver *driver; 212 struct cpufreq_driver *driver;
213 213
214 ret = -ENOMEM; 214 ret = -ENOMEM;
215 driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL); 215 driver = kzalloc(sizeof(*driver), GFP_KERNEL);
216 if (!driver) 216 if (!driver)
217 goto err_out; 217 goto err_out;
218 218
219 us3_freq_table = kzalloc( 219 us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
220 (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
221 GFP_KERNEL); 220 GFP_KERNEL);
222 if (!us3_freq_table) 221 if (!us3_freq_table)
223 goto err_out; 222 goto err_out;
@@ -227,7 +226,6 @@ static int __init us3_freq_init(void)
227 driver->target = us3_freq_target; 226 driver->target = us3_freq_target;
228 driver->get = us3_freq_get; 227 driver->get = us3_freq_get;
229 driver->exit = us3_freq_cpu_exit; 228 driver->exit = us3_freq_cpu_exit;
230 driver->owner = THIS_MODULE,
231 strcpy(driver->name, "UltraSPARC-III"); 229 strcpy(driver->name, "UltraSPARC-III");
232 230
233 cpufreq_us3_driver = driver; 231 cpufreq_us3_driver = driver;
diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
index 0915e712fbdc..f897d5105842 100644
--- a/drivers/cpufreq/speedstep-centrino.c
+++ b/drivers/cpufreq/speedstep-centrino.c
@@ -575,7 +575,6 @@ static struct cpufreq_driver centrino_driver = {
575 .target = centrino_target, 575 .target = centrino_target,
576 .get = get_cur_freq, 576 .get = get_cur_freq,
577 .attr = centrino_attr, 577 .attr = centrino_attr,
578 .owner = THIS_MODULE,
579}; 578};
580 579
581/* 580/*
diff --git a/drivers/cpufreq/speedstep-ich.c b/drivers/cpufreq/speedstep-ich.c
index e2e5aa971452..5355abb69afc 100644
--- a/drivers/cpufreq/speedstep-ich.c
+++ b/drivers/cpufreq/speedstep-ich.c
@@ -378,7 +378,6 @@ static struct cpufreq_driver speedstep_driver = {
378 .init = speedstep_cpu_init, 378 .init = speedstep_cpu_init,
379 .exit = speedstep_cpu_exit, 379 .exit = speedstep_cpu_exit,
380 .get = speedstep_get, 380 .get = speedstep_get,
381 .owner = THIS_MODULE,
382 .attr = speedstep_attr, 381 .attr = speedstep_attr,
383}; 382};
384 383
diff --git a/drivers/cpufreq/speedstep-smi.c b/drivers/cpufreq/speedstep-smi.c
index f5a6b70ee6c0..abfba4f731eb 100644
--- a/drivers/cpufreq/speedstep-smi.c
+++ b/drivers/cpufreq/speedstep-smi.c
@@ -375,7 +375,6 @@ static struct cpufreq_driver speedstep_driver = {
375 .exit = speedstep_cpu_exit, 375 .exit = speedstep_cpu_exit,
376 .get = speedstep_get, 376 .get = speedstep_get,
377 .resume = speedstep_resume, 377 .resume = speedstep_resume,
378 .owner = THIS_MODULE,
379 .attr = speedstep_attr, 378 .attr = speedstep_attr,
380}; 379};
381 380
diff --git a/drivers/cpufreq/unicore2-cpufreq.c b/drivers/cpufreq/unicore2-cpufreq.c
index 12fc904d7dab..b225f04d8ae5 100644
--- a/drivers/cpufreq/unicore2-cpufreq.c
+++ b/drivers/cpufreq/unicore2-cpufreq.c
@@ -24,7 +24,7 @@ static struct cpufreq_driver ucv2_driver;
24/* make sure that only the "userspace" governor is run 24/* make sure that only the "userspace" governor is run
25 * -- anything else wouldn't make sense on this platform, anyway. 25 * -- anything else wouldn't make sense on this platform, anyway.
26 */ 26 */
27int ucv2_verify_speed(struct cpufreq_policy *policy) 27static int ucv2_verify_speed(struct cpufreq_policy *policy)
28{ 28{
29 if (policy->cpu) 29 if (policy->cpu)
30 return -EINVAL; 30 return -EINVAL;
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 90d5a15120d5..d568f3975eeb 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -11,71 +11,36 @@
11#ifndef _LINUX_CPUFREQ_H 11#ifndef _LINUX_CPUFREQ_H
12#define _LINUX_CPUFREQ_H 12#define _LINUX_CPUFREQ_H
13 13
14#include <asm/cputime.h> 14#include <linux/cpumask.h>
15#include <linux/mutex.h> 15#include <linux/completion.h>
16#include <linux/notifier.h>
17#include <linux/threads.h>
18#include <linux/kobject.h> 16#include <linux/kobject.h>
17#include <linux/notifier.h>
19#include <linux/sysfs.h> 18#include <linux/sysfs.h>
20#include <linux/completion.h>
21#include <linux/workqueue.h>
22#include <linux/cpumask.h>
23#include <asm/div64.h>
24
25#define CPUFREQ_NAME_LEN 16
26/* Print length for names. Extra 1 space for accomodating '\n' in prints */
27#define CPUFREQ_NAME_PLEN (CPUFREQ_NAME_LEN + 1)
28 19
29/********************************************************************* 20/*********************************************************************
30 * CPUFREQ NOTIFIER INTERFACE * 21 * CPUFREQ INTERFACE *
31 *********************************************************************/ 22 *********************************************************************/
32 23/*
33#define CPUFREQ_TRANSITION_NOTIFIER (0) 24 * Frequency values here are CPU kHz
34#define CPUFREQ_POLICY_NOTIFIER (1) 25 *
35
36#ifdef CONFIG_CPU_FREQ
37int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list);
38int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list);
39extern void disable_cpufreq(void);
40#else /* CONFIG_CPU_FREQ */
41static inline int cpufreq_register_notifier(struct notifier_block *nb,
42 unsigned int list)
43{
44 return 0;
45}
46static inline int cpufreq_unregister_notifier(struct notifier_block *nb,
47 unsigned int list)
48{
49 return 0;
50}
51static inline void disable_cpufreq(void) { }
52#endif /* CONFIG_CPU_FREQ */
53
54/* if (cpufreq_driver->target) exists, the ->governor decides what frequency
55 * within the limits is used. If (cpufreq_driver->setpolicy> exists, these
56 * two generic policies are available:
57 */
58
59#define CPUFREQ_POLICY_POWERSAVE (1)
60#define CPUFREQ_POLICY_PERFORMANCE (2)
61
62/* Frequency values here are CPU kHz so that hardware which doesn't run
63 * with some frequencies can complain without having to guess what per
64 * cent / per mille means.
65 * Maximum transition latency is in nanoseconds - if it's unknown, 26 * Maximum transition latency is in nanoseconds - if it's unknown,
66 * CPUFREQ_ETERNAL shall be used. 27 * CPUFREQ_ETERNAL shall be used.
67 */ 28 */
68 29
30#define CPUFREQ_ETERNAL (-1)
31#define CPUFREQ_NAME_LEN 16
32/* Print length for names. Extra 1 space for accomodating '\n' in prints */
33#define CPUFREQ_NAME_PLEN (CPUFREQ_NAME_LEN + 1)
34
69struct cpufreq_governor; 35struct cpufreq_governor;
70 36
71/* /sys/devices/system/cpu/cpufreq: entry point for global variables */ 37struct cpufreq_freqs {
72extern struct kobject *cpufreq_global_kobject; 38 unsigned int cpu; /* cpu nr */
73int cpufreq_get_global_kobject(void); 39 unsigned int old;
74void cpufreq_put_global_kobject(void); 40 unsigned int new;
75int cpufreq_sysfs_create_file(const struct attribute *attr); 41 u8 flags; /* flags of cpufreq_driver, see below. */
76void cpufreq_sysfs_remove_file(const struct attribute *attr); 42};
77 43
78#define CPUFREQ_ETERNAL (-1)
79struct cpufreq_cpuinfo { 44struct cpufreq_cpuinfo {
80 unsigned int max_freq; 45 unsigned int max_freq;
81 unsigned int min_freq; 46 unsigned int min_freq;
@@ -117,123 +82,103 @@ struct cpufreq_policy {
117 82
118 struct cpufreq_real_policy user_policy; 83 struct cpufreq_real_policy user_policy;
119 84
85 struct list_head policy_list;
120 struct kobject kobj; 86 struct kobject kobj;
121 struct completion kobj_unregister; 87 struct completion kobj_unregister;
122 int transition_ongoing; /* Tracks transition status */ 88 int transition_ongoing; /* Tracks transition status */
123}; 89};
124 90
125#define CPUFREQ_ADJUST (0)
126#define CPUFREQ_INCOMPATIBLE (1)
127#define CPUFREQ_NOTIFY (2)
128#define CPUFREQ_START (3)
129#define CPUFREQ_UPDATE_POLICY_CPU (4)
130
131/* Only for ACPI */ 91/* Only for ACPI */
132#define CPUFREQ_SHARED_TYPE_NONE (0) /* None */ 92#define CPUFREQ_SHARED_TYPE_NONE (0) /* None */
133#define CPUFREQ_SHARED_TYPE_HW (1) /* HW does needed coordination */ 93#define CPUFREQ_SHARED_TYPE_HW (1) /* HW does needed coordination */
134#define CPUFREQ_SHARED_TYPE_ALL (2) /* All dependent CPUs should set freq */ 94#define CPUFREQ_SHARED_TYPE_ALL (2) /* All dependent CPUs should set freq */
135#define CPUFREQ_SHARED_TYPE_ANY (3) /* Freq can be set from any dependent CPU*/ 95#define CPUFREQ_SHARED_TYPE_ANY (3) /* Freq can be set from any dependent CPU*/
136 96
97struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu);
98void cpufreq_cpu_put(struct cpufreq_policy *policy);
99
137static inline bool policy_is_shared(struct cpufreq_policy *policy) 100static inline bool policy_is_shared(struct cpufreq_policy *policy)
138{ 101{
139 return cpumask_weight(policy->cpus) > 1; 102 return cpumask_weight(policy->cpus) > 1;
140} 103}
141 104
142/******************** cpufreq transition notifiers *******************/ 105/* /sys/devices/system/cpu/cpufreq: entry point for global variables */
143 106extern struct kobject *cpufreq_global_kobject;
144#define CPUFREQ_PRECHANGE (0) 107int cpufreq_get_global_kobject(void);
145#define CPUFREQ_POSTCHANGE (1) 108void cpufreq_put_global_kobject(void);
146#define CPUFREQ_RESUMECHANGE (8) 109int cpufreq_sysfs_create_file(const struct attribute *attr);
147#define CPUFREQ_SUSPENDCHANGE (9) 110void cpufreq_sysfs_remove_file(const struct attribute *attr);
148 111
149struct cpufreq_freqs { 112#ifdef CONFIG_CPU_FREQ
150 unsigned int cpu; /* cpu nr */ 113unsigned int cpufreq_get(unsigned int cpu);
151 unsigned int old; 114unsigned int cpufreq_quick_get(unsigned int cpu);
152 unsigned int new; 115unsigned int cpufreq_quick_get_max(unsigned int cpu);
153 u8 flags; /* flags of cpufreq_driver, see below. */ 116void disable_cpufreq(void);
154};
155 117
156/** 118u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy);
157 * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch 119int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
158 * safe) 120int cpufreq_update_policy(unsigned int cpu);
159 * @old: old value 121bool have_governor_per_policy(void);
160 * @div: divisor 122struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy);
161 * @mult: multiplier 123#else
162 * 124static inline unsigned int cpufreq_get(unsigned int cpu)
163 *
164 * new = old * mult / div
165 */
166static inline unsigned long cpufreq_scale(unsigned long old, u_int div,
167 u_int mult)
168{ 125{
169#if BITS_PER_LONG == 32 126 return 0;
170 127}
171 u64 result = ((u64) old) * ((u64) mult); 128static inline unsigned int cpufreq_quick_get(unsigned int cpu)
172 do_div(result, div); 129{
173 return (unsigned long) result; 130 return 0;
174 131}
175#elif BITS_PER_LONG == 64 132static inline unsigned int cpufreq_quick_get_max(unsigned int cpu)
176 133{
177 unsigned long result = old * ((u64) mult); 134 return 0;
178 result /= div; 135}
179 return result; 136static inline void disable_cpufreq(void) { }
180
181#endif 137#endif
182};
183 138
184/********************************************************************* 139/*********************************************************************
185 * CPUFREQ GOVERNORS * 140 * CPUFREQ DRIVER INTERFACE *
186 *********************************************************************/ 141 *********************************************************************/
187 142
188#define CPUFREQ_GOV_START 1 143#define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */
189#define CPUFREQ_GOV_STOP 2 144#define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */
190#define CPUFREQ_GOV_LIMITS 3
191#define CPUFREQ_GOV_POLICY_INIT 4
192#define CPUFREQ_GOV_POLICY_EXIT 5
193 145
194struct cpufreq_governor { 146struct freq_attr {
195 char name[CPUFREQ_NAME_LEN]; 147 struct attribute attr;
196 int initialized; 148 ssize_t (*show)(struct cpufreq_policy *, char *);
197 int (*governor) (struct cpufreq_policy *policy, 149 ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
198 unsigned int event);
199 ssize_t (*show_setspeed) (struct cpufreq_policy *policy,
200 char *buf);
201 int (*store_setspeed) (struct cpufreq_policy *policy,
202 unsigned int freq);
203 unsigned int max_transition_latency; /* HW must be able to switch to
204 next freq faster than this value in nano secs or we
205 will fallback to performance governor */
206 struct list_head governor_list;
207 struct module *owner;
208}; 150};
209 151
210/* 152#define cpufreq_freq_attr_ro(_name) \
211 * Pass a target to the cpufreq driver. 153static struct freq_attr _name = \
212 */ 154__ATTR(_name, 0444, show_##_name, NULL)
213extern int cpufreq_driver_target(struct cpufreq_policy *policy,
214 unsigned int target_freq,
215 unsigned int relation);
216extern int __cpufreq_driver_target(struct cpufreq_policy *policy,
217 unsigned int target_freq,
218 unsigned int relation);
219 155
220extern int __cpufreq_driver_getavg(struct cpufreq_policy *policy, 156#define cpufreq_freq_attr_ro_perm(_name, _perm) \
221 unsigned int cpu); 157static struct freq_attr _name = \
158__ATTR(_name, _perm, show_##_name, NULL)
222 159
223int cpufreq_register_governor(struct cpufreq_governor *governor); 160#define cpufreq_freq_attr_rw(_name) \
224void cpufreq_unregister_governor(struct cpufreq_governor *governor); 161static struct freq_attr _name = \
162__ATTR(_name, 0644, show_##_name, store_##_name)
225 163
226/********************************************************************* 164struct global_attr {
227 * CPUFREQ DRIVER INTERFACE * 165 struct attribute attr;
228 *********************************************************************/ 166 ssize_t (*show)(struct kobject *kobj,
167 struct attribute *attr, char *buf);
168 ssize_t (*store)(struct kobject *a, struct attribute *b,
169 const char *c, size_t count);
170};
229 171
230#define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */ 172#define define_one_global_ro(_name) \
231#define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */ 173static struct global_attr _name = \
174__ATTR(_name, 0444, show_##_name, NULL)
175
176#define define_one_global_rw(_name) \
177static struct global_attr _name = \
178__ATTR(_name, 0644, show_##_name, store_##_name)
232 179
233struct freq_attr;
234 180
235struct cpufreq_driver { 181struct cpufreq_driver {
236 struct module *owner;
237 char name[CPUFREQ_NAME_LEN]; 182 char name[CPUFREQ_NAME_LEN];
238 u8 flags; 183 u8 flags;
239 /* 184 /*
@@ -258,8 +203,6 @@ struct cpufreq_driver {
258 unsigned int (*get) (unsigned int cpu); 203 unsigned int (*get) (unsigned int cpu);
259 204
260 /* optional */ 205 /* optional */
261 unsigned int (*getavg) (struct cpufreq_policy *policy,
262 unsigned int cpu);
263 int (*bios_limit) (int cpu, unsigned int *limit); 206 int (*bios_limit) (int cpu, unsigned int *limit);
264 207
265 int (*exit) (struct cpufreq_policy *policy); 208 int (*exit) (struct cpufreq_policy *policy);
@@ -269,7 +212,6 @@ struct cpufreq_driver {
269}; 212};
270 213
271/* flags */ 214/* flags */
272
273#define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if 215#define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
274 * all ->init() calls failed */ 216 * all ->init() calls failed */
275#define CPUFREQ_CONST_LOOPS 0x02 /* loops_per_jiffy or other kernel 217#define CPUFREQ_CONST_LOOPS 0x02 /* loops_per_jiffy or other kernel
@@ -281,8 +223,7 @@ struct cpufreq_driver {
281int cpufreq_register_driver(struct cpufreq_driver *driver_data); 223int cpufreq_register_driver(struct cpufreq_driver *driver_data);
282int cpufreq_unregister_driver(struct cpufreq_driver *driver_data); 224int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);
283 225
284void cpufreq_notify_transition(struct cpufreq_policy *policy, 226const char *cpufreq_get_current_driver(void);
285 struct cpufreq_freqs *freqs, unsigned int state);
286 227
287static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy, 228static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy,
288 unsigned int min, unsigned int max) 229 unsigned int min, unsigned int max)
@@ -300,87 +241,118 @@ static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy,
300 return; 241 return;
301} 242}
302 243
303struct freq_attr { 244/*********************************************************************
304 struct attribute attr; 245 * CPUFREQ NOTIFIER INTERFACE *
305 ssize_t (*show)(struct cpufreq_policy *, char *); 246 *********************************************************************/
306 ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
307};
308
309#define cpufreq_freq_attr_ro(_name) \
310static struct freq_attr _name = \
311__ATTR(_name, 0444, show_##_name, NULL)
312
313#define cpufreq_freq_attr_ro_perm(_name, _perm) \
314static struct freq_attr _name = \
315__ATTR(_name, _perm, show_##_name, NULL)
316
317#define cpufreq_freq_attr_rw(_name) \
318static struct freq_attr _name = \
319__ATTR(_name, 0644, show_##_name, store_##_name)
320 247
321struct global_attr { 248#define CPUFREQ_TRANSITION_NOTIFIER (0)
322 struct attribute attr; 249#define CPUFREQ_POLICY_NOTIFIER (1)
323 ssize_t (*show)(struct kobject *kobj,
324 struct attribute *attr, char *buf);
325 ssize_t (*store)(struct kobject *a, struct attribute *b,
326 const char *c, size_t count);
327};
328 250
329#define define_one_global_ro(_name) \ 251/* Transition notifiers */
330static struct global_attr _name = \ 252#define CPUFREQ_PRECHANGE (0)
331__ATTR(_name, 0444, show_##_name, NULL) 253#define CPUFREQ_POSTCHANGE (1)
254#define CPUFREQ_RESUMECHANGE (8)
255#define CPUFREQ_SUSPENDCHANGE (9)
332 256
333#define define_one_global_rw(_name) \ 257/* Policy Notifiers */
334static struct global_attr _name = \ 258#define CPUFREQ_ADJUST (0)
335__ATTR(_name, 0644, show_##_name, store_##_name) 259#define CPUFREQ_INCOMPATIBLE (1)
260#define CPUFREQ_NOTIFY (2)
261#define CPUFREQ_START (3)
262#define CPUFREQ_UPDATE_POLICY_CPU (4)
336 263
337struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu); 264#ifdef CONFIG_CPU_FREQ
338void cpufreq_cpu_put(struct cpufreq_policy *data); 265int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list);
339const char *cpufreq_get_current_driver(void); 266int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list);
340 267
341/********************************************************************* 268void cpufreq_notify_transition(struct cpufreq_policy *policy,
342 * CPUFREQ 2.6. INTERFACE * 269 struct cpufreq_freqs *freqs, unsigned int state);
343 *********************************************************************/
344u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy);
345int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
346int cpufreq_update_policy(unsigned int cpu);
347bool have_governor_per_policy(void);
348struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy);
349 270
350#ifdef CONFIG_CPU_FREQ 271#else /* CONFIG_CPU_FREQ */
351/* 272static inline int cpufreq_register_notifier(struct notifier_block *nb,
352 * query the current CPU frequency (in kHz). If zero, cpufreq couldn't detect it 273 unsigned int list)
353 */
354unsigned int cpufreq_get(unsigned int cpu);
355#else
356static inline unsigned int cpufreq_get(unsigned int cpu)
357{ 274{
358 return 0; 275 return 0;
359} 276}
360#endif 277static inline int cpufreq_unregister_notifier(struct notifier_block *nb,
361 278 unsigned int list)
362/*
363 * query the last known CPU freq (in kHz). If zero, cpufreq couldn't detect it
364 */
365#ifdef CONFIG_CPU_FREQ
366unsigned int cpufreq_quick_get(unsigned int cpu);
367unsigned int cpufreq_quick_get_max(unsigned int cpu);
368#else
369static inline unsigned int cpufreq_quick_get(unsigned int cpu)
370{ 279{
371 return 0; 280 return 0;
372} 281}
373static inline unsigned int cpufreq_quick_get_max(unsigned int cpu) 282#endif /* !CONFIG_CPU_FREQ */
283
284/**
285 * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch
286 * safe)
287 * @old: old value
288 * @div: divisor
289 * @mult: multiplier
290 *
291 *
292 * new = old * mult / div
293 */
294static inline unsigned long cpufreq_scale(unsigned long old, u_int div,
295 u_int mult)
374{ 296{
375 return 0; 297#if BITS_PER_LONG == 32
376} 298 u64 result = ((u64) old) * ((u64) mult);
299 do_div(result, div);
300 return (unsigned long) result;
301
302#elif BITS_PER_LONG == 64
303 unsigned long result = old * ((u64) mult);
304 result /= div;
305 return result;
377#endif 306#endif
307}
378 308
379/********************************************************************* 309/*********************************************************************
380 * CPUFREQ DEFAULT GOVERNOR * 310 * CPUFREQ GOVERNORS *
381 *********************************************************************/ 311 *********************************************************************/
382 312
383/* 313/*
314 * If (cpufreq_driver->target) exists, the ->governor decides what frequency
315 * within the limits is used. If (cpufreq_driver->setpolicy> exists, these
316 * two generic policies are available:
317 */
318#define CPUFREQ_POLICY_POWERSAVE (1)
319#define CPUFREQ_POLICY_PERFORMANCE (2)
320
321/* Governor Events */
322#define CPUFREQ_GOV_START 1
323#define CPUFREQ_GOV_STOP 2
324#define CPUFREQ_GOV_LIMITS 3
325#define CPUFREQ_GOV_POLICY_INIT 4
326#define CPUFREQ_GOV_POLICY_EXIT 5
327
328struct cpufreq_governor {
329 char name[CPUFREQ_NAME_LEN];
330 int initialized;
331 int (*governor) (struct cpufreq_policy *policy,
332 unsigned int event);
333 ssize_t (*show_setspeed) (struct cpufreq_policy *policy,
334 char *buf);
335 int (*store_setspeed) (struct cpufreq_policy *policy,
336 unsigned int freq);
337 unsigned int max_transition_latency; /* HW must be able to switch to
338 next freq faster than this value in nano secs or we
339 will fallback to performance governor */
340 struct list_head governor_list;
341 struct module *owner;
342};
343
344/* Pass a target to the cpufreq driver */
345int cpufreq_driver_target(struct cpufreq_policy *policy,
346 unsigned int target_freq,
347 unsigned int relation);
348int __cpufreq_driver_target(struct cpufreq_policy *policy,
349 unsigned int target_freq,
350 unsigned int relation);
351int cpufreq_register_governor(struct cpufreq_governor *governor);
352void cpufreq_unregister_governor(struct cpufreq_governor *governor);
353
354/* CPUFREQ DEFAULT GOVERNOR */
355/*
384 * Performance governor is fallback governor if any other gov failed to auto 356 * Performance governor is fallback governor if any other gov failed to auto
385 * load due latency restrictions 357 * load due latency restrictions
386 */ 358 */
@@ -428,18 +400,16 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
428 unsigned int relation, 400 unsigned int relation,
429 unsigned int *index); 401 unsigned int *index);
430 402
431/* the following 3 funtions are for cpufreq core use only */ 403void cpufreq_frequency_table_update_policy_cpu(struct cpufreq_policy *policy);
404ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf);
405
406/* the following funtion is for cpufreq core use only */
432struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu); 407struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu);
433 408
434/* the following are really really optional */ 409/* the following are really really optional */
435extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs; 410extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs;
436
437void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table, 411void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
438 unsigned int cpu); 412 unsigned int cpu);
439void cpufreq_frequency_table_update_policy_cpu(struct cpufreq_policy *policy);
440
441void cpufreq_frequency_table_put_attr(unsigned int cpu); 413void cpufreq_frequency_table_put_attr(unsigned int cpu);
442 414
443ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf);
444
445#endif /* _LINUX_CPUFREQ_H */ 415#endif /* _LINUX_CPUFREQ_H */