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