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