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