aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/arm/mach-at91/cpuidle.c41
-rw-r--r--arch/arm/mach-davinci/cpuidle.c51
-rw-r--r--arch/arm/mach-exynos4/cpuidle.c30
-rw-r--r--arch/arm/mach-kirkwood/cpuidle.c42
-rw-r--r--arch/arm/mach-omap2/cpuidle34xx.c133
-rw-r--r--arch/sh/kernel/cpu/shmobile/cpuidle.c28
-rw-r--r--arch/x86/platform/mrst/pmu.c2
-rw-r--r--drivers/acpi/processor_driver.c20
-rw-r--r--drivers/acpi/processor_idle.c251
-rw-r--r--drivers/cpuidle/cpuidle.c86
-rw-r--r--drivers/cpuidle/driver.c25
-rw-r--r--drivers/cpuidle/governors/ladder.c41
-rw-r--r--drivers/cpuidle/governors/menu.c29
-rw-r--r--drivers/cpuidle/sysfs.c22
-rw-r--r--drivers/idle/intel_idle.c130
-rw-r--r--include/acpi/processor.h1
-rw-r--r--include/linux/cpuidle.h52
-rw-r--r--tools/power/x86/turbostat/turbostat.c28
18 files changed, 666 insertions, 346 deletions
diff --git a/arch/arm/mach-at91/cpuidle.c b/arch/arm/mach-at91/cpuidle.c
index 1cfeac1483d6..93178f67420e 100644
--- a/arch/arm/mach-at91/cpuidle.c
+++ b/arch/arm/mach-at91/cpuidle.c
@@ -33,7 +33,8 @@ static struct cpuidle_driver at91_idle_driver = {
33 33
34/* Actual code that puts the SoC in different idle states */ 34/* Actual code that puts the SoC in different idle states */
35static int at91_enter_idle(struct cpuidle_device *dev, 35static int at91_enter_idle(struct cpuidle_device *dev,
36 struct cpuidle_state *state) 36 struct cpuidle_driver *drv,
37 int index)
37{ 38{
38 struct timeval before, after; 39 struct timeval before, after;
39 int idle_time; 40 int idle_time;
@@ -41,10 +42,10 @@ static int at91_enter_idle(struct cpuidle_device *dev,
41 42
42 local_irq_disable(); 43 local_irq_disable();
43 do_gettimeofday(&before); 44 do_gettimeofday(&before);
44 if (state == &dev->states[0]) 45 if (index == 0)
45 /* Wait for interrupt state */ 46 /* Wait for interrupt state */
46 cpu_do_idle(); 47 cpu_do_idle();
47 else if (state == &dev->states[1]) { 48 else if (index == 1) {
48 asm("b 1f; .align 5; 1:"); 49 asm("b 1f; .align 5; 1:");
49 asm("mcr p15, 0, r0, c7, c10, 4"); /* drain write buffer */ 50 asm("mcr p15, 0, r0, c7, c10, 4"); /* drain write buffer */
50 saved_lpr = sdram_selfrefresh_enable(); 51 saved_lpr = sdram_selfrefresh_enable();
@@ -55,34 +56,38 @@ static int at91_enter_idle(struct cpuidle_device *dev,
55 local_irq_enable(); 56 local_irq_enable();
56 idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC + 57 idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC +
57 (after.tv_usec - before.tv_usec); 58 (after.tv_usec - before.tv_usec);
58 return idle_time; 59
60 dev->last_residency = idle_time;
61 return index;
59} 62}
60 63
61/* Initialize CPU idle by registering the idle states */ 64/* Initialize CPU idle by registering the idle states */
62static int at91_init_cpuidle(void) 65static int at91_init_cpuidle(void)
63{ 66{
64 struct cpuidle_device *device; 67 struct cpuidle_device *device;
65 68 struct cpuidle_driver *driver = &at91_idle_driver;
66 cpuidle_register_driver(&at91_idle_driver);
67 69
68 device = &per_cpu(at91_cpuidle_device, smp_processor_id()); 70 device = &per_cpu(at91_cpuidle_device, smp_processor_id());
69 device->state_count = AT91_MAX_STATES; 71 device->state_count = AT91_MAX_STATES;
72 driver->state_count = AT91_MAX_STATES;
70 73
71 /* Wait for interrupt state */ 74 /* Wait for interrupt state */
72 device->states[0].enter = at91_enter_idle; 75 driver->states[0].enter = at91_enter_idle;
73 device->states[0].exit_latency = 1; 76 driver->states[0].exit_latency = 1;
74 device->states[0].target_residency = 10000; 77 driver->states[0].target_residency = 10000;
75 device->states[0].flags = CPUIDLE_FLAG_TIME_VALID; 78 driver->states[0].flags = CPUIDLE_FLAG_TIME_VALID;
76 strcpy(device->states[0].name, "WFI"); 79 strcpy(driver->states[0].name, "WFI");
77 strcpy(device->states[0].desc, "Wait for interrupt"); 80 strcpy(driver->states[0].desc, "Wait for interrupt");
78 81
79 /* Wait for interrupt and RAM self refresh state */ 82 /* Wait for interrupt and RAM self refresh state */
80 device->states[1].enter = at91_enter_idle; 83 driver->states[1].enter = at91_enter_idle;
81 device->states[1].exit_latency = 10; 84 driver->states[1].exit_latency = 10;
82 device->states[1].target_residency = 10000; 85 driver->states[1].target_residency = 10000;
83 device->states[1].flags = CPUIDLE_FLAG_TIME_VALID; 86 driver->states[1].flags = CPUIDLE_FLAG_TIME_VALID;
84 strcpy(device->states[1].name, "RAM_SR"); 87 strcpy(driver->states[1].name, "RAM_SR");
85 strcpy(device->states[1].desc, "WFI and RAM Self Refresh"); 88 strcpy(driver->states[1].desc, "WFI and RAM Self Refresh");
89
90 cpuidle_register_driver(&at91_idle_driver);
86 91
87 if (cpuidle_register_device(device)) { 92 if (cpuidle_register_device(device)) {
88 printk(KERN_ERR "at91_init_cpuidle: Failed registering\n"); 93 printk(KERN_ERR "at91_init_cpuidle: Failed registering\n");
diff --git a/arch/arm/mach-davinci/cpuidle.c b/arch/arm/mach-davinci/cpuidle.c
index bd59f31b8a95..dbeeccd00173 100644
--- a/arch/arm/mach-davinci/cpuidle.c
+++ b/arch/arm/mach-davinci/cpuidle.c
@@ -78,9 +78,11 @@ static struct davinci_ops davinci_states[DAVINCI_CPUIDLE_MAX_STATES] = {
78 78
79/* Actual code that puts the SoC in different idle states */ 79/* Actual code that puts the SoC in different idle states */
80static int davinci_enter_idle(struct cpuidle_device *dev, 80static int davinci_enter_idle(struct cpuidle_device *dev,
81 struct cpuidle_state *state) 81 struct cpuidle_driver *drv,
82 int index)
82{ 83{
83 struct davinci_ops *ops = cpuidle_get_statedata(state); 84 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
85 struct davinci_ops *ops = cpuidle_get_statedata(state_usage);
84 struct timeval before, after; 86 struct timeval before, after;
85 int idle_time; 87 int idle_time;
86 88
@@ -98,13 +100,17 @@ static int davinci_enter_idle(struct cpuidle_device *dev,
98 local_irq_enable(); 100 local_irq_enable();
99 idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC + 101 idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC +
100 (after.tv_usec - before.tv_usec); 102 (after.tv_usec - before.tv_usec);
101 return idle_time; 103
104 dev->last_residency = idle_time;
105
106 return index;
102} 107}
103 108
104static int __init davinci_cpuidle_probe(struct platform_device *pdev) 109static int __init davinci_cpuidle_probe(struct platform_device *pdev)
105{ 110{
106 int ret; 111 int ret;
107 struct cpuidle_device *device; 112 struct cpuidle_device *device;
113 struct cpuidle_driver *driver = &davinci_idle_driver;
108 struct davinci_cpuidle_config *pdata = pdev->dev.platform_data; 114 struct davinci_cpuidle_config *pdata = pdev->dev.platform_data;
109 115
110 device = &per_cpu(davinci_cpuidle_device, smp_processor_id()); 116 device = &per_cpu(davinci_cpuidle_device, smp_processor_id());
@@ -116,32 +122,33 @@ static int __init davinci_cpuidle_probe(struct platform_device *pdev)
116 122
117 ddr2_reg_base = pdata->ddr2_ctlr_base; 123 ddr2_reg_base = pdata->ddr2_ctlr_base;
118 124
119 ret = cpuidle_register_driver(&davinci_idle_driver);
120 if (ret) {
121 dev_err(&pdev->dev, "failed to register driver\n");
122 return ret;
123 }
124
125 /* Wait for interrupt state */ 125 /* Wait for interrupt state */
126 device->states[0].enter = davinci_enter_idle; 126 driver->states[0].enter = davinci_enter_idle;
127 device->states[0].exit_latency = 1; 127 driver->states[0].exit_latency = 1;
128 device->states[0].target_residency = 10000; 128 driver->states[0].target_residency = 10000;
129 device->states[0].flags = CPUIDLE_FLAG_TIME_VALID; 129 driver->states[0].flags = CPUIDLE_FLAG_TIME_VALID;
130 strcpy(device->states[0].name, "WFI"); 130 strcpy(driver->states[0].name, "WFI");
131 strcpy(device->states[0].desc, "Wait for interrupt"); 131 strcpy(driver->states[0].desc, "Wait for interrupt");
132 132
133 /* Wait for interrupt and DDR self refresh state */ 133 /* Wait for interrupt and DDR self refresh state */
134 device->states[1].enter = davinci_enter_idle; 134 driver->states[1].enter = davinci_enter_idle;
135 device->states[1].exit_latency = 10; 135 driver->states[1].exit_latency = 10;
136 device->states[1].target_residency = 10000; 136 driver->states[1].target_residency = 10000;
137 device->states[1].flags = CPUIDLE_FLAG_TIME_VALID; 137 driver->states[1].flags = CPUIDLE_FLAG_TIME_VALID;
138 strcpy(device->states[1].name, "DDR SR"); 138 strcpy(driver->states[1].name, "DDR SR");
139 strcpy(device->states[1].desc, "WFI and DDR Self Refresh"); 139 strcpy(driver->states[1].desc, "WFI and DDR Self Refresh");
140 if (pdata->ddr2_pdown) 140 if (pdata->ddr2_pdown)
141 davinci_states[1].flags |= DAVINCI_CPUIDLE_FLAGS_DDR2_PWDN; 141 davinci_states[1].flags |= DAVINCI_CPUIDLE_FLAGS_DDR2_PWDN;
142 cpuidle_set_statedata(&device->states[1], &davinci_states[1]); 142 cpuidle_set_statedata(&device->states_usage[1], &davinci_states[1]);
143 143
144 device->state_count = DAVINCI_CPUIDLE_MAX_STATES; 144 device->state_count = DAVINCI_CPUIDLE_MAX_STATES;
145 driver->state_count = DAVINCI_CPUIDLE_MAX_STATES;
146
147 ret = cpuidle_register_driver(&davinci_idle_driver);
148 if (ret) {
149 dev_err(&pdev->dev, "failed to register driver\n");
150 return ret;
151 }
145 152
146 ret = cpuidle_register_device(device); 153 ret = cpuidle_register_device(device);
147 if (ret) { 154 if (ret) {
diff --git a/arch/arm/mach-exynos4/cpuidle.c b/arch/arm/mach-exynos4/cpuidle.c
index bf7e96f2793a..35f6502144ae 100644
--- a/arch/arm/mach-exynos4/cpuidle.c
+++ b/arch/arm/mach-exynos4/cpuidle.c
@@ -16,7 +16,8 @@
16#include <asm/proc-fns.h> 16#include <asm/proc-fns.h>
17 17
18static int exynos4_enter_idle(struct cpuidle_device *dev, 18static int exynos4_enter_idle(struct cpuidle_device *dev,
19 struct cpuidle_state *state); 19 struct cpuidle_driver *drv,
20 int index);
20 21
21static struct cpuidle_state exynos4_cpuidle_set[] = { 22static struct cpuidle_state exynos4_cpuidle_set[] = {
22 [0] = { 23 [0] = {
@@ -37,7 +38,8 @@ static struct cpuidle_driver exynos4_idle_driver = {
37}; 38};
38 39
39static int exynos4_enter_idle(struct cpuidle_device *dev, 40static int exynos4_enter_idle(struct cpuidle_device *dev,
40 struct cpuidle_state *state) 41 struct cpuidle_driver *drv,
42 int index)
41{ 43{
42 struct timeval before, after; 44 struct timeval before, after;
43 int idle_time; 45 int idle_time;
@@ -52,29 +54,31 @@ static int exynos4_enter_idle(struct cpuidle_device *dev,
52 idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC + 54 idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC +
53 (after.tv_usec - before.tv_usec); 55 (after.tv_usec - before.tv_usec);
54 56
55 return idle_time; 57 dev->last_residency = idle_time;
58 return index;
56} 59}
57 60
58static int __init exynos4_init_cpuidle(void) 61static int __init exynos4_init_cpuidle(void)
59{ 62{
60 int i, max_cpuidle_state, cpu_id; 63 int i, max_cpuidle_state, cpu_id;
61 struct cpuidle_device *device; 64 struct cpuidle_device *device;
62 65 struct cpuidle_driver *drv = &exynos4_idle_driver;
66
67 /* Setup cpuidle driver */
68 drv->state_count = (sizeof(exynos4_cpuidle_set) /
69 sizeof(struct cpuidle_state));
70 max_cpuidle_state = drv->state_count;
71 for (i = 0; i < max_cpuidle_state; i++) {
72 memcpy(&drv->states[i], &exynos4_cpuidle_set[i],
73 sizeof(struct cpuidle_state));
74 }
63 cpuidle_register_driver(&exynos4_idle_driver); 75 cpuidle_register_driver(&exynos4_idle_driver);
64 76
65 for_each_cpu(cpu_id, cpu_online_mask) { 77 for_each_cpu(cpu_id, cpu_online_mask) {
66 device = &per_cpu(exynos4_cpuidle_device, cpu_id); 78 device = &per_cpu(exynos4_cpuidle_device, cpu_id);
67 device->cpu = cpu_id; 79 device->cpu = cpu_id;
68 80
69 device->state_count = (sizeof(exynos4_cpuidle_set) / 81 device->state_count = drv->state_count;
70 sizeof(struct cpuidle_state));
71
72 max_cpuidle_state = device->state_count;
73
74 for (i = 0; i < max_cpuidle_state; i++) {
75 memcpy(&device->states[i], &exynos4_cpuidle_set[i],
76 sizeof(struct cpuidle_state));
77 }
78 82
79 if (cpuidle_register_device(device)) { 83 if (cpuidle_register_device(device)) {
80 printk(KERN_ERR "CPUidle register device failed\n,"); 84 printk(KERN_ERR "CPUidle register device failed\n,");
diff --git a/arch/arm/mach-kirkwood/cpuidle.c b/arch/arm/mach-kirkwood/cpuidle.c
index f68d33f1f396..ffd690dc3d33 100644
--- a/arch/arm/mach-kirkwood/cpuidle.c
+++ b/arch/arm/mach-kirkwood/cpuidle.c
@@ -32,17 +32,18 @@ static DEFINE_PER_CPU(struct cpuidle_device, kirkwood_cpuidle_device);
32 32
33/* Actual code that puts the SoC in different idle states */ 33/* Actual code that puts the SoC in different idle states */
34static int kirkwood_enter_idle(struct cpuidle_device *dev, 34static int kirkwood_enter_idle(struct cpuidle_device *dev,
35 struct cpuidle_state *state) 35 struct cpuidle_driver *drv,
36 int index)
36{ 37{
37 struct timeval before, after; 38 struct timeval before, after;
38 int idle_time; 39 int idle_time;
39 40
40 local_irq_disable(); 41 local_irq_disable();
41 do_gettimeofday(&before); 42 do_gettimeofday(&before);
42 if (state == &dev->states[0]) 43 if (index == 0)
43 /* Wait for interrupt state */ 44 /* Wait for interrupt state */
44 cpu_do_idle(); 45 cpu_do_idle();
45 else if (state == &dev->states[1]) { 46 else if (index == 1) {
46 /* 47 /*
47 * Following write will put DDR in self refresh. 48 * Following write will put DDR in self refresh.
48 * Note that we have 256 cycles before DDR puts it 49 * Note that we have 256 cycles before DDR puts it
@@ -57,35 +58,40 @@ static int kirkwood_enter_idle(struct cpuidle_device *dev,
57 local_irq_enable(); 58 local_irq_enable();
58 idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC + 59 idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC +
59 (after.tv_usec - before.tv_usec); 60 (after.tv_usec - before.tv_usec);
60 return idle_time; 61
62 /* Update last residency */
63 dev->last_residency = idle_time;
64
65 return index;
61} 66}
62 67
63/* Initialize CPU idle by registering the idle states */ 68/* Initialize CPU idle by registering the idle states */
64static int kirkwood_init_cpuidle(void) 69static int kirkwood_init_cpuidle(void)
65{ 70{
66 struct cpuidle_device *device; 71 struct cpuidle_device *device;
67 72 struct cpuidle_driver *driver = &kirkwood_idle_driver;
68 cpuidle_register_driver(&kirkwood_idle_driver);
69 73
70 device = &per_cpu(kirkwood_cpuidle_device, smp_processor_id()); 74 device = &per_cpu(kirkwood_cpuidle_device, smp_processor_id());
71 device->state_count = KIRKWOOD_MAX_STATES; 75 device->state_count = KIRKWOOD_MAX_STATES;
76 driver->state_count = KIRKWOOD_MAX_STATES;
72 77
73 /* Wait for interrupt state */ 78 /* Wait for interrupt state */
74 device->states[0].enter = kirkwood_enter_idle; 79 driver->states[0].enter = kirkwood_enter_idle;
75 device->states[0].exit_latency = 1; 80 driver->states[0].exit_latency = 1;
76 device->states[0].target_residency = 10000; 81 driver->states[0].target_residency = 10000;
77 device->states[0].flags = CPUIDLE_FLAG_TIME_VALID; 82 driver->states[0].flags = CPUIDLE_FLAG_TIME_VALID;
78 strcpy(device->states[0].name, "WFI"); 83 strcpy(driver->states[0].name, "WFI");
79 strcpy(device->states[0].desc, "Wait for interrupt"); 84 strcpy(driver->states[0].desc, "Wait for interrupt");
80 85
81 /* Wait for interrupt and DDR self refresh state */ 86 /* Wait for interrupt and DDR self refresh state */
82 device->states[1].enter = kirkwood_enter_idle; 87 driver->states[1].enter = kirkwood_enter_idle;
83 device->states[1].exit_latency = 10; 88 driver->states[1].exit_latency = 10;
84 device->states[1].target_residency = 10000; 89 driver->states[1].target_residency = 10000;
85 device->states[1].flags = CPUIDLE_FLAG_TIME_VALID; 90 driver->states[1].flags = CPUIDLE_FLAG_TIME_VALID;
86 strcpy(device->states[1].name, "DDR SR"); 91 strcpy(driver->states[1].name, "DDR SR");
87 strcpy(device->states[1].desc, "WFI and DDR Self Refresh"); 92 strcpy(driver->states[1].desc, "WFI and DDR Self Refresh");
88 93
94 cpuidle_register_driver(&kirkwood_idle_driver);
89 if (cpuidle_register_device(device)) { 95 if (cpuidle_register_device(device)) {
90 printk(KERN_ERR "kirkwood_init_cpuidle: Failed registering\n"); 96 printk(KERN_ERR "kirkwood_init_cpuidle: Failed registering\n");
91 return -EIO; 97 return -EIO;
diff --git a/arch/arm/mach-omap2/cpuidle34xx.c b/arch/arm/mach-omap2/cpuidle34xx.c
index 4bf6e6e8b100..1fe35c24fba2 100644
--- a/arch/arm/mach-omap2/cpuidle34xx.c
+++ b/arch/arm/mach-omap2/cpuidle34xx.c
@@ -88,17 +88,21 @@ static int _cpuidle_deny_idle(struct powerdomain *pwrdm,
88/** 88/**
89 * omap3_enter_idle - Programs OMAP3 to enter the specified state 89 * omap3_enter_idle - Programs OMAP3 to enter the specified state
90 * @dev: cpuidle device 90 * @dev: cpuidle device
91 * @state: The target state to be programmed 91 * @drv: cpuidle driver
92 * @index: the index of state to be entered
92 * 93 *
93 * Called from the CPUidle framework to program the device to the 94 * Called from the CPUidle framework to program the device to the
94 * specified target state selected by the governor. 95 * specified target state selected by the governor.
95 */ 96 */
96static int omap3_enter_idle(struct cpuidle_device *dev, 97static int omap3_enter_idle(struct cpuidle_device *dev,
97 struct cpuidle_state *state) 98 struct cpuidle_driver *drv,
99 int index)
98{ 100{
99 struct omap3_idle_statedata *cx = cpuidle_get_statedata(state); 101 struct omap3_idle_statedata *cx =
102 cpuidle_get_statedata(&dev->states_usage[index]);
100 struct timespec ts_preidle, ts_postidle, ts_idle; 103 struct timespec ts_preidle, ts_postidle, ts_idle;
101 u32 mpu_state = cx->mpu_state, core_state = cx->core_state; 104 u32 mpu_state = cx->mpu_state, core_state = cx->core_state;
105 int idle_time;
102 106
103 /* Used to keep track of the total time in idle */ 107 /* Used to keep track of the total time in idle */
104 getnstimeofday(&ts_preidle); 108 getnstimeofday(&ts_preidle);
@@ -113,7 +117,7 @@ static int omap3_enter_idle(struct cpuidle_device *dev,
113 goto return_sleep_time; 117 goto return_sleep_time;
114 118
115 /* Deny idle for C1 */ 119 /* Deny idle for C1 */
116 if (state == &dev->states[0]) { 120 if (index == 0) {
117 pwrdm_for_each_clkdm(mpu_pd, _cpuidle_deny_idle); 121 pwrdm_for_each_clkdm(mpu_pd, _cpuidle_deny_idle);
118 pwrdm_for_each_clkdm(core_pd, _cpuidle_deny_idle); 122 pwrdm_for_each_clkdm(core_pd, _cpuidle_deny_idle);
119 } 123 }
@@ -122,7 +126,7 @@ static int omap3_enter_idle(struct cpuidle_device *dev,
122 omap_sram_idle(); 126 omap_sram_idle();
123 127
124 /* Re-allow idle for C1 */ 128 /* Re-allow idle for C1 */
125 if (state == &dev->states[0]) { 129 if (index == 0) {
126 pwrdm_for_each_clkdm(mpu_pd, _cpuidle_allow_idle); 130 pwrdm_for_each_clkdm(mpu_pd, _cpuidle_allow_idle);
127 pwrdm_for_each_clkdm(core_pd, _cpuidle_allow_idle); 131 pwrdm_for_each_clkdm(core_pd, _cpuidle_allow_idle);
128 } 132 }
@@ -134,28 +138,38 @@ return_sleep_time:
134 local_irq_enable(); 138 local_irq_enable();
135 local_fiq_enable(); 139 local_fiq_enable();
136 140
137 return ts_idle.tv_nsec / NSEC_PER_USEC + ts_idle.tv_sec * USEC_PER_SEC; 141 idle_time = ts_idle.tv_nsec / NSEC_PER_USEC + ts_idle.tv_sec * \
142 USEC_PER_SEC;
143
144 /* Update cpuidle counters */
145 dev->last_residency = idle_time;
146
147 return index;
138} 148}
139 149
140/** 150/**
141 * next_valid_state - Find next valid C-state 151 * next_valid_state - Find next valid C-state
142 * @dev: cpuidle device 152 * @dev: cpuidle device
143 * @state: Currently selected C-state 153 * @drv: cpuidle driver
154 * @index: Index of currently selected c-state
144 * 155 *
145 * If the current state is valid, it is returned back to the caller. 156 * If the state corresponding to index is valid, index is returned back
146 * Else, this function searches for a lower c-state which is still 157 * to the caller. Else, this function searches for a lower c-state which is
147 * valid. 158 * still valid (as defined in omap3_power_states[]) and returns its index.
148 * 159 *
149 * A state is valid if the 'valid' field is enabled and 160 * A state is valid if the 'valid' field is enabled and
150 * if it satisfies the enable_off_mode condition. 161 * if it satisfies the enable_off_mode condition.
151 */ 162 */
152static struct cpuidle_state *next_valid_state(struct cpuidle_device *dev, 163static int next_valid_state(struct cpuidle_device *dev,
153 struct cpuidle_state *curr) 164 struct cpuidle_driver *drv,
165 int index)
154{ 166{
155 struct cpuidle_state *next = NULL; 167 struct cpuidle_state_usage *curr_usage = &dev->states_usage[index];
156 struct omap3_idle_statedata *cx = cpuidle_get_statedata(curr); 168 struct cpuidle_state *curr = &drv->states[index];
169 struct omap3_idle_statedata *cx = cpuidle_get_statedata(curr_usage);
157 u32 mpu_deepest_state = PWRDM_POWER_RET; 170 u32 mpu_deepest_state = PWRDM_POWER_RET;
158 u32 core_deepest_state = PWRDM_POWER_RET; 171 u32 core_deepest_state = PWRDM_POWER_RET;
172 int next_index = -1;
159 173
160 if (enable_off_mode) { 174 if (enable_off_mode) {
161 mpu_deepest_state = PWRDM_POWER_OFF; 175 mpu_deepest_state = PWRDM_POWER_OFF;
@@ -172,20 +186,20 @@ static struct cpuidle_state *next_valid_state(struct cpuidle_device *dev,
172 if ((cx->valid) && 186 if ((cx->valid) &&
173 (cx->mpu_state >= mpu_deepest_state) && 187 (cx->mpu_state >= mpu_deepest_state) &&
174 (cx->core_state >= core_deepest_state)) { 188 (cx->core_state >= core_deepest_state)) {
175 return curr; 189 return index;
176 } else { 190 } else {
177 int idx = OMAP3_NUM_STATES - 1; 191 int idx = OMAP3_NUM_STATES - 1;
178 192
179 /* Reach the current state starting at highest C-state */ 193 /* Reach the current state starting at highest C-state */
180 for (; idx >= 0; idx--) { 194 for (; idx >= 0; idx--) {
181 if (&dev->states[idx] == curr) { 195 if (&drv->states[idx] == curr) {
182 next = &dev->states[idx]; 196 next_index = idx;
183 break; 197 break;
184 } 198 }
185 } 199 }
186 200
187 /* Should never hit this condition */ 201 /* Should never hit this condition */
188 WARN_ON(next == NULL); 202 WARN_ON(next_index == -1);
189 203
190 /* 204 /*
191 * Drop to next valid state. 205 * Drop to next valid state.
@@ -193,41 +207,44 @@ static struct cpuidle_state *next_valid_state(struct cpuidle_device *dev,
193 */ 207 */
194 idx--; 208 idx--;
195 for (; idx >= 0; idx--) { 209 for (; idx >= 0; idx--) {
196 cx = cpuidle_get_statedata(&dev->states[idx]); 210 cx = cpuidle_get_statedata(&dev->states_usage[idx]);
197 if ((cx->valid) && 211 if ((cx->valid) &&
198 (cx->mpu_state >= mpu_deepest_state) && 212 (cx->mpu_state >= mpu_deepest_state) &&
199 (cx->core_state >= core_deepest_state)) { 213 (cx->core_state >= core_deepest_state)) {
200 next = &dev->states[idx]; 214 next_index = idx;
201 break; 215 break;
202 } 216 }
203 } 217 }
204 /* 218 /*
205 * C1 is always valid. 219 * C1 is always valid.
206 * So, no need to check for 'next==NULL' outside this loop. 220 * So, no need to check for 'next_index == -1' outside
221 * this loop.
207 */ 222 */
208 } 223 }
209 224
210 return next; 225 return next_index;
211} 226}
212 227
213/** 228/**
214 * omap3_enter_idle_bm - Checks for any bus activity 229 * omap3_enter_idle_bm - Checks for any bus activity
215 * @dev: cpuidle device 230 * @dev: cpuidle device
216 * @state: The target state to be programmed 231 * @drv: cpuidle driver
232 * @index: array index of target state to be programmed
217 * 233 *
218 * This function checks for any pending activity and then programs 234 * This function checks for any pending activity and then programs
219 * the device to the specified or a safer state. 235 * the device to the specified or a safer state.
220 */ 236 */
221static int omap3_enter_idle_bm(struct cpuidle_device *dev, 237static int omap3_enter_idle_bm(struct cpuidle_device *dev,
222 struct cpuidle_state *state) 238 struct cpuidle_driver *drv,
239 int index)
223{ 240{
224 struct cpuidle_state *new_state; 241 int new_state_idx;
225 u32 core_next_state, per_next_state = 0, per_saved_state = 0, cam_state; 242 u32 core_next_state, per_next_state = 0, per_saved_state = 0, cam_state;
226 struct omap3_idle_statedata *cx; 243 struct omap3_idle_statedata *cx;
227 int ret; 244 int ret;
228 245
229 if (!omap3_can_sleep()) { 246 if (!omap3_can_sleep()) {
230 new_state = dev->safe_state; 247 new_state_idx = drv->safe_state_index;
231 goto select_state; 248 goto select_state;
232 } 249 }
233 250
@@ -237,7 +254,7 @@ static int omap3_enter_idle_bm(struct cpuidle_device *dev,
237 */ 254 */
238 cam_state = pwrdm_read_pwrst(cam_pd); 255 cam_state = pwrdm_read_pwrst(cam_pd);
239 if (cam_state == PWRDM_POWER_ON) { 256 if (cam_state == PWRDM_POWER_ON) {
240 new_state = dev->safe_state; 257 new_state_idx = drv->safe_state_index;
241 goto select_state; 258 goto select_state;
242 } 259 }
243 260
@@ -253,7 +270,7 @@ static int omap3_enter_idle_bm(struct cpuidle_device *dev,
253 * Prevent PER off if CORE is not in retention or off as this 270 * Prevent PER off if CORE is not in retention or off as this
254 * would disable PER wakeups completely. 271 * would disable PER wakeups completely.
255 */ 272 */
256 cx = cpuidle_get_statedata(state); 273 cx = cpuidle_get_statedata(&dev->states_usage[index]);
257 core_next_state = cx->core_state; 274 core_next_state = cx->core_state;
258 per_next_state = per_saved_state = pwrdm_read_next_pwrst(per_pd); 275 per_next_state = per_saved_state = pwrdm_read_next_pwrst(per_pd);
259 if ((per_next_state == PWRDM_POWER_OFF) && 276 if ((per_next_state == PWRDM_POWER_OFF) &&
@@ -264,11 +281,10 @@ static int omap3_enter_idle_bm(struct cpuidle_device *dev,
264 if (per_next_state != per_saved_state) 281 if (per_next_state != per_saved_state)
265 pwrdm_set_next_pwrst(per_pd, per_next_state); 282 pwrdm_set_next_pwrst(per_pd, per_next_state);
266 283
267 new_state = next_valid_state(dev, state); 284 new_state_idx = next_valid_state(dev, drv, index);
268 285
269select_state: 286select_state:
270 dev->last_state = new_state; 287 ret = omap3_enter_idle(dev, drv, new_state_idx);
271 ret = omap3_enter_idle(dev, new_state);
272 288
273 /* Restore original PER state if it was modified */ 289 /* Restore original PER state if it was modified */
274 if (per_next_state != per_saved_state) 290 if (per_next_state != per_saved_state)
@@ -301,22 +317,31 @@ struct cpuidle_driver omap3_idle_driver = {
301 .owner = THIS_MODULE, 317 .owner = THIS_MODULE,
302}; 318};
303 319
304/* Helper to fill the C-state common data and register the driver_data */ 320/* Helper to fill the C-state common data*/
305static inline struct omap3_idle_statedata *_fill_cstate( 321static inline void _fill_cstate(struct cpuidle_driver *drv,
306 struct cpuidle_device *dev,
307 int idx, const char *descr) 322 int idx, const char *descr)
308{ 323{
309 struct omap3_idle_statedata *cx = &omap3_idle_data[idx]; 324 struct cpuidle_state *state = &drv->states[idx];
310 struct cpuidle_state *state = &dev->states[idx];
311 325
312 state->exit_latency = cpuidle_params_table[idx].exit_latency; 326 state->exit_latency = cpuidle_params_table[idx].exit_latency;
313 state->target_residency = cpuidle_params_table[idx].target_residency; 327 state->target_residency = cpuidle_params_table[idx].target_residency;
314 state->flags = CPUIDLE_FLAG_TIME_VALID; 328 state->flags = CPUIDLE_FLAG_TIME_VALID;
315 state->enter = omap3_enter_idle_bm; 329 state->enter = omap3_enter_idle_bm;
316 cx->valid = cpuidle_params_table[idx].valid;
317 sprintf(state->name, "C%d", idx + 1); 330 sprintf(state->name, "C%d", idx + 1);
318 strncpy(state->desc, descr, CPUIDLE_DESC_LEN); 331 strncpy(state->desc, descr, CPUIDLE_DESC_LEN);
319 cpuidle_set_statedata(state, cx); 332
333}
334
335/* Helper to register the driver_data */
336static inline struct omap3_idle_statedata *_fill_cstate_usage(
337 struct cpuidle_device *dev,
338 int idx)
339{
340 struct omap3_idle_statedata *cx = &omap3_idle_data[idx];
341 struct cpuidle_state_usage *state_usage = &dev->states_usage[idx];
342
343 cx->valid = cpuidle_params_table[idx].valid;
344 cpuidle_set_statedata(state_usage, cx);
320 345
321 return cx; 346 return cx;
322} 347}
@@ -330,6 +355,7 @@ static inline struct omap3_idle_statedata *_fill_cstate(
330int __init omap3_idle_init(void) 355int __init omap3_idle_init(void)
331{ 356{
332 struct cpuidle_device *dev; 357 struct cpuidle_device *dev;
358 struct cpuidle_driver *drv = &omap3_idle_driver;
333 struct omap3_idle_statedata *cx; 359 struct omap3_idle_statedata *cx;
334 360
335 mpu_pd = pwrdm_lookup("mpu_pwrdm"); 361 mpu_pd = pwrdm_lookup("mpu_pwrdm");
@@ -337,44 +363,52 @@ int __init omap3_idle_init(void)
337 per_pd = pwrdm_lookup("per_pwrdm"); 363 per_pd = pwrdm_lookup("per_pwrdm");
338 cam_pd = pwrdm_lookup("cam_pwrdm"); 364 cam_pd = pwrdm_lookup("cam_pwrdm");
339 365
340 cpuidle_register_driver(&omap3_idle_driver); 366
367 drv->safe_state_index = -1;
341 dev = &per_cpu(omap3_idle_dev, smp_processor_id()); 368 dev = &per_cpu(omap3_idle_dev, smp_processor_id());
342 369
343 /* C1 . MPU WFI + Core active */ 370 /* C1 . MPU WFI + Core active */
344 cx = _fill_cstate(dev, 0, "MPU ON + CORE ON"); 371 _fill_cstate(drv, 0, "MPU ON + CORE ON");
345 (&dev->states[0])->enter = omap3_enter_idle; 372 (&drv->states[0])->enter = omap3_enter_idle;
346 dev->safe_state = &dev->states[0]; 373 drv->safe_state_index = 0;
374 cx = _fill_cstate_usage(dev, 0);
347 cx->valid = 1; /* C1 is always valid */ 375 cx->valid = 1; /* C1 is always valid */
348 cx->mpu_state = PWRDM_POWER_ON; 376 cx->mpu_state = PWRDM_POWER_ON;
349 cx->core_state = PWRDM_POWER_ON; 377 cx->core_state = PWRDM_POWER_ON;
350 378
351 /* C2 . MPU WFI + Core inactive */ 379 /* C2 . MPU WFI + Core inactive */
352 cx = _fill_cstate(dev, 1, "MPU ON + CORE ON"); 380 _fill_cstate(drv, 1, "MPU ON + CORE ON");
381 cx = _fill_cstate_usage(dev, 1);
353 cx->mpu_state = PWRDM_POWER_ON; 382 cx->mpu_state = PWRDM_POWER_ON;
354 cx->core_state = PWRDM_POWER_ON; 383 cx->core_state = PWRDM_POWER_ON;
355 384
356 /* C3 . MPU CSWR + Core inactive */ 385 /* C3 . MPU CSWR + Core inactive */
357 cx = _fill_cstate(dev, 2, "MPU RET + CORE ON"); 386 _fill_cstate(drv, 2, "MPU RET + CORE ON");
387 cx = _fill_cstate_usage(dev, 2);
358 cx->mpu_state = PWRDM_POWER_RET; 388 cx->mpu_state = PWRDM_POWER_RET;
359 cx->core_state = PWRDM_POWER_ON; 389 cx->core_state = PWRDM_POWER_ON;
360 390
361 /* C4 . MPU OFF + Core inactive */ 391 /* C4 . MPU OFF + Core inactive */
362 cx = _fill_cstate(dev, 3, "MPU OFF + CORE ON"); 392 _fill_cstate(drv, 3, "MPU OFF + CORE ON");
393 cx = _fill_cstate_usage(dev, 3);
363 cx->mpu_state = PWRDM_POWER_OFF; 394 cx->mpu_state = PWRDM_POWER_OFF;
364 cx->core_state = PWRDM_POWER_ON; 395 cx->core_state = PWRDM_POWER_ON;
365 396
366 /* C5 . MPU RET + Core RET */ 397 /* C5 . MPU RET + Core RET */
367 cx = _fill_cstate(dev, 4, "MPU RET + CORE RET"); 398 _fill_cstate(drv, 4, "MPU RET + CORE RET");
399 cx = _fill_cstate_usage(dev, 4);
368 cx->mpu_state = PWRDM_POWER_RET; 400 cx->mpu_state = PWRDM_POWER_RET;
369 cx->core_state = PWRDM_POWER_RET; 401 cx->core_state = PWRDM_POWER_RET;
370 402
371 /* C6 . MPU OFF + Core RET */ 403 /* C6 . MPU OFF + Core RET */
372 cx = _fill_cstate(dev, 5, "MPU OFF + CORE RET"); 404 _fill_cstate(drv, 5, "MPU OFF + CORE RET");
405 cx = _fill_cstate_usage(dev, 5);
373 cx->mpu_state = PWRDM_POWER_OFF; 406 cx->mpu_state = PWRDM_POWER_OFF;
374 cx->core_state = PWRDM_POWER_RET; 407 cx->core_state = PWRDM_POWER_RET;
375 408
376 /* C7 . MPU OFF + Core OFF */ 409 /* C7 . MPU OFF + Core OFF */
377 cx = _fill_cstate(dev, 6, "MPU OFF + CORE OFF"); 410 _fill_cstate(drv, 6, "MPU OFF + CORE OFF");
411 cx = _fill_cstate_usage(dev, 6);
378 /* 412 /*
379 * Erratum i583: implementation for ES rev < Es1.2 on 3630. We cannot 413 * Erratum i583: implementation for ES rev < Es1.2 on 3630. We cannot
380 * enable OFF mode in a stable form for previous revisions. 414 * enable OFF mode in a stable form for previous revisions.
@@ -388,6 +422,9 @@ int __init omap3_idle_init(void)
388 cx->mpu_state = PWRDM_POWER_OFF; 422 cx->mpu_state = PWRDM_POWER_OFF;
389 cx->core_state = PWRDM_POWER_OFF; 423 cx->core_state = PWRDM_POWER_OFF;
390 424
425 drv->state_count = OMAP3_NUM_STATES;
426 cpuidle_register_driver(&omap3_idle_driver);
427
391 dev->state_count = OMAP3_NUM_STATES; 428 dev->state_count = OMAP3_NUM_STATES;
392 if (cpuidle_register_device(dev)) { 429 if (cpuidle_register_device(dev)) {
393 printk(KERN_ERR "%s: CPUidle register device failed\n", 430 printk(KERN_ERR "%s: CPUidle register device failed\n",
diff --git a/arch/sh/kernel/cpu/shmobile/cpuidle.c b/arch/sh/kernel/cpu/shmobile/cpuidle.c
index e4469e7233cb..ad1012ad6b42 100644
--- a/arch/sh/kernel/cpu/shmobile/cpuidle.c
+++ b/arch/sh/kernel/cpu/shmobile/cpuidle.c
@@ -25,11 +25,12 @@ static unsigned long cpuidle_mode[] = {
25}; 25};
26 26
27static int cpuidle_sleep_enter(struct cpuidle_device *dev, 27static int cpuidle_sleep_enter(struct cpuidle_device *dev,
28 struct cpuidle_state *state) 28 struct cpuidle_driver *drv,
29 int index)
29{ 30{
30 unsigned long allowed_mode = arch_hwblk_sleep_mode(); 31 unsigned long allowed_mode = arch_hwblk_sleep_mode();
31 ktime_t before, after; 32 ktime_t before, after;
32 int requested_state = state - &dev->states[0]; 33 int requested_state = index;
33 int allowed_state; 34 int allowed_state;
34 int k; 35 int k;
35 36
@@ -46,11 +47,13 @@ static int cpuidle_sleep_enter(struct cpuidle_device *dev,
46 */ 47 */
47 k = min_t(int, allowed_state, requested_state); 48 k = min_t(int, allowed_state, requested_state);
48 49
49 dev->last_state = &dev->states[k];
50 before = ktime_get(); 50 before = ktime_get();
51 sh_mobile_call_standby(cpuidle_mode[k]); 51 sh_mobile_call_standby(cpuidle_mode[k]);
52 after = ktime_get(); 52 after = ktime_get();
53 return ktime_to_ns(ktime_sub(after, before)) >> 10; 53
54 dev->last_residency = (int)ktime_to_ns(ktime_sub(after, before)) >> 10;
55
56 return k;
54} 57}
55 58
56static struct cpuidle_device cpuidle_dev; 59static struct cpuidle_device cpuidle_dev;
@@ -62,19 +65,19 @@ static struct cpuidle_driver cpuidle_driver = {
62void sh_mobile_setup_cpuidle(void) 65void sh_mobile_setup_cpuidle(void)
63{ 66{
64 struct cpuidle_device *dev = &cpuidle_dev; 67 struct cpuidle_device *dev = &cpuidle_dev;
68 struct cpuidle_driver *drv = &cpuidle_driver;
65 struct cpuidle_state *state; 69 struct cpuidle_state *state;
66 int i; 70 int i;
67 71
68 cpuidle_register_driver(&cpuidle_driver);
69 72
70 for (i = 0; i < CPUIDLE_STATE_MAX; i++) { 73 for (i = 0; i < CPUIDLE_STATE_MAX; i++) {
71 dev->states[i].name[0] = '\0'; 74 drv->states[i].name[0] = '\0';
72 dev->states[i].desc[0] = '\0'; 75 drv->states[i].desc[0] = '\0';
73 } 76 }
74 77
75 i = CPUIDLE_DRIVER_STATE_START; 78 i = CPUIDLE_DRIVER_STATE_START;
76 79
77 state = &dev->states[i++]; 80 state = &drv->states[i++];
78 snprintf(state->name, CPUIDLE_NAME_LEN, "C1"); 81 snprintf(state->name, CPUIDLE_NAME_LEN, "C1");
79 strncpy(state->desc, "SuperH Sleep Mode", CPUIDLE_DESC_LEN); 82 strncpy(state->desc, "SuperH Sleep Mode", CPUIDLE_DESC_LEN);
80 state->exit_latency = 1; 83 state->exit_latency = 1;
@@ -84,10 +87,10 @@ void sh_mobile_setup_cpuidle(void)
84 state->flags |= CPUIDLE_FLAG_TIME_VALID; 87 state->flags |= CPUIDLE_FLAG_TIME_VALID;
85 state->enter = cpuidle_sleep_enter; 88 state->enter = cpuidle_sleep_enter;
86 89
87 dev->safe_state = state; 90 drv->safe_state_index = i-1;
88 91
89 if (sh_mobile_sleep_supported & SUSP_SH_SF) { 92 if (sh_mobile_sleep_supported & SUSP_SH_SF) {
90 state = &dev->states[i++]; 93 state = &drv->states[i++];
91 snprintf(state->name, CPUIDLE_NAME_LEN, "C2"); 94 snprintf(state->name, CPUIDLE_NAME_LEN, "C2");
92 strncpy(state->desc, "SuperH Sleep Mode [SF]", 95 strncpy(state->desc, "SuperH Sleep Mode [SF]",
93 CPUIDLE_DESC_LEN); 96 CPUIDLE_DESC_LEN);
@@ -100,7 +103,7 @@ void sh_mobile_setup_cpuidle(void)
100 } 103 }
101 104
102 if (sh_mobile_sleep_supported & SUSP_SH_STANDBY) { 105 if (sh_mobile_sleep_supported & SUSP_SH_STANDBY) {
103 state = &dev->states[i++]; 106 state = &drv->states[i++];
104 snprintf(state->name, CPUIDLE_NAME_LEN, "C3"); 107 snprintf(state->name, CPUIDLE_NAME_LEN, "C3");
105 strncpy(state->desc, "SuperH Mobile Standby Mode [SF]", 108 strncpy(state->desc, "SuperH Mobile Standby Mode [SF]",
106 CPUIDLE_DESC_LEN); 109 CPUIDLE_DESC_LEN);
@@ -112,7 +115,10 @@ void sh_mobile_setup_cpuidle(void)
112 state->enter = cpuidle_sleep_enter; 115 state->enter = cpuidle_sleep_enter;
113 } 116 }
114 117
118 drv->state_count = i;
115 dev->state_count = i; 119 dev->state_count = i;
116 120
121 cpuidle_register_driver(&cpuidle_driver);
122
117 cpuidle_register_device(dev); 123 cpuidle_register_device(dev);
118} 124}
diff --git a/arch/x86/platform/mrst/pmu.c b/arch/x86/platform/mrst/pmu.c
index 9281da7d91bd..c0ac06da57ac 100644
--- a/arch/x86/platform/mrst/pmu.c
+++ b/arch/x86/platform/mrst/pmu.c
@@ -70,7 +70,7 @@ static struct mrst_device mrst_devs[] = {
70/* 24 */ { 0x4110, 0 }, /* Lincroft */ 70/* 24 */ { 0x4110, 0 }, /* Lincroft */
71}; 71};
72 72
73/* n.b. We ignore PCI-id 0x815 in LSS9 b/c MeeGo has no driver for it */ 73/* n.b. We ignore PCI-id 0x815 in LSS9 b/c Linux has no driver for it */
74static u16 mrst_lss9_pci_ids[] = {0x080a, 0x0814, 0}; 74static u16 mrst_lss9_pci_ids[] = {0x080a, 0x0814, 0};
75static u16 mrst_lss10_pci_ids[] = {0x0800, 0x0801, 0x0802, 0x0803, 75static u16 mrst_lss10_pci_ids[] = {0x0800, 0x0801, 0x0802, 0x0803,
76 0x0804, 0x0805, 0x080f, 0}; 76 0x0804, 0x0805, 0x080f, 0};
diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index a4e0f1ba6040..9d7bc9f6b6cc 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -426,7 +426,7 @@ static int acpi_cpu_soft_notify(struct notifier_block *nfb,
426 426
427 if (action == CPU_ONLINE && pr) { 427 if (action == CPU_ONLINE && pr) {
428 acpi_processor_ppc_has_changed(pr, 0); 428 acpi_processor_ppc_has_changed(pr, 0);
429 acpi_processor_cst_has_changed(pr); 429 acpi_processor_hotplug(pr);
430 acpi_processor_reevaluate_tstate(pr, action); 430 acpi_processor_reevaluate_tstate(pr, action);
431 acpi_processor_tstate_has_changed(pr); 431 acpi_processor_tstate_has_changed(pr);
432 } 432 }
@@ -503,8 +503,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
503 acpi_processor_get_throttling_info(pr); 503 acpi_processor_get_throttling_info(pr);
504 acpi_processor_get_limit_info(pr); 504 acpi_processor_get_limit_info(pr);
505 505
506 506 if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver)
507 if (cpuidle_get_driver() == &acpi_idle_driver)
508 acpi_processor_power_init(pr, device); 507 acpi_processor_power_init(pr, device);
509 508
510 pr->cdev = thermal_cooling_device_register("Processor", device, 509 pr->cdev = thermal_cooling_device_register("Processor", device,
@@ -800,17 +799,9 @@ static int __init acpi_processor_init(void)
800 799
801 memset(&errata, 0, sizeof(errata)); 800 memset(&errata, 0, sizeof(errata));
802 801
803 if (!cpuidle_register_driver(&acpi_idle_driver)) {
804 printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n",
805 acpi_idle_driver.name);
806 } else {
807 printk(KERN_DEBUG "ACPI: acpi_idle yielding to %s\n",
808 cpuidle_get_driver()->name);
809 }
810
811 result = acpi_bus_register_driver(&acpi_processor_driver); 802 result = acpi_bus_register_driver(&acpi_processor_driver);
812 if (result < 0) 803 if (result < 0)
813 goto out_cpuidle; 804 return result;
814 805
815 acpi_processor_install_hotplug_notify(); 806 acpi_processor_install_hotplug_notify();
816 807
@@ -821,11 +812,6 @@ static int __init acpi_processor_init(void)
821 acpi_processor_throttling_init(); 812 acpi_processor_throttling_init();
822 813
823 return 0; 814 return 0;
824
825out_cpuidle:
826 cpuidle_unregister_driver(&acpi_idle_driver);
827
828 return result;
829} 815}
830 816
831static void __exit acpi_processor_exit(void) 817static void __exit acpi_processor_exit(void)
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 431ab11c8c1b..24fe3afa7119 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -741,22 +741,25 @@ static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx)
741/** 741/**
742 * acpi_idle_enter_c1 - enters an ACPI C1 state-type 742 * acpi_idle_enter_c1 - enters an ACPI C1 state-type
743 * @dev: the target CPU 743 * @dev: the target CPU
744 * @state: the state data 744 * @drv: cpuidle driver containing cpuidle state info
745 * @index: index of target state
745 * 746 *
746 * This is equivalent to the HALT instruction. 747 * This is equivalent to the HALT instruction.
747 */ 748 */
748static int acpi_idle_enter_c1(struct cpuidle_device *dev, 749static int acpi_idle_enter_c1(struct cpuidle_device *dev,
749 struct cpuidle_state *state) 750 struct cpuidle_driver *drv, int index)
750{ 751{
751 ktime_t kt1, kt2; 752 ktime_t kt1, kt2;
752 s64 idle_time; 753 s64 idle_time;
753 struct acpi_processor *pr; 754 struct acpi_processor *pr;
754 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 755 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
756 struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
755 757
756 pr = __this_cpu_read(processors); 758 pr = __this_cpu_read(processors);
759 dev->last_residency = 0;
757 760
758 if (unlikely(!pr)) 761 if (unlikely(!pr))
759 return 0; 762 return -EINVAL;
760 763
761 local_irq_disable(); 764 local_irq_disable();
762 765
@@ -764,7 +767,7 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev,
764 if (acpi_idle_suspend) { 767 if (acpi_idle_suspend) {
765 local_irq_enable(); 768 local_irq_enable();
766 cpu_relax(); 769 cpu_relax();
767 return 0; 770 return -EINVAL;
768 } 771 }
769 772
770 lapic_timer_state_broadcast(pr, cx, 1); 773 lapic_timer_state_broadcast(pr, cx, 1);
@@ -773,37 +776,47 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev,
773 kt2 = ktime_get_real(); 776 kt2 = ktime_get_real();
774 idle_time = ktime_to_us(ktime_sub(kt2, kt1)); 777 idle_time = ktime_to_us(ktime_sub(kt2, kt1));
775 778
779 /* Update device last_residency*/
780 dev->last_residency = (int)idle_time;
781
776 local_irq_enable(); 782 local_irq_enable();
777 cx->usage++; 783 cx->usage++;
778 lapic_timer_state_broadcast(pr, cx, 0); 784 lapic_timer_state_broadcast(pr, cx, 0);
779 785
780 return idle_time; 786 return index;
781} 787}
782 788
783/** 789/**
784 * acpi_idle_enter_simple - enters an ACPI state without BM handling 790 * acpi_idle_enter_simple - enters an ACPI state without BM handling
785 * @dev: the target CPU 791 * @dev: the target CPU
786 * @state: the state data 792 * @drv: cpuidle driver with cpuidle state information
793 * @index: the index of suggested state
787 */ 794 */
788static int acpi_idle_enter_simple(struct cpuidle_device *dev, 795static int acpi_idle_enter_simple(struct cpuidle_device *dev,
789 struct cpuidle_state *state) 796 struct cpuidle_driver *drv, int index)
790{ 797{
791 struct acpi_processor *pr; 798 struct acpi_processor *pr;
792 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 799 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
800 struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
793 ktime_t kt1, kt2; 801 ktime_t kt1, kt2;
794 s64 idle_time_ns; 802 s64 idle_time_ns;
795 s64 idle_time; 803 s64 idle_time;
796 804
797 pr = __this_cpu_read(processors); 805 pr = __this_cpu_read(processors);
806 dev->last_residency = 0;
798 807
799 if (unlikely(!pr)) 808 if (unlikely(!pr))
800 return 0; 809 return -EINVAL;
801
802 if (acpi_idle_suspend)
803 return(acpi_idle_enter_c1(dev, state));
804 810
805 local_irq_disable(); 811 local_irq_disable();
806 812
813 if (acpi_idle_suspend) {
814 local_irq_enable();
815 cpu_relax();
816 return -EINVAL;
817 }
818
819
807 if (cx->entry_method != ACPI_CSTATE_FFH) { 820 if (cx->entry_method != ACPI_CSTATE_FFH) {
808 current_thread_info()->status &= ~TS_POLLING; 821 current_thread_info()->status &= ~TS_POLLING;
809 /* 822 /*
@@ -815,7 +828,7 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
815 if (unlikely(need_resched())) { 828 if (unlikely(need_resched())) {
816 current_thread_info()->status |= TS_POLLING; 829 current_thread_info()->status |= TS_POLLING;
817 local_irq_enable(); 830 local_irq_enable();
818 return 0; 831 return -EINVAL;
819 } 832 }
820 } 833 }
821 834
@@ -837,6 +850,9 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
837 idle_time = idle_time_ns; 850 idle_time = idle_time_ns;
838 do_div(idle_time, NSEC_PER_USEC); 851 do_div(idle_time, NSEC_PER_USEC);
839 852
853 /* Update device last_residency*/
854 dev->last_residency = (int)idle_time;
855
840 /* Tell the scheduler how much we idled: */ 856 /* Tell the scheduler how much we idled: */
841 sched_clock_idle_wakeup_event(idle_time_ns); 857 sched_clock_idle_wakeup_event(idle_time_ns);
842 858
@@ -848,7 +864,7 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
848 864
849 lapic_timer_state_broadcast(pr, cx, 0); 865 lapic_timer_state_broadcast(pr, cx, 0);
850 cx->time += idle_time; 866 cx->time += idle_time;
851 return idle_time; 867 return index;
852} 868}
853 869
854static int c3_cpu_count; 870static int c3_cpu_count;
@@ -857,37 +873,43 @@ static DEFINE_SPINLOCK(c3_lock);
857/** 873/**
858 * acpi_idle_enter_bm - enters C3 with proper BM handling 874 * acpi_idle_enter_bm - enters C3 with proper BM handling
859 * @dev: the target CPU 875 * @dev: the target CPU
860 * @state: the state data 876 * @drv: cpuidle driver containing state data
877 * @index: the index of suggested state
861 * 878 *
862 * If BM is detected, the deepest non-C3 idle state is entered instead. 879 * If BM is detected, the deepest non-C3 idle state is entered instead.
863 */ 880 */
864static int acpi_idle_enter_bm(struct cpuidle_device *dev, 881static int acpi_idle_enter_bm(struct cpuidle_device *dev,
865 struct cpuidle_state *state) 882 struct cpuidle_driver *drv, int index)
866{ 883{
867 struct acpi_processor *pr; 884 struct acpi_processor *pr;
868 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 885 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
886 struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
869 ktime_t kt1, kt2; 887 ktime_t kt1, kt2;
870 s64 idle_time_ns; 888 s64 idle_time_ns;
871 s64 idle_time; 889 s64 idle_time;
872 890
873 891
874 pr = __this_cpu_read(processors); 892 pr = __this_cpu_read(processors);
893 dev->last_residency = 0;
875 894
876 if (unlikely(!pr)) 895 if (unlikely(!pr))
877 return 0; 896 return -EINVAL;
897
878 898
879 if (acpi_idle_suspend) 899 if (acpi_idle_suspend) {
880 return(acpi_idle_enter_c1(dev, state)); 900 cpu_relax();
901 return -EINVAL;
902 }
881 903
882 if (!cx->bm_sts_skip && acpi_idle_bm_check()) { 904 if (!cx->bm_sts_skip && acpi_idle_bm_check()) {
883 if (dev->safe_state) { 905 if (drv->safe_state_index >= 0) {
884 dev->last_state = dev->safe_state; 906 return drv->states[drv->safe_state_index].enter(dev,
885 return dev->safe_state->enter(dev, dev->safe_state); 907 drv, drv->safe_state_index);
886 } else { 908 } else {
887 local_irq_disable(); 909 local_irq_disable();
888 acpi_safe_halt(); 910 acpi_safe_halt();
889 local_irq_enable(); 911 local_irq_enable();
890 return 0; 912 return -EINVAL;
891 } 913 }
892 } 914 }
893 915
@@ -904,7 +926,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
904 if (unlikely(need_resched())) { 926 if (unlikely(need_resched())) {
905 current_thread_info()->status |= TS_POLLING; 927 current_thread_info()->status |= TS_POLLING;
906 local_irq_enable(); 928 local_irq_enable();
907 return 0; 929 return -EINVAL;
908 } 930 }
909 } 931 }
910 932
@@ -954,6 +976,9 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
954 idle_time = idle_time_ns; 976 idle_time = idle_time_ns;
955 do_div(idle_time, NSEC_PER_USEC); 977 do_div(idle_time, NSEC_PER_USEC);
956 978
979 /* Update device last_residency*/
980 dev->last_residency = (int)idle_time;
981
957 /* Tell the scheduler how much we idled: */ 982 /* Tell the scheduler how much we idled: */
958 sched_clock_idle_wakeup_event(idle_time_ns); 983 sched_clock_idle_wakeup_event(idle_time_ns);
959 984
@@ -965,7 +990,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
965 990
966 lapic_timer_state_broadcast(pr, cx, 0); 991 lapic_timer_state_broadcast(pr, cx, 0);
967 cx->time += idle_time; 992 cx->time += idle_time;
968 return idle_time; 993 return index;
969} 994}
970 995
971struct cpuidle_driver acpi_idle_driver = { 996struct cpuidle_driver acpi_idle_driver = {
@@ -974,14 +999,16 @@ struct cpuidle_driver acpi_idle_driver = {
974}; 999};
975 1000
976/** 1001/**
977 * acpi_processor_setup_cpuidle - prepares and configures CPUIDLE 1002 * acpi_processor_setup_cpuidle_cx - prepares and configures CPUIDLE
1003 * device i.e. per-cpu data
1004 *
978 * @pr: the ACPI processor 1005 * @pr: the ACPI processor
979 */ 1006 */
980static int acpi_processor_setup_cpuidle(struct acpi_processor *pr) 1007static int acpi_processor_setup_cpuidle_cx(struct acpi_processor *pr)
981{ 1008{
982 int i, count = CPUIDLE_DRIVER_STATE_START; 1009 int i, count = CPUIDLE_DRIVER_STATE_START;
983 struct acpi_processor_cx *cx; 1010 struct acpi_processor_cx *cx;
984 struct cpuidle_state *state; 1011 struct cpuidle_state_usage *state_usage;
985 struct cpuidle_device *dev = &pr->power.dev; 1012 struct cpuidle_device *dev = &pr->power.dev;
986 1013
987 if (!pr->flags.power_setup_done) 1014 if (!pr->flags.power_setup_done)
@@ -992,9 +1019,62 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
992 } 1019 }
993 1020
994 dev->cpu = pr->id; 1021 dev->cpu = pr->id;
1022
1023 if (max_cstate == 0)
1024 max_cstate = 1;
1025
1026 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
1027 cx = &pr->power.states[i];
1028 state_usage = &dev->states_usage[count];
1029
1030 if (!cx->valid)
1031 continue;
1032
1033#ifdef CONFIG_HOTPLUG_CPU
1034 if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
1035 !pr->flags.has_cst &&
1036 !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
1037 continue;
1038#endif
1039
1040 cpuidle_set_statedata(state_usage, cx);
1041
1042 count++;
1043 if (count == CPUIDLE_STATE_MAX)
1044 break;
1045 }
1046
1047 dev->state_count = count;
1048
1049 if (!count)
1050 return -EINVAL;
1051
1052 return 0;
1053}
1054
1055/**
1056 * acpi_processor_setup_cpuidle states- prepares and configures cpuidle
1057 * global state data i.e. idle routines
1058 *
1059 * @pr: the ACPI processor
1060 */
1061static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
1062{
1063 int i, count = CPUIDLE_DRIVER_STATE_START;
1064 struct acpi_processor_cx *cx;
1065 struct cpuidle_state *state;
1066 struct cpuidle_driver *drv = &acpi_idle_driver;
1067
1068 if (!pr->flags.power_setup_done)
1069 return -EINVAL;
1070
1071 if (pr->flags.power == 0)
1072 return -EINVAL;
1073
1074 drv->safe_state_index = -1;
995 for (i = 0; i < CPUIDLE_STATE_MAX; i++) { 1075 for (i = 0; i < CPUIDLE_STATE_MAX; i++) {
996 dev->states[i].name[0] = '\0'; 1076 drv->states[i].name[0] = '\0';
997 dev->states[i].desc[0] = '\0'; 1077 drv->states[i].desc[0] = '\0';
998 } 1078 }
999 1079
1000 if (max_cstate == 0) 1080 if (max_cstate == 0)
@@ -1002,7 +1082,6 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1002 1082
1003 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) { 1083 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
1004 cx = &pr->power.states[i]; 1084 cx = &pr->power.states[i];
1005 state = &dev->states[count];
1006 1085
1007 if (!cx->valid) 1086 if (!cx->valid)
1008 continue; 1087 continue;
@@ -1013,8 +1092,8 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1013 !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED)) 1092 !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
1014 continue; 1093 continue;
1015#endif 1094#endif
1016 cpuidle_set_statedata(state, cx);
1017 1095
1096 state = &drv->states[count];
1018 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i); 1097 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i);
1019 strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN); 1098 strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
1020 state->exit_latency = cx->latency; 1099 state->exit_latency = cx->latency;
@@ -1027,13 +1106,13 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1027 state->flags |= CPUIDLE_FLAG_TIME_VALID; 1106 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1028 1107
1029 state->enter = acpi_idle_enter_c1; 1108 state->enter = acpi_idle_enter_c1;
1030 dev->safe_state = state; 1109 drv->safe_state_index = count;
1031 break; 1110 break;
1032 1111
1033 case ACPI_STATE_C2: 1112 case ACPI_STATE_C2:
1034 state->flags |= CPUIDLE_FLAG_TIME_VALID; 1113 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1035 state->enter = acpi_idle_enter_simple; 1114 state->enter = acpi_idle_enter_simple;
1036 dev->safe_state = state; 1115 drv->safe_state_index = count;
1037 break; 1116 break;
1038 1117
1039 case ACPI_STATE_C3: 1118 case ACPI_STATE_C3:
@@ -1049,7 +1128,7 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1049 break; 1128 break;
1050 } 1129 }
1051 1130
1052 dev->state_count = count; 1131 drv->state_count = count;
1053 1132
1054 if (!count) 1133 if (!count)
1055 return -EINVAL; 1134 return -EINVAL;
@@ -1057,7 +1136,7 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1057 return 0; 1136 return 0;
1058} 1137}
1059 1138
1060int acpi_processor_cst_has_changed(struct acpi_processor *pr) 1139int acpi_processor_hotplug(struct acpi_processor *pr)
1061{ 1140{
1062 int ret = 0; 1141 int ret = 0;
1063 1142
@@ -1078,7 +1157,7 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1078 cpuidle_disable_device(&pr->power.dev); 1157 cpuidle_disable_device(&pr->power.dev);
1079 acpi_processor_get_power_info(pr); 1158 acpi_processor_get_power_info(pr);
1080 if (pr->flags.power) { 1159 if (pr->flags.power) {
1081 acpi_processor_setup_cpuidle(pr); 1160 acpi_processor_setup_cpuidle_cx(pr);
1082 ret = cpuidle_enable_device(&pr->power.dev); 1161 ret = cpuidle_enable_device(&pr->power.dev);
1083 } 1162 }
1084 cpuidle_resume_and_unlock(); 1163 cpuidle_resume_and_unlock();
@@ -1086,10 +1165,72 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1086 return ret; 1165 return ret;
1087} 1166}
1088 1167
1168int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1169{
1170 int cpu;
1171 struct acpi_processor *_pr;
1172
1173 if (disabled_by_idle_boot_param())
1174 return 0;
1175
1176 if (!pr)
1177 return -EINVAL;
1178
1179 if (nocst)
1180 return -ENODEV;
1181
1182 if (!pr->flags.power_setup_done)
1183 return -ENODEV;
1184
1185 /*
1186 * FIXME: Design the ACPI notification to make it once per
1187 * system instead of once per-cpu. This condition is a hack
1188 * to make the code that updates C-States be called once.
1189 */
1190
1191 if (smp_processor_id() == 0 &&
1192 cpuidle_get_driver() == &acpi_idle_driver) {
1193
1194 cpuidle_pause_and_lock();
1195 /* Protect against cpu-hotplug */
1196 get_online_cpus();
1197
1198 /* Disable all cpuidle devices */
1199 for_each_online_cpu(cpu) {
1200 _pr = per_cpu(processors, cpu);
1201 if (!_pr || !_pr->flags.power_setup_done)
1202 continue;
1203 cpuidle_disable_device(&_pr->power.dev);
1204 }
1205
1206 /* Populate Updated C-state information */
1207 acpi_processor_setup_cpuidle_states(pr);
1208
1209 /* Enable all cpuidle devices */
1210 for_each_online_cpu(cpu) {
1211 _pr = per_cpu(processors, cpu);
1212 if (!_pr || !_pr->flags.power_setup_done)
1213 continue;
1214 acpi_processor_get_power_info(_pr);
1215 if (_pr->flags.power) {
1216 acpi_processor_setup_cpuidle_cx(_pr);
1217 cpuidle_enable_device(&_pr->power.dev);
1218 }
1219 }
1220 put_online_cpus();
1221 cpuidle_resume_and_unlock();
1222 }
1223
1224 return 0;
1225}
1226
1227static int acpi_processor_registered;
1228
1089int __cpuinit acpi_processor_power_init(struct acpi_processor *pr, 1229int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1090 struct acpi_device *device) 1230 struct acpi_device *device)
1091{ 1231{
1092 acpi_status status = 0; 1232 acpi_status status = 0;
1233 int retval;
1093 static int first_run; 1234 static int first_run;
1094 1235
1095 if (disabled_by_idle_boot_param()) 1236 if (disabled_by_idle_boot_param())
@@ -1126,9 +1267,26 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1126 * platforms that only support C1. 1267 * platforms that only support C1.
1127 */ 1268 */
1128 if (pr->flags.power) { 1269 if (pr->flags.power) {
1129 acpi_processor_setup_cpuidle(pr); 1270 /* Register acpi_idle_driver if not already registered */
1130 if (cpuidle_register_device(&pr->power.dev)) 1271 if (!acpi_processor_registered) {
1131 return -EIO; 1272 acpi_processor_setup_cpuidle_states(pr);
1273 retval = cpuidle_register_driver(&acpi_idle_driver);
1274 if (retval)
1275 return retval;
1276 printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n",
1277 acpi_idle_driver.name);
1278 }
1279 /* Register per-cpu cpuidle_device. Cpuidle driver
1280 * must already be registered before registering device
1281 */
1282 acpi_processor_setup_cpuidle_cx(pr);
1283 retval = cpuidle_register_device(&pr->power.dev);
1284 if (retval) {
1285 if (acpi_processor_registered == 0)
1286 cpuidle_unregister_driver(&acpi_idle_driver);
1287 return retval;
1288 }
1289 acpi_processor_registered++;
1132 } 1290 }
1133 return 0; 1291 return 0;
1134} 1292}
@@ -1139,8 +1297,13 @@ int acpi_processor_power_exit(struct acpi_processor *pr,
1139 if (disabled_by_idle_boot_param()) 1297 if (disabled_by_idle_boot_param())
1140 return 0; 1298 return 0;
1141 1299
1142 cpuidle_unregister_device(&pr->power.dev); 1300 if (pr->flags.power) {
1143 pr->flags.power_setup_done = 0; 1301 cpuidle_unregister_device(&pr->power.dev);
1302 acpi_processor_registered--;
1303 if (acpi_processor_registered == 0)
1304 cpuidle_unregister_driver(&acpi_idle_driver);
1305 }
1144 1306
1307 pr->flags.power_setup_done = 0;
1145 return 0; 1308 return 0;
1146} 1309}
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index d4c542372886..7a57b11eaa8d 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -61,8 +61,9 @@ static int __cpuidle_register_device(struct cpuidle_device *dev);
61int cpuidle_idle_call(void) 61int cpuidle_idle_call(void)
62{ 62{
63 struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices); 63 struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
64 struct cpuidle_driver *drv = cpuidle_get_driver();
64 struct cpuidle_state *target_state; 65 struct cpuidle_state *target_state;
65 int next_state; 66 int next_state, entered_state;
66 67
67 if (off) 68 if (off)
68 return -ENODEV; 69 return -ENODEV;
@@ -83,45 +84,36 @@ int cpuidle_idle_call(void)
83 hrtimer_peek_ahead_timers(); 84 hrtimer_peek_ahead_timers();
84#endif 85#endif
85 86
86 /*
87 * Call the device's prepare function before calling the
88 * governor's select function. ->prepare gives the device's
89 * cpuidle driver a chance to update any dynamic information
90 * of its cpuidle states for the current idle period, e.g.
91 * state availability, latencies, residencies, etc.
92 */
93 if (dev->prepare)
94 dev->prepare(dev);
95
96 /* ask the governor for the next state */ 87 /* ask the governor for the next state */
97 next_state = cpuidle_curr_governor->select(dev); 88 next_state = cpuidle_curr_governor->select(drv, dev);
98 if (need_resched()) { 89 if (need_resched()) {
99 local_irq_enable(); 90 local_irq_enable();
100 return 0; 91 return 0;
101 } 92 }
102 93
103 target_state = &dev->states[next_state]; 94 target_state = &drv->states[next_state];
104
105 /* enter the state and update stats */
106 dev->last_state = target_state;
107 95
108 trace_power_start(POWER_CSTATE, next_state, dev->cpu); 96 trace_power_start(POWER_CSTATE, next_state, dev->cpu);
109 trace_cpu_idle(next_state, dev->cpu); 97 trace_cpu_idle(next_state, dev->cpu);
110 98
111 dev->last_residency = target_state->enter(dev, target_state); 99 entered_state = target_state->enter(dev, drv, next_state);
112 100
113 trace_power_end(dev->cpu); 101 trace_power_end(dev->cpu);
114 trace_cpu_idle(PWR_EVENT_EXIT, dev->cpu); 102 trace_cpu_idle(PWR_EVENT_EXIT, dev->cpu);
115 103
116 if (dev->last_state) 104 if (entered_state >= 0) {
117 target_state = dev->last_state; 105 /* Update cpuidle counters */
118 106 /* This can be moved to within driver enter routine
119 target_state->time += (unsigned long long)dev->last_residency; 107 * but that results in multiple copies of same code.
120 target_state->usage++; 108 */
109 dev->states_usage[entered_state].time +=
110 (unsigned long long)dev->last_residency;
111 dev->states_usage[entered_state].usage++;
112 }
121 113
122 /* give the governor an opportunity to reflect on the outcome */ 114 /* give the governor an opportunity to reflect on the outcome */
123 if (cpuidle_curr_governor->reflect) 115 if (cpuidle_curr_governor->reflect)
124 cpuidle_curr_governor->reflect(dev); 116 cpuidle_curr_governor->reflect(dev, entered_state);
125 117
126 return 0; 118 return 0;
127} 119}
@@ -172,11 +164,11 @@ void cpuidle_resume_and_unlock(void)
172EXPORT_SYMBOL_GPL(cpuidle_resume_and_unlock); 164EXPORT_SYMBOL_GPL(cpuidle_resume_and_unlock);
173 165
174#ifdef CONFIG_ARCH_HAS_CPU_RELAX 166#ifdef CONFIG_ARCH_HAS_CPU_RELAX
175static int poll_idle(struct cpuidle_device *dev, struct cpuidle_state *st) 167static int poll_idle(struct cpuidle_device *dev,
168 struct cpuidle_driver *drv, int index)
176{ 169{
177 ktime_t t1, t2; 170 ktime_t t1, t2;
178 s64 diff; 171 s64 diff;
179 int ret;
180 172
181 t1 = ktime_get(); 173 t1 = ktime_get();
182 local_irq_enable(); 174 local_irq_enable();
@@ -188,15 +180,14 @@ static int poll_idle(struct cpuidle_device *dev, struct cpuidle_state *st)
188 if (diff > INT_MAX) 180 if (diff > INT_MAX)
189 diff = INT_MAX; 181 diff = INT_MAX;
190 182
191 ret = (int) diff; 183 dev->last_residency = (int) diff;
192 return ret; 184
185 return index;
193} 186}
194 187
195static void poll_idle_init(struct cpuidle_device *dev) 188static void poll_idle_init(struct cpuidle_driver *drv)
196{ 189{
197 struct cpuidle_state *state = &dev->states[0]; 190 struct cpuidle_state *state = &drv->states[0];
198
199 cpuidle_set_statedata(state, NULL);
200 191
201 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL"); 192 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
202 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE"); 193 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
@@ -207,7 +198,7 @@ static void poll_idle_init(struct cpuidle_device *dev)
207 state->enter = poll_idle; 198 state->enter = poll_idle;
208} 199}
209#else 200#else
210static void poll_idle_init(struct cpuidle_device *dev) {} 201static void poll_idle_init(struct cpuidle_driver *drv) {}
211#endif /* CONFIG_ARCH_HAS_CPU_RELAX */ 202#endif /* CONFIG_ARCH_HAS_CPU_RELAX */
212 203
213/** 204/**
@@ -234,21 +225,20 @@ int cpuidle_enable_device(struct cpuidle_device *dev)
234 return ret; 225 return ret;
235 } 226 }
236 227
237 poll_idle_init(dev); 228 poll_idle_init(cpuidle_get_driver());
238 229
239 if ((ret = cpuidle_add_state_sysfs(dev))) 230 if ((ret = cpuidle_add_state_sysfs(dev)))
240 return ret; 231 return ret;
241 232
242 if (cpuidle_curr_governor->enable && 233 if (cpuidle_curr_governor->enable &&
243 (ret = cpuidle_curr_governor->enable(dev))) 234 (ret = cpuidle_curr_governor->enable(cpuidle_get_driver(), dev)))
244 goto fail_sysfs; 235 goto fail_sysfs;
245 236
246 for (i = 0; i < dev->state_count; i++) { 237 for (i = 0; i < dev->state_count; i++) {
247 dev->states[i].usage = 0; 238 dev->states_usage[i].usage = 0;
248 dev->states[i].time = 0; 239 dev->states_usage[i].time = 0;
249 } 240 }
250 dev->last_residency = 0; 241 dev->last_residency = 0;
251 dev->last_state = NULL;
252 242
253 smp_wmb(); 243 smp_wmb();
254 244
@@ -282,7 +272,7 @@ void cpuidle_disable_device(struct cpuidle_device *dev)
282 dev->enabled = 0; 272 dev->enabled = 0;
283 273
284 if (cpuidle_curr_governor->disable) 274 if (cpuidle_curr_governor->disable)
285 cpuidle_curr_governor->disable(dev); 275 cpuidle_curr_governor->disable(cpuidle_get_driver(), dev);
286 276
287 cpuidle_remove_state_sysfs(dev); 277 cpuidle_remove_state_sysfs(dev);
288 enabled_devices--; 278 enabled_devices--;
@@ -310,26 +300,6 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
310 300
311 init_completion(&dev->kobj_unregister); 301 init_completion(&dev->kobj_unregister);
312 302
313 /*
314 * cpuidle driver should set the dev->power_specified bit
315 * before registering the device if the driver provides
316 * power_usage numbers.
317 *
318 * For those devices whose ->power_specified is not set,
319 * we fill in power_usage with decreasing values as the
320 * cpuidle code has an implicit assumption that state Cn
321 * uses less power than C(n-1).
322 *
323 * With CONFIG_ARCH_HAS_CPU_RELAX, C0 is already assigned
324 * an power value of -1. So we use -2, -3, etc, for other
325 * c-states.
326 */
327 if (!dev->power_specified) {
328 int i;
329 for (i = CPUIDLE_DRIVER_STATE_START; i < dev->state_count; i++)
330 dev->states[i].power_usage = -1 - i;
331 }
332
333 per_cpu(cpuidle_devices, dev->cpu) = dev; 303 per_cpu(cpuidle_devices, dev->cpu) = dev;
334 list_add(&dev->device_list, &cpuidle_detected_devices); 304 list_add(&dev->device_list, &cpuidle_detected_devices);
335 if ((ret = cpuidle_add_sysfs(sys_dev))) { 305 if ((ret = cpuidle_add_sysfs(sys_dev))) {
diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
index 3f7e3cedd133..284d7af5a9c8 100644
--- a/drivers/cpuidle/driver.c
+++ b/drivers/cpuidle/driver.c
@@ -17,6 +17,30 @@
17static struct cpuidle_driver *cpuidle_curr_driver; 17static struct cpuidle_driver *cpuidle_curr_driver;
18DEFINE_SPINLOCK(cpuidle_driver_lock); 18DEFINE_SPINLOCK(cpuidle_driver_lock);
19 19
20static void __cpuidle_register_driver(struct cpuidle_driver *drv)
21{
22 int i;
23 /*
24 * cpuidle driver should set the drv->power_specified bit
25 * before registering if the driver provides
26 * power_usage numbers.
27 *
28 * If power_specified is not set,
29 * we fill in power_usage with decreasing values as the
30 * cpuidle code has an implicit assumption that state Cn
31 * uses less power than C(n-1).
32 *
33 * With CONFIG_ARCH_HAS_CPU_RELAX, C0 is already assigned
34 * an power value of -1. So we use -2, -3, etc, for other
35 * c-states.
36 */
37 if (!drv->power_specified) {
38 for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++)
39 drv->states[i].power_usage = -1 - i;
40 }
41}
42
43
20/** 44/**
21 * cpuidle_register_driver - registers a driver 45 * cpuidle_register_driver - registers a driver
22 * @drv: the driver 46 * @drv: the driver
@@ -34,6 +58,7 @@ int cpuidle_register_driver(struct cpuidle_driver *drv)
34 spin_unlock(&cpuidle_driver_lock); 58 spin_unlock(&cpuidle_driver_lock);
35 return -EBUSY; 59 return -EBUSY;
36 } 60 }
61 __cpuidle_register_driver(drv);
37 cpuidle_curr_driver = drv; 62 cpuidle_curr_driver = drv;
38 spin_unlock(&cpuidle_driver_lock); 63 spin_unlock(&cpuidle_driver_lock);
39 64
diff --git a/drivers/cpuidle/governors/ladder.c b/drivers/cpuidle/governors/ladder.c
index 12c98900dcf8..ef6b9e4727a7 100644
--- a/drivers/cpuidle/governors/ladder.c
+++ b/drivers/cpuidle/governors/ladder.c
@@ -60,9 +60,11 @@ static inline void ladder_do_selection(struct ladder_device *ldev,
60 60
61/** 61/**
62 * ladder_select_state - selects the next state to enter 62 * ladder_select_state - selects the next state to enter
63 * @drv: cpuidle driver
63 * @dev: the CPU 64 * @dev: the CPU
64 */ 65 */
65static int ladder_select_state(struct cpuidle_device *dev) 66static int ladder_select_state(struct cpuidle_driver *drv,
67 struct cpuidle_device *dev)
66{ 68{
67 struct ladder_device *ldev = &__get_cpu_var(ladder_devices); 69 struct ladder_device *ldev = &__get_cpu_var(ladder_devices);
68 struct ladder_device_state *last_state; 70 struct ladder_device_state *last_state;
@@ -77,15 +79,17 @@ static int ladder_select_state(struct cpuidle_device *dev)
77 79
78 last_state = &ldev->states[last_idx]; 80 last_state = &ldev->states[last_idx];
79 81
80 if (dev->states[last_idx].flags & CPUIDLE_FLAG_TIME_VALID) 82 if (drv->states[last_idx].flags & CPUIDLE_FLAG_TIME_VALID) {
81 last_residency = cpuidle_get_last_residency(dev) - dev->states[last_idx].exit_latency; 83 last_residency = cpuidle_get_last_residency(dev) - \
84 drv->states[last_idx].exit_latency;
85 }
82 else 86 else
83 last_residency = last_state->threshold.promotion_time + 1; 87 last_residency = last_state->threshold.promotion_time + 1;
84 88
85 /* consider promotion */ 89 /* consider promotion */
86 if (last_idx < dev->state_count - 1 && 90 if (last_idx < drv->state_count - 1 &&
87 last_residency > last_state->threshold.promotion_time && 91 last_residency > last_state->threshold.promotion_time &&
88 dev->states[last_idx + 1].exit_latency <= latency_req) { 92 drv->states[last_idx + 1].exit_latency <= latency_req) {
89 last_state->stats.promotion_count++; 93 last_state->stats.promotion_count++;
90 last_state->stats.demotion_count = 0; 94 last_state->stats.demotion_count = 0;
91 if (last_state->stats.promotion_count >= last_state->threshold.promotion_count) { 95 if (last_state->stats.promotion_count >= last_state->threshold.promotion_count) {
@@ -96,11 +100,11 @@ static int ladder_select_state(struct cpuidle_device *dev)
96 100
97 /* consider demotion */ 101 /* consider demotion */
98 if (last_idx > CPUIDLE_DRIVER_STATE_START && 102 if (last_idx > CPUIDLE_DRIVER_STATE_START &&
99 dev->states[last_idx].exit_latency > latency_req) { 103 drv->states[last_idx].exit_latency > latency_req) {
100 int i; 104 int i;
101 105
102 for (i = last_idx - 1; i > CPUIDLE_DRIVER_STATE_START; i--) { 106 for (i = last_idx - 1; i > CPUIDLE_DRIVER_STATE_START; i--) {
103 if (dev->states[i].exit_latency <= latency_req) 107 if (drv->states[i].exit_latency <= latency_req)
104 break; 108 break;
105 } 109 }
106 ladder_do_selection(ldev, last_idx, i); 110 ladder_do_selection(ldev, last_idx, i);
@@ -123,9 +127,11 @@ static int ladder_select_state(struct cpuidle_device *dev)
123 127
124/** 128/**
125 * ladder_enable_device - setup for the governor 129 * ladder_enable_device - setup for the governor
130 * @drv: cpuidle driver
126 * @dev: the CPU 131 * @dev: the CPU
127 */ 132 */
128static int ladder_enable_device(struct cpuidle_device *dev) 133static int ladder_enable_device(struct cpuidle_driver *drv,
134 struct cpuidle_device *dev)
129{ 135{
130 int i; 136 int i;
131 struct ladder_device *ldev = &per_cpu(ladder_devices, dev->cpu); 137 struct ladder_device *ldev = &per_cpu(ladder_devices, dev->cpu);
@@ -134,8 +140,8 @@ static int ladder_enable_device(struct cpuidle_device *dev)
134 140
135 ldev->last_state_idx = CPUIDLE_DRIVER_STATE_START; 141 ldev->last_state_idx = CPUIDLE_DRIVER_STATE_START;
136 142
137 for (i = 0; i < dev->state_count; i++) { 143 for (i = 0; i < drv->state_count; i++) {
138 state = &dev->states[i]; 144 state = &drv->states[i];
139 lstate = &ldev->states[i]; 145 lstate = &ldev->states[i];
140 146
141 lstate->stats.promotion_count = 0; 147 lstate->stats.promotion_count = 0;
@@ -144,7 +150,7 @@ static int ladder_enable_device(struct cpuidle_device *dev)
144 lstate->threshold.promotion_count = PROMOTION_COUNT; 150 lstate->threshold.promotion_count = PROMOTION_COUNT;
145 lstate->threshold.demotion_count = DEMOTION_COUNT; 151 lstate->threshold.demotion_count = DEMOTION_COUNT;
146 152
147 if (i < dev->state_count - 1) 153 if (i < drv->state_count - 1)
148 lstate->threshold.promotion_time = state->exit_latency; 154 lstate->threshold.promotion_time = state->exit_latency;
149 if (i > 0) 155 if (i > 0)
150 lstate->threshold.demotion_time = state->exit_latency; 156 lstate->threshold.demotion_time = state->exit_latency;
@@ -153,11 +159,24 @@ static int ladder_enable_device(struct cpuidle_device *dev)
153 return 0; 159 return 0;
154} 160}
155 161
162/**
163 * ladder_reflect - update the correct last_state_idx
164 * @dev: the CPU
165 * @index: the index of actual state entered
166 */
167static void ladder_reflect(struct cpuidle_device *dev, int index)
168{
169 struct ladder_device *ldev = &__get_cpu_var(ladder_devices);
170 if (index > 0)
171 ldev->last_state_idx = index;
172}
173
156static struct cpuidle_governor ladder_governor = { 174static struct cpuidle_governor ladder_governor = {
157 .name = "ladder", 175 .name = "ladder",
158 .rating = 10, 176 .rating = 10,
159 .enable = ladder_enable_device, 177 .enable = ladder_enable_device,
160 .select = ladder_select_state, 178 .select = ladder_select_state,
179 .reflect = ladder_reflect,
161 .owner = THIS_MODULE, 180 .owner = THIS_MODULE,
162}; 181};
163 182
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index c47f3d09c1ee..bcbe88142135 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -182,7 +182,7 @@ static inline int performance_multiplier(void)
182 182
183static DEFINE_PER_CPU(struct menu_device, menu_devices); 183static DEFINE_PER_CPU(struct menu_device, menu_devices);
184 184
185static void menu_update(struct cpuidle_device *dev); 185static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev);
186 186
187/* This implements DIV_ROUND_CLOSEST but avoids 64 bit division */ 187/* This implements DIV_ROUND_CLOSEST but avoids 64 bit division */
188static u64 div_round64(u64 dividend, u32 divisor) 188static u64 div_round64(u64 dividend, u32 divisor)
@@ -228,9 +228,10 @@ static void detect_repeating_patterns(struct menu_device *data)
228 228
229/** 229/**
230 * menu_select - selects the next idle state to enter 230 * menu_select - selects the next idle state to enter
231 * @drv: cpuidle driver containing state data
231 * @dev: the CPU 232 * @dev: the CPU
232 */ 233 */
233static int menu_select(struct cpuidle_device *dev) 234static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
234{ 235{
235 struct menu_device *data = &__get_cpu_var(menu_devices); 236 struct menu_device *data = &__get_cpu_var(menu_devices);
236 int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY); 237 int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
@@ -240,7 +241,7 @@ static int menu_select(struct cpuidle_device *dev)
240 struct timespec t; 241 struct timespec t;
241 242
242 if (data->needs_update) { 243 if (data->needs_update) {
243 menu_update(dev); 244 menu_update(drv, dev);
244 data->needs_update = 0; 245 data->needs_update = 0;
245 } 246 }
246 247
@@ -285,11 +286,9 @@ static int menu_select(struct cpuidle_device *dev)
285 * Find the idle state with the lowest power while satisfying 286 * Find the idle state with the lowest power while satisfying
286 * our constraints. 287 * our constraints.
287 */ 288 */
288 for (i = CPUIDLE_DRIVER_STATE_START; i < dev->state_count; i++) { 289 for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) {
289 struct cpuidle_state *s = &dev->states[i]; 290 struct cpuidle_state *s = &drv->states[i];
290 291
291 if (s->flags & CPUIDLE_FLAG_IGNORE)
292 continue;
293 if (s->target_residency > data->predicted_us) 292 if (s->target_residency > data->predicted_us)
294 continue; 293 continue;
295 if (s->exit_latency > latency_req) 294 if (s->exit_latency > latency_req)
@@ -310,26 +309,30 @@ static int menu_select(struct cpuidle_device *dev)
310/** 309/**
311 * menu_reflect - records that data structures need update 310 * menu_reflect - records that data structures need update
312 * @dev: the CPU 311 * @dev: the CPU
312 * @index: the index of actual entered state
313 * 313 *
314 * NOTE: it's important to be fast here because this operation will add to 314 * NOTE: it's important to be fast here because this operation will add to
315 * the overall exit latency. 315 * the overall exit latency.
316 */ 316 */
317static void menu_reflect(struct cpuidle_device *dev) 317static void menu_reflect(struct cpuidle_device *dev, int index)
318{ 318{
319 struct menu_device *data = &__get_cpu_var(menu_devices); 319 struct menu_device *data = &__get_cpu_var(menu_devices);
320 data->needs_update = 1; 320 data->last_state_idx = index;
321 if (index >= 0)
322 data->needs_update = 1;
321} 323}
322 324
323/** 325/**
324 * menu_update - attempts to guess what happened after entry 326 * menu_update - attempts to guess what happened after entry
327 * @drv: cpuidle driver containing state data
325 * @dev: the CPU 328 * @dev: the CPU
326 */ 329 */
327static void menu_update(struct cpuidle_device *dev) 330static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev)
328{ 331{
329 struct menu_device *data = &__get_cpu_var(menu_devices); 332 struct menu_device *data = &__get_cpu_var(menu_devices);
330 int last_idx = data->last_state_idx; 333 int last_idx = data->last_state_idx;
331 unsigned int last_idle_us = cpuidle_get_last_residency(dev); 334 unsigned int last_idle_us = cpuidle_get_last_residency(dev);
332 struct cpuidle_state *target = &dev->states[last_idx]; 335 struct cpuidle_state *target = &drv->states[last_idx];
333 unsigned int measured_us; 336 unsigned int measured_us;
334 u64 new_factor; 337 u64 new_factor;
335 338
@@ -383,9 +386,11 @@ static void menu_update(struct cpuidle_device *dev)
383 386
384/** 387/**
385 * menu_enable_device - scans a CPU's states and does setup 388 * menu_enable_device - scans a CPU's states and does setup
389 * @drv: cpuidle driver
386 * @dev: the CPU 390 * @dev: the CPU
387 */ 391 */
388static int menu_enable_device(struct cpuidle_device *dev) 392static int menu_enable_device(struct cpuidle_driver *drv,
393 struct cpuidle_device *dev)
389{ 394{
390 struct menu_device *data = &per_cpu(menu_devices, dev->cpu); 395 struct menu_device *data = &per_cpu(menu_devices, dev->cpu);
391 396
diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
index be7917ec40c9..1e756e160dca 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -216,7 +216,8 @@ static struct kobj_type ktype_cpuidle = {
216 216
217struct cpuidle_state_attr { 217struct cpuidle_state_attr {
218 struct attribute attr; 218 struct attribute attr;
219 ssize_t (*show)(struct cpuidle_state *, char *); 219 ssize_t (*show)(struct cpuidle_state *, \
220 struct cpuidle_state_usage *, char *);
220 ssize_t (*store)(struct cpuidle_state *, const char *, size_t); 221 ssize_t (*store)(struct cpuidle_state *, const char *, size_t);
221}; 222};
222 223
@@ -224,19 +225,22 @@ struct cpuidle_state_attr {
224static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0444, show, NULL) 225static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0444, show, NULL)
225 226
226#define define_show_state_function(_name) \ 227#define define_show_state_function(_name) \
227static ssize_t show_state_##_name(struct cpuidle_state *state, char *buf) \ 228static ssize_t show_state_##_name(struct cpuidle_state *state, \
229 struct cpuidle_state_usage *state_usage, char *buf) \
228{ \ 230{ \
229 return sprintf(buf, "%u\n", state->_name);\ 231 return sprintf(buf, "%u\n", state->_name);\
230} 232}
231 233
232#define define_show_state_ull_function(_name) \ 234#define define_show_state_ull_function(_name) \
233static ssize_t show_state_##_name(struct cpuidle_state *state, char *buf) \ 235static ssize_t show_state_##_name(struct cpuidle_state *state, \
236 struct cpuidle_state_usage *state_usage, char *buf) \
234{ \ 237{ \
235 return sprintf(buf, "%llu\n", state->_name);\ 238 return sprintf(buf, "%llu\n", state_usage->_name);\
236} 239}
237 240
238#define define_show_state_str_function(_name) \ 241#define define_show_state_str_function(_name) \
239static ssize_t show_state_##_name(struct cpuidle_state *state, char *buf) \ 242static ssize_t show_state_##_name(struct cpuidle_state *state, \
243 struct cpuidle_state_usage *state_usage, char *buf) \
240{ \ 244{ \
241 if (state->_name[0] == '\0')\ 245 if (state->_name[0] == '\0')\
242 return sprintf(buf, "<null>\n");\ 246 return sprintf(buf, "<null>\n");\
@@ -269,16 +273,18 @@ static struct attribute *cpuidle_state_default_attrs[] = {
269 273
270#define kobj_to_state_obj(k) container_of(k, struct cpuidle_state_kobj, kobj) 274#define kobj_to_state_obj(k) container_of(k, struct cpuidle_state_kobj, kobj)
271#define kobj_to_state(k) (kobj_to_state_obj(k)->state) 275#define kobj_to_state(k) (kobj_to_state_obj(k)->state)
276#define kobj_to_state_usage(k) (kobj_to_state_obj(k)->state_usage)
272#define attr_to_stateattr(a) container_of(a, struct cpuidle_state_attr, attr) 277#define attr_to_stateattr(a) container_of(a, struct cpuidle_state_attr, attr)
273static ssize_t cpuidle_state_show(struct kobject * kobj, 278static ssize_t cpuidle_state_show(struct kobject * kobj,
274 struct attribute * attr ,char * buf) 279 struct attribute * attr ,char * buf)
275{ 280{
276 int ret = -EIO; 281 int ret = -EIO;
277 struct cpuidle_state *state = kobj_to_state(kobj); 282 struct cpuidle_state *state = kobj_to_state(kobj);
283 struct cpuidle_state_usage *state_usage = kobj_to_state_usage(kobj);
278 struct cpuidle_state_attr * cattr = attr_to_stateattr(attr); 284 struct cpuidle_state_attr * cattr = attr_to_stateattr(attr);
279 285
280 if (cattr->show) 286 if (cattr->show)
281 ret = cattr->show(state, buf); 287 ret = cattr->show(state, state_usage, buf);
282 288
283 return ret; 289 return ret;
284} 290}
@@ -316,13 +322,15 @@ int cpuidle_add_state_sysfs(struct cpuidle_device *device)
316{ 322{
317 int i, ret = -ENOMEM; 323 int i, ret = -ENOMEM;
318 struct cpuidle_state_kobj *kobj; 324 struct cpuidle_state_kobj *kobj;
325 struct cpuidle_driver *drv = cpuidle_get_driver();
319 326
320 /* state statistics */ 327 /* state statistics */
321 for (i = 0; i < device->state_count; i++) { 328 for (i = 0; i < device->state_count; i++) {
322 kobj = kzalloc(sizeof(struct cpuidle_state_kobj), GFP_KERNEL); 329 kobj = kzalloc(sizeof(struct cpuidle_state_kobj), GFP_KERNEL);
323 if (!kobj) 330 if (!kobj)
324 goto error_state; 331 goto error_state;
325 kobj->state = &device->states[i]; 332 kobj->state = &drv->states[i];
333 kobj->state_usage = &device->states_usage[i];
326 init_completion(&kobj->kobj_unregister); 334 init_completion(&kobj->kobj_unregister);
327 335
328 ret = kobject_init_and_add(&kobj->kobj, &ktype_state_cpuidle, &device->kobj, 336 ret = kobject_init_and_add(&kobj->kobj, &ktype_state_cpuidle, &device->kobj,
diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index a46dddf61078..5be9d599ff6b 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -81,7 +81,8 @@ static unsigned int mwait_substates;
81static unsigned int lapic_timer_reliable_states = (1 << 1); /* Default to only C1 */ 81static unsigned int lapic_timer_reliable_states = (1 << 1); /* Default to only C1 */
82 82
83static struct cpuidle_device __percpu *intel_idle_cpuidle_devices; 83static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
84static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state); 84static int intel_idle(struct cpuidle_device *dev,
85 struct cpuidle_driver *drv, int index);
85 86
86static struct cpuidle_state *cpuidle_state_table; 87static struct cpuidle_state *cpuidle_state_table;
87 88
@@ -109,7 +110,6 @@ static struct cpuidle_state nehalem_cstates[MWAIT_MAX_NUM_CSTATES] = {
109 { /* MWAIT C1 */ 110 { /* MWAIT C1 */
110 .name = "C1-NHM", 111 .name = "C1-NHM",
111 .desc = "MWAIT 0x00", 112 .desc = "MWAIT 0x00",
112 .driver_data = (void *) 0x00,
113 .flags = CPUIDLE_FLAG_TIME_VALID, 113 .flags = CPUIDLE_FLAG_TIME_VALID,
114 .exit_latency = 3, 114 .exit_latency = 3,
115 .target_residency = 6, 115 .target_residency = 6,
@@ -117,7 +117,6 @@ static struct cpuidle_state nehalem_cstates[MWAIT_MAX_NUM_CSTATES] = {
117 { /* MWAIT C2 */ 117 { /* MWAIT C2 */
118 .name = "C3-NHM", 118 .name = "C3-NHM",
119 .desc = "MWAIT 0x10", 119 .desc = "MWAIT 0x10",
120 .driver_data = (void *) 0x10,
121 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED, 120 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
122 .exit_latency = 20, 121 .exit_latency = 20,
123 .target_residency = 80, 122 .target_residency = 80,
@@ -125,7 +124,6 @@ static struct cpuidle_state nehalem_cstates[MWAIT_MAX_NUM_CSTATES] = {
125 { /* MWAIT C3 */ 124 { /* MWAIT C3 */
126 .name = "C6-NHM", 125 .name = "C6-NHM",
127 .desc = "MWAIT 0x20", 126 .desc = "MWAIT 0x20",
128 .driver_data = (void *) 0x20,
129 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED, 127 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
130 .exit_latency = 200, 128 .exit_latency = 200,
131 .target_residency = 800, 129 .target_residency = 800,
@@ -137,7 +135,6 @@ static struct cpuidle_state snb_cstates[MWAIT_MAX_NUM_CSTATES] = {
137 { /* MWAIT C1 */ 135 { /* MWAIT C1 */
138 .name = "C1-SNB", 136 .name = "C1-SNB",
139 .desc = "MWAIT 0x00", 137 .desc = "MWAIT 0x00",
140 .driver_data = (void *) 0x00,
141 .flags = CPUIDLE_FLAG_TIME_VALID, 138 .flags = CPUIDLE_FLAG_TIME_VALID,
142 .exit_latency = 1, 139 .exit_latency = 1,
143 .target_residency = 1, 140 .target_residency = 1,
@@ -145,7 +142,6 @@ static struct cpuidle_state snb_cstates[MWAIT_MAX_NUM_CSTATES] = {
145 { /* MWAIT C2 */ 142 { /* MWAIT C2 */
146 .name = "C3-SNB", 143 .name = "C3-SNB",
147 .desc = "MWAIT 0x10", 144 .desc = "MWAIT 0x10",
148 .driver_data = (void *) 0x10,
149 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED, 145 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
150 .exit_latency = 80, 146 .exit_latency = 80,
151 .target_residency = 211, 147 .target_residency = 211,
@@ -153,7 +149,6 @@ static struct cpuidle_state snb_cstates[MWAIT_MAX_NUM_CSTATES] = {
153 { /* MWAIT C3 */ 149 { /* MWAIT C3 */
154 .name = "C6-SNB", 150 .name = "C6-SNB",
155 .desc = "MWAIT 0x20", 151 .desc = "MWAIT 0x20",
156 .driver_data = (void *) 0x20,
157 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED, 152 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
158 .exit_latency = 104, 153 .exit_latency = 104,
159 .target_residency = 345, 154 .target_residency = 345,
@@ -161,7 +156,6 @@ static struct cpuidle_state snb_cstates[MWAIT_MAX_NUM_CSTATES] = {
161 { /* MWAIT C4 */ 156 { /* MWAIT C4 */
162 .name = "C7-SNB", 157 .name = "C7-SNB",
163 .desc = "MWAIT 0x30", 158 .desc = "MWAIT 0x30",
164 .driver_data = (void *) 0x30,
165 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED, 159 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
166 .exit_latency = 109, 160 .exit_latency = 109,
167 .target_residency = 345, 161 .target_residency = 345,
@@ -173,7 +167,6 @@ static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
173 { /* MWAIT C1 */ 167 { /* MWAIT C1 */
174 .name = "C1-ATM", 168 .name = "C1-ATM",
175 .desc = "MWAIT 0x00", 169 .desc = "MWAIT 0x00",
176 .driver_data = (void *) 0x00,
177 .flags = CPUIDLE_FLAG_TIME_VALID, 170 .flags = CPUIDLE_FLAG_TIME_VALID,
178 .exit_latency = 1, 171 .exit_latency = 1,
179 .target_residency = 4, 172 .target_residency = 4,
@@ -181,7 +174,6 @@ static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
181 { /* MWAIT C2 */ 174 { /* MWAIT C2 */
182 .name = "C2-ATM", 175 .name = "C2-ATM",
183 .desc = "MWAIT 0x10", 176 .desc = "MWAIT 0x10",
184 .driver_data = (void *) 0x10,
185 .flags = CPUIDLE_FLAG_TIME_VALID, 177 .flags = CPUIDLE_FLAG_TIME_VALID,
186 .exit_latency = 20, 178 .exit_latency = 20,
187 .target_residency = 80, 179 .target_residency = 80,
@@ -190,7 +182,6 @@ static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
190 { /* MWAIT C4 */ 182 { /* MWAIT C4 */
191 .name = "C4-ATM", 183 .name = "C4-ATM",
192 .desc = "MWAIT 0x30", 184 .desc = "MWAIT 0x30",
193 .driver_data = (void *) 0x30,
194 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED, 185 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
195 .exit_latency = 100, 186 .exit_latency = 100,
196 .target_residency = 400, 187 .target_residency = 400,
@@ -199,23 +190,55 @@ static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
199 { /* MWAIT C6 */ 190 { /* MWAIT C6 */
200 .name = "C6-ATM", 191 .name = "C6-ATM",
201 .desc = "MWAIT 0x52", 192 .desc = "MWAIT 0x52",
202 .driver_data = (void *) 0x52,
203 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED, 193 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
204 .exit_latency = 140, 194 .exit_latency = 140,
205 .target_residency = 560, 195 .target_residency = 560,
206 .enter = &intel_idle }, 196 .enter = &intel_idle },
207}; 197};
208 198
199static int get_driver_data(int cstate)
200{
201 int driver_data;
202 switch (cstate) {
203
204 case 1: /* MWAIT C1 */
205 driver_data = 0x00;
206 break;
207 case 2: /* MWAIT C2 */
208 driver_data = 0x10;
209 break;
210 case 3: /* MWAIT C3 */
211 driver_data = 0x20;
212 break;
213 case 4: /* MWAIT C4 */
214 driver_data = 0x30;
215 break;
216 case 5: /* MWAIT C5 */
217 driver_data = 0x40;
218 break;
219 case 6: /* MWAIT C6 */
220 driver_data = 0x52;
221 break;
222 default:
223 driver_data = 0x00;
224 }
225 return driver_data;
226}
227
209/** 228/**
210 * intel_idle 229 * intel_idle
211 * @dev: cpuidle_device 230 * @dev: cpuidle_device
212 * @state: cpuidle state 231 * @drv: cpuidle driver
232 * @index: index of cpuidle state
213 * 233 *
214 */ 234 */
215static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state) 235static int intel_idle(struct cpuidle_device *dev,
236 struct cpuidle_driver *drv, int index)
216{ 237{
217 unsigned long ecx = 1; /* break on interrupt flag */ 238 unsigned long ecx = 1; /* break on interrupt flag */
218 unsigned long eax = (unsigned long)cpuidle_get_statedata(state); 239 struct cpuidle_state *state = &drv->states[index];
240 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
241 unsigned long eax = (unsigned long)cpuidle_get_statedata(state_usage);
219 unsigned int cstate; 242 unsigned int cstate;
220 ktime_t kt_before, kt_after; 243 ktime_t kt_before, kt_after;
221 s64 usec_delta; 244 s64 usec_delta;
@@ -256,7 +279,10 @@ static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state)
256 if (!(lapic_timer_reliable_states & (1 << (cstate)))) 279 if (!(lapic_timer_reliable_states & (1 << (cstate))))
257 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu); 280 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
258 281
259 return usec_delta; 282 /* Update cpuidle counters */
283 dev->last_residency = (int)usec_delta;
284
285 return index;
260} 286}
261 287
262static void __setup_broadcast_timer(void *arg) 288static void __setup_broadcast_timer(void *arg)
@@ -397,6 +423,60 @@ static void intel_idle_cpuidle_devices_uninit(void)
397 return; 423 return;
398} 424}
399/* 425/*
426 * intel_idle_cpuidle_driver_init()
427 * allocate, initialize cpuidle_states
428 */
429static int intel_idle_cpuidle_driver_init(void)
430{
431 int cstate;
432 struct cpuidle_driver *drv = &intel_idle_driver;
433
434 drv->state_count = 1;
435
436 for (cstate = 1; cstate < MWAIT_MAX_NUM_CSTATES; ++cstate) {
437 int num_substates;
438
439 if (cstate > max_cstate) {
440 printk(PREFIX "max_cstate %d reached\n",
441 max_cstate);
442 break;
443 }
444
445 /* does the state exist in CPUID.MWAIT? */
446 num_substates = (mwait_substates >> ((cstate) * 4))
447 & MWAIT_SUBSTATE_MASK;
448 if (num_substates == 0)
449 continue;
450 /* is the state not enabled? */
451 if (cpuidle_state_table[cstate].enter == NULL) {
452 /* does the driver not know about the state? */
453 if (*cpuidle_state_table[cstate].name == '\0')
454 pr_debug(PREFIX "unaware of model 0x%x"
455 " MWAIT %d please"
456 " contact lenb@kernel.org",
457 boot_cpu_data.x86_model, cstate);
458 continue;
459 }
460
461 if ((cstate > 2) &&
462 !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
463 mark_tsc_unstable("TSC halts in idle"
464 " states deeper than C2");
465
466 drv->states[drv->state_count] = /* structure copy */
467 cpuidle_state_table[cstate];
468
469 drv->state_count += 1;
470 }
471
472 if (auto_demotion_disable_flags)
473 smp_call_function(auto_demotion_disable, NULL, 1);
474
475 return 0;
476}
477
478
479/*
400 * intel_idle_cpuidle_devices_init() 480 * intel_idle_cpuidle_devices_init()
401 * allocate, initialize, register cpuidle_devices 481 * allocate, initialize, register cpuidle_devices
402 */ 482 */
@@ -430,22 +510,11 @@ static int intel_idle_cpuidle_devices_init(void)
430 continue; 510 continue;
431 /* is the state not enabled? */ 511 /* is the state not enabled? */
432 if (cpuidle_state_table[cstate].enter == NULL) { 512 if (cpuidle_state_table[cstate].enter == NULL) {
433 /* does the driver not know about the state? */
434 if (*cpuidle_state_table[cstate].name == '\0')
435 pr_debug(PREFIX "unaware of model 0x%x"
436 " MWAIT %d please"
437 " contact lenb@kernel.org",
438 boot_cpu_data.x86_model, cstate);
439 continue; 513 continue;
440 } 514 }
441 515
442 if ((cstate > 2) && 516 dev->states_usage[dev->state_count].driver_data =
443 !boot_cpu_has(X86_FEATURE_NONSTOP_TSC)) 517 (void *)get_driver_data(cstate);
444 mark_tsc_unstable("TSC halts in idle"
445 " states deeper than C2");
446
447 dev->states[dev->state_count] = /* structure copy */
448 cpuidle_state_table[cstate];
449 518
450 dev->state_count += 1; 519 dev->state_count += 1;
451 } 520 }
@@ -458,8 +527,6 @@ static int intel_idle_cpuidle_devices_init(void)
458 return -EIO; 527 return -EIO;
459 } 528 }
460 } 529 }
461 if (auto_demotion_disable_flags)
462 smp_call_function(auto_demotion_disable, NULL, 1);
463 530
464 return 0; 531 return 0;
465} 532}
@@ -477,6 +544,7 @@ static int __init intel_idle_init(void)
477 if (retval) 544 if (retval)
478 return retval; 545 return retval;
479 546
547 intel_idle_cpuidle_driver_init();
480 retval = cpuidle_register_driver(&intel_idle_driver); 548 retval = cpuidle_register_driver(&intel_idle_driver);
481 if (retval) { 549 if (retval) {
482 printk(KERN_DEBUG PREFIX "intel_idle yielding to %s", 550 printk(KERN_DEBUG PREFIX "intel_idle yielding to %s",
diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index 67055f180330..610f6fb1bbc2 100644
--- a/include/acpi/processor.h
+++ b/include/acpi/processor.h
@@ -329,6 +329,7 @@ extern void acpi_processor_throttling_init(void);
329int acpi_processor_power_init(struct acpi_processor *pr, 329int acpi_processor_power_init(struct acpi_processor *pr,
330 struct acpi_device *device); 330 struct acpi_device *device);
331int acpi_processor_cst_has_changed(struct acpi_processor *pr); 331int acpi_processor_cst_has_changed(struct acpi_processor *pr);
332int acpi_processor_hotplug(struct acpi_processor *pr);
332int acpi_processor_power_exit(struct acpi_processor *pr, 333int acpi_processor_power_exit(struct acpi_processor *pr,
333 struct acpi_device *device); 334 struct acpi_device *device);
334int acpi_processor_suspend(struct acpi_device * device, pm_message_t state); 335int acpi_processor_suspend(struct acpi_device * device, pm_message_t state);
diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
index b51629e15cfc..c90418822f40 100644
--- a/include/linux/cpuidle.h
+++ b/include/linux/cpuidle.h
@@ -22,57 +22,62 @@
22#define CPUIDLE_DESC_LEN 32 22#define CPUIDLE_DESC_LEN 32
23 23
24struct cpuidle_device; 24struct cpuidle_device;
25struct cpuidle_driver;
25 26
26 27
27/**************************** 28/****************************
28 * CPUIDLE DEVICE INTERFACE * 29 * CPUIDLE DEVICE INTERFACE *
29 ****************************/ 30 ****************************/
30 31
32struct cpuidle_state_usage {
33 void *driver_data;
34
35 unsigned long long usage;
36 unsigned long long time; /* in US */
37};
38
31struct cpuidle_state { 39struct cpuidle_state {
32 char name[CPUIDLE_NAME_LEN]; 40 char name[CPUIDLE_NAME_LEN];
33 char desc[CPUIDLE_DESC_LEN]; 41 char desc[CPUIDLE_DESC_LEN];
34 void *driver_data;
35 42
36 unsigned int flags; 43 unsigned int flags;
37 unsigned int exit_latency; /* in US */ 44 unsigned int exit_latency; /* in US */
38 unsigned int power_usage; /* in mW */ 45 unsigned int power_usage; /* in mW */
39 unsigned int target_residency; /* in US */ 46 unsigned int target_residency; /* in US */
40 47
41 unsigned long long usage;
42 unsigned long long time; /* in US */
43
44 int (*enter) (struct cpuidle_device *dev, 48 int (*enter) (struct cpuidle_device *dev,
45 struct cpuidle_state *state); 49 struct cpuidle_driver *drv,
50 int index);
46}; 51};
47 52
48/* Idle State Flags */ 53/* Idle State Flags */
49#define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */ 54#define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
50#define CPUIDLE_FLAG_IGNORE (0x100) /* ignore during this idle period */
51 55
52#define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000) 56#define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
53 57
54/** 58/**
55 * cpuidle_get_statedata - retrieves private driver state data 59 * cpuidle_get_statedata - retrieves private driver state data
56 * @state: the state 60 * @st_usage: the state usage statistics
57 */ 61 */
58static inline void * cpuidle_get_statedata(struct cpuidle_state *state) 62static inline void *cpuidle_get_statedata(struct cpuidle_state_usage *st_usage)
59{ 63{
60 return state->driver_data; 64 return st_usage->driver_data;
61} 65}
62 66
63/** 67/**
64 * cpuidle_set_statedata - stores private driver state data 68 * cpuidle_set_statedata - stores private driver state data
65 * @state: the state 69 * @st_usage: the state usage statistics
66 * @data: the private data 70 * @data: the private data
67 */ 71 */
68static inline void 72static inline void
69cpuidle_set_statedata(struct cpuidle_state *state, void *data) 73cpuidle_set_statedata(struct cpuidle_state_usage *st_usage, void *data)
70{ 74{
71 state->driver_data = data; 75 st_usage->driver_data = data;
72} 76}
73 77
74struct cpuidle_state_kobj { 78struct cpuidle_state_kobj {
75 struct cpuidle_state *state; 79 struct cpuidle_state *state;
80 struct cpuidle_state_usage *state_usage;
76 struct completion kobj_unregister; 81 struct completion kobj_unregister;
77 struct kobject kobj; 82 struct kobject kobj;
78}; 83};
@@ -80,22 +85,17 @@ struct cpuidle_state_kobj {
80struct cpuidle_device { 85struct cpuidle_device {
81 unsigned int registered:1; 86 unsigned int registered:1;
82 unsigned int enabled:1; 87 unsigned int enabled:1;
83 unsigned int power_specified:1;
84 unsigned int cpu; 88 unsigned int cpu;
85 89
86 int last_residency; 90 int last_residency;
87 int state_count; 91 int state_count;
88 struct cpuidle_state states[CPUIDLE_STATE_MAX]; 92 struct cpuidle_state_usage states_usage[CPUIDLE_STATE_MAX];
89 struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX]; 93 struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
90 struct cpuidle_state *last_state;
91 94
92 struct list_head device_list; 95 struct list_head device_list;
93 struct kobject kobj; 96 struct kobject kobj;
94 struct completion kobj_unregister; 97 struct completion kobj_unregister;
95 void *governor_data; 98 void *governor_data;
96 struct cpuidle_state *safe_state;
97
98 int (*prepare) (struct cpuidle_device *dev);
99}; 99};
100 100
101DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices); 101DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
@@ -119,6 +119,11 @@ static inline int cpuidle_get_last_residency(struct cpuidle_device *dev)
119struct cpuidle_driver { 119struct cpuidle_driver {
120 char name[CPUIDLE_NAME_LEN]; 120 char name[CPUIDLE_NAME_LEN];
121 struct module *owner; 121 struct module *owner;
122
123 unsigned int power_specified:1;
124 struct cpuidle_state states[CPUIDLE_STATE_MAX];
125 int state_count;
126 int safe_state_index;
122}; 127};
123 128
124#ifdef CONFIG_CPU_IDLE 129#ifdef CONFIG_CPU_IDLE
@@ -165,11 +170,14 @@ struct cpuidle_governor {
165 struct list_head governor_list; 170 struct list_head governor_list;
166 unsigned int rating; 171 unsigned int rating;
167 172
168 int (*enable) (struct cpuidle_device *dev); 173 int (*enable) (struct cpuidle_driver *drv,
169 void (*disable) (struct cpuidle_device *dev); 174 struct cpuidle_device *dev);
175 void (*disable) (struct cpuidle_driver *drv,
176 struct cpuidle_device *dev);
170 177
171 int (*select) (struct cpuidle_device *dev); 178 int (*select) (struct cpuidle_driver *drv,
172 void (*reflect) (struct cpuidle_device *dev); 179 struct cpuidle_device *dev);
180 void (*reflect) (struct cpuidle_device *dev, int index);
173 181
174 struct module *owner; 182 struct module *owner;
175}; 183};
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 8b2d37b59c9e..3c6f7808efae 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -162,19 +162,21 @@ void print_header(void)
162 162
163void dump_cnt(struct counters *cnt) 163void dump_cnt(struct counters *cnt)
164{ 164{
165 fprintf(stderr, "package: %d ", cnt->pkg); 165 if (!cnt)
166 fprintf(stderr, "core:: %d ", cnt->core); 166 return;
167 fprintf(stderr, "CPU: %d ", cnt->cpu); 167 if (cnt->pkg) fprintf(stderr, "package: %d ", cnt->pkg);
168 fprintf(stderr, "TSC: %016llX\n", cnt->tsc); 168 if (cnt->core) fprintf(stderr, "core:: %d ", cnt->core);
169 fprintf(stderr, "c3: %016llX\n", cnt->c3); 169 if (cnt->cpu) fprintf(stderr, "CPU: %d ", cnt->cpu);
170 fprintf(stderr, "c6: %016llX\n", cnt->c6); 170 if (cnt->tsc) fprintf(stderr, "TSC: %016llX\n", cnt->tsc);
171 fprintf(stderr, "c7: %016llX\n", cnt->c7); 171 if (cnt->c3) fprintf(stderr, "c3: %016llX\n", cnt->c3);
172 fprintf(stderr, "aperf: %016llX\n", cnt->aperf); 172 if (cnt->c6) fprintf(stderr, "c6: %016llX\n", cnt->c6);
173 fprintf(stderr, "pc2: %016llX\n", cnt->pc2); 173 if (cnt->c7) fprintf(stderr, "c7: %016llX\n", cnt->c7);
174 fprintf(stderr, "pc3: %016llX\n", cnt->pc3); 174 if (cnt->aperf) fprintf(stderr, "aperf: %016llX\n", cnt->aperf);
175 fprintf(stderr, "pc6: %016llX\n", cnt->pc6); 175 if (cnt->pc2) fprintf(stderr, "pc2: %016llX\n", cnt->pc2);
176 fprintf(stderr, "pc7: %016llX\n", cnt->pc7); 176 if (cnt->pc3) fprintf(stderr, "pc3: %016llX\n", cnt->pc3);
177 fprintf(stderr, "msr0x%x: %016llX\n", extra_msr_offset, cnt->extra_msr); 177 if (cnt->pc6) fprintf(stderr, "pc6: %016llX\n", cnt->pc6);
178 if (cnt->pc7) fprintf(stderr, "pc7: %016llX\n", cnt->pc7);
179 if (cnt->extra_msr) fprintf(stderr, "msr0x%x: %016llX\n", extra_msr_offset, cnt->extra_msr);
178} 180}
179 181
180void dump_list(struct counters *cnt) 182void dump_list(struct counters *cnt)