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