processor_idle.c 49 KB

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