]> err.no Git - linux-2.6/blobdiff - drivers/acpi/processor_idle.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6
[linux-2.6] / drivers / acpi / processor_idle.c
index cc049338e418b5b968888faafd22a85492752bab..8a74bf3efd8eec821e3487fcbb835f3121fecf2d 100644 (file)
@@ -54,10 +54,10 @@ ACPI_MODULE_NAME("acpi_processor")
 #define US_TO_PM_TIMER_TICKS(t)                ((t * (PM_TIMER_FREQUENCY/1000)) / 1000)
 #define C2_OVERHEAD                    4       /* 1us (3.579 ticks per us) */
 #define C3_OVERHEAD                    4       /* 1us (3.579 ticks per us) */
-static void (*pm_idle_save) (void);
+static void (*pm_idle_save) (void) __read_mostly;
 module_param(max_cstate, uint, 0644);
 
-static unsigned int nocst = 0;
+static unsigned int nocst __read_mostly;
 module_param(nocst, uint, 0000);
 
 /*
@@ -67,7 +67,7 @@ module_param(nocst, uint, 0000);
  * 100 HZ: 0x0000000F: 4 jiffies = 40ms
  * reduce history for more aggressive entry into C3
  */
-static unsigned int bm_history =
+static unsigned int bm_history __read_mostly =
     (HZ >= 800 ? 0xFFFFFFFF : ((1U << (HZ / 25)) - 1));
 module_param(bm_history, uint, 0644);
 /* --------------------------------------------------------------------------
@@ -94,23 +94,60 @@ static int set_max_cstate(struct dmi_system_id *id)
        return 0;
 }
 
-static struct dmi_system_id __initdata processor_power_dmi_table[] = {
-       {set_max_cstate, "IBM ThinkPad R40e", {
-                                              DMI_MATCH(DMI_BIOS_VENDOR,
-                                                        "IBM"),
-                                              DMI_MATCH(DMI_BIOS_VERSION,
-                                                        "1SET60WW")},
-        (void *)1},
-       {set_max_cstate, "Medion 41700", {
-                                         DMI_MATCH(DMI_BIOS_VENDOR,
-                                                   "Phoenix Technologies LTD"),
-                                         DMI_MATCH(DMI_BIOS_VERSION,
-                                                   "R01-A1J")}, (void *)1},
-       {set_max_cstate, "Clevo 5600D", {
-                                        DMI_MATCH(DMI_BIOS_VENDOR,
-                                                  "Phoenix Technologies LTD"),
-                                        DMI_MATCH(DMI_BIOS_VERSION,
-                                                  "SHE845M0.86C.0013.D.0302131307")},
+/* Actually this shouldn't be __cpuinitdata, would be better to fix the
+   callers to only run once -AK */
+static struct dmi_system_id __cpuinitdata processor_power_dmi_table[] = {
+       { set_max_cstate, "IBM ThinkPad R40e", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
+         DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW")}, (void *)1},
+       { set_max_cstate, "IBM ThinkPad R40e", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
+         DMI_MATCH(DMI_BIOS_VERSION,"1SET43WW") }, (void*)1},
+       { set_max_cstate, "IBM ThinkPad R40e", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
+         DMI_MATCH(DMI_BIOS_VERSION,"1SET45WW") }, (void*)1},
+       { set_max_cstate, "IBM ThinkPad R40e", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
+         DMI_MATCH(DMI_BIOS_VERSION,"1SET47WW") }, (void*)1},
+       { set_max_cstate, "IBM ThinkPad R40e", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
+         DMI_MATCH(DMI_BIOS_VERSION,"1SET50WW") }, (void*)1},
+       { set_max_cstate, "IBM ThinkPad R40e", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
+         DMI_MATCH(DMI_BIOS_VERSION,"1SET52WW") }, (void*)1},
+       { set_max_cstate, "IBM ThinkPad R40e", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
+         DMI_MATCH(DMI_BIOS_VERSION,"1SET55WW") }, (void*)1},
+       { set_max_cstate, "IBM ThinkPad R40e", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
+         DMI_MATCH(DMI_BIOS_VERSION,"1SET56WW") }, (void*)1},
+       { set_max_cstate, "IBM ThinkPad R40e", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
+         DMI_MATCH(DMI_BIOS_VERSION,"1SET59WW") }, (void*)1},
+       { set_max_cstate, "IBM ThinkPad R40e", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
+         DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW") }, (void*)1},
+       { set_max_cstate, "IBM ThinkPad R40e", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
+         DMI_MATCH(DMI_BIOS_VERSION,"1SET61WW") }, (void*)1},
+       { set_max_cstate, "IBM ThinkPad R40e", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
+         DMI_MATCH(DMI_BIOS_VERSION,"1SET62WW") }, (void*)1},
+       { set_max_cstate, "IBM ThinkPad R40e", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
+         DMI_MATCH(DMI_BIOS_VERSION,"1SET64WW") }, (void*)1},
+       { set_max_cstate, "IBM ThinkPad R40e", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
+         DMI_MATCH(DMI_BIOS_VERSION,"1SET65WW") }, (void*)1},
+       { set_max_cstate, "IBM ThinkPad R40e", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
+         DMI_MATCH(DMI_BIOS_VERSION,"1SET68WW") }, (void*)1},
+       { set_max_cstate, "Medion 41700", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
+         DMI_MATCH(DMI_BIOS_VERSION,"R01-A1J")}, (void *)1},
+       { set_max_cstate, "Clevo 5600D", {
+         DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
+         DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")},
         (void *)2},
        {},
 };
@@ -169,11 +206,11 @@ acpi_processor_power_activate(struct acpi_processor *pr,
 
 static void acpi_safe_halt(void)
 {
-       clear_thread_flag(TIF_POLLING_NRFLAG);
+       current_thread_info()->status &= ~TS_POLLING;
        smp_mb__after_clear_bit();
        if (!need_resched())
                safe_halt();
-       set_thread_flag(TIF_POLLING_NRFLAG);
+       current_thread_info()->status |= TS_POLLING;
 }
 
 static atomic_t c3_cpu_count;
@@ -293,10 +330,10 @@ static void acpi_processor_idle(void)
         * Invoke the current Cx state to put the processor to sleep.
         */
        if (cx->type == ACPI_STATE_C2 || cx->type == ACPI_STATE_C3) {
-               clear_thread_flag(TIF_POLLING_NRFLAG);
+               current_thread_info()->status &= ~TS_POLLING;
                smp_mb__after_clear_bit();
                if (need_resched()) {
-                       set_thread_flag(TIF_POLLING_NRFLAG);
+                       current_thread_info()->status |= TS_POLLING;
                        local_irq_enable();
                        return;
                }
@@ -332,9 +369,14 @@ static void acpi_processor_idle(void)
                t2 = inl(acpi_fadt.xpm_tmr_blk.address);
                /* Get end time (ticks) */
                t2 = inl(acpi_fadt.xpm_tmr_blk.address);
+
+#ifdef CONFIG_GENERIC_TIME
+               /* TSC halts in C2, so notify users */
+               mark_tsc_unstable();
+#endif
                /* Re-enable interrupts */
                local_irq_enable();
-               set_thread_flag(TIF_POLLING_NRFLAG);
+               current_thread_info()->status |= TS_POLLING;
                /* Compute time (ticks) that we were actually asleep */
                sleep_ticks =
                    ticks_elapsed(t1, t2) - cx->latency_ticks - C2_OVERHEAD;
@@ -372,9 +414,13 @@ static void acpi_processor_idle(void)
                                          ACPI_MTX_DO_NOT_LOCK);
                }
 
+#ifdef CONFIG_GENERIC_TIME
+               /* TSC halts in C3, so notify users */
+               mark_tsc_unstable();
+#endif
                /* Re-enable interrupts */
                local_irq_enable();
-               set_thread_flag(TIF_POLLING_NRFLAG);
+               current_thread_info()->status |= TS_POLLING;
                /* Compute time (ticks) that we were actually asleep */
                sleep_ticks =
                    ticks_elapsed(t1, t2) - cx->latency_ticks - C3_OVERHEAD;
@@ -550,18 +596,10 @@ static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr)
        if (!pr->pblk)
                return_VALUE(-ENODEV);
 
-       memset(pr->power.states, 0, sizeof(pr->power.states));
-
        /* if info is obtained from pblk/fadt, type equals state */
-       pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1;
        pr->power.states[ACPI_STATE_C2].type = ACPI_STATE_C2;
        pr->power.states[ACPI_STATE_C3].type = ACPI_STATE_C3;
 
-       /* the C0 state only exists as a filler in our array,
-        * and all processors need to support C1 */
-       pr->power.states[ACPI_STATE_C0].valid = 1;
-       pr->power.states[ACPI_STATE_C1].valid = 1;
-
 #ifndef CONFIG_HOTPLUG_CPU
        /*
         * Check for P_LVL2_UP flag before entering C2 and above on
@@ -591,12 +629,11 @@ static int acpi_processor_get_power_info_default_c1(struct acpi_processor *pr)
 {
        ACPI_FUNCTION_TRACE("acpi_processor_get_power_info_default_c1");
 
+       /* Zero initialize all the C-states info. */
        memset(pr->power.states, 0, sizeof(pr->power.states));
 
-       /* if info is obtained from pblk/fadt, type equals state */
+       /* set the first C-State to C1 */
        pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1;
-       pr->power.states[ACPI_STATE_C2].type = ACPI_STATE_C2;
-       pr->power.states[ACPI_STATE_C3].type = ACPI_STATE_C3;
 
        /* the C0 state only exists as a filler in our array,
         * and all processors need to support C1 */
@@ -610,6 +647,7 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
 {
        acpi_status status = 0;
        acpi_integer count;
+       int current_count;
        int i;
        struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
        union acpi_object *cst;
@@ -619,10 +657,12 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
        if (nocst)
                return_VALUE(-ENODEV);
 
-       pr->power.count = 0;
-       for (i = 0; i < ACPI_PROCESSOR_MAX_POWER; i++)
-               memset(&(pr->power.states[i]), 0,
-                      sizeof(struct acpi_processor_cx));
+       current_count = 1;
+
+       /* Zero initialize C2 onwards and prepare for fresh CST lookup */
+       for (i = 2; i < ACPI_PROCESSOR_MAX_POWER; i++)
+               memset(&(pr->power.states[i]), 0, 
+                               sizeof(struct acpi_processor_cx));
 
        status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer);
        if (ACPI_FAILURE(status)) {
@@ -650,16 +690,6 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
                goto end;
        }
 
-       /* We support up to ACPI_PROCESSOR_MAX_POWER. */
-       if (count > ACPI_PROCESSOR_MAX_POWER) {
-               printk(KERN_WARNING
-                      "Limiting number of power states to max (%d)\n",
-                      ACPI_PROCESSOR_MAX_POWER);
-               printk(KERN_WARNING
-                      "Please increase ACPI_PROCESSOR_MAX_POWER if needed.\n");
-               count = ACPI_PROCESSOR_MAX_POWER;
-       }
-
        /* Tell driver that at least _CST is supported. */
        pr->flags.has_cst = 1;
 
@@ -703,7 +733,7 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
                    (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO))
                        continue;
 
-               if ((cx.type < ACPI_STATE_C1) || (cx.type > ACPI_STATE_C3))
+               if ((cx.type < ACPI_STATE_C2) || (cx.type > ACPI_STATE_C3))
                        continue;
 
                obj = (union acpi_object *)&(element->package.elements[2]);
@@ -718,15 +748,28 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
 
                cx.power = obj->integer.value;
 
-               (pr->power.count)++;
-               memcpy(&(pr->power.states[pr->power.count]), &cx, sizeof(cx));
+               current_count++;
+               memcpy(&(pr->power.states[current_count]), &cx, sizeof(cx));
+
+               /*
+                * We support total ACPI_PROCESSOR_MAX_POWER - 1
+                * (From 1 through ACPI_PROCESSOR_MAX_POWER - 1)
+                */
+               if (current_count >= (ACPI_PROCESSOR_MAX_POWER - 1)) {
+                       printk(KERN_WARNING
+                              "Limiting number of power states to max (%d)\n",
+                              ACPI_PROCESSOR_MAX_POWER);
+                       printk(KERN_WARNING
+                              "Please increase ACPI_PROCESSOR_MAX_POWER if needed.\n");
+                       break;
+               }
        }
 
        ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d power states\n",
-                         pr->power.count));
+                         current_count));
 
        /* Validate number of power states discovered */
-       if (pr->power.count < 2)
+       if (current_count < 2)
                status = -EFAULT;
 
       end:
@@ -844,12 +887,9 @@ static int acpi_processor_power_verify(struct acpi_processor *pr)
        unsigned int working = 0;
 
 #ifdef ARCH_APICTIMER_STOPS_ON_C3
-       struct cpuinfo_x86 *c = cpu_data + pr->id;
+       int timer_broadcast = 0;
        cpumask_t mask = cpumask_of_cpu(pr->id);
-
-       if (c->x86_vendor == X86_VENDOR_INTEL) {
-               on_each_cpu(switch_ipi_to_APIC_timer, &mask, 1, 1);
-       }
+       on_each_cpu(switch_ipi_to_APIC_timer, &mask, 1, 1);
 #endif
 
        for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
@@ -862,15 +902,20 @@ static int acpi_processor_power_verify(struct acpi_processor *pr)
 
                case ACPI_STATE_C2:
                        acpi_processor_power_verify_c2(cx);
+#ifdef ARCH_APICTIMER_STOPS_ON_C3
+                       /* Some AMD systems fake C3 as C2, but still
+                          have timer troubles */
+                       if (cx->valid && 
+                               boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
+                               timer_broadcast++;
+#endif
                        break;
 
                case ACPI_STATE_C3:
                        acpi_processor_power_verify_c3(pr, cx);
 #ifdef ARCH_APICTIMER_STOPS_ON_C3
-                       if (c->x86_vendor == X86_VENDOR_INTEL) {
-                               on_each_cpu(switch_APIC_timer_to_ipi,
-                                               &mask, 1, 1);
-                       }
+                       if (cx->valid)
+                               timer_broadcast++;
 #endif
                        break;
                }
@@ -879,6 +924,11 @@ static int acpi_processor_power_verify(struct acpi_processor *pr)
                        working++;
        }
 
+#ifdef ARCH_APICTIMER_STOPS_ON_C3
+       if (timer_broadcast)
+               on_each_cpu(switch_APIC_timer_to_ipi, &mask, 1, 1);
+#endif
+
        return (working);
 }
 
@@ -892,12 +942,13 @@ static int acpi_processor_get_power_info(struct acpi_processor *pr)
        /* NOTE: the idle thread may not be running while calling
         * this function */
 
+       /* Adding C1 state */
+       acpi_processor_get_power_info_default_c1(pr);
        result = acpi_processor_get_power_info_cst(pr);
        if (result == -ENODEV)
-               result = acpi_processor_get_power_info_fadt(pr);
+               acpi_processor_get_power_info_fadt(pr);
 
-       if ((result) || (acpi_processor_power_verify(pr) < 2))
-               result = acpi_processor_get_power_info_default_c1(pr);
+       pr->power.count = acpi_processor_power_verify(pr);
 
        /*
         * Set Default Policy
@@ -1039,7 +1090,7 @@ int acpi_processor_power_init(struct acpi_processor *pr,
                              struct acpi_device *device)
 {
        acpi_status status = 0;
-       static int first_run = 0;
+       static int first_run;
        struct proc_dir_entry *entry = NULL;
        unsigned int i;
 
@@ -1066,8 +1117,6 @@ int acpi_processor_power_init(struct acpi_processor *pr,
                }
        }
 
-       acpi_processor_power_init_pdc(&(pr->power), pr->id);
-       acpi_processor_set_pdc(pr, pr->power.pdc);
        acpi_processor_get_power_info(pr);
 
        /*