Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Dominik Brodowski | c5ab81c | 2006-06-24 19:37:00 -0400 | [diff] [blame] | 6 | * Copyright (C) 2004, 2005 Dominik Brodowski <linux@brodo.de> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> |
| 8 | * - Added processor hotplug support |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 9 | * Copyright (C) 2005 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> |
| 10 | * - Added support for C3 on SMP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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/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 Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 40 | #include <linux/sched.h> /* need_resched() */ |
Mark Gross | f011e2e | 2008-02-04 22:30:09 -0800 | [diff] [blame] | 41 | #include <linux/pm_qos_params.h> |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 42 | #include <linux/clockchips.h> |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 43 | #include <linux/cpuidle.h> |
Russell King | ba84be2 | 2009-01-06 14:41:07 -0800 | [diff] [blame] | 44 | #include <linux/irqflags.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Thomas Gleixner | 3434933 | 2007-02-16 01:27:54 -0800 | [diff] [blame] | 46 | /* |
| 47 | * Include the apic definitions for x86 to have the APIC timer related defines |
| 48 | * available also for UP (on SMP it gets magically included via linux/smp.h). |
| 49 | * asm/acpi.h is not an option, as it would require more include magic. Also |
| 50 | * creating an empty asm-ia64/apic.h would just trade pest vs. cholera. |
| 51 | */ |
| 52 | #ifdef CONFIG_X86 |
| 53 | #include <asm/apic.h> |
| 54 | #endif |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include <asm/io.h> |
| 57 | #include <asm/uaccess.h> |
| 58 | |
| 59 | #include <acpi/acpi_bus.h> |
| 60 | #include <acpi/processor.h> |
Zhao Yakui | c1e3b37 | 2008-06-24 17:58:53 +0800 | [diff] [blame] | 61 | #include <asm/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #define ACPI_PROCESSOR_CLASS "processor" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #define _COMPONENT ACPI_PROCESSOR_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 65 | ACPI_MODULE_NAME("processor_idle"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | #define ACPI_PROCESSOR_FILE_POWER "power" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #define US_TO_PM_TIMER_TICKS(t) ((t * (PM_TIMER_FREQUENCY/1000)) / 1000) |
Ingo Molnar | 2aa44d0 | 2007-08-23 15:18:02 +0200 | [diff] [blame] | 68 | #define PM_TIMER_TICK_NS (1000000000ULL/PM_TIMER_FREQUENCY) |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 69 | #ifndef CONFIG_CPU_IDLE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #define C2_OVERHEAD 4 /* 1us (3.579 ticks per us) */ |
| 71 | #define C3_OVERHEAD 4 /* 1us (3.579 ticks per us) */ |
Andreas Mohr | b683505 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 72 | static void (*pm_idle_save) (void) __read_mostly; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 73 | #else |
| 74 | #define C2_OVERHEAD 1 /* 1us */ |
| 75 | #define C3_OVERHEAD 1 /* 1us */ |
| 76 | #endif |
| 77 | #define PM_TIMER_TICKS_TO_US(p) (((p) * 1000)/(PM_TIMER_FREQUENCY/1000)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 79 | static unsigned int max_cstate __read_mostly = ACPI_PROCESSOR_MAX_POWER; |
Venki Pallipadi | 5b3f0e6 | 2008-01-07 17:50:10 -0500 | [diff] [blame] | 80 | #ifdef CONFIG_CPU_IDLE |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 81 | module_param(max_cstate, uint, 0000); |
Venki Pallipadi | 5b3f0e6 | 2008-01-07 17:50:10 -0500 | [diff] [blame] | 82 | #else |
| 83 | module_param(max_cstate, uint, 0644); |
| 84 | #endif |
Andreas Mohr | b683505 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 85 | static unsigned int nocst __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | module_param(nocst, uint, 0000); |
| 87 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 88 | #ifndef CONFIG_CPU_IDLE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* |
| 90 | * bm_history -- bit-mask with a bit per jiffy of bus-master activity |
| 91 | * 1000 HZ: 0xFFFFFFFF: 32 jiffies = 32ms |
| 92 | * 800 HZ: 0xFFFFFFFF: 32 jiffies = 40ms |
| 93 | * 100 HZ: 0x0000000F: 4 jiffies = 40ms |
| 94 | * reduce history for more aggressive entry into C3 |
| 95 | */ |
Andreas Mohr | b683505 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 96 | static unsigned int bm_history __read_mostly = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 97 | (HZ >= 800 ? 0xFFFFFFFF : ((1U << (HZ / 25)) - 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | module_param(bm_history, uint, 0644); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 99 | |
| 100 | static int acpi_processor_set_power_policy(struct acpi_processor *pr); |
| 101 | |
Len Brown | 4963f62 | 2007-12-13 23:50:45 -0500 | [diff] [blame] | 102 | #else /* CONFIG_CPU_IDLE */ |
Len Brown | 25de571 | 2007-12-14 00:24:15 -0500 | [diff] [blame] | 103 | static unsigned int latency_factor __read_mostly = 2; |
Len Brown | 4963f62 | 2007-12-13 23:50:45 -0500 | [diff] [blame] | 104 | module_param(latency_factor, uint, 0644); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 105 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | /* |
| 108 | * IBM ThinkPad R40e crashes mysteriously when going into C2 or C3. |
| 109 | * For now disable this. Probably a bug somewhere else. |
| 110 | * |
| 111 | * To skip this limit, boot/load with a large max_cstate limit. |
| 112 | */ |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 113 | static int set_max_cstate(const struct dmi_system_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
| 115 | if (max_cstate > ACPI_PROCESSOR_MAX_POWER) |
| 116 | return 0; |
| 117 | |
Len Brown | 3d35600 | 2005-08-03 00:22:52 -0400 | [diff] [blame] | 118 | printk(KERN_NOTICE PREFIX "%s detected - limiting to C%ld max_cstate." |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 119 | " Override with \"processor.max_cstate=%d\"\n", id->ident, |
| 120 | (long)id->driver_data, ACPI_PROCESSOR_MAX_POWER + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Len Brown | 3d35600 | 2005-08-03 00:22:52 -0400 | [diff] [blame] | 122 | max_cstate = (long)id->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
Ashok Raj | 7ded568 | 2006-02-03 21:51:23 +0100 | [diff] [blame] | 127 | /* Actually this shouldn't be __cpuinitdata, would be better to fix the |
| 128 | callers to only run once -AK */ |
| 129 | static struct dmi_system_id __cpuinitdata processor_power_dmi_table[] = { |
Thomas Rosner | 876c184 | 2006-01-06 01:31:00 -0500 | [diff] [blame] | 130 | { set_max_cstate, "IBM ThinkPad R40e", { |
| 131 | DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), |
Bartlomiej Swiercz | f831335 | 2006-05-29 07:16:00 -0400 | [diff] [blame] | 132 | DMI_MATCH(DMI_BIOS_VERSION,"1SET70WW")}, (void *)1}, |
| 133 | { set_max_cstate, "IBM ThinkPad R40e", { |
| 134 | DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), |
Thomas Rosner | 876c184 | 2006-01-06 01:31:00 -0500 | [diff] [blame] | 135 | DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW")}, (void *)1}, |
| 136 | { set_max_cstate, "IBM ThinkPad R40e", { |
| 137 | DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), |
| 138 | DMI_MATCH(DMI_BIOS_VERSION,"1SET43WW") }, (void*)1}, |
| 139 | { set_max_cstate, "IBM ThinkPad R40e", { |
| 140 | DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), |
| 141 | DMI_MATCH(DMI_BIOS_VERSION,"1SET45WW") }, (void*)1}, |
| 142 | { set_max_cstate, "IBM ThinkPad R40e", { |
| 143 | DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), |
| 144 | DMI_MATCH(DMI_BIOS_VERSION,"1SET47WW") }, (void*)1}, |
| 145 | { set_max_cstate, "IBM ThinkPad R40e", { |
| 146 | DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), |
| 147 | DMI_MATCH(DMI_BIOS_VERSION,"1SET50WW") }, (void*)1}, |
| 148 | { set_max_cstate, "IBM ThinkPad R40e", { |
| 149 | DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), |
| 150 | DMI_MATCH(DMI_BIOS_VERSION,"1SET52WW") }, (void*)1}, |
| 151 | { set_max_cstate, "IBM ThinkPad R40e", { |
| 152 | DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), |
| 153 | DMI_MATCH(DMI_BIOS_VERSION,"1SET55WW") }, (void*)1}, |
| 154 | { set_max_cstate, "IBM ThinkPad R40e", { |
| 155 | DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), |
| 156 | DMI_MATCH(DMI_BIOS_VERSION,"1SET56WW") }, (void*)1}, |
| 157 | { set_max_cstate, "IBM ThinkPad R40e", { |
| 158 | DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), |
| 159 | DMI_MATCH(DMI_BIOS_VERSION,"1SET59WW") }, (void*)1}, |
| 160 | { set_max_cstate, "IBM ThinkPad R40e", { |
| 161 | DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), |
| 162 | DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW") }, (void*)1}, |
| 163 | { set_max_cstate, "IBM ThinkPad R40e", { |
| 164 | DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), |
| 165 | DMI_MATCH(DMI_BIOS_VERSION,"1SET61WW") }, (void*)1}, |
| 166 | { set_max_cstate, "IBM ThinkPad R40e", { |
| 167 | DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), |
| 168 | DMI_MATCH(DMI_BIOS_VERSION,"1SET62WW") }, (void*)1}, |
| 169 | { set_max_cstate, "IBM ThinkPad R40e", { |
| 170 | DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), |
| 171 | DMI_MATCH(DMI_BIOS_VERSION,"1SET64WW") }, (void*)1}, |
| 172 | { set_max_cstate, "IBM ThinkPad R40e", { |
| 173 | DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), |
| 174 | DMI_MATCH(DMI_BIOS_VERSION,"1SET65WW") }, (void*)1}, |
| 175 | { set_max_cstate, "IBM ThinkPad R40e", { |
| 176 | DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), |
| 177 | DMI_MATCH(DMI_BIOS_VERSION,"1SET68WW") }, (void*)1}, |
| 178 | { set_max_cstate, "Medion 41700", { |
| 179 | DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"), |
| 180 | DMI_MATCH(DMI_BIOS_VERSION,"R01-A1J")}, (void *)1}, |
| 181 | { set_max_cstate, "Clevo 5600D", { |
| 182 | DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"), |
| 183 | DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")}, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 184 | (void *)2}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | {}, |
| 186 | }; |
| 187 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 188 | static inline u32 ticks_elapsed(u32 t1, u32 t2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
| 190 | if (t2 >= t1) |
| 191 | return (t2 - t1); |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 192 | else if (!(acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | return (((0x00FFFFFF - t1) + t2) & 0x00FFFFFF); |
| 194 | else |
| 195 | return ((0xFFFFFFFF - t1) + t2); |
| 196 | } |
| 197 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 198 | static inline u32 ticks_elapsed_in_us(u32 t1, u32 t2) |
| 199 | { |
| 200 | if (t2 >= t1) |
| 201 | return PM_TIMER_TICKS_TO_US(t2 - t1); |
| 202 | else if (!(acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER)) |
| 203 | return PM_TIMER_TICKS_TO_US(((0x00FFFFFF - t1) + t2) & 0x00FFFFFF); |
| 204 | else |
| 205 | return PM_TIMER_TICKS_TO_US((0xFFFFFFFF - t1) + t2); |
| 206 | } |
| 207 | |
venkatesh.pallipadi@intel.com | 2e90665 | 2008-01-31 17:35:03 -0800 | [diff] [blame] | 208 | /* |
| 209 | * Callers should disable interrupts before the call and enable |
| 210 | * interrupts after return. |
| 211 | */ |
Venkatesh Pallipadi | ddc081a | 2007-11-19 21:43:22 -0500 | [diff] [blame] | 212 | static void acpi_safe_halt(void) |
| 213 | { |
| 214 | current_thread_info()->status &= ~TS_POLLING; |
| 215 | /* |
| 216 | * TS_POLLING-cleared state must be visible before we |
| 217 | * test NEED_RESCHED: |
| 218 | */ |
| 219 | smp_mb(); |
Venki Pallipadi | 71e93d1 | 2008-03-13 17:18:19 -0700 | [diff] [blame] | 220 | if (!need_resched()) { |
Venkatesh Pallipadi | ddc081a | 2007-11-19 21:43:22 -0500 | [diff] [blame] | 221 | safe_halt(); |
Venki Pallipadi | 71e93d1 | 2008-03-13 17:18:19 -0700 | [diff] [blame] | 222 | local_irq_disable(); |
| 223 | } |
Venkatesh Pallipadi | ddc081a | 2007-11-19 21:43:22 -0500 | [diff] [blame] | 224 | current_thread_info()->status |= TS_POLLING; |
| 225 | } |
| 226 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 227 | #ifndef CONFIG_CPU_IDLE |
| 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 230 | acpi_processor_power_activate(struct acpi_processor *pr, |
| 231 | struct acpi_processor_cx *new) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 233 | struct acpi_processor_cx *old; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
| 235 | if (!pr || !new) |
| 236 | return; |
| 237 | |
| 238 | old = pr->power.state; |
| 239 | |
| 240 | if (old) |
| 241 | old->promotion.count = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 242 | new->demotion.count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | pr->power.state = new; |
| 245 | |
| 246 | return; |
| 247 | } |
| 248 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 249 | static atomic_t c3_cpu_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 251 | /* Common C-state entry for C2, C3, .. */ |
| 252 | static void acpi_cstate_enter(struct acpi_processor_cx *cstate) |
| 253 | { |
Steven Rostedt | dcf3099 | 2008-07-25 18:00:42 -0400 | [diff] [blame] | 254 | /* Don't trace irqs off for idle */ |
| 255 | stop_critical_timings(); |
venkatesh.pallipadi@intel.com | bc71bec | 2008-01-31 17:35:04 -0800 | [diff] [blame] | 256 | if (cstate->entry_method == ACPI_CSTATE_FFH) { |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 257 | /* Call into architectural FFH based C-state */ |
| 258 | acpi_processor_ffh_cstate_enter(cstate); |
| 259 | } else { |
| 260 | int unused; |
| 261 | /* IO port based C-state */ |
| 262 | inb(cstate->address); |
| 263 | /* Dummy wait op - must do something useless after P_LVL2 read |
| 264 | because chipsets cannot guarantee that STPCLK# signal |
| 265 | gets asserted in time to freeze execution properly. */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 266 | unused = inl(acpi_gbl_FADT.xpm_timer_block.address); |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 267 | } |
Steven Rostedt | dcf3099 | 2008-07-25 18:00:42 -0400 | [diff] [blame] | 268 | start_critical_timings(); |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 269 | } |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 270 | #endif /* !CONFIG_CPU_IDLE */ |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 271 | |
Thomas Gleixner | 169a0ab | 2007-02-16 01:27:55 -0800 | [diff] [blame] | 272 | #ifdef ARCH_APICTIMER_STOPS_ON_C3 |
| 273 | |
| 274 | /* |
| 275 | * Some BIOS implementations switch to C3 in the published C2 state. |
Linus Torvalds | 296d93c | 2007-03-23 08:03:47 -0700 | [diff] [blame] | 276 | * This seems to be a common problem on AMD boxen, but other vendors |
| 277 | * are affected too. We pick the most conservative approach: we assume |
| 278 | * that the local APIC stops in both C2 and C3. |
Thomas Gleixner | 169a0ab | 2007-02-16 01:27:55 -0800 | [diff] [blame] | 279 | */ |
| 280 | static void acpi_timer_check_state(int state, struct acpi_processor *pr, |
| 281 | struct acpi_processor_cx *cx) |
| 282 | { |
| 283 | struct acpi_processor_power *pwr = &pr->power; |
Thomas Gleixner | e585bef | 2007-03-23 16:08:01 +0100 | [diff] [blame] | 284 | u8 type = local_apic_timer_c2_ok ? ACPI_STATE_C3 : ACPI_STATE_C2; |
Thomas Gleixner | 169a0ab | 2007-02-16 01:27:55 -0800 | [diff] [blame] | 285 | |
| 286 | /* |
| 287 | * Check, if one of the previous states already marked the lapic |
| 288 | * unstable |
| 289 | */ |
| 290 | if (pwr->timer_broadcast_on_state < state) |
| 291 | return; |
| 292 | |
Thomas Gleixner | e585bef | 2007-03-23 16:08:01 +0100 | [diff] [blame] | 293 | if (cx->type >= type) |
Linus Torvalds | 296d93c | 2007-03-23 08:03:47 -0700 | [diff] [blame] | 294 | pr->power.timer_broadcast_on_state = state; |
Thomas Gleixner | 169a0ab | 2007-02-16 01:27:55 -0800 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static void acpi_propagate_timer_broadcast(struct acpi_processor *pr) |
| 298 | { |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 299 | unsigned long reason; |
| 300 | |
| 301 | reason = pr->power.timer_broadcast_on_state < INT_MAX ? |
| 302 | CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF; |
| 303 | |
| 304 | clockevents_notify(reason, &pr->id); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /* Power(C) State timer broadcast control */ |
| 308 | static void acpi_state_timer_broadcast(struct acpi_processor *pr, |
| 309 | struct acpi_processor_cx *cx, |
| 310 | int broadcast) |
| 311 | { |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 312 | int state = cx - pr->power.states; |
| 313 | |
| 314 | if (state >= pr->power.timer_broadcast_on_state) { |
| 315 | unsigned long reason; |
| 316 | |
| 317 | reason = broadcast ? CLOCK_EVT_NOTIFY_BROADCAST_ENTER : |
| 318 | CLOCK_EVT_NOTIFY_BROADCAST_EXIT; |
| 319 | clockevents_notify(reason, &pr->id); |
| 320 | } |
Thomas Gleixner | 169a0ab | 2007-02-16 01:27:55 -0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | #else |
| 324 | |
| 325 | static void acpi_timer_check_state(int state, struct acpi_processor *pr, |
| 326 | struct acpi_processor_cx *cstate) { } |
| 327 | static void acpi_propagate_timer_broadcast(struct acpi_processor *pr) { } |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 328 | static void acpi_state_timer_broadcast(struct acpi_processor *pr, |
| 329 | struct acpi_processor_cx *cx, |
| 330 | int broadcast) |
| 331 | { |
| 332 | } |
Thomas Gleixner | 169a0ab | 2007-02-16 01:27:55 -0800 | [diff] [blame] | 333 | |
| 334 | #endif |
| 335 | |
Thomas Gleixner | b04e7bd | 2007-09-22 22:29:05 +0000 | [diff] [blame] | 336 | /* |
| 337 | * Suspend / resume control |
| 338 | */ |
| 339 | static int acpi_idle_suspend; |
| 340 | |
| 341 | int acpi_processor_suspend(struct acpi_device * device, pm_message_t state) |
| 342 | { |
| 343 | acpi_idle_suspend = 1; |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | int acpi_processor_resume(struct acpi_device * device) |
| 348 | { |
| 349 | acpi_idle_suspend = 0; |
| 350 | return 0; |
| 351 | } |
| 352 | |
Pavel Machek | 6133116 | 2008-02-19 11:00:29 +0100 | [diff] [blame] | 353 | #if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86) |
Andi Kleen | ddb25f9 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 354 | static int tsc_halts_in_c(int state) |
| 355 | { |
| 356 | switch (boot_cpu_data.x86_vendor) { |
| 357 | case X86_VENDOR_AMD: |
Venki Pallipadi | 40fb171 | 2008-11-17 16:11:37 -0800 | [diff] [blame] | 358 | case X86_VENDOR_INTEL: |
Andi Kleen | ddb25f9 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 359 | /* |
| 360 | * AMD Fam10h TSC will tick in all |
| 361 | * C/P/S0/S1 states when this bit is set. |
| 362 | */ |
Venki Pallipadi | 40fb171 | 2008-11-17 16:11:37 -0800 | [diff] [blame] | 363 | if (boot_cpu_has(X86_FEATURE_NONSTOP_TSC)) |
Andi Kleen | ddb25f9 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 364 | return 0; |
Venki Pallipadi | 40fb171 | 2008-11-17 16:11:37 -0800 | [diff] [blame] | 365 | |
Andi Kleen | ddb25f9 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 366 | /*FALL THROUGH*/ |
Andi Kleen | ddb25f9 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 367 | default: |
| 368 | return state > ACPI_STATE_C1; |
| 369 | } |
| 370 | } |
| 371 | #endif |
| 372 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 373 | #ifndef CONFIG_CPU_IDLE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 374 | static void acpi_processor_idle(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 376 | struct acpi_processor *pr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | struct acpi_processor_cx *cx = NULL; |
| 378 | struct acpi_processor_cx *next_state = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 379 | int sleep_ticks = 0; |
| 380 | u32 t1, t2 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | /* |
| 383 | * Interrupts must be disabled during bus mastering calculations and |
| 384 | * for C2/C3 transitions. |
| 385 | */ |
| 386 | local_irq_disable(); |
| 387 | |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 388 | pr = __get_cpu_var(processors); |
Venkatesh Pallipadi | d5a3d32 | 2007-06-15 19:36:00 -0400 | [diff] [blame] | 389 | if (!pr) { |
| 390 | local_irq_enable(); |
| 391 | return; |
| 392 | } |
| 393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | /* |
| 395 | * Check whether we truly need to go idle, or should |
| 396 | * reschedule: |
| 397 | */ |
| 398 | if (unlikely(need_resched())) { |
| 399 | local_irq_enable(); |
| 400 | return; |
| 401 | } |
| 402 | |
| 403 | cx = pr->power.state; |
Thomas Gleixner | b04e7bd | 2007-09-22 22:29:05 +0000 | [diff] [blame] | 404 | if (!cx || acpi_idle_suspend) { |
Peter Zijlstra | 7f424a8 | 2008-04-25 17:39:01 +0200 | [diff] [blame] | 405 | if (pm_idle_save) { |
| 406 | pm_idle_save(); /* enables IRQs */ |
| 407 | } else { |
Nick Piggin | 64c7c8f | 2005-11-08 21:39:04 -0800 | [diff] [blame] | 408 | acpi_safe_halt(); |
Venki Pallipadi | 71e93d1 | 2008-03-13 17:18:19 -0700 | [diff] [blame] | 409 | local_irq_enable(); |
Peter Zijlstra | 7f424a8 | 2008-04-25 17:39:01 +0200 | [diff] [blame] | 410 | } |
Venki Pallipadi | 71e93d1 | 2008-03-13 17:18:19 -0700 | [diff] [blame] | 411 | |
Nick Piggin | 64c7c8f | 2005-11-08 21:39:04 -0800 | [diff] [blame] | 412 | return; |
| 413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
| 415 | /* |
| 416 | * Check BM Activity |
| 417 | * ----------------- |
| 418 | * Check for bus mastering activity (if required), record, and check |
| 419 | * for demotion. |
| 420 | */ |
| 421 | if (pr->flags.bm_check) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 422 | u32 bm_status = 0; |
| 423 | unsigned long diff = jiffies - pr->power.bm_check_timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
Dominik Brodowski | c5ab81c | 2006-06-24 19:37:00 -0400 | [diff] [blame] | 425 | if (diff > 31) |
| 426 | diff = 31; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Dominik Brodowski | c5ab81c | 2006-06-24 19:37:00 -0400 | [diff] [blame] | 428 | pr->power.bm_activity <<= diff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
Len Brown | a2b7b01 | 2009-01-28 12:47:15 -0500 | [diff] [blame] | 430 | acpi_get_register_unlocked(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | if (bm_status) { |
Dominik Brodowski | c5ab81c | 2006-06-24 19:37:00 -0400 | [diff] [blame] | 432 | pr->power.bm_activity |= 0x1; |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 433 | acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | /* |
| 436 | * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect |
| 437 | * the true state of bus mastering activity; forcing us to |
| 438 | * manually check the BMIDEA bit of each IDE channel. |
| 439 | */ |
| 440 | else if (errata.piix4.bmisx) { |
| 441 | if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 442 | || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01)) |
Dominik Brodowski | c5ab81c | 2006-06-24 19:37:00 -0400 | [diff] [blame] | 443 | pr->power.bm_activity |= 0x1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | pr->power.bm_check_timestamp = jiffies; |
| 447 | |
| 448 | /* |
Dominik Brodowski | c4a001b | 2006-06-24 19:37:00 -0400 | [diff] [blame] | 449 | * If bus mastering is or was active this jiffy, demote |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | * to avoid a faulty transition. Note that the processor |
| 451 | * won't enter a low-power state during this call (to this |
Dominik Brodowski | c4a001b | 2006-06-24 19:37:00 -0400 | [diff] [blame] | 452 | * function) but should upon the next. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | * |
| 454 | * TBD: A better policy might be to fallback to the demotion |
| 455 | * state (use it for this quantum only) istead of |
| 456 | * demoting -- and rely on duration as our sole demotion |
| 457 | * qualification. This may, however, introduce DMA |
| 458 | * issues (e.g. floppy DMA transfer overrun/underrun). |
| 459 | */ |
Dominik Brodowski | c4a001b | 2006-06-24 19:37:00 -0400 | [diff] [blame] | 460 | if ((pr->power.bm_activity & 0x1) && |
| 461 | cx->demotion.threshold.bm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | local_irq_enable(); |
| 463 | next_state = cx->demotion.state; |
| 464 | goto end; |
| 465 | } |
| 466 | } |
| 467 | |
Venkatesh Pallipadi | 4c03355 | 2005-09-15 12:20:00 -0400 | [diff] [blame] | 468 | #ifdef CONFIG_HOTPLUG_CPU |
| 469 | /* |
| 470 | * Check for P_LVL2_UP flag before entering C2 and above on |
| 471 | * an SMP system. We do it here instead of doing it at _CST/P_LVL |
| 472 | * detection phase, to work cleanly with logical CPU hotplug. |
| 473 | */ |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 474 | if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) && |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 475 | !pr->flags.has_cst && !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED)) |
David Shaohua Li | 1e48396 | 2005-12-01 17:00:00 -0500 | [diff] [blame] | 476 | cx = &pr->power.states[ACPI_STATE_C1]; |
Venkatesh Pallipadi | 4c03355 | 2005-09-15 12:20:00 -0400 | [diff] [blame] | 477 | #endif |
David Shaohua Li | 1e48396 | 2005-12-01 17:00:00 -0500 | [diff] [blame] | 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | /* |
| 480 | * Sleep: |
| 481 | * ------ |
| 482 | * Invoke the current Cx state to put the processor to sleep. |
| 483 | */ |
Nick Piggin | 2a298a3 | 2005-12-02 12:44:19 +1100 | [diff] [blame] | 484 | if (cx->type == ACPI_STATE_C2 || cx->type == ACPI_STATE_C3) { |
Andi Kleen | 495ab9c | 2006-06-26 13:59:11 +0200 | [diff] [blame] | 485 | current_thread_info()->status &= ~TS_POLLING; |
Ingo Molnar | 0888f06 | 2006-12-22 01:11:56 -0800 | [diff] [blame] | 486 | /* |
| 487 | * TS_POLLING-cleared state must be visible before we |
| 488 | * test NEED_RESCHED: |
| 489 | */ |
| 490 | smp_mb(); |
Nick Piggin | 2a298a3 | 2005-12-02 12:44:19 +1100 | [diff] [blame] | 491 | if (need_resched()) { |
Andi Kleen | 495ab9c | 2006-06-26 13:59:11 +0200 | [diff] [blame] | 492 | current_thread_info()->status |= TS_POLLING; |
Linus Torvalds | af2eb17 | 2005-12-02 23:09:06 -0800 | [diff] [blame] | 493 | local_irq_enable(); |
Nick Piggin | 2a298a3 | 2005-12-02 12:44:19 +1100 | [diff] [blame] | 494 | return; |
| 495 | } |
| 496 | } |
| 497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | switch (cx->type) { |
| 499 | |
| 500 | case ACPI_STATE_C1: |
| 501 | /* |
| 502 | * Invoke C1. |
| 503 | * Use the appropriate idle routine, the one that would |
| 504 | * be used without acpi C-states. |
| 505 | */ |
Peter Zijlstra | 7f424a8 | 2008-04-25 17:39:01 +0200 | [diff] [blame] | 506 | if (pm_idle_save) { |
| 507 | pm_idle_save(); /* enables IRQs */ |
| 508 | } else { |
Nick Piggin | 64c7c8f | 2005-11-08 21:39:04 -0800 | [diff] [blame] | 509 | acpi_safe_halt(); |
Peter Zijlstra | 7f424a8 | 2008-04-25 17:39:01 +0200 | [diff] [blame] | 510 | local_irq_enable(); |
| 511 | } |
Nick Piggin | 64c7c8f | 2005-11-08 21:39:04 -0800 | [diff] [blame] | 512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | /* |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 514 | * TBD: Can't get time duration while in C1, as resumes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | * go to an ISR rather than here. Need to instrument |
| 516 | * base interrupt handler. |
Ingo Molnar | 2aa44d0 | 2007-08-23 15:18:02 +0200 | [diff] [blame] | 517 | * |
| 518 | * Note: the TSC better not stop in C1, sched_clock() will |
| 519 | * skew otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | */ |
| 521 | sleep_ticks = 0xFFFFFFFF; |
Venki Pallipadi | 71e93d1 | 2008-03-13 17:18:19 -0700 | [diff] [blame] | 522 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | break; |
| 524 | |
| 525 | case ACPI_STATE_C2: |
| 526 | /* Get start time (ticks) */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 527 | t1 = inl(acpi_gbl_FADT.xpm_timer_block.address); |
Ingo Molnar | 2aa44d0 | 2007-08-23 15:18:02 +0200 | [diff] [blame] | 528 | /* Tell the scheduler that we are going deep-idle: */ |
| 529 | sched_clock_idle_sleep_event(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | /* Invoke C2 */ |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 531 | acpi_state_timer_broadcast(pr, cx, 1); |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 532 | acpi_cstate_enter(cx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | /* Get end time (ticks) */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 534 | t2 = inl(acpi_gbl_FADT.xpm_timer_block.address); |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 535 | |
Pavel Machek | 6133116 | 2008-02-19 11:00:29 +0100 | [diff] [blame] | 536 | #if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86) |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 537 | /* TSC halts in C2, so notify users */ |
Andi Kleen | ddb25f9 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 538 | if (tsc_halts_in_c(ACPI_STATE_C2)) |
| 539 | mark_tsc_unstable("possible TSC halt in C2"); |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 540 | #endif |
Ingo Molnar | 2aa44d0 | 2007-08-23 15:18:02 +0200 | [diff] [blame] | 541 | /* Compute time (ticks) that we were actually asleep */ |
| 542 | sleep_ticks = ticks_elapsed(t1, t2); |
| 543 | |
| 544 | /* Tell the scheduler how much we idled: */ |
| 545 | sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS); |
| 546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | /* Re-enable interrupts */ |
| 548 | local_irq_enable(); |
Ingo Molnar | 2aa44d0 | 2007-08-23 15:18:02 +0200 | [diff] [blame] | 549 | /* Do not account our idle-switching overhead: */ |
| 550 | sleep_ticks -= cx->latency_ticks + C2_OVERHEAD; |
| 551 | |
Andi Kleen | 495ab9c | 2006-06-26 13:59:11 +0200 | [diff] [blame] | 552 | current_thread_info()->status |= TS_POLLING; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 553 | acpi_state_timer_broadcast(pr, cx, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | break; |
| 555 | |
| 556 | case ACPI_STATE_C3: |
Venki Pallipadi | bde6f5f | 2008-01-30 13:32:01 +0100 | [diff] [blame] | 557 | acpi_unlazy_tlb(smp_processor_id()); |
Venkatesh Pallipadi | 18eab85 | 2007-06-15 19:37:00 -0400 | [diff] [blame] | 558 | /* |
Thomas Gleixner | e17bcb4 | 2007-12-07 19:16:17 +0100 | [diff] [blame] | 559 | * Must be done before busmaster disable as we might |
| 560 | * need to access HPET ! |
| 561 | */ |
| 562 | acpi_state_timer_broadcast(pr, cx, 1); |
| 563 | /* |
Venkatesh Pallipadi | 18eab85 | 2007-06-15 19:37:00 -0400 | [diff] [blame] | 564 | * disable bus master |
| 565 | * bm_check implies we need ARB_DIS |
| 566 | * !bm_check implies we need cache flush |
| 567 | * bm_control implies whether we can do ARB_DIS |
| 568 | * |
| 569 | * That leaves a case where bm_check is set and bm_control is |
| 570 | * not set. In that case we cannot do much, we enter C3 |
| 571 | * without doing anything. |
| 572 | */ |
| 573 | if (pr->flags.bm_check && pr->flags.bm_control) { |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 574 | if (atomic_inc_return(&c3_cpu_count) == |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 575 | num_online_cpus()) { |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 576 | /* |
| 577 | * All CPUs are trying to go to C3 |
| 578 | * Disable bus master arbitration |
| 579 | */ |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 580 | acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1); |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 581 | } |
Venkatesh Pallipadi | 18eab85 | 2007-06-15 19:37:00 -0400 | [diff] [blame] | 582 | } else if (!pr->flags.bm_check) { |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 583 | /* SMP with no shared cache... Invalidate cache */ |
| 584 | ACPI_FLUSH_CPU_CACHE(); |
| 585 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | /* Get start time (ticks) */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 588 | t1 = inl(acpi_gbl_FADT.xpm_timer_block.address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | /* Invoke C3 */ |
Ingo Molnar | 2aa44d0 | 2007-08-23 15:18:02 +0200 | [diff] [blame] | 590 | /* Tell the scheduler that we are going deep-idle: */ |
| 591 | sched_clock_idle_sleep_event(); |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 592 | acpi_cstate_enter(cx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | /* Get end time (ticks) */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 594 | t2 = inl(acpi_gbl_FADT.xpm_timer_block.address); |
Venkatesh Pallipadi | 18eab85 | 2007-06-15 19:37:00 -0400 | [diff] [blame] | 595 | if (pr->flags.bm_check && pr->flags.bm_control) { |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 596 | /* Enable bus master arbitration */ |
| 597 | atomic_dec(&c3_cpu_count); |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 598 | acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0); |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 599 | } |
| 600 | |
Pavel Machek | 6133116 | 2008-02-19 11:00:29 +0100 | [diff] [blame] | 601 | #if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86) |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 602 | /* TSC halts in C3, so notify users */ |
Andi Kleen | ddb25f9 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 603 | if (tsc_halts_in_c(ACPI_STATE_C3)) |
| 604 | mark_tsc_unstable("TSC halts in C3"); |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 605 | #endif |
Ingo Molnar | 2aa44d0 | 2007-08-23 15:18:02 +0200 | [diff] [blame] | 606 | /* Compute time (ticks) that we were actually asleep */ |
| 607 | sleep_ticks = ticks_elapsed(t1, t2); |
| 608 | /* Tell the scheduler how much we idled: */ |
| 609 | sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS); |
| 610 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | /* Re-enable interrupts */ |
| 612 | local_irq_enable(); |
Ingo Molnar | 2aa44d0 | 2007-08-23 15:18:02 +0200 | [diff] [blame] | 613 | /* Do not account our idle-switching overhead: */ |
| 614 | sleep_ticks -= cx->latency_ticks + C3_OVERHEAD; |
| 615 | |
Andi Kleen | 495ab9c | 2006-06-26 13:59:11 +0200 | [diff] [blame] | 616 | current_thread_info()->status |= TS_POLLING; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 617 | acpi_state_timer_broadcast(pr, cx, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | break; |
| 619 | |
| 620 | default: |
| 621 | local_irq_enable(); |
| 622 | return; |
| 623 | } |
Dominik Brodowski | a3c6598 | 2006-06-24 19:37:00 -0400 | [diff] [blame] | 624 | cx->usage++; |
| 625 | if ((cx->type != ACPI_STATE_C1) && (sleep_ticks > 0)) |
| 626 | cx->time += sleep_ticks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
| 628 | next_state = pr->power.state; |
| 629 | |
David Shaohua Li | 1e48396 | 2005-12-01 17:00:00 -0500 | [diff] [blame] | 630 | #ifdef CONFIG_HOTPLUG_CPU |
| 631 | /* Don't do promotion/demotion */ |
| 632 | if ((cx->type == ACPI_STATE_C1) && (num_online_cpus() > 1) && |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 633 | !pr->flags.has_cst && !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED)) { |
David Shaohua Li | 1e48396 | 2005-12-01 17:00:00 -0500 | [diff] [blame] | 634 | next_state = cx; |
| 635 | goto end; |
| 636 | } |
| 637 | #endif |
| 638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | /* |
| 640 | * Promotion? |
| 641 | * ---------- |
| 642 | * Track the number of longs (time asleep is greater than threshold) |
| 643 | * and promote when the count threshold is reached. Note that bus |
| 644 | * mastering activity may prevent promotions. |
| 645 | * Do not promote above max_cstate. |
| 646 | */ |
| 647 | if (cx->promotion.state && |
| 648 | ((cx->promotion.state - pr->power.states) <= max_cstate)) { |
Arjan van de Ven | 5c87579 | 2006-09-30 23:27:17 -0700 | [diff] [blame] | 649 | if (sleep_ticks > cx->promotion.threshold.ticks && |
Mark Gross | f011e2e | 2008-02-04 22:30:09 -0800 | [diff] [blame] | 650 | cx->promotion.state->latency <= |
| 651 | pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | cx->promotion.count++; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 653 | cx->demotion.count = 0; |
| 654 | if (cx->promotion.count >= |
| 655 | cx->promotion.threshold.count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | if (pr->flags.bm_check) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 657 | if (! |
| 658 | (pr->power.bm_activity & cx-> |
| 659 | promotion.threshold.bm)) { |
| 660 | next_state = |
| 661 | cx->promotion.state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | goto end; |
| 663 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 664 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | next_state = cx->promotion.state; |
| 666 | goto end; |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | /* |
| 673 | * Demotion? |
| 674 | * --------- |
| 675 | * Track the number of shorts (time asleep is less than time threshold) |
| 676 | * and demote when the usage threshold is reached. |
| 677 | */ |
| 678 | if (cx->demotion.state) { |
| 679 | if (sleep_ticks < cx->demotion.threshold.ticks) { |
| 680 | cx->demotion.count++; |
| 681 | cx->promotion.count = 0; |
| 682 | if (cx->demotion.count >= cx->demotion.threshold.count) { |
| 683 | next_state = cx->demotion.state; |
| 684 | goto end; |
| 685 | } |
| 686 | } |
| 687 | } |
| 688 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 689 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | /* |
| 691 | * Demote if current state exceeds max_cstate |
Arjan van de Ven | 5c87579 | 2006-09-30 23:27:17 -0700 | [diff] [blame] | 692 | * or if the latency of the current state is unacceptable |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | */ |
Arjan van de Ven | 5c87579 | 2006-09-30 23:27:17 -0700 | [diff] [blame] | 694 | if ((pr->power.state - pr->power.states) > max_cstate || |
Mark Gross | f011e2e | 2008-02-04 22:30:09 -0800 | [diff] [blame] | 695 | pr->power.state->latency > |
| 696 | pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | if (cx->demotion.state) |
| 698 | next_state = cx->demotion.state; |
| 699 | } |
| 700 | |
| 701 | /* |
| 702 | * New Cx State? |
| 703 | * ------------- |
| 704 | * If we're going to start using a new Cx state we must clean up |
| 705 | * from the previous and prepare to use the new. |
| 706 | */ |
| 707 | if (next_state != pr->power.state) |
| 708 | acpi_processor_power_activate(pr, next_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | } |
| 710 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 711 | static int acpi_processor_set_power_policy(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | { |
| 713 | unsigned int i; |
| 714 | unsigned int state_is_set = 0; |
| 715 | struct acpi_processor_cx *lower = NULL; |
| 716 | struct acpi_processor_cx *higher = NULL; |
| 717 | struct acpi_processor_cx *cx; |
| 718 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
| 720 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 721 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
| 723 | /* |
| 724 | * This function sets the default Cx state policy (OS idle handler). |
| 725 | * Our scheme is to promote quickly to C2 but more conservatively |
| 726 | * to C3. We're favoring C2 for its characteristics of low latency |
| 727 | * (quick response), good power savings, and ability to allow bus |
| 728 | * mastering activity. Note that the Cx state policy is completely |
| 729 | * customizable and can be altered dynamically. |
| 730 | */ |
| 731 | |
| 732 | /* startup state */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 733 | for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | cx = &pr->power.states[i]; |
| 735 | if (!cx->valid) |
| 736 | continue; |
| 737 | |
| 738 | if (!state_is_set) |
| 739 | pr->power.state = cx; |
| 740 | state_is_set++; |
| 741 | break; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 742 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | |
| 744 | if (!state_is_set) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 745 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | |
| 747 | /* demotion */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 748 | for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | cx = &pr->power.states[i]; |
| 750 | if (!cx->valid) |
| 751 | continue; |
| 752 | |
| 753 | if (lower) { |
| 754 | cx->demotion.state = lower; |
| 755 | cx->demotion.threshold.ticks = cx->latency_ticks; |
| 756 | cx->demotion.threshold.count = 1; |
| 757 | if (cx->type == ACPI_STATE_C3) |
| 758 | cx->demotion.threshold.bm = bm_history; |
| 759 | } |
| 760 | |
| 761 | lower = cx; |
| 762 | } |
| 763 | |
| 764 | /* promotion */ |
| 765 | for (i = (ACPI_PROCESSOR_MAX_POWER - 1); i > 0; i--) { |
| 766 | cx = &pr->power.states[i]; |
| 767 | if (!cx->valid) |
| 768 | continue; |
| 769 | |
| 770 | if (higher) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 771 | cx->promotion.state = higher; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | cx->promotion.threshold.ticks = cx->latency_ticks; |
| 773 | if (cx->type >= ACPI_STATE_C2) |
| 774 | cx->promotion.threshold.count = 4; |
| 775 | else |
| 776 | cx->promotion.threshold.count = 10; |
| 777 | if (higher->type == ACPI_STATE_C3) |
| 778 | cx->promotion.threshold.bm = bm_history; |
| 779 | } |
| 780 | |
| 781 | higher = cx; |
| 782 | } |
| 783 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 784 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | } |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 786 | #endif /* !CONFIG_CPU_IDLE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 788 | static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
| 791 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 792 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
| 794 | if (!pr->pblk) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 795 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | /* if info is obtained from pblk/fadt, type equals state */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | pr->power.states[ACPI_STATE_C2].type = ACPI_STATE_C2; |
| 799 | pr->power.states[ACPI_STATE_C3].type = ACPI_STATE_C3; |
| 800 | |
Venkatesh Pallipadi | 4c03355 | 2005-09-15 12:20:00 -0400 | [diff] [blame] | 801 | #ifndef CONFIG_HOTPLUG_CPU |
| 802 | /* |
| 803 | * Check for P_LVL2_UP flag before entering C2 and above on |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 804 | * an SMP system. |
Venkatesh Pallipadi | 4c03355 | 2005-09-15 12:20:00 -0400 | [diff] [blame] | 805 | */ |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 806 | if ((num_online_cpus() > 1) && |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 807 | !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 808 | return -ENODEV; |
Venkatesh Pallipadi | 4c03355 | 2005-09-15 12:20:00 -0400 | [diff] [blame] | 809 | #endif |
| 810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | /* determine C2 and C3 address from pblk */ |
| 812 | pr->power.states[ACPI_STATE_C2].address = pr->pblk + 4; |
| 813 | pr->power.states[ACPI_STATE_C3].address = pr->pblk + 5; |
| 814 | |
| 815 | /* determine latencies from FADT */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 816 | pr->power.states[ACPI_STATE_C2].latency = acpi_gbl_FADT.C2latency; |
| 817 | pr->power.states[ACPI_STATE_C3].latency = acpi_gbl_FADT.C3latency; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | |
| 819 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 820 | "lvl2[0x%08x] lvl3[0x%08x]\n", |
| 821 | pr->power.states[ACPI_STATE_C2].address, |
| 822 | pr->power.states[ACPI_STATE_C3].address)); |
| 823 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 824 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | } |
| 826 | |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 827 | static int acpi_processor_get_power_info_default(struct acpi_processor *pr) |
Venkatesh Pallipadi | acf05f4 | 2005-03-31 23:23:15 -0500 | [diff] [blame] | 828 | { |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 829 | if (!pr->power.states[ACPI_STATE_C1].valid) { |
| 830 | /* set the first C-State to C1 */ |
| 831 | /* all processors need to support C1 */ |
| 832 | pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1; |
| 833 | pr->power.states[ACPI_STATE_C1].valid = 1; |
Venkatesh Pallipadi | 0fda6b4 | 2008-04-09 21:31:46 -0400 | [diff] [blame] | 834 | pr->power.states[ACPI_STATE_C1].entry_method = ACPI_CSTATE_HALT; |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 835 | } |
| 836 | /* the C0 state only exists as a filler in our array */ |
Venkatesh Pallipadi | acf05f4 | 2005-03-31 23:23:15 -0500 | [diff] [blame] | 837 | pr->power.states[ACPI_STATE_C0].valid = 1; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 838 | return 0; |
Venkatesh Pallipadi | acf05f4 | 2005-03-31 23:23:15 -0500 | [diff] [blame] | 839 | } |
| 840 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 841 | static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 843 | acpi_status status = 0; |
| 844 | acpi_integer count; |
Janosch Machowinski | cf82478 | 2005-08-20 08:02:00 -0400 | [diff] [blame] | 845 | int current_count; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 846 | int i; |
| 847 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 848 | union acpi_object *cst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | if (nocst) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 852 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 854 | current_count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | |
| 856 | status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer); |
| 857 | if (ACPI_FAILURE(status)) { |
| 858 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No _CST, giving up\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 859 | return -ENODEV; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 860 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 862 | cst = buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
| 864 | /* There must be at least 2 elements */ |
| 865 | if (!cst || (cst->type != ACPI_TYPE_PACKAGE) || cst->package.count < 2) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 866 | printk(KERN_ERR PREFIX "not enough elements in _CST\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | status = -EFAULT; |
| 868 | goto end; |
| 869 | } |
| 870 | |
| 871 | count = cst->package.elements[0].integer.value; |
| 872 | |
| 873 | /* Validate number of power states. */ |
| 874 | if (count < 1 || count != cst->package.count - 1) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 875 | printk(KERN_ERR PREFIX "count given by _CST is not valid\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | status = -EFAULT; |
| 877 | goto end; |
| 878 | } |
| 879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | /* Tell driver that at least _CST is supported. */ |
| 881 | pr->flags.has_cst = 1; |
| 882 | |
| 883 | for (i = 1; i <= count; i++) { |
| 884 | union acpi_object *element; |
| 885 | union acpi_object *obj; |
| 886 | struct acpi_power_register *reg; |
| 887 | struct acpi_processor_cx cx; |
| 888 | |
| 889 | memset(&cx, 0, sizeof(cx)); |
| 890 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 891 | element = &(cst->package.elements[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | if (element->type != ACPI_TYPE_PACKAGE) |
| 893 | continue; |
| 894 | |
| 895 | if (element->package.count != 4) |
| 896 | continue; |
| 897 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 898 | obj = &(element->package.elements[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
| 900 | if (obj->type != ACPI_TYPE_BUFFER) |
| 901 | continue; |
| 902 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 903 | reg = (struct acpi_power_register *)obj->buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
| 905 | if (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 906 | (reg->space_id != ACPI_ADR_SPACE_FIXED_HARDWARE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | continue; |
| 908 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | /* There should be an easy way to extract an integer... */ |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 910 | obj = &(element->package.elements[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | if (obj->type != ACPI_TYPE_INTEGER) |
| 912 | continue; |
| 913 | |
| 914 | cx.type = obj->integer.value; |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 915 | /* |
| 916 | * Some buggy BIOSes won't list C1 in _CST - |
| 917 | * Let acpi_processor_get_power_info_default() handle them later |
| 918 | */ |
| 919 | if (i == 1 && cx.type != ACPI_STATE_C1) |
| 920 | current_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 922 | cx.address = reg->address; |
| 923 | cx.index = current_count + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
venkatesh.pallipadi@intel.com | bc71bec | 2008-01-31 17:35:04 -0800 | [diff] [blame] | 925 | cx.entry_method = ACPI_CSTATE_SYSTEMIO; |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 926 | if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) { |
| 927 | if (acpi_processor_ffh_cstate_probe |
| 928 | (pr->id, &cx, reg) == 0) { |
venkatesh.pallipadi@intel.com | bc71bec | 2008-01-31 17:35:04 -0800 | [diff] [blame] | 929 | cx.entry_method = ACPI_CSTATE_FFH; |
| 930 | } else if (cx.type == ACPI_STATE_C1) { |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 931 | /* |
| 932 | * C1 is a special case where FIXED_HARDWARE |
| 933 | * can be handled in non-MWAIT way as well. |
| 934 | * In that case, save this _CST entry info. |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 935 | * Otherwise, ignore this info and continue. |
| 936 | */ |
venkatesh.pallipadi@intel.com | bc71bec | 2008-01-31 17:35:04 -0800 | [diff] [blame] | 937 | cx.entry_method = ACPI_CSTATE_HALT; |
Venkatesh Pallipadi | 4fcb2fc | 2008-02-11 17:46:31 -0800 | [diff] [blame] | 938 | snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT"); |
venkatesh.pallipadi@intel.com | bc71bec | 2008-01-31 17:35:04 -0800 | [diff] [blame] | 939 | } else { |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 940 | continue; |
| 941 | } |
Zhao Yakui | da5e09a | 2008-06-24 18:01:09 +0800 | [diff] [blame] | 942 | if (cx.type == ACPI_STATE_C1 && |
| 943 | (idle_halt || idle_nomwait)) { |
Zhao Yakui | c1e3b37 | 2008-06-24 17:58:53 +0800 | [diff] [blame] | 944 | /* |
| 945 | * In most cases the C1 space_id obtained from |
| 946 | * _CST object is FIXED_HARDWARE access mode. |
| 947 | * But when the option of idle=halt is added, |
| 948 | * the entry_method type should be changed from |
| 949 | * CSTATE_FFH to CSTATE_HALT. |
Zhao Yakui | da5e09a | 2008-06-24 18:01:09 +0800 | [diff] [blame] | 950 | * When the option of idle=nomwait is added, |
| 951 | * the C1 entry_method type should be |
| 952 | * CSTATE_HALT. |
Zhao Yakui | c1e3b37 | 2008-06-24 17:58:53 +0800 | [diff] [blame] | 953 | */ |
| 954 | cx.entry_method = ACPI_CSTATE_HALT; |
| 955 | snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT"); |
| 956 | } |
Venkatesh Pallipadi | 4fcb2fc | 2008-02-11 17:46:31 -0800 | [diff] [blame] | 957 | } else { |
| 958 | snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI IOPORT 0x%x", |
| 959 | cx.address); |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 960 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
Venkatesh Pallipadi | 0fda6b4 | 2008-04-09 21:31:46 -0400 | [diff] [blame] | 962 | if (cx.type == ACPI_STATE_C1) { |
| 963 | cx.valid = 1; |
| 964 | } |
Venkatesh Pallipadi | 4fcb2fc | 2008-02-11 17:46:31 -0800 | [diff] [blame] | 965 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 966 | obj = &(element->package.elements[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | if (obj->type != ACPI_TYPE_INTEGER) |
| 968 | continue; |
| 969 | |
| 970 | cx.latency = obj->integer.value; |
| 971 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 972 | obj = &(element->package.elements[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | if (obj->type != ACPI_TYPE_INTEGER) |
| 974 | continue; |
| 975 | |
| 976 | cx.power = obj->integer.value; |
| 977 | |
Janosch Machowinski | cf82478 | 2005-08-20 08:02:00 -0400 | [diff] [blame] | 978 | current_count++; |
| 979 | memcpy(&(pr->power.states[current_count]), &cx, sizeof(cx)); |
| 980 | |
| 981 | /* |
| 982 | * We support total ACPI_PROCESSOR_MAX_POWER - 1 |
| 983 | * (From 1 through ACPI_PROCESSOR_MAX_POWER - 1) |
| 984 | */ |
| 985 | if (current_count >= (ACPI_PROCESSOR_MAX_POWER - 1)) { |
| 986 | printk(KERN_WARNING |
| 987 | "Limiting number of power states to max (%d)\n", |
| 988 | ACPI_PROCESSOR_MAX_POWER); |
| 989 | printk(KERN_WARNING |
| 990 | "Please increase ACPI_PROCESSOR_MAX_POWER if needed.\n"); |
| 991 | break; |
| 992 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | } |
| 994 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 995 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d power states\n", |
Janosch Machowinski | cf82478 | 2005-08-20 08:02:00 -0400 | [diff] [blame] | 996 | current_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | |
| 998 | /* Validate number of power states discovered */ |
Janosch Machowinski | cf82478 | 2005-08-20 08:02:00 -0400 | [diff] [blame] | 999 | if (current_count < 2) |
Venkatesh Pallipadi | 6d93c64 | 2005-09-15 12:19:00 -0400 | [diff] [blame] | 1000 | status = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1002 | end: |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 1003 | kfree(buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1005 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | static void acpi_processor_power_verify_c2(struct acpi_processor_cx *cx) |
| 1009 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | |
| 1011 | if (!cx->address) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1012 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | |
| 1014 | /* |
| 1015 | * C2 latency must be less than or equal to 100 |
| 1016 | * microseconds. |
| 1017 | */ |
| 1018 | else if (cx->latency > ACPI_PROCESSOR_MAX_C2_LATENCY) { |
| 1019 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1020 | "latency too large [%d]\n", cx->latency)); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1021 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | /* |
| 1025 | * Otherwise we've met all of our C2 requirements. |
| 1026 | * Normalize the C2 latency to expidite policy |
| 1027 | */ |
| 1028 | cx->valid = 1; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1029 | |
| 1030 | #ifndef CONFIG_CPU_IDLE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1032 | #else |
| 1033 | cx->latency_ticks = cx->latency; |
| 1034 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1036 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1039 | static void acpi_processor_power_verify_c3(struct acpi_processor *pr, |
| 1040 | struct acpi_processor_cx *cx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | { |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 1042 | static int bm_check_flag; |
| 1043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | |
| 1045 | if (!cx->address) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1046 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | |
| 1048 | /* |
| 1049 | * C3 latency must be less than or equal to 1000 |
| 1050 | * microseconds. |
| 1051 | */ |
| 1052 | else if (cx->latency > ACPI_PROCESSOR_MAX_C3_LATENCY) { |
| 1053 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1054 | "latency too large [%d]\n", cx->latency)); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1055 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | } |
| 1057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | /* |
| 1059 | * PIIX4 Erratum #18: We don't support C3 when Type-F (fast) |
| 1060 | * DMA transfers are used by any ISA device to avoid livelock. |
| 1061 | * Note that we could disable Type-F DMA (as recommended by |
| 1062 | * the erratum), but this is known to disrupt certain ISA |
| 1063 | * devices thus we take the conservative approach. |
| 1064 | */ |
| 1065 | else if (errata.piix4.fdma) { |
| 1066 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1067 | "C3 not supported on PIIX4 with Type-F DMA\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1068 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 1071 | /* All the logic here assumes flags.bm_check is same across all CPUs */ |
| 1072 | if (!bm_check_flag) { |
| 1073 | /* Determine whether bm_check is needed based on CPU */ |
| 1074 | acpi_processor_power_init_bm_check(&(pr->flags), pr->id); |
| 1075 | bm_check_flag = pr->flags.bm_check; |
| 1076 | } else { |
| 1077 | pr->flags.bm_check = bm_check_flag; |
| 1078 | } |
| 1079 | |
| 1080 | if (pr->flags.bm_check) { |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 1081 | if (!pr->flags.bm_control) { |
Venki Pallipadi | ed3110e | 2007-07-31 12:04:31 -0700 | [diff] [blame] | 1082 | if (pr->flags.has_cst != 1) { |
| 1083 | /* bus mastering control is necessary */ |
| 1084 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 1085 | "C3 support requires BM control\n")); |
| 1086 | return; |
| 1087 | } else { |
| 1088 | /* Here we enter C3 without bus mastering */ |
| 1089 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 1090 | "C3 support without BM control\n")); |
| 1091 | } |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 1092 | } |
| 1093 | } else { |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 1094 | /* |
| 1095 | * WBINVD should be set in fadt, for C3 state to be |
| 1096 | * supported on when bm_check is not required. |
| 1097 | */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 1098 | if (!(acpi_gbl_FADT.flags & ACPI_FADT_WBINVD)) { |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 1099 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1100 | "Cache invalidation should work properly" |
| 1101 | " for C3 to be enabled on SMP systems\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1102 | return; |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 1103 | } |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 1104 | } |
| 1105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | /* |
| 1107 | * Otherwise we've met all of our C3 requirements. |
| 1108 | * Normalize the C3 latency to expidite policy. Enable |
| 1109 | * checking of bus mastering status (bm_check) so we can |
| 1110 | * use this in our C3 policy |
| 1111 | */ |
| 1112 | cx->valid = 1; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1113 | |
| 1114 | #ifndef CONFIG_CPU_IDLE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1116 | #else |
| 1117 | cx->latency_ticks = cx->latency; |
| 1118 | #endif |
Len Brown | 31878dd | 2009-01-28 18:28:09 -0500 | [diff] [blame^] | 1119 | /* |
| 1120 | * On older chipsets, BM_RLD needs to be set |
| 1121 | * in order for Bus Master activity to wake the |
| 1122 | * system from C3. Newer chipsets handle DMA |
| 1123 | * during C3 automatically and BM_RLD is a NOP. |
| 1124 | * In either case, the proper way to |
| 1125 | * handle BM_RLD is to set it and leave it set. |
| 1126 | */ |
| 1127 | acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1129 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | static int acpi_processor_power_verify(struct acpi_processor *pr) |
| 1133 | { |
| 1134 | unsigned int i; |
| 1135 | unsigned int working = 0; |
Venkatesh Pallipadi | 6eb0a0f | 2006-01-11 22:44:21 +0100 | [diff] [blame] | 1136 | |
Thomas Gleixner | 169a0ab | 2007-02-16 01:27:55 -0800 | [diff] [blame] | 1137 | pr->power.timer_broadcast_on_state = INT_MAX; |
Venkatesh Pallipadi | 6eb0a0f | 2006-01-11 22:44:21 +0100 | [diff] [blame] | 1138 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1139 | for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | struct acpi_processor_cx *cx = &pr->power.states[i]; |
| 1141 | |
| 1142 | switch (cx->type) { |
| 1143 | case ACPI_STATE_C1: |
| 1144 | cx->valid = 1; |
| 1145 | break; |
| 1146 | |
| 1147 | case ACPI_STATE_C2: |
| 1148 | acpi_processor_power_verify_c2(cx); |
Linus Torvalds | 296d93c | 2007-03-23 08:03:47 -0700 | [diff] [blame] | 1149 | if (cx->valid) |
Thomas Gleixner | 169a0ab | 2007-02-16 01:27:55 -0800 | [diff] [blame] | 1150 | acpi_timer_check_state(i, pr, cx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | break; |
| 1152 | |
| 1153 | case ACPI_STATE_C3: |
| 1154 | acpi_processor_power_verify_c3(pr, cx); |
Linus Torvalds | 296d93c | 2007-03-23 08:03:47 -0700 | [diff] [blame] | 1155 | if (cx->valid) |
Thomas Gleixner | 169a0ab | 2007-02-16 01:27:55 -0800 | [diff] [blame] | 1156 | acpi_timer_check_state(i, pr, cx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | break; |
| 1158 | } |
| 1159 | |
| 1160 | if (cx->valid) |
| 1161 | working++; |
| 1162 | } |
| 1163 | |
Thomas Gleixner | 169a0ab | 2007-02-16 01:27:55 -0800 | [diff] [blame] | 1164 | acpi_propagate_timer_broadcast(pr); |
Andi Kleen | bd66334 | 2006-03-25 16:31:07 +0100 | [diff] [blame] | 1165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | return (working); |
| 1167 | } |
| 1168 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1169 | static int acpi_processor_get_power_info(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | { |
| 1171 | unsigned int i; |
| 1172 | int result; |
| 1173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | |
| 1175 | /* NOTE: the idle thread may not be running while calling |
| 1176 | * this function */ |
| 1177 | |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 1178 | /* Zero initialize all the C-states info. */ |
| 1179 | memset(pr->power.states, 0, sizeof(pr->power.states)); |
| 1180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | result = acpi_processor_get_power_info_cst(pr); |
Venkatesh Pallipadi | 6d93c64 | 2005-09-15 12:19:00 -0400 | [diff] [blame] | 1182 | if (result == -ENODEV) |
Darrick J. Wong | c5a114f | 2006-10-19 23:28:28 -0700 | [diff] [blame] | 1183 | result = acpi_processor_get_power_info_fadt(pr); |
Venkatesh Pallipadi | 6d93c64 | 2005-09-15 12:19:00 -0400 | [diff] [blame] | 1184 | |
Venkatesh Pallipadi | 991528d | 2006-09-25 16:28:13 -0700 | [diff] [blame] | 1185 | if (result) |
| 1186 | return result; |
| 1187 | |
| 1188 | acpi_processor_get_power_info_default(pr); |
| 1189 | |
Janosch Machowinski | cf82478 | 2005-08-20 08:02:00 -0400 | [diff] [blame] | 1190 | pr->power.count = acpi_processor_power_verify(pr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1192 | #ifndef CONFIG_CPU_IDLE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | /* |
| 1194 | * Set Default Policy |
| 1195 | * ------------------ |
| 1196 | * Now that we know which states are supported, set the default |
| 1197 | * policy. Note that this policy can be changed dynamically |
| 1198 | * (e.g. encourage deeper sleeps to conserve battery life when |
| 1199 | * not on AC). |
| 1200 | */ |
| 1201 | result = acpi_processor_set_power_policy(pr); |
| 1202 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1203 | return result; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1204 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | |
| 1206 | /* |
| 1207 | * if one state of type C2 or C3 is available, mark this |
| 1208 | * CPU as being "idle manageable" |
| 1209 | */ |
| 1210 | for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) { |
Venkatesh Pallipadi | acf05f4 | 2005-03-31 23:23:15 -0500 | [diff] [blame] | 1211 | if (pr->power.states[i].valid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | pr->power.count = i; |
Linus Torvalds | 2203d6e | 2005-11-18 07:29:51 -0800 | [diff] [blame] | 1213 | if (pr->power.states[i].type >= ACPI_STATE_C2) |
| 1214 | pr->flags.power = 1; |
Venkatesh Pallipadi | acf05f4 | 2005-03-31 23:23:15 -0500 | [diff] [blame] | 1215 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | } |
| 1217 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1218 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset) |
| 1222 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1223 | struct acpi_processor *pr = seq->private; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1224 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | |
| 1227 | if (!pr) |
| 1228 | goto end; |
| 1229 | |
| 1230 | seq_printf(seq, "active state: C%zd\n" |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1231 | "max_cstate: C%d\n" |
Arjan van de Ven | 5c87579 | 2006-09-30 23:27:17 -0700 | [diff] [blame] | 1232 | "bus master activity: %08x\n" |
| 1233 | "maximum allowed latency: %d usec\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1234 | pr->power.state ? pr->power.state - pr->power.states : 0, |
Arjan van de Ven | 5c87579 | 2006-09-30 23:27:17 -0700 | [diff] [blame] | 1235 | max_cstate, (unsigned)pr->power.bm_activity, |
Mark Gross | f011e2e | 2008-02-04 22:30:09 -0800 | [diff] [blame] | 1236 | pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | |
| 1238 | seq_puts(seq, "states:\n"); |
| 1239 | |
| 1240 | for (i = 1; i <= pr->power.count; i++) { |
| 1241 | seq_printf(seq, " %cC%d: ", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1242 | (&pr->power.states[i] == |
| 1243 | pr->power.state ? '*' : ' '), i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | |
| 1245 | if (!pr->power.states[i].valid) { |
| 1246 | seq_puts(seq, "<not supported>\n"); |
| 1247 | continue; |
| 1248 | } |
| 1249 | |
| 1250 | switch (pr->power.states[i].type) { |
| 1251 | case ACPI_STATE_C1: |
| 1252 | seq_printf(seq, "type[C1] "); |
| 1253 | break; |
| 1254 | case ACPI_STATE_C2: |
| 1255 | seq_printf(seq, "type[C2] "); |
| 1256 | break; |
| 1257 | case ACPI_STATE_C3: |
| 1258 | seq_printf(seq, "type[C3] "); |
| 1259 | break; |
| 1260 | default: |
| 1261 | seq_printf(seq, "type[--] "); |
| 1262 | break; |
| 1263 | } |
| 1264 | |
| 1265 | if (pr->power.states[i].promotion.state) |
| 1266 | seq_printf(seq, "promotion[C%zd] ", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1267 | (pr->power.states[i].promotion.state - |
| 1268 | pr->power.states)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | else |
| 1270 | seq_puts(seq, "promotion[--] "); |
| 1271 | |
| 1272 | if (pr->power.states[i].demotion.state) |
| 1273 | seq_printf(seq, "demotion[C%zd] ", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1274 | (pr->power.states[i].demotion.state - |
| 1275 | pr->power.states)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | else |
| 1277 | seq_puts(seq, "demotion[--] "); |
| 1278 | |
Dominik Brodowski | a3c6598 | 2006-06-24 19:37:00 -0400 | [diff] [blame] | 1279 | seq_printf(seq, "latency[%03d] usage[%08d] duration[%020llu]\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1280 | pr->power.states[i].latency, |
Dominik Brodowski | a3c6598 | 2006-06-24 19:37:00 -0400 | [diff] [blame] | 1281 | pr->power.states[i].usage, |
Alexey Starikovskiy | b0b7eaa | 2007-01-25 22:39:44 -0500 | [diff] [blame] | 1282 | (unsigned long long)pr->power.states[i].time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | } |
| 1284 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1285 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1286 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | static int acpi_processor_power_open_fs(struct inode *inode, struct file *file) |
| 1290 | { |
| 1291 | return single_open(file, acpi_processor_power_seq_show, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1292 | PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 1295 | static const struct file_operations acpi_processor_power_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1296 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1297 | .open = acpi_processor_power_open_fs, |
| 1298 | .read = seq_read, |
| 1299 | .llseek = seq_lseek, |
| 1300 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | }; |
| 1302 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1303 | #ifndef CONFIG_CPU_IDLE |
| 1304 | |
| 1305 | int acpi_processor_cst_has_changed(struct acpi_processor *pr) |
| 1306 | { |
| 1307 | int result = 0; |
| 1308 | |
Venkatesh Pallipadi | 36a9135 | 2008-04-30 13:57:15 -0400 | [diff] [blame] | 1309 | if (boot_option_idle_override) |
| 1310 | return 0; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1311 | |
| 1312 | if (!pr) |
| 1313 | return -EINVAL; |
| 1314 | |
| 1315 | if (nocst) { |
| 1316 | return -ENODEV; |
| 1317 | } |
| 1318 | |
| 1319 | if (!pr->flags.power_setup_done) |
| 1320 | return -ENODEV; |
| 1321 | |
Thomas Gleixner | b032bf70d | 2008-07-27 23:47:12 +0200 | [diff] [blame] | 1322 | /* |
| 1323 | * Fall back to the default idle loop, when pm_idle_save had |
| 1324 | * been initialized. |
| 1325 | */ |
| 1326 | if (pm_idle_save) { |
| 1327 | pm_idle = pm_idle_save; |
| 1328 | /* Relies on interrupts forcing exit from idle. */ |
| 1329 | synchronize_sched(); |
| 1330 | } |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1331 | |
| 1332 | pr->flags.power = 0; |
| 1333 | result = acpi_processor_get_power_info(pr); |
| 1334 | if ((pr->flags.power == 1) && (pr->flags.power_setup_done)) |
| 1335 | pm_idle = acpi_processor_idle; |
| 1336 | |
| 1337 | return result; |
| 1338 | } |
| 1339 | |
Andrew Morton | 1fec74a | 2006-10-17 00:09:58 -0700 | [diff] [blame] | 1340 | #ifdef CONFIG_SMP |
Arjan van de Ven | 5c87579 | 2006-09-30 23:27:17 -0700 | [diff] [blame] | 1341 | static void smp_callback(void *v) |
| 1342 | { |
| 1343 | /* we already woke the CPU up, nothing more to do */ |
| 1344 | } |
| 1345 | |
| 1346 | /* |
| 1347 | * This function gets called when a part of the kernel has a new latency |
| 1348 | * requirement. This means we need to get all processors out of their C-state, |
| 1349 | * and then recalculate a new suitable C-state. Just do a cross-cpu IPI; that |
| 1350 | * wakes them all right up. |
| 1351 | */ |
| 1352 | static int acpi_processor_latency_notify(struct notifier_block *b, |
| 1353 | unsigned long l, void *v) |
| 1354 | { |
Jens Axboe | 8691e5a | 2008-06-06 11:18:06 +0200 | [diff] [blame] | 1355 | smp_call_function(smp_callback, NULL, 1); |
Arjan van de Ven | 5c87579 | 2006-09-30 23:27:17 -0700 | [diff] [blame] | 1356 | return NOTIFY_OK; |
| 1357 | } |
| 1358 | |
| 1359 | static struct notifier_block acpi_processor_latency_notifier = { |
| 1360 | .notifier_call = acpi_processor_latency_notify, |
| 1361 | }; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1362 | |
Andrew Morton | 1fec74a | 2006-10-17 00:09:58 -0700 | [diff] [blame] | 1363 | #endif |
Arjan van de Ven | 5c87579 | 2006-09-30 23:27:17 -0700 | [diff] [blame] | 1364 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1365 | #else /* CONFIG_CPU_IDLE */ |
| 1366 | |
| 1367 | /** |
| 1368 | * acpi_idle_bm_check - checks if bus master activity was detected |
| 1369 | */ |
| 1370 | static int acpi_idle_bm_check(void) |
| 1371 | { |
| 1372 | u32 bm_status = 0; |
| 1373 | |
Len Brown | a2b7b01 | 2009-01-28 12:47:15 -0500 | [diff] [blame] | 1374 | acpi_get_register_unlocked(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1375 | if (bm_status) |
| 1376 | acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS, 1); |
| 1377 | /* |
| 1378 | * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect |
| 1379 | * the true state of bus mastering activity; forcing us to |
| 1380 | * manually check the BMIDEA bit of each IDE channel. |
| 1381 | */ |
| 1382 | else if (errata.piix4.bmisx) { |
| 1383 | if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01) |
| 1384 | || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01)) |
| 1385 | bm_status = 1; |
| 1386 | } |
| 1387 | return bm_status; |
| 1388 | } |
| 1389 | |
| 1390 | /** |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1391 | * acpi_idle_do_entry - a helper function that does C2 and C3 type entry |
| 1392 | * @cx: cstate data |
venkatesh.pallipadi@intel.com | bc71bec | 2008-01-31 17:35:04 -0800 | [diff] [blame] | 1393 | * |
| 1394 | * Caller disables interrupt before call and enables interrupt after return. |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1395 | */ |
| 1396 | static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx) |
| 1397 | { |
Steven Rostedt | dcf3099 | 2008-07-25 18:00:42 -0400 | [diff] [blame] | 1398 | /* Don't trace irqs off for idle */ |
| 1399 | stop_critical_timings(); |
venkatesh.pallipadi@intel.com | bc71bec | 2008-01-31 17:35:04 -0800 | [diff] [blame] | 1400 | if (cx->entry_method == ACPI_CSTATE_FFH) { |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1401 | /* Call into architectural FFH based C-state */ |
| 1402 | acpi_processor_ffh_cstate_enter(cx); |
venkatesh.pallipadi@intel.com | bc71bec | 2008-01-31 17:35:04 -0800 | [diff] [blame] | 1403 | } else if (cx->entry_method == ACPI_CSTATE_HALT) { |
| 1404 | acpi_safe_halt(); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1405 | } else { |
| 1406 | int unused; |
| 1407 | /* IO port based C-state */ |
| 1408 | inb(cx->address); |
| 1409 | /* Dummy wait op - must do something useless after P_LVL2 read |
| 1410 | because chipsets cannot guarantee that STPCLK# signal |
| 1411 | gets asserted in time to freeze execution properly. */ |
| 1412 | unused = inl(acpi_gbl_FADT.xpm_timer_block.address); |
| 1413 | } |
Steven Rostedt | dcf3099 | 2008-07-25 18:00:42 -0400 | [diff] [blame] | 1414 | start_critical_timings(); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | /** |
| 1418 | * acpi_idle_enter_c1 - enters an ACPI C1 state-type |
| 1419 | * @dev: the target CPU |
| 1420 | * @state: the state data |
| 1421 | * |
| 1422 | * This is equivalent to the HALT instruction. |
| 1423 | */ |
| 1424 | static int acpi_idle_enter_c1(struct cpuidle_device *dev, |
| 1425 | struct cpuidle_state *state) |
| 1426 | { |
venkatesh.pallipadi@intel.com | 9b12e18 | 2008-01-31 17:35:05 -0800 | [diff] [blame] | 1427 | u32 t1, t2; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1428 | struct acpi_processor *pr; |
| 1429 | struct acpi_processor_cx *cx = cpuidle_get_statedata(state); |
venkatesh.pallipadi@intel.com | 9b12e18 | 2008-01-31 17:35:05 -0800 | [diff] [blame] | 1430 | |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 1431 | pr = __get_cpu_var(processors); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1432 | |
| 1433 | if (unlikely(!pr)) |
| 1434 | return 0; |
| 1435 | |
venkatesh.pallipadi@intel.com | 2e90665 | 2008-01-31 17:35:03 -0800 | [diff] [blame] | 1436 | local_irq_disable(); |
Venkatesh Pallipadi | b077fba | 2008-02-11 15:20:27 -0800 | [diff] [blame] | 1437 | |
| 1438 | /* Do not access any ACPI IO ports in suspend path */ |
| 1439 | if (acpi_idle_suspend) { |
| 1440 | acpi_safe_halt(); |
| 1441 | local_irq_enable(); |
| 1442 | return 0; |
| 1443 | } |
| 1444 | |
venkatesh.pallipadi@intel.com | 9b12e18 | 2008-01-31 17:35:05 -0800 | [diff] [blame] | 1445 | t1 = inl(acpi_gbl_FADT.xpm_timer_block.address); |
venkatesh.pallipadi@intel.com | bc71bec | 2008-01-31 17:35:04 -0800 | [diff] [blame] | 1446 | acpi_idle_do_entry(cx); |
venkatesh.pallipadi@intel.com | 9b12e18 | 2008-01-31 17:35:05 -0800 | [diff] [blame] | 1447 | t2 = inl(acpi_gbl_FADT.xpm_timer_block.address); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1448 | |
venkatesh.pallipadi@intel.com | 2e90665 | 2008-01-31 17:35:03 -0800 | [diff] [blame] | 1449 | local_irq_enable(); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1450 | cx->usage++; |
| 1451 | |
venkatesh.pallipadi@intel.com | 9b12e18 | 2008-01-31 17:35:05 -0800 | [diff] [blame] | 1452 | return ticks_elapsed_in_us(t1, t2); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | /** |
| 1456 | * acpi_idle_enter_simple - enters an ACPI state without BM handling |
| 1457 | * @dev: the target CPU |
| 1458 | * @state: the state data |
| 1459 | */ |
| 1460 | static int acpi_idle_enter_simple(struct cpuidle_device *dev, |
| 1461 | struct cpuidle_state *state) |
| 1462 | { |
| 1463 | struct acpi_processor *pr; |
| 1464 | struct acpi_processor_cx *cx = cpuidle_get_statedata(state); |
| 1465 | u32 t1, t2; |
Venkatesh Pallipadi | 5062911 | 2007-11-19 19:49:00 -0500 | [diff] [blame] | 1466 | int sleep_ticks = 0; |
| 1467 | |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 1468 | pr = __get_cpu_var(processors); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1469 | |
| 1470 | if (unlikely(!pr)) |
| 1471 | return 0; |
| 1472 | |
Len Brown | e196441 | 2007-10-04 01:23:47 -0400 | [diff] [blame] | 1473 | if (acpi_idle_suspend) |
| 1474 | return(acpi_idle_enter_c1(dev, state)); |
| 1475 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1476 | local_irq_disable(); |
| 1477 | current_thread_info()->status &= ~TS_POLLING; |
| 1478 | /* |
| 1479 | * TS_POLLING-cleared state must be visible before we test |
| 1480 | * NEED_RESCHED: |
| 1481 | */ |
| 1482 | smp_mb(); |
| 1483 | |
| 1484 | if (unlikely(need_resched())) { |
| 1485 | current_thread_info()->status |= TS_POLLING; |
| 1486 | local_irq_enable(); |
| 1487 | return 0; |
| 1488 | } |
| 1489 | |
Thomas Gleixner | e17bcb4 | 2007-12-07 19:16:17 +0100 | [diff] [blame] | 1490 | /* |
| 1491 | * Must be done before busmaster disable as we might need to |
| 1492 | * access HPET ! |
| 1493 | */ |
| 1494 | acpi_state_timer_broadcast(pr, cx, 1); |
| 1495 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1496 | if (cx->type == ACPI_STATE_C3) |
| 1497 | ACPI_FLUSH_CPU_CACHE(); |
| 1498 | |
| 1499 | t1 = inl(acpi_gbl_FADT.xpm_timer_block.address); |
Venkatesh Pallipadi | 5062911 | 2007-11-19 19:49:00 -0500 | [diff] [blame] | 1500 | /* Tell the scheduler that we are going deep-idle: */ |
| 1501 | sched_clock_idle_sleep_event(); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1502 | acpi_idle_do_entry(cx); |
| 1503 | t2 = inl(acpi_gbl_FADT.xpm_timer_block.address); |
| 1504 | |
Pavel Machek | 6133116 | 2008-02-19 11:00:29 +0100 | [diff] [blame] | 1505 | #if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86) |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1506 | /* TSC could halt in idle, so notify users */ |
Andi Kleen | ddb25f9 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 1507 | if (tsc_halts_in_c(cx->type)) |
| 1508 | mark_tsc_unstable("TSC halts in idle");; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1509 | #endif |
Venkatesh Pallipadi | 5062911 | 2007-11-19 19:49:00 -0500 | [diff] [blame] | 1510 | sleep_ticks = ticks_elapsed(t1, t2); |
| 1511 | |
| 1512 | /* Tell the scheduler how much we idled: */ |
| 1513 | sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1514 | |
| 1515 | local_irq_enable(); |
| 1516 | current_thread_info()->status |= TS_POLLING; |
| 1517 | |
| 1518 | cx->usage++; |
| 1519 | |
| 1520 | acpi_state_timer_broadcast(pr, cx, 0); |
Venkatesh Pallipadi | 5062911 | 2007-11-19 19:49:00 -0500 | [diff] [blame] | 1521 | cx->time += sleep_ticks; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1522 | return ticks_elapsed_in_us(t1, t2); |
| 1523 | } |
| 1524 | |
| 1525 | static int c3_cpu_count; |
| 1526 | static DEFINE_SPINLOCK(c3_lock); |
| 1527 | |
| 1528 | /** |
| 1529 | * acpi_idle_enter_bm - enters C3 with proper BM handling |
| 1530 | * @dev: the target CPU |
| 1531 | * @state: the state data |
| 1532 | * |
| 1533 | * If BM is detected, the deepest non-C3 idle state is entered instead. |
| 1534 | */ |
| 1535 | static int acpi_idle_enter_bm(struct cpuidle_device *dev, |
| 1536 | struct cpuidle_state *state) |
| 1537 | { |
| 1538 | struct acpi_processor *pr; |
| 1539 | struct acpi_processor_cx *cx = cpuidle_get_statedata(state); |
| 1540 | u32 t1, t2; |
Venkatesh Pallipadi | 5062911 | 2007-11-19 19:49:00 -0500 | [diff] [blame] | 1541 | int sleep_ticks = 0; |
| 1542 | |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 1543 | pr = __get_cpu_var(processors); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1544 | |
| 1545 | if (unlikely(!pr)) |
| 1546 | return 0; |
| 1547 | |
Len Brown | e196441 | 2007-10-04 01:23:47 -0400 | [diff] [blame] | 1548 | if (acpi_idle_suspend) |
| 1549 | return(acpi_idle_enter_c1(dev, state)); |
| 1550 | |
Venkatesh Pallipadi | ddc081a | 2007-11-19 21:43:22 -0500 | [diff] [blame] | 1551 | if (acpi_idle_bm_check()) { |
| 1552 | if (dev->safe_state) { |
Venkatesh Pallipadi | addbad4 | 2008-09-29 15:24:28 -0700 | [diff] [blame] | 1553 | dev->last_state = dev->safe_state; |
Venkatesh Pallipadi | ddc081a | 2007-11-19 21:43:22 -0500 | [diff] [blame] | 1554 | return dev->safe_state->enter(dev, dev->safe_state); |
| 1555 | } else { |
venkatesh.pallipadi@intel.com | 2e90665 | 2008-01-31 17:35:03 -0800 | [diff] [blame] | 1556 | local_irq_disable(); |
Venkatesh Pallipadi | ddc081a | 2007-11-19 21:43:22 -0500 | [diff] [blame] | 1557 | acpi_safe_halt(); |
venkatesh.pallipadi@intel.com | 2e90665 | 2008-01-31 17:35:03 -0800 | [diff] [blame] | 1558 | local_irq_enable(); |
Venkatesh Pallipadi | ddc081a | 2007-11-19 21:43:22 -0500 | [diff] [blame] | 1559 | return 0; |
| 1560 | } |
| 1561 | } |
| 1562 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1563 | local_irq_disable(); |
| 1564 | current_thread_info()->status &= ~TS_POLLING; |
| 1565 | /* |
| 1566 | * TS_POLLING-cleared state must be visible before we test |
| 1567 | * NEED_RESCHED: |
| 1568 | */ |
| 1569 | smp_mb(); |
| 1570 | |
| 1571 | if (unlikely(need_resched())) { |
| 1572 | current_thread_info()->status |= TS_POLLING; |
| 1573 | local_irq_enable(); |
| 1574 | return 0; |
| 1575 | } |
| 1576 | |
Venki Pallipadi | 996520c | 2008-03-24 14:24:10 -0700 | [diff] [blame] | 1577 | acpi_unlazy_tlb(smp_processor_id()); |
| 1578 | |
Venkatesh Pallipadi | 5062911 | 2007-11-19 19:49:00 -0500 | [diff] [blame] | 1579 | /* Tell the scheduler that we are going deep-idle: */ |
| 1580 | sched_clock_idle_sleep_event(); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1581 | /* |
| 1582 | * Must be done before busmaster disable as we might need to |
| 1583 | * access HPET ! |
| 1584 | */ |
| 1585 | acpi_state_timer_broadcast(pr, cx, 1); |
| 1586 | |
Venkatesh Pallipadi | ddc081a | 2007-11-19 21:43:22 -0500 | [diff] [blame] | 1587 | /* |
| 1588 | * disable bus master |
| 1589 | * bm_check implies we need ARB_DIS |
| 1590 | * !bm_check implies we need cache flush |
| 1591 | * bm_control implies whether we can do ARB_DIS |
| 1592 | * |
| 1593 | * That leaves a case where bm_check is set and bm_control is |
| 1594 | * not set. In that case we cannot do much, we enter C3 |
| 1595 | * without doing anything. |
| 1596 | */ |
| 1597 | if (pr->flags.bm_check && pr->flags.bm_control) { |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1598 | spin_lock(&c3_lock); |
| 1599 | c3_cpu_count++; |
| 1600 | /* Disable bus master arbitration when all CPUs are in C3 */ |
| 1601 | if (c3_cpu_count == num_online_cpus()) |
| 1602 | acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1); |
| 1603 | spin_unlock(&c3_lock); |
Venkatesh Pallipadi | ddc081a | 2007-11-19 21:43:22 -0500 | [diff] [blame] | 1604 | } else if (!pr->flags.bm_check) { |
| 1605 | ACPI_FLUSH_CPU_CACHE(); |
| 1606 | } |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1607 | |
Venkatesh Pallipadi | ddc081a | 2007-11-19 21:43:22 -0500 | [diff] [blame] | 1608 | t1 = inl(acpi_gbl_FADT.xpm_timer_block.address); |
| 1609 | acpi_idle_do_entry(cx); |
| 1610 | t2 = inl(acpi_gbl_FADT.xpm_timer_block.address); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1611 | |
Venkatesh Pallipadi | ddc081a | 2007-11-19 21:43:22 -0500 | [diff] [blame] | 1612 | /* Re-enable bus master arbitration */ |
| 1613 | if (pr->flags.bm_check && pr->flags.bm_control) { |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1614 | spin_lock(&c3_lock); |
Venkatesh Pallipadi | ddc081a | 2007-11-19 21:43:22 -0500 | [diff] [blame] | 1615 | acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1616 | c3_cpu_count--; |
| 1617 | spin_unlock(&c3_lock); |
| 1618 | } |
| 1619 | |
Pavel Machek | 6133116 | 2008-02-19 11:00:29 +0100 | [diff] [blame] | 1620 | #if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86) |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1621 | /* TSC could halt in idle, so notify users */ |
Andi Kleen | ddb25f9 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 1622 | if (tsc_halts_in_c(ACPI_STATE_C3)) |
| 1623 | mark_tsc_unstable("TSC halts in idle"); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1624 | #endif |
Venkatesh Pallipadi | 5062911 | 2007-11-19 19:49:00 -0500 | [diff] [blame] | 1625 | sleep_ticks = ticks_elapsed(t1, t2); |
| 1626 | /* Tell the scheduler how much we idled: */ |
| 1627 | sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1628 | |
| 1629 | local_irq_enable(); |
| 1630 | current_thread_info()->status |= TS_POLLING; |
| 1631 | |
| 1632 | cx->usage++; |
| 1633 | |
| 1634 | acpi_state_timer_broadcast(pr, cx, 0); |
Venkatesh Pallipadi | 5062911 | 2007-11-19 19:49:00 -0500 | [diff] [blame] | 1635 | cx->time += sleep_ticks; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1636 | return ticks_elapsed_in_us(t1, t2); |
| 1637 | } |
| 1638 | |
| 1639 | struct cpuidle_driver acpi_idle_driver = { |
| 1640 | .name = "acpi_idle", |
| 1641 | .owner = THIS_MODULE, |
| 1642 | }; |
| 1643 | |
| 1644 | /** |
| 1645 | * acpi_processor_setup_cpuidle - prepares and configures CPUIDLE |
| 1646 | * @pr: the ACPI processor |
| 1647 | */ |
| 1648 | static int acpi_processor_setup_cpuidle(struct acpi_processor *pr) |
| 1649 | { |
venkatesh.pallipadi@intel.com | 9a0b841 | 2008-01-31 17:35:06 -0800 | [diff] [blame] | 1650 | int i, count = CPUIDLE_DRIVER_STATE_START; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1651 | struct acpi_processor_cx *cx; |
| 1652 | struct cpuidle_state *state; |
| 1653 | struct cpuidle_device *dev = &pr->power.dev; |
| 1654 | |
| 1655 | if (!pr->flags.power_setup_done) |
| 1656 | return -EINVAL; |
| 1657 | |
| 1658 | if (pr->flags.power == 0) { |
| 1659 | return -EINVAL; |
| 1660 | } |
| 1661 | |
Venkatesh Pallipadi | dcb84f3 | 2008-05-19 19:09:27 -0400 | [diff] [blame] | 1662 | dev->cpu = pr->id; |
Venkatesh Pallipadi | 4fcb2fc | 2008-02-11 17:46:31 -0800 | [diff] [blame] | 1663 | for (i = 0; i < CPUIDLE_STATE_MAX; i++) { |
| 1664 | dev->states[i].name[0] = '\0'; |
| 1665 | dev->states[i].desc[0] = '\0'; |
| 1666 | } |
| 1667 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1668 | for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) { |
| 1669 | cx = &pr->power.states[i]; |
| 1670 | state = &dev->states[count]; |
| 1671 | |
| 1672 | if (!cx->valid) |
| 1673 | continue; |
| 1674 | |
| 1675 | #ifdef CONFIG_HOTPLUG_CPU |
| 1676 | if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) && |
| 1677 | !pr->flags.has_cst && |
| 1678 | !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED)) |
| 1679 | continue; |
| 1680 | #endif |
| 1681 | cpuidle_set_statedata(state, cx); |
| 1682 | |
| 1683 | snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i); |
Venkatesh Pallipadi | 4fcb2fc | 2008-02-11 17:46:31 -0800 | [diff] [blame] | 1684 | strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1685 | state->exit_latency = cx->latency; |
Len Brown | 4963f62 | 2007-12-13 23:50:45 -0500 | [diff] [blame] | 1686 | state->target_residency = cx->latency * latency_factor; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1687 | state->power_usage = cx->power; |
| 1688 | |
| 1689 | state->flags = 0; |
| 1690 | switch (cx->type) { |
| 1691 | case ACPI_STATE_C1: |
| 1692 | state->flags |= CPUIDLE_FLAG_SHALLOW; |
Venki Pallipadi | 8e92b66 | 2008-02-29 10:24:32 -0800 | [diff] [blame] | 1693 | if (cx->entry_method == ACPI_CSTATE_FFH) |
| 1694 | state->flags |= CPUIDLE_FLAG_TIME_VALID; |
| 1695 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1696 | state->enter = acpi_idle_enter_c1; |
Venkatesh Pallipadi | ddc081a | 2007-11-19 21:43:22 -0500 | [diff] [blame] | 1697 | dev->safe_state = state; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1698 | break; |
| 1699 | |
| 1700 | case ACPI_STATE_C2: |
| 1701 | state->flags |= CPUIDLE_FLAG_BALANCED; |
| 1702 | state->flags |= CPUIDLE_FLAG_TIME_VALID; |
| 1703 | state->enter = acpi_idle_enter_simple; |
Venkatesh Pallipadi | ddc081a | 2007-11-19 21:43:22 -0500 | [diff] [blame] | 1704 | dev->safe_state = state; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1705 | break; |
| 1706 | |
| 1707 | case ACPI_STATE_C3: |
| 1708 | state->flags |= CPUIDLE_FLAG_DEEP; |
| 1709 | state->flags |= CPUIDLE_FLAG_TIME_VALID; |
| 1710 | state->flags |= CPUIDLE_FLAG_CHECK_BM; |
| 1711 | state->enter = pr->flags.bm_check ? |
| 1712 | acpi_idle_enter_bm : |
| 1713 | acpi_idle_enter_simple; |
| 1714 | break; |
| 1715 | } |
| 1716 | |
| 1717 | count++; |
venkatesh.pallipadi@intel.com | 9a0b841 | 2008-01-31 17:35:06 -0800 | [diff] [blame] | 1718 | if (count == CPUIDLE_STATE_MAX) |
| 1719 | break; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | dev->state_count = count; |
| 1723 | |
| 1724 | if (!count) |
| 1725 | return -EINVAL; |
| 1726 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1727 | return 0; |
| 1728 | } |
| 1729 | |
| 1730 | int acpi_processor_cst_has_changed(struct acpi_processor *pr) |
| 1731 | { |
Venkatesh Pallipadi | dcb84f3 | 2008-05-19 19:09:27 -0400 | [diff] [blame] | 1732 | int ret = 0; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1733 | |
Venkatesh Pallipadi | 36a9135 | 2008-04-30 13:57:15 -0400 | [diff] [blame] | 1734 | if (boot_option_idle_override) |
| 1735 | return 0; |
| 1736 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1737 | if (!pr) |
| 1738 | return -EINVAL; |
| 1739 | |
| 1740 | if (nocst) { |
| 1741 | return -ENODEV; |
| 1742 | } |
| 1743 | |
| 1744 | if (!pr->flags.power_setup_done) |
| 1745 | return -ENODEV; |
| 1746 | |
| 1747 | cpuidle_pause_and_lock(); |
| 1748 | cpuidle_disable_device(&pr->power.dev); |
| 1749 | acpi_processor_get_power_info(pr); |
Venkatesh Pallipadi | dcb84f3 | 2008-05-19 19:09:27 -0400 | [diff] [blame] | 1750 | if (pr->flags.power) { |
| 1751 | acpi_processor_setup_cpuidle(pr); |
| 1752 | ret = cpuidle_enable_device(&pr->power.dev); |
| 1753 | } |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1754 | cpuidle_resume_and_unlock(); |
| 1755 | |
| 1756 | return ret; |
| 1757 | } |
| 1758 | |
| 1759 | #endif /* CONFIG_CPU_IDLE */ |
| 1760 | |
Pierre Ossman | 7af8b66 | 2006-10-10 14:20:31 -0700 | [diff] [blame] | 1761 | int __cpuinit acpi_processor_power_init(struct acpi_processor *pr, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1762 | struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1764 | acpi_status status = 0; |
Andreas Mohr | b683505 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 1765 | static int first_run; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1766 | struct proc_dir_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | unsigned int i; |
| 1768 | |
Venkatesh Pallipadi | 36a9135 | 2008-04-30 13:57:15 -0400 | [diff] [blame] | 1769 | if (boot_option_idle_override) |
| 1770 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | |
| 1772 | if (!first_run) { |
Zhao Yakui | c1e3b37 | 2008-06-24 17:58:53 +0800 | [diff] [blame] | 1773 | if (idle_halt) { |
| 1774 | /* |
| 1775 | * When the boot option of "idle=halt" is added, halt |
| 1776 | * is used for CPU IDLE. |
| 1777 | * In such case C2/C3 is meaningless. So the max_cstate |
| 1778 | * is set to one. |
| 1779 | */ |
| 1780 | max_cstate = 1; |
| 1781 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | dmi_check_system(processor_power_dmi_table); |
Alexey Starikovskiy | c1c3063 | 2007-11-26 20:42:19 +0100 | [diff] [blame] | 1783 | max_cstate = acpi_processor_cstate_check(max_cstate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | if (max_cstate < ACPI_C_STATES_MAX) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1785 | printk(KERN_NOTICE |
| 1786 | "ACPI: processor limited to max C-state %d\n", |
| 1787 | max_cstate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | first_run++; |
Mark Gross | f011e2e | 2008-02-04 22:30:09 -0800 | [diff] [blame] | 1789 | #if !defined(CONFIG_CPU_IDLE) && defined(CONFIG_SMP) |
| 1790 | pm_qos_add_notifier(PM_QOS_CPU_DMA_LATENCY, |
| 1791 | &acpi_processor_latency_notifier); |
Andrew Morton | 1fec74a | 2006-10-17 00:09:58 -0700 | [diff] [blame] | 1792 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 1795 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1796 | return -EINVAL; |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 1797 | |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 1798 | if (acpi_gbl_FADT.cst_control && !nocst) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1799 | status = |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 1800 | acpi_os_write_port(acpi_gbl_FADT.smi_command, acpi_gbl_FADT.cst_control, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 1802 | ACPI_EXCEPTION((AE_INFO, status, |
| 1803 | "Notifying BIOS of _CST ability failed")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | } |
| 1805 | } |
| 1806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | acpi_processor_get_power_info(pr); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1808 | pr->flags.power_setup_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | |
| 1810 | /* |
| 1811 | * Install the idle handler if processor power management is supported. |
| 1812 | * Note that we use previously set idle handler will be used on |
| 1813 | * platforms that only support C1. |
| 1814 | */ |
Venkatesh Pallipadi | 36a9135 | 2008-04-30 13:57:15 -0400 | [diff] [blame] | 1815 | if (pr->flags.power) { |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1816 | #ifdef CONFIG_CPU_IDLE |
| 1817 | acpi_processor_setup_cpuidle(pr); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1818 | if (cpuidle_register_device(&pr->power.dev)) |
| 1819 | return -EIO; |
| 1820 | #endif |
| 1821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | printk(KERN_INFO PREFIX "CPU%d (power states:", pr->id); |
| 1823 | for (i = 1; i <= pr->power.count; i++) |
| 1824 | if (pr->power.states[i].valid) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1825 | printk(" C%d[C%d]", i, |
| 1826 | pr->power.states[i].type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | printk(")\n"); |
| 1828 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1829 | #ifndef CONFIG_CPU_IDLE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | if (pr->id == 0) { |
| 1831 | pm_idle_save = pm_idle; |
| 1832 | pm_idle = acpi_processor_idle; |
| 1833 | } |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1834 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | /* 'power' [R] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1838 | entry = proc_create_data(ACPI_PROCESSOR_FILE_POWER, |
| 1839 | S_IRUGO, acpi_device_dir(device), |
| 1840 | &acpi_processor_power_fops, |
| 1841 | acpi_driver_data(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | if (!entry) |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 1843 | return -EIO; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1844 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | } |
| 1846 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1847 | int acpi_processor_power_exit(struct acpi_processor *pr, |
| 1848 | struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | { |
Venkatesh Pallipadi | 36a9135 | 2008-04-30 13:57:15 -0400 | [diff] [blame] | 1850 | if (boot_option_idle_override) |
| 1851 | return 0; |
| 1852 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1853 | #ifdef CONFIG_CPU_IDLE |
Venkatesh Pallipadi | dcb84f3 | 2008-05-19 19:09:27 -0400 | [diff] [blame] | 1854 | cpuidle_unregister_device(&pr->power.dev); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1855 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | pr->flags.power_setup_done = 0; |
| 1857 | |
| 1858 | if (acpi_device_dir(device)) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1859 | remove_proc_entry(ACPI_PROCESSOR_FILE_POWER, |
| 1860 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1862 | #ifndef CONFIG_CPU_IDLE |
| 1863 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | /* Unregister the idle handler when processor #0 is removed. */ |
| 1865 | if (pr->id == 0) { |
Thomas Gleixner | b032bf70d | 2008-07-27 23:47:12 +0200 | [diff] [blame] | 1866 | if (pm_idle_save) |
| 1867 | pm_idle = pm_idle_save; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | |
| 1869 | /* |
| 1870 | * We are about to unload the current idle thread pm callback |
| 1871 | * (pm_idle), Wait for all processors to update cached/local |
| 1872 | * copies of pm_idle before proceeding. |
| 1873 | */ |
| 1874 | cpu_idle_wait(); |
Andrew Morton | 1fec74a | 2006-10-17 00:09:58 -0700 | [diff] [blame] | 1875 | #ifdef CONFIG_SMP |
Mark Gross | f011e2e | 2008-02-04 22:30:09 -0800 | [diff] [blame] | 1876 | pm_qos_remove_notifier(PM_QOS_CPU_DMA_LATENCY, |
| 1877 | &acpi_processor_latency_notifier); |
Andrew Morton | 1fec74a | 2006-10-17 00:09:58 -0700 | [diff] [blame] | 1878 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | } |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 1880 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1882 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | } |