processor_idle.c 47 KB

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