Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / drivers / acpi / processor_idle.c
1 /*
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>
6  *  Copyright (C) 2004, 2005 Dominik Brodowski <linux@brodo.de>
7  *  Copyright (C) 2004  Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
8  *                      - Added processor hotplug support
9  *  Copyright (C) 2005  Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
10  *                      - Added support for C3 on SMP
11  *
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/slab.h>
36 #include <linux/acpi.h>
37 #include <linux/dmi.h>
38 #include <linux/moduleparam.h>
39 #include <linux/sched.h>        /* need_resched() */
40 #include <linux/pm_qos.h>
41 #include <linux/clockchips.h>
42 #include <linux/cpuidle.h>
43 #include <linux/irqflags.h>
44
45 /*
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
55 #include <asm/io.h>
56 #include <asm/uaccess.h>
57
58 #include <acpi/acpi_bus.h>
59 #include <acpi/processor.h>
60 #include <asm/processor.h>
61
62 #define PREFIX "ACPI: "
63
64 #define ACPI_PROCESSOR_CLASS            "processor"
65 #define _COMPONENT              ACPI_PROCESSOR_COMPONENT
66 ACPI_MODULE_NAME("processor_idle");
67 #define PM_TIMER_TICK_NS                (1000000000ULL/PM_TIMER_FREQUENCY)
68 #define C2_OVERHEAD                     1       /* 1us */
69 #define C3_OVERHEAD                     1       /* 1us */
70 #define PM_TIMER_TICKS_TO_US(p)         (((p) * 1000)/(PM_TIMER_FREQUENCY/1000))
71
72 static unsigned int max_cstate __read_mostly = ACPI_PROCESSOR_MAX_POWER;
73 module_param(max_cstate, uint, 0000);
74 static unsigned int nocst __read_mostly;
75 module_param(nocst, uint, 0000);
76 static int bm_check_disable __read_mostly;
77 module_param(bm_check_disable, uint, 0000);
78
79 static unsigned int latency_factor __read_mostly = 2;
80 module_param(latency_factor, uint, 0644);
81
82 static int disabled_by_idle_boot_param(void)
83 {
84         return boot_option_idle_override == IDLE_POLL ||
85                 boot_option_idle_override == IDLE_FORCE_MWAIT ||
86                 boot_option_idle_override == IDLE_HALT;
87 }
88
89 /*
90  * IBM ThinkPad R40e crashes mysteriously when going into C2 or C3.
91  * For now disable this. Probably a bug somewhere else.
92  *
93  * To skip this limit, boot/load with a large max_cstate limit.
94  */
95 static int set_max_cstate(const struct dmi_system_id *id)
96 {
97         if (max_cstate > ACPI_PROCESSOR_MAX_POWER)
98                 return 0;
99
100         printk(KERN_NOTICE PREFIX "%s detected - limiting to C%ld max_cstate."
101                " Override with \"processor.max_cstate=%d\"\n", id->ident,
102                (long)id->driver_data, ACPI_PROCESSOR_MAX_POWER + 1);
103
104         max_cstate = (long)id->driver_data;
105
106         return 0;
107 }
108
109 /* Actually this shouldn't be __cpuinitdata, would be better to fix the
110    callers to only run once -AK */
111 static struct dmi_system_id __cpuinitdata processor_power_dmi_table[] = {
112         { set_max_cstate, "Clevo 5600D", {
113           DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
114           DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")},
115          (void *)2},
116         { set_max_cstate, "Pavilion zv5000", {
117           DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
118           DMI_MATCH(DMI_PRODUCT_NAME,"Pavilion zv5000 (DS502A#ABA)")},
119          (void *)1},
120         { set_max_cstate, "Asus L8400B", {
121           DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
122           DMI_MATCH(DMI_PRODUCT_NAME,"L8400B series Notebook PC")},
123          (void *)1},
124         {},
125 };
126
127
128 #ifndef CONFIG_PROCESSOR_EXTERNAL_CONTROL
129 /*
130  * Callers should disable interrupts before the call and enable
131  * interrupts after return.
132  */
133 static void acpi_safe_halt(void)
134 {
135         current_thread_info()->status &= ~TS_POLLING;
136         /*
137          * TS_POLLING-cleared state must be visible before we
138          * test NEED_RESCHED:
139          */
140         smp_mb();
141         if (!need_resched()) {
142                 safe_halt();
143                 local_irq_disable();
144         }
145         current_thread_info()->status |= TS_POLLING;
146 }
147 #endif
148
149 #ifdef ARCH_APICTIMER_STOPS_ON_C3
150
151 /*
152  * Some BIOS implementations switch to C3 in the published C2 state.
153  * This seems to be a common problem on AMD boxen, but other vendors
154  * are affected too. We pick the most conservative approach: we assume
155  * that the local APIC stops in both C2 and C3.
156  */
157 static void lapic_timer_check_state(int state, struct acpi_processor *pr,
158                                    struct acpi_processor_cx *cx)
159 {
160         struct acpi_processor_power *pwr = &pr->power;
161         u8 type = local_apic_timer_c2_ok ? ACPI_STATE_C3 : ACPI_STATE_C2;
162
163         if (cpu_has(&cpu_data(pr->id), X86_FEATURE_ARAT))
164                 return;
165
166         if (amd_e400_c1e_detected)
167                 type = ACPI_STATE_C1;
168
169         /*
170          * Check, if one of the previous states already marked the lapic
171          * unstable
172          */
173         if (pwr->timer_broadcast_on_state < state)
174                 return;
175
176         if (cx->type >= type)
177                 pr->power.timer_broadcast_on_state = state;
178 }
179
180 static void __lapic_timer_propagate_broadcast(void *arg)
181 {
182         struct acpi_processor *pr = (struct acpi_processor *) arg;
183         unsigned long reason;
184
185         reason = pr->power.timer_broadcast_on_state < INT_MAX ?
186                 CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF;
187
188         clockevents_notify(reason, &pr->id);
189 }
190
191 static void lapic_timer_propagate_broadcast(struct acpi_processor *pr)
192 {
193         smp_call_function_single(pr->id, __lapic_timer_propagate_broadcast,
194                                  (void *)pr, 1);
195 }
196
197 /* Power(C) State timer broadcast control */
198 static void lapic_timer_state_broadcast(struct acpi_processor *pr,
199                                        struct acpi_processor_cx *cx,
200                                        int broadcast)
201 {
202         int state = cx - pr->power.states;
203
204         if (state >= pr->power.timer_broadcast_on_state) {
205                 unsigned long reason;
206
207                 reason = broadcast ?  CLOCK_EVT_NOTIFY_BROADCAST_ENTER :
208                         CLOCK_EVT_NOTIFY_BROADCAST_EXIT;
209                 clockevents_notify(reason, &pr->id);
210         }
211 }
212
213 #else
214
215 static void lapic_timer_check_state(int state, struct acpi_processor *pr,
216                                    struct acpi_processor_cx *cstate) { }
217 static void lapic_timer_propagate_broadcast(struct acpi_processor *pr) { }
218 static inline void lapic_timer_state_broadcast(struct acpi_processor *pr,
219                                        struct acpi_processor_cx *cx,
220                                        int broadcast)
221 {
222 }
223
224 #endif
225
226 /*
227  * Suspend / resume control
228  */
229 static u32 saved_bm_rld;
230
231 static void acpi_idle_bm_rld_save(void)
232 {
233         acpi_read_bit_register(ACPI_BITREG_BUS_MASTER_RLD, &saved_bm_rld);
234 }
235 static void acpi_idle_bm_rld_restore(void)
236 {
237         u32 resumed_bm_rld;
238
239         acpi_read_bit_register(ACPI_BITREG_BUS_MASTER_RLD, &resumed_bm_rld);
240
241         if (resumed_bm_rld != saved_bm_rld)
242                 acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_RLD, saved_bm_rld);
243 }
244
245 int acpi_processor_suspend(struct acpi_device * device, pm_message_t state)
246 {
247         acpi_idle_bm_rld_save();
248         return 0;
249 }
250
251 int acpi_processor_resume(struct acpi_device * device)
252 {
253         acpi_idle_bm_rld_restore();
254         return 0;
255 }
256
257 #if defined(CONFIG_X86) && !defined(CONFIG_PROCESSOR_EXTERNAL_CONTROL)
258 static void tsc_check_state(int state)
259 {
260         switch (boot_cpu_data.x86_vendor) {
261         case X86_VENDOR_AMD:
262         case X86_VENDOR_INTEL:
263                 /*
264                  * AMD Fam10h TSC will tick in all
265                  * C/P/S0/S1 states when this bit is set.
266                  */
267                 if (boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
268                         return;
269
270                 /*FALL THROUGH*/
271         default:
272                 /* TSC could halt in idle, so notify users */
273                 if (state > ACPI_STATE_C1)
274                         mark_tsc_unstable("TSC halts in idle");
275         }
276 }
277 #else
278 static void tsc_check_state(int state) { return; }
279 #endif
280
281 static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr)
282 {
283
284         if (!pr)
285                 return -EINVAL;
286
287         if (!pr->pblk)
288                 return -ENODEV;
289
290         /* if info is obtained from pblk/fadt, type equals state */
291         pr->power.states[ACPI_STATE_C2].type = ACPI_STATE_C2;
292         pr->power.states[ACPI_STATE_C3].type = ACPI_STATE_C3;
293
294 #ifndef CONFIG_HOTPLUG_CPU
295         /*
296          * Check for P_LVL2_UP flag before entering C2 and above on
297          * an SMP system.
298          */
299         if ((num_online_cpus() > 1) &&
300             !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
301                 return -ENODEV;
302 #endif
303
304         /* determine C2 and C3 address from pblk */
305         pr->power.states[ACPI_STATE_C2].address = pr->pblk + 4;
306         pr->power.states[ACPI_STATE_C3].address = pr->pblk + 5;
307
308         /* determine latencies from FADT */
309         pr->power.states[ACPI_STATE_C2].latency = acpi_gbl_FADT.C2latency;
310         pr->power.states[ACPI_STATE_C3].latency = acpi_gbl_FADT.C3latency;
311
312         /*
313          * FADT specified C2 latency must be less than or equal to
314          * 100 microseconds.
315          */
316         if (acpi_gbl_FADT.C2latency > ACPI_PROCESSOR_MAX_C2_LATENCY) {
317                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
318                         "C2 latency too large [%d]\n", acpi_gbl_FADT.C2latency));
319                 /* invalidate C2 */
320                 pr->power.states[ACPI_STATE_C2].address = 0;
321         }
322
323         /*
324          * FADT supplied C3 latency must be less than or equal to
325          * 1000 microseconds.
326          */
327         if (acpi_gbl_FADT.C3latency > ACPI_PROCESSOR_MAX_C3_LATENCY) {
328                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
329                         "C3 latency too large [%d]\n", acpi_gbl_FADT.C3latency));
330                 /* invalidate C3 */
331                 pr->power.states[ACPI_STATE_C3].address = 0;
332         }
333
334         ACPI_DEBUG_PRINT((ACPI_DB_INFO,
335                           "lvl2[0x%08x] lvl3[0x%08x]\n",
336                           pr->power.states[ACPI_STATE_C2].address,
337                           pr->power.states[ACPI_STATE_C3].address));
338
339         return 0;
340 }
341
342 static int acpi_processor_get_power_info_default(struct acpi_processor *pr)
343 {
344         if (!pr->power.states[ACPI_STATE_C1].valid) {
345                 /* set the first C-State to C1 */
346                 /* all processors need to support C1 */
347                 pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1;
348                 pr->power.states[ACPI_STATE_C1].valid = 1;
349                 pr->power.states[ACPI_STATE_C1].entry_method = ACPI_CSTATE_HALT;
350         }
351         /* the C0 state only exists as a filler in our array */
352         pr->power.states[ACPI_STATE_C0].valid = 1;
353         return 0;
354 }
355
356 static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
357 {
358         acpi_status status = 0;
359         u64 count;
360         int current_count;
361         int i;
362         struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
363         union acpi_object *cst;
364
365
366         if (nocst)
367                 return -ENODEV;
368
369         current_count = 0;
370
371         status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer);
372         if (ACPI_FAILURE(status)) {
373                 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No _CST, giving up\n"));
374                 return -ENODEV;
375         }
376
377         cst = buffer.pointer;
378
379         /* There must be at least 2 elements */
380         if (!cst || (cst->type != ACPI_TYPE_PACKAGE) || cst->package.count < 2) {
381                 printk(KERN_ERR PREFIX "not enough elements in _CST\n");
382                 status = -EFAULT;
383                 goto end;
384         }
385
386         count = cst->package.elements[0].integer.value;
387
388         /* Validate number of power states. */
389         if (count < 1 || count != cst->package.count - 1) {
390                 printk(KERN_ERR PREFIX "count given by _CST is not valid\n");
391                 status = -EFAULT;
392                 goto end;
393         }
394
395         /* Tell driver that at least _CST is supported. */
396         pr->flags.has_cst = 1;
397
398         for (i = 1; i <= count; i++) {
399                 union acpi_object *element;
400                 union acpi_object *obj;
401                 struct acpi_power_register *reg;
402                 struct acpi_processor_cx cx;
403
404                 memset(&cx, 0, sizeof(cx));
405
406                 element = &(cst->package.elements[i]);
407                 if (element->type != ACPI_TYPE_PACKAGE)
408                         continue;
409
410                 if (element->package.count != 4)
411                         continue;
412
413                 obj = &(element->package.elements[0]);
414
415                 if (obj->type != ACPI_TYPE_BUFFER)
416                         continue;
417
418                 reg = (struct acpi_power_register *)obj->buffer.pointer;
419
420                 if (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO &&
421                     (reg->space_id != ACPI_ADR_SPACE_FIXED_HARDWARE))
422                         continue;
423
424                 /* There should be an easy way to extract an integer... */
425                 obj = &(element->package.elements[1]);
426                 if (obj->type != ACPI_TYPE_INTEGER)
427                         continue;
428
429                 cx.type = obj->integer.value;
430                 /*
431                  * Some buggy BIOSes won't list C1 in _CST -
432                  * Let acpi_processor_get_power_info_default() handle them later
433                  */
434                 if (i == 1 && cx.type != ACPI_STATE_C1)
435                         current_count++;
436
437                 cx.address = reg->address;
438                 cx.index = current_count + 1;
439
440                 cx.entry_method = ACPI_CSTATE_SYSTEMIO;
441                 if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) {
442                         if (acpi_processor_ffh_cstate_probe
443                                         (pr->id, &cx, reg) == 0) {
444                                 cx.entry_method = ACPI_CSTATE_FFH;
445                         } else if (cx.type == ACPI_STATE_C1) {
446                                 /*
447                                  * C1 is a special case where FIXED_HARDWARE
448                                  * can be handled in non-MWAIT way as well.
449                                  * In that case, save this _CST entry info.
450                                  * Otherwise, ignore this info and continue.
451                                  */
452                                 cx.entry_method = ACPI_CSTATE_HALT;
453                                 snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT");
454                         /* This doesn't apply to external control case */
455                         } else if (!processor_pm_external()) {
456                                 continue;
457                         }
458                         if (cx.type == ACPI_STATE_C1 &&
459                             (boot_option_idle_override == IDLE_NOMWAIT)) {
460                                 /*
461                                  * In most cases the C1 space_id obtained from
462                                  * _CST object is FIXED_HARDWARE access mode.
463                                  * But when the option of idle=halt is added,
464                                  * the entry_method type should be changed from
465                                  * CSTATE_FFH to CSTATE_HALT.
466                                  * When the option of idle=nomwait is added,
467                                  * the C1 entry_method type should be
468                                  * CSTATE_HALT.
469                                  */
470                                 cx.entry_method = ACPI_CSTATE_HALT;
471                                 snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT");
472                         }
473                 } else {
474                         snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI IOPORT 0x%x",
475                                  cx.address);
476                 }
477
478                 if (cx.type == ACPI_STATE_C1) {
479                         cx.valid = 1;
480                 }
481
482                 obj = &(element->package.elements[2]);
483                 if (obj->type != ACPI_TYPE_INTEGER)
484                         continue;
485
486                 cx.latency = obj->integer.value;
487
488                 obj = &(element->package.elements[3]);
489                 if (obj->type != ACPI_TYPE_INTEGER)
490                         continue;
491
492                 cx.power = obj->integer.value;
493
494 #ifdef CONFIG_PROCESSOR_EXTERNAL_CONTROL
495                 /* cache control methods to notify external logic */
496                 if (processor_pm_external())
497                         memcpy(&cx.reg, reg, sizeof(*reg));
498 #endif
499
500                 current_count++;
501                 memcpy(&(pr->power.states[current_count]), &cx, sizeof(cx));
502
503                 /*
504                  * We support total ACPI_PROCESSOR_MAX_POWER - 1
505                  * (From 1 through ACPI_PROCESSOR_MAX_POWER - 1)
506                  */
507                 if (current_count >= (ACPI_PROCESSOR_MAX_POWER - 1)) {
508                         printk(KERN_WARNING
509                                "Limiting number of power states to max (%d)\n",
510                                ACPI_PROCESSOR_MAX_POWER);
511                         printk(KERN_WARNING
512                                "Please increase ACPI_PROCESSOR_MAX_POWER if needed.\n");
513                         break;
514                 }
515         }
516
517         ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d power states\n",
518                           current_count));
519
520         /* Validate number of power states discovered */
521         if (current_count < (processor_pm_external() ? 1 : 2))
522                 status = -EFAULT;
523
524       end:
525         kfree(buffer.pointer);
526
527         return status;
528 }
529
530 static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
531                                            struct acpi_processor_cx *cx)
532 {
533         static int bm_check_flag = -1;
534         static int bm_control_flag = -1;
535
536
537         if (!cx->address)
538                 return;
539
540         /*
541          * PIIX4 Erratum #18: We don't support C3 when Type-F (fast)
542          * DMA transfers are used by any ISA device to avoid livelock.
543          * Note that we could disable Type-F DMA (as recommended by
544          * the erratum), but this is known to disrupt certain ISA
545          * devices thus we take the conservative approach.
546          */
547         else if (errata.piix4.fdma) {
548                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
549                                   "C3 not supported on PIIX4 with Type-F DMA\n"));
550                 return;
551         }
552
553         /* All the logic here assumes flags.bm_check is same across all CPUs */
554         if (bm_check_flag == -1) {
555                 /* Determine whether bm_check is needed based on CPU  */
556                 acpi_processor_power_init_bm_check(&(pr->flags), pr->id);
557                 bm_check_flag = pr->flags.bm_check;
558                 bm_control_flag = pr->flags.bm_control;
559         } else {
560                 pr->flags.bm_check = bm_check_flag;
561                 pr->flags.bm_control = bm_control_flag;
562         }
563
564         if (pr->flags.bm_check) {
565                 if (!pr->flags.bm_control) {
566                         if (pr->flags.has_cst != 1) {
567                                 /* bus mastering control is necessary */
568                                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
569                                         "C3 support requires BM control\n"));
570                                 return;
571                         } else {
572                                 /* Here we enter C3 without bus mastering */
573                                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
574                                         "C3 support without BM control\n"));
575                         }
576                 }
577         } else {
578                 /*
579                  * WBINVD should be set in fadt, for C3 state to be
580                  * supported on when bm_check is not required.
581                  */
582                 if (!(acpi_gbl_FADT.flags & ACPI_FADT_WBINVD)) {
583                         ACPI_DEBUG_PRINT((ACPI_DB_INFO,
584                                           "Cache invalidation should work properly"
585                                           " for C3 to be enabled on SMP systems\n"));
586                         return;
587                 }
588         }
589
590         /*
591          * Otherwise we've met all of our C3 requirements.
592          * Normalize the C3 latency to expidite policy.  Enable
593          * checking of bus mastering status (bm_check) so we can
594          * use this in our C3 policy
595          */
596         cx->valid = 1;
597
598         cx->latency_ticks = cx->latency;
599         /*
600          * On older chipsets, BM_RLD needs to be set
601          * in order for Bus Master activity to wake the
602          * system from C3.  Newer chipsets handle DMA
603          * during C3 automatically and BM_RLD is a NOP.
604          * In either case, the proper way to
605          * handle BM_RLD is to set it and leave it set.
606          */
607         acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_RLD, 1);
608
609         return;
610 }
611
612 static int acpi_processor_power_verify(struct acpi_processor *pr)
613 {
614         unsigned int i;
615         unsigned int working = 0;
616
617 #ifndef CONFIG_PROCESSOR_EXTERNAL_CONTROL
618         pr->power.timer_broadcast_on_state = INT_MAX;
619 #endif
620
621         for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
622                 struct acpi_processor_cx *cx = &pr->power.states[i];
623
624                 switch (cx->type) {
625                 case ACPI_STATE_C1:
626                         cx->valid = 1;
627                         break;
628
629                 case ACPI_STATE_C2:
630                         if (!cx->address)
631                                 break;
632                         cx->valid = 1; 
633                         cx->latency_ticks = cx->latency; /* Normalize latency */
634                         break;
635
636                 case ACPI_STATE_C3:
637                         acpi_processor_power_verify_c3(pr, cx);
638                         break;
639                 }
640                 if (!cx->valid)
641                         continue;
642
643                 lapic_timer_check_state(i, pr, cx);
644                 tsc_check_state(cx->type);
645                 working++;
646         }
647
648         lapic_timer_propagate_broadcast(pr);
649
650         return (working);
651 }
652
653 static int acpi_processor_get_power_info(struct acpi_processor *pr)
654 {
655         unsigned int i;
656         int result;
657
658
659         /* NOTE: the idle thread may not be running while calling
660          * this function */
661
662         /* Zero initialize all the C-states info. */
663         memset(pr->power.states, 0, sizeof(pr->power.states));
664
665         result = acpi_processor_get_power_info_cst(pr);
666         if (result == -ENODEV)
667                 result = acpi_processor_get_power_info_fadt(pr);
668
669         if (result)
670                 return result;
671
672         acpi_processor_get_power_info_default(pr);
673
674         pr->power.count = acpi_processor_power_verify(pr);
675
676         /*
677          * if one state of type C2 or C3 is available, mark this
678          * CPU as being "idle manageable"
679          */
680         for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
681                 if (pr->power.states[i].valid) {
682                         pr->power.count = i;
683                         if (pr->power.states[i].type >= ACPI_STATE_C2)
684                                 pr->flags.power = 1;
685                 }
686         }
687
688         return 0;
689 }
690
691 #ifndef CONFIG_PROCESSOR_EXTERNAL_CONTROL
692 /**
693  * acpi_idle_bm_check - checks if bus master activity was detected
694  */
695 static int acpi_idle_bm_check(void)
696 {
697         u32 bm_status = 0;
698
699         if (bm_check_disable)
700                 return 0;
701
702         acpi_read_bit_register(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status);
703         if (bm_status)
704                 acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_STATUS, 1);
705         /*
706          * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect
707          * the true state of bus mastering activity; forcing us to
708          * manually check the BMIDEA bit of each IDE channel.
709          */
710         else if (errata.piix4.bmisx) {
711                 if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01)
712                     || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01))
713                         bm_status = 1;
714         }
715         return bm_status;
716 }
717
718 /**
719  * acpi_idle_do_entry - a helper function that does C2 and C3 type entry
720  * @cx: cstate data
721  *
722  * Caller disables interrupt before call and enables interrupt after return.
723  */
724 static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx)
725 {
726         /* Don't trace irqs off for idle */
727         stop_critical_timings();
728         if (cx->entry_method == ACPI_CSTATE_FFH) {
729                 /* Call into architectural FFH based C-state */
730                 acpi_processor_ffh_cstate_enter(cx);
731         } else if (cx->entry_method == ACPI_CSTATE_HALT) {
732                 acpi_safe_halt();
733         } else {
734                 /* IO port based C-state */
735                 inb(cx->address);
736                 /* Dummy wait op - must do something useless after P_LVL2 read
737                    because chipsets cannot guarantee that STPCLK# signal
738                    gets asserted in time to freeze execution properly. */
739                 inl(acpi_gbl_FADT.xpm_timer_block.address);
740         }
741         start_critical_timings();
742 }
743
744 /**
745  * acpi_idle_enter_c1 - enters an ACPI C1 state-type
746  * @dev: the target CPU
747  * @drv: cpuidle driver containing cpuidle state info
748  * @index: index of target state
749  *
750  * This is equivalent to the HALT instruction.
751  */
752 static int acpi_idle_enter_c1(struct cpuidle_device *dev,
753                 struct cpuidle_driver *drv, int index)
754 {
755         ktime_t  kt1, kt2;
756         s64 idle_time;
757         struct acpi_processor *pr;
758         struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
759         struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
760
761         pr = __this_cpu_read(processors);
762         dev->last_residency = 0;
763
764         if (unlikely(!pr))
765                 return -EINVAL;
766
767         local_irq_disable();
768
769         lapic_timer_state_broadcast(pr, cx, 1);
770         kt1 = ktime_get_real();
771         acpi_idle_do_entry(cx);
772         kt2 = ktime_get_real();
773         idle_time =  ktime_to_us(ktime_sub(kt2, kt1));
774
775         /* Update device last_residency*/
776         dev->last_residency = (int)idle_time;
777
778         local_irq_enable();
779         cx->usage++;
780         lapic_timer_state_broadcast(pr, cx, 0);
781
782         return index;
783 }
784
785
786 /**
787  * acpi_idle_play_dead - enters an ACPI state for long-term idle (i.e. off-lining)
788  * @dev: the target CPU
789  * @index: the index of suggested state
790  */
791 static int acpi_idle_play_dead(struct cpuidle_device *dev, int index)
792 {
793         struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
794         struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
795
796         ACPI_FLUSH_CPU_CACHE();
797
798         while (1) {
799
800                 if (cx->entry_method == ACPI_CSTATE_HALT)
801                         safe_halt();
802                 else if (cx->entry_method == ACPI_CSTATE_SYSTEMIO) {
803                         inb(cx->address);
804                         /* See comment in acpi_idle_do_entry() */
805                         inl(acpi_gbl_FADT.xpm_timer_block.address);
806                 } else
807                         return -ENODEV;
808         }
809
810         /* Never reached */
811         return 0;
812 }
813
814 /**
815  * acpi_idle_enter_simple - enters an ACPI state without BM handling
816  * @dev: the target CPU
817  * @drv: cpuidle driver with cpuidle state information
818  * @index: the index of suggested state
819  */
820 static int acpi_idle_enter_simple(struct cpuidle_device *dev,
821                 struct cpuidle_driver *drv, int index)
822 {
823         struct acpi_processor *pr;
824         struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
825         struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
826         ktime_t  kt1, kt2;
827         s64 idle_time_ns;
828         s64 idle_time;
829
830         pr = __this_cpu_read(processors);
831         dev->last_residency = 0;
832
833         if (unlikely(!pr))
834                 return -EINVAL;
835
836         local_irq_disable();
837
838         if (cx->entry_method != ACPI_CSTATE_FFH) {
839                 current_thread_info()->status &= ~TS_POLLING;
840                 /*
841                  * TS_POLLING-cleared state must be visible before we test
842                  * NEED_RESCHED:
843                  */
844                 smp_mb();
845
846                 if (unlikely(need_resched())) {
847                         current_thread_info()->status |= TS_POLLING;
848                         local_irq_enable();
849                         return -EINVAL;
850                 }
851         }
852
853         /*
854          * Must be done before busmaster disable as we might need to
855          * access HPET !
856          */
857         lapic_timer_state_broadcast(pr, cx, 1);
858
859         if (cx->type == ACPI_STATE_C3)
860                 ACPI_FLUSH_CPU_CACHE();
861
862         kt1 = ktime_get_real();
863         /* Tell the scheduler that we are going deep-idle: */
864         sched_clock_idle_sleep_event();
865         acpi_idle_do_entry(cx);
866         kt2 = ktime_get_real();
867         idle_time_ns = ktime_to_ns(ktime_sub(kt2, kt1));
868         idle_time = idle_time_ns;
869         do_div(idle_time, NSEC_PER_USEC);
870
871         /* Update device last_residency*/
872         dev->last_residency = (int)idle_time;
873
874         /* Tell the scheduler how much we idled: */
875         sched_clock_idle_wakeup_event(idle_time_ns);
876
877         local_irq_enable();
878         if (cx->entry_method != ACPI_CSTATE_FFH)
879                 current_thread_info()->status |= TS_POLLING;
880
881         cx->usage++;
882
883         lapic_timer_state_broadcast(pr, cx, 0);
884         cx->time += idle_time;
885         return index;
886 }
887
888 static int c3_cpu_count;
889 static DEFINE_RAW_SPINLOCK(c3_lock);
890
891 /**
892  * acpi_idle_enter_bm - enters C3 with proper BM handling
893  * @dev: the target CPU
894  * @drv: cpuidle driver containing state data
895  * @index: the index of suggested state
896  *
897  * If BM is detected, the deepest non-C3 idle state is entered instead.
898  */
899 static int acpi_idle_enter_bm(struct cpuidle_device *dev,
900                 struct cpuidle_driver *drv, int index)
901 {
902         struct acpi_processor *pr;
903         struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
904         struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
905         ktime_t  kt1, kt2;
906         s64 idle_time_ns;
907         s64 idle_time;
908
909
910         pr = __this_cpu_read(processors);
911         dev->last_residency = 0;
912
913         if (unlikely(!pr))
914                 return -EINVAL;
915
916         if (!cx->bm_sts_skip && acpi_idle_bm_check()) {
917                 if (drv->safe_state_index >= 0) {
918                         return drv->states[drv->safe_state_index].enter(dev,
919                                                 drv, drv->safe_state_index);
920                 } else {
921                         local_irq_disable();
922                         acpi_safe_halt();
923                         local_irq_enable();
924                         return -EINVAL;
925                 }
926         }
927
928         local_irq_disable();
929
930         if (cx->entry_method != ACPI_CSTATE_FFH) {
931                 current_thread_info()->status &= ~TS_POLLING;
932                 /*
933                  * TS_POLLING-cleared state must be visible before we test
934                  * NEED_RESCHED:
935                  */
936                 smp_mb();
937
938                 if (unlikely(need_resched())) {
939                         current_thread_info()->status |= TS_POLLING;
940                         local_irq_enable();
941                         return -EINVAL;
942                 }
943         }
944
945         acpi_unlazy_tlb(smp_processor_id());
946
947         /* Tell the scheduler that we are going deep-idle: */
948         sched_clock_idle_sleep_event();
949         /*
950          * Must be done before busmaster disable as we might need to
951          * access HPET !
952          */
953         lapic_timer_state_broadcast(pr, cx, 1);
954
955         kt1 = ktime_get_real();
956         /*
957          * disable bus master
958          * bm_check implies we need ARB_DIS
959          * !bm_check implies we need cache flush
960          * bm_control implies whether we can do ARB_DIS
961          *
962          * That leaves a case where bm_check is set and bm_control is
963          * not set. In that case we cannot do much, we enter C3
964          * without doing anything.
965          */
966         if (pr->flags.bm_check && pr->flags.bm_control) {
967                 raw_spin_lock(&c3_lock);
968                 c3_cpu_count++;
969                 /* Disable bus master arbitration when all CPUs are in C3 */
970                 if (c3_cpu_count == num_online_cpus())
971                         acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 1);
972                 raw_spin_unlock(&c3_lock);
973         } else if (!pr->flags.bm_check) {
974                 ACPI_FLUSH_CPU_CACHE();
975         }
976
977         acpi_idle_do_entry(cx);
978
979         /* Re-enable bus master arbitration */
980         if (pr->flags.bm_check && pr->flags.bm_control) {
981                 raw_spin_lock(&c3_lock);
982                 acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 0);
983                 c3_cpu_count--;
984                 raw_spin_unlock(&c3_lock);
985         }
986         kt2 = ktime_get_real();
987         idle_time_ns = ktime_to_ns(ktime_sub(kt2, kt1));
988         idle_time = idle_time_ns;
989         do_div(idle_time, NSEC_PER_USEC);
990
991         /* Update device last_residency*/
992         dev->last_residency = (int)idle_time;
993
994         /* Tell the scheduler how much we idled: */
995         sched_clock_idle_wakeup_event(idle_time_ns);
996
997         local_irq_enable();
998         if (cx->entry_method != ACPI_CSTATE_FFH)
999                 current_thread_info()->status |= TS_POLLING;
1000
1001         cx->usage++;
1002
1003         lapic_timer_state_broadcast(pr, cx, 0);
1004         cx->time += idle_time;
1005         return index;
1006 }
1007
1008 struct cpuidle_driver acpi_idle_driver = {
1009         .name =         "acpi_idle",
1010         .owner =        THIS_MODULE,
1011 };
1012
1013 /**
1014  * acpi_processor_setup_cpuidle_cx - prepares and configures CPUIDLE
1015  * device i.e. per-cpu data
1016  *
1017  * @pr: the ACPI processor
1018  */
1019 static int acpi_processor_setup_cpuidle_cx(struct acpi_processor *pr)
1020 {
1021         int i, count = CPUIDLE_DRIVER_STATE_START;
1022         struct acpi_processor_cx *cx;
1023         struct cpuidle_state_usage *state_usage;
1024         struct cpuidle_device *dev = &pr->power.dev;
1025
1026         if (!pr->flags.power_setup_done)
1027                 return -EINVAL;
1028
1029         if (pr->flags.power == 0) {
1030                 return -EINVAL;
1031         }
1032
1033         dev->cpu = pr->id;
1034
1035         if (max_cstate == 0)
1036                 max_cstate = 1;
1037
1038         for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
1039                 cx = &pr->power.states[i];
1040                 state_usage = &dev->states_usage[count];
1041
1042                 if (!cx->valid)
1043                         continue;
1044
1045 #ifdef CONFIG_HOTPLUG_CPU
1046                 if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
1047                     !pr->flags.has_cst &&
1048                     !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
1049                         continue;
1050 #endif
1051
1052                 cpuidle_set_statedata(state_usage, cx);
1053
1054                 count++;
1055                 if (count == CPUIDLE_STATE_MAX)
1056                         break;
1057         }
1058
1059         dev->state_count = count;
1060
1061         if (!count)
1062                 return -EINVAL;
1063
1064         return 0;
1065 }
1066
1067 /**
1068  * acpi_processor_setup_cpuidle states- prepares and configures cpuidle
1069  * global state data i.e. idle routines
1070  *
1071  * @pr: the ACPI processor
1072  */
1073 static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
1074 {
1075         int i, count = CPUIDLE_DRIVER_STATE_START;
1076         struct acpi_processor_cx *cx;
1077         struct cpuidle_state *state;
1078         struct cpuidle_driver *drv = &acpi_idle_driver;
1079
1080         if (!pr->flags.power_setup_done)
1081                 return -EINVAL;
1082
1083         if (pr->flags.power == 0)
1084                 return -EINVAL;
1085
1086         drv->safe_state_index = -1;
1087         for (i = 0; i < CPUIDLE_STATE_MAX; i++) {
1088                 drv->states[i].name[0] = '\0';
1089                 drv->states[i].desc[0] = '\0';
1090         }
1091
1092         if (max_cstate == 0)
1093                 max_cstate = 1;
1094
1095         for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
1096                 cx = &pr->power.states[i];
1097
1098                 if (!cx->valid)
1099                         continue;
1100
1101 #ifdef CONFIG_HOTPLUG_CPU
1102                 if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
1103                     !pr->flags.has_cst &&
1104                     !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
1105                         continue;
1106 #endif
1107
1108                 state = &drv->states[count];
1109                 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i);
1110                 strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
1111                 state->exit_latency = cx->latency;
1112                 state->target_residency = cx->latency * latency_factor;
1113
1114                 state->flags = 0;
1115                 switch (cx->type) {
1116                         case ACPI_STATE_C1:
1117                         if (cx->entry_method == ACPI_CSTATE_FFH)
1118                                 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1119
1120                         state->enter = acpi_idle_enter_c1;
1121                         state->enter_dead = acpi_idle_play_dead;
1122                         drv->safe_state_index = count;
1123                         break;
1124
1125                         case ACPI_STATE_C2:
1126                         state->flags |= CPUIDLE_FLAG_TIME_VALID;
1127                         state->enter = acpi_idle_enter_simple;
1128                         state->enter_dead = acpi_idle_play_dead;
1129                         drv->safe_state_index = count;
1130                         break;
1131
1132                         case ACPI_STATE_C3:
1133                         state->flags |= CPUIDLE_FLAG_TIME_VALID;
1134                         state->enter = pr->flags.bm_check ?
1135                                         acpi_idle_enter_bm :
1136                                         acpi_idle_enter_simple;
1137                         break;
1138                 }
1139
1140                 count++;
1141                 if (count == CPUIDLE_STATE_MAX)
1142                         break;
1143         }
1144
1145         drv->state_count = count;
1146
1147         if (!count)
1148                 return -EINVAL;
1149
1150         return 0;
1151 }
1152 #else
1153 static void acpi_processor_setup_cpuidle_cx(struct acpi_processor *pr) {}
1154 static void acpi_processor_setup_cpuidle_states(struct acpi_processor *pr) {}
1155 #endif /* CONFIG_PROCESSOR_EXTERNAL_CONTROL */
1156
1157 int acpi_processor_hotplug(struct acpi_processor *pr)
1158 {
1159         int ret = 0;
1160
1161         if (disabled_by_idle_boot_param())
1162                 return 0;
1163
1164         if (!pr)
1165                 return -EINVAL;
1166
1167         if (nocst) {
1168                 return -ENODEV;
1169         }
1170
1171         if (!pr->flags.power_setup_done)
1172                 return -ENODEV;
1173
1174         if (processor_pm_external()) {
1175                 pr->flags.power = 0;
1176                 ret = acpi_processor_get_power_info(pr);
1177                 processor_notify_external(pr,
1178                         PROCESSOR_PM_CHANGE, PM_TYPE_IDLE);
1179                 return ret;
1180         }
1181
1182         cpuidle_pause_and_lock();
1183         cpuidle_disable_device(&pr->power.dev);
1184         acpi_processor_get_power_info(pr);
1185         if (pr->flags.power) {
1186                 acpi_processor_setup_cpuidle_cx(pr);
1187                 ret = cpuidle_enable_device(&pr->power.dev);
1188         }
1189         cpuidle_resume_and_unlock();
1190
1191         return ret;
1192 }
1193
1194 int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1195 {
1196         int cpu;
1197         struct acpi_processor *_pr;
1198
1199         if (disabled_by_idle_boot_param())
1200                 return 0;
1201
1202         if (!pr)
1203                 return -EINVAL;
1204
1205         if (nocst)
1206                 return -ENODEV;
1207
1208         if (!pr->flags.power_setup_done)
1209                 return -ENODEV;
1210
1211         /*
1212          * FIXME:  Design the ACPI notification to make it once per
1213          * system instead of once per-cpu.  This condition is a hack
1214          * to make the code that updates C-States be called once.
1215          */
1216
1217         if (pr->id == 0 && cpuidle_get_driver() == &acpi_idle_driver) {
1218
1219                 cpuidle_pause_and_lock();
1220                 /* Protect against cpu-hotplug */
1221                 get_online_cpus();
1222
1223                 /* Disable all cpuidle devices */
1224                 for_each_online_cpu(cpu) {
1225                         _pr = per_cpu(processors, cpu);
1226                         if (!_pr || !_pr->flags.power_setup_done)
1227                                 continue;
1228                         cpuidle_disable_device(&_pr->power.dev);
1229                 }
1230
1231                 /* Populate Updated C-state information */
1232                 acpi_processor_setup_cpuidle_states(pr);
1233
1234                 /* Enable all cpuidle devices */
1235                 for_each_online_cpu(cpu) {
1236                         _pr = per_cpu(processors, cpu);
1237                         if (!_pr || !_pr->flags.power_setup_done)
1238                                 continue;
1239                         acpi_processor_get_power_info(_pr);
1240                         if (_pr->flags.power) {
1241                                 acpi_processor_setup_cpuidle_cx(_pr);
1242                                 cpuidle_enable_device(&_pr->power.dev);
1243                         }
1244                 }
1245                 put_online_cpus();
1246                 cpuidle_resume_and_unlock();
1247         }
1248
1249         return 0;
1250 }
1251
1252 static int acpi_processor_registered;
1253
1254 int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1255                               struct acpi_device *device)
1256 {
1257         acpi_status status = 0;
1258         static int first_run;
1259
1260         if (disabled_by_idle_boot_param())
1261                 return 0;
1262
1263         if (!first_run) {
1264                 dmi_check_system(processor_power_dmi_table);
1265                 max_cstate = acpi_processor_cstate_check(max_cstate);
1266                 if (max_cstate < ACPI_C_STATES_MAX)
1267                         printk(KERN_NOTICE
1268                                "ACPI: processor limited to max C-state %d\n",
1269                                max_cstate);
1270                 first_run++;
1271         }
1272
1273         if (!pr)
1274                 return -EINVAL;
1275
1276         if (acpi_gbl_FADT.cst_control && !nocst) {
1277                 status =
1278                     acpi_os_write_port(acpi_gbl_FADT.smi_command, acpi_gbl_FADT.cst_control, 8);
1279                 if (ACPI_FAILURE(status)) {
1280                         ACPI_EXCEPTION((AE_INFO, status,
1281                                         "Notifying BIOS of _CST ability failed"));
1282                 }
1283         }
1284
1285         acpi_processor_get_power_info(pr);
1286         pr->flags.power_setup_done = 1;
1287
1288 #ifndef CONFIG_PROCESSOR_EXTERNAL_CONTROL
1289         /*
1290          * Install the idle handler if processor power management is supported.
1291          * Note that we use previously set idle handler will be used on
1292          * platforms that only support C1.
1293          */
1294         if (pr->flags.power) {
1295                 int retval;
1296
1297                 /* Register acpi_idle_driver if not already registered */
1298                 if (!acpi_processor_registered) {
1299                         acpi_processor_setup_cpuidle_states(pr);
1300                         retval = cpuidle_register_driver(&acpi_idle_driver);
1301                         if (retval)
1302                                 return retval;
1303                         printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n",
1304                                         acpi_idle_driver.name);
1305                 }
1306                 /* Register per-cpu cpuidle_device. Cpuidle driver
1307                  * must already be registered before registering device
1308                  */
1309                 acpi_processor_setup_cpuidle_cx(pr);
1310                 retval = cpuidle_register_device(&pr->power.dev);
1311                 if (retval) {
1312                         if (acpi_processor_registered == 0)
1313                                 cpuidle_unregister_driver(&acpi_idle_driver);
1314                         return retval;
1315                 }
1316                 acpi_processor_registered++;
1317         }
1318 #endif
1319
1320         if (processor_pm_external())
1321                 processor_notify_external(pr,
1322                         PROCESSOR_PM_INIT, PM_TYPE_IDLE);
1323
1324         return 0;
1325 }
1326
1327 int acpi_processor_power_exit(struct acpi_processor *pr,
1328                               struct acpi_device *device)
1329 {
1330         if (disabled_by_idle_boot_param())
1331                 return 0;
1332
1333         if (pr->flags.power) {
1334                 cpuidle_unregister_device(&pr->power.dev);
1335                 acpi_processor_registered--;
1336                 if (acpi_processor_registered == 0)
1337                         cpuidle_unregister_driver(&acpi_idle_driver);
1338         }
1339
1340         pr->flags.power_setup_done = 0;
1341         return 0;
1342 }