blob: 2fe34cc73c1327a191a48aee32b70ee14c922c9e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * processor_idle - idle state submodule to the ACPI processor driver
3 *
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
Dominik Brodowskic5ab81c2006-06-24 19:37:00 -04006 * Copyright (C) 2004, 2005 Dominik Brodowski <linux@brodo.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
8 * - Added processor hotplug support
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -04009 * Copyright (C) 2005 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
10 * - Added support for C3 on SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
12 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or (at
17 * your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 *
28 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29 */
30
31#include <linux/kernel.h>
32#include <linux/module.h>
33#include <linux/init.h>
34#include <linux/cpufreq.h>
35#include <linux/proc_fs.h>
36#include <linux/seq_file.h>
37#include <linux/acpi.h>
38#include <linux/dmi.h>
39#include <linux/moduleparam.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080040#include <linux/sched.h> /* need_resched() */
Arjan van de Ven5c875792006-09-30 23:27:17 -070041#include <linux/latency.h>
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -080042#include <linux/clockchips.h>
Len Brown4f86d3a2007-10-03 18:58:00 -040043#include <linux/cpuidle.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Thomas Gleixner34349332007-02-16 01:27:54 -080045/*
46 * Include the apic definitions for x86 to have the APIC timer related defines
47 * available also for UP (on SMP it gets magically included via linux/smp.h).
48 * asm/acpi.h is not an option, as it would require more include magic. Also
49 * creating an empty asm-ia64/apic.h would just trade pest vs. cholera.
50 */
51#ifdef CONFIG_X86
52#include <asm/apic.h>
53#endif
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <asm/io.h>
56#include <asm/uaccess.h>
57
58#include <acpi/acpi_bus.h>
59#include <acpi/processor.h>
60
61#define ACPI_PROCESSOR_COMPONENT 0x01000000
62#define ACPI_PROCESSOR_CLASS "processor"
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#define _COMPONENT ACPI_PROCESSOR_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050064ACPI_MODULE_NAME("processor_idle");
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#define ACPI_PROCESSOR_FILE_POWER "power"
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#define US_TO_PM_TIMER_TICKS(t) ((t * (PM_TIMER_FREQUENCY/1000)) / 1000)
Ingo Molnar2aa44d02007-08-23 15:18:02 +020067#define PM_TIMER_TICK_NS (1000000000ULL/PM_TIMER_FREQUENCY)
Len Brown4f86d3a2007-10-03 18:58:00 -040068#ifndef CONFIG_CPU_IDLE
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#define C2_OVERHEAD 4 /* 1us (3.579 ticks per us) */
70#define C3_OVERHEAD 4 /* 1us (3.579 ticks per us) */
Andreas Mohrb6835052006-04-27 05:25:00 -040071static void (*pm_idle_save) (void) __read_mostly;
Len Brown4f86d3a2007-10-03 18:58:00 -040072#else
73#define C2_OVERHEAD 1 /* 1us */
74#define C3_OVERHEAD 1 /* 1us */
75#endif
76#define PM_TIMER_TICKS_TO_US(p) (((p) * 1000)/(PM_TIMER_FREQUENCY/1000))
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Len Brown4f86d3a2007-10-03 18:58:00 -040078static unsigned int max_cstate __read_mostly = ACPI_PROCESSOR_MAX_POWER;
79module_param(max_cstate, uint, 0000);
Andreas Mohrb6835052006-04-27 05:25:00 -040080static unsigned int nocst __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081module_param(nocst, uint, 0000);
82
Len Brown4f86d3a2007-10-03 18:58:00 -040083#ifndef CONFIG_CPU_IDLE
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/*
85 * bm_history -- bit-mask with a bit per jiffy of bus-master activity
86 * 1000 HZ: 0xFFFFFFFF: 32 jiffies = 32ms
87 * 800 HZ: 0xFFFFFFFF: 32 jiffies = 40ms
88 * 100 HZ: 0x0000000F: 4 jiffies = 40ms
89 * reduce history for more aggressive entry into C3
90 */
Andreas Mohrb6835052006-04-27 05:25:00 -040091static unsigned int bm_history __read_mostly =
Len Brown4be44fc2005-08-05 00:44:28 -040092 (HZ >= 800 ? 0xFFFFFFFF : ((1U << (HZ / 25)) - 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070093module_param(bm_history, uint, 0644);
Len Brown4f86d3a2007-10-03 18:58:00 -040094
95static int acpi_processor_set_power_policy(struct acpi_processor *pr);
96
97#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99/*
100 * IBM ThinkPad R40e crashes mysteriously when going into C2 or C3.
101 * For now disable this. Probably a bug somewhere else.
102 *
103 * To skip this limit, boot/load with a large max_cstate limit.
104 */
Jeff Garzik18552562007-10-03 15:15:40 -0400105static int set_max_cstate(const struct dmi_system_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
107 if (max_cstate > ACPI_PROCESSOR_MAX_POWER)
108 return 0;
109
Len Brown3d356002005-08-03 00:22:52 -0400110 printk(KERN_NOTICE PREFIX "%s detected - limiting to C%ld max_cstate."
Len Brown4be44fc2005-08-05 00:44:28 -0400111 " Override with \"processor.max_cstate=%d\"\n", id->ident,
112 (long)id->driver_data, ACPI_PROCESSOR_MAX_POWER + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Len Brown3d356002005-08-03 00:22:52 -0400114 max_cstate = (long)id->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116 return 0;
117}
118
Ashok Raj7ded5682006-02-03 21:51:23 +0100119/* Actually this shouldn't be __cpuinitdata, would be better to fix the
120 callers to only run once -AK */
121static struct dmi_system_id __cpuinitdata processor_power_dmi_table[] = {
Thomas Rosner876c1842006-01-06 01:31:00 -0500122 { set_max_cstate, "IBM ThinkPad R40e", {
123 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
Bartlomiej Swierczf8313352006-05-29 07:16:00 -0400124 DMI_MATCH(DMI_BIOS_VERSION,"1SET70WW")}, (void *)1},
125 { set_max_cstate, "IBM ThinkPad R40e", {
126 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
Thomas Rosner876c1842006-01-06 01:31:00 -0500127 DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW")}, (void *)1},
128 { set_max_cstate, "IBM ThinkPad R40e", {
129 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
130 DMI_MATCH(DMI_BIOS_VERSION,"1SET43WW") }, (void*)1},
131 { set_max_cstate, "IBM ThinkPad R40e", {
132 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
133 DMI_MATCH(DMI_BIOS_VERSION,"1SET45WW") }, (void*)1},
134 { set_max_cstate, "IBM ThinkPad R40e", {
135 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
136 DMI_MATCH(DMI_BIOS_VERSION,"1SET47WW") }, (void*)1},
137 { set_max_cstate, "IBM ThinkPad R40e", {
138 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
139 DMI_MATCH(DMI_BIOS_VERSION,"1SET50WW") }, (void*)1},
140 { set_max_cstate, "IBM ThinkPad R40e", {
141 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
142 DMI_MATCH(DMI_BIOS_VERSION,"1SET52WW") }, (void*)1},
143 { set_max_cstate, "IBM ThinkPad R40e", {
144 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
145 DMI_MATCH(DMI_BIOS_VERSION,"1SET55WW") }, (void*)1},
146 { set_max_cstate, "IBM ThinkPad R40e", {
147 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
148 DMI_MATCH(DMI_BIOS_VERSION,"1SET56WW") }, (void*)1},
149 { set_max_cstate, "IBM ThinkPad R40e", {
150 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
151 DMI_MATCH(DMI_BIOS_VERSION,"1SET59WW") }, (void*)1},
152 { set_max_cstate, "IBM ThinkPad R40e", {
153 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
154 DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW") }, (void*)1},
155 { set_max_cstate, "IBM ThinkPad R40e", {
156 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
157 DMI_MATCH(DMI_BIOS_VERSION,"1SET61WW") }, (void*)1},
158 { set_max_cstate, "IBM ThinkPad R40e", {
159 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
160 DMI_MATCH(DMI_BIOS_VERSION,"1SET62WW") }, (void*)1},
161 { set_max_cstate, "IBM ThinkPad R40e", {
162 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
163 DMI_MATCH(DMI_BIOS_VERSION,"1SET64WW") }, (void*)1},
164 { set_max_cstate, "IBM ThinkPad R40e", {
165 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
166 DMI_MATCH(DMI_BIOS_VERSION,"1SET65WW") }, (void*)1},
167 { set_max_cstate, "IBM ThinkPad R40e", {
168 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
169 DMI_MATCH(DMI_BIOS_VERSION,"1SET68WW") }, (void*)1},
170 { set_max_cstate, "Medion 41700", {
171 DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
172 DMI_MATCH(DMI_BIOS_VERSION,"R01-A1J")}, (void *)1},
173 { set_max_cstate, "Clevo 5600D", {
174 DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
175 DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")},
Len Brown4be44fc2005-08-05 00:44:28 -0400176 (void *)2},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 {},
178};
179
Len Brown4be44fc2005-08-05 00:44:28 -0400180static inline u32 ticks_elapsed(u32 t1, u32 t2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
182 if (t2 >= t1)
183 return (t2 - t1);
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300184 else if (!(acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 return (((0x00FFFFFF - t1) + t2) & 0x00FFFFFF);
186 else
187 return ((0xFFFFFFFF - t1) + t2);
188}
189
Len Brown4f86d3a2007-10-03 18:58:00 -0400190static inline u32 ticks_elapsed_in_us(u32 t1, u32 t2)
191{
192 if (t2 >= t1)
193 return PM_TIMER_TICKS_TO_US(t2 - t1);
194 else if (!(acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER))
195 return PM_TIMER_TICKS_TO_US(((0x00FFFFFF - t1) + t2) & 0x00FFFFFF);
196 else
197 return PM_TIMER_TICKS_TO_US((0xFFFFFFFF - t1) + t2);
198}
199
Venkatesh Pallipadiddc081a2007-11-19 21:43:22 -0500200static void acpi_safe_halt(void)
201{
202 current_thread_info()->status &= ~TS_POLLING;
203 /*
204 * TS_POLLING-cleared state must be visible before we
205 * test NEED_RESCHED:
206 */
207 smp_mb();
208 if (!need_resched())
209 safe_halt();
210 current_thread_info()->status |= TS_POLLING;
211}
212
Len Brown4f86d3a2007-10-03 18:58:00 -0400213#ifndef CONFIG_CPU_IDLE
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215static void
Len Brown4be44fc2005-08-05 00:44:28 -0400216acpi_processor_power_activate(struct acpi_processor *pr,
217 struct acpi_processor_cx *new)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Len Brown4be44fc2005-08-05 00:44:28 -0400219 struct acpi_processor_cx *old;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 if (!pr || !new)
222 return;
223
224 old = pr->power.state;
225
226 if (old)
227 old->promotion.count = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400228 new->demotion.count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230 /* Cleanup from old state. */
231 if (old) {
232 switch (old->type) {
233 case ACPI_STATE_C3:
234 /* Disable bus master reload */
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -0400235 if (new->type != ACPI_STATE_C3 && pr->flags.bm_check)
Bob Moored8c71b62007-02-02 19:48:21 +0300236 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 break;
238 }
239 }
240
241 /* Prepare to use new state. */
242 switch (new->type) {
243 case ACPI_STATE_C3:
244 /* Enable bus master reload */
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -0400245 if (old->type != ACPI_STATE_C3 && pr->flags.bm_check)
Bob Moored8c71b62007-02-02 19:48:21 +0300246 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 break;
248 }
249
250 pr->power.state = new;
251
252 return;
253}
254
Len Brown4be44fc2005-08-05 00:44:28 -0400255static atomic_t c3_cpu_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Venkatesh Pallipadi991528d2006-09-25 16:28:13 -0700257/* Common C-state entry for C2, C3, .. */
258static void acpi_cstate_enter(struct acpi_processor_cx *cstate)
259{
260 if (cstate->space_id == ACPI_CSTATE_FFH) {
261 /* Call into architectural FFH based C-state */
262 acpi_processor_ffh_cstate_enter(cstate);
263 } else {
264 int unused;
265 /* IO port based C-state */
266 inb(cstate->address);
267 /* Dummy wait op - must do something useless after P_LVL2 read
268 because chipsets cannot guarantee that STPCLK# signal
269 gets asserted in time to freeze execution properly. */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300270 unused = inl(acpi_gbl_FADT.xpm_timer_block.address);
Venkatesh Pallipadi991528d2006-09-25 16:28:13 -0700271 }
272}
Len Brown4f86d3a2007-10-03 18:58:00 -0400273#endif /* !CONFIG_CPU_IDLE */
Venkatesh Pallipadi991528d2006-09-25 16:28:13 -0700274
Thomas Gleixner169a0ab2007-02-16 01:27:55 -0800275#ifdef ARCH_APICTIMER_STOPS_ON_C3
276
277/*
278 * Some BIOS implementations switch to C3 in the published C2 state.
Linus Torvalds296d93c2007-03-23 08:03:47 -0700279 * This seems to be a common problem on AMD boxen, but other vendors
280 * are affected too. We pick the most conservative approach: we assume
281 * that the local APIC stops in both C2 and C3.
Thomas Gleixner169a0ab2007-02-16 01:27:55 -0800282 */
283static void acpi_timer_check_state(int state, struct acpi_processor *pr,
284 struct acpi_processor_cx *cx)
285{
286 struct acpi_processor_power *pwr = &pr->power;
Thomas Gleixnere585bef2007-03-23 16:08:01 +0100287 u8 type = local_apic_timer_c2_ok ? ACPI_STATE_C3 : ACPI_STATE_C2;
Thomas Gleixner169a0ab2007-02-16 01:27:55 -0800288
289 /*
290 * Check, if one of the previous states already marked the lapic
291 * unstable
292 */
293 if (pwr->timer_broadcast_on_state < state)
294 return;
295
Thomas Gleixnere585bef2007-03-23 16:08:01 +0100296 if (cx->type >= type)
Linus Torvalds296d93c2007-03-23 08:03:47 -0700297 pr->power.timer_broadcast_on_state = state;
Thomas Gleixner169a0ab2007-02-16 01:27:55 -0800298}
299
300static void acpi_propagate_timer_broadcast(struct acpi_processor *pr)
301{
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800302 unsigned long reason;
303
304 reason = pr->power.timer_broadcast_on_state < INT_MAX ?
305 CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF;
306
307 clockevents_notify(reason, &pr->id);
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800308}
309
310/* Power(C) State timer broadcast control */
311static void acpi_state_timer_broadcast(struct acpi_processor *pr,
312 struct acpi_processor_cx *cx,
313 int broadcast)
314{
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800315 int state = cx - pr->power.states;
316
317 if (state >= pr->power.timer_broadcast_on_state) {
318 unsigned long reason;
319
320 reason = broadcast ? CLOCK_EVT_NOTIFY_BROADCAST_ENTER :
321 CLOCK_EVT_NOTIFY_BROADCAST_EXIT;
322 clockevents_notify(reason, &pr->id);
323 }
Thomas Gleixner169a0ab2007-02-16 01:27:55 -0800324}
325
326#else
327
328static void acpi_timer_check_state(int state, struct acpi_processor *pr,
329 struct acpi_processor_cx *cstate) { }
330static void acpi_propagate_timer_broadcast(struct acpi_processor *pr) { }
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800331static void acpi_state_timer_broadcast(struct acpi_processor *pr,
332 struct acpi_processor_cx *cx,
333 int broadcast)
334{
335}
Thomas Gleixner169a0ab2007-02-16 01:27:55 -0800336
337#endif
338
Thomas Gleixnerb04e7bd2007-09-22 22:29:05 +0000339/*
340 * Suspend / resume control
341 */
342static int acpi_idle_suspend;
343
344int acpi_processor_suspend(struct acpi_device * device, pm_message_t state)
345{
346 acpi_idle_suspend = 1;
347 return 0;
348}
349
350int acpi_processor_resume(struct acpi_device * device)
351{
352 acpi_idle_suspend = 0;
353 return 0;
354}
355
Len Brown4f86d3a2007-10-03 18:58:00 -0400356#ifndef CONFIG_CPU_IDLE
Len Brown4be44fc2005-08-05 00:44:28 -0400357static void acpi_processor_idle(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
Len Brown4be44fc2005-08-05 00:44:28 -0400359 struct acpi_processor *pr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 struct acpi_processor_cx *cx = NULL;
361 struct acpi_processor_cx *next_state = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400362 int sleep_ticks = 0;
363 u32 t1, t2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 /*
366 * Interrupts must be disabled during bus mastering calculations and
367 * for C2/C3 transitions.
368 */
369 local_irq_disable();
370
Venkatesh Pallipadid5a3d322007-06-15 19:36:00 -0400371 pr = processors[smp_processor_id()];
372 if (!pr) {
373 local_irq_enable();
374 return;
375 }
376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 /*
378 * Check whether we truly need to go idle, or should
379 * reschedule:
380 */
381 if (unlikely(need_resched())) {
382 local_irq_enable();
383 return;
384 }
385
386 cx = pr->power.state;
Thomas Gleixnerb04e7bd2007-09-22 22:29:05 +0000387 if (!cx || acpi_idle_suspend) {
Nick Piggin64c7c8f2005-11-08 21:39:04 -0800388 if (pm_idle_save)
389 pm_idle_save();
390 else
391 acpi_safe_halt();
392 return;
393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395 /*
396 * Check BM Activity
397 * -----------------
398 * Check for bus mastering activity (if required), record, and check
399 * for demotion.
400 */
401 if (pr->flags.bm_check) {
Len Brown4be44fc2005-08-05 00:44:28 -0400402 u32 bm_status = 0;
403 unsigned long diff = jiffies - pr->power.bm_check_timestamp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Dominik Brodowskic5ab81c2006-06-24 19:37:00 -0400405 if (diff > 31)
406 diff = 31;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Dominik Brodowskic5ab81c2006-06-24 19:37:00 -0400408 pr->power.bm_activity <<= diff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Bob Moored8c71b62007-02-02 19:48:21 +0300410 acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 if (bm_status) {
Dominik Brodowskic5ab81c2006-06-24 19:37:00 -0400412 pr->power.bm_activity |= 0x1;
Bob Moored8c71b62007-02-02 19:48:21 +0300413 acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 }
415 /*
416 * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect
417 * the true state of bus mastering activity; forcing us to
418 * manually check the BMIDEA bit of each IDE channel.
419 */
420 else if (errata.piix4.bmisx) {
421 if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01)
Len Brown4be44fc2005-08-05 00:44:28 -0400422 || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01))
Dominik Brodowskic5ab81c2006-06-24 19:37:00 -0400423 pr->power.bm_activity |= 0x1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 }
425
426 pr->power.bm_check_timestamp = jiffies;
427
428 /*
Dominik Brodowskic4a001b2006-06-24 19:37:00 -0400429 * If bus mastering is or was active this jiffy, demote
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 * to avoid a faulty transition. Note that the processor
431 * won't enter a low-power state during this call (to this
Dominik Brodowskic4a001b2006-06-24 19:37:00 -0400432 * function) but should upon the next.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 *
434 * TBD: A better policy might be to fallback to the demotion
435 * state (use it for this quantum only) istead of
436 * demoting -- and rely on duration as our sole demotion
437 * qualification. This may, however, introduce DMA
438 * issues (e.g. floppy DMA transfer overrun/underrun).
439 */
Dominik Brodowskic4a001b2006-06-24 19:37:00 -0400440 if ((pr->power.bm_activity & 0x1) &&
441 cx->demotion.threshold.bm) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 local_irq_enable();
443 next_state = cx->demotion.state;
444 goto end;
445 }
446 }
447
Venkatesh Pallipadi4c033552005-09-15 12:20:00 -0400448#ifdef CONFIG_HOTPLUG_CPU
449 /*
450 * Check for P_LVL2_UP flag before entering C2 and above on
451 * an SMP system. We do it here instead of doing it at _CST/P_LVL
452 * detection phase, to work cleanly with logical CPU hotplug.
453 */
Len Brown4f86d3a2007-10-03 18:58:00 -0400454 if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300455 !pr->flags.has_cst && !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
David Shaohua Li1e483962005-12-01 17:00:00 -0500456 cx = &pr->power.states[ACPI_STATE_C1];
Venkatesh Pallipadi4c033552005-09-15 12:20:00 -0400457#endif
David Shaohua Li1e483962005-12-01 17:00:00 -0500458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 /*
460 * Sleep:
461 * ------
462 * Invoke the current Cx state to put the processor to sleep.
463 */
Nick Piggin2a298a32005-12-02 12:44:19 +1100464 if (cx->type == ACPI_STATE_C2 || cx->type == ACPI_STATE_C3) {
Andi Kleen495ab9c2006-06-26 13:59:11 +0200465 current_thread_info()->status &= ~TS_POLLING;
Ingo Molnar0888f062006-12-22 01:11:56 -0800466 /*
467 * TS_POLLING-cleared state must be visible before we
468 * test NEED_RESCHED:
469 */
470 smp_mb();
Nick Piggin2a298a32005-12-02 12:44:19 +1100471 if (need_resched()) {
Andi Kleen495ab9c2006-06-26 13:59:11 +0200472 current_thread_info()->status |= TS_POLLING;
Linus Torvaldsaf2eb172005-12-02 23:09:06 -0800473 local_irq_enable();
Nick Piggin2a298a32005-12-02 12:44:19 +1100474 return;
475 }
476 }
477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 switch (cx->type) {
479
480 case ACPI_STATE_C1:
481 /*
482 * Invoke C1.
483 * Use the appropriate idle routine, the one that would
484 * be used without acpi C-states.
485 */
486 if (pm_idle_save)
487 pm_idle_save();
488 else
Nick Piggin64c7c8f2005-11-08 21:39:04 -0800489 acpi_safe_halt();
490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 /*
Len Brown4be44fc2005-08-05 00:44:28 -0400492 * TBD: Can't get time duration while in C1, as resumes
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 * go to an ISR rather than here. Need to instrument
494 * base interrupt handler.
Ingo Molnar2aa44d02007-08-23 15:18:02 +0200495 *
496 * Note: the TSC better not stop in C1, sched_clock() will
497 * skew otherwise.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 */
499 sleep_ticks = 0xFFFFFFFF;
500 break;
501
502 case ACPI_STATE_C2:
503 /* Get start time (ticks) */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300504 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
Ingo Molnar2aa44d02007-08-23 15:18:02 +0200505 /* Tell the scheduler that we are going deep-idle: */
506 sched_clock_idle_sleep_event();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 /* Invoke C2 */
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800508 acpi_state_timer_broadcast(pr, cx, 1);
Venkatesh Pallipadi991528d2006-09-25 16:28:13 -0700509 acpi_cstate_enter(cx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 /* Get end time (ticks) */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300511 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
john stultz539eb112006-06-26 00:25:10 -0700512
Tony Luck0aa366f2007-07-20 11:22:30 -0700513#if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86_TSC)
john stultz539eb112006-06-26 00:25:10 -0700514 /* TSC halts in C2, so notify users */
john stultz5a90cf22007-05-02 19:27:08 +0200515 mark_tsc_unstable("possible TSC halt in C2");
john stultz539eb112006-06-26 00:25:10 -0700516#endif
Ingo Molnar2aa44d02007-08-23 15:18:02 +0200517 /* Compute time (ticks) that we were actually asleep */
518 sleep_ticks = ticks_elapsed(t1, t2);
519
520 /* Tell the scheduler how much we idled: */
521 sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 /* Re-enable interrupts */
524 local_irq_enable();
Ingo Molnar2aa44d02007-08-23 15:18:02 +0200525 /* Do not account our idle-switching overhead: */
526 sleep_ticks -= cx->latency_ticks + C2_OVERHEAD;
527
Andi Kleen495ab9c2006-06-26 13:59:11 +0200528 current_thread_info()->status |= TS_POLLING;
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800529 acpi_state_timer_broadcast(pr, cx, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 break;
531
532 case ACPI_STATE_C3:
Venkatesh Pallipadi18eab852007-06-15 19:37:00 -0400533 /*
Thomas Gleixnere17bcb42007-12-07 19:16:17 +0100534 * Must be done before busmaster disable as we might
535 * need to access HPET !
536 */
537 acpi_state_timer_broadcast(pr, cx, 1);
538 /*
Venkatesh Pallipadi18eab852007-06-15 19:37:00 -0400539 * disable bus master
540 * bm_check implies we need ARB_DIS
541 * !bm_check implies we need cache flush
542 * bm_control implies whether we can do ARB_DIS
543 *
544 * That leaves a case where bm_check is set and bm_control is
545 * not set. In that case we cannot do much, we enter C3
546 * without doing anything.
547 */
548 if (pr->flags.bm_check && pr->flags.bm_control) {
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -0400549 if (atomic_inc_return(&c3_cpu_count) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400550 num_online_cpus()) {
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -0400551 /*
552 * All CPUs are trying to go to C3
553 * Disable bus master arbitration
554 */
Bob Moored8c71b62007-02-02 19:48:21 +0300555 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1);
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -0400556 }
Venkatesh Pallipadi18eab852007-06-15 19:37:00 -0400557 } else if (!pr->flags.bm_check) {
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -0400558 /* SMP with no shared cache... Invalidate cache */
559 ACPI_FLUSH_CPU_CACHE();
560 }
Len Brown4be44fc2005-08-05 00:44:28 -0400561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 /* Get start time (ticks) */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300563 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 /* Invoke C3 */
Ingo Molnar2aa44d02007-08-23 15:18:02 +0200565 /* Tell the scheduler that we are going deep-idle: */
566 sched_clock_idle_sleep_event();
Venkatesh Pallipadi991528d2006-09-25 16:28:13 -0700567 acpi_cstate_enter(cx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 /* Get end time (ticks) */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300569 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
Venkatesh Pallipadi18eab852007-06-15 19:37:00 -0400570 if (pr->flags.bm_check && pr->flags.bm_control) {
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -0400571 /* Enable bus master arbitration */
572 atomic_dec(&c3_cpu_count);
Bob Moored8c71b62007-02-02 19:48:21 +0300573 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -0400574 }
575
Tony Luck0aa366f2007-07-20 11:22:30 -0700576#if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86_TSC)
john stultz539eb112006-06-26 00:25:10 -0700577 /* TSC halts in C3, so notify users */
john stultz5a90cf22007-05-02 19:27:08 +0200578 mark_tsc_unstable("TSC halts in C3");
john stultz539eb112006-06-26 00:25:10 -0700579#endif
Ingo Molnar2aa44d02007-08-23 15:18:02 +0200580 /* Compute time (ticks) that we were actually asleep */
581 sleep_ticks = ticks_elapsed(t1, t2);
582 /* Tell the scheduler how much we idled: */
583 sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 /* Re-enable interrupts */
586 local_irq_enable();
Ingo Molnar2aa44d02007-08-23 15:18:02 +0200587 /* Do not account our idle-switching overhead: */
588 sleep_ticks -= cx->latency_ticks + C3_OVERHEAD;
589
Andi Kleen495ab9c2006-06-26 13:59:11 +0200590 current_thread_info()->status |= TS_POLLING;
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800591 acpi_state_timer_broadcast(pr, cx, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 break;
593
594 default:
595 local_irq_enable();
596 return;
597 }
Dominik Brodowskia3c65982006-06-24 19:37:00 -0400598 cx->usage++;
599 if ((cx->type != ACPI_STATE_C1) && (sleep_ticks > 0))
600 cx->time += sleep_ticks;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
602 next_state = pr->power.state;
603
David Shaohua Li1e483962005-12-01 17:00:00 -0500604#ifdef CONFIG_HOTPLUG_CPU
605 /* Don't do promotion/demotion */
606 if ((cx->type == ACPI_STATE_C1) && (num_online_cpus() > 1) &&
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300607 !pr->flags.has_cst && !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED)) {
David Shaohua Li1e483962005-12-01 17:00:00 -0500608 next_state = cx;
609 goto end;
610 }
611#endif
612
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 /*
614 * Promotion?
615 * ----------
616 * Track the number of longs (time asleep is greater than threshold)
617 * and promote when the count threshold is reached. Note that bus
618 * mastering activity may prevent promotions.
619 * Do not promote above max_cstate.
620 */
621 if (cx->promotion.state &&
622 ((cx->promotion.state - pr->power.states) <= max_cstate)) {
Arjan van de Ven5c875792006-09-30 23:27:17 -0700623 if (sleep_ticks > cx->promotion.threshold.ticks &&
624 cx->promotion.state->latency <= system_latency_constraint()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 cx->promotion.count++;
Len Brown4be44fc2005-08-05 00:44:28 -0400626 cx->demotion.count = 0;
627 if (cx->promotion.count >=
628 cx->promotion.threshold.count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 if (pr->flags.bm_check) {
Len Brown4be44fc2005-08-05 00:44:28 -0400630 if (!
631 (pr->power.bm_activity & cx->
632 promotion.threshold.bm)) {
633 next_state =
634 cx->promotion.state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 goto end;
636 }
Len Brown4be44fc2005-08-05 00:44:28 -0400637 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 next_state = cx->promotion.state;
639 goto end;
640 }
641 }
642 }
643 }
644
645 /*
646 * Demotion?
647 * ---------
648 * Track the number of shorts (time asleep is less than time threshold)
649 * and demote when the usage threshold is reached.
650 */
651 if (cx->demotion.state) {
652 if (sleep_ticks < cx->demotion.threshold.ticks) {
653 cx->demotion.count++;
654 cx->promotion.count = 0;
655 if (cx->demotion.count >= cx->demotion.threshold.count) {
656 next_state = cx->demotion.state;
657 goto end;
658 }
659 }
660 }
661
Len Brown4be44fc2005-08-05 00:44:28 -0400662 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 /*
664 * Demote if current state exceeds max_cstate
Arjan van de Ven5c875792006-09-30 23:27:17 -0700665 * or if the latency of the current state is unacceptable
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 */
Arjan van de Ven5c875792006-09-30 23:27:17 -0700667 if ((pr->power.state - pr->power.states) > max_cstate ||
668 pr->power.state->latency > system_latency_constraint()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 if (cx->demotion.state)
670 next_state = cx->demotion.state;
671 }
672
673 /*
674 * New Cx State?
675 * -------------
676 * If we're going to start using a new Cx state we must clean up
677 * from the previous and prepare to use the new.
678 */
679 if (next_state != pr->power.state)
680 acpi_processor_power_activate(pr, next_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
Len Brown4be44fc2005-08-05 00:44:28 -0400683static int acpi_processor_set_power_policy(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684{
685 unsigned int i;
686 unsigned int state_is_set = 0;
687 struct acpi_processor_cx *lower = NULL;
688 struct acpi_processor_cx *higher = NULL;
689 struct acpi_processor_cx *cx;
690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
692 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400693 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
695 /*
696 * This function sets the default Cx state policy (OS idle handler).
697 * Our scheme is to promote quickly to C2 but more conservatively
698 * to C3. We're favoring C2 for its characteristics of low latency
699 * (quick response), good power savings, and ability to allow bus
700 * mastering activity. Note that the Cx state policy is completely
701 * customizable and can be altered dynamically.
702 */
703
704 /* startup state */
Len Brown4be44fc2005-08-05 00:44:28 -0400705 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 cx = &pr->power.states[i];
707 if (!cx->valid)
708 continue;
709
710 if (!state_is_set)
711 pr->power.state = cx;
712 state_is_set++;
713 break;
Len Brown4be44fc2005-08-05 00:44:28 -0400714 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 if (!state_is_set)
Patrick Mocheld550d982006-06-27 00:41:40 -0400717 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
719 /* demotion */
Len Brown4be44fc2005-08-05 00:44:28 -0400720 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 cx = &pr->power.states[i];
722 if (!cx->valid)
723 continue;
724
725 if (lower) {
726 cx->demotion.state = lower;
727 cx->demotion.threshold.ticks = cx->latency_ticks;
728 cx->demotion.threshold.count = 1;
729 if (cx->type == ACPI_STATE_C3)
730 cx->demotion.threshold.bm = bm_history;
731 }
732
733 lower = cx;
734 }
735
736 /* promotion */
737 for (i = (ACPI_PROCESSOR_MAX_POWER - 1); i > 0; i--) {
738 cx = &pr->power.states[i];
739 if (!cx->valid)
740 continue;
741
742 if (higher) {
Len Brown4be44fc2005-08-05 00:44:28 -0400743 cx->promotion.state = higher;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 cx->promotion.threshold.ticks = cx->latency_ticks;
745 if (cx->type >= ACPI_STATE_C2)
746 cx->promotion.threshold.count = 4;
747 else
748 cx->promotion.threshold.count = 10;
749 if (higher->type == ACPI_STATE_C3)
750 cx->promotion.threshold.bm = bm_history;
751 }
752
753 higher = cx;
754 }
755
Patrick Mocheld550d982006-06-27 00:41:40 -0400756 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757}
Len Brown4f86d3a2007-10-03 18:58:00 -0400758#endif /* !CONFIG_CPU_IDLE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
Len Brown4be44fc2005-08-05 00:44:28 -0400760static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400764 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
766 if (!pr->pblk)
Patrick Mocheld550d982006-06-27 00:41:40 -0400767 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 /* if info is obtained from pblk/fadt, type equals state */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 pr->power.states[ACPI_STATE_C2].type = ACPI_STATE_C2;
771 pr->power.states[ACPI_STATE_C3].type = ACPI_STATE_C3;
772
Venkatesh Pallipadi4c033552005-09-15 12:20:00 -0400773#ifndef CONFIG_HOTPLUG_CPU
774 /*
775 * Check for P_LVL2_UP flag before entering C2 and above on
Len Brown4f86d3a2007-10-03 18:58:00 -0400776 * an SMP system.
Venkatesh Pallipadi4c033552005-09-15 12:20:00 -0400777 */
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300778 if ((num_online_cpus() > 1) &&
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300779 !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
Patrick Mocheld550d982006-06-27 00:41:40 -0400780 return -ENODEV;
Venkatesh Pallipadi4c033552005-09-15 12:20:00 -0400781#endif
782
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 /* determine C2 and C3 address from pblk */
784 pr->power.states[ACPI_STATE_C2].address = pr->pblk + 4;
785 pr->power.states[ACPI_STATE_C3].address = pr->pblk + 5;
786
787 /* determine latencies from FADT */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300788 pr->power.states[ACPI_STATE_C2].latency = acpi_gbl_FADT.C2latency;
789 pr->power.states[ACPI_STATE_C3].latency = acpi_gbl_FADT.C3latency;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
792 "lvl2[0x%08x] lvl3[0x%08x]\n",
793 pr->power.states[ACPI_STATE_C2].address,
794 pr->power.states[ACPI_STATE_C3].address));
795
Patrick Mocheld550d982006-06-27 00:41:40 -0400796 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797}
798
Venkatesh Pallipadi991528d2006-09-25 16:28:13 -0700799static int acpi_processor_get_power_info_default(struct acpi_processor *pr)
Venkatesh Pallipadiacf05f42005-03-31 23:23:15 -0500800{
Venkatesh Pallipadi991528d2006-09-25 16:28:13 -0700801 if (!pr->power.states[ACPI_STATE_C1].valid) {
802 /* set the first C-State to C1 */
803 /* all processors need to support C1 */
804 pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1;
805 pr->power.states[ACPI_STATE_C1].valid = 1;
806 }
807 /* the C0 state only exists as a filler in our array */
Venkatesh Pallipadiacf05f42005-03-31 23:23:15 -0500808 pr->power.states[ACPI_STATE_C0].valid = 1;
Patrick Mocheld550d982006-06-27 00:41:40 -0400809 return 0;
Venkatesh Pallipadiacf05f42005-03-31 23:23:15 -0500810}
811
Len Brown4be44fc2005-08-05 00:44:28 -0400812static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Len Brown4be44fc2005-08-05 00:44:28 -0400814 acpi_status status = 0;
815 acpi_integer count;
Janosch Machowinskicf824782005-08-20 08:02:00 -0400816 int current_count;
Len Brown4be44fc2005-08-05 00:44:28 -0400817 int i;
818 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
819 union acpi_object *cst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 if (nocst)
Patrick Mocheld550d982006-06-27 00:41:40 -0400823 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
Venkatesh Pallipadi991528d2006-09-25 16:28:13 -0700825 current_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
827 status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer);
828 if (ACPI_FAILURE(status)) {
829 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No _CST, giving up\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400830 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200833 cst = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
835 /* There must be at least 2 elements */
836 if (!cst || (cst->type != ACPI_TYPE_PACKAGE) || cst->package.count < 2) {
Len Brown64684632006-06-26 23:41:38 -0400837 printk(KERN_ERR PREFIX "not enough elements in _CST\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 status = -EFAULT;
839 goto end;
840 }
841
842 count = cst->package.elements[0].integer.value;
843
844 /* Validate number of power states. */
845 if (count < 1 || count != cst->package.count - 1) {
Len Brown64684632006-06-26 23:41:38 -0400846 printk(KERN_ERR PREFIX "count given by _CST is not valid\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 status = -EFAULT;
848 goto end;
849 }
850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 /* Tell driver that at least _CST is supported. */
852 pr->flags.has_cst = 1;
853
854 for (i = 1; i <= count; i++) {
855 union acpi_object *element;
856 union acpi_object *obj;
857 struct acpi_power_register *reg;
858 struct acpi_processor_cx cx;
859
860 memset(&cx, 0, sizeof(cx));
861
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200862 element = &(cst->package.elements[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 if (element->type != ACPI_TYPE_PACKAGE)
864 continue;
865
866 if (element->package.count != 4)
867 continue;
868
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200869 obj = &(element->package.elements[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
871 if (obj->type != ACPI_TYPE_BUFFER)
872 continue;
873
Len Brown4be44fc2005-08-05 00:44:28 -0400874 reg = (struct acpi_power_register *)obj->buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
876 if (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO &&
Len Brown4be44fc2005-08-05 00:44:28 -0400877 (reg->space_id != ACPI_ADR_SPACE_FIXED_HARDWARE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 continue;
879
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 /* There should be an easy way to extract an integer... */
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200881 obj = &(element->package.elements[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 if (obj->type != ACPI_TYPE_INTEGER)
883 continue;
884
885 cx.type = obj->integer.value;
Venkatesh Pallipadi991528d2006-09-25 16:28:13 -0700886 /*
887 * Some buggy BIOSes won't list C1 in _CST -
888 * Let acpi_processor_get_power_info_default() handle them later
889 */
890 if (i == 1 && cx.type != ACPI_STATE_C1)
891 current_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
Venkatesh Pallipadi991528d2006-09-25 16:28:13 -0700893 cx.address = reg->address;
894 cx.index = current_count + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
Venkatesh Pallipadi991528d2006-09-25 16:28:13 -0700896 cx.space_id = ACPI_CSTATE_SYSTEMIO;
897 if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) {
898 if (acpi_processor_ffh_cstate_probe
899 (pr->id, &cx, reg) == 0) {
900 cx.space_id = ACPI_CSTATE_FFH;
901 } else if (cx.type != ACPI_STATE_C1) {
902 /*
903 * C1 is a special case where FIXED_HARDWARE
904 * can be handled in non-MWAIT way as well.
905 * In that case, save this _CST entry info.
906 * That is, we retain space_id of SYSTEM_IO for
907 * halt based C1.
908 * Otherwise, ignore this info and continue.
909 */
910 continue;
911 }
912 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200914 obj = &(element->package.elements[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 if (obj->type != ACPI_TYPE_INTEGER)
916 continue;
917
918 cx.latency = obj->integer.value;
919
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200920 obj = &(element->package.elements[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 if (obj->type != ACPI_TYPE_INTEGER)
922 continue;
923
924 cx.power = obj->integer.value;
925
Janosch Machowinskicf824782005-08-20 08:02:00 -0400926 current_count++;
927 memcpy(&(pr->power.states[current_count]), &cx, sizeof(cx));
928
929 /*
930 * We support total ACPI_PROCESSOR_MAX_POWER - 1
931 * (From 1 through ACPI_PROCESSOR_MAX_POWER - 1)
932 */
933 if (current_count >= (ACPI_PROCESSOR_MAX_POWER - 1)) {
934 printk(KERN_WARNING
935 "Limiting number of power states to max (%d)\n",
936 ACPI_PROCESSOR_MAX_POWER);
937 printk(KERN_WARNING
938 "Please increase ACPI_PROCESSOR_MAX_POWER if needed.\n");
939 break;
940 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 }
942
Len Brown4be44fc2005-08-05 00:44:28 -0400943 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d power states\n",
Janosch Machowinskicf824782005-08-20 08:02:00 -0400944 current_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
946 /* Validate number of power states discovered */
Janosch Machowinskicf824782005-08-20 08:02:00 -0400947 if (current_count < 2)
Venkatesh Pallipadi6d93c642005-09-15 12:19:00 -0400948 status = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Len Brown4be44fc2005-08-05 00:44:28 -0400950 end:
Len Brown02438d82006-06-30 03:19:10 -0400951 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Patrick Mocheld550d982006-06-27 00:41:40 -0400953 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954}
955
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956static void acpi_processor_power_verify_c2(struct acpi_processor_cx *cx)
957{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
959 if (!cx->address)
Patrick Mocheld550d982006-06-27 00:41:40 -0400960 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
962 /*
963 * C2 latency must be less than or equal to 100
964 * microseconds.
965 */
966 else if (cx->latency > ACPI_PROCESSOR_MAX_C2_LATENCY) {
967 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400968 "latency too large [%d]\n", cx->latency));
Patrick Mocheld550d982006-06-27 00:41:40 -0400969 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 }
971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 /*
973 * Otherwise we've met all of our C2 requirements.
974 * Normalize the C2 latency to expidite policy
975 */
976 cx->valid = 1;
Len Brown4f86d3a2007-10-03 18:58:00 -0400977
978#ifndef CONFIG_CPU_IDLE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency);
Len Brown4f86d3a2007-10-03 18:58:00 -0400980#else
981 cx->latency_ticks = cx->latency;
982#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Patrick Mocheld550d982006-06-27 00:41:40 -0400984 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985}
986
Len Brown4be44fc2005-08-05 00:44:28 -0400987static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
988 struct acpi_processor_cx *cx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989{
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -0400990 static int bm_check_flag;
991
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
993 if (!cx->address)
Patrick Mocheld550d982006-06-27 00:41:40 -0400994 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
996 /*
997 * C3 latency must be less than or equal to 1000
998 * microseconds.
999 */
1000 else if (cx->latency > ACPI_PROCESSOR_MAX_C3_LATENCY) {
1001 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001002 "latency too large [%d]\n", cx->latency));
Patrick Mocheld550d982006-06-27 00:41:40 -04001003 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 }
1005
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 /*
1007 * PIIX4 Erratum #18: We don't support C3 when Type-F (fast)
1008 * DMA transfers are used by any ISA device to avoid livelock.
1009 * Note that we could disable Type-F DMA (as recommended by
1010 * the erratum), but this is known to disrupt certain ISA
1011 * devices thus we take the conservative approach.
1012 */
1013 else if (errata.piix4.fdma) {
1014 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001015 "C3 not supported on PIIX4 with Type-F DMA\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001016 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 }
1018
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -04001019 /* All the logic here assumes flags.bm_check is same across all CPUs */
1020 if (!bm_check_flag) {
1021 /* Determine whether bm_check is needed based on CPU */
1022 acpi_processor_power_init_bm_check(&(pr->flags), pr->id);
1023 bm_check_flag = pr->flags.bm_check;
1024 } else {
1025 pr->flags.bm_check = bm_check_flag;
1026 }
1027
1028 if (pr->flags.bm_check) {
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -04001029 if (!pr->flags.bm_control) {
Venki Pallipadied3110e2007-07-31 12:04:31 -07001030 if (pr->flags.has_cst != 1) {
1031 /* bus mastering control is necessary */
1032 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1033 "C3 support requires BM control\n"));
1034 return;
1035 } else {
1036 /* Here we enter C3 without bus mastering */
1037 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1038 "C3 support without BM control\n"));
1039 }
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -04001040 }
1041 } else {
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -04001042 /*
1043 * WBINVD should be set in fadt, for C3 state to be
1044 * supported on when bm_check is not required.
1045 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +03001046 if (!(acpi_gbl_FADT.flags & ACPI_FADT_WBINVD)) {
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -04001047 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001048 "Cache invalidation should work properly"
1049 " for C3 to be enabled on SMP systems\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001050 return;
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -04001051 }
Bob Moored8c71b62007-02-02 19:48:21 +03001052 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -04001053 }
1054
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 /*
1056 * Otherwise we've met all of our C3 requirements.
1057 * Normalize the C3 latency to expidite policy. Enable
1058 * checking of bus mastering status (bm_check) so we can
1059 * use this in our C3 policy
1060 */
1061 cx->valid = 1;
Len Brown4f86d3a2007-10-03 18:58:00 -04001062
1063#ifndef CONFIG_CPU_IDLE
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency);
Len Brown4f86d3a2007-10-03 18:58:00 -04001065#else
1066 cx->latency_ticks = cx->latency;
1067#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
Patrick Mocheld550d982006-06-27 00:41:40 -04001069 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070}
1071
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072static int acpi_processor_power_verify(struct acpi_processor *pr)
1073{
1074 unsigned int i;
1075 unsigned int working = 0;
Venkatesh Pallipadi6eb0a0f2006-01-11 22:44:21 +01001076
Thomas Gleixner169a0ab2007-02-16 01:27:55 -08001077 pr->power.timer_broadcast_on_state = INT_MAX;
Venkatesh Pallipadi6eb0a0f2006-01-11 22:44:21 +01001078
Len Brown4be44fc2005-08-05 00:44:28 -04001079 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 struct acpi_processor_cx *cx = &pr->power.states[i];
1081
1082 switch (cx->type) {
1083 case ACPI_STATE_C1:
1084 cx->valid = 1;
1085 break;
1086
1087 case ACPI_STATE_C2:
1088 acpi_processor_power_verify_c2(cx);
Linus Torvalds296d93c2007-03-23 08:03:47 -07001089 if (cx->valid)
Thomas Gleixner169a0ab2007-02-16 01:27:55 -08001090 acpi_timer_check_state(i, pr, cx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 break;
1092
1093 case ACPI_STATE_C3:
1094 acpi_processor_power_verify_c3(pr, cx);
Linus Torvalds296d93c2007-03-23 08:03:47 -07001095 if (cx->valid)
Thomas Gleixner169a0ab2007-02-16 01:27:55 -08001096 acpi_timer_check_state(i, pr, cx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 break;
1098 }
1099
1100 if (cx->valid)
1101 working++;
1102 }
1103
Thomas Gleixner169a0ab2007-02-16 01:27:55 -08001104 acpi_propagate_timer_broadcast(pr);
Andi Kleenbd663342006-03-25 16:31:07 +01001105
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 return (working);
1107}
1108
Len Brown4be44fc2005-08-05 00:44:28 -04001109static int acpi_processor_get_power_info(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110{
1111 unsigned int i;
1112 int result;
1113
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
1115 /* NOTE: the idle thread may not be running while calling
1116 * this function */
1117
Venkatesh Pallipadi991528d2006-09-25 16:28:13 -07001118 /* Zero initialize all the C-states info. */
1119 memset(pr->power.states, 0, sizeof(pr->power.states));
1120
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 result = acpi_processor_get_power_info_cst(pr);
Venkatesh Pallipadi6d93c642005-09-15 12:19:00 -04001122 if (result == -ENODEV)
Darrick J. Wongc5a114f2006-10-19 23:28:28 -07001123 result = acpi_processor_get_power_info_fadt(pr);
Venkatesh Pallipadi6d93c642005-09-15 12:19:00 -04001124
Venkatesh Pallipadi991528d2006-09-25 16:28:13 -07001125 if (result)
1126 return result;
1127
1128 acpi_processor_get_power_info_default(pr);
1129
Janosch Machowinskicf824782005-08-20 08:02:00 -04001130 pr->power.count = acpi_processor_power_verify(pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
Len Brown4f86d3a2007-10-03 18:58:00 -04001132#ifndef CONFIG_CPU_IDLE
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 /*
1134 * Set Default Policy
1135 * ------------------
1136 * Now that we know which states are supported, set the default
1137 * policy. Note that this policy can be changed dynamically
1138 * (e.g. encourage deeper sleeps to conserve battery life when
1139 * not on AC).
1140 */
1141 result = acpi_processor_set_power_policy(pr);
1142 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001143 return result;
Len Brown4f86d3a2007-10-03 18:58:00 -04001144#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146 /*
1147 * if one state of type C2 or C3 is available, mark this
1148 * CPU as being "idle manageable"
1149 */
1150 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
Venkatesh Pallipadiacf05f42005-03-31 23:23:15 -05001151 if (pr->power.states[i].valid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 pr->power.count = i;
Linus Torvalds2203d6e2005-11-18 07:29:51 -08001153 if (pr->power.states[i].type >= ACPI_STATE_C2)
1154 pr->flags.power = 1;
Venkatesh Pallipadiacf05f42005-03-31 23:23:15 -05001155 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 }
1157
Patrick Mocheld550d982006-06-27 00:41:40 -04001158 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159}
1160
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset)
1162{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001163 struct acpi_processor *pr = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001164 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
1167 if (!pr)
1168 goto end;
1169
1170 seq_printf(seq, "active state: C%zd\n"
Len Brown4be44fc2005-08-05 00:44:28 -04001171 "max_cstate: C%d\n"
Arjan van de Ven5c875792006-09-30 23:27:17 -07001172 "bus master activity: %08x\n"
1173 "maximum allowed latency: %d usec\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001174 pr->power.state ? pr->power.state - pr->power.states : 0,
Arjan van de Ven5c875792006-09-30 23:27:17 -07001175 max_cstate, (unsigned)pr->power.bm_activity,
1176 system_latency_constraint());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
1178 seq_puts(seq, "states:\n");
1179
1180 for (i = 1; i <= pr->power.count; i++) {
1181 seq_printf(seq, " %cC%d: ",
Len Brown4be44fc2005-08-05 00:44:28 -04001182 (&pr->power.states[i] ==
1183 pr->power.state ? '*' : ' '), i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
1185 if (!pr->power.states[i].valid) {
1186 seq_puts(seq, "<not supported>\n");
1187 continue;
1188 }
1189
1190 switch (pr->power.states[i].type) {
1191 case ACPI_STATE_C1:
1192 seq_printf(seq, "type[C1] ");
1193 break;
1194 case ACPI_STATE_C2:
1195 seq_printf(seq, "type[C2] ");
1196 break;
1197 case ACPI_STATE_C3:
1198 seq_printf(seq, "type[C3] ");
1199 break;
1200 default:
1201 seq_printf(seq, "type[--] ");
1202 break;
1203 }
1204
1205 if (pr->power.states[i].promotion.state)
1206 seq_printf(seq, "promotion[C%zd] ",
Len Brown4be44fc2005-08-05 00:44:28 -04001207 (pr->power.states[i].promotion.state -
1208 pr->power.states));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 else
1210 seq_puts(seq, "promotion[--] ");
1211
1212 if (pr->power.states[i].demotion.state)
1213 seq_printf(seq, "demotion[C%zd] ",
Len Brown4be44fc2005-08-05 00:44:28 -04001214 (pr->power.states[i].demotion.state -
1215 pr->power.states));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 else
1217 seq_puts(seq, "demotion[--] ");
1218
Dominik Brodowskia3c65982006-06-24 19:37:00 -04001219 seq_printf(seq, "latency[%03d] usage[%08d] duration[%020llu]\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001220 pr->power.states[i].latency,
Dominik Brodowskia3c65982006-06-24 19:37:00 -04001221 pr->power.states[i].usage,
Alexey Starikovskiyb0b7eaa2007-01-25 22:39:44 -05001222 (unsigned long long)pr->power.states[i].time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 }
1224
Len Brown4be44fc2005-08-05 00:44:28 -04001225 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001226 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227}
1228
1229static int acpi_processor_power_open_fs(struct inode *inode, struct file *file)
1230{
1231 return single_open(file, acpi_processor_power_seq_show,
Len Brown4be44fc2005-08-05 00:44:28 -04001232 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233}
1234
Arjan van de Vend7508032006-07-04 13:06:00 -04001235static const struct file_operations acpi_processor_power_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -04001236 .open = acpi_processor_power_open_fs,
1237 .read = seq_read,
1238 .llseek = seq_lseek,
1239 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240};
1241
Len Brown4f86d3a2007-10-03 18:58:00 -04001242#ifndef CONFIG_CPU_IDLE
1243
1244int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1245{
1246 int result = 0;
1247
1248
1249 if (!pr)
1250 return -EINVAL;
1251
1252 if (nocst) {
1253 return -ENODEV;
1254 }
1255
1256 if (!pr->flags.power_setup_done)
1257 return -ENODEV;
1258
1259 /* Fall back to the default idle loop */
1260 pm_idle = pm_idle_save;
1261 synchronize_sched(); /* Relies on interrupts forcing exit from idle. */
1262
1263 pr->flags.power = 0;
1264 result = acpi_processor_get_power_info(pr);
1265 if ((pr->flags.power == 1) && (pr->flags.power_setup_done))
1266 pm_idle = acpi_processor_idle;
1267
1268 return result;
1269}
1270
Andrew Morton1fec74a2006-10-17 00:09:58 -07001271#ifdef CONFIG_SMP
Arjan van de Ven5c875792006-09-30 23:27:17 -07001272static void smp_callback(void *v)
1273{
1274 /* we already woke the CPU up, nothing more to do */
1275}
1276
1277/*
1278 * This function gets called when a part of the kernel has a new latency
1279 * requirement. This means we need to get all processors out of their C-state,
1280 * and then recalculate a new suitable C-state. Just do a cross-cpu IPI; that
1281 * wakes them all right up.
1282 */
1283static int acpi_processor_latency_notify(struct notifier_block *b,
1284 unsigned long l, void *v)
1285{
1286 smp_call_function(smp_callback, NULL, 0, 1);
1287 return NOTIFY_OK;
1288}
1289
1290static struct notifier_block acpi_processor_latency_notifier = {
1291 .notifier_call = acpi_processor_latency_notify,
1292};
Len Brown4f86d3a2007-10-03 18:58:00 -04001293
Andrew Morton1fec74a2006-10-17 00:09:58 -07001294#endif
Arjan van de Ven5c875792006-09-30 23:27:17 -07001295
Len Brown4f86d3a2007-10-03 18:58:00 -04001296#else /* CONFIG_CPU_IDLE */
1297
1298/**
1299 * acpi_idle_bm_check - checks if bus master activity was detected
1300 */
1301static int acpi_idle_bm_check(void)
1302{
1303 u32 bm_status = 0;
1304
1305 acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status);
1306 if (bm_status)
1307 acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS, 1);
1308 /*
1309 * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect
1310 * the true state of bus mastering activity; forcing us to
1311 * manually check the BMIDEA bit of each IDE channel.
1312 */
1313 else if (errata.piix4.bmisx) {
1314 if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01)
1315 || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01))
1316 bm_status = 1;
1317 }
1318 return bm_status;
1319}
1320
1321/**
1322 * acpi_idle_update_bm_rld - updates the BM_RLD bit depending on target state
1323 * @pr: the processor
1324 * @target: the new target state
1325 */
1326static inline void acpi_idle_update_bm_rld(struct acpi_processor *pr,
1327 struct acpi_processor_cx *target)
1328{
1329 if (pr->flags.bm_rld_set && target->type != ACPI_STATE_C3) {
1330 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
1331 pr->flags.bm_rld_set = 0;
1332 }
1333
1334 if (!pr->flags.bm_rld_set && target->type == ACPI_STATE_C3) {
1335 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1);
1336 pr->flags.bm_rld_set = 1;
1337 }
1338}
1339
1340/**
1341 * acpi_idle_do_entry - a helper function that does C2 and C3 type entry
1342 * @cx: cstate data
1343 */
1344static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx)
1345{
1346 if (cx->space_id == ACPI_CSTATE_FFH) {
1347 /* Call into architectural FFH based C-state */
1348 acpi_processor_ffh_cstate_enter(cx);
1349 } else {
1350 int unused;
1351 /* IO port based C-state */
1352 inb(cx->address);
1353 /* Dummy wait op - must do something useless after P_LVL2 read
1354 because chipsets cannot guarantee that STPCLK# signal
1355 gets asserted in time to freeze execution properly. */
1356 unused = inl(acpi_gbl_FADT.xpm_timer_block.address);
1357 }
1358}
1359
1360/**
1361 * acpi_idle_enter_c1 - enters an ACPI C1 state-type
1362 * @dev: the target CPU
1363 * @state: the state data
1364 *
1365 * This is equivalent to the HALT instruction.
1366 */
1367static int acpi_idle_enter_c1(struct cpuidle_device *dev,
1368 struct cpuidle_state *state)
1369{
1370 struct acpi_processor *pr;
1371 struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
1372 pr = processors[smp_processor_id()];
1373
1374 if (unlikely(!pr))
1375 return 0;
1376
1377 if (pr->flags.bm_check)
1378 acpi_idle_update_bm_rld(pr, cx);
1379
Venkatesh Pallipadiddc081a2007-11-19 21:43:22 -05001380 acpi_safe_halt();
Len Brown4f86d3a2007-10-03 18:58:00 -04001381
1382 cx->usage++;
1383
1384 return 0;
1385}
1386
1387/**
1388 * acpi_idle_enter_simple - enters an ACPI state without BM handling
1389 * @dev: the target CPU
1390 * @state: the state data
1391 */
1392static int acpi_idle_enter_simple(struct cpuidle_device *dev,
1393 struct cpuidle_state *state)
1394{
1395 struct acpi_processor *pr;
1396 struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
1397 u32 t1, t2;
Venkatesh Pallipadi50629112007-11-19 19:49:00 -05001398 int sleep_ticks = 0;
1399
Len Brown4f86d3a2007-10-03 18:58:00 -04001400 pr = processors[smp_processor_id()];
1401
1402 if (unlikely(!pr))
1403 return 0;
1404
Len Browne1964412007-10-04 01:23:47 -04001405 if (acpi_idle_suspend)
1406 return(acpi_idle_enter_c1(dev, state));
1407
Len Brown4f86d3a2007-10-03 18:58:00 -04001408 local_irq_disable();
1409 current_thread_info()->status &= ~TS_POLLING;
1410 /*
1411 * TS_POLLING-cleared state must be visible before we test
1412 * NEED_RESCHED:
1413 */
1414 smp_mb();
1415
1416 if (unlikely(need_resched())) {
1417 current_thread_info()->status |= TS_POLLING;
1418 local_irq_enable();
1419 return 0;
1420 }
1421
Thomas Gleixnere17bcb42007-12-07 19:16:17 +01001422 /*
1423 * Must be done before busmaster disable as we might need to
1424 * access HPET !
1425 */
1426 acpi_state_timer_broadcast(pr, cx, 1);
1427
1428 if (pr->flags.bm_check)
1429 acpi_idle_update_bm_rld(pr, cx);
1430
Len Brown4f86d3a2007-10-03 18:58:00 -04001431 if (cx->type == ACPI_STATE_C3)
1432 ACPI_FLUSH_CPU_CACHE();
1433
1434 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
Venkatesh Pallipadi50629112007-11-19 19:49:00 -05001435 /* Tell the scheduler that we are going deep-idle: */
1436 sched_clock_idle_sleep_event();
Len Brown4f86d3a2007-10-03 18:58:00 -04001437 acpi_idle_do_entry(cx);
1438 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
1439
1440#if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86_TSC)
1441 /* TSC could halt in idle, so notify users */
1442 mark_tsc_unstable("TSC halts in idle");;
1443#endif
Venkatesh Pallipadi50629112007-11-19 19:49:00 -05001444 sleep_ticks = ticks_elapsed(t1, t2);
1445
1446 /* Tell the scheduler how much we idled: */
1447 sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
Len Brown4f86d3a2007-10-03 18:58:00 -04001448
1449 local_irq_enable();
1450 current_thread_info()->status |= TS_POLLING;
1451
1452 cx->usage++;
1453
1454 acpi_state_timer_broadcast(pr, cx, 0);
Venkatesh Pallipadi50629112007-11-19 19:49:00 -05001455 cx->time += sleep_ticks;
Len Brown4f86d3a2007-10-03 18:58:00 -04001456 return ticks_elapsed_in_us(t1, t2);
1457}
1458
1459static int c3_cpu_count;
1460static DEFINE_SPINLOCK(c3_lock);
1461
1462/**
1463 * acpi_idle_enter_bm - enters C3 with proper BM handling
1464 * @dev: the target CPU
1465 * @state: the state data
1466 *
1467 * If BM is detected, the deepest non-C3 idle state is entered instead.
1468 */
1469static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1470 struct cpuidle_state *state)
1471{
1472 struct acpi_processor *pr;
1473 struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
1474 u32 t1, t2;
Venkatesh Pallipadi50629112007-11-19 19:49:00 -05001475 int sleep_ticks = 0;
1476
Len Brown4f86d3a2007-10-03 18:58:00 -04001477 pr = processors[smp_processor_id()];
1478
1479 if (unlikely(!pr))
1480 return 0;
1481
Len Browne1964412007-10-04 01:23:47 -04001482 if (acpi_idle_suspend)
1483 return(acpi_idle_enter_c1(dev, state));
1484
Venkatesh Pallipadiddc081a2007-11-19 21:43:22 -05001485 if (acpi_idle_bm_check()) {
1486 if (dev->safe_state) {
1487 return dev->safe_state->enter(dev, dev->safe_state);
1488 } else {
1489 acpi_safe_halt();
1490 return 0;
1491 }
1492 }
1493
Len Brown4f86d3a2007-10-03 18:58:00 -04001494 local_irq_disable();
1495 current_thread_info()->status &= ~TS_POLLING;
1496 /*
1497 * TS_POLLING-cleared state must be visible before we test
1498 * NEED_RESCHED:
1499 */
1500 smp_mb();
1501
1502 if (unlikely(need_resched())) {
1503 current_thread_info()->status |= TS_POLLING;
1504 local_irq_enable();
1505 return 0;
1506 }
1507
Venkatesh Pallipadi50629112007-11-19 19:49:00 -05001508 /* Tell the scheduler that we are going deep-idle: */
1509 sched_clock_idle_sleep_event();
Len Brown4f86d3a2007-10-03 18:58:00 -04001510 /*
1511 * Must be done before busmaster disable as we might need to
1512 * access HPET !
1513 */
1514 acpi_state_timer_broadcast(pr, cx, 1);
1515
Venkatesh Pallipadiddc081a2007-11-19 21:43:22 -05001516 acpi_idle_update_bm_rld(pr, cx);
Len Brown4f86d3a2007-10-03 18:58:00 -04001517
Venkatesh Pallipadiddc081a2007-11-19 21:43:22 -05001518 /*
1519 * disable bus master
1520 * bm_check implies we need ARB_DIS
1521 * !bm_check implies we need cache flush
1522 * bm_control implies whether we can do ARB_DIS
1523 *
1524 * That leaves a case where bm_check is set and bm_control is
1525 * not set. In that case we cannot do much, we enter C3
1526 * without doing anything.
1527 */
1528 if (pr->flags.bm_check && pr->flags.bm_control) {
Len Brown4f86d3a2007-10-03 18:58:00 -04001529 spin_lock(&c3_lock);
1530 c3_cpu_count++;
1531 /* Disable bus master arbitration when all CPUs are in C3 */
1532 if (c3_cpu_count == num_online_cpus())
1533 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1);
1534 spin_unlock(&c3_lock);
Venkatesh Pallipadiddc081a2007-11-19 21:43:22 -05001535 } else if (!pr->flags.bm_check) {
1536 ACPI_FLUSH_CPU_CACHE();
1537 }
Len Brown4f86d3a2007-10-03 18:58:00 -04001538
Venkatesh Pallipadiddc081a2007-11-19 21:43:22 -05001539 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
1540 acpi_idle_do_entry(cx);
1541 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
Len Brown4f86d3a2007-10-03 18:58:00 -04001542
Venkatesh Pallipadiddc081a2007-11-19 21:43:22 -05001543 /* Re-enable bus master arbitration */
1544 if (pr->flags.bm_check && pr->flags.bm_control) {
Len Brown4f86d3a2007-10-03 18:58:00 -04001545 spin_lock(&c3_lock);
Venkatesh Pallipadiddc081a2007-11-19 21:43:22 -05001546 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
Len Brown4f86d3a2007-10-03 18:58:00 -04001547 c3_cpu_count--;
1548 spin_unlock(&c3_lock);
1549 }
1550
1551#if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86_TSC)
1552 /* TSC could halt in idle, so notify users */
1553 mark_tsc_unstable("TSC halts in idle");
1554#endif
Venkatesh Pallipadi50629112007-11-19 19:49:00 -05001555 sleep_ticks = ticks_elapsed(t1, t2);
1556 /* Tell the scheduler how much we idled: */
1557 sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
Len Brown4f86d3a2007-10-03 18:58:00 -04001558
1559 local_irq_enable();
1560 current_thread_info()->status |= TS_POLLING;
1561
1562 cx->usage++;
1563
1564 acpi_state_timer_broadcast(pr, cx, 0);
Venkatesh Pallipadi50629112007-11-19 19:49:00 -05001565 cx->time += sleep_ticks;
Len Brown4f86d3a2007-10-03 18:58:00 -04001566 return ticks_elapsed_in_us(t1, t2);
1567}
1568
1569struct cpuidle_driver acpi_idle_driver = {
1570 .name = "acpi_idle",
1571 .owner = THIS_MODULE,
1572};
1573
1574/**
1575 * acpi_processor_setup_cpuidle - prepares and configures CPUIDLE
1576 * @pr: the ACPI processor
1577 */
1578static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1579{
1580 int i, count = 0;
1581 struct acpi_processor_cx *cx;
1582 struct cpuidle_state *state;
1583 struct cpuidle_device *dev = &pr->power.dev;
1584
1585 if (!pr->flags.power_setup_done)
1586 return -EINVAL;
1587
1588 if (pr->flags.power == 0) {
1589 return -EINVAL;
1590 }
1591
1592 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
1593 cx = &pr->power.states[i];
1594 state = &dev->states[count];
1595
1596 if (!cx->valid)
1597 continue;
1598
1599#ifdef CONFIG_HOTPLUG_CPU
1600 if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
1601 !pr->flags.has_cst &&
1602 !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
1603 continue;
1604#endif
1605 cpuidle_set_statedata(state, cx);
1606
1607 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i);
1608 state->exit_latency = cx->latency;
1609 state->target_residency = cx->latency * 6;
1610 state->power_usage = cx->power;
1611
1612 state->flags = 0;
1613 switch (cx->type) {
1614 case ACPI_STATE_C1:
1615 state->flags |= CPUIDLE_FLAG_SHALLOW;
1616 state->enter = acpi_idle_enter_c1;
Venkatesh Pallipadiddc081a2007-11-19 21:43:22 -05001617 dev->safe_state = state;
Len Brown4f86d3a2007-10-03 18:58:00 -04001618 break;
1619
1620 case ACPI_STATE_C2:
1621 state->flags |= CPUIDLE_FLAG_BALANCED;
1622 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1623 state->enter = acpi_idle_enter_simple;
Venkatesh Pallipadiddc081a2007-11-19 21:43:22 -05001624 dev->safe_state = state;
Len Brown4f86d3a2007-10-03 18:58:00 -04001625 break;
1626
1627 case ACPI_STATE_C3:
1628 state->flags |= CPUIDLE_FLAG_DEEP;
1629 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1630 state->flags |= CPUIDLE_FLAG_CHECK_BM;
1631 state->enter = pr->flags.bm_check ?
1632 acpi_idle_enter_bm :
1633 acpi_idle_enter_simple;
1634 break;
1635 }
1636
1637 count++;
1638 }
1639
1640 dev->state_count = count;
1641
1642 if (!count)
1643 return -EINVAL;
1644
Len Brown4f86d3a2007-10-03 18:58:00 -04001645 return 0;
1646}
1647
1648int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1649{
1650 int ret;
1651
1652 if (!pr)
1653 return -EINVAL;
1654
1655 if (nocst) {
1656 return -ENODEV;
1657 }
1658
1659 if (!pr->flags.power_setup_done)
1660 return -ENODEV;
1661
1662 cpuidle_pause_and_lock();
1663 cpuidle_disable_device(&pr->power.dev);
1664 acpi_processor_get_power_info(pr);
1665 acpi_processor_setup_cpuidle(pr);
1666 ret = cpuidle_enable_device(&pr->power.dev);
1667 cpuidle_resume_and_unlock();
1668
1669 return ret;
1670}
1671
1672#endif /* CONFIG_CPU_IDLE */
1673
Pierre Ossman7af8b662006-10-10 14:20:31 -07001674int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
Len Brown4be44fc2005-08-05 00:44:28 -04001675 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676{
Len Brown4be44fc2005-08-05 00:44:28 -04001677 acpi_status status = 0;
Andreas Mohrb6835052006-04-27 05:25:00 -04001678 static int first_run;
Len Brown4be44fc2005-08-05 00:44:28 -04001679 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 unsigned int i;
1681
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682
1683 if (!first_run) {
1684 dmi_check_system(processor_power_dmi_table);
Alexey Starikovskiyc1c30632007-11-26 20:42:19 +01001685 max_cstate = acpi_processor_cstate_check(max_cstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 if (max_cstate < ACPI_C_STATES_MAX)
Len Brown4be44fc2005-08-05 00:44:28 -04001687 printk(KERN_NOTICE
1688 "ACPI: processor limited to max C-state %d\n",
1689 max_cstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 first_run++;
Len Brown4f86d3a2007-10-03 18:58:00 -04001691#if !defined (CONFIG_CPU_IDLE) && defined (CONFIG_SMP)
Arjan van de Ven5c875792006-09-30 23:27:17 -07001692 register_latency_notifier(&acpi_processor_latency_notifier);
Andrew Morton1fec74a2006-10-17 00:09:58 -07001693#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 }
1695
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -04001696 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -04001697 return -EINVAL;
Venkatesh Pallipadi02df8b92005-04-15 15:07:10 -04001698
Alexey Starikovskiycee324b2007-02-02 19:48:22 +03001699 if (acpi_gbl_FADT.cst_control && !nocst) {
Len Brown4be44fc2005-08-05 00:44:28 -04001700 status =
Alexey Starikovskiycee324b2007-02-02 19:48:22 +03001701 acpi_os_write_port(acpi_gbl_FADT.smi_command, acpi_gbl_FADT.cst_control, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001703 ACPI_EXCEPTION((AE_INFO, status,
1704 "Notifying BIOS of _CST ability failed"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 }
1706 }
1707
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 acpi_processor_get_power_info(pr);
Len Brown4f86d3a2007-10-03 18:58:00 -04001709 pr->flags.power_setup_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
1711 /*
1712 * Install the idle handler if processor power management is supported.
1713 * Note that we use previously set idle handler will be used on
1714 * platforms that only support C1.
1715 */
1716 if ((pr->flags.power) && (!boot_option_idle_override)) {
Len Brown4f86d3a2007-10-03 18:58:00 -04001717#ifdef CONFIG_CPU_IDLE
1718 acpi_processor_setup_cpuidle(pr);
1719 pr->power.dev.cpu = pr->id;
1720 if (cpuidle_register_device(&pr->power.dev))
1721 return -EIO;
1722#endif
1723
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 printk(KERN_INFO PREFIX "CPU%d (power states:", pr->id);
1725 for (i = 1; i <= pr->power.count; i++)
1726 if (pr->power.states[i].valid)
Len Brown4be44fc2005-08-05 00:44:28 -04001727 printk(" C%d[C%d]", i,
1728 pr->power.states[i].type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 printk(")\n");
1730
Len Brown4f86d3a2007-10-03 18:58:00 -04001731#ifndef CONFIG_CPU_IDLE
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 if (pr->id == 0) {
1733 pm_idle_save = pm_idle;
1734 pm_idle = acpi_processor_idle;
1735 }
Len Brown4f86d3a2007-10-03 18:58:00 -04001736#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 }
1738
1739 /* 'power' [R] */
1740 entry = create_proc_entry(ACPI_PROCESSOR_FILE_POWER,
Len Brown4be44fc2005-08-05 00:44:28 -04001741 S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 if (!entry)
Thomas Renningera6fc6722006-06-26 23:58:43 -04001743 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 else {
1745 entry->proc_fops = &acpi_processor_power_fops;
1746 entry->data = acpi_driver_data(device);
1747 entry->owner = THIS_MODULE;
1748 }
1749
Patrick Mocheld550d982006-06-27 00:41:40 -04001750 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751}
1752
Len Brown4be44fc2005-08-05 00:44:28 -04001753int acpi_processor_power_exit(struct acpi_processor *pr,
1754 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755{
Len Brown4f86d3a2007-10-03 18:58:00 -04001756#ifdef CONFIG_CPU_IDLE
1757 if ((pr->flags.power) && (!boot_option_idle_override))
1758 cpuidle_unregister_device(&pr->power.dev);
1759#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 pr->flags.power_setup_done = 0;
1761
1762 if (acpi_device_dir(device))
Len Brown4be44fc2005-08-05 00:44:28 -04001763 remove_proc_entry(ACPI_PROCESSOR_FILE_POWER,
1764 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
Len Brown4f86d3a2007-10-03 18:58:00 -04001766#ifndef CONFIG_CPU_IDLE
1767
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 /* Unregister the idle handler when processor #0 is removed. */
1769 if (pr->id == 0) {
1770 pm_idle = pm_idle_save;
1771
1772 /*
1773 * We are about to unload the current idle thread pm callback
1774 * (pm_idle), Wait for all processors to update cached/local
1775 * copies of pm_idle before proceeding.
1776 */
1777 cpu_idle_wait();
Andrew Morton1fec74a2006-10-17 00:09:58 -07001778#ifdef CONFIG_SMP
Arjan van de Ven5c875792006-09-30 23:27:17 -07001779 unregister_latency_notifier(&acpi_processor_latency_notifier);
Andrew Morton1fec74a2006-10-17 00:09:58 -07001780#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 }
Len Brown4f86d3a2007-10-03 18:58:00 -04001782#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
Patrick Mocheld550d982006-06-27 00:41:40 -04001784 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785}